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());
}
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());
}
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();
}
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);
}
}
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());
}
Aggregations