X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fosgi%2FNetconfConfigUtil.java;h=38563cba93eef1f727330b17ff72879a012f70ff;hb=b825b2a5b92734113eae6c9c1176ec160ec8776b;hp=987708d67ed03db1276a6459ad47c75f7eabf0bf;hpb=1bcd646e91c564887d1385c23b94faf3419b7c9a;p=controller.git diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java index 987708d67e..38563cba93 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java @@ -8,14 +8,22 @@ package org.opendaylight.controller.netconf.util.osgi; - import com.google.common.base.Optional; - import java.net.InetSocketAddress; - import org.osgi.framework.BundleContext; - import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Optional; +import org.osgi.framework.BundleContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.InetSocketAddress; + +import static com.google.common.base.Preconditions.checkNotNull; public class NetconfConfigUtil { + private static final Logger logger = LoggerFactory.getLogger(NetconfConfigUtil.class); + private static final String PREFIX_PROP = "netconf."; + + private enum InfixProp { tcp, ssh } @@ -23,6 +31,24 @@ public class NetconfConfigUtil { private static final String PORT_SUFFIX_PROP = ".port"; private static final String ADDRESS_SUFFIX_PROP = ".address"; private static final String CLIENT_PROP = ".client"; + private static final String PRIVATE_KEY_PATH_PROP = ".pk.path"; + + private static final String CONNECTION_TIMEOUT_MILLIS_PROP = "connectionTimeoutMillis"; + private static final long DEFAULT_TIMEOUT_MILLIS = 5000; + + public static long extractTimeoutMillis(BundleContext bundleContext) { + String key = PREFIX_PROP + CONNECTION_TIMEOUT_MILLIS_PROP; + String timeoutString = bundleContext.getProperty(key); + if (timeoutString == null || timeoutString.length() == 0) { + return DEFAULT_TIMEOUT_MILLIS; + } + try { + return Long.parseLong(timeoutString); + }catch(NumberFormatException e) { + logger.warn("Cannot parse {} property: {}, using defaults", key, timeoutString, e); + return DEFAULT_TIMEOUT_MILLIS; + } + } public static InetSocketAddress extractTCPNetconfAddress(BundleContext context, String exceptionMessageIfNotFound, boolean forClient) { @@ -31,13 +57,28 @@ public class NetconfConfigUtil { if (inetSocketAddressOptional.isPresent() == false) { throw new IllegalStateException("Netconf tcp address not found." + exceptionMessageIfNotFound); } - return inetSocketAddressOptional.get(); + InetSocketAddress inetSocketAddress = inetSocketAddressOptional.get(); + if (inetSocketAddress.getAddress().isAnyLocalAddress()) { + logger.warn("Unprotected netconf TCP address is configured to ANY local address. This is a security risk. " + + "Consider changing {} to 127.0.0.1", PREFIX_PROP + InfixProp.tcp + ADDRESS_SUFFIX_PROP); + } + return inetSocketAddress; } public static Optional extractSSHNetconfAddress(BundleContext context, String exceptionMessage) { return extractSomeNetconfAddress(context, InfixProp.ssh, exceptionMessage, false); } + public static String getPrivateKeyPath(BundleContext context){ + return getPropertyValue(context,PREFIX_PROP + InfixProp.ssh +PRIVATE_KEY_PATH_PROP); + } + private static String getPropertyValue(BundleContext context, String propertyName){ + String propertyValue = context.getProperty(propertyName); + if (propertyValue == null){ + throw new IllegalStateException("Cannot find initial property with name '"+propertyName+"'"); + } + return propertyValue; + } /** * @param context * from which properties are being read.