forked from I2P_Developers/i2p.i2p
Router: Add support for building tunnels through ECIES routers (proposals 152,156)
Preliminary, proposal not finalized, subject to change Not yet compatibility tested with other implementations Add peers to match requested length for explicitPeers remove commented out code log tweaks
This commit is contained in:
@@ -130,16 +130,19 @@ public class HandshakeState implements Destroyable, Cloneable {
|
||||
|
||||
public static final String protocolName = "Noise_XKaesobfse+hs2+hs3_25519_ChaChaPoly_SHA256";
|
||||
public static final String protocolName2 = "Noise_IKelg2+hs2_25519_ChaChaPoly_SHA256";
|
||||
public static final String protocolName3 = "Noise_N_25519_ChaChaPoly_SHA256";
|
||||
private static final String prefix;
|
||||
private final String patternId;
|
||||
public static final String PATTERN_ID_XK = "XK";
|
||||
public static final String PATTERN_ID_IK = "IK";
|
||||
public static final String PATTERN_ID_N = "N";
|
||||
private static String dh;
|
||||
private static final String cipher;
|
||||
private static final String hash;
|
||||
private final short[] pattern;
|
||||
private static final short[] PATTERN_XK;
|
||||
private static final short[] PATTERN_IK;
|
||||
private static final short[] PATTERN_N;
|
||||
|
||||
static {
|
||||
// Parse the protocol name into its components.
|
||||
@@ -169,13 +172,21 @@ public class HandshakeState implements Destroyable, Cloneable {
|
||||
PATTERN_IK = Pattern.lookup(id);
|
||||
if (PATTERN_IK == null)
|
||||
throw new IllegalArgumentException("Handshake pattern is not recognized");
|
||||
// N
|
||||
components = protocolName3.split("_");
|
||||
id = components[1];
|
||||
if (!PATTERN_ID_N.equals(id))
|
||||
throw new IllegalArgumentException();
|
||||
PATTERN_N = Pattern.lookup(id);
|
||||
if (PATTERN_N == null)
|
||||
throw new IllegalArgumentException("Handshake pattern is not recognized");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Noise handshake.
|
||||
* Noise protocol name is hardcoded.
|
||||
*
|
||||
* @param patternId XK or IK
|
||||
* @param patternId XK, IK, or N
|
||||
* @param role The role, HandshakeState.INITIATOR or HandshakeState.RESPONDER.
|
||||
* @param xdh The key pair factory for ephemeral keys
|
||||
*
|
||||
@@ -192,6 +203,8 @@ public class HandshakeState implements Destroyable, Cloneable {
|
||||
pattern = PATTERN_XK;
|
||||
else if (patternId.equals(PATTERN_ID_IK))
|
||||
pattern = PATTERN_IK;
|
||||
else if (patternId.equals(PATTERN_ID_N))
|
||||
pattern = PATTERN_N;
|
||||
else
|
||||
throw new IllegalArgumentException("Handshake pattern is not recognized");
|
||||
short flags = pattern[0];
|
||||
|
||||
@@ -54,6 +54,15 @@ class Pattern {
|
||||
public static final short FLAG_REMOTE_HYBRID = 0x1000;
|
||||
public static final short FLAG_REMOTE_HYBRID_REQ = 0x2000;
|
||||
|
||||
private static final short[] noise_pattern_N = {
|
||||
FLAG_LOCAL_EPHEMERAL |
|
||||
FLAG_REMOTE_STATIC |
|
||||
FLAG_REMOTE_REQUIRED,
|
||||
|
||||
E,
|
||||
ES
|
||||
};
|
||||
|
||||
private static final short[] noise_pattern_XK = {
|
||||
FLAG_LOCAL_STATIC |
|
||||
FLAG_LOCAL_EPHEMERAL |
|
||||
@@ -96,7 +105,9 @@ class Pattern {
|
||||
*/
|
||||
public static short[] lookup(String name)
|
||||
{
|
||||
if (name.equals("XK"))
|
||||
if (name.equals("N"))
|
||||
return noise_pattern_N;
|
||||
else if (name.equals("XK"))
|
||||
return noise_pattern_XK;
|
||||
else if (name.equals("IK"))
|
||||
return noise_pattern_IK;
|
||||
|
||||
@@ -39,10 +39,12 @@ class SymmetricState implements Destroyable, Cloneable {
|
||||
// precalculated hash of the Noise name
|
||||
private static final byte[] INIT_HASH_XK;
|
||||
private static final byte[] INIT_HASH_IK;
|
||||
private static final byte[] INIT_HASH_N;
|
||||
|
||||
static {
|
||||
INIT_HASH_XK = initHash(HandshakeState.protocolName);
|
||||
INIT_HASH_IK = initHash(HandshakeState.protocolName2);
|
||||
INIT_HASH_N = initHash(HandshakeState.protocolName3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,6 +104,8 @@ class SymmetricState implements Destroyable, Cloneable {
|
||||
initHash = INIT_HASH_XK;
|
||||
else if (patternId.equals(HandshakeState.PATTERN_ID_IK))
|
||||
initHash = INIT_HASH_IK;
|
||||
else if (patternId.equals(HandshakeState.PATTERN_ID_N))
|
||||
initHash = INIT_HASH_N;
|
||||
else
|
||||
throw new IllegalArgumentException("Handshake pattern is not recognized");
|
||||
System.arraycopy(initHash, 0, h, 0, hashLength);
|
||||
|
||||
Reference in New Issue
Block a user