def License_store(): """Tests that a license can be loaded from the stored data""" f = io.BytesIO() License.issue(certificate(), key(), license_data = LicenseData( '2014-01-01T00:00:00', '2014-01-01T00:00:01')).store(f, b'valid password') License.load(io.BytesIO(f.getvalue()), b'valid password')
def License_store(): """Tests that a license can be loaded from the stored data""" f = io.BytesIO() License.issue(certificate(), key(), license_data=LicenseData('2014-01-01T00:00:00', '2014-01-01T00:00:01')).store( f, b'valid password') License.load(io.BytesIO(f.getvalue()), b'valid password')
def test_store(self): """Tests that a license can be loaded from the stored data""" f = io.BytesIO() License.issue(CERTIFICATE, key(), license_data=LicenseData('2014-01-01T00:00:00', '2014-01-01T00:00:01')).store( f, b'valid password') License.load(io.BytesIO(f.getvalue()), b'valid password')
def test_store(self): """Tests that a license can be loaded from the stored data""" f = io.BytesIO() License.issue( CERTIFICATE, key(), license_data=LicenseData( '2014-01-01T00:00:00', '2014-01-01T00:00:01')).store(f, b'valid password') License.load(io.BytesIO(f.getvalue()), b'valid password')
def lget_license(sock): ''' get license data from the server which is connecting sock ''' lengthb = lrecv(sock, 1024) length = unpack('i', lengthb)[0] lsend(sock, b'ack') lic = lrecv(sock, length) # create local license file and check it temp = tempfile.TemporaryFile() temp.write(lic) temp.seek(0) return License.load(temp, PSK)
def VerifyLicense(self, certificate_path, licence_input, licence_file='license.key'): with open(certificate_path, 'rb') as f: certificate = f.read() # Load the license try: with open(licence_file, 'rb') as f: license = License.load( f, str.encode(licence_input, encoding='UTF-8')) license.verify(certificate) return True except truepy.License.InvalidPasswordException: return False
def _keyIsValid(self) -> bool: try: path = os.path.join( Resources.getPath( self._application.ResourceTypes.Certificates), "license_cert.pem") with open(path, 'rb') as f: certificate = f.read() key = BytesIO(bytes.fromhex(self.licenseKey)) lic = License.load(key, b'StereotechSTESlicerProFeatures') lic.verify(certificate) return True except License.InvalidSignatureException: Logger.log("w", "License key is wrong!") return False except FileNotFoundError: Logger.log("w", "Certificate not found!") return False except Exception as e: Logger.log("w", "License error: %s", str(e)) return False
def load_license(self, license_file): ''' load the license file and check validation of it. ''' self.logger.info('Loading %s ...', license_file) # open license file try: fid = open(license_file, 'rb') except IOError as ioe: self.logger.error('I/O error: %s: %s', ioe.strerror, license_file) sys.exit(-1) # import license file try: self.lic = License.load(fid, self.psk) except License.InvalidSignatureException: exc = sys.exc_info() self.logger.critical('truepy: %s', str(exc[1])) sys.exit(-1) fid.close() self.license_file = license_file self.extra = eval(self.lic.data.extra, {'null': None}) self.feats = self.extra['features'] # dump licenseData self._dump_data() # checking host ID if self._check_serverid(): self.logger.error( 'run \'%s\' on valid server has the following host IDs: %s', self.prog, repr(self.extra['serverids'])) sys.exit(-1) # load the license file as row data to pass to clients. size = os.path.getsize(license_file) with open(license_file, 'rb') as fid: self.rowsize = size self.rowlic = fid.read(size)
def show(license_file, issuer_certificate, license_file_password, **args): """show [license file] Verifies the signature of a license file and shows information about it. You must specify the issuer certificate as --issuer-certificate on the command line, and the license file password as --license-file-password. """ with open(license_file, 'rb') as f: try: license = License.load(f, license_file_password) except Exception as e: raise RuntimeError('Failed to load license file: %s', e) try: license.verify(issuer_certificate) except Exception as e: raise RuntimeError('Failed to verify license: %s', e) print('License information') print('\tissued by:\t"%s"' % str(license.data.issuer)) print('\tissued to:\t"%s"' % str(license.data.holder)) print('\tvalid from:\t%s' % str(license.data.not_before)) print('\tvalid to:\t%s' % str(license.data.not_after)) print('\tsubject:\t%s' % ( '"%s"' % license.data.subject if license.data.subject else '<none>')) print('\tconsumer_type:\t%s' % ( '"%s"' % license.data.consumer_type if license.data.consumer_type else '<none>')) print('\tinformation:\t%s' % ( '"%s"' % license.data.info if license.data.info else '<none>')) print('\textra data:\t%s' % ( '"%s"' % license.data.extra if license.data.extra else '<none>'))
def test_load_invalid_data(self): """Tests that License.load fails for invalid license data""" with self.assertRaises(License.InvalidPasswordException): License.load(io.BytesIO(b'hello world!!!!!'), b'password')
def test_load(self): """Tests that License.load succeeds with valid license data""" License.load(license(), b'valid password')
def test_load_invalid_password(self): """Tests that License.load fails for invalid license data""" with self.assertRaises(License.InvalidPasswordException): License.load(license(), b'invalid password')
def License_load_invalid_data(): """Tests that License.load fails for invalid license data""" with assert_exception(License.InvalidPasswordException): License.load(io.BytesIO(b'hello world!!!!!'), b'password')
def License_load_invalid_password(): """Tests that License.load fails for invalid license data""" with assert_exception(License.InvalidPasswordException): License.load(license(), b'invalid password')