/** * Checks if the message has Extensions * * @return True if the message has Extensions */ protected boolean hasExtensions() { return msg.getExtensionBytes() != null; }
/** * Writes the ExtensionBytes of the message into the final byte[] */ protected void writeExtensionBytes() { appendBytes(msg.getExtensionBytes().getValue()); LOGGER.debug("ExtensionBytes: " + ArrayConverter.bytesToHexString(msg.getExtensionBytes().getValue())); }
protected void prepareExtensionLength() { msg.setExtensionsLength(msg.getExtensionBytes().getValue().length); LOGGER.debug("ExtensionLength: " + msg.getExtensionsLength().getValue()); }
protected void prepareExtensions() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (msg.getExtensions() != null) { for (ExtensionMessage extensionMessage : msg.getExtensions()) { HandshakeMessageType handshakeMessageType = msg.getHandshakeMessageType(); if (extensionMessage instanceof HRRKeyShareExtensionMessage) { handshakeMessageType = HandshakeMessageType.HELLO_RETRY_REQUEST; } ExtensionHandler handler = HandlerFactory.getExtensionHandler(chooser.getContext(), extensionMessage.getExtensionTypeConstant(), handshakeMessageType); handler.getPreparator(extensionMessage).prepare(); try { stream.write(extensionMessage.getExtensionBytes().getValue()); } catch (IOException ex) { throw new PreparationException("Could not write ExtensionBytes to byte[]", ex); } } } msg.setExtensionBytes(stream.toByteArray()); LOGGER.debug("ExtensionBytes: " + ArrayConverter.bytesToHexString(msg.getExtensionBytes().getValue())); }
protected void afterPrepareExtensions() { ByteArrayOutputStream stream = new ByteArrayOutputStream(); if (msg.getExtensions() != null) { for (ExtensionMessage extensionMessage : msg.getExtensions()) { HandshakeMessageType handshakeMessageType = msg.getHandshakeMessageType(); if (extensionMessage instanceof HRRKeyShareExtensionMessage) { // TODO // fix // design // flaw handshakeMessageType = HandshakeMessageType.HELLO_RETRY_REQUEST; } ExtensionHandler handler = HandlerFactory.getExtensionHandler(chooser.getContext(), extensionMessage.getExtensionTypeConstant(), handshakeMessageType); Preparator preparator = handler.getPreparator(extensionMessage); if (handler instanceof PreSharedKeyExtensionHandler && msg instanceof ClientHelloMessage && chooser.getConnectionEndType() == ConnectionEndType.CLIENT) { ((PreSharedKeyExtensionPreparator) preparator).setClientHello((ClientHelloMessage) msg); preparator.afterPrepare(); } try { stream.write(extensionMessage.getExtensionBytes().getValue()); } catch (IOException ex) { throw new PreparationException("Could not write ExtensionBytes to byte[]", ex); } } } msg.setExtensionBytes(stream.toByteArray()); LOGGER.debug("ExtensionBytes: " + ArrayConverter.bytesToHexString(msg.getExtensionBytes().getValue())); }