本文将为您提供关于SunCertPathBuilderException:无法在CN1应用中找到到请求目标的有效证书路径的详细介绍,同时,我们还将为您提供关于Androidjava.security.
本文将为您提供关于SunCertPathBuilderException:无法在CN1应用中找到到请求目标的有效证书路径的详细介绍,同时,我们还将为您提供关于Android java.security.cert.CertPathValidatorException:找不到证书路径的信任锚、Android JavaMail应用程序-CertPathValidatorException:找不到证书路径的信任锚、CXF客户端:无法找到到请求目标的有效证书路径、java – Smack 4在连接上抛出“SSLHandshakeException:ValidatorException:SunCertPathBuilderException”的实用信息。
本文目录一览:- SunCertPathBuilderException:无法在CN1应用中找到到请求目标的有效证书路径
- Android java.security.cert.CertPathValidatorException:找不到证书路径的信任锚
- Android JavaMail应用程序-CertPathValidatorException:找不到证书路径的信任锚
- CXF客户端:无法找到到请求目标的有效证书路径
- java – Smack 4在连接上抛出“SSLHandshakeException:ValidatorException:SunCertPathBuilderException”
SunCertPathBuilderException:无法在CN1应用中找到到请求目标的有效证书路径
请你帮忙。我有一个Codenameone应用程序,该应用程序向云Tomcat
8服务器发出GET请求,并期望返回一些响应JSON。重要的是,这是一个HTTPS调用。
当我在邮递员中运行请求时,它工作正常:
https://www.mydomain.co.uk:8443/MyProject/v1/generate_token
通过我的浏览器使用的URL相同,并显示为“安全”,我可以看到我的证书详细信息。我已经为我的SSL /
TLS配置购买了证书,并且似乎在启动日志中可以正常运行。
在模拟器中,从URL调用读取响应时,我得到以下错误-我猜必须将其加密:
Exception: 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 targetjavax.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 at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1514) at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026) at sun.security.ssl.Handshaker.process_record(Handshaker.java:961) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492) at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:347) at com.codename1.impl.javase.JavaSEPort.getResponseCode(JavaSEPort.java:7591) at com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:702) at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:282) at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
为什么该应用程序与Postman进行呼叫有什么不同(“网络监视器”窗口确认相同的URL呼叫)?
我打电话后没有任何日志被更新,因此没有要检查的日志。从http更改为https之后,我尚未对应用程序进行任何更改(正在运行)。
这是进行呼叫的CN1代码:
public String fetchTokenIntoStorage(String userName, String password) { ConnectionRequest r = new ConnectionRequest(); r.setUrl(Constants.URL_HOST_PORT + "/MyProject" + Constants.LIVE_OR_TEST + "/v1/generate_token"); r.addRequestHeader("Content-Type", "application/json"); r.addRequestHeader("userName", userName); r.addRequestHeader("password", password); r.setHttpMethod("GET"); r.setFailSilently(false); r.setPost(false); // show spinning dialog while connecting InfiniteProgress prog = new InfiniteProgress(); Dialog dlg = prog.showInifiniteBlocking(); r.setDisposeOnCompletion(dlg); NetworkManager.getInstance().setTimeout(10000); // NetworkManager.getInstance().addErrorListener(new ActionListener() { // // @Override // public void actionPerformed(ActionEvent evt) { // MessageBox.showDialogMessage("Unable to connect to server. Please // retry later."); // } // }); // NetworkManager.getInstance().updateThreadCount(2); NetworkManager.getInstance().addToQueueAndWait(r); if (r.getResponseData() != null) { JSONParser parser = new JSONParser(); Map<String, Object> json = null; try { json = parser.parseJSON(new InputStreamReader(new ByteArrayInputStream(r.getResponseData()))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (json.get("error") != null) { return String.valueOf(json.get("error")); } JwtRecord record = new JwtRecord(); record.userId = Integer.parseInt(String.valueOf(json.get("userId"))); record.jsonWebToken = (String) json.get("jwt"); record.theme = "LIGHT"; Storage.getInstance().writeObject("MyToken", record); return ""; } if (!r.getResponseErrorMessage().equalsIgnoreCase("")) { return r.getResponseErrorMessage(); } else { return "Unable to connect to server. Please check connection."; } }
单步执行代码之后似乎出错
NetworkManager.getInstance().addToQueueAndWait(r);
r.getResponseData()和r.getResponseErrorMessage()为空。
非常感谢
答案1
小编典典现在正在工作。
(在tomcat上)我确保根证书和中间证书在我的密钥库中(根据我之前包含的链接)。我将我的.ca-bundle很好地包含在密钥库中。
(在tomcat上)我注意到我正在使用旧版本的Apache配置(从中学到了依赖较旧的论坛帖子的经验)。需要让apache .conf文件中的SSLCACertificateFile指向我的.ca-bundle文件,而不是使用SSCertificateChainFile。
它仍然在我的模拟器上出错,但可以在我的iPhone上运行,这表明(如Shai所述)我期望的JDK不同,因此将笔记本电脑升级到了更高的JDK 1.8.171。这本身并没有改变,但可能是必需的。
通过深入研究,我意识到笔记本电脑上的模拟器也需要上述工具。因此,我最终以管理员身份在命令提示符下运行以下语句,现在我的模拟器正在运行。
cd%java_home%\ jre \ lib \ security
路径=%java_home \ bin
keytool-导入-alias comodo -keystore cacerts-文件C:\ path \ ComodoRoot.cer
keytool-导入-alias comodo_intermediate -keystore cacerts-文件C:\ path \
ComodoInter.cer
keytool-导入-别名购买_cert-密钥库cacerts-文件C:\ path \ my_purchased_cert.crt
Android java.security.cert.CertPathValidatorException:找不到证书路径的信任锚
android应用有三台主机进行身份验证和授权。最终主机是REST API。首次使用Oauth身份验证和授权过程,它可以正常工作。
但是,如果 用户 在登录并访问REST API提供的服务后 杀死了该应用程序 ,然后再次打开该应用程序,则会出现此问题。
在这段时间内,身份验证和授权过程不会发生,只有REST API会发生。
这是造成原因,java.security.cert.CertPathValidatorException
但在首次使用(登录然后使用该应用程序)期间正在工作。
有人可以解释此异常背后的情况以及该应用程序有什么问题。如果根据此SO答案将认证异常忽略如下,则此方法有效。
SSLSocketFactory sslSocketFactory = null;
try {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
// Initialise the TMF as you normally would,for example:
try {
tmf.init((KeyStore)null);
} catch(KeyStoreException e) {
e.printStackTrace();
}
TrustManager[] trustManagers = tmf.getTrustManagers();
final X509TrustManager origTrustmanager = (X509TrustManager)trustManagers[0];
// Create a trust manager that does not validate certificate chains
TrustManager[] wrappedTrustManagers = new TrustManager[]{
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return origTrustmanager.getAcceptedIssuers();
}
public void checkClientTrusted(X509Certificate[] certs,String authType) {
try {
origTrustmanager.checkClientTrusted(certs,authType);
} catch(CertificateException e) {
e.printStackTrace();
}
}
public void checkServerTrusted(X509Certificate[] certs,String authType) {
try {
origTrustmanager.checkServerTrusted(certs,authType);
} catch(CertificateException e) {
e.printStackTrace();
}
}
}
};
//TrustManager[] trustAllCerts = TrustManagerFactory.getInstance("SSL").getTrustManagers();
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null,wrappedTrustManagers,new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
sslSocketFactory = sslContext.getSocketFactory();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
e.printStackTrace();
}
return sslSocketFactory;
我对http请求使用Okhttp 3。任何建议都将有助于解决问题。并且请告诉我是否使用上述代码段,是否违反安全规定?对应用程序的安全性有影响吗?
Android JavaMail应用程序-CertPathValidatorException:找不到证书路径的信任锚
请在重复之前,请先阅读我的问题.
使用自签名证书时,我已阅读有关此错误的许多问题和解答.但是,我的问题是,尝试连接到GMAIL imap服务器时出现此错误.所以,我真的需要一些帮助.我的代码是:
private String[] ReadMailBox(String MailBoxName) throws IOException {
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
props.setProperty("mail.imaps.port", "993");
List<String> FromAddressArrList = new ArrayList<String>();
props.setProperty("mail.store.protocol", "imaps");
try {
Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect("imap.gmail.com", "username", "password");
ActiveMailBox = store.getFolder(MailBoxName);
ActiveMailBox.open(Folder.READ_ONLY);
Message[] messages = ActiveMailBox.getMessages();
for (int i = 0; i < messages.length; i++) {
Message message = messages[i];
Address[] from = message.getFrom();
FromAddressArrList.add(from[0].toString());
}
//ActiveMailBox.close(true);
store.close();
} catch (NoSuchProviderException e) {
FromAddressArrList.add(e.toString());
} catch (MessagingException e) {
FromAddressArrList.add(e.toString());
}
String[] FromAddressArr = new String[FromAddressArrList.size()];
FromAddressArrList.toArray(FromAddressArr);
return FromAddressArr;
}
我收到此错误消息:
javax.mail.MessagingException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.; nested exception is: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
现在,当涉及到自签名证书时,我会发生这种情况,但是为什么在尝试连接到GMAIL时收到此消息?您能帮我使我的应用程序正常工作吗?
解决方法:
可能有防火墙,防病毒或代理程序正在拦截您连接到邮件服务器的请求,并提供其证书而不是Gmail证书.使用InstallCert程序查看它要提供给您的证书.
另一种可能性是信任库为空,丢失或配置不正确,这就是为什么它找不到信任锚的原因.
CXF客户端:无法找到到请求目标的有效证书路径
我正在尝试为我也编写的基于CXF的Web服务实现客户端。
我的Web服务运行良好(通过soapUI测试正常),但是运行客户端失败,并显示以下内容:
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:323)
该消息明确指出了证书问题,因此我进行了快速搜索,找到了在CXF中支持SSL的正确方法,并将以下内容添加到了Spring应用程序上下文配置XML:
<http:conduit name="https://myserver/myws/register/soap?wsdl:{http://glob.reg.com/myws}.http-conduit"> <http:tlsClientParameters> <sec:keyManagers keyPassword="password"> <sec:keyStore type="JKS" password="password" file="my/file/dir/Morpit.jks"/> </sec:keyManagers> <sec:trustManagers> <sec:keyStore type="JKS" password="password" file="my/file/dir/Truststore.jks"/> </sec:trustManagers> <sec:cipherSuitesFilter> <!-- these filters ensure that a ciphersuite with export-suitable or null encryption is used, but exclude anonymous Diffie-Hellman key change as this is vulnerable to man-in-the-middle attacks --> <sec:include>.*_EXPORT_.*</sec:include> <sec:include>.*_EXPORT1024_.*</sec:include> <sec:include>.*_WITH_DES_.*</sec:include> <sec:include>.*_WITH_AES_.*</sec:include> <sec:include>.*_WITH_NULL_.*</sec:include> <sec:exclude>.*_DH_anon_.*</sec:exclude> </sec:cipherSuitesFilter> </http:tlsClientParameters> <http:authorization> <sec:UserName>Betty</sec:UserName> <sec:Password>password</sec:Password> </http:authorization> <http:client AutoRedirect="true" Connection="Keep-Alive"/> </http:conduit>
并重建了客户。客户端构建成功,但是我仍然得到相同的确切错误和相同的堆栈跟踪,好像我从未添加过该http:conduit
东西一样。
我尚未将证书添加到存储中,并且存储路径不正确,但这是有意的,因为我只是想查看重新构建的客户端如何报告此问题并调整为新http:conduit
信息。
相反,我很惊讶地发现它被完全忽略了。
我错过了什么?
解决这个问题的正确方法是什么?
更新: 我刚刚注意到我的applicationcontext.xml http:conduit
带有以下错误消息:
The prefix "http" for element "http:conduit" is not bound.
因此,我进行了快速搜索,发现了一个提示:
客户端需要使用包含STS证书的密钥库配置HTTP管道,例如:
<http:conduit name="https://localhost:.*"> <http:tlsClientParameters disableCNCheck="true"> <sec:trustManagers> <sec:keyStore type="jks" password="cspass" resource="clientstore.jks"/> </sec:trustManagers> </http:tlsClientParameters> </http:conduit>
这加强了@GreyBeardedGeek的内容。现在要为此工作
…
答案1
小编典典问题解决了!
我仔细阅读了这篇magicmonster文章(请注意“
java的较旧版本”的亮点以及默认密码“
changeit”),以将整个自签名证书链导入到Java的受信任证书列表中:
http://magicmonster.com/kb/prg/java/ssl/pkix_path_building_failed.html
还有一个非常重要的 附加功能 : 对链中的所有证书(不仅是根证书)都这样做! (在我的情况下,有三个:组织的,中间的和根的)
然后…转到 Spring应用程序上下文配置XML 并修改该<http:conduit
部分,使其具有Java的 cacerts
文件的正确路径(和密码):
<http:tlsClientParameters> <sec:keyManagers keyPassword="changeit"> <sec:keyStore type="JKS" password="changeit" file="C:\Program Files (x86)\Java\jdk1.6.0_45\jre\lib\security\cacerts"/> </sec:keyManagers> <sec:trustManagers> <sec:keyStore type="JKS" password="changeit" file="C:\Program Files (x86)\Java\jdk1.6.0_45\jre\lib\security\cacerts"/> </sec:trustManagers>
java – Smack 4在连接上抛出“SSLHandshakeException:ValidatorException:SunCertPathBuilderException”
现在我想在版本4.0.2中使用smack-core和smack-tcp连接到服务器.
问题:
Caused by: 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
由于smack 4 api已经发生了很大的变化,到目前为止发现的例子已经不能再使用了.
以前有人试过吗?
解决方法
Java API(即,这不是由Smack完成的)无法使用活动SSLContext为服务器SSL / TLS证书构建有效的证书链.这就是抛出此异常的原因.您需要提供有效的证书(但是由您当前使用的SSLContext定义)或告诉Smack使用接受当前服务器证书的SSLContext(ConnectionConfiguration.setCustomSSLContext(SSLContext))
关于SunCertPathBuilderException:无法在CN1应用中找到到请求目标的有效证书路径的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于Android java.security.cert.CertPathValidatorException:找不到证书路径的信任锚、Android JavaMail应用程序-CertPathValidatorException:找不到证书路径的信任锚、CXF客户端:无法找到到请求目标的有效证书路径、java – Smack 4在连接上抛出“SSLHandshakeException:ValidatorException:SunCertPathBuilderException”的相关信息,请在本站寻找。
本文标签: