BAEL-7340 Using Custom TrustStore in Java (#15562)

* BAEL-6953 implemented

* BAEL-6953 added live test

* Fixed test

* BAEL-7340 Using Custom TrustStore in Java

* BAEL-7340 Added explicit --add-exports statement for core-java-security-4
This commit is contained in:
Mikhail Polivakha
2024-01-09 06:08:14 +03:00
committed by GitHub
parent b467eb65f6
commit 7a14fcdb32
5 changed files with 176 additions and 0 deletions
@@ -0,0 +1,32 @@
package com.baeldung.multiple_truststores;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;
import org.junit.jupiter.api.Test;
import com.baeldung.multiple_truststores.SslContextConfigurer;
import sun.security.x509.X509CertImpl;
public class SslContextConfigurerUnitTest {
@Test
public void givenCustomTrustManager_whenCheckingCertificateValidity_thenTrustManagerApprovesCert()
throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
X509TrustManager trustManager = SslContextConfigurer.addAdditionalTrustStore(
"new_trustStore.p12",
"change"
);
InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("cert_to_check.pem");
X509CertImpl x509Cert = new X509CertImpl(resourceAsStream);
trustManager.checkClientTrusted(new X509Certificate[]{x509Cert}, "server");
}
}