我试图使用twitter4j库为我的java项目获得推文,它在封面下使用java.net.HttpURLConnection(可以在堆栈跟踪中看到)。在我第一次运行时,我得到了一个关于证书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"

但是没有成功。以下是获取推文的流程:

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() + " : " + tweet.getText());
        }
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to search tweets: " + te.getMessage());
    }

这里是错误:

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Relevant discussions can be found on the Internet at:
    http://www.google.co.jp/search?q=d35baff5 or
    http://www.google.co.jp/search?q=1446302e
TwitterException{exceptionCode=[d35baff5-1446302e 43208640-747fd158 43208640-747fd158 43208640-747fd158], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.5}
    at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:177)
    at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
    at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:81)
    at twitter4j.TwitterImpl.get(TwitterImpl.java:1929)
    at twitter4j.TwitterImpl.search(TwitterImpl.java:306)
    at jku.cc.servlets.TweetsAnalyzer.main(TweetsAnalyzer.java:38)
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 sun.security.ssl.Alerts.getSSLException(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
    at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
    at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
    at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
    at sun.security.ssl.Handshaker.processLoop(Unknown Source)
    at sun.security.ssl.Handshaker.process_record(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
    at twitter4j.internal.http.HttpResponseImpl.<init>(HttpResponseImpl.java:34)
    at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:141)
    ... 5 more
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(Unknown Source)
    at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
    at sun.security.validator.Validator.validate(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
    at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
    ... 20 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
    at java.security.cert.CertPathBuilder.build(Unknown Source)
    ... 26 more
Failed to search tweets: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

在这里,这种异常通常发生在受信任证书的PATH不匹配时。检查用于安全通信的服务器证书所需的配置或路径。


在花了好几个小时试图构建证书文件以使我的Java 6安装能够与新的twitter证书一起工作之后,我终于无意中发现了一个隐藏在留言板上的评论中令人难以置信的简单解决方案。只需从Java 7安装中复制cacerts文件,并覆盖Java 6安装中的cacerts文件。可能最好先备份cacerts文件,但随后只需复制新文件,然后嘣!它就是有用。

注意,我实际上复制了一个Windows cacerts文件到Linux安装中,它工作得很好。

该文件位于旧的和新的Java jdk安装中的jre/lib/security/cacerts中。

希望这能帮别人省下几个小时的麻烦。


我偶然发现了这个问题,花了很多时间研究来解决,特别是自动生成的证书,与官方证书不同,它非常棘手,Java不太喜欢它们。

请检查以下链接:用Java解决证书问题

基本上,您必须将服务器上的证书添加到Java Home certs中。

Generate or Get your certificate and configure Tomcat to use it in Servers.xml Download the Java source code of the class InstallCert and execute it while the server is running, providing the following arguments server[:port]. No password is needed, as the original password works for the Java certs ("changeit"). The Program will connect to the server and Java will throw an exception, it will analyze the certificate provided by the server and allow you to create a jssecerts file inside the directory where you executed the Program (If executed from Eclipse then make sure you configure the Work directory in Run -> Configurations). Manually copy that file to $JAVA_HOME/jre/lib/security

遵循这些步骤之后,与证书的连接将不再在Java中生成异常。

下面的源代码很重要,它从(Sun) Oracle博客中消失了,我发现它的唯一页面是在提供的链接上,因此我将它附加在答案中以供参考。

/*
 * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 *   - Neither the name of Sun Microsystems nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/**
 * Originally from:
 * http://blogs.sun.com/andreas/resource/InstallCert.java
 * Use:
 * java InstallCert hostname
 * Example:
 *% java InstallCert ecc.fedora.redhat.com
 */

import javax.net.ssl.*;
import java.io.*;
import java.security.KeyStore;
import java.security.MessageDigest;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

/**
 * Class used to add the server's certificate to the KeyStore
 * with your trusted certificates.
 */
public class InstallCert {

    public static void main(String[] args) throws Exception {
        String host;
        int port;
        char[] passphrase;
        if ((args.length == 1) || (args.length == 2)) {
            String[] c = args[0].split(":");
            host = c[0];
            port = (c.length == 1) ? 443 : Integer.parseInt(c[1]);
            String p = (args.length == 1) ? "changeit" : args[1];
            passphrase = p.toCharArray();
        } else {
            System.out.println("Usage: java InstallCert [:port] [passphrase]");
            return;
        }

        File file = new File("jssecacerts");
        if (file.isFile() == false) {
            char SEP = File.separatorChar;
            File dir = new File(System.getProperty("java.home") + SEP
                    + "lib" + SEP + "security");
            file = new File(dir, "jssecacerts");
            if (file.isFile() == false) {
                file = new File(dir, "cacerts");
            }
        }
        System.out.println("Loading KeyStore " + file + "...");
        InputStream in = new FileInputStream(file);
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
        ks.load(in, passphrase);
        in.close();

        SSLContext context = SSLContext.getInstance("TLS");
        TrustManagerFactory tmf =
                TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(ks);
        X509TrustManager defaultTrustManager = (X509TrustManager) tmf.getTrustManagers()[0];
        SavingTrustManager tm = new SavingTrustManager(defaultTrustManager);
        context.init(null, new TrustManager[]{tm}, null);
        SSLSocketFactory factory = context.getSocketFactory();

        System.out.println("Opening connection to " + host + ":" + port + "...");
        SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
        socket.setSoTimeout(10000);
        try {
            System.out.println("Starting SSL handshake...");
            socket.startHandshake();
            socket.close();
            System.out.println();
            System.out.println("No errors, certificate is already trusted");
        } catch (SSLException e) {
            System.out.println();
            e.printStackTrace(System.out);
        }

        X509Certificate[] chain = tm.chain;
        if (chain == null) {
            System.out.println("Could not obtain server certificate chain");
            return;
        }

        BufferedReader reader =
                new BufferedReader(new InputStreamReader(System.in));

        System.out.println();
        System.out.println("Server sent " + chain.length + " certificate(s):");
        System.out.println();
        MessageDigest sha1 = MessageDigest.getInstance("SHA1");
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        for (int i = 0; i < chain.length; i++) {
            X509Certificate cert = chain[i];
            System.out.println
                    (" " + (i + 1) + " Subject " + cert.getSubjectDN());
            System.out.println("   Issuer  " + cert.getIssuerDN());
            sha1.update(cert.getEncoded());
            System.out.println("   sha1    " + toHexString(sha1.digest()));
            md5.update(cert.getEncoded());
            System.out.println("   md5     " + toHexString(md5.digest()));
            System.out.println();
        }

        System.out.println("Enter certificate to add to trusted keystore or 'q' to quit: [1]");
        String line = reader.readLine().trim();
        int k;
        try {
            k = (line.length() == 0) ? 0 : Integer.parseInt(line) - 1;
        } catch (NumberFormatException e) {
            System.out.println("KeyStore not changed");
            return;
        }

        X509Certificate cert = chain[k];
        String alias = host + "-" + (k + 1);
        ks.setCertificateEntry(alias, cert);

        OutputStream out = new FileOutputStream("jssecacerts");
        ks.store(out, passphrase);
        out.close();

        System.out.println();
        System.out.println(cert);
        System.out.println();
        System.out.println
                ("Added certificate to keystore 'jssecacerts' using alias '"
                        + alias + "'");
    }

    private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();

    private static String toHexString(byte[] bytes) {
        StringBuilder sb = new StringBuilder(bytes.length * 3);
        for (int b : bytes) {
            b &= 0xff;
            sb.append(HEXDIGITS[b >> 4]);
            sb.append(HEXDIGITS[b & 15]);
            sb.append(' ');
        }
        return sb.toString();
    }

    private static class SavingTrustManager implements X509TrustManager {

        private final X509TrustManager tm;
        private X509Certificate[] chain;

        SavingTrustManager(X509TrustManager tm) {
            this.tm = tm;
        }

        public X509Certificate[] getAcceptedIssuers() {
            throw new UnsupportedOperationException();
        }

        public void checkClientTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
            throw new UnsupportedOperationException();
        }

        public void checkServerTrusted(X509Certificate[] chain, String authType)
                throws CertificateException {
            this.chain = chain;
            tm.checkServerTrusted(chain, authType);
        }
    }
}

-Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true

用于跳过证书验证。

警告!

仅用于开发目的,这是不安全的!


在浏览器中进入URL:

点击HTTPS证书链(URL地址旁边的锁图标)。点击“更多信息”>“安全”>“显示证书“>”详细信息“>”导出。拾取名称并选择文件类型example.cer chrome -点击网站图标左侧地址栏,选择“证书”->“详细信息”->“导出”并保存为“Der-encoded binary, single Certificate”格式。

现在您有了带有密钥存储库的文件,并且必须将其添加到JVM中。确定cacerts文件的位置,例如。 C:\Program Files (x86)\Java\ jre1.6.0_22\lib\security\cacerts。 接下来导入示例。在命令行中将Cer文件转换为cacerts(可能需要管理员命令提示符):

"C:\Program Files (x86)\Java\jre1.6.0_22\lib\security\cacerts" -file example.cer

您将被要求输入密码,默认为changeit

重新启动JVM/PC。

来源: http://magicmonster.com/kb/prg/java/ssl/pkix_path_building_failed.html


我在ubuntu 15.10上也有同样的问题。请尝试在本地下载插件,例如https://github.com/lmenezes/elasticsearch-kopf/archive/master.zip,并使用以下命令安装:

sudo /usr/share/elasticsearch/bin/plugin install file:/home/dev/Downloads/elasticsearch-kopf-master.zip

路径可能不同,取决于你的环境。

的问候。


对我来说,证书错误弹出是因为我有fiddler运行在后台,这打乱了证书。它作为一个代理如此接近,并重新启动eclipse。


我的UI方法:

从这里下载密钥库资源管理器 打开$ JAVA_HOME / jre / lib /安全/除 输入PW: changeit(可以在Mac上changeme) 导入.crt文件

CMD-Line:

Keytool -importcert -file jetty。crt -alias jetty -keystore $JAVA_HOME/jre/lib/security/cacerts . crt -alias jetty -keystore $JAVA_HOME/jre/lib/security/cacerts . crt 输入PW: changeit(可以在Mac上changeme)


我的情况略有不同,当时我的系统上同时存在JDK和JRE 1.8.0_112。

我导入新的CA证书到[JDK_FOLDER]\jre\lib\security\cacerts使用已知的命令:

keytool -import -trustcacerts -keystore cacerts -alias <new_ca_alias> -file <path_to_ca_cert_file>

尽管如此,我仍然得到相同的PKIX路径构建失败错误。

我在java命令行中添加了调试信息,使用java -Djavax.net.debug=all…> debug.log。在debug.log文件中,以trustStore开头的行实际上指向[JRE_FOLDER]\lib\security\cacerts中找到的cacerts存储。

在我的案例中,解决方案是将JDK使用的cacerts文件(添加了新的ca)复制到JRE使用的cacerts文件上,这样就解决了问题。


我想为smtp.gmail.com导入证书。对我来说唯一有效的办法就是

输入命令查看该证书 D:\openssl\bin\openssl.exe s_client连接smtp.gmail.com:465 将-----BEGIN CERTIFICATE-----和-----END CERTIFICATE-----之间的行复制并保存到一个文件gmail.cer中 运行 keytool -import -alias smtp.gmail.com -keystore "%JAVA_HOME%/jre/lib/security/cacerts" -file C:\Users\Admin\Desktop\gmail.cer 输入密码:changeit 单击“是”,导入证书 重新启动Java

现在运行命令,就可以开始了。


我在尝试通过Eclipse的更新站点在Eclipse中安装Cucumber-Eclipse插件时遇到了这个问题。我收到了同样的SunCertPathBuilderException错误:

Unable to read repository at http://cucumber.io/cucumber-eclipse/update-site/content.xml.
    Unable to read repository at http://cucumber.io/cucumber-eclipse/update-site/content.xml.
    sun.security.validator.ValidatorException: PKIX path building failed: 
   sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

虽然其他一些答案在这个问题的特定情况下是合适和有用的,但它们对我的问题没有帮助和误导。

在我的情况下,问题是他们的更新站点提供的URL是:

https://cucumber.io/cucumber-eclipse/update-site

然而,当通过浏览器导航到它时,它重定向到(注意添加的“。github”):

http://cucumber.github.io/cucumber-eclipse/update-site/

因此,解决方案是在eclipse中添加更新站点时,只需使用更新站点URL的重定向版本。


加仙人掌对我没用。 在使用flag -Djavax.net.debug=all启用日志后,才知道java从jssecacerts读取。

导入到jssecacerts终于工作了。


目标:

使用HTTPS连接 验证SSL链 不处理仙人掌 在运行时添加证书 不从cacerts丢失证书

怎么做:

定义自己的密钥库 将证书放入密钥库 使用自定义类重新定义SSL默认上下文 ??? 利润

我的Keystore包装文件:

public class CertificateManager {

    private final static Logger logger = Logger.getLogger(CertificateManager.class);

    private String keyStoreLocation;
    private String keyStorePassword;
    private X509TrustManager myTrustManager;
    private static KeyStore myTrustStore;

    public CertificateManager(String keyStoreLocation, String keyStorePassword) throws Exception {
        this.keyStoreLocation = keyStoreLocation;
        this.keyStorePassword = keyStorePassword;
        myTrustStore = createKeyStore(keyStoreLocation, keyStorePassword);
    }

    public void addCustomCertificate(String certFileName, String certificateAlias)
            throws Exception {
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init((KeyStore) null);
        Certificate certificate = myTrustStore.getCertificate(certificateAlias);
        if (certificate == null) {
            logger.info("Certificate not exists");
            addCertificate(certFileName, certificateAlias);
        } else {
            logger.info("Certificate exists");
        }
        tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(myTrustStore);
        for (TrustManager tm : tmf.getTrustManagers()) {
            if (tm instanceof X509TrustManager) {
                setMytrustManager((X509TrustManager) tm);
                logger.info("Trust manager found");
                break;
            }
        }
    }

    private InputStream fullStream(String fname) throws IOException {
        ClassLoader classLoader = getClass().getClassLoader();
        InputStream resource = classLoader.getResourceAsStream(fname);
        try {
            if (resource != null) {
                DataInputStream dis = new DataInputStream(resource);
                byte[] bytes = new byte[dis.available()];
                dis.readFully(bytes);
                return new ByteArrayInputStream(bytes);
            } else {
                logger.info("resource not found");
            }
        } catch (Exception e) {
            logger.error("exception in certificate fetching as resource", e);
        }
        return null;
    }

    public static KeyStore createKeyStore(String keystore, String pass) throws Exception {
        try {
            InputStream in = CertificateManager.class.getClass().getResourceAsStream(keystore);
            KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            keyStore.load(in, pass.toCharArray());
            logger.info("Keystore was created from resource file");
            return keyStore;
        } catch (Exception e) {
            logger.info("Fail to create keystore from resource file");
        }

        File file = new File(keystore);
        KeyStore keyStore = KeyStore.getInstance("JKS");
        if (file.exists()) {
            keyStore.load(new FileInputStream(file), pass.toCharArray());
            logger.info("Default keystore loaded");
        } else {
            keyStore.load(null, null);
            keyStore.store(new FileOutputStream(file), pass.toCharArray());
            logger.info("New keystore created");
        }
        return keyStore;
    }

    private void addCertificate(String certFileName, String certificateAlias) throws CertificateException,
            IOException, KeyStoreException, NoSuchAlgorithmException {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        InputStream certStream = fullStream(certFileName);
        Certificate certs = cf.generateCertificate(certStream);
        myTrustStore.setCertificateEntry(certificateAlias, certs);
        FileOutputStream out = new FileOutputStream(getKeyStoreLocation());
        myTrustStore.store(out, getKeyStorePassword().toCharArray());
        out.close();
        logger.info("Certificate pushed");
    }

    public String getKeyStoreLocation() {
        return keyStoreLocation;
    }

    public String getKeyStorePassword() {
        return keyStorePassword;
    }
    public X509TrustManager getMytrustManager() {
        return myTrustManager;
    }
    public void setMytrustManager(X509TrustManager myTrustManager) {
        this.myTrustManager = myTrustManager;
    }
}

如果需要,该类将创建密钥存储库,并能够在其中管理证书。下面是SSL context的类:

public class CustomTrustManager implements X509TrustManager {

    private final static Logger logger = Logger.getLogger(CertificateManager.class);

    private static SSLSocketFactory socketFactory;
    private static CustomTrustManager instance = new CustomTrustManager();
    private static List<CertificateManager> register = new ArrayList<>();

    public static CustomTrustManager getInstance() {
        return instance;
    }

    private X509TrustManager defaultTm;

    public void register(CertificateManager certificateManager) {
        for(CertificateManager manager : register) {
            if(manager == certificateManager) {
                logger.info("Certificate manager already registered");
                return;
            }
        }
        register.add(certificateManager);
        logger.info("New Certificate manager registered");
    }

    private CustomTrustManager() {
        try {
            String algorithm = TrustManagerFactory.getDefaultAlgorithm();
            TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);

            tmf.init((KeyStore) null);
            boolean found = false;
            for (TrustManager tm : tmf.getTrustManagers()) {
                if (tm instanceof X509TrustManager) {
                    defaultTm = (X509TrustManager) tm;
                    found = true;
                    break;
                }
            }
            if(found) {
                logger.info("Default trust manager found");
            } else {
                logger.warn("Default trust manager was not found");
            }

            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, new TrustManager[]{this}, null);
            SSLContext.setDefault(sslContext);
            socketFactory = sslContext.getSocketFactory();
            HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory);


            logger.info("Custom trust manager was set");
        } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
            logger.warn("Custom trust manager can't be set");
            e.printStackTrace();
        }
    }

    @Override
    public X509Certificate[] getAcceptedIssuers() {
        List<X509Certificate> out = new ArrayList<>();
        if (defaultTm != null) {
            out.addAll(Arrays.asList(defaultTm.getAcceptedIssuers()));
        }
        int defaultCount = out.size();
        logger.info("Default trust manager contain " + defaultCount + " certficates");
        for(CertificateManager manager : register) {
            X509TrustManager customTrustManager = manager.getMytrustManager();
            X509Certificate[] issuers = customTrustManager.getAcceptedIssuers();
            out.addAll(Arrays.asList(issuers));
        }
        logger.info("Custom trust managers contain " + (out.size() - defaultCount) + " certficates");
        X509Certificate[] arrayOut = new X509Certificate[out.size()];
        return out.toArray(arrayOut);
    }

    @Override
    public void checkServerTrusted(X509Certificate[] chain,
                                   String authType) throws CertificateException {
        for(CertificateManager certificateManager : register) {
            X509TrustManager customTrustManager = certificateManager.getMytrustManager();
            try {
                customTrustManager.checkServerTrusted(chain, authType);
                logger.info("Certificate chain (server) was aproved by custom trust manager");
                return;
            } catch (Exception e) {
            }
        }
        if (defaultTm != null) {
            defaultTm.checkServerTrusted(chain, authType);
            logger.info("Certificate chain (server) was aproved by default trust manager");
        } else {
            logger.info("Certificate chain (server) was rejected");
            throw new CertificateException("Can't check server trusted certificate.");
        }
    }

    @Override
    public void checkClientTrusted(X509Certificate[] chain,
                                   String authType) throws CertificateException {
        try {
            if (defaultTm != null) {
                defaultTm.checkClientTrusted(chain, authType);
                logger.info("Certificate chain (client) was aproved by default trust manager");
            } else {
                throw new NullPointerException();
            }
        } catch (Exception e) {
            for(CertificateManager certificateManager : register) {
                X509TrustManager customTrustManager = certificateManager.getMytrustManager();
                try {
                    customTrustManager.checkClientTrusted(chain, authType);
                    logger.info("Certificate chain (client) was aproved by custom trust manager");
                    return;
                } catch (Exception e1) {
                }
            }
            logger.info("Certificate chain (client) was rejected");
            throw new CertificateException("Can't check client trusted certificate.");
        }
    }

    public SSLSocketFactory getSocketFactory() {
        return socketFactory;
    }
}

