第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

為什么我的放心 POST 方法不能接受所有主機(jī)?

為什么我的放心 POST 方法不能接受所有主機(jī)?

揚(yáng)帆大魚 2023-12-13 14:53:32
我們的目標(biāo)服務(wù)器 (censored.local) 具有 HTTPS 證書,CN = censored.com, *.censored.com測(cè)試引發(fā)異常:javax.net.ssl.SSLException: Certificate for "censored.local" doesn't match any of the subject alternative names: [censored.com, *.censored.com]我理解為什么會(huì)發(fā)生這種情況(RFC 2818),但我想出于測(cè)試目的繞過(guò)它。無(wú)法在目標(biāo)服務(wù)器上安裝不同的證書。.relaxedHTTPSValidation() 和 .allowAllHostnames() 不起作用。所以,我嘗試編寫代碼:我的測(cè)試課:....given().spec(reqSpec)...我的配置類:public abstract class Configurator {    protected static TestEnv envConf = chooseEnv();    protected static RequestSpecification reqSpec;    static { try { reqSpec = configureRestAssured(); } catch (Exception e) {e.printStackTrace(); } }    protected static TestEnv chooseEnv() {        // Some logic following to select an instance from TestEnv (not shown here)        ...            envConf = TestEnv.BETA;        return envConf;    }    protected static RequestSpecification configureRestAssured() {        RequestSpecification reqSpec = new RequestSpecBuilder().build();        reqSpec                .header("Authorization", String.format("Bearer %s", envConf.getBearerToken()))                // This gets the censored.local URI:                .baseUri(envConf.getBaseURI())                .config(getRAconfig());        return reqSpec;    }    private static RestAssuredConfig getRAconfig() {        SSLSocketFactory sslSocket = getSSLsocket (envConf.getKeystoreFile(), "keystorePassword", "PrivateKeyPassword");        RestAssuredConfig raConfig = RestAssuredConfig.config()        .sslConfig(SSLConfig.sslConfig().sslSocketFactory(sslSocket));        return raConfig;    }STRICT基本上顯示了我的問(wèn)題嗎?如果是這樣,如何破解非嚴(yán)格的 x509HostnameVerifier?另外,我知道以下內(nèi)容,但不知道如何將其用于我的放心連接:https://tutoref.com/how-to-disable-ssl-certificat-validation-in-java/
查看完整描述

1 回答

?
Cats萌萌

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超9個(gè)贊

我找到了根據(jù)需要自定義 SSL 配置的方法。附有稍微審查的代碼。尋找“圣杯”評(píng)論:


 protected static RequestSpecification configureRestAssured() {

    // Create the ReqSpec instance:

    RequestSpecification reqSpecToBuild = new RequestSpecBuilder().build();

    // Configure more simple stuff for common request specification:

    reqSpecToBuild

            .header("Content-Type", "application/json")

            .baseUri(envConf.getBaseURI())

            .config(getRAconfig());

    return reqSpecToBuild; 

    }

// Add extended config object to the request spec:

private static RestAssuredConfig getRAconfig() {

    // Create a special socket with our keystore and ALLOW_ALL_HOSTNAME_VERIFIER:

    SSLSocketFactory sslSocket = getSSLsocket (envConf.getKeystoreFile(), somePass, somePass);

    // Create a configuration instance to load into the request spec via config():

    RestAssuredConfig raConfigToBuild = RestAssuredConfig.config()

            // Set SSL configuration into the RA configuration, with an SSLConfig object, that refers to our socket:

            .sslConfig(SSLConfig.sslConfig().sslSocketFactory(sslSocket));

    return raConfigToBuild;

}

private static SSLSocketFactory getSSLsocket(String ksPath, String ksPassword, String pkPassword) {

    KeyStore keystore = KeyStore.getInstance("PKCS12");

    // Load keystore file and password:

    keystore.load(new FileInputStream(ksPath), ksPassword.toCharArray());

    SSLContext context = SSLContexts.custom()

            .loadKeyMaterial(keystore, pkPassword.toCharArray())

            .build();

    // This is the holy grail:

    SSLSocketFactory sslSocketToBuild = new SSLSocketFactory(context, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

    return sslSocketToBuild;

}

}

請(qǐng)注意,我不僅向 SSLSocketFactory 的構(gòu)造函數(shù)提供一個(gè)參數(shù),而且還提供常規(guī)參數(shù)(上下文)以及 ALLOW_ALL_HOSTNAME_VERIFIER 參數(shù) - 這會(huì)產(chǎn)生影響!


查看完整回答
反對(duì) 回復(fù) 2023-12-13
  • 1 回答
  • 0 關(guān)注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)