m-click / requests_pkcs12

Add PKCS#12 support to the Python requests library in a clean way, without monkey patching or temporary files
ISC License
123 stars 33 forks source link

SSLV3_ALERT_BAD_CERTIFICATE when switching to Pkcs12Adapter #46

Closed berndwinterstein closed 1 year ago

berndwinterstein commented 1 year ago

When switching from classic requests cert parameter to Pkcs12Adapter I always get SSLV3_ALERT_BAD_CERTIFICATE from the server. In wireshark I can see that there are no certificates send to the server. The certificates part is empty. Any ideas?

`

    backend = default_backend()
    p12file = self.application.flink_client_keystore()

    with open(p12file, 'rb') as pkcs12_file:
        pkcs12_data = pkcs12_file.read()
    pkcs12_password_bytes = "confluent".encode('utf8')

    p12 = crypto.load_pkcs12(pkcs12_data, pkcs12_password_bytes)
    pycaP12 = load_key_and_certificates(pkcs12_data, pkcs12_password_bytes, backend)
    pk_bytes = pycaP12[0].private_bytes(Encoding.DER, PrivateFormat.PKCS8, NoEncryption())
    cert_bytes = pycaP12[1].public_bytes(Encoding.DER)

    cert = dump_certificate(FILETYPE_PEM, p12.get_certificate())
    pk = dump_privatekey(FILETYPE_PEM, p12.get_privatekey())

    with open('test_cert.pem', 'wb') as pem_file:
        pem_file.write(cert)
    with open('test_cert.key', 'wb') as key_file:
        key_file.write(pk)

    self.session = requests.Session()

    # WORKS!
    #self.session.cert = ('test_cert.pem', 'test_cert.key')

    # DOESN'T WORK
    self.session.mount('{baseurl}'.format(baseurl=self.active_jobmanager_url), Pkcs12Adapter(pkcs12_data=pkcs12_data, pkcs12_password="confluent".encode('utf8')))

`

vog commented 1 year ago

@berndwinterstein Can you please test again with the latest version 1.18? Is this issue still present?

vog commented 1 year ago

Receiving no response for months, I assume this issue is fixed.

@berndwinterstein Feel free to open another issue in case you still encounter problems.