@Test public void testNegotiatedIkePhase1EncryptedPsk() { IpsecSession.Builder ipsecSessionBuilder = IpsecSession.builder(); IkePhase1Key initiatorKey = new IkePhase1Key(); initiatorKey.setKeyType(IkeKeyType.PRE_SHARED_KEY_ENCRYPTED); initiatorKey.setKeyHash("key1"); IkePhase1Key responderKey = new IkePhase1Key(); responderKey.setKeyType(IkeKeyType.PRE_SHARED_KEY_ENCRYPTED); responderKey.setKeyHash("key2"); negotiateIkePhase1Key(initiatorKey, responderKey, ipsecSessionBuilder); assertThat(ipsecSessionBuilder.getNegotiatedIkeP1Key(), notNullValue()); assertThat( ipsecSessionBuilder.getNegotiatedIkeP1Key().getKeyType(), equalTo(IkeKeyType.PRE_SHARED_KEY_ENCRYPTED)); }
@VisibleForTesting static void negotiateIkePhase1Key( IkePhase1Key initiatorKey, IkePhase1Key responderKey, IpsecSession.Builder ipsecSessionBuilder) { if (!responderKey.getKeyType().equals(initiatorKey.getKeyType())) { return; } IkePhase1Key negotiatedIkePhase1Key = new IkePhase1Key(); negotiatedIkePhase1Key.setKeyType(initiatorKey.getKeyType()); if (responderKey.getKeyType().equals(IkeKeyType.RSA_PUB_KEY) || responderKey.getKeyType().equals(IkeKeyType.PRE_SHARED_KEY_ENCRYPTED)) { ipsecSessionBuilder.setNegotiatedIkeP1Key(negotiatedIkePhase1Key); } else if (responderKey.getKeyType().equals(IkeKeyType.PRE_SHARED_KEY_UNENCRYPTED) && responderKey.getKeyHash().equals(initiatorKey.getKeyHash())) { negotiatedIkePhase1Key.setKeyHash(initiatorKey.getKeyHash()); ipsecSessionBuilder.setNegotiatedIkeP1Key(negotiatedIkePhase1Key); } }
IpsecUtil { @VisibleForTesting static void negotiateIkePhase1Key( IkePhase1Key initiatorKey, IkePhase1Key responderKey, IpsecSession.Builder ipsecSessionBuilder) { if (!responderKey.getKeyType().equals(initiatorKey.getKeyType())) { return; } IkePhase1Key negotiatedIkePhase1Key = new IkePhase1Key(); negotiatedIkePhase1Key.setKeyType(initiatorKey.getKeyType()); if (responderKey.getKeyType().equals(IkeKeyType.RSA_PUB_KEY) || responderKey.getKeyType().equals(IkeKeyType.PRE_SHARED_KEY_ENCRYPTED)) { ipsecSessionBuilder.setNegotiatedIkeP1Key(negotiatedIkePhase1Key); } else if (responderKey.getKeyType().equals(IkeKeyType.PRE_SHARED_KEY_UNENCRYPTED) && responderKey.getKeyHash().equals(initiatorKey.getKeyHash())) { negotiatedIkePhase1Key.setKeyHash(initiatorKey.getKeyHash()); ipsecSessionBuilder.setNegotiatedIkeP1Key(negotiatedIkePhase1Key); } } }
IpsecUtil { @VisibleForTesting static void negotiateIkePhase1Key( IkePhase1Key initiatorKey, IkePhase1Key responderKey, IpsecSession.Builder ipsecSessionBuilder) { if (!responderKey.getKeyType().equals(initiatorKey.getKeyType())) { return; } IkePhase1Key negotiatedIkePhase1Key = new IkePhase1Key(); negotiatedIkePhase1Key.setKeyType(initiatorKey.getKeyType()); if (responderKey.getKeyType().equals(IkeKeyType.RSA_PUB_KEY) || responderKey.getKeyType().equals(IkeKeyType.PRE_SHARED_KEY_ENCRYPTED)) { ipsecSessionBuilder.setNegotiatedIkeP1Key(negotiatedIkePhase1Key); } else if (responderKey.getKeyType().equals(IkeKeyType.PRE_SHARED_KEY_UNENCRYPTED) && responderKey.getKeyHash().equals(initiatorKey.getKeyHash())) { negotiatedIkePhase1Key.setKeyHash(initiatorKey.getKeyHash()); ipsecSessionBuilder.setNegotiatedIkeP1Key(negotiatedIkePhase1Key); } }  }
IpsecUtil { @VisibleForTesting static void negotiateIkePhase1Key( IkePhase1Key initiatorKey, IkePhase1Key responderKey, IpsecSession.Builder ipsecSessionBuilder) { if (!responderKey.getKeyType().equals(initiatorKey.getKeyType())) { return; } IkePhase1Key negotiatedIkePhase1Key = new IkePhase1Key(); negotiatedIkePhase1Key.setKeyType(initiatorKey.getKeyType()); if (responderKey.getKeyType().equals(IkeKeyType.RSA_PUB_KEY) || responderKey.getKeyType().equals(IkeKeyType.PRE_SHARED_KEY_ENCRYPTED)) { ipsecSessionBuilder.setNegotiatedIkeP1Key(negotiatedIkePhase1Key); } else if (responderKey.getKeyType().equals(IkeKeyType.PRE_SHARED_KEY_UNENCRYPTED) && responderKey.getKeyHash().equals(initiatorKey.getKeyHash())) { negotiatedIkePhase1Key.setKeyHash(initiatorKey.getKeyHash()); ipsecSessionBuilder.setNegotiatedIkeP1Key(negotiatedIkePhase1Key); } }  static IpsecTopology initIpsecTopology(Map<String, Configuration> configurations); static IpsecTopology retainCompatibleTunnelEdges(
      IpsecTopology ipsecTopology, Map<String, Configuration> configurations); static Set<Edge> toEdgeSet(
      @Nonnull IpsecTopology ipsecTopology, @Nonnull Map<String, Configuration> configurations); static @Nonnull IpsecTopology retainReachableIpsecEdges(
      IpsecTopology ipsecTopology,
      Map<String, Configuration> configurations,
      TracerouteEngine tracerouteEngine); }
