private void prepareBinderValue() { try { HKDFAlgorithm hkdfAlgortihm = AlgorithmResolver.getHKDFAlgorithm(pskBinder.getBinderCipherConfig()); int macLen = Mac.getInstance(hkdfAlgortihm.getMacAlgorithm().getJavaName()).getMacLength(); pskBinder.setBinderEntry(new byte[macLen]); pskBinder.setBinderEntryLength(pskBinder.getBinderEntry().getValue().length); } catch (NoSuchAlgorithmException ex) { LOGGER.warn(ex); } }
for (int x = 0; x < msg.getBinders().size(); x++) { try { HKDFAlgorithm hkdfAlgortihm = AlgorithmResolver.getHKDFAlgorithm(pskSets.get(x).getCipherSuite()); Mac mac = Mac.getInstance(hkdfAlgortihm.getMacAlgorithm().getJavaName()); DigestAlgorithm digestAlgo = AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS13, pskSets.get(x)
private byte[] derivePsk(NewSessionTicketMessage message) { try { LOGGER.debug("Deriving PSK from current session"); HKDFAlgorithm hkdfAlgortihm = AlgorithmResolver.getHKDFAlgorithm(tlsContext.getChooser() .getSelectedCipherSuite()); DigestAlgorithm digestAlgo = AlgorithmResolver.getDigestAlgorithm(tlsContext.getChooser() .getSelectedProtocolVersion(), tlsContext.getChooser().getSelectedCipherSuite()); int macLength = Mac.getInstance(hkdfAlgortihm.getMacAlgorithm().getJavaName()).getMacLength(); byte[] resumptionMasterSecret = HKDFunction.deriveSecret(hkdfAlgortihm, digestAlgo.getJavaName(), tlsContext.getMasterSecret(), HKDFunction.RESUMPTION_MASTER_SECRET, tlsContext.getDigest() .getRawBytes()); LOGGER.debug("Derived ResumptionMasterSecret: " + ArrayConverter.bytesToHexString(resumptionMasterSecret)); byte[] psk = HKDFunction.expandLabel(hkdfAlgortihm, resumptionMasterSecret, HKDFunction.RESUMPTION, message .getTicket().getTicketNonce().getValue(), macLength); LOGGER.debug("Derived PSK: " + ArrayConverter.bytesToHexString(psk)); return psk; } catch (NoSuchAlgorithmException | CryptoException ex) { LOGGER.error("DigestAlgorithm for psk derivation unknown"); throw new WorkflowExecutionException(ex.toString()); } }
private byte[] computeVerifyData() throws CryptoException { if (chooser.getSelectedProtocolVersion().isTLS13()) { try { HKDFAlgorithm hkdfAlgortihm = AlgorithmResolver.getHKDFAlgorithm(chooser.getSelectedCipherSuite()); Mac mac = Mac.getInstance(hkdfAlgortihm.getMacAlgorithm().getJavaName()); byte[] finishedKey;
private void adjustEarlyTrafficSecret() throws CryptoException { HKDFAlgorithm hkdfAlgortihm = AlgorithmResolver.getHKDFAlgorithm(tlsContext.getChooser() .getEarlyDataCipherSuite()); DigestAlgorithm digestAlgo = AlgorithmResolver.getDigestAlgorithm(ProtocolVersion.TLS13, tlsContext .getChooser().getEarlyDataCipherSuite()); byte[] earlySecret = HKDFunction.extract(hkdfAlgortihm, new byte[0], tlsContext.getChooser().getEarlyDataPsk()); tlsContext.setEarlySecret(earlySecret); byte[] earlyTrafficSecret = HKDFunction.deriveSecret(hkdfAlgortihm, digestAlgo.getJavaName(), tlsContext .getChooser().getEarlySecret(), HKDFunction.CLIENT_EARLY_TRAFFIC_SECRET, tlsContext.getDigest() .getRawBytes()); tlsContext.setClientEarlyTrafficSecret(earlyTrafficSecret); LOGGER.debug("EarlyTrafficSecret: " + ArrayConverter.bytesToHexString(earlyTrafficSecret)); }
private void adjustApplicationTrafficSecrets() { HKDFAlgorithm hkdfAlgortihm = AlgorithmResolver.getHKDFAlgorithm(tlsContext.getChooser() .getSelectedCipherSuite()); DigestAlgorithm digestAlgo = AlgorithmResolver.getDigestAlgorithm(tlsContext.getChooser() .getSelectedProtocolVersion(), tlsContext.getChooser().getSelectedCipherSuite()); try { int macLength = Mac.getInstance(hkdfAlgortihm.getMacAlgorithm().getJavaName()).getMacLength(); byte[] saltMasterSecret = HKDFunction.deriveSecret(hkdfAlgortihm, digestAlgo.getJavaName(), tlsContext .getChooser().getHandshakeSecret(), HKDFunction.DERIVED, ArrayConverter.hexStringToByteArray("")); byte[] masterSecret = HKDFunction.extract(hkdfAlgortihm, saltMasterSecret, new byte[macLength]); byte[] clientApplicationTrafficSecret = HKDFunction.deriveSecret(hkdfAlgortihm, digestAlgo.getJavaName(), masterSecret, HKDFunction.CLIENT_APPLICATION_TRAFFIC_SECRET, tlsContext.getDigest().getRawBytes()); tlsContext.setClientApplicationTrafficSecret(clientApplicationTrafficSecret); LOGGER.debug("Set clientApplicationTrafficSecret in Context to " + ArrayConverter.bytesToHexString(clientApplicationTrafficSecret)); byte[] serverApplicationTrafficSecret = HKDFunction.deriveSecret(hkdfAlgortihm, digestAlgo.getJavaName(), masterSecret, HKDFunction.SERVER_APPLICATION_TRAFFIC_SECRET, tlsContext.getDigest().getRawBytes()); tlsContext.setServerApplicationTrafficSecret(serverApplicationTrafficSecret); LOGGER.debug("Set serverApplicationTrafficSecret in Context to " + ArrayConverter.bytesToHexString(serverApplicationTrafficSecret)); tlsContext.setMasterSecret(masterSecret); LOGGER.debug("Set masterSecret in Context to " + ArrayConverter.bytesToHexString(masterSecret)); } catch (NoSuchAlgorithmException | CryptoException ex) { throw new AdjustmentException(ex); } }
private void adjustHandshakeTrafficSecrets() { HKDFAlgorithm hkdfAlgortihm = AlgorithmResolver.getHKDFAlgorithm(tlsContext.getChooser() .getSelectedCipherSuite()); DigestAlgorithm digestAlgo = AlgorithmResolver.getDigestAlgorithm(tlsContext.getChooser()
CipherAlgorithm cipherAlg = AlgorithmResolver.getCipher(cipherSuite); KeySet keySet = new KeySet(keySetType); HKDFAlgorithm hkdfAlgortihm = AlgorithmResolver.getHKDFAlgorithm(cipherSuite); keySet.setClientWriteKey(HKDFunction.expandLabel(hkdfAlgortihm, clientSecret, HKDFunction.KEY, new byte[] {}, cipherAlg.getKeySize()));