@Override protected SrpClientKeyExchangeMessage createHandshakeMessage() { return new SrpClientKeyExchangeMessage(); }
private void prepareSalt(SrpClientKeyExchangeMessage msg) { msg.setSalt(msg.getComputations().getSalt()); LOGGER.debug("Salt: " + ArrayConverter.bytesToHexString(msg.getSalt().getValue())); }
private void prepareGeneratorLength(SrpClientKeyExchangeMessage msg) { msg.setGeneratorLength(msg.getGenerator().getValue().length); LOGGER.debug("Generator Length: " + msg.getGeneratorLength().getValue()); }
private void prepareModulusLength(SrpClientKeyExchangeMessage msg) { msg.setModulusLength(msg.getModulus().getValue().length); LOGGER.debug("Modulus Length: " + msg.getModulusLength().getValue()); } }
private void prepareSaltLength(SrpClientKeyExchangeMessage msg) { msg.setSaltLength(msg.getSalt().getValue().length); LOGGER.debug("Salt Length: " + msg.getSaltLength().getValue()); }
private void preparePublicKeyLength(SrpClientKeyExchangeMessage msg) { msg.setPublicKeyLength(msg.getPublicKey().getValue().length); LOGGER.debug("PublicKeyLength: " + msg.getPublicKeyLength().getValue()); }
private void prepareGenerator(SrpClientKeyExchangeMessage msg) { msg.setGenerator(msg.getComputations().getGenerator().getByteArray()); LOGGER.debug("Generator: " + ArrayConverter.bytesToHexString(msg.getGenerator().getValue())); }
private void prepareModulus(SrpClientKeyExchangeMessage msg) { msg.setModulus(msg.getComputations().getModulus().getByteArray()); LOGGER.debug("Modulus: " + ArrayConverter.bytesToHexString(msg.getModulus().getValue())); }
/** * Reads the next bytes as the PublicKey and writes them in the message * * @param msg * Message to write in */ private void parsePublicKey(SrpClientKeyExchangeMessage message) { message.setPublicKey(parseByteArrayField(message.getPublicKeyLength().getValue())); LOGGER.debug("PublicKey: " + ArrayConverter.bytesToHexString(message.getPublicKey().getValue())); } }
@Override public void prepareComputations() { if (getComputations() == null) { computations = new SRPClientComputations(); } }
/** * Reads the next bytes as the PublicKeyLength and writes them in the * message * * @param msg * Message to write in */ private void parsePublicKeyLength(SrpClientKeyExchangeMessage message) { message.setPublicKeyLength(parseIntField(HandshakeByteLength.SRP_PUBLICKEY_LENGTH)); LOGGER.debug("PublicKeyLength: " + message.getPublicKeyLength().getValue()); }
private void preparePublicKey(SrpClientKeyExchangeMessage msg) { msg.setPublicKey(clientPublicKey.toByteArray()); LOGGER.debug("PublicKey: " + ArrayConverter.bytesToHexString(msg.getPublicKey().getValue())); }
@Override public void prepareAfterParse(boolean clientMode) { if (!clientMode) { BigInteger privateKey = chooser.getSRPServerPrivateKey(); BigInteger clientPublic = new BigInteger(1, msg.getPublicKey().getValue()); msg.prepareComputations(); premasterSecret = calculatePremasterSecretServer(chooser.getSRPModulus(), chooser.getSRPGenerator(), privateKey, chooser.getSRPServerPublicKey(), clientPublic, chooser.getSRPServerSalt(), chooser.getSRPIdentity(), chooser.getSRPPassword()); preparePremasterSecret(msg); prepareClientServerRandom(msg); } }
@Override public void prepareHandshakeMessageContents() { LOGGER.debug("Preparing SRPClientExchangeMessage"); msg.prepareComputations(); setComputationGenerator(msg); setComputationModulus(msg); setComputationPrivateKey(msg); setComputationServerPublicKey(msg); setComputationSalt(msg); setSRPIdentity(msg); setSRPPassword(msg); clientPublicKey = calculatePublicKey(msg.getComputations().getGenerator().getValue(), msg.getComputations() .getModulus().getValue(), msg.getComputations().getPrivateKey().getValue()); prepareModulus(msg); prepareModulusLength(msg); prepareGenerator(msg); prepareGeneratorLength(msg); prepareSalt(msg); prepareSaltLength(msg); preparePublicKey(msg); preparePublicKeyLength(msg); premasterSecret = calculateClientPremasterSecret(msg.getComputations().getModulus().getValue(), msg .getComputations().getGenerator().getValue(), msg.getComputations().getPrivateKey().getValue(), msg .getComputations().getServerPublicKey().getValue(), clientPublicKey, msg.getComputations().getSalt() .getValue(), msg.getComputations().getSRPIdentity().getValue(), msg.getComputations().getSRPPassword() .getValue()); preparePremasterSecret(msg); prepareClientServerRandom(msg); }
/** * Writes the SerializedPublicKeyLength of the SrpClientKeyExchangeMessage * into the final byte[] */ private void writeSerializedPublicKeyLength(SrpClientKeyExchangeMessage msg) { appendInt(msg.getPublicKeyLength().getValue(), HandshakeByteLength.SRP_PUBLICKEY_LENGTH); LOGGER.debug("SerializedPublicKexLength: " + msg.getPublicKeyLength().getValue()); }
/** * Writes the SerializedPublicKey of the SrpClientKeyExchangeMessage into * the final byte[] */ private void writeSerializedPublicKey(SrpClientKeyExchangeMessage msg) { appendBytes(msg.getPublicKey().getValue()); LOGGER.debug("SerializedPublicKey: " + ArrayConverter.bytesToHexString(msg.getPublicKey().getValue())); } }
private void setComputationSalt(SrpClientKeyExchangeMessage msg) { msg.getComputations().setSalt(chooser.getSRPServerSalt()); LOGGER.debug("Salt used for Computations: " + msg.getComputations().getSalt()); }
private void setSRPIdentity(SrpClientKeyExchangeMessage msg) { msg.getComputations().setSRPIdentity(chooser.getSRPIdentity()); LOGGER.debug("SRP Identity used for Computations: " + msg.getComputations().getSRPIdentity()); }
case SRP_SHA_RSA: case SRP_SHA: return new SrpClientKeyExchangeMessage(config); case VKO_GOST01: case VKO_GOST12:
private void setSRPPassword(SrpClientKeyExchangeMessage msg) { msg.getComputations().setSRPPassword(chooser.getSRPPassword()); LOGGER.debug("SRP Password used for Computations: " + msg.getComputations().getSRPPassword()); }