Search in sources :

Example 1 with SslContextFactory

use of org.opendaylight.protocol.pcep.impl.tls.SslContextFactory in project bgpcep by opendaylight.

the class SslContextFactoryTest method testSslContextFactory.

@Test
public void testSslContextFactory() {
    final SslContextFactory sslContextFactory = new SslContextFactory(createTlsConfig());
    final SSLContext sslContext = sslContextFactory.getServerContext();
    assertNotNull(sslContext);
}
Also used : SslContextFactory(org.opendaylight.protocol.pcep.impl.tls.SslContextFactory) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.Test)

Example 2 with SslContextFactory

use of org.opendaylight.protocol.pcep.impl.tls.SslContextFactory in project bgpcep by opendaylight.

the class AbstractPCEPSessionNegotiator method handleMessageStartTlsWait.

private boolean handleMessageStartTlsWait(final Message msg) {
    if (msg instanceof Starttls) {
        final SslContextFactory sslFactory = new SslContextFactory(this.tlsConfiguration);
        final SSLContext sslContext = sslFactory.getServerContext();
        if (sslContext == null) {
            this.sendErrorMessage(PCEPErrors.NOT_POSSIBLE_WITHOUT_TLS);
            negotiationFailed(new IllegalStateException("Failed to establish a TLS connection."));
            this.state = State.FINISHED;
            return true;
        }
        final SSLEngine engine = sslContext.createSSLEngine();
        engine.setNeedClientAuth(true);
        engine.setUseClientMode(false);
        this.channel.pipeline().addFirst(new SslHandler(engine));
        LOG.info("PCEPS TLS connection with peer: {} established succesfully.", this.channel);
        startNegotiationWithOpen();
        return true;
    } else if (!(msg instanceof Pcerr)) {
        this.sendErrorMessage(PCEPErrors.NON_STARTTLS_MSG_RCVD);
        negotiationFailed(new IllegalStateException("Unexpected message recieved."));
        this.state = State.FINISHED;
        return true;
    }
    return false;
}
Also used : SslContextFactory(org.opendaylight.protocol.pcep.impl.tls.SslContextFactory) SSLEngine(javax.net.ssl.SSLEngine) Pcerr(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr) SSLContext(javax.net.ssl.SSLContext) Starttls(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Starttls) SslHandler(io.netty.handler.ssl.SslHandler)

Aggregations

SSLContext (javax.net.ssl.SSLContext)2 SslContextFactory (org.opendaylight.protocol.pcep.impl.tls.SslContextFactory)2 SslHandler (io.netty.handler.ssl.SslHandler)1 SSLEngine (javax.net.ssl.SSLEngine)1 Test (org.junit.Test)1 Pcerr (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Pcerr)1 Starttls (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Starttls)1