国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

解決javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException

這篇具有很好參考價(jià)值的文章主要介紹了解決javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

問題現(xiàn)象:

Java Spring應(yīng)用發(fā)送數(shù)據(jù)報(bào)如下問題。

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

原因分析:

用httpclient訪問https資源時(shí),會(huì)出現(xiàn)異常,與環(huán)境也有關(guān)系,有些機(jī)器請(qǐng)求正常。

解決方案:

1.復(fù)制附錄代碼到文本文件中,改名為InstallCert.java。然后在命令行中執(zhí)行命令,編譯InstallCert.java:

javac InstallCert.java

?2.再執(zhí)行以下命令:

java InstallCert www.baidu.com

說明:網(wǎng)址處不需要輸入(https://)信息,比如 www.baidu.com,只需域名即可。

隨后服務(wù)器會(huì)返回認(rèn)證的主題,發(fā)行方,加密方式等信息。

3.在這里輸入1后,回車。

Enter certificate to add to trusted keystore or 'q' to quit: [1]
1

在目錄下會(huì)生成文件jssecacerts,自此認(rèn)證過程結(jié)束。

替換證書:

1.windows系統(tǒng):將生成的jssecacerts文件復(fù)制到 jdk的相應(yīng)路徑下即可。

windows系統(tǒng)一般需要首先找到j(luò)dk安裝路徑

D:\Java\jdk1.8.0_221\jre\lib\security

2.Linux系統(tǒng):需要首先使用 scp 命令 將 jssecacerts 傳輸至服務(wù)器。

3.docker:jdk通常在這個(gè)地方

/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/security/

/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/ (和上面其實(shí)一樣)

替換完后,重啟 docker 即可。

附錄:?

/*

 * 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.

 */

import java.io.*;

import java.net.URL;

import java.security.*;

import java.security.cert.*;

import javax.net.ssl.*;

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);

        }
    }

}

另詳見:https://blog.csdn.net/chaishen10000/article/details/82992291文章來源地址http://www.zghlxwxcb.cn/news/detail-573584.html

