2

I have a java application that speaks TLS1.2 over SSL to a 3rd-party. Recently they updated their certificate that "broke" the app.

org.bouncycastle.tls.TlsFatalAlert: bad_certificate(42)
    at org.bouncycastle.jsse.provider.ProvTlsClient$1.notifyServerCertificate(Unknown Source)
    at org.bouncycastle.tls.TlsUtils.processServerCertificate(Unknown Source)
    at org.bouncycastle.tls.TlsClientProtocol.handleServerCertificate(Unknown Source)
    at org.bouncycastle.tls.TlsClientProtocol.handleHandshakeMessage(Unknown Source)
    at org.bouncycastle.tls.TlsProtocol.processHandshakeQueue(Unknown Source)
    at org.bouncycastle.tls.TlsProtocol.processRecord(Unknown Source)
    at org.bouncycastle.tls.RecordStream.readRecord(Unknown Source)
    at org.bouncycastle.tls.TlsProtocol.safeReadRecord(Unknown Source)
    at org.bouncycastle.tls.TlsProtocol.blockForHandshake(Unknown Source)
    at org.bouncycastle.tls.TlsClientProtocol.connect(Unknown Source)
    at org.bouncycastle.jsse.provider.ProvSSLSocketDirect.startHandshake(Unknown Source)
    at org.bouncycastle.jsse.provider.ProvSSLSocketDirect.handshakeIfNecessary(Unknown Source)
    at org.bouncycastle.jsse.provider.ProvSSLSocketDirect$AppDataOutput.write(Unknown Source)
    at java.io.DataOutputStream.writeBytes(DataOutputStream.java:259)

Not sure how to install the new cert, which I have in *.cer format. I tried adding to the jre using keytool, but it didn't fix it. Is there a separate bouncycastle store I need to add it to? If so how?

        Security.addProvider(new BouncyCastleProvider());
        Security.addProvider(new BouncyCastleJsseProvider());

        SSLContext context = SSLContext.getInstance("TLSv1.2", BouncyCastleJsseProvider.PROVIDER_NAME);
        context.init( null, null, new SecureRandom() );
        SSLSocketFactory ssf = context.getSocketFactory();
        SSLSocket s = (SSLSocket) ssf.createSocket( HOST, activePort );

        DataOutputStream dos = new DataOutputStream( s.getOutputStream() );

Thanks for any help!

  • You can use a similar setup as shown here to update the certificates whenever neden: https://stackoverflow.com/questions/69506869/reloading-a-java-net-http-httpclients-sslcontext/69507126#69507126 – Hakan54 Jun 19 '23 at 11:58

0 Answers0