2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.it;
11 import io.netty.channel.ChannelFuture;
12 import org.junit.After;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
16 import org.opendaylight.controller.config.spi.ModuleFactory;
17 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
18 import org.opendaylight.controller.netconf.client.test.TestingNetconfClient;
19 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.NetconfOperationServiceFactoryImpl;
20 import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException;
21 import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer;
22 import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher;
23 import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl;
25 import javax.net.ssl.KeyManagerFactory;
26 import javax.net.ssl.SSLContext;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.lang.management.ManagementFactory;
30 import java.net.InetSocketAddress;
31 import java.security.KeyManagementException;
32 import java.security.KeyStoreException;
33 import java.security.NoSuchAlgorithmException;
34 import java.security.UnrecoverableKeyException;
35 import java.security.cert.CertificateException;
36 import java.util.Collection;
37 import java.util.List;
39 public class NetconfITSecureTest extends AbstractNetconfConfigTest {
41 private static final InetSocketAddress tlsAddress = new InetSocketAddress("127.0.0.1", 12024);
43 private DefaultCommitNotificationProducer commitNot;
44 private NetconfServerDispatcher dispatchS;
48 public void setUp() throws Exception {
49 super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(getModuleFactories().toArray(
50 new ModuleFactory[0])));
52 NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl();
53 factoriesListener.onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore()));
55 commitNot = new DefaultCommitNotificationProducer(ManagementFactory.getPlatformMBeanServer());
58 dispatchS = createDispatcher(factoriesListener);
59 ChannelFuture s = dispatchS.createServer(tlsAddress);
63 private NetconfServerDispatcher createDispatcher(NetconfOperationServiceFactoryListenerImpl factoriesListener) {
64 return super.createDispatcher(factoriesListener, NetconfITTest.getNetconfMonitoringListenerService(), commitNot);
68 public void tearDown() throws Exception {
72 private SSLContext getSslContext() throws KeyStoreException, NoSuchAlgorithmException, CertificateException,
73 IOException, UnrecoverableKeyException, KeyManagementException {
74 final InputStream keyStore = getClass().getResourceAsStream("/keystore.jks");
75 final InputStream trustStore = getClass().getResourceAsStream("/keystore.jks");
76 SSLContext sslContext = SSLUtil.initializeSecureContext("password", keyStore, trustStore, KeyManagerFactory.getDefaultAlgorithm());
82 private HardcodedYangStoreService getYangStore() throws YangStoreException, IOException {
83 final Collection<InputStream> yangDependencies = NetconfITTest.getBasicYangs();
84 return new HardcodedYangStoreService(yangDependencies);
87 protected List<ModuleFactory> getModuleFactories() {
88 return NetconfITTest.getModuleFactoriesS();
92 public void testSecure() throws Exception {
93 NetconfClientDispatcher dispatch = new NetconfClientDispatcher(nettyThreadgroup, nettyThreadgroup, 5000);
94 try (TestingNetconfClient netconfClient = new TestingNetconfClient("tls-client", tlsAddress, 4000, dispatch)) {