Esempio n. 1
0
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')
Esempio n. 2
0
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')
Esempio n. 3
0
 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')
Esempio n. 4
0
 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')
Esempio n. 5
0
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)
Esempio n. 6
0
    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
Esempio n. 7
0
 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
Esempio n. 8
0
    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)
Esempio n. 9
0
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>'))
Esempio n. 10
0
 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')
Esempio n. 11
0
 def test_load(self):
     """Tests that License.load succeeds with valid license data"""
     License.load(license(), b'valid password')
Esempio n. 12
0
 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')
Esempio n. 13
0
 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')
Esempio n. 14
0
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')
Esempio n. 15
0
 def test_load(self):
     """Tests that License.load succeeds with valid license data"""
     License.load(license(), b'valid password')
Esempio n. 16
0
 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')
Esempio n. 17
0
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')
Esempio n. 18
0
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')
Esempio n. 19
0
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')