78 lines
1.8 KiB
Python
Executable File
78 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import jwt
|
|
from Crypto.PublicKey import ECC
|
|
|
|
REPLACE_TEMPLATE = '''
|
|
from sys import argv
|
|
public_key = bytes.fromhex(
|
|
"67186ade9d222c21b1be112009b7c43676aab17f1b8796682f88c8636dceaf2f")
|
|
|
|
new_public_key = bytes.fromhex(
|
|
"<NEW_KEY>")
|
|
|
|
|
|
with open(argv[1], "rb") as f:
|
|
data = f.read()
|
|
|
|
assert public_key in data
|
|
|
|
with open(argv[1], "wb") as f:
|
|
f.write(data.replace(public_key, new_public_key))
|
|
|
|
'''
|
|
|
|
|
|
def create_ed25519_pair(is_save=False):
|
|
f = ECC.generate(curve="ed25519")
|
|
private_key = f.export_key(format="PEM") # 生成私钥
|
|
public_key = f.public_key().export_key(format="PEM") # 生成公钥
|
|
if is_save:
|
|
with open("private.pem", "w") as f:
|
|
f.write(private_key)
|
|
with open("public.pem", "w") as f:
|
|
f.write(public_key)
|
|
return public_key, private_key
|
|
|
|
|
|
data = {
|
|
"exp": 1706356587,
|
|
"nbf": 1674820527,
|
|
"iat": 1674820527,
|
|
"license_expires": 1706356587,
|
|
"account_type": "salesforce",
|
|
"account_id": "1234567890",
|
|
"trial": False,
|
|
"all_features": True,
|
|
"version": 3,
|
|
"features": {
|
|
"appearance": 1,
|
|
"audit_log": 1,
|
|
"browser_only": 1,
|
|
"external_provisioner_daemons": 1,
|
|
"high_availability": 1,
|
|
"multiple_git_auth": 1,
|
|
"scim": 1,
|
|
"template_rbac": 1,
|
|
"user_limit": 114514
|
|
}
|
|
}
|
|
|
|
public_key, private_key = create_ed25519_pair(is_save=True)
|
|
|
|
with open("private.pem", "rb") as f:
|
|
private_key = f.read()
|
|
|
|
with open("public.pem", "rb") as f:
|
|
public_key = f.read()
|
|
|
|
encoded = jwt.encode(data, private_key, algorithm="EdDSA", headers={
|
|
"kid": "2022-08-12",
|
|
})
|
|
|
|
with open("lic.txt", "w") as f:
|
|
f.write(encoded)
|
|
|
|
with open("replace.py", "w") as f:
|
|
f.write(REPLACE_TEMPLATE.replace("<NEW_KEY>", ECC.import_key(
|
|
public_key).export_key(format="raw").hex()))
|