Пример #1
0
    def _get_certificate_and_key_pair_from_files(self, certificate_params_dict):
        key_pair = {}
        with open(certificate_params_dict['private_key_path'], 'rb') as private_key_file:
            private_key = private_key_file.read()
            if 'BEGIN RSA PRIVATE KEY' not in private_key:
                # key is in DER format
                private_key = crypto_functions.privkey_der_to_pem(private_key)
            public_key = crypto_functions.get_public_key_from_private_key(private_key)
            key_pair['public_key'] = public_key
            key_pair['private_key'] = private_key

        with open(certificate_params_dict['certificate_path'], 'rb') as cert_file:
            cert_raw = cert_file.read()
            if 'BEGIN CERTIFICATE' in cert_raw:
                cert = cert_raw
            else:
                cert = crypto_functions.cert_der_to_pem(cert_raw)

        return (cert, key_pair)
    def _get_certificate_and_key_pair_from_files(self, certificate_params_dict):
        key_pair={}
        with open(certificate_params_dict['private_key_path'], 'rb') as private_key_file:
            private_key = private_key_file.read()
            if 'BEGIN RSA PRIVATE KEY' not in private_key:
                #key is in DER format
                private_key = crypto_functions.privkey_der_to_pem(private_key)
            public_key = crypto_functions.get_public_key_from_private_key(private_key)
            key_pair['public_key']=public_key
            key_pair['private_key']=private_key

        with open(certificate_params_dict['certificate_path'], 'rb') as cert_file:
            cert_raw = cert_file.read()
            if 'BEGIN CERTIFICATE' in cert_raw:
                cert = cert_raw
            else:
                cert = crypto_functions.cert_der_to_pem(cert_raw)

        return (cert, key_pair)