import binascii import datetime import filetimes import kmsPidGenerator import os import struct import sys import time import uuid from structure import Structure import logging # sqlite3 is optional try: import sqlite3 except: pass class UUID(Structure): commonHdr = () structure = ( ('raw', '16s'), ) def get(self): return uuid.UUID(bytes_le=str(self)) class kmsBase: class kmsRequestStruct(Structure): commonHdr = () structure = ( ('versionMinor', ' This line was returning garbage in the pidGenerator if not self.config["epid"]: response["kmsEpid"] = kmsPidGenerator.epidGenerator(applicationId, kmsRequest['versionMajor'], self.config["lcid"]).encode('utf-16le') else: response["kmsEpid"] = self.config["epid"].encode('utf-16le') response['clientMachineId'] = kmsRequest['clientMachineId'] response['responseTime'] = kmsRequest['requestTime'] response['currentClientCount'] = self.config["CurrentClientCount"] response['vLActivationInterval'] = self.config["VLActivationInterval"] response['vLRenewalInterval'] = self.config["VLRenewalInterval"] if self.config['sqlite'] and self.config['dbSupport']: con = None try: con = sqlite3.connect(self.dbName) cur = con.cursor() cur.execute("SELECT * FROM clients WHERE clientMachineId=?;", [str(kmsRequest['clientMachineId'].get())]) try: data = cur.fetchone() #print "Data:", data if data[6]: response["kmsEpid"] = data[6].encode('utf-16le') else: cur.execute("UPDATE clients SET kmsEpid=? WHERE clientMachineId=?;", (str(response["kmsEpid"].decode('utf-16le')), str(kmsRequest['clientMachineId'].get()))) except sqlite3.Error, e: logging.error("%s:" % e.args[0]) except sqlite3.Error, e: logging.error("%s:" % e.args[0]) sys.exit(1) finally: if con: con.commit() con.close() logging.info("Server ePID: %s" % response["kmsEpid"].decode('utf-16le').encode('utf-8')) return response import kmsRequestV4, kmsRequestV5, kmsRequestV6, kmsRequestUnknown def generateKmsResponseData(data, config): version = kmsBase.GenericRequestHeader(data)['versionMajor'] currentDate = datetime.datetime.now().ctime() if version == 4: logging.info("Received V%d request on %s." % (version, currentDate)) messagehandler = kmsRequestV4.kmsRequestV4(data, config) messagehandler.executeRequestLogic() elif version == 5: logging.info("Received V%d request on %s." % (version, currentDate)) messagehandler = kmsRequestV5.kmsRequestV5(data, config) messagehandler.executeRequestLogic() elif version == 6: logging.info("Received V%d request on %s." % (version, currentDate)) messagehandler = kmsRequestV6.kmsRequestV6(data, config) messagehandler.executeRequestLogic() else: logging.info("Unhandled KMS version V%d." % version) messagehandler = kmsRequestUnknown.kmsRequestUnknown(data, config) return messagehandler.getResponse()