簡單的 HTTPS 學習

簡單的 HTTPS 學習

1. 需求

現在使用的服務是HTTP調用形式,服務可能會有調用外圍https形式的服務,簡單了解了一下,然后寫了一個簡單的例子進行記錄。

HTTP(超文本傳輸協議) 是一種用于傳輸超文本的應用層協議,建立在TCP/IP協議棧之上。它定義了客戶端(如瀏覽器)如何向服務器請求資源,以及服務器如何響應這些請求。

HTTPS(超文本傳輸安全協議) 是HTTP協議的安全版本,它在HTTP與TCP之間加入了SSL/TLS加密層,通過加密數據傳輸來保障數據的安全性和完整性。

他們的主要區別如下所示:

  • 安全性

    HTTP協議不加密傳輸的數據,任何人都可以輕易地獲取和篡改傳輸的內容,存在嚴重的安全風險。

    為了解決HTTP協議的安全問題,HTTPS應運而生。

    HTTPS協議通過SSL/TLS加密傳輸的數據,即使數據被攔截,攻擊者也無法解密,有效地保障了數據的安全。

  • 數據傳輸方式

    HTTP使用的是不安全的TCP端口80進行數據傳輸,而HTTPS使用的是更安全的TCP端口443,并通過 SSL/TLS 協議對數據進行加密后再傳輸,進一步提升了數據傳輸的安全性。

  • 部署成本

    HTTP協議是免費的,不需要額外的證書。

    而HTTPS協議需要SSL/TLS證書,這些證書通常需要從受信任的證書頒發機構(CA)購買。

  • 性能

    由于需要進行加密和解密操作,HTTPS協議可能會略微影響網站的加載速度。

    但是,隨著現代硬件和優化加密算法的應用,這種影響已經被大大降低。

2. 準備

測試環境,我們使用JDK自帶的工具生成測試證書,我們此次的調用形式使用RestTemplate進行調用,調用形式分為以下情況

  • http 服務調用 https 服務 (服務端驗證)
  • https 服務調用 https 服務(客戶端 服務端雙向驗證)

2.1 準備證書秘鑰信息

我們本地使用 keytool 工具生成,我本地工具類位置如下C:\Program Files\Java\jdk1.8.0_131\bin

在這里插入圖片描述

然后需要使用PowerShell工具進入到keytool目錄中,執行命令生成兩份證書信息,對應兩個https服務使用,我們要輸入秘鑰口令,以及其他基礎信息

# 參數含義如下:
# keytool: 表示keytool工具
# genkey: 表示要創建一個新的密鑰。
# alias: 表示 keystore 的別名。anyname 都可以。
# storetype: 表示密鑰的倉庫類型,存儲格式是PKCS12.
# keyalg: 表示使用的加密算法是 RSA ,一種非對稱加密算法。
# keysize: 表示密鑰的長度。這里是2048.
# keystore: 表示生成的證書文件存放位置。 這里是D:\httpsSecurityKey.p12
# validity: 表示證書的有效時間365天。
keytool -genkey -alias httpsSecurity -storetype PKCS12 -keyalg RSA -keysize 2048  -keystore D:\https_security_key\httpsSecurityKey.p12 -validity 365keytool -genkey -alias httpsSecuritySecond -storetype PKCS12 -keyalg RSA -keysize 2048  -keystore D:\https_security_key\httpsSecuritySecondKey.p12 -validity 365

在這里插入圖片描述

然后執行命令生成兩份公鑰文件

