SrpServerKeyExchangeHandler extends ServerKeyExchangeHandler<SrpServerKeyExchangeMessage> { @Override public void adjustTLSContext(SrpServerKeyExchangeMessage message) { adjustSRPGenerator(message); adjustSRPModulus(message); adjustSalt(message); adjustServerPublicKey(message); if (message.getComputations() != null && message.getComputations().getPrivateKey() != null) { adjustServerPrivateKey(message); } } SrpServerKeyExchangeHandler(TlsContext tlsContext); @Override SrpServerKeyExchangeParser getParser(byte[] message, int pointer); @Override SrpServerKeyExchangePreparator getPreparator(SrpServerKeyExchangeMessage message); @Override SrpServerKeyExchangeSerializer getSerializer(SrpServerKeyExchangeMessage message); @Override void adjustTLSContext(SrpServerKeyExchangeMessage message);  }
@Test public void testAdjustTLSContext() { SrpServerKeyExchangeMessage message = new SrpServerKeyExchangeMessage(); message.setModulus(BigInteger.TEN.toByteArray()); message.setGenerator(BigInteger.ONE.toByteArray()); message.setSalt(BigInteger.TEN.toByteArray()); message.setPublicKey(new byte[] { 0, 1, 2, 3 }); context.setSelectedCipherSuite(CipherSuite.TLS_SRP_SHA_WITH_AES_128_CBC_SHA); message.prepareComputations(); message.getComputations().setPrivateKey(BigInteger.ZERO); handler.adjustTLSContext(message); assertEquals(BigInteger.TEN, context.getSRPModulus()); assertEquals(BigInteger.ONE, context.getSRPGenerator()); assertArrayEquals(BigInteger.TEN.toByteArray(), context.getSRPServerSalt()); assertEquals(new BigInteger(new byte[] { 0, 1, 2, 3 }), context.getServerSRPPublicKey()); assertEquals(BigInteger.ZERO, context.getServerSRPPrivateKey()); assertNull(context.getPreMasterSecret()); assertNull(context.getMasterSecret()); }
@Test public void testAdjustTLSContextWithoutComputations() { SrpServerKeyExchangeMessage message = new SrpServerKeyExchangeMessage(); message.setModulus(BigInteger.TEN.toByteArray()); message.setGenerator(BigInteger.ONE.toByteArray()); message.setSalt(BigInteger.TEN.toByteArray()); message.setPublicKey(new byte[] { 0, 1, 2, 3 }); handler.adjustTLSContext(message); assertEquals(BigInteger.TEN, context.getSRPModulus()); assertEquals(BigInteger.ONE, context.getSRPGenerator()); assertArrayEquals(BigInteger.TEN.toByteArray(), context.getSRPServerSalt()); assertEquals(new BigInteger(new byte[] { 0, 1, 2, 3 }), context.getServerSRPPublicKey()); assertNull(context.getServerSRPPrivateKey()); assertNull(context.getPreMasterSecret()); assertNull(context.getMasterSecret()); }