这个类被设置为单例,因为只允许一个defaultSSL上下文。现在来看用法:

            CertificateManager certificateManager = new CertificateManager("C:\\myapplication\\mykeystore.jks", "changeit");
            String certificatePath = "C:\\myapplication\\public_key_for_your_ssl_service.crt";
            try {
                certificateManager.addCustomCertificate(certificatePath, "alias_for_public_key_for_your_ssl_service");
            } catch (Exception e) {
                log.error("Can't add custom certificate");
                e.printStackTrace();
            }
            CustomTrustManager.getInstance().register(certificateManager);

可能,它将无法与此设置,因为我将证书文件保存在资源文件夹内,所以我的路径不是绝对的。但总的来说,它工作得很完美。


1. 检查证书

尝试在浏览器中加载目标URL并查看网站的证书(通常可以通过带有锁标志的图标访问)。它在浏览器地址栏的左边或右边),无论它是否过期或由于其他原因不受信任。

2. 安装最新版本的JRE和JDK

新版本通常附带一组更新后的受信任证书。

如果可能的话,卸载旧版本。这将使错误配置错误显式地出现。

3.检查您的配置:

检查JAVA_HOME环境变量指向的位置。 检查您使用哪个java版本来运行程序。在IntelliJ中检查: 文件->项目结构…—>项目设置—>项目—>项目SDK: 文件->项目结构…—>平台设置—>个sdk

