Esempio n. 1
0
    def _get_cert_key_from_property(self, cert_property, cert_type):
        """Gets the cert & key from dataprov info

        :type cert_property: CertProperty
        :type cert_type: str
        """
        cert, priv_key, pub_key = None, None, None

        # Validate the cert property
        if not cert_property.validate():
            raise RuntimeError(cert_type.title() + " certificate params are invalid! Please check config file.")
        logger.info('Initialization with dataprov. These fields might not be used in final output if overridden')

        # Extract the private and public key
        if cert_property.priv_path and c_path.validate_file(cert_property.priv_path):
            logger.info('Using a predefined ' + cert_type + ' private key from: ' + cert_property.priv_path)
            with open(cert_property.priv_path, 'rb') as fp:
                priv_key = fp.read()
                if self.using_ecdsa:
                    priv_key = ecdsa_functions.get_key_in_format(priv_key, utils.FORMAT_PEM)
                    pub_key = ecdsa_functions.get_public_key_from_private(priv_key)
                else:
                    priv_key = rsa_functions.get_key_in_format(priv_key, utils.FORMAT_PEM)
                    pub_key = rsa_functions.get_public_key_from_private(priv_key)

        # Extract the certificate
        if cert_property.cert_path and c_path.validate_file(cert_property.cert_path):
            logger.info('Using a predefined ' + cert_type + ' certificate from: ' + cert_property.cert_path)
            with open(cert_property.cert_path, 'rb') as fp:
                cert = fp.read()
                cert = cert_functions.get_cert_in_format(cert, utils.FORMAT_PEM)
        return cert, priv_key, pub_key
Esempio n. 2
0
    def update_certs_format(self):
        # Update basic certs
        for tag in ['root_cert', 'attestation_ca_cert', 'attestation_cert']:
            val = getattr(self, tag)
            if val:
                val = cert_functions.get_cert_in_format(val, utils.FORMAT_DER)
            setattr(self, tag, val)

        # Update root cert list
        for idx in range(len(self.root_cert_list)):
            val = self.root_cert_list[idx]
            if val:
                val = cert_functions.get_cert_in_format(val, utils.FORMAT_DER)
            self.root_cert_list[idx] = val

        # Update keys
        for tag in ['root_key', 'attestation_ca_key', 'attestation_key']:
            val = getattr(self, tag)
            if val:
                val = rsa_functions.get_key_in_format(val, utils.FORMAT_DER)
            setattr(self, tag, val)