Package com.eatthepath.noise
Class NamedProtocolHandshakeBuilder
java.lang.Object
com.eatthepath.noise.NamedProtocolHandshakeBuilder
A NamedProtocolHandshakeBuilder
constructs NoiseHandshake
instances given a full Noise protocol
name and a role (initiator or responder). In contrast to NoiseHandshakeBuilder
, callers are responsible for
identifying and providing all required key material, which may vary with handshake pattern and role. For example, the
NN handshake pattern is defined as:
NN: -> e <- e, ee
…and so neither the initiator nor the responder requires any static or pre-shared keys:
final NoiseHandshake nnInitiatorHandshake =
new NamedProtocolHandshakeBuilder(nnProtocolName, NoiseHandshake.Role.INITIATOR).build();
final NoiseHandshake nnResponderHandshake =
new NamedProtocolHandshakeBuilder(nnProtocolName, NoiseHandshake.Role.RESPONDER).build();
By contrast, the IK handshake pattern is defined as:
IK: <- s ... -> e, es, s, ss <- e, ee, se
…and so the initiator needs a local static key pair and a remote static public key, while the responder needs only a local static key pair:
final NoiseHandshake ikInitiatorHandshake =
new NamedProtocolHandshakeBuilder(ikProtocolName, NoiseHandshake.Role.INITIATOR)
.setLocalStaticKeyPair(initiatorLocalStaticKeyPair)
.setRemoteStaticPublicKey(initiatorRemoteStaticPublicKey)
.build();
final NoiseHandshake ikResponderHandshake =
new NamedProtocolHandshakeBuilder(ikProtocolName, NoiseHandshake.Role.RESPONDER)
.setLocalStaticKeyPair(responderLocalStaticKeyPair)
.build();
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionNamedProtocolHandshakeBuilder
(String noiseProtocolName, NoiseHandshake.Role role) Constructs a new Noise handshake for the given Noise protocol name and role. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Constructs a Noise handshake with the previously-configured protocol and keys.setLocalStaticKeyPair
(KeyPair localStaticKeyPair) Sets the local static key pair for this handshake.setPreSharedKeys
(List<byte[]> preSharedKeys) Sets the pre-shared keys for this handshake.setPrologue
(byte[] prologue) Sets the prologue for this handshake.setRemoteStaticPublicKey
(PublicKey remoteStaticPublicKey) Sets the remote static public key for this handshake.
-
Constructor Details
-
NamedProtocolHandshakeBuilder
public NamedProtocolHandshakeBuilder(String noiseProtocolName, NoiseHandshake.Role role) throws NoSuchAlgorithmException, NoSuchPatternException Constructs a new Noise handshake for the given Noise protocol name and role.- Parameters:
noiseProtocolName
- the full Noise protocol name for which to construct a handshake objectrole
- the role for the handshake object- Throws:
NoSuchAlgorithmException
- if one or more components of the Noise protocol was not recognized or is not supported in the current JVMNoSuchPatternException
- if the handshake pattern in the Noise protocol name was not recognized or is invalid
-
-
Method Details
-
setPrologue
Sets the prologue for this handshake.- Parameters:
prologue
- the prologue for this handshake; may benull
- Returns:
- a reference to this handshake builder
-
setLocalStaticKeyPair
Sets the local static key pair for this handshake.- Parameters:
localStaticKeyPair
- the local static key pair for this handshake; must not benull
- Returns:
- a reference to this handshake builder
- Throws:
IllegalStateException
- if the chosen handshake pattern does not allow for local static keys- See Also:
-
setRemoteStaticPublicKey
Sets the remote static public key for this handshake.- Parameters:
remoteStaticPublicKey
- the remote static public key for this handshake; must not benull
- Returns:
- a reference to this builder
- Throws:
IllegalStateException
- if the chosen handshake pattern does not allow for remote static keys- See Also:
-
build
Constructs a Noise handshake with the previously-configured protocol and keys.- Returns:
- a Noise handshake with the previously-configured protocol and keys
- Throws:
IllegalStateException
- if any keys required by the chosen handshake pattern have not been set- See Also:
-