4. 从新的Java版本复制整个密钥存储库

如果您使用的JDK不是最新可用的JDK,请尝试将%JAVA_HOME%/jre/lib/security/cacerts文件替换为最新安装的jre中的新文件(先做备份),正如@jeremy-goodell在他的回答中建议的那样

5. 向您的密钥存储库中添加证书

如果以上都不能解决您的问题,请使用keytool将证书保存到Java的密钥存储库:

keytool -trustcacerts -keystore "%JAVA_HOME%jre\lib\security\cacerts" -storepass changeit -importcert -alias <alias_name> -file <path_to_crt_file>

正如@MagGGG在他的回答中建议的那样,可以从浏览器中获得带有证书的文件。

注1:您可能需要对链中的每个证书重复此操作,直到站点的证书。从根根开始。

注意2:<alias_name>在存储中的键中应该是唯一的,否则keytool将显示错误。

要获取存储中所有证书的列表,您可以运行:

keytool -list -trustcacerts -keystore "%JAVA_HOME%jre\lib\security\cacerts" -storepass changeit

如果出现问题,这将帮助您从存储中删除证书:

keytool -delete -alias <alias_name> -keystore "%JAVA_HOME%jre\lib\security\cacerts" -storepass changeit

我也遇到过同样的问题,使用以下简单的步骤来解决它:

