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 static java.util.Objects.requireNonNull;
12 import io.netty.handler.ssl.SslHandler;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.netconf.callhome.protocol.tls.TlsAllowedDevicesMonitor;
16 import org.opendaylight.netconf.client.SslHandlerFactory;
17 import org.opendaylight.netconf.client.mdsal.api.NetconfKeystoreAdapter;
18 import org.opendaylight.netconf.sal.connect.util.SslHandlerFactoryImpl;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class SslHandlerFactoryAdapter implements SslHandlerFactory {
23 private static final Logger LOG = LoggerFactory.getLogger(SslHandlerFactoryAdapter.class);
25 private final TlsAllowedDevicesMonitor allowedDevicesMonitor;
26 private final SslHandlerFactory sslHandlerFactory;
28 public SslHandlerFactoryAdapter(final NetconfKeystoreAdapter keystoreAdapter,
29 final @NonNull TlsAllowedDevicesMonitor allowedDevicesMonitor) {
30 this.allowedDevicesMonitor = requireNonNull(allowedDevicesMonitor);
31 sslHandlerFactory = new SslHandlerFactoryImpl(keystoreAdapter);
35 public SslHandler createSslHandler() {
36 return createSslHandlerFilteredByKeys();
40 public SslHandler createSslHandler(final Set<String> allowedKeys) {
41 // FIXME: we are ignoring passed in keys?!
42 return createSslHandlerFilteredByKeys();
45 private SslHandler createSslHandlerFilteredByKeys() {
46 final var allowedKeys = allowedDevicesMonitor.findAllowedKeys();
47 if (allowedKeys.isEmpty()) {
48 LOG.error("No associated keys for TLS authentication were found");
49 throw new IllegalStateException("No associated keys for TLS authentication were found");
51 return sslHandlerFactory.createSslHandler(allowedKeys);