Search in sources :

Example 1 with TlsCase

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);
    }
}
Also used : TlsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.protocol.specification.TlsCase) SSLEngine(javax.net.ssl.SSLEngine) GeneralSecurityException(java.security.GeneralSecurityException) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) KeyStore(java.security.KeyStore) SslHandler(io.netty.handler.ssl.SslHandler) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) TrustManagerFactory(javax.net.ssl.TrustManagerFactory)

Example 2 with TlsCase

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;
}
Also used : TlsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.protocol.specification.TlsCase) NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) TlsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.protocol.specification.TlsCaseBuilder) Host(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host) ProtocolBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.ProtocolBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) LoginPasswordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder) TlsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.protocol.specification.tls._case.TlsBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) Credentials(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Aggregations

TlsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.protocol.specification.TlsCase)2 SslHandler (io.netty.handler.ssl.SslHandler)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyStore (java.security.KeyStore)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1 SSLContext (javax.net.ssl.SSLContext)1 SSLEngine (javax.net.ssl.SSLEngine)1 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)1 Host (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)1 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)1 NetconfNodeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder)1 ProtocolBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.ProtocolBuilder)1 TlsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.protocol.specification.TlsCaseBuilder)1 TlsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.protocol.specification.tls._case.TlsBuilder)1 Credentials (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials)1 LoginPasswordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder)1