Class SSU2Util

java.lang.Object
net.i2p.router.transport.udp.SSU2Util

final class SSU2Util extends Object
SSU2 Utils and constants
Since:
0.9.54
  • Field Details

    • PROTOCOL_VERSION

      public static final int PROTOCOL_VERSION
      See Also:
    • ENABLE_RELAY

      public static final boolean ENABLE_RELAY
      See Also:
    • ENABLE_PEER_TEST

      public static final boolean ENABLE_PEER_TEST
      See Also:
    • ENABLE_PATH_CHALLENGE

      public static final boolean ENABLE_PATH_CHALLENGE
      See Also:
    • KEY_LEN

      public static final int KEY_LEN
      32
    • MAC_LEN

      public static final int MAC_LEN
      See Also:
    • CHACHA_IV_LEN

      public static final int CHACHA_IV_LEN
      See Also:
    • INTRO_KEY_LEN

      public static final int INTRO_KEY_LEN
      See Also:
    • SHORT_HEADER_SIZE

      public static final int SHORT_HEADER_SIZE
      See Also:
    • LONG_HEADER_SIZE

      public static final int LONG_HEADER_SIZE
      See Also:
    • SESSION_HEADER_SIZE

      public static final int SESSION_HEADER_SIZE
      64
    • DEST_CONN_ID_OFFSET

      public static final int DEST_CONN_ID_OFFSET
      See Also:
    • PKT_NUM_OFFSET

      public static final int PKT_NUM_OFFSET
      See Also:
    • PKT_NUM_LEN

      public static final int PKT_NUM_LEN
      See Also:
    • TYPE_OFFSET

      public static final int TYPE_OFFSET
      See Also:
    • VERSION_OFFSET

      public static final int VERSION_OFFSET
      See Also:
    • SHORT_HEADER_FLAGS_OFFSET

      public static final int SHORT_HEADER_FLAGS_OFFSET
      See Also:
    • SHORT_HEADER_FLAGS_LEN

      public static final int SHORT_HEADER_FLAGS_LEN
      See Also:
    • NETID_OFFSET

      public static final int NETID_OFFSET
      See Also:
    • LONG_HEADER_FLAGS_OFFSET

      public static final int LONG_HEADER_FLAGS_OFFSET
      See Also:
    • SRC_CONN_ID_OFFSET

      public static final int SRC_CONN_ID_OFFSET
      See Also:
    • TOKEN_OFFSET

      public static final int TOKEN_OFFSET
      See Also:
    • HEADER_PROT_SAMPLE_LEN

      public static final int HEADER_PROT_SAMPLE_LEN
      See Also:
    • TOTAL_PROT_SAMPLE_LEN

      public static final int TOTAL_PROT_SAMPLE_LEN
      See Also:
    • HEADER_PROT_SAMPLE_1_OFFSET

      public static final int HEADER_PROT_SAMPLE_1_OFFSET
      See Also:
    • HEADER_PROT_SAMPLE_2_OFFSET

      public static final int HEADER_PROT_SAMPLE_2_OFFSET
      See Also:
    • HEADER_PROT_DATA_LEN

      public static final int HEADER_PROT_DATA_LEN
      See Also:
    • HEADER_PROT_1_OFFSET

      public static final int HEADER_PROT_1_OFFSET
      See Also:
    • HEADER_PROT_2_OFFSET

      public static final int HEADER_PROT_2_OFFSET
      See Also:
    • PADDING_MAX

      public static final int PADDING_MAX
      See Also:
    • PADDING_MAX_SESSION_REQUEST

      public static final int PADDING_MAX_SESSION_REQUEST
      See Also:
    • PADDING_MAX_SESSION_CREATED

      public static final int PADDING_MAX_SESSION_CREATED
      See Also:
    • MIN_DATA_LEN

      public static final int MIN_DATA_LEN
      40
      See Also:
    • MIN_LONG_DATA_LEN

      public static final int MIN_LONG_DATA_LEN
      56
      See Also:
    • MIN_HANDSHAKE_DATA_LEN

      public static final int MIN_HANDSHAKE_DATA_LEN
      88
    • MIN_TOKEN_REQUEST_LEN

      public static final int MIN_TOKEN_REQUEST_LEN
      56
      See Also:
    • MIN_RETRY_LEN

      public static final int MIN_RETRY_LEN
      56
      See Also:
    • MIN_SESSION_REQUEST_LEN

      public static final int MIN_SESSION_REQUEST_LEN
      88
    • MIN_SESSION_CREATED_LEN

      public static final int MIN_SESSION_CREATED_LEN
      88
    • MIN_SESSION_CONFIRMED_LEN

      public static final int MIN_SESSION_CONFIRMED_LEN
      380 Any RI, even compressed, will be at least 400 bytes. It has a minimum 387 byte ident and 40 byte sig, neither is compressible. Use 300 just to be safe for compression.
    • FIRST_FRAGMENT_HEADER_SIZE

      public static final int FIRST_FRAGMENT_HEADER_SIZE
      3 byte block header
      See Also:
    • DATA_FOLLOWON_EXTRA_SIZE

      public static final int DATA_FOLLOWON_EXTRA_SIZE
      5 for flag and msg number in followon block
      See Also:
    • FOLLOWON_FRAGMENT_HEADER_SIZE

      public static final int FOLLOWON_FRAGMENT_HEADER_SIZE
      3 byte block header + 4 byte msg ID + 1 byte fragment info = 8
      See Also:
    • DATA_HEADER_SIZE

      public static final int DATA_HEADER_SIZE
      16 byte short header
      See Also:
    • SESSION_REQUEST_FLAG_BYTE

      public static final byte SESSION_REQUEST_FLAG_BYTE
      The message types, 0-10, as bytes
      See Also:
    • SESSION_CREATED_FLAG_BYTE

      public static final byte SESSION_CREATED_FLAG_BYTE
      See Also:
    • SESSION_CONFIRMED_FLAG_BYTE

      public static final byte SESSION_CONFIRMED_FLAG_BYTE
      See Also:
    • DATA_FLAG_BYTE

      public static final byte DATA_FLAG_BYTE
      See Also:
    • PEER_TEST_FLAG_BYTE

      public static final byte PEER_TEST_FLAG_BYTE
      See Also:
    • RETRY_FLAG_BYTE

      public static final byte RETRY_FLAG_BYTE
      See Also:
    • TOKEN_REQUEST_FLAG_BYTE

      public static final byte TOKEN_REQUEST_FLAG_BYTE
      See Also:
    • HOLE_PUNCH_FLAG_BYTE

      public static final byte HOLE_PUNCH_FLAG_BYTE
      See Also:
    • INFO_CREATED

      public static final String INFO_CREATED
      See Also:
    • INFO_CONFIRMED

      public static final String INFO_CONFIRMED
      See Also:
    • INFO_DATA

      public static final String INFO_DATA
      See Also:
    • ZEROLEN

      public static final byte[] ZEROLEN
    • ZEROKEY

      public static final byte[] ZEROKEY
    • RELAY_REQUEST_PROLOGUE

      public static final byte[] RELAY_REQUEST_PROLOGUE
    • RELAY_RESPONSE_PROLOGUE

      public static final byte[] RELAY_RESPONSE_PROLOGUE
    • PEER_TEST_PROLOGUE

      public static final byte[] PEER_TEST_PROLOGUE
    • TEST_ACCEPT

      public static final int TEST_ACCEPT
      See Also:
    • TEST_REJECT_BOB_UNSPEC

      public static final int TEST_REJECT_BOB_UNSPEC
      See Also:
    • TEST_REJECT_BOB_NO_CHARLIE

      public static final int TEST_REJECT_BOB_NO_CHARLIE
      See Also:
    • TEST_REJECT_BOB_LIMIT

      public static final int TEST_REJECT_BOB_LIMIT
      See Also:
    • TEST_REJECT_BOB_SIGFAIL

      public static final int TEST_REJECT_BOB_SIGFAIL
      See Also:
    • TEST_REJECT_BOB_ADDRESS

      public static final int TEST_REJECT_BOB_ADDRESS
      See Also:
    • TEST_REJECT_CHARLIE_UNSPEC

      public static final int TEST_REJECT_CHARLIE_UNSPEC
      See Also:
    • TEST_REJECT_CHARLIE_ADDRESS

      public static final int TEST_REJECT_CHARLIE_ADDRESS
      See Also:
    • TEST_REJECT_CHARLIE_LIMIT

      public static final int TEST_REJECT_CHARLIE_LIMIT
      See Also:
    • TEST_REJECT_CHARLIE_SIGFAIL

      public static final int TEST_REJECT_CHARLIE_SIGFAIL
      See Also:
    • TEST_REJECT_CHARLIE_CONNECTED

      public static final int TEST_REJECT_CHARLIE_CONNECTED
      See Also:
    • TEST_REJECT_CHARLIE_BANNED

      public static final int TEST_REJECT_CHARLIE_BANNED
      See Also:
    • TEST_REJECT_CHARLIE_UNKNOWN_ALICE

      public static final int TEST_REJECT_CHARLIE_UNKNOWN_ALICE
      See Also:
    • RELAY_ACCEPT

      public static final int RELAY_ACCEPT
      See Also:
    • RELAY_REJECT_BOB_UNSPEC

      public static final int RELAY_REJECT_BOB_UNSPEC
      See Also:
    • RELAY_REJECT_BOB_BANNED_CHARLIE

      public static final int RELAY_REJECT_BOB_BANNED_CHARLIE
      See Also:
    • RELAY_REJECT_BOB_LIMIT

      public static final int RELAY_REJECT_BOB_LIMIT
      See Also:
    • RELAY_REJECT_BOB_SIGFAIL

      public static final int RELAY_REJECT_BOB_SIGFAIL
      See Also:
    • RELAY_REJECT_BOB_NO_TAG

      public static final int RELAY_REJECT_BOB_NO_TAG
      See Also:
    • RELAY_REJECT_BOB_UNKNOWN_ALICE

      public static final int RELAY_REJECT_BOB_UNKNOWN_ALICE
      See Also:
    • RELAY_REJECT_CHARLIE_UNSPEC

      public static final int RELAY_REJECT_CHARLIE_UNSPEC
      See Also:
    • RELAY_REJECT_CHARLIE_ADDRESS

      public static final int RELAY_REJECT_CHARLIE_ADDRESS
      See Also:
    • RELAY_REJECT_CHARLIE_LIMIT

      public static final int RELAY_REJECT_CHARLIE_LIMIT
      See Also:
    • RELAY_REJECT_CHARLIE_SIGFAIL

      public static final int RELAY_REJECT_CHARLIE_SIGFAIL
      See Also:
    • RELAY_REJECT_CHARLIE_CONNECTED

      public static final int RELAY_REJECT_CHARLIE_CONNECTED
      See Also:
    • RELAY_REJECT_CHARLIE_BANNED

      public static final int RELAY_REJECT_CHARLIE_BANNED
      See Also:
    • RELAY_REJECT_CHARLIE_UNKNOWN_ALICE

      public static final int RELAY_REJECT_CHARLIE_UNKNOWN_ALICE
      See Also:
    • REASON_UNSPEC

      public static final int REASON_UNSPEC
      See Also:
    • REASON_TERMINATION

      public static final int REASON_TERMINATION
      See Also:
    • REASON_TIMEOUT

      public static final int REASON_TIMEOUT
      See Also:
    • REASON_SHUTDOWN

      public static final int REASON_SHUTDOWN
      See Also:
    • REASON_AEAD

      public static final int REASON_AEAD
      See Also:
    • REASON_OPTIONS

      public static final int REASON_OPTIONS
      See Also:
    • REASON_SIGTYPE

      public static final int REASON_SIGTYPE
      See Also:
    • REASON_SKEW

      public static final int REASON_SKEW
      See Also:
    • REASON_PADDING

      public static final int REASON_PADDING
      See Also:
    • REASON_FRAMING

      public static final int REASON_FRAMING
      See Also:
    • REASON_PAYLOAD

      public static final int REASON_PAYLOAD
      See Also:
    • REASON_MSG1

      public static final int REASON_MSG1
      See Also:
    • REASON_MSG2

      public static final int REASON_MSG2
      See Also:
    • REASON_MSG3

      public static final int REASON_MSG3
      See Also:
    • REASON_FRAME_TIMEOUT

      public static final int REASON_FRAME_TIMEOUT
      See Also:
    • REASON_SIGFAIL

      public static final int REASON_SIGFAIL
      See Also:
    • REASON_S_MISMATCH

      public static final int REASON_S_MISMATCH
      See Also:
    • REASON_BANNED

      public static final int REASON_BANNED
      See Also:
    • REASON_TOKEN

      public static final int REASON_TOKEN
      See Also:
    • REASON_LIMITS

      public static final int REASON_LIMITS
      See Also:
    • REASON_VERSION

      public static final int REASON_VERSION
      See Also:
    • REASON_NETID

      public static final int REASON_NETID
      See Also:
    • REASON_REPLACED

      public static final int REASON_REPLACED
      See Also:
  • Method Details

    • hkdf

      public static byte[] hkdf(I2PAppContext ctx, byte[] key, String info)
      32 byte output, ZEROLEN data
    • 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:
      h - to be included in sig, not included in data
      h2 - may be null, to be included in sig, not included in data
      role - unused
      ip - may be null
      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:
      h - Bob hash to be included in sig, not included in data
      h2 - Charlie hash to be included in sig, not included in data
      ip - non-null
      Returns:
      null on failure
      Since:
      0.9.55
    • 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:
      h - Bob hash to be included in sig, not included in data
      ip - may be null
      port - ignored if ip is null
      token - if nonzero, append it
      Returns:
      null on failure
      Since:
      0.9.55
    • 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:
      h - to be included in sig, not included in data
      h2 - may be null, to be included in sig, not included in data
      data - if desired, leave room at end for sig
      datalen - the length of the data to be signed
      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:
      h2 - may be null
      data - not including relay response token