JSK证书生成

生成密钥库和证书

使用Java的keytool命令来生成一个Java密钥库(Keystore)和证书。keytool是Java开发工具包(JDK)中用于管理密钥库和证书的命令行工具。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#创建证书存放目录
[weblogic@osb1 jksHL]$ mkdir -p /home/weblogic/Oracle/jksHL
#生成证书
[weblogic@Weblogic201 jksHL]$ keytool -genkey -alias weblogic -keyalg RSA -keypass keypass -keystore identity.jks -storepass storepass -validity 3650
#姓氏
What is your first and last name?

[Unknown]: LiuJiangxu
#组织单位
What is the name of your organizationalunit?

[Unknown]: GJYX
#组织
What is the name of your organization?

[Unknown]: GJYX
#城市/地区
What is the name of your City or Locality?

[Unknown]: XA
#省份/州
What is the name of your State or Province?

[Unknown]: SX
#国家代码
What is the two-letter country code forthis unit?

[Unknown]: CN

Is CN=HaiLang, OU=GZCSS, O=GZCSS, L=GZ,ST=GD, C=CN correct?

[no]: yes
参数 含义
-alias weblogic 为密钥对指定一个别名
-keyalg RSA 指定密钥算法为RSA
-keysize 2048 指定密钥大小为2048位
-validity 3650 设置证书的有效期为3650天
-keystore identity.jks 指定密钥库文件的名称
-storepass storepass 设置密钥库的密码
-keypass keypass 设置私钥的密码

导出证书

1
2
3
4
[weblogic@osb1 jksHL]$ keytool -export -alias weblogic -file root.cer -keystore identity.jks
Enter keystore password: (输入密码:storepass)

Certificate stored in file <root.cer>
参数 含义
-alias weblogic 指定要导出的密钥对的别名
-file root.cer 指定导出证书文件的名称
-keystore identity.jks 指定密钥库文件的名称

导入证书

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[weblogic@osb1 jksHL]$ keytool -import -alias weblogic -trustcacerts -file root.cer -keystore trust.jks
Enter keystore password:
Re-enter new password:
Owner: CN=liujiangxu, OU=GJYX, O=GJYX, L=XA, ST=SX, C=CN
Issuer: CN=liujiangxu, OU=GJYX, O=GJYX, L=XA, ST=SX, C=CN
Serial number: 277fe686
Valid from: Mon Dec 02 10:00:10 CST 2024 until: Thu Nov 30 10:00:10 CST 2034
Certificate fingerprints:
MD5: 85:51:94:BE:A0:C4:67:9A:34:CB:F9:29:D9:1C:46:96
SHA1: 27:0A:E0:6A:65:3F:73:76:14:94:D4:3C:3A:36:EA:D9:B5:43:31:B0
SHA256: B9:10:AF:01:D9:88:6C:3E:31:03:11:66:C3:B3:51:EF:2C:7C:E8:F6:21:E0:5C:16:CF:C0:D8:83:13:B0:3A:C4
Signature algorithm name: SHA256withRSA
Subject Public Key Algorithm: 2048-bit RSA key
Version: 3

Extensions:

#1: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 51 70 A3 F8 A0 E3 31 11 8E 9A A0 DB 0C 98 B2 91 Qp....1.........
0010: 8F F7 6B A5 ..k.
]
]
参数 含义
-alias weblogic 为导入的证书指定一个别名
-keystore trust.jks 指定密钥库的名称和位置
-trustcacerts -file root.cer 添加证书至信任库

console启用ssl功能

密钥库

主页osb1服务器概要AdminServer

upload successful

SSL

主页osb1服务器概要AdminServer

upload successful

一般信息

upload successful

信息添后保存激活更改(不需要重启)查看服务器对应8443端口已监听 访问正常

upload successful

nginx反代配置安全证书

自签CA

下载 mkcert 自签ca脚本
创建CA根证书(powershell)

PS C:\Users\ljx\Desktop> .\mkcert-v1.4.4-windows-amd64.exe -install

生成对应nginx IP证书

PS C:\Users\ljx\Desktop> .\mkcert-v1.4.4-windows-amd64.exe 10.1.74.23

查看根证书存放位置

PS C:\Users\ljx\Desktop> .\mkcert-v1.4.4-windows-amd64.exe -CAROOT

配置nginx

上传证书至服务器,修改文件后缀

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
server {
listen 443 ssl;
server_name 10.1.74.23;
ssl_certificate /usr/local/nginx/cert/10.1.74.23.crt;
ssl_certificate_key /usr/local/nginx/cert/10.1.74.23.key;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;

ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
access_log /logs/ssl_access.log;

location / {
proxy_pass https://10.1.72.215:8443/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

}

本地导安装根证书

将生成根证书rootCA.pem修改为rootCA.crt
双击安装证书
存储位置-》本地计算机
将所有证书都放入下列存储-》受信任的根证书颁发机构
至此本地自签https安全已完成

upload successful