Skip to content

Commit 6be2906

Browse files
authored
Make sure machine code on Windows is the same as in the .NET Client (#20)
* Update internal.py * Update * Update LICENSE.txt * Minor update * Update setup.py
1 parent ca19e34 commit 6be2906

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Cryptolens AB
3+
Copyright (c) Cryptolens AB and Contributors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

licensing/internal.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,20 @@ def send_request(method, params):
104104
.encode("utf-8")).read().decode("utf-8")
105105

106106
@staticmethod
107-
def start_process(command):
107+
def start_process(command, v = 1):
108108

109109
process = Popen(command, stdout=PIPE)
110110
(output, err) = process.communicate()
111111
exit_code = process.wait()
112-
return output.decode("utf-8")
113-
112+
113+
if v == 1:
114+
return output.decode('utf-8')
115+
elif v == 2:
116+
rawOutput = output.decode('utf-8')
117+
return rawOutput[rawOutput.index("UUID")+4:].strip()
118+
else:
119+
raise ValueError("Version can be either 1 or 2.")
120+
114121
@staticmethod
115122
def get_dbus_machine_id():
116123
try:

licensing/methods.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,15 @@ def deactivate(token, product_id, key, machine_code, floating = False):
164164
class Helpers:
165165

166166
@staticmethod
167-
def GetMachineCode():
167+
def GetMachineCode(v=1):
168168

169169
"""
170-
Get a unique identifier for this device.
170+
Get a unique identifier for this device. If you want the machine code to be the same in .NET on Windows, you
171+
can set v=2. More information is available here: https://help.cryptolens.io/faq/index#machine-code-generation
171172
"""
172173

173174
if "windows" in platform.platform().lower():
174-
return HelperMethods.get_SHA256(HelperMethods.start_process(["cmd.exe", "/C", "wmic","csproduct", "get", "uuid"]))
175+
return HelperMethods.get_SHA256(HelperMethods.start_process(["cmd.exe", "/C", "wmic","csproduct", "get", "uuid"],v))
175176
elif "mac" in platform.platform().lower() or "darwin" in platform.platform().lower():
176177
res = HelperMethods.start_process(["system_profiler","SPHardwareDataType"])
177178
return HelperMethods.get_SHA256(res[res.index("UUID"):].strip())
@@ -181,13 +182,14 @@ def GetMachineCode():
181182
return HelperMethods.get_SHA256(HelperMethods.compute_machine_code())
182183

183184
@staticmethod
184-
def IsOnRightMachine(license_key, is_floating_license = False, allow_overdraft=False):
185+
def IsOnRightMachine(license_key, is_floating_license = False, allow_overdraft=False, v = 1):
185186

186187
"""
187188
Check if the device is registered with the license key.
189+
The version parameter is related to the one in GetMachineCode method.
188190
"""
189191

190-
current_mid = Helpers.GetMachineCode()
192+
current_mid = Helpers.GetMachineCode(v)
191193

192194
if license_key.activated_machines == None:
193195
return False

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
setup(
33
name = 'licensing', # How you named your package folder (MyLib)
44
packages = ['licensing'], # Chose the same as "name"
5-
version = '0.14', # Start with a small number and increase it with every change you make
5+
version = '0.15', # Start with a small number and increase it with every change you make
66
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
77
description = 'Client library for Cryptolens licensing Web API.', # Give a short description about your library
88
author = 'Cryptolens AB', # Type in your name
99
author_email = '[email protected]', # Type in your E-Mail
1010
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/v_14.tar.gz', # I explain this later on
11+
download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/v_15.tar.gz', # I explain this later on
1212
keywords = ['software licensing', 'licensing library', 'cryptolens'], # Keywords that define your package best
1313
classifiers=[
1414
#'Development Status :: 5 - Stable', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package

0 commit comments

Comments
 (0)