@Override protected T createHandshakeMessage() { return (T) new RSAClientKeyExchangeMessage(); }
/** * Reads the next bytes as the SerializedPublicKey and writes them in the * message * * @param msg * Message to write in */ private void parseSerializedPublicKey(T msg) { msg.setPublicKey(parseByteArrayField(msg.getPublicKeyLength().getValue())); LOGGER.debug("SerializedPublicKey: " + ArrayConverter.bytesToHexString(msg.getPublicKey().getValue())); }
protected void prepareSerializedPublicKeyLength(T msg) { msg.setPublicKeyLength(msg.getPublicKey().getValue().length); LOGGER.debug("SerializedPublicKeyLength: " + msg.getPublicKeyLength().getValue()); }
protected void prepareSerializedPublicKey(T msg) { msg.setPublicKey(encrypted); LOGGER.debug("SerializedPublicKey: " + ArrayConverter.bytesToHexString(msg.getPublicKey().getValue())); }
WorkflowTrace trace = new WorkflowConfigurationFactory(tlsConfig).createWorkflowTrace(WorkflowTraceType.HELLO, RunningModeType.CLIENT); RSAClientKeyExchangeMessage cke = new RSAClientKeyExchangeMessage(tlsConfig); ModifiableByteArray epms = new ModifiableByteArray(); epms.setModification(ByteArrayModificationFactory.explicitValue(encryptedPMS)); cke.setPublicKey(epms); trace.addTlsAction(new SendAction(cke)); if (null != type) {
@Override public void prepareAfterParse(boolean clientMode) { msg.prepareComputations(); prepareClientServerRandom(msg); int keyByteLength = chooser.getServerRsaModulus().bitLength() / 8; if (clientMode && (msg.getPublicKey() == null || msg.getPublicKey().getValue() == null)) { int randomByteLength = keyByteLength - HandshakeByteLength.PREMASTER_SECRET - 3; padding = new byte[randomByteLength]; preparePlainPaddedPremasterSecret(msg); byte[] paddedPremasterSecret = msg.getComputations().getPlainPaddedPremasterSecret().getValue();
/** * Reads the next bytes as the SerializedPublicKeyLength and writes them in * the message * * @param msg * Message to write in */ private void parseSerializedPublicKeyLength(T msg) { if (getVersion().isSSL()) { msg.setPublicKeyLength(getBytesLeft()); } else { msg.setPublicKeyLength(parseIntField(HandshakeByteLength.ENCRYPTED_PREMASTER_SECRET_LENGTH)); } LOGGER.debug("SerializedPublicKeyLength: " + msg.getPublicKeyLength().getValue()); }
protected void preparePremasterSecret(T msg) { msg.getComputations().setPremasterSecret(premasterSecret); LOGGER.debug("PremasterSecret: " + ArrayConverter.bytesToHexString(msg.getComputations().getPremasterSecret().getValue())); }
/** * Writes the SerializedPublicKey of the RSAClientKeyExchangeMessage into * the final byte[] */ private void writeSerializedPublickey(T msg) { appendBytes(msg.getPublicKey().getValue()); LOGGER.debug("SerializedPublicKey: " + ArrayConverter.bytesToHexString(msg.getPublicKey().getValue())); } }
/** * Writes the SerializedPublicKeyLength of the RSAClientKeyExchangeMessage * into the final byte[] */ private void writeSerializedPublicKeyLength(T msg) { appendInt(msg.getPublicKeyLength().getValue(), HandshakeByteLength.ENCRYPTED_PREMASTER_SECRET_LENGTH); LOGGER.debug("SerializedPublicKeyLength: " + msg.getPublicKeyLength().getValue()); }
protected void preparePadding(T msg) { msg.getComputations().setPadding(padding); LOGGER.debug("Padding: " + ArrayConverter.bytesToHexString(msg.getComputations().getPadding().getValue())); }
protected byte[] decryptPremasterSecret() { BigInteger bigIntegerEncryptedPremasterSecret = new BigInteger(1, msg.getPublicKey().getValue()); BigInteger serverPrivateKey = chooser.getServerRSAPrivateKey(); if (chooser.getServerRsaModulus().equals(BigInteger.ZERO)) { LOGGER.warn("RSA Modulus is Zero, returning new byte[0] as decryptedPremasterSecret"); return new byte[0]; } BigInteger decrypted = bigIntegerEncryptedPremasterSecret.modPow(serverPrivateKey, chooser .getServerRsaModulus().abs()); return decrypted.toByteArray(); }
switch (algorithm) { case RSA: return new RSAClientKeyExchangeMessage(config); case ECDHE_ECDSA: case ECDH_ECDSA:
protected void preparePlainPaddedPremasterSecret(T msg) { msg.getComputations().setPlainPaddedPremasterSecret( ArrayConverter.concatenate(new byte[] { 0x00, 0x02 }, padding, new byte[] { 0x00 }, msg .getComputations().getPremasterSecret().getValue())); LOGGER.debug("PlainPaddedPremasterSecret: " + ArrayConverter.bytesToHexString(msg.getComputations().getPlainPaddedPremasterSecret().getValue())); }
protected void prepareClientServerRandom(T msg) { clientServerRandom = ArrayConverter.concatenate(chooser.getClientRandom(), chooser.getServerRandom()); msg.getComputations().setClientServerRandom(clientServerRandom); LOGGER.debug("ClientRandom: " + ArrayConverter.bytesToHexString(msg.getComputations().getClientServerRandom().getValue())); }