# 從密鑰庫中提取公鑰證書到獨立的證書文件
# 從 httpsSecurityKey.p12 中導出證書部分
# 生成 httpsSecurity.cer 證書文件(只包含公鑰和身份信息,不含私鑰)
# 這個證書文件可以安全地分發給其他方
keytool -export -alias httpsSecurity -keystore D:\https_security_key\httpsSecurityKey.p12 -storetype PKCS12 -file D:\https_security_key\httpsSecurity.cer# 將證書添加到信任庫中,表示信任該證書持有者
# 創建或更新 truststore.jks 信任庫文件
# 將 httpsSecurity.cer 證書導入信任庫
# 設置該證書為"受信任的",用于驗證對方身份
keytool -import -alias httpsSecurity -file D:\https_security_key\httpsSecurity.cer -keystore D:\https_security_key\truststore.jks# 從密鑰庫中提取公鑰證書到獨立的證書文件...
keytool -export -alias httpsSecuritySecond -keystore D:\https_security_key\httpsSecuritySecondKey.p12 -storetype PKCS12 -file D:\https_security_key\httpsSecuritySecond.cer# 將證書添加到信任庫中,表示信任該證書持有者...
keytool -import -alias httpsSecuritySecond -file D:\https_security_key\httpsSecuritySecond.cer -keystore D:\https_security_key\truststoreSecond.jks

最終執行完畢后,會在目錄中看到這些文件

在這里插入圖片描述

2.2 編寫代碼

此次測試我們用到了三個服務,分別為http-server,https-server以及 https-server-second,整體的項目結構如下:

在這里插入圖片描述

2.2.1 引入pom

服務引入pom分為根pom,服務pom,具體內容如下所示

  1. 服務根pom

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>cn.git</groupId><artifactId>https-test</artifactId><version>1.0-SNAPSHOT</version><modules><module>http-server</module><module>https-server</module><module>https-server-second</module></modules><packaging>pom</packaging><properties><!-- 如果項目部署要給其他人使用,則此值必須填寫為true,否則父級pom不上傳,會引起子jar包無法下載情況 --><maven.deploy.skip>false</maven.deploy.skip><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><mybatis-plus.version>3.3.0</mybatis-plus.version><fastjson.version>1.2.83</fastjson.version><druid.version>1.2.4</druid.version><oracle.version>11.2.0.4.0-atlassian-hosted</oracle.version><hutool.version>5.5.7</hutool.version><lombok.version>1.18.6</lombok.version><mapstruct.version>1.4.1.Final</mapstruct.version><swagger.version>3.0.0</swagger.version><elasticjob.version>3.0.0-RC1</elasticjob.version><poi-tl.version>1.9.1</poi-tl.version><poi.version>4.1.2</poi.version><easyexcel.version>2.2.8</easyexcel.version><tomcat.version>9.0.44</tomcat.version></properties><!-- springboot dependency --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.8.RELEASE</version><relativePath/></parent><!-- 部署到私庫 --><distributionManagement><repository><id>git</id><name>git-releases</name><url>http://3.1.101.57:8081/repository/maven-releases/</url></repository><snapshotRepository><id>git</id><name>git-snapshot</name><url>http://3.1.101.57:8081/repository/maven-snapshots/</url></snapshotRepository></distributionManagement><dependencyManagement><dependencies><!-- fastjson --><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>${fastjson.version}</version></dependency><!-- hutool --><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>${hutool.version}</version></dependency><!-- lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></dependency><!-- mapstruct --><dependency><groupId>org.mapstruct</groupId><artifactId>mapstruct</artifactId><version>${mapstruct.version}</version></dependency><!-- swagger --><dependency><groupId>io.springfox</groupId><artifactId>springfox-boot-starter</artifactId><version>${swagger.version}</version></dependency><!-- poi --><dependency><groupId>com.deepoove</groupId><artifactId>poi-tl</artifactId><version>${poi-tl.version}</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>${poi.version}</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>${poi.version}</version></dependency><!-- easyexcel --><dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>${easyexcel.version}</version></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>${fastjson.version}</version></dependency></dependencies></project>
    
  2. 服務pom

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><artifactId>https-test</artifactId><groupId>cn.git</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>https-server-second</artifactId><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.6</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.5.7</version></dependency><dependency><groupId>org.mapstruct</groupId><artifactId>mapstruct</artifactId><version>1.4.1.Final</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.83</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-logging</artifactId></exclusion></exclusions></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-log4j2</artifactId></dependency><dependency><groupId>com.lmax</groupId><artifactId>disruptor</artifactId><version>3.3.4</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.14</version></dependency></dependencies><build><plugins><!-- compiler --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><configuration><source>1.8</source><target>1.8</target><annotationProcessorPaths><path><groupId>org.mapstruct</groupId><artifactId>mapstruct-processor</artifactId><version>1.4.1.Final</version></path><path><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></path></annotationProcessorPaths></configuration></plugin><!-- package --><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><!-- maven私服jar包部署插件 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-deploy-plugin</artifactId><version>${maven-deploy-plugin.version}</version><configuration><skip>false</skip></configuration></plugin></plugins></build>
    </project>
    

