Guest User

Untitled

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