fork download
  1. import argparse
  2. import base64
  3. import binascii
  4. import zlib
  5. import hmac
  6. import hashlib
  7. import struct
  8. from Crypto.Cipher import AES
  9.  
  10.  
  11. # obtain values from /usr/local/lib/libfts_license.so.1.12.1
  12. # Note that in python, you enter binary hex values as b"\x0d\x0e..."
  13. HMAC_KEY = b""
  14. HMAC_MSG = b"" * 4
  15. AES_IV = b""
  16.  
  17.  
  18. def init_lookup_table():
  19. out = []
  20. for i in range(0x100):
  21. lookup_table_entry = i << 0x18
  22. for k in range(8):
  23. if lookup_table_entry >> 31:
  24. inlr = lookup_table_entry << 1
  25. if lookup_table_entry >> 31:
  26. lookup_table_entry = inlr ^ 0x4c11db7
  27. else:
  28. lookup_table_entry = lookup_table_entry << 1
  29. lookup_table_entry &= 0xffffffff
  30. out.append(lookup_table_entry)
  31. return out
  32.  
  33.  
  34. def spd_crc32(param_1, x):
  35. tbl = init_lookup_table()
  36. for pbVar1 in param_1:
  37. x = (tbl[(pbVar1 ^ x >> 0x18) & 0xff] ^ x << 8) & 0xffffffff
  38. return x
  39.  
  40.  
  41. def simple_generator(ext_features, type, serial):
  42. if ext_features.lower() == "kvm":
  43. features = b"\x01\x00\x00\x00"
  44. elif ext_features.lower() == "kvm_media":
  45. features = b"\x03\x00\x00\x00"
  46. elif ext_features.lower() == "kvm_media_elcm":
  47. # this license type doesn't validate on my TX chassis
  48. # but apparently works on RX chassis
  49. if type.lower() == "tx":
  50. print("License may not be valid for TX chassis with eLCM enabled")
  51. features = b"\x0f\x00\x00\x00"
  52. return license_generator(serial, features, type.lower())
  53.  
  54.  
  55. def license_generator(serial, features, type):
  56. # chassis type TX
  57. struct_data = 0xffffff00
  58. if type == "rx":
  59. # chassis type RX
  60. struct_data = 0xffffff05
  61. DATA = b'iRMC' \
  62. + features \
  63. + struct.pack('>I', struct_data) + \
  64. struct.pack('<I', spd_crc32(serial.encode("ASCII"), 1))
  65. print(binascii.hexlify(DATA).decode('utf-8'))
  66.  
  67. aes_key = hmac.new(HMAC_KEY, HMAC_MSG, hashlib.sha1).digest()
  68. # this is AES-128, so only take the first 16 bytes of the aes_key
  69. cipher = AES.new(aes_key[:16], AES.MODE_CBC, iv=AES_IV)
  70. encrypted_license = cipher.encrypt(DATA)
  71. encoded_license = base64.b32encode(encrypted_license)
  72. license = encoded_license.decode("UTF-8").replace("=","")
  73. return '-'.join(license[i:i+4] for i in range(0, len(license), 4))
  74.  
  75.  
  76. if __name__ == "__main__":
  77. if len(HMAC_KEY) != 16 or len(HMAC_MSG) != 16*4 or len(AES_IV) != 16:
  78. print("You are missing the HMAC and AES values")
  79. else:
  80. print(simple_generator("kvm_media", "rx", "YV3R002727"))
Success #stdin #stdout 0.04s 10572KB
stdin
Standard input is empty
stdout
You are missing the HMAC and AES values