到了這里,關(guān)于解決javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 請(qǐng)求https報(bào)錯(cuò)證書校驗(yàn)失?。╦avax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX

    項(xiàng)目中請(qǐng)求第三方https的URL,報(bào)錯(cuò)ssl證書校驗(yàn)失敗 ssl校驗(yàn)失敗有兩種可能,一種是服務(wù)端ssl證書配置錯(cuò)誤,一種是客戶端請(qǐng)求的是非信任的https地址,客戶端不信任該https的ssl證書。懷疑是使用了自簽名證書,非各大廠提供簽名證書 該問題有兩種請(qǐng)求方案 手動(dòng)下載ssl證書 (

    2024年02月03日
    瀏覽(43)
  • sun.security.validator.ValidatorException: PKIXpath building failed: sun.security.provider,javax.net

    sun.security.validator.ValidatorException: PKIXpath building failed: sun.security.provider,javax.net

    報(bào)錯(cuò)信息: 問題描述: 在java代碼中調(diào)用其他項(xiàng)目接口,發(fā)起的是https請(qǐng)求。報(bào)錯(cuò)信息說找不到有效證書路徑。 問題解決: 信任所有SSL證書 1、新建一個(gè)SslUtil類 2、在HttpUtil工具類中修改代碼 忽略HTTPS請(qǐng)求的SSL證書代碼,必須在openConnection之前調(diào)用 解決方案參考文章https://de

    2024年02月08日
    瀏覽(16)
  • Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateNotYetValidException:

    Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateNotYetValidException:

    生命就像人家的魔法書,涂涂改改又是一年?? 原因 解決辦法 完整報(bào)錯(cuò): 在執(zhí)行sqoop腳本導(dǎo)數(shù)據(jù)的時(shí)候出現(xiàn) Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateNotYetValidException: NotBefore: Tue Oct 11 17:24:18 CST 2022 報(bào)錯(cuò),證書不合法,解決辦法是jdbc連接MySQL時(shí)不使用ssl協(xié)議,

    2024年02月15日
    瀏覽(58)
  • Macos jdk ssl javax.net.ssl.SSLHandshakeException完美解決

    Macos jdk ssl javax.net.ssl.SSLHandshakeException完美解決

    報(bào)了這么一個(gè)錯(cuò)誤 javax.net.ssl.SSLHandshakeException: Remote host terminated the handshake 網(wǎng)上一大把,測(cè)試不能用,谷歌了一下,發(fā)現(xiàn)少配置了一個(gè)環(huán)境變量。 System.setProperty(\\\"jdk.tls.useExtendedMasterSecret\\\", \\\"false\\\");//設(shè)置環(huán)境變量 /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre/lib/security/java.se

    2024年02月13日
    瀏覽(25)
  • 解決遠(yuǎn)程調(diào)用三方接口:javax.net.ssl.SSLHandshakeException報(bào)錯(cuò)

    最近在對(duì)接騰訊會(huì)議API接口,在鑒權(quán)完成后開始調(diào)用對(duì)方的接口,在此過程中出現(xiàn)調(diào)用報(bào)錯(cuò):javax.net.ssl.SSLHandshakeException。 當(dāng)你在進(jìn)行https請(qǐng)求時(shí),JDK中不存在三方服務(wù)的信任證書,導(dǎo)致出現(xiàn)錯(cuò)誤javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路徑構(gòu)建失敗。

    2024年02月13日
    瀏覽(29)
  • 已解決javax.net.ssl.SSLHandshakeException: SSL握手異常的正確解決方法,親測(cè)有效?。?!

    已解決javax.net.ssl.SSLHandshakeException: SSL握手異常的正確解決方法,親測(cè)有效?。。?目錄 問題分析 場(chǎng)景描述 報(bào)錯(cuò)原因 解決思路 解決方法 總結(jié) ?博主v:XiaoMing_Java 在開發(fā)涉及HTTPS通信的Java應(yīng)用時(shí), javax.net.ssl.SSLHandshakeException 是一個(gè)常見的問題,它發(fā)生在客戶端與服務(wù)器嘗試建

    2024年04月12日
    瀏覽(20)
  • 解決報(bào)錯(cuò):javax.net.ssl.SSLHandshakeException: No appropriate protocol

    解決報(bào)錯(cuò):javax.net.ssl.SSLHandshakeException: No appropriate protocol

    使用對(duì)象存儲(chǔ)進(jìn)行文件上傳時(shí)報(bào)錯(cuò) 注:該問題只要需要用到http的都有可能出現(xiàn),不是只針對(duì)對(duì)象存儲(chǔ) jdk 的 java.security 文件存在配置問題 1、查看當(dāng)前服務(wù)器使用的 jdk 版本 命令: java -version 2、查看該jdk的安裝目錄 命令: find / -name java.security 這里選擇通過搜索 java.security 來

    2024年01月24日
    瀏覽(23)
  • javax.net.ssl.SSLHandshakeException No appropriate protocol報(bào)錯(cuò)解決方案

    javax.net.ssl.SSLHandshakeException No appropriate protocol報(bào)錯(cuò)解決方案

    用java開發(fā)了一個(gè)簡(jiǎn)單的***發(fā)送郵件***的程序,本地運(yùn)行正常,但是上傳到服務(wù)器就出現(xiàn)報(bào)錯(cuò): 方案一 [原文參考地址](javax.net.ssl.SSLHandshakeException: No appropriate protocol報(bào)錯(cuò)解決_藍(lán)緣的博客-CSDN博客) ? 1、找到j(luò)dk目錄/jre/lib/security/java.security,去掉jdk.tls.disabledAlgorithm中的SSLv3、T

    2023年04月15日
    瀏覽(21)
  • javax.net.ssl.SSLHandshakeException

    解決辦法升級(jí)jdk版本或者修改jdk文件 1、對(duì)于服務(wù)器來說要支持域名并且不進(jìn)行ssl證書校驗(yàn),需要升級(jí)到j(luò)dk1.8的201版本及以上 2、修改…JavaJDKjrelibsecurity目錄下java.security文件,添加下面語句到文件內(nèi)容中

    2024年02月11日
    瀏覽(21)
  • https請(qǐng)求報(bào)錯(cuò):javax.net.ssl.SSLHandshakeException:Received fatal alert: unrecognized_name 的解決過程

    https請(qǐng)求報(bào)錯(cuò):javax.net.ssl.SSLHandshakeException:Received fatal alert: unrecognized_name 的解決過程

    提示:本地調(diào)試正常: 項(xiàng)目場(chǎng)景: 部署到WebSphere服務(wù)器上就會(huì)報(bào)上述錯(cuò)誤; 一度認(rèn)為是WebSphere服務(wù)器上的配置有問題,經(jīng)過多次償試,最終解決問題發(fā)現(xiàn)和服務(wù)配置無關(guān); 測(cè)試環(huán)境使用HttpClient發(fā)送https請(qǐng)求下載附件時(shí)報(bào)錯(cuò): 提示:項(xiàng)目地址是http,需要訪問的地址是https: 因?yàn)樵L問

    2024年02月05日
    瀏覽(35)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包