NIFI-8088 Removed deprecation warning log for PKCS12 trust stores

Signed-off-by: Nathan Gough <thenatog@gmail.com>

This closes #4727.
This commit is contained in:
exceptionfactory 2020-12-14 10:51:20 -05:00 committed by Nathan Gough
parent 67d06003b7
commit 2cdb0fb6a3
8 changed files with 10 additions and 30 deletions

View File

@ -88,20 +88,6 @@ public class KeyStoreUtils {
return KeyStore.getInstance(keyStoreType); return KeyStore.getInstance(keyStoreType);
} }
/**
* Returns an empty KeyStore intended for use as a TrustStore backed by the appropriate provider
*
* @param trustStoreType the trustStoreType
* @return an empty KeyStore
* @throws KeyStoreException if a KeyStore of the given type cannot be instantiated
*/
public static KeyStore getTrustStore(String trustStoreType) throws KeyStoreException {
if (KeystoreType.PKCS12.toString().equalsIgnoreCase(trustStoreType)) {
logger.warn(trustStoreType + " truststores are deprecated. " + KeystoreType.JKS.toString() + " is preferred.");
}
return getKeyStore(trustStoreType);
}
/** /**
* Returns a loaded {@link KeyStore} given the provided configuration values. * Returns a loaded {@link KeyStore} given the provided configuration values.
* *
@ -194,7 +180,7 @@ public class KeyStoreUtils {
public static KeyStore loadTrustStore(String truststorePath, char[] truststorePassword, String truststoreType) throws TlsException { public static KeyStore loadTrustStore(String truststorePath, char[] truststorePassword, String truststoreType) throws TlsException {
final KeyStore trustStore; final KeyStore trustStore;
try { try {
trustStore = KeyStoreUtils.getTrustStore(truststoreType); trustStore = KeyStoreUtils.getKeyStore(truststoreType);
try (final InputStream trustStoreStream = new FileInputStream(truststorePath)) { try (final InputStream trustStoreStream = new FileInputStream(truststorePath)) {
trustStore.load(trustStoreStream, truststorePassword); trustStore.load(trustStoreStream, truststorePassword);
} }

View File

@ -88,17 +88,17 @@ public class KeyStoreUtilsTest {
@Test @Test
public void testJksTrustStoreRoundTrip() throws GeneralSecurityException, IOException { public void testJksTrustStoreRoundTrip() throws GeneralSecurityException, IOException {
testTrustStoreRoundTrip(() -> KeyStoreUtils.getTrustStore(KeystoreType.JKS.toString().toLowerCase())); testTrustStoreRoundTrip(() -> KeyStoreUtils.getKeyStore(KeystoreType.JKS.toString().toLowerCase()));
} }
@Test @Test
public void testPkcs12TrustStoreBcRoundTrip() throws GeneralSecurityException, IOException { public void testPkcs12TrustStoreBcRoundTrip() throws GeneralSecurityException, IOException {
testTrustStoreRoundTrip(() -> KeyStoreUtils.getTrustStore(KeystoreType.PKCS12.toString().toLowerCase())); testTrustStoreRoundTrip(() -> KeyStoreUtils.getKeyStore(KeystoreType.PKCS12.toString().toLowerCase()));
} }
@Test @Test
public void testPkcs12TrustStoreRoundTripBcReload() throws GeneralSecurityException, IOException { public void testPkcs12TrustStoreRoundTripBcReload() throws GeneralSecurityException, IOException {
testTrustStoreRoundTrip(() -> KeyStore.getInstance(KeystoreType.PKCS12.toString().toLowerCase()), () -> KeyStoreUtils.getTrustStore(KeystoreType.PKCS12.toString().toLowerCase())); testTrustStoreRoundTrip(() -> KeyStore.getInstance(KeystoreType.PKCS12.toString().toLowerCase()), () -> KeyStoreUtils.getKeyStore(KeystoreType.PKCS12.toString().toLowerCase()));
} }
private void testTrustStoreRoundTrip(KeyStoreSupplier keyStoreSupplier) throws GeneralSecurityException, IOException { private void testTrustStoreRoundTrip(KeyStoreSupplier keyStoreSupplier) throws GeneralSecurityException, IOException {

View File

@ -902,13 +902,7 @@ public interface SiteToSiteClient extends Closeable {
final TrustManagerFactory trustManagerFactory; final TrustManagerFactory trustManagerFactory;
if (truststoreFilename != null && truststorePass != null && truststoreType != null) { if (truststoreFilename != null && truststorePass != null && truststoreType != null) {
try { try {
// prepare the truststore trustManagerFactory = KeyStoreUtils.loadTrustManagerFactory(truststoreFilename, truststorePass, getTruststoreType().name());
final KeyStore trustStore = KeyStoreUtils.getTrustStore(getTruststoreType().name());
try (final InputStream trustStoreStream = new FileInputStream(new File(getTruststoreFilename()))) {
trustStore.load(trustStoreStream, truststorePass.toCharArray());
}
trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
} catch (final Exception e) { } catch (final Exception e) {
throw new IllegalStateException("Failed to load Truststore", e); throw new IllegalStateException("Failed to load Truststore", e);
} }

View File

@ -194,7 +194,7 @@ public class OcspCertificateValidator {
// load the configured truststore // load the configured truststore
try (final FileInputStream fis = new FileInputStream(truststorePath)) { try (final FileInputStream fis = new FileInputStream(truststorePath)) {
final KeyStore truststore = KeyStoreUtils.getTrustStore(KeyStore.getDefaultType()); final KeyStore truststore = KeyStoreUtils.getKeyStore(KeyStore.getDefaultType());
truststore.load(fis, truststorePassword); truststore.load(fis, truststorePassword);
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());

View File

@ -332,7 +332,7 @@ public class GetHTTP extends AbstractSessionFactoryProcessor {
final SSLContextBuilder sslContextBuilder = new SSLContextBuilder(); final SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
if (StringUtils.isNotBlank(service.getTrustStoreFile())) { if (StringUtils.isNotBlank(service.getTrustStoreFile())) {
final KeyStore truststore = KeyStoreUtils.getTrustStore(service.getTrustStoreType()); final KeyStore truststore = KeyStoreUtils.getKeyStore(service.getTrustStoreType());
try (final InputStream in = new FileInputStream(new File(service.getTrustStoreFile()))) { try (final InputStream in = new FileInputStream(new File(service.getTrustStoreFile()))) {
truststore.load(in, service.getTrustStorePassword().toCharArray()); truststore.load(in, service.getTrustStorePassword().toCharArray());
} }

View File

@ -514,7 +514,7 @@ public class PostHTTP extends AbstractProcessor {
SSLContextBuilder builder = SSLContexts.custom(); SSLContextBuilder builder = SSLContexts.custom();
final String trustFilename = service.getTrustStoreFile(); final String trustFilename = service.getTrustStoreFile();
if (trustFilename != null) { if (trustFilename != null) {
final KeyStore truststore = KeyStoreUtils.getTrustStore(service.getTrustStoreType()); final KeyStore truststore = KeyStoreUtils.getKeyStore(service.getTrustStoreType());
try (final InputStream in = new FileInputStream(new File(service.getTrustStoreFile()))) { try (final InputStream in = new FileInputStream(new File(service.getTrustStoreFile()))) {
truststore.load(in, service.getTrustStorePassword().toCharArray()); truststore.load(in, service.getTrustStorePassword().toCharArray());
} }

View File

@ -251,7 +251,7 @@ public class TlsCertificateAuthorityTest {
// Does the certificate contain the SAN we defined in the client config? // Does the certificate contain the SAN we defined in the client config?
assert(isSANPresent(certificateChain[0])); assert(isSANPresent(certificateChain[0]));
KeyStore clientTrustStore = KeyStoreUtils.getTrustStore(KeystoreType.JKS.toString()); KeyStore clientTrustStore = KeyStoreUtils.getKeyStore(KeystoreType.JKS.toString());
clientTrustStore.load(new ByteArrayInputStream(clientTrustStoreOutputStream.toByteArray()), clientConfig.getTrustStorePassword().toCharArray()); clientTrustStore.load(new ByteArrayInputStream(clientTrustStoreOutputStream.toByteArray()), clientConfig.getTrustStorePassword().toCharArray());
assertEquals(caCertificate, clientTrustStore.getCertificate(TlsToolkitStandalone.NIFI_CERT)); assertEquals(caCertificate, clientTrustStore.getCertificate(TlsToolkitStandalone.NIFI_CERT));
} }

View File

@ -464,7 +464,7 @@ public class TlsToolkitStandaloneTest {
String trustStoreType = nifiProperties.getProperty(NiFiProperties.SECURITY_TRUSTSTORE_TYPE); String trustStoreType = nifiProperties.getProperty(NiFiProperties.SECURITY_TRUSTSTORE_TYPE);
assertEquals(KeystoreType.JKS.toString().toLowerCase(), trustStoreType.toLowerCase()); assertEquals(KeystoreType.JKS.toString().toLowerCase(), trustStoreType.toLowerCase());
KeyStore trustStore = KeyStoreUtils.getTrustStore(trustStoreType); KeyStore trustStore = KeyStoreUtils.getKeyStore(trustStoreType);
try (InputStream inputStream = new FileInputStream(new File(hostDir, "truststore." + trustStoreType))) { try (InputStream inputStream = new FileInputStream(new File(hostDir, "truststore." + trustStoreType))) {
trustStore.load(inputStream, nifiProperties.getProperty(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD).toCharArray()); trustStore.load(inputStream, nifiProperties.getProperty(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD).toCharArray());
} }