licensing 0.45__tar.gz → 0.47__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.45 → licensing-0.47}/PKG-INFO +19 -19
- {licensing-0.45 → licensing-0.47}/licensing/internal.py +240 -240
- {licensing-0.45 → licensing-0.47}/licensing/methods.py +1557 -1551
- {licensing-0.45 → licensing-0.47}/licensing/models.py +219 -219
- {licensing-0.45 → licensing-0.47}/setup.cfg +2 -2
- {licensing-0.45 → licensing-0.47}/setup.py +22 -22
- {licensing-0.45 → licensing-0.47}/licensing/__init__.py +0 -0
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
Metadata-Version: 1.1
|
|
2
|
-
Name: licensing
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Client library for Cryptolens licensing Web API.
|
|
5
|
-
Home-page: https://cryptolens.io
|
|
6
|
-
Author: Cryptolens AB
|
|
7
|
-
Author-email: support@cryptolens.io
|
|
8
|
-
License: MIT
|
|
9
|
-
Download-URL: https://github.com/Cryptolens/cryptolens-python/archive/
|
|
10
|
-
Description: UNKNOWN
|
|
11
|
-
Keywords: software licensing,licensing library,cryptolens
|
|
12
|
-
Platform: UNKNOWN
|
|
13
|
-
Classifier: Intended Audience :: Developers
|
|
14
|
-
Classifier: Topic :: Software Development :: Build Tools
|
|
15
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
-
Classifier: Programming Language :: Python :: 3
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.4
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.5
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
1
|
+
Metadata-Version: 1.1
|
|
2
|
+
Name: licensing
|
|
3
|
+
Version: 0.47
|
|
4
|
+
Summary: Client library for Cryptolens licensing Web API.
|
|
5
|
+
Home-page: https://cryptolens.io
|
|
6
|
+
Author: Cryptolens AB
|
|
7
|
+
Author-email: support@cryptolens.io
|
|
8
|
+
License: MIT
|
|
9
|
+
Download-URL: https://github.com/Cryptolens/cryptolens-python/archive/v_47.tar.gz
|
|
10
|
+
Description: UNKNOWN
|
|
11
|
+
Keywords: software licensing,licensing library,cryptolens
|
|
12
|
+
Platform: UNKNOWN
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.4
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.5
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
@@ -1,240 +1,240 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
Created on Wed Jan 23 10:12:13 2019
|
|
4
|
-
|
|
5
|
-
@author: Artem Los
|
|
6
|
-
"""
|
|
7
|
-
import base64
|
|
8
|
-
import urllib.request
|
|
9
|
-
import hashlib
|
|
10
|
-
import subprocess
|
|
11
|
-
import os, os.path
|
|
12
|
-
import ssl
|
|
13
|
-
|
|
14
|
-
def subprocess_args(include_stdout=True):
|
|
15
|
-
if hasattr(subprocess, 'STARTUPINFO'):
|
|
16
|
-
si = subprocess.STARTUPINFO()
|
|
17
|
-
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
|
18
|
-
env = os.environ
|
|
19
|
-
else:
|
|
20
|
-
si = None
|
|
21
|
-
env = None
|
|
22
|
-
|
|
23
|
-
if include_stdout:
|
|
24
|
-
ret = {'stdout': subprocess.PIPE}
|
|
25
|
-
else:
|
|
26
|
-
ret = {}
|
|
27
|
-
|
|
28
|
-
ret.update({'stdin': subprocess.PIPE,
|
|
29
|
-
'stderr': subprocess.PIPE,
|
|
30
|
-
'startupinfo': si,
|
|
31
|
-
'env': env })
|
|
32
|
-
return ret
|
|
33
|
-
|
|
34
|
-
class HelperMethods:
|
|
35
|
-
|
|
36
|
-
server_address = "https://api.cryptolens.io/api/"
|
|
37
|
-
|
|
38
|
-
verify_SSL = True
|
|
39
|
-
|
|
40
|
-
proxy_experimental = False
|
|
41
|
-
|
|
42
|
-
@staticmethod
|
|
43
|
-
def get_SHA256(string):
|
|
44
|
-
"""
|
|
45
|
-
Compute the SHA256 signature of a string.
|
|
46
|
-
"""
|
|
47
|
-
return hashlib.sha256(string.encode("utf-8")).hexdigest()
|
|
48
|
-
|
|
49
|
-
@staticmethod
|
|
50
|
-
def I2OSP(x, xLen):
|
|
51
|
-
if x > (1 << (8 * xLen)):
|
|
52
|
-
return None
|
|
53
|
-
Xrev = []
|
|
54
|
-
for _ in range(0, xLen):
|
|
55
|
-
x, m = divmod(x, 256)
|
|
56
|
-
Xrev.append(m)
|
|
57
|
-
return bytes(reversed(Xrev))
|
|
58
|
-
|
|
59
|
-
@staticmethod
|
|
60
|
-
def OS2IP(X):
|
|
61
|
-
import binascii
|
|
62
|
-
h = binascii.hexlify(X)
|
|
63
|
-
return int(h, 16)
|
|
64
|
-
|
|
65
|
-
@staticmethod
|
|
66
|
-
def RSAVP1(pair, s):
|
|
67
|
-
n, e = pair
|
|
68
|
-
if s < 0 or n-1 < s:
|
|
69
|
-
return None
|
|
70
|
-
return pow(s, e, n)
|
|
71
|
-
|
|
72
|
-
@staticmethod
|
|
73
|
-
def EMSA_PKCS1_V15_ENCODE(M, emLen, hlen = 256):
|
|
74
|
-
import hashlib
|
|
75
|
-
h = hashlib.sha256()
|
|
76
|
-
if hlen == 512:
|
|
77
|
-
h = hashlib.sha512()
|
|
78
|
-
h.update(M)
|
|
79
|
-
H = h.digest()
|
|
80
|
-
|
|
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
|
-
|
|
85
|
-
tLen = len(T)
|
|
86
|
-
if emLen < tLen + 11:
|
|
87
|
-
return None
|
|
88
|
-
PS = bytes([0xff for _ in range(emLen - tLen - 3)])
|
|
89
|
-
return b"".join([b"\x00\x01", PS, b"\x00", T])
|
|
90
|
-
|
|
91
|
-
@staticmethod
|
|
92
|
-
def RSAASSA_PKCS1_V15_VERIFY(pair, M, S, l=256):
|
|
93
|
-
n, e = pair
|
|
94
|
-
s = HelperMethods.OS2IP(S)
|
|
95
|
-
m = HelperMethods.RSAVP1((n,e), s)
|
|
96
|
-
if m is None: return False
|
|
97
|
-
EM = HelperMethods.I2OSP(m, 256)
|
|
98
|
-
if EM is None: return False
|
|
99
|
-
EM2 = HelperMethods.EMSA_PKCS1_V15_ENCODE(M, 256, l)
|
|
100
|
-
if EM2 is None: return False
|
|
101
|
-
|
|
102
|
-
try:
|
|
103
|
-
import hmac
|
|
104
|
-
return hmac.compare_digest(EM, EM2)
|
|
105
|
-
except (ImportError, AttributeError):
|
|
106
|
-
return EM == EM2
|
|
107
|
-
|
|
108
|
-
@staticmethod
|
|
109
|
-
def verify_signature(response, rsaPublicKey):
|
|
110
|
-
"""
|
|
111
|
-
Verifies a signature from .NET RSACryptoServiceProvider.
|
|
112
|
-
"""
|
|
113
|
-
|
|
114
|
-
n = HelperMethods.OS2IP(base64.b64decode(rsaPublicKey.modulus))
|
|
115
|
-
e = HelperMethods.OS2IP(base64.b64decode(rsaPublicKey.exponent))
|
|
116
|
-
|
|
117
|
-
m = base64.b64decode(response.license_key)
|
|
118
|
-
r = base64.b64decode(response.signature)
|
|
119
|
-
|
|
120
|
-
return HelperMethods.RSAASSA_PKCS1_V15_VERIFY((n,e), m, r)
|
|
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
|
-
|
|
139
|
-
@staticmethod
|
|
140
|
-
def int2base64(num):
|
|
141
|
-
return base64.b64encode(int.to_bytes(num), byteorder='big')
|
|
142
|
-
|
|
143
|
-
@staticmethod
|
|
144
|
-
def base642int(string):
|
|
145
|
-
return int.from_bytes(base64.b64decode((string)), byteorder='big')
|
|
146
|
-
|
|
147
|
-
@staticmethod
|
|
148
|
-
def send_request(method, params):
|
|
149
|
-
"""
|
|
150
|
-
Send a POST request to method in the Web API with the specified
|
|
151
|
-
params and return the response string.
|
|
152
|
-
|
|
153
|
-
method: the path of the method, eg. key/activate
|
|
154
|
-
params: a dictionary of parameters
|
|
155
|
-
"""
|
|
156
|
-
|
|
157
|
-
if HelperMethods.verify_SSL:
|
|
158
|
-
req = urllib.request.Request(HelperMethods.server_address + method, \
|
|
159
|
-
urllib.parse.urlencode(params)\
|
|
160
|
-
.encode("utf-8"))
|
|
161
|
-
|
|
162
|
-
if HelperMethods.proxy_experimental == True:
|
|
163
|
-
proxies = urllib.request.getproxies()
|
|
164
|
-
if proxies != {}:
|
|
165
|
-
|
|
166
|
-
if 'http' in proxies:
|
|
167
|
-
req.set_proxy(proxies['http'], 'http')
|
|
168
|
-
|
|
169
|
-
if 'https' in proxies:
|
|
170
|
-
req.set_proxy(proxies['https'], 'https')
|
|
171
|
-
|
|
172
|
-
else:
|
|
173
|
-
return urllib.request.urlopen(req).read().decode("utf-8")
|
|
174
|
-
|
|
175
|
-
else:
|
|
176
|
-
ctx = ssl.create_default_context()
|
|
177
|
-
ctx.check_hostname = False
|
|
178
|
-
ctx.verify_mode = ssl.CERT_NONE
|
|
179
|
-
|
|
180
|
-
return urllib.request.urlopen(HelperMethods.server_address + method, \
|
|
181
|
-
urllib.parse.urlencode(params)\
|
|
182
|
-
.encode("utf-8"), context=ctx).read().decode("utf-8")
|
|
183
|
-
|
|
184
|
-
@staticmethod
|
|
185
|
-
def start_process_ps_v2():
|
|
186
|
-
ps_args = "-Command (Get-CimInstance -Class Win32_ComputerSystemProduct).UUID"
|
|
187
|
-
|
|
188
|
-
cmd = ["powershell", *ps_args.split(" ")]
|
|
189
|
-
|
|
190
|
-
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
|
191
|
-
out, err = proc.communicate(timeout=120)
|
|
192
|
-
|
|
193
|
-
rawOutput = out.decode('utf-8').strip()
|
|
194
|
-
return rawOutput
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
@staticmethod
|
|
198
|
-
def start_process(command, v = 1):
|
|
199
|
-
|
|
200
|
-
output = subprocess.check_output(command,
|
|
201
|
-
**subprocess_args(False))
|
|
202
|
-
|
|
203
|
-
if v == 1:
|
|
204
|
-
return output.decode('utf-8')
|
|
205
|
-
elif v == 2:
|
|
206
|
-
rawOutput = output.decode('utf-8')
|
|
207
|
-
return rawOutput[rawOutput.index("UUID")+4:].strip()
|
|
208
|
-
else:
|
|
209
|
-
raise ValueError("Version can be either 1 or 2.")
|
|
210
|
-
|
|
211
|
-
@staticmethod
|
|
212
|
-
def get_dbus_machine_id():
|
|
213
|
-
try:
|
|
214
|
-
with open("/etc/machine-id") as f:
|
|
215
|
-
return f.read().strip()
|
|
216
|
-
except:
|
|
217
|
-
pass
|
|
218
|
-
try:
|
|
219
|
-
with open("/var/lib/dbus/machine-id") as f:
|
|
220
|
-
return f.read().strip()
|
|
221
|
-
except:
|
|
222
|
-
pass
|
|
223
|
-
return ""
|
|
224
|
-
|
|
225
|
-
@staticmethod
|
|
226
|
-
def get_inodes():
|
|
227
|
-
import os
|
|
228
|
-
files = ["/bin", "/etc", "/lib", "/root", "/sbin", "/usr", "/var"]
|
|
229
|
-
inodes = []
|
|
230
|
-
for file in files:
|
|
231
|
-
try:
|
|
232
|
-
inodes.append(os.stat(file).st_ino)
|
|
233
|
-
except:
|
|
234
|
-
pass
|
|
235
|
-
return "".join([str(x) for x in inodes])
|
|
236
|
-
|
|
237
|
-
@staticmethod
|
|
238
|
-
def compute_machine_code():
|
|
239
|
-
return HelperMethods.get_dbus_machine_id() + HelperMethods.get_inodes()
|
|
240
|
-
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Created on Wed Jan 23 10:12:13 2019
|
|
4
|
+
|
|
5
|
+
@author: Artem Los
|
|
6
|
+
"""
|
|
7
|
+
import base64
|
|
8
|
+
import urllib.request
|
|
9
|
+
import hashlib
|
|
10
|
+
import subprocess
|
|
11
|
+
import os, os.path
|
|
12
|
+
import ssl
|
|
13
|
+
|
|
14
|
+
def subprocess_args(include_stdout=True):
|
|
15
|
+
if hasattr(subprocess, 'STARTUPINFO'):
|
|
16
|
+
si = subprocess.STARTUPINFO()
|
|
17
|
+
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
|
18
|
+
env = os.environ
|
|
19
|
+
else:
|
|
20
|
+
si = None
|
|
21
|
+
env = None
|
|
22
|
+
|
|
23
|
+
if include_stdout:
|
|
24
|
+
ret = {'stdout': subprocess.PIPE}
|
|
25
|
+
else:
|
|
26
|
+
ret = {}
|
|
27
|
+
|
|
28
|
+
ret.update({'stdin': subprocess.PIPE,
|
|
29
|
+
'stderr': subprocess.PIPE,
|
|
30
|
+
'startupinfo': si,
|
|
31
|
+
'env': env })
|
|
32
|
+
return ret
|
|
33
|
+
|
|
34
|
+
class HelperMethods:
|
|
35
|
+
|
|
36
|
+
server_address = "https://api.cryptolens.io/api/"
|
|
37
|
+
|
|
38
|
+
verify_SSL = True
|
|
39
|
+
|
|
40
|
+
proxy_experimental = False
|
|
41
|
+
|
|
42
|
+
@staticmethod
|
|
43
|
+
def get_SHA256(string):
|
|
44
|
+
"""
|
|
45
|
+
Compute the SHA256 signature of a string.
|
|
46
|
+
"""
|
|
47
|
+
return hashlib.sha256(string.encode("utf-8")).hexdigest()
|
|
48
|
+
|
|
49
|
+
@staticmethod
|
|
50
|
+
def I2OSP(x, xLen):
|
|
51
|
+
if x > (1 << (8 * xLen)):
|
|
52
|
+
return None
|
|
53
|
+
Xrev = []
|
|
54
|
+
for _ in range(0, xLen):
|
|
55
|
+
x, m = divmod(x, 256)
|
|
56
|
+
Xrev.append(m)
|
|
57
|
+
return bytes(reversed(Xrev))
|
|
58
|
+
|
|
59
|
+
@staticmethod
|
|
60
|
+
def OS2IP(X):
|
|
61
|
+
import binascii
|
|
62
|
+
h = binascii.hexlify(X)
|
|
63
|
+
return int(h, 16)
|
|
64
|
+
|
|
65
|
+
@staticmethod
|
|
66
|
+
def RSAVP1(pair, s):
|
|
67
|
+
n, e = pair
|
|
68
|
+
if s < 0 or n-1 < s:
|
|
69
|
+
return None
|
|
70
|
+
return pow(s, e, n)
|
|
71
|
+
|
|
72
|
+
@staticmethod
|
|
73
|
+
def EMSA_PKCS1_V15_ENCODE(M, emLen, hlen = 256):
|
|
74
|
+
import hashlib
|
|
75
|
+
h = hashlib.sha256()
|
|
76
|
+
if hlen == 512:
|
|
77
|
+
h = hashlib.sha512()
|
|
78
|
+
h.update(M)
|
|
79
|
+
H = h.digest()
|
|
80
|
+
|
|
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
|
+
|
|
85
|
+
tLen = len(T)
|
|
86
|
+
if emLen < tLen + 11:
|
|
87
|
+
return None
|
|
88
|
+
PS = bytes([0xff for _ in range(emLen - tLen - 3)])
|
|
89
|
+
return b"".join([b"\x00\x01", PS, b"\x00", T])
|
|
90
|
+
|
|
91
|
+
@staticmethod
|
|
92
|
+
def RSAASSA_PKCS1_V15_VERIFY(pair, M, S, l=256):
|
|
93
|
+
n, e = pair
|
|
94
|
+
s = HelperMethods.OS2IP(S)
|
|
95
|
+
m = HelperMethods.RSAVP1((n,e), s)
|
|
96
|
+
if m is None: return False
|
|
97
|
+
EM = HelperMethods.I2OSP(m, 256)
|
|
98
|
+
if EM is None: return False
|
|
99
|
+
EM2 = HelperMethods.EMSA_PKCS1_V15_ENCODE(M, 256, l)
|
|
100
|
+
if EM2 is None: return False
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
import hmac
|
|
104
|
+
return hmac.compare_digest(EM, EM2)
|
|
105
|
+
except (ImportError, AttributeError):
|
|
106
|
+
return EM == EM2
|
|
107
|
+
|
|
108
|
+
@staticmethod
|
|
109
|
+
def verify_signature(response, rsaPublicKey):
|
|
110
|
+
"""
|
|
111
|
+
Verifies a signature from .NET RSACryptoServiceProvider.
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
n = HelperMethods.OS2IP(base64.b64decode(rsaPublicKey.modulus))
|
|
115
|
+
e = HelperMethods.OS2IP(base64.b64decode(rsaPublicKey.exponent))
|
|
116
|
+
|
|
117
|
+
m = base64.b64decode(response.license_key)
|
|
118
|
+
r = base64.b64decode(response.signature)
|
|
119
|
+
|
|
120
|
+
return HelperMethods.RSAASSA_PKCS1_V15_VERIFY((n,e), m, r)
|
|
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
|
+
|
|
139
|
+
@staticmethod
|
|
140
|
+
def int2base64(num):
|
|
141
|
+
return base64.b64encode(int.to_bytes(num), byteorder='big')
|
|
142
|
+
|
|
143
|
+
@staticmethod
|
|
144
|
+
def base642int(string):
|
|
145
|
+
return int.from_bytes(base64.b64decode((string)), byteorder='big')
|
|
146
|
+
|
|
147
|
+
@staticmethod
|
|
148
|
+
def send_request(method, params):
|
|
149
|
+
"""
|
|
150
|
+
Send a POST request to method in the Web API with the specified
|
|
151
|
+
params and return the response string.
|
|
152
|
+
|
|
153
|
+
method: the path of the method, eg. key/activate
|
|
154
|
+
params: a dictionary of parameters
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
if HelperMethods.verify_SSL:
|
|
158
|
+
req = urllib.request.Request(HelperMethods.server_address + method, \
|
|
159
|
+
urllib.parse.urlencode(params)\
|
|
160
|
+
.encode("utf-8"))
|
|
161
|
+
|
|
162
|
+
if HelperMethods.proxy_experimental == True:
|
|
163
|
+
proxies = urllib.request.getproxies()
|
|
164
|
+
if proxies != {}:
|
|
165
|
+
|
|
166
|
+
if 'http' in proxies:
|
|
167
|
+
req.set_proxy(proxies['http'], 'http')
|
|
168
|
+
|
|
169
|
+
if 'https' in proxies:
|
|
170
|
+
req.set_proxy(proxies['https'], 'https')
|
|
171
|
+
|
|
172
|
+
else:
|
|
173
|
+
return urllib.request.urlopen(req).read().decode("utf-8")
|
|
174
|
+
|
|
175
|
+
else:
|
|
176
|
+
ctx = ssl.create_default_context()
|
|
177
|
+
ctx.check_hostname = False
|
|
178
|
+
ctx.verify_mode = ssl.CERT_NONE
|
|
179
|
+
|
|
180
|
+
return urllib.request.urlopen(HelperMethods.server_address + method, \
|
|
181
|
+
urllib.parse.urlencode(params)\
|
|
182
|
+
.encode("utf-8"), context=ctx).read().decode("utf-8")
|
|
183
|
+
|
|
184
|
+
@staticmethod
|
|
185
|
+
def start_process_ps_v2():
|
|
186
|
+
ps_args = "-Command (Get-CimInstance -Class Win32_ComputerSystemProduct).UUID"
|
|
187
|
+
|
|
188
|
+
cmd = ["powershell", *ps_args.split(" ")]
|
|
189
|
+
|
|
190
|
+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
|
191
|
+
out, err = proc.communicate(timeout=120)
|
|
192
|
+
|
|
193
|
+
rawOutput = out.decode('utf-8').strip()
|
|
194
|
+
return rawOutput
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
@staticmethod
|
|
198
|
+
def start_process(command, v = 1):
|
|
199
|
+
|
|
200
|
+
output = subprocess.check_output(command,
|
|
201
|
+
**subprocess_args(False))
|
|
202
|
+
|
|
203
|
+
if v == 1:
|
|
204
|
+
return output.decode('utf-8')
|
|
205
|
+
elif v == 2:
|
|
206
|
+
rawOutput = output.decode('utf-8')
|
|
207
|
+
return rawOutput[rawOutput.index("UUID")+4:].strip()
|
|
208
|
+
else:
|
|
209
|
+
raise ValueError("Version can be either 1 or 2.")
|
|
210
|
+
|
|
211
|
+
@staticmethod
|
|
212
|
+
def get_dbus_machine_id():
|
|
213
|
+
try:
|
|
214
|
+
with open("/etc/machine-id") as f:
|
|
215
|
+
return f.read().strip()
|
|
216
|
+
except:
|
|
217
|
+
pass
|
|
218
|
+
try:
|
|
219
|
+
with open("/var/lib/dbus/machine-id") as f:
|
|
220
|
+
return f.read().strip()
|
|
221
|
+
except:
|
|
222
|
+
pass
|
|
223
|
+
return ""
|
|
224
|
+
|
|
225
|
+
@staticmethod
|
|
226
|
+
def get_inodes():
|
|
227
|
+
import os
|
|
228
|
+
files = ["/bin", "/etc", "/lib", "/root", "/sbin", "/usr", "/var"]
|
|
229
|
+
inodes = []
|
|
230
|
+
for file in files:
|
|
231
|
+
try:
|
|
232
|
+
inodes.append(os.stat(file).st_ino)
|
|
233
|
+
except:
|
|
234
|
+
pass
|
|
235
|
+
return "".join([str(x) for x in inodes])
|
|
236
|
+
|
|
237
|
+
@staticmethod
|
|
238
|
+
def compute_machine_code():
|
|
239
|
+
return HelperMethods.get_dbus_machine_id() + HelperMethods.get_inodes()
|
|
240
|
+
|