Example #1
0
    def validate_sig(self, to_sign, signature, cert_chain_der):
        # Check that openssl is available
        try:
            crypto_functions.are_available([crypto_functions.MOD_OPENSSL])
        except Exception as e:
            raise RuntimeError('Cannot validate signing: ' + str(e))

        hmac_params = crypto_functions.get_hmacparams_from_certificate_chain(
            cert_chain_der[0])
        hash_algo = crypto_functions.get_hash_algorithm_from_certicate_chain(
            cert_chain_der[0])

        cert_chain_pem = []
        for cert in cert_chain_der:
            cert_chain_pem.append(crypto_functions.cert_der_to_pem(cert))

        public_key = crypto_functions.get_public_key_from_cert_chain(
            cert_chain_pem)
        decrypted_hash = crypto_functions.decrypt_with_public_key(
            signature, public_key)

        hasher = Hasher()
        image_hash = hasher.qcom_hmac(to_sign, hmac_params, hash_algo)

        return image_hash == decrypted_hash
Example #2
0
    def validate_sig_using_hash(self, image_hash, signature, cert_chain_der):
        # Check that openssl is available
        try:
            crypto_functions.are_available([crypto_functions.MOD_OPENSSL])
        except Exception as e:
            raise RuntimeError('Cannot validate signing: ' + str(e))

        use_pss = crypto_functions.cert_uses_pss(cert_chain_der[0], 'DER')
        use_dsa = crypto_functions.cert_uses_dsa(cert_chain_der[0], 'DER')

        if use_pss:
            logger.info('image is signed with RSAPSS')
        if use_dsa:
            logger.info('image is signed with ECDSA')
        if not use_dsa and not use_pss:
            logger.info('image is signed with PKCS')

        hash_algo = crypto_functions.get_hash_algorithm_from_certicate_chain(
            cert_chain_der[0])

        cert_chain_pem = []
        for cert in cert_chain_der:
            cert_chain_pem.append(crypto_functions.cert_der_to_pem(cert))

        public_key = crypto_functions.get_public_key_from_cert_chain(
            cert_chain_pem)
        decrypted_hash = crypto_functions.decrypt_with_public_key(
            signature,
            public_key,
            image_hash,
            use_pss,
            use_dsa,
            pss_digest_algorithm=hash_algo)
        return image_hash == decrypted_hash
    def validate_sig(self, to_sign, signature, cert_chain_der):
        hmac_params=crypto_functions.get_hmacparams_from_certificate_chain(cert_chain_der[0])
        cert_chain_pem = []
        for cert in cert_chain_der:
            cert_chain_pem.append(crypto_functions.cert_der_to_pem(cert))

        public_key = crypto_functions.get_public_key_from_cert_chain(cert_chain_pem)
        decrypted_hash =  crypto_functions.decrypt_with_public_key(signature, public_key)

        hasher = Hasher()
        image_hash = hasher.qcom_hmac(to_sign, hmac_params)

        return image_hash == decrypted_hash
    def validate_sig(self, to_sign, signature, cert_chain_der):
        hmac_params=crypto_functions.get_hmacparams_from_certificate_chain(cert_chain_der[0])
        cert_chain_pem = []
        for cert in cert_chain_der:
            cert_chain_pem.append(crypto_functions.cert_der_to_pem(cert))

        public_key = crypto_functions.get_public_key_from_cert_chain(cert_chain_pem)
        decrypted_hash =  crypto_functions.decrypt_with_public_key(signature, public_key)

        hasher = Hasher()
        image_hash = hasher.qcom_hmac(to_sign, hmac_params)

        return image_hash == decrypted_hash