Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

A TLS handshake ends with the alert certificate_unknown (46)

Your error

org.bouncycastle.tls.TlsFatalAlert: certificate_unknown(46)3 more lines it can show

Fix it fast

Most common cause, 1 of 3

Your Java side does not trust the certificate the peer sent

Import the CA that issued the peer's certificate into a trust store and make the JVM load it with the javax.net.ssl.trustStore, trustStoreType and trustStorePassword properties, or import it into the cacerts file of that Java installation.

Fix
keytool -importcert -alias partner-ca -file partner-ca.pem -keystore truststore.p12 -storetype PKCS12 -storepass changeit -noprompt
java -Djavax.net.ssl.trustStore=truststore.p12 -Djavax.net.ssl.trustStoreType=PKCS12 -Djavax.net.ssl.trustStorePassword=changeit -jar app.jar
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

certificate_unknown(46) means one side found a certificate unacceptable without naming why. Bouncy Castle's TlsFatalAlert says your own trust manager rejected the peer's certificate; TlsFatalAlertReceived, or OpenSSL's 14094416 alert certificate unknown seen in Indy, says the peer rejected yours. Trust the right CA, present an accepted client certificate, or update a stale pin. Applies to bctls 1.87.

  • Applies to Bouncy Castle bctls 1.87, Java 21, OpenSSL 3.0 to 4.1, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Read the exception class or the error text before anything else, because it tells you which side to fix. Then replay the handshake with openssl s_client, first without a client certificate and then with one. The first run tests whether the server's chain verifies against your CA file; the second tests whether the server accepts your certificate.

Run this first
openssl s_client -connect api.example.com:443 -servername api.example.com -CAfile ca.pem -verify_return_error -brief </dev/null
openssl s_client -connect api.example.com:443 -servername api.example.com -CAfile ca.pem -cert client.crt -key client.key -verify_return_error -brief </dev/null

Then find the line you see in this list and open its fix:

  1. 1Your Java side does not trust the certificate the peer sentTlsFatalAlert: certificate_unknown(46), without Received in the class name, followed by a Caused by line with a CertificateException
  2. 2The peer refuses the client certificate you presentTlsFatalAlertReceived: certificate_unknown(46) in Bouncy Castle, or 14094416 sslv3 alert certificate unknown from an OpenSSL client such as Indy, against a service that asks for a client certificate; the first s_client run works and the second fails
  3. 3Custom verification code refuses a certificate that verifies cleanlys_client verifies the same chain with the same CA file without errors, but the application still raises alert 46

What does the error look like?

  • org.bouncycastle.tls.TlsFatalAlert: certificate_unknown(46)
  • org.bouncycastle.tls.TlsFatalAlertReceived: certificate_unknown(46)
  • error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown
  • tls alert certificate unknown (the wording of newer OpenSSL releases)

Cause 1 of 3

Your Java side does not trust the certificate the peer sent

You seeTlsFatalAlert: certificate_unknown(46), without Received in the class name, followed by a Caused by line with a CertificateException

Check

TlsFatalAlert certificate_unknown(46) without Received means your own Java trust manager rejected the peer's certificate. Bouncy Castle's JSSE provider turns any CertificateException from the trust manager, for a server or a client certificate, into that alert and sends it to the peer. Its default trust store is the file in javax.net.ssl.trustStore; with the property unset it uses lib/security/jssecacerts, then lib/security/cacerts under java.home.

Check
keytool -cacerts -list -storepass changeit | grep -i partner
keytool -list -keystore truststore.p12 -storepass changeit

Fix

Import the CA that issued the peer's certificate into a trust store and make the JVM load it with the javax.net.ssl.trustStore, trustStoreType and trustStorePassword properties, or import it into the cacerts file of that Java installation.

Fix
keytool -importcert -alias partner-ca -file partner-ca.pem -keystore truststore.p12 -storetype PKCS12 -storepass changeit -noprompt
java -Djavax.net.ssl.trustStore=truststore.p12 -Djavax.net.ssl.trustStoreType=PKCS12 -Djavax.net.ssl.trustStorePassword=changeit -jar app.jar

Verify

keytool lists the new alias and the application completes the handshake.

Verify
keytool -list -keystore truststore.p12 -storepass changeit -alias partner-ca

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

The peer refuses the client certificate you present

You seeTlsFatalAlertReceived: certificate_unknown(46) in Bouncy Castle, or 14094416 sslv3 alert certificate unknown from an OpenSSL client such as Indy, against a service that asks for a client certificate; the first s_client run works and the second fails

Check

TlsFatalAlertReceived certificate_unknown(46), or OpenSSL's alert certificate unknown, means the server received your client certificate and refused it. Bouncy Castle throws the Received class when a fatal alert arrives from the other side, and OpenSSL reports any received alert as an error named after it. A current OpenSSL server maps common verification failures to more specific alerts, such as unknown_ca or certificate_expired, so a plain 46 often points to a server built on Java or on its own checking code.

Check
openssl x509 -in client.crt -noout -subject -issuer -dates
openssl x509 -in client.crt -noout -ext extendedKeyUsage

Fix

Ask the service which CA it accepts for client certificates, get a certificate from that CA, and send its intermediates along with it. With s_client, -cert_chain supplies those intermediates; in Java, keytool -importcert can store the CA's full chain reply under the alias of your key entry.

Fix
openssl s_client -connect api.example.com:443 -servername api.example.com -CAfile ca.pem -cert client.crt -key client.key -cert_chain intermediates.pem -verify_return_error -brief </dev/null

Verify

The handshake with the client certificate completes and prints the negotiated protocol.

Verify
openssl s_client -connect api.example.com:443 -servername api.example.com -cert client.crt -key client.key -cert_chain intermediates.pem -brief </dev/null

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

Custom verification code refuses a certificate that verifies cleanly

You sees_client verifies the same chain with the same CA file without errors, but the application still raises alert 46

Check

certificate_unknown(46) on a chain that s_client verifies cleanly means your own pinning or custom trust code refused it. In Bouncy Castle, the CertificateException such a trust manager throws becomes alert 46 like any other; in OpenSSL, a verify callback that returns 0 stops verification and sends a failure alert. A pinned value left over from before a certificate renewal is the usual case.

Check
openssl s_client -connect api.example.com:443 -servername api.example.com </dev/null 2>/dev/null | openssl x509 -noout -fingerprint -sha256 -subject
grep -R -n -i -E "TrustManager|pin|fingerprint|thumbprint" src/

Fix

Log the subject and fingerprint that your hook receives next to the value it expects, then update the stored pin or rule to match the renewed certificate.

Fix
openssl x509 -in server.crt -noout -fingerprint -sha256

Verify

With the new value in place the application connects to the same server.

Verify
openssl s_client -connect api.example.com:443 -servername api.example.com -brief </dev/null

Confirmed by raw.githubusercontent.com

Did this fix it?

How do I stop it coming back?

  • Log the peer certificate's subject and the verification result on both ends, so alert 46 is never the only clue.
  • When you pin a certificate or key, add the next value before the current certificate is replaced.
  • Load the same CA file in your s_client tests and in the application's trust store, so the two never disagree.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.