From: Robert Varga Date: Tue, 30 Jan 2024 00:23:05 +0000 (+0100) Subject: Require key specification X-Git-Tag: v7.0.0~76 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=081fb37b7b3f19e0ee12e5fa42e2bfc1c94adc25;p=netconf.git Require key specification We have a testing-only utility method. Ditch it in favor of supplying the value from tests. JIRA: NETCONF-1237 Change-Id: Ibe0a0f3c78365043401e5a80db00c3e841ac9027 Signed-off-by: Robert Varga --- diff --git a/plugins/netconf-client-mdsal/src/main/java/org/opendaylight/netconf/client/mdsal/impl/DefaultSslHandlerFactoryProvider.java b/plugins/netconf-client-mdsal/src/main/java/org/opendaylight/netconf/client/mdsal/impl/DefaultSslHandlerFactoryProvider.java index 0ff1359374..f26655eb2e 100644 --- a/plugins/netconf-client-mdsal/src/main/java/org/opendaylight/netconf/client/mdsal/impl/DefaultSslHandlerFactoryProvider.java +++ b/plugins/netconf-client-mdsal/src/main/java/org/opendaylight/netconf/client/mdsal/impl/DefaultSslHandlerFactoryProvider.java @@ -72,19 +72,6 @@ public final class DefaultSslHandlerFactoryProvider extends AbstractNetconfKeyst throw new IllegalArgumentException("Cannot get TLS specification from: " + specification); } - /** - * Using private keys and trusted certificates to create a new JDK KeyStore which - * will be used by TLS clients to create SSLEngine. The private keys are essential - * to create JDK KeyStore while the trusted certificates are optional. - * - * @return A JDK KeyStore object - * @throws GeneralSecurityException If any security exception occurred - * @throws IOException If there is an I/O problem with the keystore data - */ - KeyStore getJavaKeyStore() throws GeneralSecurityException, IOException { - return getJavaKeyStore(Set.of()); - } - /** * Using private keys and trusted certificates to create a new JDK KeyStore which * will be used by TLS clients to create SSLEngine. The private keys are essential diff --git a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/impl/DefaultSslHandlerFactoryProviderTest.java b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/impl/DefaultSslHandlerFactoryProviderTest.java index c59f62805a..08f41b46db 100644 --- a/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/impl/DefaultSslHandlerFactoryProviderTest.java +++ b/plugins/netconf-client-mdsal/src/test/java/org/opendaylight/netconf/client/mdsal/impl/DefaultSslHandlerFactoryProviderTest.java @@ -18,6 +18,7 @@ import static org.mockito.Mockito.doReturn; import java.security.KeyStoreException; import java.util.ArrayList; import java.util.List; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -78,7 +79,7 @@ class DefaultSslHandlerFactoryProviderTest { @Test void testKeystoreAdapterInit() throws Exception { try (var keystoreAdapter = new DefaultSslHandlerFactoryProvider(dataBroker)) { - final var ex = assertThrows(KeyStoreException.class, keystoreAdapter::getJavaKeyStore); + final var ex = assertThrows(KeyStoreException.class, () -> keystoreAdapter.getJavaKeyStore(Set.of())); assertThat(ex.getMessage(), startsWith("No keystore private key found")); } } @@ -96,7 +97,7 @@ class DefaultSslHandlerFactoryProviderTest { try (var keystoreAdapter = new DefaultSslHandlerFactoryProvider(dataBroker)) { listener.onDataTreeChanged(List.of(dataTreeModification1)); - final var keyStore = keystoreAdapter.getJavaKeyStore(); + final var keyStore = keystoreAdapter.getJavaKeyStore(Set.of()); assertTrue(keyStore.containsAlias(privateKey.getName())); } } @@ -129,7 +130,7 @@ class DefaultSslHandlerFactoryProviderTest { listener.onDataTreeChanged(List.of(dataTreeModification1, dataTreeModification2)); // Check result - final var keyStore = keystoreAdapter.getJavaKeyStore(); + final var keyStore = keystoreAdapter.getJavaKeyStore(Set.of()); assertTrue(keyStore.containsAlias(privateKey.getName())); assertTrue(keyStore.containsAlias(trustedCertificate.getName())); }