public class BuildRequestRecord extends Object
bytes 0-3: tunnel ID to receive messages as bytes 4-35: local router identity hash (Unused and no accessor here) bytes 36-39: next tunnel ID bytes 40-71: next router identity hash bytes 72-103: AES-256 tunnel layer key bytes 104-135: AES-256 tunnel IV key bytes 136-167: AES-256 reply key bytes 168-183: reply IV byte 184: flags bytes 185-188: request time (in hours since the epoch) bytes 189-192: next message ID bytes 193-221: uninterpreted / random paddingEncrypted:
bytes 0-15: First 16 bytes of router hash bytes 16-527: ElGamal encrypted block (discarding zero bytes at elg[0] and elg[257])ECIES long record format, ref: proposal 152: Holds the unencrypted 464-byte tunnel request record, with a constructor for ECIES decryption and a method for ECIES encryption. Iterative AES encryption/decryption is done elsewhere. Cleartext:
bytes 0-3: tunnel ID to receive messages as, nonzero bytes 4-7: next tunnel ID, nonzero bytes 8-39: next router identity hash bytes 40-71: AES-256 tunnel layer key bytes 72-103: AES-256 tunnel IV key bytes 104-135: AES-256 reply key bytes 136-151: AES-256 reply IV byte 152: flags bytes 153-155: more flags, unused, set to 0 for compatibility bytes 156-159: request time (in minutes since the epoch, rounded down) bytes 160-163: request expiration (in seconds since creation) bytes 164-167: next message ID bytes 168-x: tunnel build options (Mapping) bytes x-x: other data as implied by flags or options bytes x-463: random paddingEncrypted:
bytes 0-15: Hop's truncated identity hash bytes 16-47: Sender's ephemeral X25519 public key bytes 48-511: ChaCha20 encrypted BuildRequestRecord bytes 512-527: Poly1305 MACECIES short record format, ref: proposal 157: Holds the unencrypted 154-byte tunnel request record, with a constructor for ECIES decryption and a method for ECIES encryption. Iterative AES encryption/decryption is done elsewhere. Cleartext:
bytes 0-3: tunnel ID to receive messages as, nonzero bytes 4-7: next tunnel ID, nonzero bytes 8-39: next router identity hash byte 40: flags bytes 41-42: more flags, unused, set to 0 for compatibility byte 43: layer enc. type bytes 44-47: request time (in minutes since the epoch, rounded down) bytes 48-51: request expiration (in seconds since creation) bytes 52-55: next message ID bytes 56-x: tunnel build options (Mapping) bytes x-x: other data as implied by flags or options bytes x-153: random paddingEncrypted:
bytes 0-15: Hop's truncated identity hash bytes 16-47: Sender's ephemeral X25519 public key bytes 48-201: ChaCha20 encrypted BuildRequestRecord bytes 202-217: Poly1305 MAC
| Modifier and Type | Field and Description |
|---|---|
static int |
IV_SIZE
IV size in bytes
|
static int |
OFF_REPLY_KEY
Offset for reply key in ElGamal format
|
static int |
OFF_REPLY_KEY_EC
Offset for reply key in ECIES long format
|
static int |
PEER_SIZE
we show 16 bytes of the peer hash outside the elGamal block
|
| Constructor and Description |
|---|
BuildRequestRecord(I2PAppContext ctx,
long receiveTunnelId,
Hash peer,
long nextTunnelId,
Hash nextHop,
long nextMsgId,
SessionKey layerKey,
SessionKey ivKey,
SessionKey replyKey,
byte[] iv,
boolean isInGateway,
boolean isOutEndpoint)
Creates a new ElGamal build request record.
|
BuildRequestRecord(I2PAppContext ctx,
long receiveTunnelId,
long nextTunnelId,
Hash nextHop,
long nextMsgId,
boolean isInGateway,
boolean isOutEndpoint,
Properties options)
Creates a new ECIES short build request record.
|
BuildRequestRecord(I2PAppContext ctx,
long receiveTunnelId,
long nextTunnelId,
Hash nextHop,
long nextMsgId,
SessionKey layerKey,
SessionKey ivKey,
SessionKey replyKey,
byte[] iv,
boolean isInGateway,
boolean isOutEndpoint,
Properties options)
Creates a new ECIES long build request record.
|
BuildRequestRecord(RouterContext ctx,
PrivateKey ourKey,
EncryptedBuildRecord encryptedRecord)
Decrypts an encrypted build request record.
|
| Modifier and Type | Method and Description |
|---|---|
EncryptedBuildRecord |
encryptECIESRecord(RouterContext ctx,
PublicKey toKey,
Hash toPeer)
Encrypts the record using ECIES.
|
EncryptedBuildRecord |
encryptRecord(I2PAppContext ctx,
PublicKey toKey,
Hash toPeer)
Encrypts the record using ElGamal.
|
byte[] |
getChaChaReplyAD()
Returns the ChaCha reply AD (Associated Data).
|
SessionKey |
getChaChaReplyKey()
Returns the ChaCha reply key.
|
byte[] |
getData()
Returns the raw record data.
|
long |
readExpiration()
Reads the expiration time.
|
MessageWrapper.OneTimeSession |
readGarlicKeys()
Reads the garlic keys for OBEP.
|
boolean |
readIsInboundGateway()
Reads whether this hop is an inbound gateway.
|
boolean |
readIsOutboundEndpoint()
Reads whether this hop is an outbound endpoint.
|
SessionKey |
readIVKey()
Reads the tunnel IV encryption key.
|
int |
readLayerEncryptionType()
Reads the layer encryption type.
|
SessionKey |
readLayerKey()
Reads the tunnel layer encryption key.
|
Hash |
readNextIdentity()
Reads the next hop's identity hash.
|
long |
readNextTunnelId()
Reads the next hop's tunnel ID.
|
Properties |
readOptions()
Reads the tunnel build options.
|
long |
readReceiveTunnelId()
Reads the tunnel ID this hop should receive messages on.
|
byte[] |
readReplyIV()
Reads the reply IV.
|
SessionKey |
readReplyKey()
Reads the reply encryption key.
|
long |
readReplyMessageId()
Reads the reply message ID.
|
long |
readRequestTime()
Reads the request time.
|
String |
toString()
Returns a string representation of this record.
|
public static final int IV_SIZE
public static final int OFF_REPLY_KEY
public static final int OFF_REPLY_KEY_EC
public static final int PEER_SIZE
public BuildRequestRecord(I2PAppContext ctx, long receiveTunnelId, Hash peer, long nextTunnelId, Hash nextHop, long nextMsgId, SessionKey layerKey, SessionKey ivKey, SessionKey replyKey, byte[] iv, boolean isInGateway, boolean isOutEndpoint)
ctx - the application contextreceiveTunnelId - tunnel the current hop will receive messages onpeer - current hop's identity, unused, no read() methodnextTunnelId - id for the next hop, or where we send the reply (if we are the outbound endpoint)nextHop - next hop's identity, or where we send the reply (if we are the outbound endpoint)nextMsgId - message ID to use when sending on to the next hop (or for the reply)layerKey - tunnel layer key to be used by the peerivKey - tunnel IV key to be used by the peerreplyKey - key to be used when encrypting the reply to this build requestiv - iv to be used when encrypting the reply to this build requestisInGateway - are we the gateway of an inbound tunnel?isOutEndpoint - are we the endpoint of an outbound tunnel?public BuildRequestRecord(I2PAppContext ctx, long receiveTunnelId, long nextTunnelId, Hash nextHop, long nextMsgId, boolean isInGateway, boolean isOutEndpoint, Properties options)
ctx - the application contextreceiveTunnelId - tunnel the current hop will receive messages onnextTunnelId - id for the next hop, or where we send the reply (if we are the outbound endpoint)nextHop - next hop's identity, or where we send the reply (if we are the outbound endpoint)nextMsgId - message ID to use when sending on to the next hop (or for the reply)isInGateway - are we the gateway of an inbound tunnel?isOutEndpoint - are we the endpoint of an outbound tunnel?options - 98 bytes max when serializedIllegalArgumentException - if options too longpublic BuildRequestRecord(I2PAppContext ctx, long receiveTunnelId, long nextTunnelId, Hash nextHop, long nextMsgId, SessionKey layerKey, SessionKey ivKey, SessionKey replyKey, byte[] iv, boolean isInGateway, boolean isOutEndpoint, Properties options)
ctx - the application contextreceiveTunnelId - tunnel the current hop will receive messages onnextTunnelId - id for the next hop, or where we send the reply (if we are the outbound endpoint)nextHop - next hop's identity, or where we send the reply (if we are the outbound endpoint)nextMsgId - message ID to use when sending on to the next hop (or for the reply)layerKey - tunnel layer key to be used by the peerivKey - tunnel IV key to be used by the peerreplyKey - key to be used when encrypting the reply to this build requestiv - iv to be used when encrypting the reply to this build requestisInGateway - are we the gateway of an inbound tunnel?isOutEndpoint - are we the endpoint of an outbound tunnel?options - 296 bytes max when serializedIllegalArgumentException - if options too longpublic BuildRequestRecord(RouterContext ctx, PrivateKey ourKey, EncryptedBuildRecord encryptedRecord) throws DataFormatException
ctx - the router contextourKey - our private key to decrypt withencryptedRecord - the encrypted build recordDataFormatException - on decrypt failpublic EncryptedBuildRecord encryptECIESRecord(RouterContext ctx, PublicKey toKey, Hash toPeer)
ctx - the router contexttoKey - the public key to encrypt totoPeer - the peer's identity hashIllegalArgumentException - if key type is not ECIESIllegalStateException - on encryption failurepublic EncryptedBuildRecord encryptRecord(I2PAppContext ctx, PublicKey toKey, Hash toPeer)
bytes 0-15: truncated SHA-256 of the current hop's identity (the toPeer parameter) bytes 15-527: ElGamal-2048 encrypted blockElGamal only.
ctx - the application contexttoKey - the public key to encrypt totoPeer - the peer's identity hashIllegalArgumentException - if key type is not ElGamalpublic byte[] getChaChaReplyAD()
public SessionKey getChaChaReplyKey()
public byte[] getData()
public long readExpiration()
public MessageWrapper.OneTimeSession readGarlicKeys()
public boolean readIsInboundGateway()
public boolean readIsOutboundEndpoint()
public SessionKey readIVKey()
public int readLayerEncryptionType()
public SessionKey readLayerKey()
public Hash readNextIdentity()
public long readNextTunnelId()
public Properties readOptions()
public long readReceiveTunnelId()
public byte[] readReplyIV()
IllegalStateException - for short ECIES recordspublic SessionKey readReplyKey()
IllegalStateException - for short ECIES recordspublic long readReplyMessageId()
public long readRequestTime()