IpsecUtil { @VisibleForTesting static void negotiateIkePhase1Key( IkePhase1Key initiatorKey, IkePhase1Key responderKey, IpsecSession.Builder ipsecSessionBuilder) { if (!responderKey.getKeyType().equals(initiatorKey.getKeyType())) { return; } IkePhase1Key negotiatedIkePhase1Key = new IkePhase1Key(); negotiatedIkePhase1Key.setKeyType(initiatorKey.getKeyType()); if (responderKey.getKeyType().equals(IkeKeyType.RSA_PUB_KEY) || responderKey.getKeyType().equals(IkeKeyType.PRE_SHARED_KEY_ENCRYPTED)) { ipsecSessionBuilder.setNegotiatedIkeP1Key(negotiatedIkePhase1Key); } else if (responderKey.getKeyType().equals(IkeKeyType.PRE_SHARED_KEY_UNENCRYPTED) && responderKey.getKeyHash().equals(initiatorKey.getKeyHash())) { negotiatedIkePhase1Key.setKeyHash(initiatorKey.getKeyHash()); ipsecSessionBuilder.setNegotiatedIkeP1Key(negotiatedIkePhase1Key); } }  static IpsecTopology initIpsecTopology(Map<String, Configuration> configurations); static IpsecTopology retainCompatibleTunnelEdges(
      IpsecTopology ipsecTopology, Map<String, Configuration> configurations); static Set<Edge> toEdgeSet(
      @Nonnull IpsecTopology ipsecTopology, @Nonnull Map<String, Configuration> configurations); static @Nonnull IpsecTopology retainReachableIpsecEdges(
      IpsecTopology ipsecTopology,
      Map<String, Configuration> configurations,
      TracerouteEngine tracerouteEngine);  }