2 * Copyright (c) 2020 Pantheon Technologies, s.r.o. 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
8 package org.opendaylight.netconf.callhome.mount.tls;
10 import io.netty.handler.ssl.SslHandler;
12 import org.opendaylight.mdsal.binding.api.DataBroker;
13 import org.opendaylight.netconf.callhome.protocol.tls.TlsAllowedDevicesMonitor;
14 import org.opendaylight.netconf.client.SslHandlerFactory;
15 import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfKeystoreAdapter;
16 import org.opendaylight.netconf.sal.connect.util.SslHandlerFactoryImpl;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class SslHandlerFactoryAdapter implements SslHandlerFactory {
21 private static final Logger LOG = LoggerFactory.getLogger(SslHandlerFactoryAdapter.class);
23 private final TlsAllowedDevicesMonitor allowedDevicesMonitor;
24 private final SslHandlerFactory sslHandlerFactory;
26 public SslHandlerFactoryAdapter(final DataBroker dataBroker, final TlsAllowedDevicesMonitor allowedDevicesMonitor) {
27 final NetconfKeystoreAdapter keystoreAdapter = new NetconfKeystoreAdapter(dataBroker);
28 this.sslHandlerFactory = new SslHandlerFactoryImpl(keystoreAdapter);
29 this.allowedDevicesMonitor = allowedDevicesMonitor;
33 public SslHandler createSslHandler() {
34 return createSslHandlerFilteredByKeys();
38 public SslHandler createSslHandler(final Set<String> allowedKeys) {
39 return createSslHandlerFilteredByKeys();
42 private SslHandler createSslHandlerFilteredByKeys() {
43 if (allowedDevicesMonitor.findAllowedKeys().isEmpty()) {
44 LOG.error("No associated keys for TLS authentication were found");
45 throw new IllegalStateException("No associated keys for TLS authentication were found");
47 return sslHandlerFactory.createSslHandler(allowedDevicesMonitor.findAllowedKeys());