private static KeySet getTlsKeySet(TlsContext context) throws CryptoException {
ProtocolVersion protocolVersion = context.getChooser().getSelectedProtocolVersion();
CipherSuite cipherSuite = context.getChooser().getSelectedCipherSuite();
byte[] masterSecret = context.getChooser().getMasterSecret();
byte[] seed = ArrayConverter.concatenate(context.getChooser().getServerRandom(), context.getChooser()
.getClientRandom());
byte[] keyBlock;
if (protocolVersion.isSSL()) {
keyBlock = SSLUtils.calculateKeyBlockSSL3(masterSecret, seed,
getSecretSetSize(protocolVersion, cipherSuite));
} else {
PRFAlgorithm prfAlgorithm = AlgorithmResolver.getPRFAlgorithm(protocolVersion, cipherSuite);
keyBlock = PseudoRandomFunction.compute(prfAlgorithm, masterSecret,
PseudoRandomFunction.KEY_EXPANSION_LABEL, seed, getSecretSetSize(protocolVersion, cipherSuite));
}
LOGGER.debug("A new key block was generated: {}", ArrayConverter.bytesToHexString(keyBlock));
KeyBlockParser parser = new KeyBlockParser(keyBlock, cipherSuite, protocolVersion);
KeySet keySet = parser.parse();
if (cipherSuite.isExportSymmetricCipher()) {
deriveExportKeys(keySet, context);
}
return keySet;
}