empower.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #coding=utf-8
  2. import Crypto.Hash
  3. import Crypto.PublicKey.RSA
  4. import Crypto.Signature.PKCS1_v1_5
  5. import uuid
  6. import platform
  7. import base64
  8. import hashlib
  9. import os
  10. XorKey = [0xB2, 0x09, 0xBB, 0x55, 0x93, 0x83, 0x03, 0x24]
  11. def enc(src):
  12. j, result = 0, ""
  13. for s in src:
  14. result = result + hex(ord(s) ^ (XorKey[j]))[2:]
  15. j = (j + 1) % 8
  16. return result
  17. def getMac():
  18. sysstr = platform.system()
  19. if (sysstr == "Windows"):
  20. import winreg
  21. key = winreg.OpenKey(
  22. winreg.HKEY_LOCAL_MACHINE,
  23. "SOFTWARE\\Microsoft\\Cryptography",
  24. 0,
  25. winreg.KEY_READ | winreg.KEY_WOW64_64KEY
  26. )
  27. result = winreg.QueryValueEx(key, "MachineGuid")
  28. mac = result[0]
  29. else:
  30. mac = ':'.join(['{:02x}'.format((uuid.getnode() >> i) & 0xff) for i in range(0, 8 * 6, 8)][::-1])
  31. path = '/auth/kaohe/v2/'
  32. mac += 'ZZLY[' + path + ']20190325'
  33. mac = enc(mac)
  34. mac = base64.b64encode(mac.encode())
  35. mac = hashlib.sha256(mac).hexdigest()
  36. return mac
  37. def checkLicence():
  38. pub_key = """-----BEGIN RSA PUBLIC KEY-----
  39. MIGJAoGBAMhqydgWZUV7qy96aGTY6i/pGC5mC8AyjvwIwoH2zE6hi5MQsW5cpOLS
  40. d2VNhfi2ypg19w3Z2sd248X/fc4lGwDwP8/fXNoRtVBDR/3F/+WlaK9beFIyp5J4
  41. Fa2XHj5lOiCjLoJpzehE2Dguv+3xORJn10oGAHQhXxFjdWEt5xBBAgMBAAE=
  42. -----END RSA PUBLIC KEY-----"""
  43. mac = getMac()
  44. with open(os.path.dirname(__file__) + "/../licence", 'rb') as x:
  45. licence = x.read()
  46. d_rsa = Crypto.PublicKey.RSA.importKey(pub_key)
  47. verifer = Crypto.Signature.PKCS1_v1_5.new(d_rsa)
  48. msg_hash = Crypto.Hash.SHA256.new()
  49. msg_hash.update(mac.encode('utf-8'))
  50. return verifer.verify(msg_hash, base64.decodebytes(licence))