protected void prepareSerializedPublicKeyLength(T msg) { msg.setPublicKeyLength(msg.getPublicKey().getValue().length); LOGGER.debug("SerializedPublicKeyLength: " + msg.getPublicKeyLength().getValue()); }
/** * Writes the SerializedPublicKey of the ECDHCLientKeyExchangeMessage into * the final byte[] */ private void writeSerializedPublicKey(T msg) { appendBytes(msg.getPublicKey().getValue()); LOGGER.debug("SerializedPublicKey: " + ArrayConverter.bytesToHexString(msg.getPublicKey().getValue())); }
/** * Reads the next bytes as the SerializedPublicKey and writes them in the * message * * @param msg * Message to write in */ private void parseSerializedPublicKey(ECDHClientKeyExchangeMessage msg) { msg.setPublicKey(parseByteArrayField(msg.getPublicKeyLength().getValue())); LOGGER.debug("SerializedPublicKey: " + ArrayConverter.bytesToHexString(msg.getPublicKey().getValue())); }
protected void prepareSerializedPublicKey(T msg) { msg.setPublicKey(ArrayConverter.concatenate(new byte[] { msg.getEcPointFormat().getValue() }, msg .getEcPointEncoded().getValue())); LOGGER.debug("SerializedPublicKey: " + ArrayConverter.bytesToHexString(msg.getPublicKey().getValue())); }
private void adjustClientPublicKey(ECDHClientKeyExchangeMessage message) { byte[] serializedPoint = message.getPublicKey().getValue(); List<ECPointFormat> pointFormatList = tlsContext.getChooser().getServerSupportedPointFormats(); ECPointFormat[] formatArray = pointFormatList.toArray(new ECPointFormat[pointFormatList.size()]); NamedGroup usedGroup = tlsContext.getChooser().getSelectedNamedGroup(); ECDomainParameters ecParams = getDomainParameters(tlsContext.getChooser().getEcCurveType(), usedGroup); short[] pointFormats = ECCUtilsBCWrapper.convertPointFormats(formatArray); try { ECPublicKeyParameters clientPublicKey = TlsECCUtils.deserializeECPublicKey(pointFormats, ecParams, serializedPoint); tlsContext.setClientEcPublicKey(new CustomECPoint(clientPublicKey.getQ().getRawXCoord().toBigInteger(), clientPublicKey.getQ().getRawYCoord().toBigInteger())); } catch (IOException ex) { LOGGER.info("Could not deserialize EC point (it is possible that some of your modifications made " + "the EC point invalid)"); LOGGER.debug( "EC point that was attempted to be deserialized: " + ArrayConverter.bytesToHexString(serializedPoint), ex); } }
protected void setComputationPublicKey(T msg, boolean clientMode) { if (clientMode) { msg.getComputations().setPublicKey(chooser.getServerEcPublicKey().getX(), chooser.getServerEcPublicKey().getY()); } else { serializedPoint = msg.getPublicKey().getValue(); List<ECPointFormat> pointFormatList = chooser.getServerSupportedPointFormats(); ECPointFormat[] formatArray = pointFormatList.toArray(new ECPointFormat[pointFormatList.size()]); NamedGroup usedGroup = chooser.getSelectedNamedGroup(); ECDomainParameters ecParams = getDomainParameters(chooser.getEcCurveType(), usedGroup); short[] pointFormats = ECCUtilsBCWrapper.convertPointFormats(formatArray); try { ECPublicKeyParameters clientPublicKey = TlsECCUtils.deserializeECPublicKey(pointFormats, ecParams, serializedPoint); ECPoint q = clientPublicKey.getQ(); q = q.normalize(); msg.getComputations().setPublicKey(q.getRawXCoord().toBigInteger(), q.getRawYCoord().toBigInteger()); } catch (IOException ex) { throw new PreparationException("Could not deserialize EC Point: " + ArrayConverter.bytesToHexString(serializedPoint), ex); } } LOGGER.debug("Computation PublicKey: " + msg.getComputations().getPublicKey().toString()); }