public class HandshakeState extends Object implements Destroyable
Modifier and Type | Field and Description |
---|---|
static int |
COMPLETE
The handshake is complete and the data session ciphers
have been split() out successfully.
|
static int |
FAILED
The handshake has failed due to some kind of error.
|
static int |
INITIATOR
Enumerated value that indicates that the handshake object
is handling the initiator role.
|
static int |
NO_ACTION
No action is required of the application yet because the
handshake has not started.
|
static String |
protocolName |
static int |
READ_MESSAGE
The HandshakeState expects the application to read the
next message payload from the handshake.
|
static int |
RESPONDER
Enumerated value that indicates that the handshake object
is handling the responder role.
|
static int |
SPLIT
The handshake is over and the application is expected to call
split() and begin data session communications.
|
static int |
WRITE_MESSAGE
The HandshakeState expects the application to write the
next message payload for the handshake.
|
Constructor and Description |
---|
HandshakeState(int role,
X25519KeyFactory xdh)
Creates a new Noise handshake.
|
Modifier and Type | Method and Description |
---|---|
void |
destroy()
Destroys all sensitive state in the current object.
|
int |
getAction()
Gets the next action that the application should perform for
the handshake part of the protocol.
|
byte[] |
getChainingKey()
I2P for getting chaining key for siphash calc
|
byte[] |
getHandshakeHash()
Gets the current value of the handshake hash.
|
DHState |
getLocalKeyPair()
Gets the keypair object for the local static key.
|
String |
getProtocolName()
Gets the name of the Noise protocol.
|
DHState |
getRemotePublicKey()
Gets the public key object for the remote static key.
|
int |
getRole()
Gets the role for this handshake.
|
boolean |
hasLocalKeyPair()
Determine if this handshake has already been configured
with a local static key.
|
boolean |
hasRemotePublicKey()
Determine if this handshake has already been configured
with a remote static key.
|
void |
mixHash(byte[] data,
int offset,
int length)
I2P for mixing in padding in messages 1 and 2
|
boolean |
needsLocalKeyPair()
Determine if this handshake requires a local static key.
|
boolean |
needsRemotePublicKey()
Determine if this handshake requires a remote static key.
|
int |
readMessage(byte[] message,
int messageOffset,
int messageLength,
byte[] payload,
int payloadOffset)
Reads a message payload during the handshake.
|
CipherStatePair |
split()
Splits the transport encryption CipherState objects out of
this HandshakeState object once the handshake completes.
|
CipherStatePair |
split(byte[] secondaryKey,
int offset,
int length)
Splits the transport encryption CipherState objects out of
this HandshakeObject after mixing in a secondary symmetric key.
|
void |
start()
Starts the handshake running.
|
String |
toString()
I2P debug
|
int |
writeMessage(byte[] message,
int messageOffset,
byte[] payload,
int payloadOffset,
int payloadLength)
Writes a message payload during the handshake.
|
public static final int INITIATOR
public static final int RESPONDER
public static final int NO_ACTION
public static final int WRITE_MESSAGE
public static final int READ_MESSAGE
public static final int FAILED
public static final int SPLIT
public static final int COMPLETE
public static final String protocolName
public HandshakeState(int role, X25519KeyFactory xdh) throws NoSuchAlgorithmException
role
- The role, HandshakeState.INITIATOR or HandshakeState.RESPONDER.xdh
- The key pair factory for ephemeral keysIllegalArgumentException
- The protocolName is not
formatted correctly, or the role is not recognized.NoSuchAlgorithmException
- One of the cryptographic algorithms
that is specified in the protocolName is not supported.public String getProtocolName()
public int getRole()
public DHState getLocalKeyPair()
public boolean needsLocalKeyPair()
public boolean hasLocalKeyPair()
public DHState getRemotePublicKey()
public boolean needsRemotePublicKey()
public boolean hasRemotePublicKey()
public void start()
IllegalStateException
- The handshake has already started, or one or
more of the required parameters has not been supplied.UnsupportedOperationException
- An attempt was made to start a
fallback handshake pattern without first calling fallback() on a
previous handshake.getAction()
,
writeMessage(byte[], int, byte[], int, int)
,
see #fallback()
public int getAction()
public int writeMessage(byte[] message, int messageOffset, byte[] payload, int payloadOffset, int payloadLength) throws ShortBufferException
message
- The buffer that will be populated with the
handshake packet to be written to the transport.messageOffset
- First offset within the message buffer
to be populated.payload
- Buffer containing the payload to add to the
handshake message; can be null if there is no payload.payloadOffset
- Offset into the payload buffer of the
first payload buffer.payloadLength
- Length of the payload in bytes.IllegalStateException
- The action is not WRITE_MESSAGE.IllegalArgumentException
- The payload is null, but
payloadOffset or payloadLength is non-zero.ShortBufferException
- The message buffer does not have
enough space for the handshake message.getAction()
,
readMessage(byte[], int, int, byte[], int)
public int readMessage(byte[] message, int messageOffset, int messageLength, byte[] payload, int payloadOffset) throws ShortBufferException, BadPaddingException
message
- Buffer containing the incoming handshake
that was read from the transport.messageOffset
- Offset of the first message byte.messageLength
- The length of the incoming message.payload
- Buffer that will be populated with the message payload.payloadOffset
- Offset of the first byte in the
payload buffer to be populated with payload data.IllegalStateException
- The action is not READ_MESSAGE.ShortBufferException
- The message buffer does not have
sufficient bytes for a valid message or the payload buffer does
not have enough space for the decrypted payload.BadPaddingException
- A MAC value in the message failed
to verify.getAction()
,
writeMessage(byte[], int, byte[], int, int)
public CipherStatePair split()
IllegalStateException
- The action is not SPLIT.public CipherStatePair split(byte[] secondaryKey, int offset, int length)
secondaryKey
- The buffer containing the secondary key.offset
- The offset of the first secondary key byte.length
- The length of the secondary key in bytes, which
must be either 0 or 32.IllegalStateException
- The action is not SPLIT.IllegalArgumentException
- The length is not 0 or 32.public byte[] getHandshakeHash()
IllegalStateException
- The action is not SPLIT or COMPLETE.public void destroy()
Destroyable
destroy
in interface Destroyable
public void mixHash(byte[] data, int offset, int length)
public byte[] getChainingKey()