final class SSU2Util extends Object
| Modifier and Type | Field and Description |
|---|---|
static int | CHACHA_IV_LEN12 bytes, ChaCha20 nonce length |
static byte | DATA_FLAG_BYTEMessage type flag for data |
static int | DATA_FOLLOWON_EXTRA_SIZE5 for flag and msg number in followon block |
static int | DATA_HEADER_SIZE16 byte short header |
static int | DEST_CONN_ID_OFFSETOffset of destination connection ID in header |
static int | FIRST_FRAGMENT_HEADER_SIZE3 byte block header |
static int | FOLLOWON_FRAGMENT_HEADER_SIZE3 byte block header + 4 byte msg ID + 1 byte fragment info = 8 |
static int | HEADER_PROT_1_OFFSETOffset of first header protection region (dest conn ID) |
static int | HEADER_PROT_2_OFFSETOffset of second header protection region (packet number) |
static int | HEADER_PROT_DATA_LENLength of header protection data in bytes |
static int | HEADER_PROT_SAMPLE_1_OFFSETOffset of first header protection sample |
static int | HEADER_PROT_SAMPLE_2_OFFSETOffset of second header protection sample |
static int | HEADER_PROT_SAMPLE_LENLength of header protection sample in bytes |
static byte | HOLE_PUNCH_FLAG_BYTEMessage type flag for hole punch |
static String | INFO_CONFIRMEDHKDF info string for session confirmed key derivation |
static String | INFO_CREATEDHKDF info string for session created header key derivation |
static String | INFO_DATAHKDF info string for data packet key derivation |
static int | INTRO_KEY_LEN32 bytes, introductory key length |
static int | KEY_LEN32 bytes, X25519 public key length |
static int | LONG_HEADER_FLAGS_OFFSETOffset of long header flags |
static int | LONG_HEADER_SIZE32 bytes, long (handshake) header size |
static int | MAC_LEN16 bytes, MAC tag length |
static int | MIN_DATA_LENShort message type (e.g. |
static int | MIN_HANDSHAKE_DATA_LENHandshake message type minimum length in bytes (88). |
static int | MIN_LONG_DATA_LENLong message type minimum length in bytes (56). |
static int | MIN_RETRY_LENRetry message minimum length in bytes (56). |
static int | MIN_SESSION_CREATED_LENSession created minimum length in bytes (88). |
static int | MIN_SESSION_REQUEST_LENSession request minimum length in bytes (88). |
static int | MIN_TOKEN_REQUEST_LENToken request minimum length in bytes (56). |
static int | NETID_OFFSETOffset of network ID in header |
static int | PADDING_MAXMaximum padding for data packets |
static int | PADDING_MAX_SESSION_CREATEDMaximum padding for session created |
static int | PADDING_MAX_SESSION_REQUESTMaximum padding for session request |
static byte | PEER_TEST_FLAG_BYTEMessage type flag for peer test |
static byte[] | PEER_TEST_PROLOGUEPrologue for peer test signatures |
static int | PKT_NUM_LENLength of packet number field in bytes |
static int | PKT_NUM_OFFSETOffset of packet number in header |
static int | PROTOCOL_VERSIONSSU2 protocol version number |
static int | REASON_AEADAEAD verification failure |
static int | REASON_BANNEDPeer is banned |
static int | REASON_FRAME_TIMEOUTFrame acknowledgment timeout |
static int | REASON_FRAMINGFraming protocol error |
static int | REASON_LIMITSResource limits exceeded |
static int | REASON_MSG1Error in session request message |
static int | REASON_MSG2Error in session created message |
static int | REASON_MSG3Error in session confirmed message |
static int | REASON_NETIDNetwork ID mismatch |
static int | REASON_OPTIONSOptions parameter mismatch |
static int | REASON_PADDINGInvalid padding |
static int | REASON_PAYLOADPayload data error |
static int | REASON_REPLACEDSession was replaced by a new connection |
static int | REASON_S_MISMATCHSession key mismatch |
static int | REASON_SHUTDOWNRouter shutting down |
static int | REASON_SIGFAILSignature verification failed |
static int | REASON_SIGTYPESignature type error or mismatch |
static int | REASON_SKEWClock skew exceeds tolerance |
static int | REASON_TERMINATIONTermination requested by remote |
static int | REASON_TIMEOUTConnection timeout |
static int | REASON_TOKENToken validation error |
static int | REASON_UNSPECUnspecified reason |
static int | REASON_VERSIONProtocol version mismatch |
static int | RELAY_ACCEPTRelay accepted |
static int | RELAY_REJECT_BOB_BANNED_CHARLIERejected by Bob: Charlie is banned |
static int | RELAY_REJECT_BOB_LIMITRejected by Bob: limit reached |
static int | RELAY_REJECT_BOB_NO_TAGRejected by Bob: no tag found |
static int | RELAY_REJECT_BOB_SIGFAILRejected by Bob: signature failure |
static int | RELAY_REJECT_BOB_UNKNOWN_ALICERejected by Bob: unknown Alice |
static int | RELAY_REJECT_BOB_UNSPECRejected by Bob: unspecified reason |
static int | RELAY_REJECT_CHARLIE_ADDRESSRejected by Charlie: address mismatch |
static int | RELAY_REJECT_CHARLIE_BANNEDRejected by Charlie: banned |
static int | RELAY_REJECT_CHARLIE_CONNECTEDRejected by Charlie: already connected |
static int | RELAY_REJECT_CHARLIE_LIMITRejected by Charlie: limit reached |
static int | RELAY_REJECT_CHARLIE_SIGFAILRejected by Charlie: signature failure |
static int | RELAY_REJECT_CHARLIE_UNKNOWN_ALICERejected by Charlie: unknown Alice |
static int | RELAY_REJECT_CHARLIE_UNSPECRejected by Charlie: unspecified reason |
static byte[] | RELAY_REQUEST_PROLOGUEPrologue for relay request signatures |
static byte[] | RELAY_RESPONSE_PROLOGUEPrologue for relay response signatures |
static byte | RETRY_FLAG_BYTEMessage type flag for retry |
static byte | SESSION_CONFIRMED_FLAG_BYTEMessage type flag for session confirmed |
static byte | SESSION_CREATED_FLAG_BYTEMessage type flag for session created |
static int | SESSION_HEADER_SIZE64 bytes, combined long header and key |
static byte | SESSION_REQUEST_FLAG_BYTEThe message types, 0-11, as bytes. |
static int | SHORT_HEADER_FLAGS_LENLength of short header flags in bytes |
static int | SHORT_HEADER_FLAGS_OFFSETOffset of short header flags |
static int | SHORT_HEADER_SIZE16 bytes, short (data) header size |
static int | SRC_CONN_ID_OFFSETOffset of source connection ID in long header |
static int | TEST_ACCEPTPeer test accepted |
static int | TEST_REJECT_BOB_ADDRESSRejected by Bob: address mismatch |
static int | TEST_REJECT_BOB_LIMITRejected by Bob: limit reached |
static int | TEST_REJECT_BOB_NO_CHARLIERejected by Bob: no Charlie |
static int | TEST_REJECT_BOB_SIGFAILRejected by Bob: signature failure |
static int | TEST_REJECT_BOB_UNSPECRejected by Bob: unspecified reason |
static int | TEST_REJECT_CHARLIE_ADDRESSRejected by Charlie: address mismatch |
static int | TEST_REJECT_CHARLIE_BANNEDRejected by Charlie: banned |
static int | TEST_REJECT_CHARLIE_CONNECTEDRejected by Charlie: already connected |
static int | TEST_REJECT_CHARLIE_LIMITRejected by Charlie: limit reached |
static int | TEST_REJECT_CHARLIE_SIGFAILRejected by Charlie: signature failure |
static int | TEST_REJECT_CHARLIE_UNKNOWN_ALICERejected by Charlie: unknown Alice |
static int | TEST_REJECT_CHARLIE_UNSPECRejected by Charlie: unspecified reason |
static int | TOKEN_OFFSETOffset of token in long header |
static byte | TOKEN_REQUEST_FLAG_BYTEMessage type flag for token request |
static int | TOTAL_PROT_SAMPLE_LENTotal header protection sample length for both samples |
static int | TYPE_OFFSETOffset of message type in header |
static int | VERSION_OFFSETOffset of protocol version in header |
static byte[] | ZEROKEYAll-zero key of KEY_LEN bytes |
static byte[] | ZEROLENEmpty byte array, used as HKDF salt |
| Modifier and Type | Method and Description |
|---|---|
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 |
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 byte[] | hkdf(I2PAppContext ctx,
byte[] key,
String info)32 byte output, ZEROLEN data |
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. |
static String | terminationCodeToString(int code)Convert a termination reason code to a human-readable string |
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. |
public static final int CHACHA_IV_LEN
public static final byte DATA_FLAG_BYTE
public static final int DATA_FOLLOWON_EXTRA_SIZE
public static final int DATA_HEADER_SIZE
public static final int DEST_CONN_ID_OFFSET
public static final int FIRST_FRAGMENT_HEADER_SIZE
public static final int FOLLOWON_FRAGMENT_HEADER_SIZE
public static final int HEADER_PROT_1_OFFSET
public static final int HEADER_PROT_2_OFFSET
public static final int HEADER_PROT_DATA_LEN
public static final int HEADER_PROT_SAMPLE_1_OFFSET
public static final int HEADER_PROT_SAMPLE_2_OFFSET
public static final int HEADER_PROT_SAMPLE_LEN
public static final byte HOLE_PUNCH_FLAG_BYTE
public static final String INFO_CONFIRMED
public static final String INFO_CREATED
public static final String INFO_DATA
public static final int INTRO_KEY_LEN
public static final int KEY_LEN
public static final int LONG_HEADER_FLAGS_OFFSET
public static final int LONG_HEADER_SIZE
public static final int MAC_LEN
public static final int MIN_DATA_LEN
public static final int MIN_HANDSHAKE_DATA_LEN
public static final int MIN_LONG_DATA_LEN
public static final int MIN_RETRY_LEN
public static final int MIN_SESSION_CREATED_LEN
public static final int MIN_SESSION_REQUEST_LEN
public static final int MIN_TOKEN_REQUEST_LEN
public static final int NETID_OFFSET
public static final int PADDING_MAX
public static final int PADDING_MAX_SESSION_CREATED
public static final int PADDING_MAX_SESSION_REQUEST
public static final byte PEER_TEST_FLAG_BYTE
public static final byte[] PEER_TEST_PROLOGUE
public static final int PKT_NUM_LEN
public static final int PKT_NUM_OFFSET
public static final int PROTOCOL_VERSION
public static final int REASON_AEAD
public static final int REASON_BANNED
public static final int REASON_FRAME_TIMEOUT
public static final int REASON_FRAMING
public static final int REASON_LIMITS
public static final int REASON_MSG1
public static final int REASON_MSG2
public static final int REASON_MSG3
public static final int REASON_NETID
public static final int REASON_OPTIONS
public static final int REASON_PADDING
public static final int REASON_PAYLOAD
public static final int REASON_REPLACED
public static final int REASON_S_MISMATCH
public static final int REASON_SHUTDOWN
public static final int REASON_SIGFAIL
public static final int REASON_SIGTYPE
public static final int REASON_SKEW
public static final int REASON_TERMINATION
public static final int REASON_TIMEOUT
public static final int REASON_TOKEN
public static final int REASON_UNSPEC
public static final int REASON_VERSION
public static final int RELAY_ACCEPT
public static final int RELAY_REJECT_BOB_BANNED_CHARLIE
public static final int RELAY_REJECT_BOB_LIMIT
public static final int RELAY_REJECT_BOB_NO_TAG
public static final int RELAY_REJECT_BOB_SIGFAIL
public static final int RELAY_REJECT_BOB_UNKNOWN_ALICE
public static final int RELAY_REJECT_BOB_UNSPEC
public static final int RELAY_REJECT_CHARLIE_ADDRESS
public static final int RELAY_REJECT_CHARLIE_BANNED
public static final int RELAY_REJECT_CHARLIE_CONNECTED
public static final int RELAY_REJECT_CHARLIE_LIMIT
public static final int RELAY_REJECT_CHARLIE_SIGFAIL
public static final int RELAY_REJECT_CHARLIE_UNKNOWN_ALICE
public static final int RELAY_REJECT_CHARLIE_UNSPEC
public static final byte[] RELAY_REQUEST_PROLOGUE
public static final byte[] RELAY_RESPONSE_PROLOGUE
public static final byte RETRY_FLAG_BYTE
public static final byte SESSION_CONFIRMED_FLAG_BYTE
public static final byte SESSION_CREATED_FLAG_BYTE
public static final int SESSION_HEADER_SIZE
public static final byte SESSION_REQUEST_FLAG_BYTE
public static final int SHORT_HEADER_FLAGS_LEN
public static final int SHORT_HEADER_FLAGS_OFFSET
public static final int SHORT_HEADER_SIZE
public static final int SRC_CONN_ID_OFFSET
public static final int TEST_ACCEPT
public static final int TEST_REJECT_BOB_ADDRESS
public static final int TEST_REJECT_BOB_LIMIT
public static final int TEST_REJECT_BOB_NO_CHARLIE
public static final int TEST_REJECT_BOB_SIGFAIL
public static final int TEST_REJECT_BOB_UNSPEC
public static final int TEST_REJECT_CHARLIE_ADDRESS
public static final int TEST_REJECT_CHARLIE_BANNED
public static final int TEST_REJECT_CHARLIE_CONNECTED
public static final int TEST_REJECT_CHARLIE_LIMIT
public static final int TEST_REJECT_CHARLIE_SIGFAIL
public static final int TEST_REJECT_CHARLIE_UNKNOWN_ALICE
public static final int TEST_REJECT_CHARLIE_UNSPEC
public static final int TOKEN_OFFSET
public static final byte TOKEN_REQUEST_FLAG_BYTE
public static final int TOTAL_PROT_SAMPLE_LEN
public static final int TYPE_OFFSET
public static final int VERSION_OFFSET
public static final byte[] ZEROKEY
public static final byte[] ZEROLEN
public static byte[] createPeerTestData(I2PAppContext ctx, Hash h, Hash h2, PeerTestState.Role role, long nonce, byte[] ip, int port, SigningPrivateKey spk)
h - to be included in sig, not included in datah2 - may be null, to be included in sig, not included in datarole - unusedip - may be nullpublic static byte[] createRelayRequestData(I2PAppContext ctx, Hash h, Hash h2, long nonce, long tag, byte[] ip, int port, SigningPrivateKey spk)
h - Bob hash to be included in sig, not included in datah2 - Charlie hash to be included in sig, not included in dataip - non-nullpublic static byte[] createRelayResponseData(I2PAppContext ctx, Hash h, int code, long nonce, byte[] ip, int port, SigningPrivateKey spk, long token)
h - Bob hash to be included in sig, not included in dataip - may be nullport - the UDP port number if ip is nulltoken - if nonzero, append itpublic static byte[] hkdf(I2PAppContext ctx, byte[] key, String info)
public static Signature sign(I2PAppContext ctx, byte[] prologue, Hash h, Hash h2, byte[] data, int datalen, SigningPrivateKey spk)
data - if desired, leave room at end for sigdatalen - the length of the data to be signedh - to be included in sig, not included in datah2 - may be null, to be included in sig, not included in datapublic static String terminationCodeToString(int code)
code - one of the REASON_* constantspublic static boolean validateSig(I2PAppContext ctx, byte[] prologue, Hash h, Hash h2, byte[] data, SigningPublicKey spk)
h2 - may be nulldata - not including relay response token