[ONOS-8111]Fix for passwordless ssh to netconf device without sshkey
Change-Id: I7bedb4c1463024d359b641b24a2089c909e6f03e
diff --git a/deps/deps.json b/deps/deps.json
index 244f898..d72b890 100644
--- a/deps/deps.json
+++ b/deps/deps.json
@@ -329,8 +329,8 @@
"org.apache.servicemix.bundles.dom4j":"mvn:org.apache.servicemix.bundles:org.apache.servicemix.bundles.dom4j:1.6.1_5",
"plexus-utils": "mvn:org.codehaus.plexus:plexus-utils:3.0.24",
"sshd-core": "mvn:org.apache.sshd:sshd-core:1.7.0",
- "bcpkix-jdk15on": "mvn:org.bouncycastle:bcpkix-jdk15on:1.59",
- "bcprov-jdk15on": "mvn:org.bouncycastle:bcprov-jdk15on:1.59",
+ "bcpkix-jdk15on": "mvn:org.bouncycastle:bcpkix-jdk15on:1.66",
+ "bcprov-jdk15on": "mvn:org.bouncycastle:bcprov-jdk15on:1.66",
"hamcrest-optional": "mvn:com.spotify:hamcrest-optional:1.1.0",
"swagger-annotations": "mvn:io.swagger:swagger-annotations:1.5.16",
"kafka-clients": "mvn:org.apache.servicemix.bundles:org.apache.servicemix.bundles.kafka-clients:1.1.1_1",
diff --git a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java
index 2a574ab..22bb2b8 100644
--- a/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java
+++ b/protocols/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/impl/NetconfSessionMinaImpl.java
@@ -52,7 +52,7 @@
import org.onosproject.netconf.NetconfTransportException;
import org.slf4j.Logger;
-import java.io.CharArrayReader;
+import java.io.FileReader;
import java.io.IOException;
import java.security.KeyFactory;
import java.security.KeyPair;
@@ -122,6 +122,8 @@
private static final String NETCONF_11_CAPABILITY = "urn:ietf:params:netconf:base:1.1";
private static final String NETCONF_CLIENT_CAPABILITY = "netconfClientCapability";
private static final String NOTIFICATION_STREAM = "notificationStream";
+ private static final String SSH_KEY_PATH = "/root/.ssh/id_rsa";
+ private static final String EMPTY_STRING = "";
private static ServiceDirectory directory = new DefaultServiceDirectory();
@@ -255,16 +257,16 @@
deviceInfo.port())
.verify(connectTimeout, TimeUnit.SECONDS);
session = connectFuture.getSession();
- //Using the device ssh key if possible
- if (deviceInfo.getKey() != null) {
- try (PEMParser pemParser = new PEMParser(new CharArrayReader(deviceInfo.getKey()))) {
+ //Using the onos private ssh key at path SSH_KEY_PATH
+ if (deviceInfo.password().equals(EMPTY_STRING)) {
+ try (PEMParser pemParser = new PEMParser(new FileReader(SSH_KEY_PATH))) {
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME);
try {
KeyPair kp = converter.getKeyPair((PEMKeyPair) pemParser.readObject());
session.addPublicKeyIdentity(kp);
} catch (IOException e) {
- throw new NetconfException("Failed to authenticate session with device " +
- deviceInfo + "check key to be a valid key", e);
+ throw new NetconfException("Failed to authenticate session. Please check if ssk key is generated" +
+" on ONOS host machine at path " + SSH_KEY_PATH + " : ", e);
}
}
} else {
diff --git a/tools/build/bazel/generate_workspace.bzl b/tools/build/bazel/generate_workspace.bzl
index eb7b26e..946ebe0 100644
--- a/tools/build/bazel/generate_workspace.bzl
+++ b/tools/build/bazel/generate_workspace.bzl
@@ -1,4 +1,4 @@
-# ***** This file was auto-generated at Mon, 6 Jul 2020 20:55:29 GMT. Do not edit this file manually. *****
+# ***** This file was auto-generated at Mon, 27 Jul 2020 12:28:54 GMT. Do not edit this file manually. *****
# ***** Use onos-lib-gen *****
load("//tools/build/bazel:variables.bzl", "ONOS_GROUP_ID", "ONOS_VERSION")
@@ -1279,15 +1279,15 @@
if "bcpkix_jdk15on" not in native.existing_rules():
java_import_external(
name = "bcpkix_jdk15on",
- jar_sha256 = "601d85cfbcef76a1cb77cbf755a6234a4ba1d4c02a98d9a81028d471f388694f",
+ jar_sha256 = "02d61268352fdb35dba996c9ca68a3f793d7b8bfa75754aac66d696517a421bd",
licenses = ["notice"],
- jar_urls = ["https://repo1.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.59/bcpkix-jdk15on-1.59.jar"], )
+ jar_urls = ["https://repo1.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.66/bcpkix-jdk15on-1.66.jar"], )
if "bcprov_jdk15on" not in native.existing_rules():
java_import_external(
name = "bcprov_jdk15on",
- jar_sha256 = "1c31e44e331d25e46d293b3e8ee2d07028a67db011e74cb2443285aed1d59c85",
+ jar_sha256 = "1b861dba1c5445de9b38a1789c211ef28b9d07e26d1fa38bee717e5b51162ffe",
licenses = ["notice"],
- jar_urls = ["https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.59/bcprov-jdk15on-1.59.jar"], )
+ jar_urls = ["https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.66/bcprov-jdk15on-1.66.jar"], )
if "hamcrest_optional" not in native.existing_rules():
java_import_external(
name = "hamcrest_optional",
@@ -1535,8 +1535,8 @@
artifact_map["@org_apache_servicemix_bundles_dom4j//:org_apache_servicemix_bundles_dom4j"] = "mvn:org.apache.servicemix.bundles:org.apache.servicemix.bundles.dom4j:jar:1.6.1_5"
artifact_map["@plexus_utils//:plexus_utils"] = "mvn:org.codehaus.plexus:plexus-utils:jar:NON-OSGI:3.0.24"
artifact_map["@sshd_core//:sshd_core"] = "mvn:org.apache.sshd:sshd-core:jar:1.7.0"
-artifact_map["@bcpkix_jdk15on//:bcpkix_jdk15on"] = "mvn:org.bouncycastle:bcpkix-jdk15on:jar:1.59"
-artifact_map["@bcprov_jdk15on//:bcprov_jdk15on"] = "mvn:org.bouncycastle:bcprov-jdk15on:jar:1.59"
+artifact_map["@bcpkix_jdk15on//:bcpkix_jdk15on"] = "mvn:org.bouncycastle:bcpkix-jdk15on:jar:1.66"
+artifact_map["@bcprov_jdk15on//:bcprov_jdk15on"] = "mvn:org.bouncycastle:bcprov-jdk15on:jar:1.66"
artifact_map["@hamcrest_optional//:hamcrest_optional"] = "mvn:com.spotify:hamcrest-optional:jar:NON-OSGI:1.1.0"
artifact_map["@swagger_annotations//:swagger_annotations"] = "mvn:io.swagger:swagger-annotations:jar:1.5.16"
artifact_map["@kafka_clients//:kafka_clients"] = "mvn:org.apache.servicemix.bundles:org.apache.servicemix.bundles.kafka-clients:jar:1.1.1_1"