2.2.2 http-server服務

RestTemplate配置部分代碼

package cn.git.http.config;import org.apache.http.client.HttpClient;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;import javax.net.ssl.SSLContext;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.*;
import java.security.cert.CertificateException;/*** @description: RestTemplate 配置類* @program: bank-credit-sy* @author: lixuchun* @create: 2025-08-13*/
@Configuration
public class RestTemplateConfig {@Value("${client.ssl.trust-store}")private String trustStorePath;@Value("${client.ssl.trust-store-password}")private String trustStorePassword;@Value("${client.ssl.trust-store-type}")private String trustStoreType;/*** 創建RestTemplate實例** @return* @throws KeyStoreException* @throws NoSuchAlgorithmException* @throws KeyManagementException*/@Beanpublic RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {// 加載https服務提供的公鑰信息KeyStore trustStore = KeyStore.getInstance(trustStoreType);try {// 處理 classpath 資源ClassPathResource resource = new ClassPathResource(trustStorePath);InputStream in = resource.getInputStream();trustStore.load(in, trustStorePassword.toCharArray());in.close();} catch (IOException | NoSuchAlgorithmException | CertificateException e) {e.printStackTrace();}// 構建SSL上下文SSLContext sslContext = SSLContextBuilder.create()// 信任的證書.loadTrustMaterial(trustStore, null).build();SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext,// 禁用主機名驗證NoopHostnameVerifier.INSTANCE);HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();HttpComponentsClientHttpRequestFactory factory =new HttpComponentsClientHttpRequestFactory(httpClient);return new RestTemplate(factory);}
}

請求controller代碼

package cn.git.http.controller;import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;/*** @description: httpController測試接口* @program: bank-credit-sy* @author: lixuchun* @create: 2025-08-13*/
@Slf4j
@RestController
@RequestMapping("/http")
public class HttpController {@Autowiredprivate RestTemplate restTemplate;@GetMapping("/getHttpInfo")public String getHttpInfo() {log.info("getHttpInfo");return "http";}/*** GET獲取https服務信息** @return*/@GetMapping("/getHttpsInfo")public String getHttpsInfo() {return restTemplate.getForObject("https://3.2.36.116:443/https/getHttpsInfo", String.class);}/*** POST獲取https服務信息** @return*/@GetMapping("/getPostHttpsInfo")public String getPostHttpsInfo() {String requestBody = "{\"id\":\"1\",\"name\": \"jack\"}";// 創建請求頭,設置Content-Type為JSONHttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.APPLICATION_JSON);// 創建HttpEntityHttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);// POST請求,調用https服務return restTemplate.postForObject("https://3.2.36.116:443/https/getPostHttpsInfo", requestEntity, String.class);}
}

application.yaml配置文件內容

spring:application:name: @project.artifactId@main:allow-bean-definition-overriding: trueserver:port: 80# https-server 客戶端公鑰密碼配置
client:ssl:# 服務端提供信任庫文件trust-store: truststore.jkstrust-store-type: JKS# 信任庫文件密碼trust-store-password: 888666li

并且我們需要將生成的信任庫文件放入到 resoures 目錄之中

在這里插入圖片描述

2.2.3 https-server服務

controller測試接口文件

package cn.git.https.controller;import cn.git.https.vo.HttpsInVO;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.*;/*** @description: httpController測試接口* @program: bank-credit-sy* @author: lixuchun* @create: 2025-08-13*/
@RestController
@RequestMapping("/https")
public class HttpsController {@GetMapping("/getHttpsInfo")public String getHttpInfo() {return "https";}@PostMapping("/getPostHttpsInfo")public String getPostHttpInfo(@RequestBody HttpsInVO httpsInVO) {return JSONObject.toJSONString(httpsInVO);}
}

POST形式調用參數inVO文件

package cn.git.https.vo;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;/*** @description: 傳入inVO* @program: bank-credit-sy* @author: lixuchun* @create: 2025-08-13*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HttpsInVO {private String id;private String name;
}

application.yaml 服務配置文件

spring:application:name: @project.artifactId@main:allow-bean-definition-overriding: trueserver:port: 443ssl:# 服務器端HTTPS證書key-store: classpath:httpsSecurityKey.p12# 服務器端HTTPS證書密碼key-store-password: 666888li# 服務器端HTTPS證書別名key-alias: httpsSecurity# 服務器端HTTPS證書類型,默認JKSkey-store-type: PKCS12# 新增的雙向認證配置# 信任庫(包含客戶端公鑰證書)trust-store: classpath:truststoreSecond.jks# 信任庫密碼trust-store-password: 888666secondli# 要求客戶端認證 : want-不強制希望,need-強制,none-不認證client-auth: need

注意,我們需要將生成的服務證書以及另一個https服務提供的信任庫文件放到resources目錄中

在這里插入圖片描述

2.2.4 https-server-second服務

RestTemplate配置,此為雙向驗證,所以與http-server的restTemplate配置略有不同

package cn.git.https.config;import cn.hutool.core.util.StrUtil;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;import javax.net.ssl.SSLContext;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.security.*;
import java.security.cert.CertificateException;/*** @description: RestTemplate 配置類* @program: bank-credit-sy* @author: lixuchun* @create: 2025-08-13*/
@Configuration
public class RestTemplateConfig {@Value("${client.ssl.trust-store}")private String trustStorePath;@Value("${client.ssl.trust-store-password}")private String trustStorePassword;@Value("${client.ssl.trust-store-type}")private String trustStoreType;@Value("${server.ssl.key-store}")private String keyStorePath;@Value("${server.ssl.key-store-password}")private String keyStorePassword;@Value("${server.ssl.key-store-type}")private String keyStoreType;/*** 創建RestTemplate實例** @return* @throws KeyStoreException* @throws NoSuchAlgorithmException* @throws KeyManagementException*/@Beanpublic RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException, UnrecoverableKeyException {// 加載客戶端證書(用于雙向認證)KeyStore keyStore = KeyStore.getInstance(keyStoreType);try {// 處理 classpath 資源ClassPathResource resource = new ClassPathResource(keyStorePath.substring(10));InputStream in = resource.getInputStream();keyStore.load(in, keyStorePassword.toCharArray());in.close();} catch (IOException | NoSuchAlgorithmException | CertificateException e) {e.printStackTrace();}// 加載信任證書KeyStore trustStore = KeyStore.getInstance(trustStoreType);try {// 處理 classpath 資源ClassPathResource resource = new ClassPathResource(trustStorePath);InputStream in = resource.getInputStream();trustStore.load(in, trustStorePassword.toCharArray());in.close();} catch (IOException | NoSuchAlgorithmException | CertificateException e) {e.printStackTrace();}// 構建SSL上下文SSLContext sslContext = SSLContextBuilder.create().loadKeyMaterial(keyStore, keyStorePassword.toCharArray())// 信任的證書.loadTrustMaterial(trustStore, null).build();SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext,// 禁用主機名驗證NoopHostnameVerifier.INSTANCE);// 創建HttpClient實例HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();// 創建RestTemplate實例HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);return new RestTemplate(factory);}
}

controller測試接口代碼

package cn.git.https.controller;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;/*** @description: second-https controller測試接口* @program: bank-credit-sy* @author: lixuchun* @create: 2025-08-13*/
@RestController
@RequestMapping("/https")
public class HttpsSecondController {@Autowiredprivate RestTemplate restTemplate;@GetMapping("/getLocalHttpsSecondInfo")public String getHttpInfo() {return "getHttpsSecondInfo";}/*** GET獲取https服務信息** @return*/@GetMapping("/getHttpsSecondInfo")public String getHttpsSecondInfo() {return restTemplate.getForObject("https://3.2.36.116:443/https/getHttpsInfo", String.class);}/*** POST獲取https服務信息** @return*/@GetMapping("/getPostHttpsSecondInfo")public String getPostHttpsInfo() {String requestBody = "{\"id\":\"1\",\"name\": \"jack\"}";// 創建請求頭,設置Content-Type為JSONHttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.APPLICATION_JSON);// 創建HttpEntityHttpEntity<String> requestEntity = new HttpEntity<>(requestBody, headers);// POST請求,調用https服務return restTemplate.postForObject("https://3.2.36.116:443/https/getPostHttpsInfo", requestEntity, String.class);}
}

application.yaml配置文件信息

spring:application:name: @project.artifactId@main:allow-bean-definition-overriding: true# 服務器端HTTPS配置
server:port: 8443ssl:# 服務器端HTTPS證書key-store: classpath:httpsSecuritySecondKey.p12# 服務器端HTTPS證書密碼key-store-password: 666888secondli# 服務器端HTTPS證書別名key-alias: httpsSecuritySecond# 服務器端HTTPS證書類型key-store-type: PKCS12# 新增的雙向認證配置# 信任庫(包含客戶端公鑰證書)trust-store: classpath:truststore.jks# 信任庫密碼trust-store-password: 888666li# 要求客戶端認證 : want-不強制希望,need-強制,none-不認證client-auth: none# https-server 客戶端公鑰密碼配置
client:ssl:# 服務端提供信任庫文件trust-store: truststore.jks# 服務端提供信任庫文件類型trust-store-type: JKS# 信任庫文件密碼trust-store-password: 888666li

注意,我們需要將生成的服務證書以及另一個https服務提供的信任庫文件放到resources目錄中,主要實現雙向認證

在這里插入圖片描述

3. 測試

測試主要分為兩種測試,第一個http調用https,第二種https調用https(雙向驗證)

3.1 http調用 https

http調用https形式的時候,我們需要將https-server服務端的 client-auth 客戶端驗證禁用,否則訪問接口提示如下信息,需要配置瀏覽器證書信息

在這里插入圖片描述

禁用客戶端驗證,將 client-auth 設置為 none

在這里插入圖片描述

先訪問https-server自己服務接口,https://localhost/https/getHttpsInfo,請求結果如下

在這里插入圖片描述

然后通過http-server接口,restTemplate調用 https-server接口,http://localhost/http/getHttpsInfo 請求結果如下

在這里插入圖片描述

通過PostMan,訪問 https://localhost:443/https/getPostHttpsInfo 進行post請求,請求結果如下

在這里插入圖片描述

如果禁用 restTemplate配置的SSL證書信任庫,然后再發起請求,http://localhost/http/getHttpsInfo 請求結果如下

在這里插入圖片描述
在這里插入圖片描述

在這里插入圖片描述

3.2 https調用https

我們首先開啟https-server的客戶端驗證,現在訪問需要進行客戶端驗證了
在這里插入圖片描述

我們訪問 https-server-second 接口,里面進行了restTemplate調用 https-server接口 https://localhost:8443/https/getHttpsSecondInfo 展示結果如下

在這里插入圖片描述

如果我注釋https-server-second 配置restTemplate的 加載客戶端證書(用于雙向認證)配置,再次訪問https://localhost:8443/https/getHttpsSecondInfo 展示結果如下

在這里插入圖片描述
在這里插入圖片描述
項目的源碼位置:https://gitee.com/xiaodali/https-test

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/95705.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/95705.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/95705.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

[系統架構設計師]系統質量屬性與架構評估(八)

[系統架構設計師]系統質量屬性與架構評估&#xff08;八&#xff09; 一.軟件系統質量屬性 1.基本概念 軟件系統質量屬性&#xff1a;可測量或可測試的屬性 開發期質量屬性&#xff0c;運行期質量屬性面向架構評估的質量屬性&#xff1a;1.可用性&#xff1a; 提升策略 錯誤檢測…

【R語言】R 語言中 gsub 與正則表達式詳解(含 POSIX 與 Perl 風格實例)

R 語言中 gsub 與正則表達式詳解&#xff08;含 POSIX 與 Perl 風格實例&#xff09; 在 R 語言中&#xff0c;字符串處理是非常常見的需求&#xff0c;R 語言中的 gsub() 函數則具有字符串替換的功能。本文將通過兩個實例&#xff0c;幫助你深入理解 R 的 gsub()、POSIX 字符…

EN55035多媒體設備電磁兼容性抗干擾要求標準

EN55035 是一項由歐洲標準化委員會制定的電磁兼容性&#xff08;EMC&#xff09;標準&#xff0c;全稱為《多媒體設備的電磁兼容性要求》。該標準主要針對多媒體設備的電磁輻射和抗干擾能力進行規范&#xff0c;確保這類設備在電磁環境中能夠正常工作&#xff0c;同時不對其他設…

計算分組內時間列的最大差值

計算分組內時間列的最大差值 在 Pandas 中&#xff0c;要計算每個分組內 time 列的最大值與當前行值的差值&#xff0c;需結合 groupby() 和 transform() 方法。核心步驟如下&#xff1a;分組計算最大值 使用 transform(max) 獲取每個分組中 time 列的最大值&#xff0c;結果會…

CUDA 編程筆記:CUDA延遲隱藏

一、核心概念&#xff1a;延遲隱藏&#xff08;Latency Hiding&#xff09;是 GPU 通過多線程機制掩蓋指令延遲的關鍵技術。當某些線程束&#xff08;warp&#xff09;因指令延遲&#xff08;如內存訪問或算術計算&#xff09;而等待時&#xff0c;其他就緒線程束會立即被調度執…

MySQL工具包中的其他程序

雖然有很多不同的程序&#xff0c;但有些選項是公共的&#xff0c;比兔用戶名和密碼&#xff0c;使用方法和MySQL相同&#xff0c;在這里統一列出&#xff0c;后面我們介紹不同的工具時&#xff0c;只討論個性的選項以及作用以下是常用的MySQL程序&#xff1a;程序名作用mysqld…

C#WPF實戰出真汁09--【消費開單】--選擇菜品

1、功能介紹當選擇一個空桌時&#xff0c;必須先開臺才能開單&#xff0c;可以先開臺&#xff0c;再開單&#xff0c;也可以開臺的同時開單當選擇一個用餐中的餐桌時&#xff0c;必須顯示該桌前面已經點好的菜品&#xff0c;同時可以繼續點餐或結賬所以無論哪個功能都涉及選擇菜…

大廠語音合成成本深度對比:微軟 / 阿里 / 騰訊 / 火山 API 計費拆解與技術選型指南

在 AI 配音、智能客服、教育音頻等場景爆發的當下&#xff0c;語音合成 API 已成為企業技術棧中的核心組件。然而&#xff0c;不同云廠商的計費規則差異顯著&#xff0c;短文本 / 長文本計費分離、預付費 / 后付費價格梯度懸殊、音色授權費暗藏成本陷阱等問題&#xff0c;常導致…

Flutter開發 網絡請求

HttpClient&#xff08;dart自有&#xff09; 1.get 點擊請求按鈕獲取數據&#xff0c;解析數據獲取單詞展示到屏幕上。class MyState extends State {String info "暫無數據";List<Widget> texts [];overridevoid initState() {super.initState();}override…

vscode中用python調用matlab的函數(環境安裝)

本實踐適用于WIN11-x64和ubuntu22.04-x64系統&#xff0c;其余系統和架構未驗證。 效果展示 1.環境要求 MATLAB Engine API for Python 的系統要求&#xff1a;參閱此官方文檔MATLAB 與 Python 的版本兼容性&#xff1a;參閱此官方文檔 2.安裝步驟 安裝Vscode&#xff08;不…

【數據分享】大清河(大慶河)流域上游土地利用

而今天要說明數據就是大清河&#xff08;大慶河&#xff09;流域上游土地利用。數據介紹大清河&#xff0c;又稱大慶河&#xff0c;作為海河流域的重要支流&#xff0c;其流域上游地區不僅是區域水資源調控的關鍵節點&#xff0c;更是生態保護與經濟發展的重要載體。以下從地理…

圖論——Djikstra最短路

原理解釋 首先解釋一下它大概的應用場景以及原理&#xff1a;現在有這么一張圖&#xff0c;圖上各點之間都有一定的邊權或者說是距離。給定你一個起點&#xff08;例如點1&#xff09;&#xff0c;讓你求這個點到圖上所有點的最短距離是多少&#xff1f; 這個問題比較平常&…

kafka初步介紹

Kafka角色介紹TopicTopic主題的意思&#xff0c;消費者必須指定主題用于的消息發送&#xff0c;生產者也必須指定主題用于消息的接收。topic只是邏輯上的劃分。partitionpartition是分區的意思&#xff0c;他的主要作用是將發送到一個topic的數據做一個劃分。如果有4個partitio…

windows10的vs2019編譯openssl靜態庫備忘

1、下載安裝openssl源碼2、官網下載安裝activeperl或Strawberry Perl。官網下載慢&#xff0c;網盤找找。使用中activeperl有些異常提示、缺模塊&#xff0c;最后使用了Strawberry Perl。3、安裝nasm。powershell使用choco install nasm -y 即可。powershell使用cd命令打開當前…

學習筆記與效率提升指南:編程、記憶與面試備考

在學習與工作中&#xff0c;高效的記錄習慣、針對性的記憶方法和實用的技能儲備&#xff0c;是提升效率的關鍵。本文結合編程學習、面試備考和英語單詞積累&#xff0c;整理一套可落地的學習思路&#xff0c;尤其適合編程初學者。 一、學習核心原則&#xff1a;高效優先&#x…

順豐面試題

1. 你擅長處理哪類問題推薦回答&#xff1a; "我比較擅長處理以下幾類前端問題&#xff1a;性能優化&#xff1a;包括加載優化&#xff08;代碼分割、懶加載&#xff09;、運行時優化&#xff08;減少重排重繪&#xff09;等復雜組件開發&#xff1a;如表單聯動、可視化圖…

Warmup_steps 設置經驗

文章目錄什么是 Warmup&#xff1f;實現示例科學設置 Warmup 的黃金法則直觀例子什么是 Warmup&#xff1f; Warmup 是一種學習率調度策略&#xff0c;在訓練初期逐步增加學習率&#xff08;LR&#xff09;&#xff0c;而不是直接使用目標學習率。它解決了兩個關鍵問題&#x…

vue一個超簡單的菜單欄伸縮示例

代碼<template><div class"container"><!-- 左側區域 --><div class"left-side" :style"{ width: leftWidth px }">左側內容</div><!-- 右側區域 --><div class"right-side" :style"{ l…

Spark學習(Pyspark)

&#xff08;1&#xff09;Spark基礎入門 ①什么是Spark Spark是一款分布式內存計算的統一分析引擎。其特點就是對任意類型的數據進行自定義計算。Spark可以計算&#xff1a;結構化、半結構化、非結構化等各種類型的數據結構&#xff0c;同時也支持使用Python、Java、Scala、R以…

PDF壓縮原理詳解:如何在不失真的前提下減小文件體積?

與直接刪除內容不同&#xff0c;良好的PDF壓縮能在大幅減小體積的同時&#xff0c;較好地保留原有文字清晰度和圖像質量&#xff0c;兼顧實用性與視覺效果。軟件操作十分直觀&#xff0c;僅需設置輸入文件與輸出路徑&#xff0c;點擊【開始壓縮】按鈕即可啟動處理。畫質壓縮等級…