licensing 0.40__tar.gz → 0.42__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {licensing-0.40 → licensing-0.42}/PKG-INFO +2 -2
- {licensing-0.40 → licensing-0.42}/licensing/internal.py +26 -4
- {licensing-0.40 → licensing-0.42}/licensing/methods.py +17 -3
- {licensing-0.40 → licensing-0.42}/licensing/models.py +16 -4
- {licensing-0.40 → licensing-0.42}/setup.py +2 -2
- {licensing-0.40 → licensing-0.42}/licensing/__init__.py +0 -0
- {licensing-0.40 → licensing-0.42}/setup.cfg +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 1.1
|
|
2
2
|
Name: licensing
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.42
|
|
4
4
|
Summary: Client library for Cryptolens licensing Web API.
|
|
5
5
|
Home-page: https://cryptolens.io
|
|
6
6
|
Author: Cryptolens AB
|
|
7
7
|
Author-email: support@cryptolens.io
|
|
8
8
|
License: MIT
|
|
9
|
-
Download-URL: https://github.com/Cryptolens/cryptolens-python/archive/
|
|
9
|
+
Download-URL: https://github.com/Cryptolens/cryptolens-python/archive/v_42.tar.gz
|
|
10
10
|
Description: UNKNOWN
|
|
11
11
|
Keywords: software licensing,licensing library,cryptolens
|
|
12
12
|
Platform: UNKNOWN
|
|
@@ -70,28 +70,33 @@ class HelperMethods:
|
|
|
70
70
|
return pow(s, e, n)
|
|
71
71
|
|
|
72
72
|
@staticmethod
|
|
73
|
-
def EMSA_PKCS1_V15_ENCODE(M, emLen):
|
|
73
|
+
def EMSA_PKCS1_V15_ENCODE(M, emLen, hlen = 256):
|
|
74
74
|
import hashlib
|
|
75
75
|
h = hashlib.sha256()
|
|
76
|
+
if hlen == 512:
|
|
77
|
+
h = hashlib.sha512()
|
|
76
78
|
h.update(M)
|
|
77
79
|
H = h.digest()
|
|
78
80
|
|
|
79
81
|
T = bytes([0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20]) + H
|
|
82
|
+
if hlen == 512:
|
|
83
|
+
T = bytes([0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40]) + H
|
|
84
|
+
|
|
80
85
|
tLen = len(T)
|
|
81
86
|
if emLen < tLen + 11:
|
|
82
87
|
return None
|
|
83
88
|
PS = bytes([0xff for _ in range(emLen - tLen - 3)])
|
|
84
89
|
return b"".join([b"\x00\x01", PS, b"\x00", T])
|
|
85
|
-
|
|
90
|
+
|
|
86
91
|
@staticmethod
|
|
87
|
-
def RSAASSA_PKCS1_V15_VERIFY(pair, M, S):
|
|
92
|
+
def RSAASSA_PKCS1_V15_VERIFY(pair, M, S, l=256):
|
|
88
93
|
n, e = pair
|
|
89
94
|
s = HelperMethods.OS2IP(S)
|
|
90
95
|
m = HelperMethods.RSAVP1((n,e), s)
|
|
91
96
|
if m is None: return False
|
|
92
97
|
EM = HelperMethods.I2OSP(m, 256)
|
|
93
98
|
if EM is None: return False
|
|
94
|
-
EM2 = HelperMethods.EMSA_PKCS1_V15_ENCODE(M, 256)
|
|
99
|
+
EM2 = HelperMethods.EMSA_PKCS1_V15_ENCODE(M, 256, l)
|
|
95
100
|
if EM2 is None: return False
|
|
96
101
|
|
|
97
102
|
try:
|
|
@@ -114,6 +119,23 @@ class HelperMethods:
|
|
|
114
119
|
|
|
115
120
|
return HelperMethods.RSAASSA_PKCS1_V15_VERIFY((n,e), m, r)
|
|
116
121
|
|
|
122
|
+
@staticmethod
|
|
123
|
+
def verify_signature_metadata(signature, rsaPublicKey):
|
|
124
|
+
|
|
125
|
+
import base64
|
|
126
|
+
import json
|
|
127
|
+
|
|
128
|
+
n = HelperMethods.OS2IP(base64.b64decode(rsaPublicKey.modulus))
|
|
129
|
+
e = HelperMethods.OS2IP(base64.b64decode(rsaPublicKey.exponent))
|
|
130
|
+
|
|
131
|
+
data = json.loads(base64.b64decode(signature))
|
|
132
|
+
|
|
133
|
+
d = base64.b64decode(data["Data"])
|
|
134
|
+
s = base64.b64decode(data["Signature"])
|
|
135
|
+
|
|
136
|
+
return [HelperMethods.RSAASSA_PKCS1_V15_VERIFY((n,e), d,s, l=512), d]
|
|
137
|
+
|
|
138
|
+
|
|
117
139
|
@staticmethod
|
|
118
140
|
def int2base64(num):
|
|
119
141
|
return base64.b64encode(int.to_bytes(num), byteorder='big')
|
|
@@ -61,11 +61,25 @@ class Key:
|
|
|
61
61
|
else:
|
|
62
62
|
try:
|
|
63
63
|
if HelperMethods.verify_signature(response, pubkey):
|
|
64
|
-
|
|
64
|
+
if metadata:
|
|
65
|
+
|
|
66
|
+
try:
|
|
67
|
+
metadata_s = HelperMethods.verify_signature_metadata(response.metadata["signature"], pubkey)
|
|
68
|
+
|
|
69
|
+
if metadata_s[0]:
|
|
70
|
+
return (LicenseKey.from_response(response), response.message, json.loads(metadata_s[1]))
|
|
71
|
+
else:
|
|
72
|
+
return (LicenseKey.from_response(response), response.message, "Signature check for metadata object failed.")
|
|
73
|
+
except:
|
|
74
|
+
return (LicenseKey.from_response(response), response.message, "Signature check for metadata object failed.")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
else:
|
|
78
|
+
return (LicenseKey.from_response(response), response.message)
|
|
65
79
|
else:
|
|
66
80
|
return (None, "The signature check failed.")
|
|
67
|
-
except Exception:
|
|
68
|
-
return (None, "
|
|
81
|
+
except Exception as ex:
|
|
82
|
+
return (None, "An error occured: {0}".format(ex))
|
|
69
83
|
|
|
70
84
|
@staticmethod
|
|
71
85
|
def get_key(token, rsa_pub_key, product_id, key, fields_to_return = 0,\
|
|
@@ -78,7 +78,7 @@ class LicenseKey:
|
|
|
78
78
|
@staticmethod
|
|
79
79
|
def from_response(response):
|
|
80
80
|
|
|
81
|
-
if response.result ==
|
|
81
|
+
if response.result == 1:
|
|
82
82
|
raise ValueError("The response did not contain any license key object since it was unsuccessful. Message '{0}'.".format(response.message))
|
|
83
83
|
|
|
84
84
|
obj = json.loads(base64.b64decode(response.license_key).decode('utf-8'))
|
|
@@ -87,7 +87,12 @@ class LicenseKey:
|
|
|
87
87
|
|
|
88
88
|
if "Reseller" in obj and obj["Reseller"] != None:
|
|
89
89
|
reseller = Reseller(**obj["Reseller"])
|
|
90
|
-
|
|
90
|
+
|
|
91
|
+
try:
|
|
92
|
+
datetime.datetime.fromtimestamp(obj["Expires"])
|
|
93
|
+
except:
|
|
94
|
+
raise ValueError("The expiration date cannot be converted to a datetime object. Please try setting the period to a lower value. Read more: https://github.com/Cryptolens/cryptolens-python/tree/master#the-expiration-date-cannot-be-converted-to-a-datetime-object-please-try-setting-the-period-to-a-lower-value")
|
|
95
|
+
|
|
91
96
|
return LicenseKey(obj["ProductId"], obj["ID"], obj["Key"], datetime.datetime.fromtimestamp(obj["Created"]),\
|
|
92
97
|
datetime.datetime.fromtimestamp(obj["Expires"]), obj["Period"], obj["F1"], obj["F2"], \
|
|
93
98
|
obj["F3"], obj["F4"],obj["F5"],obj["F6"], obj["F7"], \
|
|
@@ -159,11 +164,12 @@ class LicenseKey:
|
|
|
159
164
|
|
|
160
165
|
class Response:
|
|
161
166
|
|
|
162
|
-
def __init__(self, license_key, signature, result, message):
|
|
167
|
+
def __init__(self, license_key, signature, result, message, metadata=None):
|
|
163
168
|
self.license_key = license_key
|
|
164
169
|
self.signature = signature
|
|
165
170
|
self.result = result
|
|
166
171
|
self.message = message
|
|
172
|
+
self.metadata = metadata
|
|
167
173
|
|
|
168
174
|
@staticmethod
|
|
169
175
|
def from_string(responseString):
|
|
@@ -173,6 +179,7 @@ class Response:
|
|
|
173
179
|
signature = ""
|
|
174
180
|
result = 0
|
|
175
181
|
message = ""
|
|
182
|
+
metadata = None
|
|
176
183
|
|
|
177
184
|
if "licensekey" in obj:
|
|
178
185
|
licenseKey = obj["licensekey"]
|
|
@@ -187,8 +194,13 @@ class Response:
|
|
|
187
194
|
result = obj["result"]
|
|
188
195
|
else:
|
|
189
196
|
result = 1
|
|
197
|
+
|
|
198
|
+
if "metadata" in obj:
|
|
199
|
+
metadata = obj["metadata"]
|
|
200
|
+
|
|
201
|
+
|
|
190
202
|
|
|
191
|
-
return Response(licenseKey, signature, result, message)
|
|
203
|
+
return Response(licenseKey, signature, result, message, metadata)
|
|
192
204
|
|
|
193
205
|
class RSAPublicKey:
|
|
194
206
|
|
|
@@ -2,13 +2,13 @@ from distutils.core import setup
|
|
|
2
2
|
setup(
|
|
3
3
|
name = 'licensing', # How you named your package folder (MyLib)
|
|
4
4
|
packages = ['licensing'], # Chose the same as "name"
|
|
5
|
-
version = '0.
|
|
5
|
+
version = '0.42', # Start with a small number and increase it with every change you make
|
|
6
6
|
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
|
|
7
7
|
description = 'Client library for Cryptolens licensing Web API.', # Give a short description about your library
|
|
8
8
|
author = 'Cryptolens AB', # Type in your name
|
|
9
9
|
author_email = 'support@cryptolens.io', # Type in your E-Mail
|
|
10
10
|
url = 'https://cryptolens.io', # Provide either the link to your github or to your website
|
|
11
|
-
download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/
|
|
11
|
+
download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/v_42.tar.gz', # I explain this later on
|
|
12
12
|
keywords = ['software licensing', 'licensing library', 'cryptolens'], # Keywords that define your package best
|
|
13
13
|
classifiers=[
|
|
14
14
|
#'Development Status :: 5 - Stable', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
|
|
File without changes
|
|
File without changes
|