Guest User

Untitled

a guest
Oct 23rd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. """
  4. THIS SCRIPT IS USED FOR EDUCATIONAL PURPOSES ONLY. DO NOT USE IT IN ILLEGAL WAY!!!
  5. """
  6.  
  7. import base64
  8. from datetime import datetime
  9. from hashlib import sha1
  10. import zlib
  11. from M2Crypto import DSA
  12.  
  13.  
  14. def keymaker(organisation, server_id, license_edition, license_type_name, purchase_date=datetime.today(), private_key='./private.pem'):
  15. license_types = ('ACADEMIC', 'COMMERCIAL', 'COMMUNITY', 'DEMONSTRATION', 'DEVELOPER', 'NON_PROFIT', 'OPEN_SOURCE', 'PERSONAL', 'STARTER', 'HOSTED', 'TESTING')
  16. license_editions = ('BASIC', 'STANDARD', 'PROFESSIONAL', 'ENTERPRISE')
  17. if license_type_name not in license_types:
  18. raise ValueError('License Type Name must be one of the following values:\n\t%s' % ', '.join(license_types))
  19. if license_edition not in license_editions:
  20. raise ValueError('License Edition must be one of the following values:\n\t%s' % ', '.join(license_editions))
  21.  
  22. header = purchase_date.ctime()
  23. properties = {
  24. 'Description': 'JIRA\\: Developer',
  25. 'CreationDate': purchase_date.strftime('%Y-%m-%d'),
  26. 'jira.LicenseEdition': license_edition,
  27. 'Evaluation': 'false',
  28. 'jira.LicenseTypeName': license_type_name,
  29. 'jira.active': 'true',
  30. 'licenseVersion': '2',
  31. 'MaintenanceExpiryDate': '2099-12-31',
  32. 'Organisation': organisation,
  33. 'jira.NumberOfUsers': '-1',
  34. 'ServerID': server_id,
  35. 'SEN': 'SEN-L0000000',
  36. 'LicenseID': 'LIDSEN-L0000000',
  37. 'LicenseExpiryDate': '2099-12-31',
  38. 'PurchaseDate': purchase_date.strftime('%Y-%m-%d')
  39. }
  40. properties_text = '#%s\n%s' % (header, '\n'.join(['%s=%s' % (key, value) for key, value in properties.iteritems()]))
  41. compressed_properties_text = zlib.compress(properties_text, 9)
  42. license_text_prefix = map(chr, (13, 14, 12, 10, 15))
  43. license_text = ''.join(license_text_prefix + [compressed_properties_text])
  44.  
  45. dsa = DSA.load_key(private_key)
  46. assert dsa.check_key()
  47. license_signature = dsa.sign_asn1(sha1(license_text).digest())
  48. license_pair_base64 = base64.b64encode('%s%s%s' % (unichr(len(license_text)).encode('UTF-32BE'), license_text, license_signature))
  49. license_str = '%sX02%s' % (license_pair_base64, base_n(len(license_pair_base64), 31))
  50. return license_str
  51.  
  52.  
  53. def main():
  54. license_edition = 'ENTERPRISE'
  55. license_type_name = 'DEVELOPER'
  56. organisation = 'PUT YOUR ORGANIZATION NAME' # Change this to what you like
  57. server_id = 'ABCD-1234-EFGH-5678' # Change this to your server ID
  58. print keymaker(organisation, server_id, license_edition, license_type_name)
  59.  
  60.  
  61. def base_n(num, b, numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
  62. return ((num == 0) and "0") or (base_n(num // b, b).lstrip("0") + numerals[num % b])
  63.  
  64. if __name__ == '__main__':
  65. main()
Add Comment
Please, Sign In to add comment