Spring Cloud Gateway配置双向SSL认证(完整指南)
本文将详细介绍如何为Spring Cloud Gateway配置双向SSL认证,包括证书生成、配置和使用。
目录结构
/my-gateway-project
├── /certs
│ ├── ca.crt # 根证书
│ ├── ca.key # 根私钥
│ ├── gateway.crt # 网关证书
│ ├── gateway.key # 网关私钥
│ ├── client.crt # 客户端证书
│ ├── client.key # 客户端私钥
│ ├── gateway.p12 # 网关PKCS12格式
│ ├── client.p12 # 客户端PKCS12格式
│ └── truststore.p12 # 信任库(存放CA证书)
├── /src
│ └── /main
│ └── /resources
│ └── /keystore
│ ├── gateway.p12 # 网关证书
│ └── truststore.p12 # 信任库
1. 生成SSL证书
1.1 创建根CA(自签名)
openssl req -x509 -sha256 -days 365 -newkey rsa:2048 -nodes \
-keyout certs/ca.key -out certs/ca.crt \
-subj "/CN=MyRootCA"