1)从谷歌下载InstallCert.java

2)使用javac InstallCert.java编译

3)运行InstallCert.java,带主机名和https端口,要求输入时按“1”。它将添加“localhost”作为受信任的密钥存储库,并生成名为“jssecacerts”的文件,如下所示:

java InstallCert localhost:443

4)拷贝jssecacerts到$JAVA_HOME/jre/lib/security文件夹

解决这个问题的主要方法是:

https://ankurjain26.blogspot.in/2017/11/javaxnetsslsslhandshakeexception.html


问题背景:

当我试图在我的项目中运行mvn清洁安装并通过Netbeans IDE清洁和构建选项时,我得到了以下错误。 此问题是由于通过NET beans IDE/通过命令提示符下载时证书不可用,但可以通过浏览器下载文件。

错误:

Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact com.java.project:product:jar:1.0.32 from/to repo-local (https://url/local-repo): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target  

解决方法:

1. 下载有关网址的证书:

Launch IE by "run as adminstrator" (otherwise, we will not be able to download the certificate) Enter the url in IE-> https://url/local-repo (In my case this url had a untrusted certificate.) Download the certificate by clicking on Certificate error -> view certificate Select Details tab -> copy to file -> next -> select "DER encoded binary X.509 (.CER) save the certificate in some location, example : c:/user/sheldon/desktop/product.cer Congrats! you have successfully downloaded the certificate for the site

2. 现在安装密钥存储库以修复该问题。

运行keytool命令将下载的密钥存储库附加到 已存在的证书文件。 命令:jdk (JAVA_HOME) bin文件夹下的如下命令。

C:\Program Files\Java\ jdk1.8.0_141\jre\bin>keytool -importcert -file .使用实例 “C: / user /谢耳朵/桌面/产品。-alias product -keystore “C: /程序文件/ Java / jdk1.8.0_141 / jre / lib /安全/除”。

系统将提示您输入密码。输入keystore密码: 再次输入“changeit”,输入“信任此证书?”(没有):“,输入 “是的”

示例命令行命令/输出:

keytool -importcert -file "C:/Users/sheldon/Desktop/product.cer" -alias product -keystore "C:/Program iles/Java/jdk1.8.0_141/jre/lib/security/cacerts"
Enter keystore password:
Trust this certificate? [no]:  yes
Certificate was added to keystore

Contgrats !现在你应该删除“PKIX路径构建失败:sun.security.provider.certpath”。在Netbeans IDE中出现SunCertPathBuilderException错误。


这不是twitter特有的答案,但这是在搜索此错误时出现的问题。如果您的系统在连接到一个在web浏览器中查看时似乎具有有效证书的网站时接收到此错误,这可能意味着该网站具有不完整的证书链。

简单总结一下这个问题:证书颁发机构不会使用他们的根证书对任何旧证书进行签名。相反,它们(通常)签署也设置了证书颁发机构标志的中间证书(也就是说,允许签署证书)。然后,当您从CA购买证书时,他们将使用这些中间证书之一签署您的CSR。

您的Java信任存储区很可能只有根证书,而没有中间证书。

错误配置的站点可能只返回已签名的证书。问题:该站点使用的中间证书不在您的信任存储区中。浏览器将通过下载或使用缓存的中间证书来处理这个问题;这最大限度地提高了网站的兼容性。然而,Java和像OpenSSL这样的工具不会。这会导致问题中的错误。

您可以通过使用Qualys SSL测试来验证这种怀疑。如果你在网站上搜索,上面写着

此服务器的证书链不完整。

那就证实了这一点。您还可以通过查看认证路径并查看文本Extra Download来了解这一点。

How to fix it: the server administrator needs to configure the web server to return the intermediate certificates as well. For Comodo, for example, this is where the .ca-bundle file comes in handy. For example, in an Apache configuration with mod_ssl, you'd use the SSLCertificateChainFile configuration setting. For nginx, you need to concatenate the intermediate certificates and the signed certificate and use that in the SSL cert configuration. You can find more by searching for "incomplete certificate chain" online.


它是对答案https://stackoverflow.com/a/36427118/1491414的补充。由于@MagGGG

请确保您有管理员权限 请使用双引号作为密钥存储库路径(-keystore C:\Program Files (x86)\Java\ jre1.6.0_22\lib\security\cacerts"),因为在Windows操作系统中,默认的安装位置将是程序文件,由于程序文件之间的空格,您将得到一个错误。


我用下面的方法修正了这个问题

复制有连接问题的url 进入Android Studio->Settings->Http Settings 在“Test Connection”中,粘贴该url并按ok 点击确定,Android Studio会要求导入证书 Url,导入 就是这样。没别的事可做,我的问题就没了。不需要 重新启动工作室。


当你有上述错误与atlassian软件exjira

2018-08-18 11:35:00,312 Caesium-1-4 WARN anonymous    Default Mail Handler [c.a.mail.incoming.mailfetcherservice] Default Mail Handler[10001]: 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 while connecting to host 'imap.xyz.pl' as user 'jira@xyz.pl' via protocol 'imaps, 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

您可以将证书添加到它的可信密钥存储库(将missing_ca更改为正确的证书名称):

keytool -importcert -file missing_ca.crt -alias missing_ca -keystore /opt/atlassian/jira/jre/lib/security/cacerts

如果要求输入密码,输入changeit并确认y

之后,只需重启jira。


我们得到上述错误的原因是,JDK与许多受信任的证书颁发机构(CA)证书捆绑在一个名为“cacerts”的文件中,但该文件没有我们自签名证书的任何提示。换句话说,cacerts文件没有导入我们的自签名证书,因此没有将其视为受信任的实体,因此给出了上述错误。

如何修复上述错误

要修复上述错误,只需将自签名证书导入cacerts文件。

首先,找到cacerts文件。我们需要找到JDK的位置。如果您正在通过Eclipse或IntelliJ Idea等IDE运行应用程序,请进入项目设置并找出JDK的位置。 例如,在Mac操作系统上,cacerts文件的典型位置是这个位置/Library/Java/JavaVirtualMachines/ {{JDK_version}}/Contents/Home/jre/lib/security 在windows的机器上,它将在{{Installation_directory}}/{{JDK_version}}/jre/lib/security下

找到cacerts文件后,现在我们需要将自签名证书导入到这个cacerts文件中。如果您不知道如何正确生成自签名证书,请查看上一篇文章。

如果你没有一个证书文件(.crt),只有一个.jks文件,你可以使用下面的命令生成一个.crt文件。如果你已经有了。crt/。Pem文件,那么你可以忽略下面的命令

##从密钥库生成证书。JKS文件)####

keytool -export -keystore keystore.jks -alias selfsigned -file selfsigned.crt

以上步骤将生成一个名为selfsigned.crt的文件。现在将证书导入cacerts

Now add the certificate to JRE/lib/security/cacerts (trustore)
keytool -importcert -file selfsigned.crt -alias selfsigned -keystore {{cacerts path}}

对如

keytool -importcert -file selfsigned.nextgen.crt -alias selfsigned.nextgen -keystore /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/security/cacerts

这就是全部,重新启动应用程序,它应该可以正常工作。如果它仍然不工作,并获得SSL握手异常。这可能意味着您正在使用不同的域名,然后在证书中注册。

链接有详细的解释和一步一步的解决方案在这里。


如果您的存储库URL也可以在HTTP上工作,并且安全性不是问题,您可以访问settings.xml(通常,但不总是,位于%USERPROFILE%/.m2),并将<repository>和<pluginRepository> URL的HTTPS替换为HTTP。

例如,这个:

<repository>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <id>central</id>
    <name>libs-release</name>
    <url>https://<artifactory>/libs-release</url>
</repository>

应改为:

<repository>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <id>central</id>
    <name>libs-release</name>
    <url>https://<artifactory>/libs-release</url>
</repository>

我使用我自己的信任存储,而不是JRE,通过传递arg -Djavax.net.ssl.trustStore=

不管信任库中的certs如何,我都得到这个错误。对我来说,问题是在参数行上传递的属性的顺序。 当我把-Djavax.net.ssl.trustStore=& -Djavax.net.ssl.trustStorePassword=之前-Dspring.config。Location = & -jar args我能够通过https成功调用我的rest调用。


如果您正在使用CloudFoundry并遇到证书问题,那么您必须确保再次使用包含证书的keystore-service来推动jar。简单地解绑定、绑定和重新启动是行不通的。


如果你的主机位于防火墙/代理之后,在cmd中使用以下命令:

keytool -J-Dhttps.proxyHost=<proxy_hostname> -J-Dhttps.proxyPort=<proxy_port> -printcert -rfc -sslserver <remote_host_name:remote_ssl_port>

将<proxy_hostname>和<proxy_port>替换为已配置的HTTP代理服务器。将<remote_host_name:remote_ssl_port>替换为一个存在认证问题的远程主机(基本上是url)和端口。

将上次打印的证书内容复印一份(同时复印开始证书和结束证书)。将其粘贴到文本文件中,并将扩展名为.crt。现在使用java keytool命令将该证书导入cacerts,它应该可以工作。

keytool -importcert -file <filename>.crt -alias randomaliasname -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changeit

尝试复制java cacerts:

cp /usr/lib/jvm/java - 1.8.0 openjdk 1.8.0.172 b11.fc28——9.。除x86_64 / jre / lib /安全/ $ JAVA_HOME / jre / lib /安全/除


当java应用程序试图与另一个应用程序/站点通信时,如果您在linux容器中看到此问题,这是因为证书已错误地导入到负载均衡器中。导入证书需要遵循一系列步骤,如果操作不正确,您将看到如下问题

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid 
certification path to requested target

一旦正确地导入了证书,就应该这样做。不需要修补任何JDK证书。


这是一个解决方案,但以我的故事的形式:

我尝试了上面给出的所有解决方案(3天),几乎要死了,没有一个对我有效。

我失去了所有的希望。

我联系了我的安全团队,因为我在代理服务器后面,他们告诉我他们最近更新了他们的安全策略。

后来他们发布了一个新的“cacerts”文件,其中包含了所有的证书。

我删除了%JAVA_HOME%/jre/lib/security中的cacerts文件,它解决了我的问题。

所以如果你正面临这个问题,它可能来自你的网络团队。


下载证书文件,并按照下面的命令使用证书文件更新密钥存储库。

sudo keytool -importcert -别名“aws2”-文件~/桌面/*aws。crt -keystore /Library/java/JavaVirtualMachines/jdk1.8.0_131.jdk/ Home/ jdk/ lib/security/cacerts


我为Intellij Idea解决了这个问题 虽然,我改变了很多地方来解决问题。我找到了一个解决方案。右键单击你的项目,你会看到Maven,然后按生成源代码和更新文件夹和重新导入

完成了。


I solved this issue on Windows Server 2016 with Java 8, by importing cert from pkcs12 store to cacerts keystore. Path to pkcs12 store: C:\Apps\pkcs12.pfx Path to Java cacerts: C:\Program Files\Java\jre1.8.0_151\lib\security\cacerts Path to keytool: C:\Program Files\Java\jre1.8.0_151\bin After possitioning to folder with keytool in command prompt (as administrator), command to import cert from pkcs12 to cacerts is as follows: keytool -v -importkeystore -srckeystore C:\Apps\pkcs12.pfx -srcstoretype PKCS12 -destkeystore "C:\Program Files\Java\jre1.8.0_151\lib\security\cacerts" -deststoretype JKS You will be prompted to: 1. enter destination keystore password (cacerts pasword, default is "changeit") 2. enter source keystore password (pkcs12 password)

要使更改生效,请重新启动服务器机器(或只需重新启动JVM)。


我也遇到了同样的问题,我使用的是8.1.0-3,但后来我使用了9.2.1-0,这个问题在没有任何手动步骤的情况下得到了修复。自签名证书工作正常。


我遇到了同样的问题,但更新错误的jre在我的linux机器。tomcat很可能正在使用不同的jre,而您的cli提示符被配置为使用不同的jre。

确保您选择了正确的jre。

步骤# 1:

ps -ef | grep tomcat

你会看到如下内容:

root     29855     1  3 17:54 pts/3    00:00:42 /usr/java/jdk1.7.0_79/jre/bin/java 

现在用这个:

keytool -import -alias example -keystore  /usr/java/jdk1.7.0_79/jre/lib/security/cacerts -file cert.cer
PWD: changeit

*。Cer文件可以如下所示生成:(或者您可以使用自己的)

openssl x509 -in cert.pem -outform pem -outform der -out cert.cer

经过半天的努力,又找到了一个解决问题的方法。我能够在MAC 10.15.5 (Catalina)中解决这个问题。遵循以下步骤。

This problem occurs when we are running behind a company proxy , In my case its Zscaler. Open Key chain access, export CA certificate.(Select CA certificate, File->export items and save with the desired name) Copy the path of existing cacerts from java folder(/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/jre/lib/security/cacerts ) Open terminal and navigate to the Keytool folder (/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/jre/bin ) Run the below command. Keytool -importcert - file (Path to exported cert from the keychainaccess) -alias (give a name) -keystore (Path of existing cacerts from java folder) sudo Keytool -importcert -file /Users/Desktop/RootCA.cer -alias demo -keystore /Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/jre/lib/security/cacerts It will ask for password , give it as : changeit It asks for confirmation , Say : yes

完成所有这些步骤后,退出eclipse并启动新的会话。


当证书比Java版本更新时,您将得到此错误。使用更新的Java版本可以解决这个问题。


问题是,您的eclipse无法连接实际上它正在尝试连接的站点。 我也遇到过类似的问题,下面给出的解决方案对我来说很有效。

关闭任何第三方互联网安全应用程序,如Zscaler 有时也需要断开VPN如果你是连接的。

谢谢


1 .首先,将你的crt文件导入到{JAVA_HOME}/jre/security/cacerts中,如果你仍然遇到这个异常,改变你的jdk版本。例如,从jdk1.8.0_17到jdk1.8.0_231


如果您仍然得到这个错误

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid 
certification path to requested target

执行以下命令并重新启动Java进程后

keytool -import -alias certificatealias -keystore C:\Program Files\Java\jre1.8.0_151\lib\security\cacerts -file certificate.cer

然后JDK有一些问题。尝试从可信的提供者安装JDK。 一旦您从可信的提供商重新安装它,就不会遇到这个问题。


Mac

接受的答案不适用于Mac,因为Mac (Chrome或Firefox)中没有导出按钮。请检查此答案以下载证书,并按照以下步骤执行:

列出keystore中安装的所有证书:

cd $JAVA_HOME/lib/security
keytool -list -keystore cacerts

注:

密钥库的默认密码为:changeit。 对于Java-8或以下版本,请使用cd $JAVA_HOME/jre/lib/security命令

在将证书导入密钥存储库之前,请备份密钥存储库:

sudo cp cacerts cacerts.bak

将下载的证书导入keystore:

sudo keytool -importcert -alias youralias -file /path/to/the/downloaded/certificate -keystore cacerts

检查证书是否存储在密钥存储库中:

sudo keytool -list -keystore cacerts -alias youralias

如果你想看到更详细的信息,添加-v标志:

sudo keytool -v -list -keystore cacerts -alias youralias

虽然我复制了证书到cacerts文件,但错误并没有消失。

问题是证书上的日期已经过期,这就是为什么它返回错误。

我请求了一个新的有效证书,错误现在已经消失了。


我留下一些小费。

使用- dsll .debug=true检查SSL。 检查您是否正在创建隧道或试图忽略它

SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (x509CertChain, authType) -> true).build();
            httpClient = HttpClientBuilder.create()
                    .setSSLContext(sslContext)
                    .setConnectionManager(new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create()
                            .register("http", PlainConnectionSocketFactory.INSTANCE)
                            .register("https", new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE))
                            .build()
                    )).build();

httpClient.execute(requisicao)

在我的情况下(Windows 10, IIS,本地开发环境(自签名SSL证书),Apache JMeter)。我必须导入两个证书到cacerts。 一个用于自定义主机名: CN = localhostCustom 第二个是localhost主机名: CN = localhost

的问候。


Linux

下载证书:

echo \
openssl s_client -showcerts -servername DOMAIN_NAME -connect DOMAIN_NAME:443 2>/dev/null \
awk '/-----BEGIN CERTIFICATE-----/, /-----END CERTIFICATE-----/' >> ~/FILENAME.cer

占位符:

DOMAIN_NAME -服务的域名 FILENAME -文件路径证书

导入证书到Java CA证书(Java 11):

keytool -importcert -trustcacerts -file ~/FILENAME.cer -alias ca_alias -keystore $JAVA_HOME/lib/security/cacerts

输入keystore默认密码changeit 信任此证书:输入yes。输出:

Certificate was added to keystore

我在使用Java 8时遇到了这个问题,但在升级到Java 11后得到了解决


错误

A problem occurred configuring root project 'uy-android-pagos'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve com.goo  gle.firebase:firebase-crashlytics-gradle:2.1.0.
     Required by:
         project :
      > Could not resolve com.goo  gle.firebase:firebase-crashlytics-gradle:2.1.0.
         > Could not get resource 'https://depdes.artifactory.prod.cloud.ihf/artifactory/itau-oq6-frameworks-maven/com/goo%20%20gle/firebase/firebase-crashlytics-gradle/2.1.0/firebase-crashlytics-gradle-2.1.0.pom'.
            > Could not GET 'https://depdes.artifactory.prod.cloud.ihf/artifactory/itau-oq6-frameworks-maven/com/goo%20%20gle/firebase/firebase-crashlytics-gradle/2.1.0/firebase-crashlytics-gradle-2.1.0.pom'.
               > PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

解决方案

请记住,有许多可能的原因产生这个错误,在我的情况下,我用以下方式修复了它:

用Gradle文件同步项目 检查错误无法解决com。咕gle.firebase: firebase-crashlytics-gradle:魅惑。 结构变化。Gradle (:project) from comGoo gle.firebase:firebase-crashlytic -gradle:2.1.0 to com.google.firebase:firebase-crashlytic -gradle:2.1.0(注意空格)

依赖类路径中的任何错误都会生成这种类型的异常。检查生成问题的提交的gradle。

GL


如果您在Spring Tools Suite或Eclipse等IDE中遇到此错误,请首先尝试使用URL的HTTP版本而不是HTTPS版本。

当我试图将SonarQube链接添加到Spring Tools Suite时,我遇到了这个错误。我将我的URL替换为:

http://sonarqube...

而不是

https://sonarqube...

我已经成功连接SonarQube。

我希望它能对那些像我一样在寻找这个问题答案的人有所帮助。


在我的案例中,我从Android Studio终端运行以下命令解决了这个问题

。/ gradlew组装

从那以后,项目顺利运行。


这是针对Glassfish服务器的:

通常Glassfish会看着仙人掌。证书文件存放在GLASSFISH_SERVER\glassfish\domains\domain1\config目录下。您可以更改此配置或替换cacerts。JKS文件和cacerts文件。

Glassfish使用了一些默认的JVM选项:

 -XX:+UnlockDiagnosticVMOptions
 -XX:NewRatio=2
 -XX:MaxPermSize=192m
 -Xmx512m
 -client
 -javaagent:C:/glassfish5/glassfish/lib/monitor/flashlight-agent.jar
 -Djavax.xml.accessExternalSchema=all
 -Djavax.net.ssl.trustStore=C:\glassfish5\glassfish\domains\domain1/config/cacerts.jks
 -Djdk.tls.rejectClientInitiatedRenegotiation=true
 -Djdk.corba.allowOutputStreamSubclass=true

如果你使用的是ubuntu/linux系统,在终端运行下面的命令。

cd /usr/local/share/ca-certificates

Cp /文件位置/----。crt。(拷贝CRT文件到/usr/local/share/ca-certificates)

sudo update-ca-certificates


受信任的证书存储在密钥工具中。当没有在关键工具中添加任何网站受信任证书时,会发生此错误。除上述答案外,请参考

面对PKIX路径构建失败的异常硒断链接脚本


将JDK版本从旧的jdk1.8.0_90版本更改为最新版本jdk1.8.0_239 如上所述,回答将证书导入keystore 向gradle添加密钥库属性。属性文件在java/react原生android基于项目

systemProp.javax.net.ssl.trustStore=C://Program Files//AdoptOpenJDK//jdk-8.0.282.8-hotspot//jre//lib//security//cacerts systemProp.javax.net.ssl.trustStorePassword=changeit


解决这个异常的简单步骤,(我在java 11上做的),

First you need to Download the public SSL certificate file of the target domain that you are trying to call,for that Open the target domain website in the chrome (Example: https://amazonservice.domain.com) Click on the small lock icon before the URL in the browser Click View certificates Now Click on Certificate is valid as shown below Now a new Popup will open as shown below, Open the details tab Select the RootCert at the top Click Export and save the .cer file to your system in a directory

现在您有了目标域的公共密钥存储库,您正在尝试在java应用程序中调用该密钥存储库,现在我们需要将该密钥存储库导入您的jre,为此转到$JAVA_HOME/bin目录并运行以下命令

./keytool -importcert -alias someAliasName -keystore {JAVA_HOME}/lib/security/cacerts -file {PathToDownloads}/certificateFileName.cer

它会要求您输入密码,如果您知道,请输入密码,证书的默认密码是changeit

参考文献

https://confluence.atlassian.com/kb/how-to-import-a-public-ssl-certificate-into-a-jvm-867025849.html https://confluence.atlassian.com/kb/unable-to-connect-to-ssl-services-due-to-pkix-path-building-failed-error-779355358.html


请选择根证书。默认情况下,浏览器选择的子证书可能无法解决问题。有关详细信息,请参阅此线程:无法找到请求目标的有效认证路径