From 3cc08ef765f65627d2260c4c69dfdacfa17a3fd6 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Fri, 8 Jul 2016 18:08:16 +1000 Subject: [PATCH] Spec rev30: Fixes for the new fallback patterns --- .../noise/protocol/HandshakeState.java | 13 ++++++++++--- .../com/southernstorm/noise/tests/VectorTests.java | 12 ++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/NoiseJava/src/com/southernstorm/noise/protocol/HandshakeState.java b/NoiseJava/src/com/southernstorm/noise/protocol/HandshakeState.java index d7c332d..9753965 100644 --- a/NoiseJava/src/com/southernstorm/noise/protocol/HandshakeState.java +++ b/NoiseJava/src/com/southernstorm/noise/protocol/HandshakeState.java @@ -593,10 +593,17 @@ public class HandshakeState implements Destroyable { throw new IllegalStateException("Responder cannot fall back from this state"); } - // Format a new protocol name for the "XXfallback" variant + // Format a new protocol name for the fallback variant // and recreate the SymmetricState object. - String name = symmetric.getProtocolName().replace("_IK_", "_XXfallback_"); - String[] components = name.split("_"); + String[] components = symmetric.getProtocolName().split("_"); + components[1] = patternName; + StringBuilder builder = new StringBuilder(); + builder.append(components[0]); + for (int index = 1; index < components.length; ++index) { + builder.append('_'); + builder.append(components[index]); + } + String name = builder.toString(); SymmetricState newSymmetric = new SymmetricState(name, components[3], components[4]); symmetric.destroy(); symmetric = newSymmetric; diff --git a/NoiseJavaTests/src/com/southernstorm/noise/tests/VectorTests.java b/NoiseJavaTests/src/com/southernstorm/noise/tests/VectorTests.java index 7bdd090..323d75c 100644 --- a/NoiseJavaTests/src/com/southernstorm/noise/tests/VectorTests.java +++ b/NoiseJavaTests/src/com/southernstorm/noise/tests/VectorTests.java @@ -75,6 +75,7 @@ public class VectorTests { public String dh; public String cipher; public String hash; + public String fallback_pattern; public byte[] init_prologue; public byte[] init_ephemeral; public byte[] init_static; @@ -196,9 +197,14 @@ public class VectorTests { // Success! } + // Look up the pattern to fall back to. + String pattern = vec.fallback_pattern; + if (pattern == null) + pattern = "XXfallback"; + // Initiate fallback on both sides. - initiator.fallback(); - responder.fallback(); + initiator.fallback(pattern); + responder.fallback(pattern); // Restart the protocols. initiator.start(); @@ -297,6 +303,8 @@ public class VectorTests { vec.cipher = reader.nextString(); else if (name.equals("hash")) vec.hash = reader.nextString(); + else if (name.equals("fallback_pattern")) + vec.fallback_pattern = reader.nextString(); else if (name.equals("init_prologue")) vec.init_prologue = DatatypeConverter.parseHexBinary(reader.nextString()); else if (name.equals("init_ephemeral"))