HelperMethods.ironpython2730_legacy = True
.
Please check out our guide about common errors and how to solve them: https://help.cryptolens.io/faq/index#troubleshooting-api-errors. For Python specific errors, please review this section.
Installation
Python 3
Python 2
Please copycryptolens_python2.py
file into your project folder. The entire library is contained in that file.
In the examples below, please disregard the imports and use only the following one:
Example
Key verification
The code below will work exactly as the one explained in the key verification tutorial. First, we need to add the namespaces: In Python 3:RSAPubKey
- the RSA public key (can be found here, in API Keys section).token
- the access token (can be found here, in API Keys section).product_id
- the id of the product can be found on the product page.key
- the license key to be verifiedmachine_code
- the unique id of the device.
Helpers.IsOnRightMachine(result[0])
will return False
. You can read more about this behaviour here.
Offline activation (saving/loading licenses)
Assuming the license key verification was successful, we can save the result in a file so that we can use it instead of contacting Cryptolens.Floating licenses
Floating licenses can be enabled by setting the floatingTimeInterval. Optionally, you can also allow customers to exceed the bound by specifying the maxOverdraft. The code below has a floatingTimeInterval of 300 seconds and maxOverdraft set to 1. To support floating licenses with overdraft, the call toHelpers.IsOnRightMachine(license, true, true)
needs two boolean flags to be set to true.
Create Trial Key (verified trial)
Idea
A trial key allows your users to evaluate some or all parts of your software for a limited period of time. The goal of trial keys is to set it up in such a way that you don’t need to manually create them, while still keeping everything secure. In Cryptolens, all trial keys are bound to the device that requested them, which helps to prevent users from using the trial after reinstalling their device. You can define which features should count as trial by editing feature definitions on the product page.Implementation
The code below shows how to create trial key. If the trial key is successful,trial_key[0]
will contain the license key string. We then need to call Key.Activate
(as shown in the earlier examples) with the obtained license key to verify the license.
License server or custom endpoint
To forward requests to a local license server or a different API, you can set it using theserver_address
in HelperMethods, i.e.,
Other settings
Proxy
If you have customers who want to use a proxy server, we recommend enabling the following setting before calling any other API method, such as Key.Activate.SSL verification
SSL verification can temporarily be disabled by adding the line below before any call to Key.Activate.Possible errors
The expiration date cannot be converted to a datetime object. Please try setting the period to a lower value.
This error occurs when the timestamp for the expiration date received from the server exceeds the limit in Python. This typically occurs when the Period is set to a excessively large value, often to prevent the license from expiring. While Cryptolens requires a period (defaulted to 30) during the creation of a new license, this does not mark the license as time-limited. You can learn more about it here. In essence, a license is treated as time-limited by either enforcing this in the Python code (e.g. if F1=true, the license is time-limited and so we check the expiration date against the current date, to see that it is still valid) or on the server side. On the server side, you can, for example, set up a feature that will automatically block expired licenses. You can read more about it here. In sum, to solve this issue, you can either follow one of the methods described above or set the period to a smaller value.Could not contact the server. “Error message: <urlopen error [SSL: CERTIFICATE_VERIFY _FAILED] certificate verify failed: unable to get local issuer certificate (ssl.c:1125)>”
This error is thrown when the urllib library (a built in library in Python that we use to send HTTP requests) is unable to locate the CA files on the client machine. From our experience, this error occurs exclusively on Macs where the Python environment is incorrectly installed. To solve this temporarily for testing purposes, you could temporary disable SSL verifications as described in here, however, we do not recommend this in a production scenario. Instead, a better solution is to fix the underlying issue preventing the Python environment from finding the CA files. This can be accomplished in at least two ways: Using certifi Before calling any of the API methods (e.g. Key.activate), you can add the following code:certifi
package to be installed.
Running a script in the Python environment
An alternative is to run script in their environment that should fix the issue. You can read more about it in this thread: https://github.com/Cryptolens/cryptolens-python/issues/65
Summary
The key takeaway is that it is better to address the issue with missing CA on the user side, since this issue will typically be user-specific. If that is not possible, you can use the code above to manually set the path to CA files. Although we have mentioned turning off SSL verification temporarily, it should not be used in production. Key.activate
takes care of signature verification internally, but some other methods do not.