Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
444
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def keymaker(organisation, server_id, license_edition, license_type_name, purchase_date=datetime.today(), private_key='./private.pem'):
  2. license_types = ('ACADEMIC', 'COMMERCIAL', 'COMMUNITY', 'DEMONSTRATION', 'DEVELOPER', 'NON_PROFIT', 'OPEN_SOURCE', 'PERSONAL', 'STARTER', 'HOSTED', 'TESTING')
  3. license_editions = ('BASIC', 'STANDARD', 'PROFESSIONAL', 'ENTERPRISE')
  4. if license_type_name not in license_types:
  5. raise ValueError('License Type Name must be one of the following values:\n\t%s' % ', '.join(license_types))
  6. if license_edition not in license_editions:
  7. raise ValueError('License Edition must be one of the following values:\n\t%s' % ', '.join(license_editions))
  8. header = purchase_date.ctime()
  9. properties = {
  10. 'Description': 'XXXX\\: Developer',
  11. 'CreationDate': purchase_date.strftime('%Y-%m-%d'),
  12. 'jira.LicenseEdition': license_edition,
  13. 'Evaluation': 'false',
  14. 'jira.LicenseTypeName': license_type_name,
  15. 'jira.active': 'true',
  16. 'licenseVersion': '2',
  17. 'MaintenanceExpiryDate': '2099-12-31',
  18. 'Organisation': organisation,
  19. 'jira.NumberOfUsers': '-1',
  20. 'ServerID': server_id,
  21. 'SEN': 'SEN-L0000000',
  22. 'LicenseID': 'LIDSEN-L0000000',
  23. 'LicenseExpiryDate': '2099-12-31',
  24. 'PurchaseDate': purchase_date.strftime('%Y-%m-%d')
  25. }
  26. properties_text = '#%s\n%s' % (header, '\n'.join(['%s=%s' % (key, value) for key, value in properties.iteritems()]))
  27. compressed_properties_text = zlib.compress(properties_text, 9)
  28. license_text_prefix = map(chr, (13, 14, 12, 10, 15))
  29. license_text = ''.join(license_text_prefix + [compressed_properties_text])
  30. dsa = DSA.load_key(private_key)
  31. assert dsa.check_key()
  32. license_signature = dsa.sign_asn1(sha1(license_text).digest())
  33. license_pair_base64 = base64.b64encode('%s%s%s' % (unichr(len(license_text)).encode('UTF-32BE'), license_text, license_signature))
  34. license_str = '%sX02%s' % (license_pair_base64, base_n(len(license_pair_base64), 31))
  35. return license_str
Advertisement
RAW Paste Data Copied
Advertisement