Last active
August 29, 2015 14:13
-
-
Save thm1118/181774705203b7aafc7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| #!/usr/bin/env python | |
| """ | |
| THIS SCRIPT IS USED FOR EDUCATIONAL PURPOSES ONLY. DO NOT USE IT IN ILLEGAL WAY!!! | |
| """ | |
| import base64 | |
| from datetime import datetime | |
| from hashlib import sha1 | |
| import zlib | |
| from M2Crypto import DSA | |
| #stash pluckin Add-on key | |
| AddOnKeys = ['ch.mibex.stash.sonar4stash', 'nl.stefankohler.stash.stash-notification-plugin', 'com.stiltsoft.stash.graphs', | |
| 'com.simplenia.stash.plugins.snippets', 'org.tmatesoft.subgit.stash-svn-importer'] | |
| def getProperties(addOnKey, license_type_name, organisation, purchase_date): | |
| properties = {'NumberOfUsers': '-1', | |
| 'CreationDate': purchase_date.strftime('%Y-%m-%d'), | |
| 'Evaluation': 'false', | |
| 'licenseVersion': '2', | |
| 'MaintenanceExpiryDate': '2099-12-31', | |
| 'Organisation': organisation, | |
| 'SEN': 'SEN-L5116290', | |
| 'LicenseExpiryDate': '2099-12-31', | |
| 'LicenseTypeName': license_type_name, | |
| 'PurchaseDate': purchase_date.strftime('%Y-%m-%d'), | |
| 'Description': addOnKey.split('.')[-1] + ' for Stash for Stash (Server)\\: Developer', | |
| addOnKey + '.enterprise': 'true', | |
| addOnKey + '.active': 'true'} | |
| return properties | |
| def getCompressed_propertyies_text(addOnKey, license_edition, license_type_name, organisation, purchase_date): | |
| license_types = ('ACADEMIC', 'COMMERCIAL', 'COMMUNITY', 'DEMONSTRATION', 'DEVELOPER', 'NON_PROFIT', 'OPEN_SOURCE', 'PERSONAL', 'STARTER', 'HOSTED', 'TESTING') | |
| license_editions = ('BASIC', 'STANDARD', 'PROFESSIONAL', 'ENTERPRISE') | |
| if license_type_name not in license_types: | |
| raise ValueError('License Type Name must be one of the following values:\n\t%s' % ', '.join(license_types)) | |
| if license_edition not in license_editions: | |
| raise ValueError('License Edition must be one of the following values:\n\t%s' % ', '.join(license_editions)) | |
| header = purchase_date.ctime() | |
| properties = getProperties(addOnKey, license_type_name, organisation, purchase_date) | |
| properties_text = '#%s\n%s' % (header, '\n'.join(['%s=%s' % (key, value) for key, value in properties.iteritems()])) | |
| compressed_properties_text = zlib.compress(properties_text, 9) | |
| return compressed_properties_text | |
| def keymaker(compressed_properties_text, private_key='./atlassion_keys/myprivate.pem'): | |
| license_text_prefix = map(chr, (13, 14, 12, 10, 15)) | |
| license_text = ''.join(license_text_prefix + [compressed_properties_text]) | |
| dsa = DSA.load_key(private_key) | |
| assert dsa.check_key() | |
| license_signature = dsa.sign_asn1(sha1(license_text).digest()) | |
| license_pair_base64 = base64.b64encode('%s%s%s' % (unichr(len(license_text)).encode('UTF-32BE'), license_text, license_signature)) | |
| license_str = '%sX02%s' % (license_pair_base64, base_n(len(license_pair_base64), 31)) | |
| return license_str | |
| def main(): | |
| license_edition = 'ENTERPRISE' | |
| license_type_name = 'DEVELOPER' | |
| organisation = ' Change this to what you like' # Change this to what you like | |
| purchase_date = datetime.today() | |
| for addOnKey in AddOnKeys: | |
| compressed_properties_text = getCompressed_propertyies_text(addOnKey, license_edition, license_type_name, organisation, | |
| purchase_date) | |
| print addOnKey, ': ', keymaker(compressed_properties_text) | |
| def base_n(num, b, numerals="0123456789abcdefghijklmnopqrstuvwxyz"): | |
| return ((num == 0) and "0") or (base_n(num // b, b).lstrip("0") + numerals[num % b]) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment