use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.protocol.specification.TlsCase in project netconf by opendaylight.
the class SslHandlerFactoryImpl method createSslHandler.
@Override
public SslHandler createSslHandler(Set<String> allowedKeys) {
try {
final KeyStore keyStore = keystoreAdapter.getJavaKeyStore(allowedKeys);
final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, "".toCharArray());
final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
final SSLContext sslCtx = SSLContext.getInstance("TLS");
sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
final SSLEngine engine = sslCtx.createSSLEngine();
engine.setUseClientMode(true);
final String[] engineProtocols = engine.getSupportedProtocols();
final String[] enabledProtocols;
if (specification != null) {
checkArgument(specification instanceof TlsCase, "Cannot get TLS specification from: %s", specification);
final Set<String> protocols = Sets.newHashSet(engineProtocols);
protocols.removeAll(((TlsCase) specification).getTls().getExcludedVersions());
enabledProtocols = protocols.toArray(new String[0]);
} else {
enabledProtocols = engineProtocols;
}
engine.setEnabledProtocols(enabledProtocols);
engine.setEnabledCipherSuites(engine.getSupportedCipherSuites());
engine.setEnableSessionCreation(true);
return new SslHandler(engine);
} catch (GeneralSecurityException | IOException exc) {
throw new IllegalStateException(exc);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.protocol.specification.TlsCase in project netconf by opendaylight.
the class NetconfConnectDeviceCommand method execute.
@Override
public Object execute() {
if (!NetconfCommandUtils.isIpValid(deviceIp) || !NetconfCommandUtils.isPortValid(devicePort)) {
return "Invalid IP:" + deviceIp + " or Port:" + devicePort + "Please enter a valid entry to proceed.";
}
final boolean isTcpOnly = connectionType.equals("true");
final boolean isSchemaless = schemaless.equals("true");
final NetconfNodeBuilder netconfNodeBuilder = new NetconfNodeBuilder();
netconfNodeBuilder.setHost(new Host(new IpAddress(new Ipv4Address(deviceIp)))).setPort(new PortNumber(Uint16.valueOf(Integer.decode(devicePort)))).setTcpOnly(isTcpOnly).setSchemaless(isSchemaless);
if (isTcpOnly || protocol.equalsIgnoreCase("ssh")) {
if (Strings.isNullOrEmpty(username) || Strings.isNullOrEmpty(password)) {
return "Empty Username:" + username + " or Password:" + password + ". In TCP or SSH mode, you must provide valid username and password.";
}
final Credentials credentials = new LoginPasswordBuilder().setPassword(password).setUsername(username).build();
netconfNodeBuilder.setCredentials(credentials);
if (!isTcpOnly) {
netconfNodeBuilder.setProtocol(new ProtocolBuilder().setName(Name.SSH).build());
}
} else if (protocol.equalsIgnoreCase("tls")) {
TlsCase tlsCase = null;
if (!Strings.isNullOrEmpty(excludedTlsVersions)) {
tlsCase = new TlsCaseBuilder().setTls(new TlsBuilder().setExcludedVersions(Arrays.asList(excludedTlsVersions.split(","))).build()).build();
}
netconfNodeBuilder.setProtocol(new ProtocolBuilder().setName(Name.TLS).setSpecification(tlsCase).build());
} else {
return "Invalid protocol: " + protocol + ". Only SSH and TLS are supported.";
}
service.connectDevice(netconfNodeBuilder.build(), deviceId);
final String message = "Netconf connector added succesfully";
return message;
}
Aggregations