PskClientKeyExchangePreparator extends ClientKeyExchangePreparator<PskClientKeyExchangeMessage> { @Override public void prepareHandshakeMessageContents() { msg.setIdentity(chooser.getPSKIdentity()); msg.setIdentityLength(msg.getIdentity().getValue().length); msg.prepareComputations(); premasterSecret = generatePremasterSecret(); preparePremasterSecret(msg); prepareClientServerRandom(msg); } PskClientKeyExchangePreparator(Chooser chooser, PskClientKeyExchangeMessage message); @Override void prepareHandshakeMessageContents(); byte[] generatePremasterSecret(); @Override void prepareAfterParse(boolean clientMode);  }
@Test public void testPrepare() { context.setSelectedProtocolVersion(ProtocolVersion.TLS12); context.setSelectedCipherSuite(CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA); context.setClientRandom(ArrayConverter.hexStringToByteArray(RANDOM)); context.setServerRandom(ArrayConverter.hexStringToByteArray(RANDOM)); preparator.prepareHandshakeMessageContents(); assertArrayEquals(PREMASTERSECRET, message.getComputations().getPremasterSecret().getValue()); assertNotNull(message.getComputations().getClientServerRandom()); assertArrayEquals( ArrayConverter.concatenate(ArrayConverter.hexStringToByteArray(RANDOM), ArrayConverter.hexStringToByteArray(RANDOM)), message.getComputations().getClientServerRandom() .getValue()); }