BC occasionally fails to establish a TLS connection

Daniel JeliƄski <[email protected]> Thu, 7 Nov 2019 14:49:31 +0100
Newsgroups gmane.comp.encryption.bouncy-castle.devel
Message-ID <CAMrH03JGiE_ErR037Md9AKu5UJsOa5+nQXx7LT2VmA_T84MKKA@mail.gmail.com>
Hello all,
I'm running an evaluation of BC-FIPS (1.0.2) library, and I'm
regularly encountering the following entries in application logs:

2019-11-07 13:00:14 UTC WARNING Client raised fatal(2)
internal_error(80) alert: Failed to read record
java.lang.IllegalStateException: Secret has already been extracted or destroyed
at org.bouncycastle.tls.crypto.impl.AbstractTlsSecret.checkAlive(Unknown Source)
at org.bouncycastle.tls.crypto.impl.jcajce.JceTlsSecret.deriveUsingPRF(Unknown
Source)
at org.bouncycastle.tls.crypto.impl.TlsImplUtils.PRF(Unknown Source)
at org.bouncycastle.tls.crypto.impl.TlsImplUtils.calculateKeyBlock(Unknown
Source)
at org.bouncycastle.tls.crypto.impl.TlsAEADCipher.<init>(Unknown Source)
at org.bouncycastle.tls.crypto.impl.TlsAEADCipher.<init>(Unknown Source)
at org.bouncycastle.tls.crypto.impl.jcajce.JcaTlsCrypto.createCipher_AES_GCM(Unknown
Source)
at org.bouncycastle.tls.crypto.impl.jcajce.JcaTlsCrypto.createCipher(Unknown
Source)
at org.bouncycastle.tls.crypto.impl.AbstractTlsSecret.createCipher(Unknown
Source)
at org.bouncycastle.tls.TlsUtils.initCipher(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.ProvSSLSocketWrap.startHandshake(Unknown
Source)
at org.bouncycastle.jsse.provider.ProvSSLSocketWrap.startHandshake(Unknown
Source)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:396)
(removed the rest of stack trace, probably irrelevant).

My application is sending a request to the same server once every
minute. I was able to capture the failing session in Wireshark; from
what I can see, the client is asking for an abbreviated handshake, the
server agrees and sends back the same session ID, then the client
aborts the handshake reporting internal error.

While I'm seeing the error regularly, I wasn't able to create a repro.
The application is pretty big, and it's hard to tell which parts are
relevant to the issue.

Is that a known issue? Any troubleshooting and/or mitigation
instructions welcome.

For what it's worth, I'm running the application on Windows machine
with the following security providers configured:
security.provider.1=org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider
C:HYBRID;ENABLE{ALL}
security.provider.2=org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
fips:BCFIPS
security.provider.3=sun.security.provider.Sun

I'm also using BCTLS-FIPS-1.0.9 and BCPKIX-FIPS-1.0.3. The problem
appears both in approved and non-approved mode.
Thanks,
Daniel