Introduce pcep-session-tls 13/104013/5
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 12 Jan 2023 14:46:16 +0000 (15:46 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 12 Jan 2023 16:58:44 +0000 (17:58 +0100)
TLS configuration is a session establishment thing. Capture its
configuration in a grouping and pass that down instead of the hard-coded
datastore instance.

JIRA: BGPCEP-962
Change-Id: I2e0b4d383172c1cbbca7ac4b484b25db1242cb83
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
pcep/api/src/main/yang/pcep-config.yang
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/AbstractPCEPSessionNegotiator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiator.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/DefaultPCEPSessionNegotiatorFactory.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tls/SslContextFactory.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/tls/SslKeyStore.java
pcep/impl/src/main/yang/pcep-app-config.yang
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/FiniteStateMachineTest.java
pcep/impl/src/test/java/org/opendaylight/protocol/pcep/impl/SslContextFactoryTest.java

index 18b7da1d7fd61004d8250306d333631360c7dd32..43793ccda605bbfdce62fe57abcb6174d3d8f761 100644 (file)
@@ -21,8 +21,11 @@ module pcep-config {
          http://www.eclipse.org/legal/epl-v10.html";
 
     revision 2023-01-12 {
-        description "Updated timer definitions to uint8 and split them off
-                     into pcep-session-timers grouping";
+        description
+            "Updated timer definitions to uint8 and split them off into
+             pcep-session-timers grouping.
+
+             Introduced pcep-session-tls to hold TLS-related configuration.";
     }
 
     revision 2022-03-28 {
@@ -52,6 +55,68 @@ module pcep-config {
         }
     }
 
+    grouping pcep-session-tls {
+        typedef path-type {
+            type enumeration {
+                enum PATH;
+                enum CLASSPATH;
+            }
+        }
+
+        typedef store-type {
+            type enumeration {
+                enum JKS;
+                enum PKCS12;
+            }
+        }
+
+        leaf keystore {
+            description "keystore location";
+            type string;
+            mandatory true;
+        }
+        leaf keystore-type {
+            description "keystore type (JKS or PKCS12)";
+            type store-type;
+            mandatory true;
+        }
+        leaf keystore-path-type {
+            description "keystore path type (CLASSPATH or PATH)";
+            type path-type;
+            mandatory true;
+        }
+        leaf keystore-password {
+            description "password protecting keystore";
+            type string;
+            mandatory true;
+        }
+        leaf certificate-password {
+            description "password protecting certificate";
+            type string;
+            mandatory true;
+        }
+        leaf truststore {
+            description "truststore location";
+            type string;
+            mandatory true;
+        }
+        leaf truststore-type {
+            description "truststore type (JKS or PKCS12)";
+            type store-type;
+            mandatory true;
+        }
+        leaf truststore-path-type {
+            description "truststore path type (CLASSPATH or PATH)";
+            type path-type;
+            mandatory true;
+        }
+        leaf truststore-password {
+            description "password protecting truststore";
+            type string;
+            mandatory true;
+        }
+    }
+
     grouping pcep-config {
         container session-config {
             description "PCEP topology config";
@@ -78,6 +143,11 @@ module pcep-config {
             }
 
             uses pcep-session-timers;
+
+            container tls {
+                presence "Indicates TLS-enabled (PCEPS) operation";
+                uses pcep-session-tls;
+            }
         }
     }
 
index 1785d7c70e0cbb7694024bf54642ab6e3ea4ae37..185a3f15a6d0ed35bbd02616a2e824987d16affc 100644 (file)
@@ -22,7 +22,7 @@ import javax.net.ssl.SSLEngine;
 import org.opendaylight.protocol.pcep.impl.spi.Util;
 import org.opendaylight.protocol.pcep.impl.tls.SslContextFactory;
 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.PcepSessionTls;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.KeepaliveBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.OpenBuilder;
@@ -85,7 +85,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
     private static final Keepalive KEEPALIVE =
         new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
 
-    private final Tls tlsConfiguration;
+    private final PcepSessionTls tlsConfiguration;
 
     private volatile boolean localOK;
     private volatile boolean openRetry;
@@ -96,7 +96,7 @@ public abstract class AbstractPCEPSessionNegotiator extends AbstractSessionNegot
     private Open remotePrefs;
 
     protected AbstractPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
-            final Tls tlsConfiguration) {
+            final PcepSessionTls tlsConfiguration) {
         super(promise, channel);
         this.tlsConfiguration = tlsConfiguration;
     }
index 1b94701f95c19dd7bc10f57aebdd036facd19f16..befcbc396a01cd401099e108712d2f7120b2f78a 100644 (file)
@@ -13,7 +13,7 @@ import com.google.common.annotations.VisibleForTesting;
 import io.netty.channel.Channel;
 import io.netty.util.concurrent.Promise;
 import org.opendaylight.protocol.pcep.PCEPSessionListener;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.PcepSessionTls;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder;
 import org.opendaylight.yangtools.yang.common.Uint8;
@@ -24,7 +24,7 @@ public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegot
 
     public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
             final PCEPSessionListener listener, final Uint8 sessionId, final int maxUnknownMessages,
-            final Open localPrefs, final Tls tlsConfiguration) {
+            final Open localPrefs, final PcepSessionTls tlsConfiguration) {
         super(promise, channel, tlsConfiguration);
         this.listener = requireNonNull(listener);
         this.maxUnknownMessages = maxUnknownMessages;
index f9e3643a5e64b6b4150476ac287331e786747b3f..02dd2569f2a9cf238004b7f9edd52cc4e860fb54 100644 (file)
@@ -15,21 +15,21 @@ import java.net.InetSocketAddress;
 import org.opendaylight.protocol.pcep.PCEPSessionNegotiatorFactoryDependencies;
 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.PcepDispatcherConfig;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.PcepSessionTls;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open;
 import org.opendaylight.yangtools.yang.common.Uint8;
 
 public final class DefaultPCEPSessionNegotiatorFactory extends AbstractPCEPSessionNegotiatorFactory {
     private final PCEPSessionProposalFactory spf;
     private final int maxUnknownMessages;
-    private final Tls tlsConfiguration;
+    private final PcepSessionTls tlsConfiguration;
 
     public DefaultPCEPSessionNegotiatorFactory(final PCEPSessionProposalFactory spf, final int maxUnknownMessages) {
         this(spf, maxUnknownMessages, null);
     }
 
     private DefaultPCEPSessionNegotiatorFactory(final PCEPSessionProposalFactory spf, final int maxUnknownMessages,
-            final Tls tlsConfiguration) {
+            final PcepSessionTls tlsConfiguration) {
         this.spf = requireNonNull(spf);
         this.maxUnknownMessages = maxUnknownMessages;
         this.tlsConfiguration = tlsConfiguration;
index 2b9f3af531941c9a5062c0147854aa3587843300..20640bb9e0ef49ea050afff30d154f6e658defbb 100644 (file)
@@ -19,7 +19,7 @@ import java.security.cert.CertificateException;
 import javax.net.ssl.KeyManagerFactory;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManagerFactory;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.PcepSessionTls;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -30,14 +30,14 @@ public class SslContextFactory {
     private static final Logger LOG = LoggerFactory.getLogger(SslContextFactory.class);
     private static final String PROTOCOL = "TLS";
 
-    private final Tls tlsConfig;
+    private final PcepSessionTls tlsConfig;
 
     /**
      * SslContextFactory provides information about the TLS context and configuration.
      * @param tlsConfig
      *            TLS configuration object, contains keystore locations and keystore types
      */
-    public SslContextFactory(final Tls tlsConfig) {
+    public SslContextFactory(final PcepSessionTls tlsConfig) {
         this.tlsConfig = requireNonNull(tlsConfig);
     }
 
index bb6d208375612354f168942c8d78b643a5d5cecc..644ef760765e279e26edf8bbbf7010ff84c1c4bf 100644 (file)
@@ -12,7 +12,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.PathType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.pcep.session.tls.PathType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index e3da559bb67cacc751e0efee40a728883850a78f..4962d8d777d2dbef4846cbcb347bbcdfc5fc748e 100644 (file)
@@ -20,25 +20,13 @@ module pcep-app-config {
     import pcep-config { prefix pc; }
 
     container pcep-session-config {
-        // FIXME: remove this container
+        // FIXME: BGPCEP-962: remove this container
         uses pc:pcep-session-timers;
     }
 
-    typedef path-type {
-        type enumeration {
-            enum "PATH";
-            enum "CLASSPATH";
-        }
-    }
-
-    typedef store-type {
-        type enumeration {
-            enum "JKS";
-            enum "PKCS12";
-        }
-    }
-
     container pcep-dispatcher-config {
+        // FIXME: BGPCEP-962: remove this container
+
         leaf max-unknown-messages {
             type uint16 {
                 range "1..max";
@@ -48,51 +36,7 @@ module pcep-app-config {
 
         container tls {
             presence true;
-            leaf keystore {
-                description "keystore location";
-                type string;
-                mandatory true;
-            }
-            leaf keystore-type {
-                description "keystore type (JKS or PKCS12)";
-                type store-type;
-                mandatory true;
-            }
-            leaf keystore-path-type {
-                description "keystore path type (CLASSPATH or PATH)";
-                type path-type;
-                mandatory true;
-            }
-            leaf keystore-password {
-                description "password protecting keystore";
-                type string;
-                mandatory true;
-            }
-            leaf certificate-password {
-                description "password protecting certificate";
-                type string;
-                mandatory true;
-            }
-            leaf truststore {
-                description "truststore location";
-                type string;
-                mandatory true;
-            }
-            leaf truststore-type {
-                description "truststore type (JKS or PKCS12)";
-                type store-type;
-                mandatory true;
-            }
-            leaf truststore-path-type {
-                description "truststore path type (CLASSPATH or PATH)";
-                type path-type;
-                mandatory true;
-            }
-            leaf truststore-password {
-                description "password protecting truststore";
-                type string;
-                mandatory true;
-            }
+            uses pc:pcep-session-tls;
         }
     }
 }
index 9597b11609a391ec534651560bf64e6e286a6e96..f45094e4082c827bdee9eb63507bec074cff69f2 100644 (file)
@@ -27,7 +27,7 @@ import org.opendaylight.protocol.pcep.PCEPSessionListener;
 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
 import org.opendaylight.protocol.pcep.impl.spi.Util;
 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.TlsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.pcep.config.session.config.TlsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcerr;
index f2d2a858119782394a729bc82251e7a5d552b760..07f83b71834f4e766087af107a0c48dc015e5e10 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.protocol.pcep.impl;
 
 import static org.junit.Assert.assertNotNull;
@@ -13,10 +12,10 @@ import static org.junit.Assert.assertNotNull;
 import javax.net.ssl.SSLContext;
 import org.junit.Test;
 import org.opendaylight.protocol.pcep.impl.tls.SslContextFactory;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.PathType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.StoreType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.TlsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.PcepSessionTls;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.pcep.config.session.config.TlsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.pcep.session.tls.PathType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.pcep.session.tls.StoreType;
 
 public class SslContextFactoryTest {
 
@@ -27,11 +26,17 @@ public class SslContextFactoryTest {
         assertNotNull(sslContext);
     }
 
-    public static Tls createTlsConfig() {
-        return new TlsBuilder().setCertificatePassword("opendaylight").setKeystore("/exemplary-ctlKeystore")
-                .setKeystorePassword("opendaylight").setKeystorePathType(PathType.CLASSPATH)
-                .setKeystoreType(StoreType.JKS).setTruststore("/exemplary-ctlTrustStore")
-                .setTruststorePassword("opendaylight").setTruststorePathType(PathType.CLASSPATH)
-                .setTruststoreType(StoreType.JKS).build();
+    public static PcepSessionTls createTlsConfig() {
+        return new TlsBuilder()
+            .setCertificatePassword("opendaylight")
+            .setKeystore("/exemplary-ctlKeystore")
+            .setKeystorePassword("opendaylight")
+            .setKeystorePathType(PathType.CLASSPATH)
+            .setKeystoreType(StoreType.JKS)
+            .setTruststore("/exemplary-ctlTrustStore")
+            .setTruststorePassword("opendaylight")
+            .setTruststorePathType(PathType.CLASSPATH)
+            .setTruststoreType(StoreType.JKS)
+            .build();
     }
 }