Remove dependecies on bgpcep concepts/util 97/4297/7
authorRobert Varga <rovarga@cisco.com>
Thu, 16 Jan 2014 09:49:24 +0000 (10:49 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Sat, 18 Jan 2014 18:46:28 +0000 (18:46 +0000)
Change-Id: I2d1c1175ee06e77e0d6e3a31b98cd44843572bc6
Signed-off-by: Robert Varga <rovarga@cisco.com>
12 files changed:
opendaylight/commons/opendaylight/pom.xml
opendaylight/distribution/opendaylight/pom.xml
opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java
opendaylight/md-sal/sal-netconf-connector/pom.xml
opendaylight/md-sal/test/sal-rest-connector-it/src/test/java/org/opendaylight/controller/test/restconf/it/ServiceProviderController.java
opendaylight/netconf/netconf-impl/pom.xml
opendaylight/netconf/netconf-it/pom.xml
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java
opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/SSLUtil.java [new file with mode: 0644]
opendaylight/netconf/netconf-util/pom.xml
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageFactory.java
opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageHeader.java

index 67da0228fe3ede4c317ae558ae5e7bdf1f2cb885..d49437fbaf582d06ce7ab838df5da739b90995a2 100644 (file)
        <version>${yang-ext.version}</version>
       </dependency>
       <!-- bgppcep dependencies -->
-      <dependency>
-       <groupId>org.opendaylight.bgpcep</groupId>
-       <artifactId>concepts</artifactId>
-       <version>${bgpcep.version}</version>
-      </dependency>
-      <dependency>
-       <groupId>org.opendaylight.bgpcep</groupId>
-       <artifactId>util</artifactId>
-       <version>${bgpcep.version}</version>
-      </dependency>
     <dependency>
         <groupId>org.opendaylight.bgpcep</groupId>
         <artifactId>framework</artifactId>
index a8dd607f44240d17203e782a57d8a9179e53d5f0..22799281e20b6c3ace34fecebdf0cedcfbef6e07 100644 (file)
     </dependency>
 
     <!-- bgppcep dependencies -->
-    <dependency>
-     <groupId>org.opendaylight.bgpcep</groupId>
-     <artifactId>concepts</artifactId>
-    </dependency>
-    <dependency>
-     <groupId>org.opendaylight.bgpcep</groupId>
-     <artifactId>util</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.opendaylight.bgpcep</groupId>
       <artifactId>framework</artifactId>
index 2e2d77087220de946b1aad4384841f4f2073b0cf..82ad7cffe24d16b42c046b7b1978336d52e43e96 100644 (file)
@@ -39,7 +39,6 @@ public class TestHelper {
     public static Option configMinumumBundles() {
         return new DefaultCompositeOption(
                 mavenBundle("org.opendaylight.bgpcep", "framework").versionAsInProject(), //
-                mavenBundle("org.opendaylight.bgpcep", "util").versionAsInProject(), //
                 mavenBundle("commons-codec", "commons-codec").versionAsInProject(),
 
                 mavenBundle(CONTROLLER, "config-api").versionAsInProject(), // //
index 67e2934a0ea1b604d2737d122bf723714045722c..770056f825f8c9f626a5e848b1c4759ff9c02e23 100644 (file)
             <version>${netconf.version}</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.bgpcep</groupId>
-            <artifactId>util</artifactId>
-            <scope>test</scope>
-            <version>0.3.0-SNAPSHOT</version>
-        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>netconf-client</artifactId>
index b8ebedfdfbdf36034f203e8f66e3c9796e7a8327..a9637f867288b753991de25a205d710faae956b8 100644 (file)
@@ -221,7 +221,6 @@ public class ServiceProviderController {
                 mavenBundle(ODL, "config-persister-impl").versionAsInProject(),
 
                 mavenBundle("org.opendaylight.bgpcep", "framework").versionAsInProject(),
-                mavenBundle("org.opendaylight.bgpcep", "util").versionAsInProject(),
                 mavenBundle(YANG, "binding-generator-spi").versionAsInProject(), //
                 mavenBundle(YANG, "binding-model-api").versionAsInProject(), //
                 mavenBundle(YANG, "binding-generator-util").versionAsInProject(),
index 27db4729aebb53b6608c7ebc3e8c42dd81212f3d..981a81d7b6e5c56e5998ee82187d4702d735ac03 100644 (file)
             <artifactId>ietf-inet-types</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>org.opendaylight.bgpcep</groupId>
-            <artifactId>util</artifactId>
-        </dependency>
-
         <dependency>
             <groupId>org.opendaylight.bgpcep</groupId>
             <artifactId>framework</artifactId>
index 504c5220c6929504abba2503e5c5f2f95edacc31..5e8f29193a53b52df1bd0550b83999f97b92bb61 100644 (file)
             <artifactId>netconf-api</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.bgpcep</groupId>
-            <artifactId>util</artifactId>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>netconf-client</artifactId>
index 91b543b4de90b2410501e91ddcf8d160d986149b..793a756d540ecf7fee82499121db0bdb6b0f167f 100644 (file)
@@ -43,7 +43,6 @@ import org.opendaylight.controller.netconf.impl.NetconfServerSessionListenerFact
 import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory;
 import org.opendaylight.controller.netconf.impl.SessionIdProvider;
 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
-import org.opendaylight.protocol.util.SSLUtil;
 
 public class NetconfITSecureTest extends AbstractConfigTest {
 
diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/SSLUtil.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/SSLUtil.java
new file mode 100644 (file)
index 0000000..07ca2f1
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.controller.netconf.it;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
+
+import com.google.common.base.Preconditions;
+
+public final class SSLUtil {
+
+    private SSLUtil() {
+    }
+
+    public static SSLContext initializeSecureContext(final String pass, final InputStream ksKeysFile, final InputStream ksTrustFile,
+            final String algorithm) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException,
+            UnrecoverableKeyException, KeyManagementException {
+
+        Preconditions.checkNotNull(ksTrustFile, "ksTrustFile cannot be null");
+        Preconditions.checkNotNull(ksKeysFile, "ksKeysFile cannot be null");
+
+        final char[] passphrase = pass.toCharArray();
+
+        // First initialize the key and trust material.
+        final KeyStore ksKeys = KeyStore.getInstance("JKS");
+        ksKeys.load(ksKeysFile, passphrase);
+        final KeyStore ksTrust = KeyStore.getInstance("JKS");
+        ksTrust.load(ksTrustFile, passphrase);
+
+        // KeyManager's decide which key material to use.
+        final KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
+        kmf.init(ksKeys, passphrase);
+
+        // TrustManager's decide whether to allow connections.
+        final TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
+        tmf.init(ksTrust);
+
+        final SSLContext sslContext = SSLContext.getInstance("TLS");
+
+        // Create/initialize the SSLContext with key material
+        sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
+        return sslContext;
+    }
+
+}
index 353dd1aae70ba8eac0b8cb2fa9ca4ab21da5ba10..2f6da9e3c6f0d04c048985a7ff5e539be0e275ca 100644 (file)
             <groupId>org.opendaylight.bgpcep</groupId>
             <artifactId>framework</artifactId>
         </dependency>
-        <dependency>
-            <groupId>org.opendaylight.bgpcep</groupId>
-            <artifactId>util</artifactId>
-        </dependency>
 
         <dependency>
             <groupId>org.osgi</groupId>
                             org.opendaylight.controller.netconf.api,
                             org.opendaylight.controller.netconf.mapping.api,
                             org.opendaylight.protocol.framework,
-                            org.opendaylight.protocol.util,
                             org.osgi.framework,
                             org.slf4j,
                             org.w3c.dom,
index 9097da4d91d284c0eb53a3285295ab27724cd65a..6f86cc37f92bcb6ba93c352e6475e72935df2730 100644 (file)
@@ -20,7 +20,6 @@ import org.opendaylight.controller.netconf.util.xml.XmlUtil;
 import org.opendaylight.protocol.framework.DeserializerException;
 import org.opendaylight.protocol.framework.DocumentedException;
 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
-import org.opendaylight.protocol.util.ByteArray;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Comment;
@@ -77,9 +76,34 @@ public final class NetconfMessageFactory implements ProtocolMessageFactory<Netco
         return message;
     }
 
+    private static int findByteSequence(final byte[] bytes, final byte[] sequence) {
+        if (bytes.length < sequence.length) {
+            throw new IllegalArgumentException("Sequence to be found is longer than the given byte array.");
+        }
+        if (bytes.length == sequence.length) {
+            if (Arrays.equals(bytes, sequence)) {
+                return 0;
+            } else {
+                return -1;
+            }
+        }
+        int j = 0;
+        for (int i = 0; i < bytes.length; i++) {
+            if (bytes[i] == sequence[j]) {
+                j++;
+                if (j == sequence.length) {
+                    return i - j + 1;
+                }
+            } else {
+                j = 0;
+            }
+        }
+        return -1;
+    }
+
     private int getAdditionalHeaderEndIndex(byte[] bytes) {
         for (byte[] possibleEnd : POSSIBLE_ENDS) {
-            int idx = ByteArray.findByteSequence(bytes, possibleEnd);
+            int idx = findByteSequence(bytes, possibleEnd);
 
             if (idx != -1) {
                 return idx;
index 4ea7df5da0f89358fa4e8c9e15784bb89ff22eb4..a61541b9146556f7b71e0766e0c8b99a65a81fd9 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.controller.netconf.util.messages;
 
 import com.google.common.base.Charsets;
 import com.google.common.base.Preconditions;
-import org.opendaylight.protocol.util.ByteArray;
 
 import java.nio.ByteBuffer;
 
@@ -39,8 +38,7 @@ public final class NetconfMessageHeader {
         // the length should be only numbers and therefore easily parsed with
         // ASCII
         this.length = Long.parseLong(Charsets.US_ASCII.decode(
-                ByteBuffer.wrap(ByteArray.subByte(bytes, headerBegin.length, bytes.length - headerBegin.length - 1)))
-                .toString());
+                ByteBuffer.wrap(bytes, headerBegin.length, bytes.length - headerBegin.length - 1)).toString());
         Preconditions.checkState(this.length < Integer.MAX_VALUE && this.length > 0);
         this.parsed = true;
         return this;