123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #coding=utf-8
- import Crypto.Hash
- import Crypto.PublicKey.RSA
- import Crypto.Signature.PKCS1_v1_5
- import uuid
- import platform
- import base64
- import hashlib
- import os
- XorKey = [0xB2, 0x09, 0xBB, 0x55, 0x93, 0x83, 0x03, 0x24]
- def enc(src):
- j, result = 0, ""
- for s in src:
- result = result + hex(ord(s) ^ (XorKey[j]))[2:]
- j = (j + 1) % 8
- return result
- def getMac():
- sysstr = platform.system()
- if (sysstr == "Windows"):
- import winreg
- key = winreg.OpenKey(
- winreg.HKEY_LOCAL_MACHINE,
- "SOFTWARE\\Microsoft\\Cryptography",
- 0,
- winreg.KEY_READ | winreg.KEY_WOW64_64KEY
- )
- result = winreg.QueryValueEx(key, "MachineGuid")
- mac = result[0]
- else:
- mac = ':'.join(['{:02x}'.format((uuid.getnode() >> i) & 0xff) for i in range(0, 8 * 6, 8)][::-1])
- path = '/auth/kaohe/v2/'
- mac += 'ZZLY[' + path + ']20190325'
- mac = enc(mac)
- mac = base64.b64encode(mac.encode())
- mac = hashlib.sha256(mac).hexdigest()
- return mac
- def checkLicence():
- pub_key = """-----BEGIN RSA PUBLIC KEY-----
- MIGJAoGBAMhqydgWZUV7qy96aGTY6i/pGC5mC8AyjvwIwoH2zE6hi5MQsW5cpOLS
- d2VNhfi2ypg19w3Z2sd248X/fc4lGwDwP8/fXNoRtVBDR/3F/+WlaK9beFIyp5J4
- Fa2XHj5lOiCjLoJpzehE2Dguv+3xORJn10oGAHQhXxFjdWEt5xBBAgMBAAE=
- -----END RSA PUBLIC KEY-----"""
- mac = getMac()
- with open(os.path.dirname(__file__) + "/../licence", 'rb') as x:
- licence = x.read()
- d_rsa = Crypto.PublicKey.RSA.importKey(pub_key)
- verifer = Crypto.Signature.PKCS1_v1_5.new(d_rsa)
- msg_hash = Crypto.Hash.SHA256.new()
- msg_hash.update(mac.encode('utf-8'))
- return verifer.verify(msg_hash, base64.decodebytes(licence))
|