ssl证书(https/wss)内网测试

前言

一般后端部署到外网,可以去申请免费的SSL 证书, 但在内网测试时,需要自己生成证书

本章主要讲述ssl证书生成

1:环境

生成证书 openssl (windows or linux 都行)

2:生成证书

1>生成私钥

pkcs#1私钥

openssl genrsa -out server.key 2048

pkcs#8私钥

openssl genpkey -out server-pkcs8.key -algorithm RSA -pkeyopt rsa_keygen_bits:2048

2>生成 证书请求文件

subj子参数详解:

缩写 翻译 英文对照

C 国家名称缩写 Country Name (2 letter code)

ST 州或省名称 State or Province Name (full name)

L 城市或区域称 Locality Name (eg, city)

O 组织名(或公司名) Organization Name (eg, company)

OU 组织单位名称(或部门名) Organizational Unit Name (eg, section)

CN 服务器域名/证书拥有者名称 Common Name (e.g. server FQDN or YOUR name)

emailAddress 邮件地址 Email

这里以内网IP 192.168.1.32 为例,

openssl req -subj "/CN=192.168.1.32" -new -key server.key -out server.csr

3>生成自签名证书

openssl x509 -req -days 3650 -in server.csr -signkey server.key -out ca.crt

3:测试

1> ca.crt 导入 (前端所在机子)

win10 位置 受信任的根证书颁发机构

2> 服务器

(1) c++ openssl

前端用golang 写的 结果如下

前端发hello 后端回复 hello变大写,其他不变

非hello ,第一个字符变为_

(2) rust tokio-websocket

如用要用pkcs12 可以用命令生成 密码自己随便设

openssl pkcs12 -export -in cert.crt -inkey private.key -out cert.p12

rust tokio_native_tls 读取方式

私钥 pkcs1 转 pkcs8

openssl pkcs8 -in rsakey-pkcs1.key-topk8 -out rsakey-pkcs8.key -nocrypt

私钥 pkcs1 转 pkcs8 加密的

openssl pkcs8 -in rsakey-pkcs1.key -topk8 -out rsakey-pkcs8-enc.key

Enter Encryption Password: xxxx

Verifying - Enter Encryption Password: xxxx

4:DEMO工程 后续如有需要再上传
如果觉得有用,麻烦点个赞,加个收藏

相关推荐
2501_916007471 天前
苹果商店iOS应用上架费用全面解析:开发者计划与审核费用计算
android·ios·小程序·https·uni-app·iphone·webview
Lsetea1 天前
证书没到期却报certificate has expired:OpenSSL定位中间证书与系统时间
运维·https·ssl证书·openssl·证书链
2501_916008891 天前
如何实现iOS App代码混淆:SwiftShield使用指南
android·ios·小程序·https·uni-app·iphone·webview
SDWAN_Cheap1 天前
HTTPS到底加密了什么?
https·数据加密
2501_916008891 天前
怎么用 Godot 导出 iOS 应用并上架 App Store?签名字段该填什么?
android·ios·小程序·https·uni-app·iphone·webview
Lsetea2 天前
Nginx报No required SSL certificate was sent:mTLS客户端证书排查
运维·nginx·https·ssl·openssl
ZeroNews内网穿透2 天前
内网部署 Halo 建站,用 ZeroNews 免费内网穿透安全发布到公网(无公网 IP 也能 HTTPS 访问)
docker·https·内网穿透·nas·反向代理·halo·zeronews
szephyr3 天前
HTTPS 证书申请与自动续期:acme.sh + Let‘s Encrypt 完整记录
nginx·https·acme.sh·证书续期
Lsetea3 天前
部署证书后提示“证书名称与输入不匹配”:Safari 报错的三层排查
nginx·https·safari·ssl证书·openssl
其实防守也摸鱼4 天前
DeepSeek Harness 开源贡献手记:从入门到合入主线
服务器·数据库·windows·https·ssl