I'm trying to acess a apllication secured by https, i have a p12 certificate (already imported as .cer into cacerts folder of my jdk).
I already tried this tutorial to no success:
https://dzone.com/articles/ssl-based-feignclient-example-in-java-microcervice
And also i'm using part of this solution:
How to use p12 client certificate with spring feign client
Debuging the ssl connection i get the following error:
javax.net.ssl|ERROR|25|http-nio-auto-1-exec-1|2021-01-26 16:56:34.789 BRT|TransportContext.java:317|Fatal (HANDSHAKE_FAILURE): Received fatal alert: handshake_failure
My current feign config class
@Bean
@ConditionalOnMissingBean
public Feign.Builder feignBuilder(Retryer retryer) {
return Feign.builder().retryer(retryer);
}
@Bean
public Feign.Builder feignBuilder() {
return Feign.builder()
.retryer(Retryer.NEVER_RETRY)
.client(new Client.Default(getSSLSocketFactory(), null));
}
private SSLSocketFactory getSSLSocketFactory() {
String keyStorePassword = "myPassword";
char[] allPassword = keyStorePassword.toCharArray();
SSLContext sslContext = null;
try {
sslContext = SSLContextBuilder
.create()
.setKeyStoreType("PKCS12")
.loadKeyMaterial(ResourceUtils.getFile("keypath"), allPassword, allPassword)
.build();
} catch (Exception e) { }
return sslContext.getSocketFactory();
}
In the debbuging section of the code i can see my certificate is there, but still my java is getting the handshake error. I'm new to ssl concept and possible did some config wrong.
One last note, when in the feign config class and set the trust store and password by System
System.setProperty("javax.net.ssl.trustStorePassword", "pass");
System.setProperty("javax.net.ssl.trustStore", "pathtocerth.p12");
The error change to this:
javax.net.ssl|ERROR|25|http-nio-auto-1-exec-1|2021-01-26 16:48:58.551 BRT|TransportContext.java:317|Fatal (CERTIFICATE_UNKNOWN): PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
question from:
https://stackoverflow.com/questions/65908364/using-ssl-certificate-with-feign 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…