Skip to content

Commit b13684a

Browse files
committed
Misc. refactoring in tls
1 parent 685f920 commit b13684a

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

tls/src/main/java/org/bouncycastle/jsse/provider/ProvTlsServer.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,10 @@ protected boolean selectCipherSuite(int cipherSuite) throws IOException
340340
}
341341
}
342342

343-
boolean result = super.selectCipherSuite(cipherSuite);
344-
if (result)
345-
{
346-
this.credentials = cipherSuiteCredentials;
347-
}
348-
return result;
343+
this.selectedCipherSuite = cipherSuite;
344+
this.credentials = cipherSuiteCredentials;
345+
346+
return true;
349347
}
350348

351349
@Override

tls/src/main/java/org/bouncycastle/tls/DTLSServerProtocol.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,27 @@ protected DTLSTransport serverHandshake(ServerHandshakeState state, DTLSRequest
188188

189189
state.keyExchange = TlsUtils.initKeyExchangeServer(serverContext, server);
190190

191-
state.serverCredentials = null;
191+
TlsCredentials serverCredentials = null;
192192

193193
if (!KeyExchangeAlgorithm.isAnonymous(securityParameters.getKeyExchangeAlgorithm()))
194194
{
195-
state.serverCredentials = TlsUtils.establishServerCredentials(server);
195+
serverCredentials = TlsUtils.establishServerCredentials(server);
196196
}
197197

198198
// Server certificate
199199
{
200200
Certificate serverCertificate = null;
201201

202202
ByteArrayOutputStream endPointHash = new ByteArrayOutputStream();
203-
if (state.serverCredentials == null)
203+
if (serverCredentials == null)
204204
{
205205
state.keyExchange.skipServerCredentials();
206206
}
207207
else
208208
{
209-
state.keyExchange.processServerCredentials(state.serverCredentials);
209+
state.keyExchange.processServerCredentials(serverCredentials);
210210

211-
serverCertificate = state.serverCredentials.getCertificate();
211+
serverCertificate = serverCredentials.getCertificate();
212212

213213
sendCertificateMessage(serverContext, handshake, serverCertificate, endPointHash);
214214
}
@@ -237,7 +237,7 @@ protected DTLSTransport serverHandshake(ServerHandshakeState state, DTLSRequest
237237
handshake.sendMessage(HandshakeType.server_key_exchange, serverKeyExchange);
238238
}
239239

240-
if (state.serverCredentials != null)
240+
if (serverCredentials != null)
241241
{
242242
state.certificateRequest = server.getCertificateRequest();
243243

@@ -1026,7 +1026,6 @@ protected static class ServerHandshakeState
10261026
Hashtable serverExtensions = null;
10271027
boolean expectSessionTicket = false;
10281028
TlsKeyExchange keyExchange = null;
1029-
TlsCredentials serverCredentials = null;
10301029
CertificateRequest certificateRequest = null;
10311030
TlsHeartbeat heartbeat = null;
10321031
short heartbeatPolicy = HeartbeatMode.peer_not_allowed_to_send;

tls/src/main/java/org/bouncycastle/tls/TlsServerProtocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,7 @@ protected void send13ServerHelloCoda(ServerHello serverHello, boolean afterHello
15931593
this.connection_state = CS_SERVER_CERTIFICATE_REQUEST;
15941594
}
15951595
}
1596-
1596+
15971597
TlsCredentialedSigner serverCredentials = TlsUtils.establish13ServerCredentials(tlsServer);
15981598
if (null == serverCredentials)
15991599
{

tls/src/main/java/org/bouncycastle/tls/crypto/impl/TlsAEADCipher.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ private void rekeyCipher(SecurityParameters securityParameters, TlsAEADCipherImp
436436
private void setup13Cipher(TlsAEADCipherImpl cipher, byte[] nonce, TlsSecret secret, int cryptoHashAlgorithm)
437437
throws IOException
438438
{
439-
byte[] key = TlsCryptoUtils.hkdfExpandLabel(secret, cryptoHashAlgorithm, "key", TlsUtils.EMPTY_BYTES, keySize).extract();
440-
byte[] iv = TlsCryptoUtils.hkdfExpandLabel(secret, cryptoHashAlgorithm, "iv", TlsUtils.EMPTY_BYTES, fixed_iv_length).extract();
439+
byte[] key = hkdfExpandLabel(secret, cryptoHashAlgorithm, "key", keySize).extract();
440+
byte[] iv = hkdfExpandLabel(secret, cryptoHashAlgorithm, "iv", fixed_iv_length).extract();
441441

442442
cipher.setKey(key, 0, keySize);
443443
System.arraycopy(iv, 0, nonce, 0, fixed_iv_length);
@@ -458,4 +458,10 @@ private static int getNonceMode(boolean isTLSv13, int aeadType) throws IOExcepti
458458
throw new TlsFatalAlert(AlertDescription.internal_error);
459459
}
460460
}
461+
462+
private static TlsSecret hkdfExpandLabel(TlsSecret secret, int cryptoHashAlgorithm, String label, int length)
463+
throws IOException
464+
{
465+
return TlsCryptoUtils.hkdfExpandLabel(secret, cryptoHashAlgorithm, label, TlsUtils.EMPTY_BYTES, length);
466+
}
461467
}

0 commit comments

Comments
 (0)