PskDheServerKeyExchangeHandler extends ServerKeyExchangeHandler<PskDheServerKeyExchangeMessage> { @Override public void adjustTLSContext(PskDheServerKeyExchangeMessage message) { adjustPSKGenerator(message); adjustPSKModulus(message); adjustServerPublicKey(message); if (message.getComputations() != null && message.getComputations().getPrivateKey() != null) { adjustServerPrivateKey(message); } } PskDheServerKeyExchangeHandler(TlsContext tlsContext); @Override PskDheServerKeyExchangeParser getParser(byte[] message, int pointer); @Override PskDheServerKeyExchangePreparator getPreparator(PskDheServerKeyExchangeMessage message); @Override PskDheServerKeyExchangeSerializer getSerializer(PskDheServerKeyExchangeMessage message); @Override void adjustTLSContext(PskDheServerKeyExchangeMessage message);  }
@Test public void testAdjustTLSContext() { PskDheServerKeyExchangeMessage message = new PskDheServerKeyExchangeMessage(); message.setModulus(BigInteger.TEN.toByteArray()); message.setGenerator(BigInteger.ONE.toByteArray()); message.setPublicKey(new byte[] { 0, 1, 2, 3 }); context.setSelectedCipherSuite(CipherSuite.TLS_DHE_PSK_WITH_AES_128_CBC_SHA); message.prepareComputations(); message.getComputations().setPrivateKey(BigInteger.ZERO); handler.adjustTLSContext(message); assertNull(context.getPreMasterSecret()); }
@Test public void testAdjustTLSContextWithoutComputations() { PskDheServerKeyExchangeMessage message = new PskDheServerKeyExchangeMessage(); message.setModulus(BigInteger.TEN.toByteArray()); message.setGenerator(BigInteger.ONE.toByteArray()); message.setPublicKey(new byte[] { 0, 1, 2, 3 }); handler.adjustTLSContext(message); assertNull(context.getPreMasterSecret()); assertNull(context.getMasterSecret()); }