Documentation for package truepy

Contents:

class truepy.License(encoded, signature, signature_algorithm='SHA1withRSA', signature_encoding='US-ASCII/Base64')[source]
exception InvalidPasswordException[source]

Raised when the license password is invalid

exception License.InvalidSignatureException[source]

Raised when the signature does not match

License.data = None

The decoded license data as an instance of LicenseData

License.encoded

The encoded license data

classmethod License.issue(certificate, key, digest='SHA1', **license_data)[source]

Issues a new License.

Parameters:
  • certificate (bytes or cryptography.x509.Certificate) – The issuer certificate.
  • key – The private key of the certificate.
  • digest (str) – The digest algorithm to use.
  • license_data – Parameters to pass on to truepy.LicenseData. Do not pass issuer; this value will be read from the certificate subject. You may also specify the single value license_data; this must in that case be an instance of LicenseData.
Raises ValueError:
 

if license data cannot be created from the keyword arguments or if the issuer name is passed

Returns:

a new license

Return type:

truepy.License

classmethod License.load(f, password)[source]

Loads a license from a stream.

Parameters:
  • f (file or stream) – The data stream.
  • password (bytes) – The password used by the licensed application.
Returns:

a license object

Return type:

truepy.License

Raises:
License.signature

The signature of the license data as base 64 encoded data

License.signature_algorithm

The signature algorithm used to sign

License.signature_encoding

The encoding of the signature; this is always US-ASCII/Base64

License.store(f, password)[source]

Stores this license to a stream.

Parameters:
  • f (file or stream) – The data stream.
  • password (bytes) – The password used by the licensed application.
License.verify(certificate)[source]

Verifies the signature of this certificate against a certificate.

Parameters:certificate (bytes or cryptography.x509.Certificate) – The issuer certificate.
Raises truepy.License.InvalidSignatureException:
 if the signature does not match
class truepy.LicenseData(not_before, not_after, issued=None, issuer=None, holder=None, subject=None, consumer_type=None, info=None, extra=None)[source]
consumer_type

The type of entity to which this license is issued

extra

The license extra data

holder

The license holder distinguished name

info

Generic information about this license

issued

The issued timestamp of this license

issuer

The license issuer distinguished name

not_after

The notAfter timestamp of this license

not_before

The notBefore timestamp of this license

subject

The license subject

class truepy.Name(name)[source]
ATTRIBUTES = {'C': <ObjectIdentifier(oid=2.5.4.6, name=countryName)>, 'CN': <ObjectIdentifier(oid=2.5.4.3, name=commonName)>, 'SN': <ObjectIdentifier(oid=2.5.4.4, name=surname)>, 'GN': <ObjectIdentifier(oid=2.5.4.42, name=givenName)>, 'OU': <ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, 'L': <ObjectIdentifier(oid=2.5.4.7, name=localityName)>, 'O': <ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, 'ST': <ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>}

A mapping from short attribute names to OIDs

ESCAPABLES = ('"', '+', ',', ';', '<', '>')

The escapable characters

REVERSED_ATTRIBUTES = {<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>: 'O', <ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>: 'OU', <ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>: 'ST', <ObjectIdentifier(oid=2.5.4.6, name=countryName)>: 'C', <ObjectIdentifier(oid=2.5.4.7, name=localityName)>: 'L', <ObjectIdentifier(oid=2.5.4.4, name=surname)>: 'SN', <ObjectIdentifier(oid=2.5.4.3, name=commonName)>: 'CN', <ObjectIdentifier(oid=2.5.4.42, name=givenName)>: 'GN'}

The reversed mapping from attr:ATTRIBUTES

classmethod escape(s)[source]

Escapes a string.

Parameters:s (str) – The string to escape.
Returns:an escaped string
Return type:str
classmethod from_x509_name(name)[source]

Creates a name from a cryptography.x509.Name.

Parameters:name (cryptography.x509.Name) – The source name.
classmethod unescape(s)[source]

Unescapes a string.

This is the inverse operation to escape.

Parameters:s (str) – The string to unescape.
Returns:an unescaped string
Return type:str
Raises ValueError:
 if an invalid escape is encountered; only characters in ESCAPABLES are supported

Indices and tables