Search in sources :

Example 1 with Tls

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Tls in project bgpcep by opendaylight.

the class FiniteStateMachineTest method testFailedToEstablishTLS.

/**
 * As Tls is not configured properly, PCE will send error PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS.
 */
@Test
public void testFailedToEstablishTLS() {
    this.tlsSessionNegotiator.channelActive(null);
    assertEquals(1, this.msgsSend.size());
    assertTrue(this.msgsSend.get(0) instanceof Starttls);
    assertEquals(DefaultPCEPSessionNegotiator.State.START_TLS_WAIT, this.tlsSessionNegotiator.getState());
    this.tlsSessionNegotiator.handleMessage(this.startTlsMsg);
    assertEquals(2, this.msgsSend.size());
    assertTrue(this.msgsSend.get(1) instanceof Pcerr);
    final Errors obj = ((Pcerr) this.msgsSend.get(1)).getPcerrMessage().getErrors().get(0);
    assertEquals(PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS.getErrorType(), obj.getErrorObject().getType());
    assertEquals(PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS.getErrorValue(), obj.getErrorObject().getValue());
    assertEquals(DefaultPCEPSessionNegotiator.State.FINISHED, this.tlsSessionNegotiator.getState());
}
Also used : Errors(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.Errors) PCEPErrors(org.opendaylight.protocol.pcep.spi.PCEPErrors) Pcerr(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcerr) Starttls(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Starttls) Test(org.junit.Test)

Example 2 with Tls

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Tls in project bgpcep by opendaylight.

the class FiniteStateMachineTest method testEstablishTLS.

/**
 * Establish PCEPS TLS connection with peer.
 */
@Test
public void testEstablishTLS() {
    final DefaultPCEPSessionNegotiator negotiator = new DefaultPCEPSessionNegotiator(new DefaultPromise<>(GlobalEventExecutor.INSTANCE), this.channel, this.listener, (short) 1, 20, new OpenBuilder().setKeepalive(Uint8.ONE).build(), SslContextFactoryTest.createTlsConfig());
    negotiator.channelActive(null);
    assertEquals(1, this.msgsSend.size());
    assertTrue(this.msgsSend.get(0) instanceof Starttls);
    assertEquals(DefaultPCEPSessionNegotiator.State.START_TLS_WAIT, negotiator.getState());
    negotiator.handleMessage(this.startTlsMsg);
    assertEquals(DefaultPCEPSessionNegotiator.State.OPEN_WAIT, negotiator.getState());
    assertEquals(2, this.msgsSend.size());
    assertTrue(this.msgsSend.get(1) instanceof Open);
    negotiator.handleMessage(this.openMsg);
    assertEquals(DefaultPCEPSessionNegotiator.State.KEEP_WAIT, negotiator.getState());
}
Also used : OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder) Starttls(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Starttls) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Open) Test(org.junit.Test)

Example 3 with Tls

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Tls in project netconf by opendaylight.

the class IetfZeroTouchCallHomeServerProvider method createOperationalDevice.

private Device createOperationalDevice(final Device cfgDevice, final Device1 devStatus) {
    final DeviceBuilder deviceBuilder = new DeviceBuilder().addAugmentation(devStatus).setUniqueId(cfgDevice.getUniqueId());
    if (cfgDevice.getTransport() instanceof Ssh) {
        final String hostKey = ((Ssh) cfgDevice.getTransport()).getSshClientParams().getHostKey();
        final SshClientParams params = new SshClientParamsBuilder().setHostKey(hostKey).build();
        final Transport sshTransport = new SshBuilder().setSshClientParams(params).build();
        deviceBuilder.setTransport(sshTransport);
    } else if (cfgDevice.getTransport() instanceof Tls) {
        deviceBuilder.setTransport(cfgDevice.getTransport());
    } else if (cfgDevice.getSshHostKey() != null) {
        deviceBuilder.setSshHostKey(cfgDevice.getSshHostKey());
    }
    return deviceBuilder.build();
}
Also used : DeviceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.DeviceBuilder) SshClientParams(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParams) SshClientParamsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.ssh.SshClientParamsBuilder) SshBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.SshBuilder) Ssh(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Ssh) Tls(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Tls) Transport(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.Transport)

Example 4 with Tls

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Tls 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 5 with Tls

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.device.transport.Tls in project bgpcep by opendaylight.

the class AbstractPCEPSessionNegotiator method startNegotiation.

@Override
protected final void startNegotiation() {
    Preconditions.checkState(this.state == State.IDLE);
    if (this.tlsConfiguration != null) {
        this.sendMessage(new StarttlsBuilder().setStartTlsMessage(new StartTlsMessageBuilder().build()).build());
        this.state = State.START_TLS_WAIT;
        scheduleFailTimer();
        LOG.info("Started TLS connection negotiation with peer {}", this.channel);
    } else {
        startNegotiationWithOpen();
    }
    this.channel.closeFuture().addListener((ChannelFutureListener) f -> cancelTimers());
}
Also used : KeepaliveMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.keepalive.message.KeepaliveMessageBuilder) SSLContext(javax.net.ssl.SSLContext) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive) Pcerr(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcerr) OpenMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.OpenMessage) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) SSLEngine(javax.net.ssl.SSLEngine) Future(java.util.concurrent.Future) PCEPErrors(org.opendaylight.protocol.pcep.spi.PCEPErrors) ChannelFutureListener(io.netty.channel.ChannelFutureListener) SslContextFactory(org.opendaylight.protocol.pcep.impl.tls.SslContextFactory) Tls(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls) ErrorObject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcep.error.object.ErrorObject) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.OpenBuilder) Logger(org.slf4j.Logger) Promise(io.netty.util.concurrent.Promise) Starttls(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Starttls) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Util(org.opendaylight.protocol.pcep.impl.spi.Util) OpenMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessageBuilder) StarttlsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.StarttlsBuilder) SslHandler(io.netty.handler.ssl.SslHandler) KeepaliveBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.KeepaliveBuilder) Message(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message) Open(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StartTlsMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.start.tls.message.StartTlsMessageBuilder) SessionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.pcerr.message.pcerr.message.error.type.SessionCase) StartTlsMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.start.tls.message.StartTlsMessageBuilder) StarttlsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.StarttlsBuilder)

Aggregations

Starttls (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Starttls)4 SslHandler (io.netty.handler.ssl.SslHandler)3 SSLContext (javax.net.ssl.SSLContext)3 SSLEngine (javax.net.ssl.SSLEngine)3 Pcerr (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcerr)3 KeyStore (java.security.KeyStore)2 Test (org.junit.Test)2 SslContextFactory (org.opendaylight.protocol.pcep.impl.tls.SslContextFactory)2 PCEPErrors (org.opendaylight.protocol.pcep.spi.PCEPErrors)2 TlsCase (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.protocol.specification.TlsCase)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Channel (io.netty.channel.Channel)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 Promise (io.netty.util.concurrent.Promise)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyStoreException (java.security.KeyStoreException)1 Certificate (java.security.cert.Certificate)1 CertificateException (java.security.cert.CertificateException)1