简体   繁体   English

无法找到到请求的目标PKIX路径构建的有效证书路径失败:sun.security.provider.certpath.SunCertPathBuilderException

[英]unable to find valid certification path to requested target PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException

I have create a custom keystore file xyz.jsk, When I tried to using this file I am getting exception 我创建了一个自定义密钥库文件xyz.jsk,当我尝试使用此文件时,出现异常

org.springframework.web.client.ResourceAccessException: I/O error on POST request for : sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; org.springframework.web.client.ResourceAccessException:POST请求的I / O错误:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求的有效证书路径目标; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 嵌套的异常是javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到到请求目标的有效证书路径

   String keyStorePassword = "NEWPASSWORD";
     KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
     ClassLoader classLoader = getClass().getClassLoader();
    //  File file = new 
   File(classLoader.getResource(keyStoreFile).getFile());

     File file = new File(dir, "xyz.jks");;


    keyStore.load(new FileInputStream(file), 
    keyStorePassword.toCharArray());

    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
            new SSLContextBuilder()
                    .loadTrustMaterial(null, new TrustSelfSignedStrategy())
                    .loadKeyMaterial(keyStore, keyStorePassword.toCharArray())
                    .build(),
            NoopHostnameVerifier.INSTANCE);

    HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();

        HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
        restTemplate.setRequestFactory(httpRequestFactory);

    ((HttpComponentsClientHttpRequestFactory) restTemplate.getRequestFactory())
            .setConnectTimeout(Integer.parseInt(strTimeOut));
    ResponseEntity<String> responseEntity = restTemplate.exchange(urlPath, HttpMethod.POST, entity, clazz);

Programmatic solution for certificate solution 证书解决方案的程序化解决方案
Please look into following imports :- 请研究以下进口:-

import java.security.SecureRandom;
import java.security.cert.X509Certificate;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

Now the function 现在的功能

ClientConfig clientConfig = getClientConfig();

TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
    return null;
}

public void checkClientTrusted(X509Certificate[] certs, String authType) {
}

public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
SSLContext sc = null;
try {
    sc = SSLContext.getInstance("TLS");
    sc.init(null, trustAllCerts, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
    // do nothing
    }

    Client client = ClientBuilder.newBuilder().withConfig(clientConfig).sslContext(sc).hostnameVerifier((s1, s2) -> true)
    .build();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PKIX 构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径 - PKIX building failed:sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到到请求目标的有效认证路径? - PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target? CXF:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径 - CXF:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到到请求目标的有效认证路径 - PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target GCP-PUBSUB:-sun.security.provider.certpath.SunCertPathBuilderException: 无法找到请求目标的有效认证路径 - GCP-PUBSUB:-sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求的目标错误的有效证书路径 - sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target error 引起:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径 - Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target Java:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效认证路径 - Java: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 使用 xmpp 时出现错误“sun.security.provider.certpath.SunCertPathBuilderException:无法找到到所请求目标的有效证书路径” - Error ' sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target' when using xmpp PKIX路径构建失败sun.security.provider.certpath.SunCertPathBuilderException - PKIX path building failed sun.security.provider.certpath.SunCertPathBuilderException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM