java.lang.Object
net.i2p.router.transport.udp.SSU2Util
SSU2 Utils and constants.
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int12 bytes, ChaCha20 nonce length.static final byteMessage type flag for data.static final int5 for flag and msg number in followon block.static final int16 byte short header.static final intOffset of destination connection ID in header.static final int3 byte block header.static final int3 byte block header + 4 byte msg ID + 1 byte fragment info = 8.static final intOffset of first header protection region (dest conn ID).static final intOffset of second header protection region (packet number).static final intLength of header protection data in bytes.static final intOffset of first header protection sample.static final intOffset of second header protection sample.static final intLength of header protection sample in bytes.static final byteMessage type flag for hole punch.static final StringHKDF info string for session confirmed key derivation.static final StringHKDF info string for session created header key derivation.static final StringHKDF info string for data packet key derivation.static final int32 bytes, introductory key length.static final intIPv4 address length in bytes.static final intIPv6 address length in bytes.static final int32 bytes, X25519 public key length.static final intOffset of long header flags.static final int32 bytes, long (handshake) header size.static final int16 bytes, MAC tag length.static final intThe newest SSU2 version accepted when establishing.static final intMinimum short-header data message size, 40 bytes.static final intHandshake message type minimum length in bytes (88).static final intLong message type minimum length in bytes (56).static final intRetry message minimum length in bytes (56).static final intSession created minimum length in bytes (88).static final intSession request minimum length in bytes (88).static final intThe oldest SSU2 version accepted when establishing.static final intToken request minimum length in bytes (56).static final intOffset of network ID in header.static final intMaximum padding for data packets.static final intMaximum padding for session created.static final intMaximum padding for session request.static final byteMessage type flag for peer test.static final byte[]Prologue for peer test signatures.static final intLength of packet number field in bytes.static final intOffset of packet number in header.static final intSSU2 protocol version number.static final intAEAD verification failure.static final intPeer is banned.static final intFrame acknowledgment timeout.static final intFraming protocol error.static final intResource limits exceeded.static final intError in session request message.static final intError in session created message.static final intError in session confirmed message.static final intNetwork ID mismatch.static final intOptions parameter mismatch.static final intInvalid padding.static final intPayload data error.static final intSession was replaced by a new connection.static final intSession key mismatch.static final intRouter shutting down.static final intSignature verification failed.static final intSignature type error or mismatch.static final intClock skew exceeds tolerance.static final intTermination requested by remote.static final intConnection timeout.static final intToken validation error.static final intUnspecified reason.static final intProtocol version mismatch.static final intRelay accepted.static final intThe encoded address length value in relay response / peer test data for an IPv4 address.static final intThe encoded address length value in relay response / peer test data for an IPv6 address.static final intOffset of the address length byte in relay response / peer test data.static final intOffset of the IP address bytes in relay response / peer test data.static final intLength of the port field in the relay/peer-test address block.static final intOffset of the 2-byte port in relay response / peer test data.static final intOffset of the version byte in relay response / peer test data.static final intRejected by Bob: Charlie is banned.static final intRejected by Bob: limit reached.static final intRejected by Bob: no tag found.static final intRejected by Bob: signature failure.static final intRejected by Bob: unknown Alice.static final intRejected by Bob: unspecified reason.static final intRejected by Charlie: address mismatch.static final intRejected by Charlie: banned.static final intRejected by Charlie: already connected.static final intRejected by Charlie: limit reached.static final intRejected by Charlie: signature failure.static final intRejected by Charlie: unknown Alice.static final intRejected by Charlie: unspecified reason.static final byte[]Prologue for relay request signatures.static final byte[]Prologue for relay response signatures.static final intThe trailing 8-byte token in a signed relay response with a zero code.static final byteMessage type flag for retry.static final byteMessage type flag for session confirmed.static final byteMessage type flag for session created.static final int64 bytes, combined long header and key.static final byteThe message types, 0-11, as bytes.static final intLength of short header flags in bytes.static final intOffset of short header flags.static final int16 bytes, short (data) header size.static final intOffset of source connection ID in long header.static final intPeer test accepted.static final intRejected by Bob: address mismatch.static final intRejected by Bob: limit reached.static final intRejected by Bob: no Charlie.static final intRejected by Bob: signature failure.static final intRejected by Bob: unspecified reason.static final intRejected by Charlie: address mismatch.static final intRejected by Charlie: banned.static final intRejected by Charlie: already connected.static final intRejected by Charlie: limit reached.static final intRejected by Charlie: signature failure.static final intRejected by Charlie: unknown Alice.static final intRejected by Charlie: unspecified reason.static final intOffset of token in long header.static final byteMessage type flag for token request.static final intTotal header protection sample length for both samples.static final intOffset of message type in header.static final intOffset of protocol version in header.static final byte[]All-zero key of KEY_LEN bytes.static final byte[]Empty byte array, used as HKDF salt.Constructor Summary
ConstructorsMethod Summary
Public MethodsModifier and TypeMethodDescriptionstatic byte[]createPeerTestData(I2PAppContext ctx, Hash h, Hash h2, PeerTestState.Role role, long nonce, byte[] ip, int port, SigningPrivateKey spk) Make the data for the peer test block.static byte[]createRelayRequestData(I2PAppContext ctx, Hash h, Hash h2, long nonce, long tag, byte[] ip, int port, SigningPrivateKey spk) Make the data for the relay request block.static byte[]createRelayResponseData(I2PAppContext ctx, Hash h, int code, long nonce, byte[] ip, int port, SigningPrivateKey spk, long token) Make the data for the relay response block.static intgetRelayDataAddrLen(byte[] data) Parse the encoded address length byte out of relay response / peer test data.static byte[]getRelayDataIP(byte[] data, int addrLen) Parse the IP address out of relay response / peer test data.static intgetRelayDataPort(byte[] data) Parse the 2-byte port out of relay response / peer test data.static longgetRelayResponseToken(byte[] data) Parse the trailing token out of the relay response signed data.static byte[]hkdf(I2PAppContext ctx, byte[] key, String info) 32 byte output, ZEROLEN data.static booleanisSupportedVersion(int version) True if the given version is accepted when establishing.static booleanisValidRelayDataAddrLen(int addrLen) Is the given encoded address length valid (IPv4 or IPv6)?(package private) static intpqCreatedExtra(int version) Bytes the Noise F token adds to the session created (message 2) for the post-quantum versions: the ML-KEM ciphertext plus its MAC.(package private) static intpqRequestExtra(int version) Bytes the Noise F token adds to the session request (message 1) for the post-quantum versions: the ML-KEM encapsulation key plus its MAC.static Signaturesign(I2PAppContext ctx, byte[] prologue, Hash h, Hash h2, byte[] data, int datalen, SigningPrivateKey spk) Sign the relay or peer test data, using the prologue and hash as the initial data, and then the provided data.static StringterminationCodeToString(int code) Convert a termination reason code to a human-readable string.static byte[]trimRelayResponseToken(byte[] data) Trim the trailing token off the relay response signed data, returning the portion that was signed.static booleanvalidateSig(I2PAppContext ctx, byte[] prologue, Hash h, Hash h2, byte[] data, SigningPublicKey spk) Validate the signed relay or peer test data, using the prologue and hash as the initial data, and then the provided data which ends with a signature of the specified type.
Field Details
PROTOCOL_VERSION
MIN_SUPPORTED_VERSION
public static final int MIN_SUPPORTED_VERSIONThe oldest SSU2 version accepted when establishing. Reject earlier versions as unsupported.- See Also:
MAX_SUPPORTED_VERSION
public static final int MAX_SUPPORTED_VERSIONThe newest SSU2 version accepted when establishing.- See Also:
KEY_LEN
public static final int KEY_LEN32 bytes, X25519 public key length.MAC_LEN
CHACHA_IV_LEN
INTRO_KEY_LEN
public static final int INTRO_KEY_LEN32 bytes, introductory key length.- See Also:
SHORT_HEADER_SIZE
public static final int SHORT_HEADER_SIZE16 bytes, short (data) header size.- See Also:
LONG_HEADER_SIZE
public static final int LONG_HEADER_SIZE32 bytes, long (handshake) header size.- See Also:
SESSION_HEADER_SIZE
public static final int SESSION_HEADER_SIZE64 bytes, combined long header and key.DEST_CONN_ID_OFFSET
public static final int DEST_CONN_ID_OFFSETOffset of destination connection ID in header.- See Also:
PKT_NUM_OFFSET
public static final int PKT_NUM_OFFSETOffset of packet number in header.- See Also:
PKT_NUM_LEN
public static final int PKT_NUM_LENLength of packet number field in bytes.- See Also:
TYPE_OFFSET
VERSION_OFFSET
public static final int VERSION_OFFSETOffset of protocol version in header.- See Also:
SHORT_HEADER_FLAGS_OFFSET
public static final int SHORT_HEADER_FLAGS_OFFSETOffset of short header flags.- See Also:
SHORT_HEADER_FLAGS_LEN
public static final int SHORT_HEADER_FLAGS_LENLength of short header flags in bytes.- See Also:
NETID_OFFSET
LONG_HEADER_FLAGS_OFFSET
public static final int LONG_HEADER_FLAGS_OFFSETOffset of long header flags.- See Also:
SRC_CONN_ID_OFFSET
public static final int SRC_CONN_ID_OFFSETOffset of source connection ID in long header.- See Also:
TOKEN_OFFSET
HEADER_PROT_SAMPLE_LEN
public static final int HEADER_PROT_SAMPLE_LENLength of header protection sample in bytes.- See Also:
TOTAL_PROT_SAMPLE_LEN
public static final int TOTAL_PROT_SAMPLE_LENTotal header protection sample length for both samples.- See Also:
HEADER_PROT_SAMPLE_1_OFFSET
public static final int HEADER_PROT_SAMPLE_1_OFFSETOffset of first header protection sample.- See Also:
HEADER_PROT_SAMPLE_2_OFFSET
public static final int HEADER_PROT_SAMPLE_2_OFFSETOffset of second header protection sample.- See Also:
HEADER_PROT_DATA_LEN
public static final int HEADER_PROT_DATA_LENLength of header protection data in bytes.- See Also:
HEADER_PROT_1_OFFSET
public static final int HEADER_PROT_1_OFFSETOffset of first header protection region (dest conn ID).- See Also:
HEADER_PROT_2_OFFSET
public static final int HEADER_PROT_2_OFFSETOffset of second header protection region (packet number).- See Also:
PADDING_MAX
PADDING_MAX_SESSION_REQUEST
public static final int PADDING_MAX_SESSION_REQUESTMaximum padding for session request.- See Also:
PADDING_MAX_SESSION_CREATED
public static final int PADDING_MAX_SESSION_CREATEDMaximum padding for session created.- See Also:
MIN_DATA_LEN
public static final int MIN_DATA_LENMinimum short-header data message size, 40 bytes. No minimum here includes the IP or UDP headers.- See Also:
MIN_LONG_DATA_LEN
public static final int MIN_LONG_DATA_LENLong message type minimum length in bytes (56).- See Also:
MIN_HANDSHAKE_DATA_LEN
public static final int MIN_HANDSHAKE_DATA_LENHandshake message type minimum length in bytes (88).MIN_TOKEN_REQUEST_LEN
public static final int MIN_TOKEN_REQUEST_LENToken request minimum length in bytes (56).- See Also:
MIN_RETRY_LEN
public static final int MIN_RETRY_LENRetry message minimum length in bytes (56).- See Also:
MIN_SESSION_REQUEST_LEN
public static final int MIN_SESSION_REQUEST_LENSession request minimum length in bytes (88).MIN_SESSION_CREATED_LEN
public static final int MIN_SESSION_CREATED_LENSession created minimum length in bytes (88).FIRST_FRAGMENT_HEADER_SIZE
public static final int FIRST_FRAGMENT_HEADER_SIZE3 byte block header.- See Also:
DATA_FOLLOWON_EXTRA_SIZE
public static final int DATA_FOLLOWON_EXTRA_SIZE5 for flag and msg number in followon block.- See Also:
FOLLOWON_FRAGMENT_HEADER_SIZE
public static final int FOLLOWON_FRAGMENT_HEADER_SIZE3 byte block header + 4 byte msg ID + 1 byte fragment info = 8.- See Also:
DATA_HEADER_SIZE
SESSION_REQUEST_FLAG_BYTE
public static final byte SESSION_REQUEST_FLAG_BYTEThe message types, 0-11, as bytes. Message type flag for session request.- See Also:
SESSION_CREATED_FLAG_BYTE
public static final byte SESSION_CREATED_FLAG_BYTEMessage type flag for session created.- See Also:
SESSION_CONFIRMED_FLAG_BYTE
public static final byte SESSION_CONFIRMED_FLAG_BYTEMessage type flag for session confirmed.- See Also:
DATA_FLAG_BYTE
PEER_TEST_FLAG_BYTE
public static final byte PEER_TEST_FLAG_BYTEMessage type flag for peer test.- See Also:
RETRY_FLAG_BYTE
TOKEN_REQUEST_FLAG_BYTE
public static final byte TOKEN_REQUEST_FLAG_BYTEMessage type flag for token request.- See Also:
HOLE_PUNCH_FLAG_BYTE
public static final byte HOLE_PUNCH_FLAG_BYTEMessage type flag for hole punch.- See Also:
INFO_CREATED
HKDF info string for session created header key derivation.- See Also:
INFO_CONFIRMED
HKDF info string for session confirmed key derivation.- See Also:
INFO_DATA
HKDF info string for data packet key derivation.- See Also:
ZEROLEN
public static final byte[] ZEROLENEmpty byte array, used as HKDF salt.ZEROKEY
public static final byte[] ZEROKEYAll-zero key of KEY_LEN bytes.RELAY_REQUEST_PROLOGUE
public static final byte[] RELAY_REQUEST_PROLOGUEPrologue for relay request signatures.RELAY_RESPONSE_PROLOGUE
public static final byte[] RELAY_RESPONSE_PROLOGUEPrologue for relay response signatures.PEER_TEST_PROLOGUE
public static final byte[] PEER_TEST_PROLOGUEPrologue for peer test signatures.TEST_ACCEPT
TEST_REJECT_BOB_UNSPEC
public static final int TEST_REJECT_BOB_UNSPECRejected by Bob: unspecified reason.- See Also:
TEST_REJECT_BOB_NO_CHARLIE
public static final int TEST_REJECT_BOB_NO_CHARLIERejected by Bob: no Charlie.- See Also:
TEST_REJECT_BOB_LIMIT
public static final int TEST_REJECT_BOB_LIMITRejected by Bob: limit reached.- See Also:
TEST_REJECT_BOB_SIGFAIL
public static final int TEST_REJECT_BOB_SIGFAILRejected by Bob: signature failure.- See Also:
TEST_REJECT_BOB_ADDRESS
public static final int TEST_REJECT_BOB_ADDRESSRejected by Bob: address mismatch.- See Also:
TEST_REJECT_CHARLIE_UNSPEC
public static final int TEST_REJECT_CHARLIE_UNSPECRejected by Charlie: unspecified reason.- See Also:
TEST_REJECT_CHARLIE_ADDRESS
public static final int TEST_REJECT_CHARLIE_ADDRESSRejected by Charlie: address mismatch.- See Also:
TEST_REJECT_CHARLIE_LIMIT
public static final int TEST_REJECT_CHARLIE_LIMITRejected by Charlie: limit reached.- See Also:
TEST_REJECT_CHARLIE_SIGFAIL
public static final int TEST_REJECT_CHARLIE_SIGFAILRejected by Charlie: signature failure.- See Also:
TEST_REJECT_CHARLIE_CONNECTED
public static final int TEST_REJECT_CHARLIE_CONNECTEDRejected by Charlie: already connected.- See Also:
TEST_REJECT_CHARLIE_BANNED
public static final int TEST_REJECT_CHARLIE_BANNEDRejected by Charlie: banned.- See Also:
TEST_REJECT_CHARLIE_UNKNOWN_ALICE
public static final int TEST_REJECT_CHARLIE_UNKNOWN_ALICERejected by Charlie: unknown Alice.- See Also:
RELAY_ACCEPT
RELAY_REJECT_BOB_UNSPEC
public static final int RELAY_REJECT_BOB_UNSPECRejected by Bob: unspecified reason.- See Also:
RELAY_REJECT_BOB_BANNED_CHARLIE
public static final int RELAY_REJECT_BOB_BANNED_CHARLIERejected by Bob: Charlie is banned.- See Also:
RELAY_REJECT_BOB_LIMIT
public static final int RELAY_REJECT_BOB_LIMITRejected by Bob: limit reached.- See Also:
RELAY_REJECT_BOB_SIGFAIL
public static final int RELAY_REJECT_BOB_SIGFAILRejected by Bob: signature failure.- See Also:
RELAY_REJECT_BOB_NO_TAG
public static final int RELAY_REJECT_BOB_NO_TAGRejected by Bob: no tag found.- See Also:
RELAY_REJECT_BOB_UNKNOWN_ALICE
public static final int RELAY_REJECT_BOB_UNKNOWN_ALICERejected by Bob: unknown Alice.- See Also:
RELAY_REJECT_CHARLIE_UNSPEC
public static final int RELAY_REJECT_CHARLIE_UNSPECRejected by Charlie: unspecified reason.- See Also:
RELAY_REJECT_CHARLIE_ADDRESS
public static final int RELAY_REJECT_CHARLIE_ADDRESSRejected by Charlie: address mismatch.- See Also:
RELAY_REJECT_CHARLIE_LIMIT
public static final int RELAY_REJECT_CHARLIE_LIMITRejected by Charlie: limit reached.- See Also:
RELAY_REJECT_CHARLIE_SIGFAIL
public static final int RELAY_REJECT_CHARLIE_SIGFAILRejected by Charlie: signature failure.- See Also:
RELAY_REJECT_CHARLIE_CONNECTED
public static final int RELAY_REJECT_CHARLIE_CONNECTEDRejected by Charlie: already connected.- See Also:
RELAY_REJECT_CHARLIE_BANNED
public static final int RELAY_REJECT_CHARLIE_BANNEDRejected by Charlie: banned.- See Also:
RELAY_REJECT_CHARLIE_UNKNOWN_ALICE
public static final int RELAY_REJECT_CHARLIE_UNKNOWN_ALICERejected by Charlie: unknown Alice.- See Also:
REASON_UNSPEC
REASON_TERMINATION
public static final int REASON_TERMINATIONTermination requested by remote.- See Also:
REASON_TIMEOUT
REASON_SHUTDOWN
REASON_AEAD
REASON_OPTIONS
REASON_SIGTYPE
public static final int REASON_SIGTYPESignature type error or mismatch.- See Also:
REASON_SKEW
REASON_PADDING
REASON_FRAMING
REASON_PAYLOAD
REASON_MSG1
REASON_MSG2
REASON_MSG3
public static final int REASON_MSG3Error in session confirmed message.- See Also:
REASON_FRAME_TIMEOUT
public static final int REASON_FRAME_TIMEOUTFrame acknowledgment timeout.- See Also:
REASON_SIGFAIL
REASON_S_MISMATCH
REASON_BANNED
REASON_TOKEN
REASON_LIMITS
REASON_VERSION
REASON_NETID
REASON_REPLACED
public static final int REASON_REPLACEDSession was replaced by a new connection.- See Also:
RELAY_RESPONSE_TOKEN_LEN
public static final int RELAY_RESPONSE_TOKEN_LENThe trailing 8-byte token in a signed relay response with a zero code. When present it is appended after the signature.- See Also:
IPV4_LEN
IPV6_LEN
RELAY_DATA_PORT_LEN
public static final int RELAY_DATA_PORT_LENLength of the port field in the relay/peer-test address block.- See Also:
RELAY_DATA_VERSION_OFFSET
public static final int RELAY_DATA_VERSION_OFFSETOffset of the version byte in relay response / peer test data.- See Also:
RELAY_DATA_ADDR_LEN_OFFSET
public static final int RELAY_DATA_ADDR_LEN_OFFSETOffset of the address length byte in relay response / peer test data. The byte encodes the IP address length plus the port field length.- See Also:
RELAY_DATA_PORT_OFFSET
public static final int RELAY_DATA_PORT_OFFSETOffset of the 2-byte port in relay response / peer test data.- See Also:
RELAY_DATA_IP_OFFSET
public static final int RELAY_DATA_IP_OFFSETOffset of the IP address bytes in relay response / peer test data.- See Also:
RELAY_DATA_ADDR_LEN_IPV4
public static final int RELAY_DATA_ADDR_LEN_IPV4The encoded address length value in relay response / peer test data for an IPv4 address.- See Also:
RELAY_DATA_ADDR_LEN_IPV6
public static final int RELAY_DATA_ADDR_LEN_IPV6The encoded address length value in relay response / peer test data for an IPv6 address.- See Also:
Constructor Details
SSU2Util
private SSU2Util()Utility class, not intended for instantiation.
Method Details
isSupportedVersion
public static boolean isSupportedVersion(int version) True if the given version is accepted when establishing. The only supported versions are inMIN_SUPPORTED_VERSIONtoMAX_SUPPORTED_VERSIONinclusive.- Parameters:
version- the peer's SSU2 version- Returns:
- true if the version is supported
pqRequestExtra
static int pqRequestExtra(int version) Bytes the Noise F token adds to the session request (message 1) for the post-quantum versions: the ML-KEM encapsulation key plus its MAC. Zero for version 2, which has no PQ frame. Noise writes this frame between the ephemeral key and the encrypted payload, so the payload staging offset, the packet length, and the padding budget all have to account for it. An unsupported version is an error rather than a zero-length frame, which would silently omit the frame and fail the tag check.- Parameters:
version- the negotiated SSU2 version- Returns:
- the PQ frame length in bytes, 0 for version 2
- Throws:
IllegalArgumentException- if the version is not 2, 3 or 4
pqCreatedExtra
static int pqCreatedExtra(int version) Bytes the Noise F token adds to the session created (message 2) for the post-quantum versions: the ML-KEM ciphertext plus its MAC. Zero for version 2, which has no PQ frame. Same position rules aspqRequestExtra(int), but the ciphertext is smaller than the encapsulation key for MLKEM-768, which is why a session created fits a smaller MTU than a session request.- Parameters:
version- the negotiated SSU2 version- Returns:
- the PQ frame length in bytes, 0 for version 2
- Throws:
IllegalArgumentException- if the version is not 2, 3 or 4
terminationCodeToString
Convert a termination reason code to a human-readable string.- Parameters:
code- one of the REASON_* constants- Returns:
- a short phrase naming the termination reason, or a string naming the unknown code when it is not one of the REASON_* constants
hkdf
32 byte output, ZEROLEN data.- Parameters:
ctx- the application context, providing the HMAC generatorkey- the input keying materialinfo- the ASCII info string identifying this derivation, "" if none- Returns:
- a newly allocated 32-byte output array
createPeerTestData
public static byte[] createPeerTestData(I2PAppContext ctx, Hash h, Hash h2, PeerTestState.Role role, long nonce, byte[] ip, int port, SigningPrivateKey spk) Make the data for the peer test block.- Parameters:
ctx- the application context, for the clock and DSA serviceh- to be included in sig, not included in datah2- may be null, to be included in sig, not included in datarole- accepted but never read; any value is ignorednonce- the peer's nonce, written into the signed dataip- may be nullport- the peer's UDP port number, written into the data only if ip is non-nullspk- the signing key- Returns:
- null on failure
createRelayRequestData
public static byte[] createRelayRequestData(I2PAppContext ctx, Hash h, Hash h2, long nonce, long tag, byte[] ip, int port, SigningPrivateKey spk) Make the data for the relay request block.- Parameters:
ctx- the application context, for the clock and DSA serviceh- Bob hash to be included in sig, not included in datah2- Charlie hash to be included in sig, not included in datanonce- the request nonce to echo in the signed datatag- the request's per-tunnel tag, written into the signed dataip- non-nullport- the OBEP's UDP port numberspk- the signing key- Returns:
- null on failure
getRelayDataAddrLen
public static int getRelayDataAddrLen(byte[] data) Parse the encoded address length byte out of relay response / peer test data. The byte encodes the IP address length plus the port field length.- Parameters:
data- the data after the signature- Returns:
- the encoded address length
isValidRelayDataAddrLen
public static boolean isValidRelayDataAddrLen(int addrLen) Is the given encoded address length valid (IPv4 or IPv6)?- Parameters:
addrLen- the encoded address length- Returns:
- true if valid
getRelayDataPort
public static int getRelayDataPort(byte[] data) Parse the 2-byte port out of relay response / peer test data.- Parameters:
data- the data after the signature- Returns:
- the 16-bit UDP port number decoded from the 2-byte field
getRelayDataIP
public static byte[] getRelayDataIP(byte[] data, int addrLen) Parse the IP address out of relay response / peer test data.- Parameters:
data- the data after the signatureaddrLen- the encoded address length- Returns:
- the IP address bytes
getRelayResponseToken
public static long getRelayResponseToken(byte[] data) Parse the trailing token out of the relay response signed data.- Parameters:
data- the signed data- Returns:
- the 8-byte relay token value carried in the trailer
- Throws:
ArrayIndexOutOfBoundsException- if the token is not present
trimRelayResponseToken
public static byte[] trimRelayResponseToken(byte[] data) Trim the trailing token off the relay response signed data, returning the portion that was signed.- Parameters:
data- the signed data- Returns:
- the data without the trailing token
createRelayResponseData
public static byte[] createRelayResponseData(I2PAppContext ctx, Hash h, int code, long nonce, byte[] ip, int port, SigningPrivateKey spk, long token) Make the data for the relay response block.- Parameters:
ctx- the application context, for the clock and DSA serviceh- Bob hash to be included in sig, not included in datacode- the termination code, written into the first payload bytenonce- the request nonce to echo in the signed dataip- may be nullport- the UDP port number if ip is nullspk- the signing keytoken- if nonzero, append it- Returns:
- null on failure
sign
public static Signature sign(I2PAppContext ctx, byte[] prologue, Hash h, Hash h2, byte[] data, int datalen, SigningPrivateKey spk) Sign the relay or peer test data, using the prologue and hash as the initial data, and then the provided data.- Parameters:
ctx- the application context, providing the DSA serviceprologue- the protocol-specific prologue prepended to the signed bufferh- to be included in sig, not included in datah2- may be null, to be included in sig, not included in datadata- if desired, leave room at end for sigdatalen- the length of the data to be signedspk- the signing key- Returns:
- null on failure
validateSig
public static boolean validateSig(I2PAppContext ctx, byte[] prologue, Hash h, Hash h2, byte[] data, SigningPublicKey spk) Validate the signed relay or peer test data, using the prologue and hash as the initial data, and then the provided data which ends with a signature of the specified type.- Parameters:
ctx- the application context, providing the DSA serviceprologue- the protocol-specific prologue prepended to the verified bufferh- Bob hash prepended to the verified buffer; a null value fails validationh2- may be nulldata- not including relay response tokenspk- the key the appended signature was made with- Returns:
- true if the trailing signature of data verifies against the key