我正在尝试使用twitter4j库为我的java项目发送推文.在我第一次运行时,我收到了关于证书sun.security.validator.ValidatorException和错误的错误sun.security.provider.certpath.SunCertPathBuilderException.然后我添加了twitter证书:
C:\Program Files\Java\jdk1.7.0_45\jre\lib\security>keytool -importcert -trustcacerts -file PathToCert -alias ca_alias -keystore "C:\Program Files\Java\jdk1.7.0_45\jre\lib\security\cacerts"
Run Code Online (Sandbox Code Playgroud)
但没有成功.这是获得twitters的过程:
public static void main(String[] args) throws TwitterException {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("myConsumerKey")
.setOAuthConsumerSecret("myConsumerSecret")
.setOAuthAccessToken("myAccessToken")
.setOAuthAccessTokenSecret("myAccessTokenSecret");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
try {
Query query = new Query("iphone");
QueryResult result;
result = twitter.search(query);
System.out.println("Total amount of tweets: " + result.getTweets().size());
List<Status> tweets = result.getTweets();
for (Status tweet : tweets) {
System.out.println("@" + tweet.getUser().getScreenName() + " …Run Code Online (Sandbox Code Playgroud) 我有一个Java客户端试图访问带有自签名证书的服务器.
当我尝试发布到服务器时,我收到以下错误:
无法找到所请求目标的有效证书路径
在对这个问题进行了一些研究之后,我做了以下工作.
root.cer文件.keytool -import -alias example -keystore cacerts -file root.cerkeytool -list -v -keystore cacerts我仍然得到同样的错误.
我有一种感觉这是因为我的Glassfish实际上并没有阅读我修改过的cacert文件,但可能还有其他一些.
你们有没有遇到过这个问题,能否把我推向正确的方向?
我的java程序如何知道包含证书的密钥库在哪里?或者,我如何告诉我的java程序在哪里查找密钥库?
以某种方式指定密钥库后,如何指定用于向客户端验证服务器的证书?
我一直在研究从动态Web应用程序中提取信息的程序,该程序运行正常,直到我将我的tomcat服务器设置为使用自签名(因此,不受信任)证书使用SSL.错误的堆栈跟踪是:
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
Error: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:150)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1584)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:174)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:168)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:848)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:106)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:495)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:433)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:877)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1089)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1116)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1100)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:402)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:170)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:857)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
at com.certicom.gls.glscs.nongui.URLReader$PostURL.setupURL(URLReader.java:34)
at com.certicom.gls.glscs.nongui.URLReader.getLogin(URLReader.java:227)
at com.certicom.gls.glscs.nongui.URLReader.testLogin(URLReader.java:436)
at com.certicom.gls.glscs.nongui.Controller.loginMenu(Controller.java:384)
at com.certicom.gls.glscs.nongui.Controller.menu(Controller.java:324)
at com.certicom.gls.glscs.nongui.Controller.<init>(Controller.java:49)
at com.certicom.gls.glscs.nongui.Controller.main(Controller.java:61)
Run Code Online (Sandbox Code Playgroud)
在Web浏览器中,当访问具有不受信任证书的HTTPS站点时,系统会向用户发出警告,并且如果他想继续,则要求例外; …
当我使用imaps连接到我的imap服务器时,它很脆弱.
你能告诉我如何忽略javamail中的服务器证书错误
Exception in thread "main"
javax.mail.MessagingException:
sun.security.validator.ValidatorException:
PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification
path to requested target; 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 at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:665)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at App20110204.main(App20110204.java:31)
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 at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1623)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:198)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:192)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1074)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:128)
at …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个测试,它将使用JavaMail SMTP或SMTPS通过SSL和身份验证向我正在运行的Greenmail服务器发送消息.
我写了一个快速的小子,它应该完全符合我的要求:
import java.util.Properties;
import javax.mail.Session;
import javax.mail.Transport;
import com.icegreen.greenmail.user.GreenMailUser;
import com.icegreen.greenmail.util.GreenMail;
public class MailTest {
public static void main(String[] args) throws Exception {
GreenMail greenmail = new GreenMail();
try {
greenmail.start();
String email = "foo@bar";
String userid = "user";
String password = "pa$$word";
GreenMailUser setUser = greenmail.setUser(email, userid, password);
setUser.create();
GreenMailUser user = greenmail.getManagers().getUserManager().getUser(userid);
System.out.println("User created:" + user.getEmail() + ":" + user.getLogin() + ":" + user.getPassword());
int portSmtps = greenmail.getSmtps().getPort();
System.out.println("Smtps started on port:" + portSmtps); …Run Code Online (Sandbox Code Playgroud) 我有个问题.已经挣扎了很长时间.这是我的代码:
package com.XYZ.spr.server;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.SimpleEmail;
public class GeneratorMaili {
public static final String HOSTNAME = "smtp.XYZ.com";
public static final String ADDRESS_FROM = "user@XYZ.com";
public static final String TOPIC= "Topic";
public static void wyslijEmail(String reciver) throws Exception {
System.setProperty("javax.net.ssl.trustStore", "cacerts");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
Email email = new SimpleEmail();
email.setSmtpPort(587);
// email.setTLS(true);
email.setSSL(true);
System.out.println("fdfdf");
email.setAuthentication("user@.XYZ.pl", "pass");
email.setDebug(true);
email.setHostName(HOSTNAME);
email.setFrom(ADDRESS_FROM);
email.setSubject(TOPIC);
email.setMsg("Test");
email.addTo(reciver);
System.out.println(reciver);
email.send();
System.out.println("Ok!");
}
}
Run Code Online (Sandbox Code Playgroud)
我的证书有问题.以下是我所做的步骤:
我写了一个java客户端通过ssl连接到Ldap。我将 CA 证书导入到我的 java 密钥库中,并且能够通过 ssl 连接 Ldap 并提取信息。问题是它并不总是有效。通常它会抛出:CommunicationException:sun.security.validator.ValidatorException: PKIX path building failed。如果我再次运行(没有改变任何东西),它就可以工作。
这个问题让我死了好几天,作为一种解决方法,我正在捕获这个异常并重试。但我正在寻找永久修复。任何帮助将不胜感激。
下面是我获取上下文的代码:
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, securityPrincipal);
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_CREDENTIALS, securityCredential);
env.put("java.naming.provider.url", url);
return new InitialLdapContext(env, null);
Run Code Online (Sandbox Code Playgroud)
跟踪跟踪:
javax.naming.CommunicationException: simple bind failed: adapps.nms.comm:636 [Root 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]
at com.sun.jndi.ldap.LdapClient.authenticate(LdapClient.java:215)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2685)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:306)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:193)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:211)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:154)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
at …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Apache服务器上使用通过StartSSL.com获得的SSL证书.与浏览器的连接很好,但是当我尝试使用Java应用程序时,我得到了这个例外:
线程"main"中的异常javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到所请求目标的有效证书路径
我不明白可能是什么问题,因为在浏览器中,我获得了带有绿色标签的SSL.
我正在尝试通过 Web 服务将 xml 发送到另一个系统。但是在尝试发送时我收到以下错误。我已经安装了他们给我的证书。但它仍然不起作用。
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
Run Code Online (Sandbox Code Playgroud)