gpt4 book ai didi

openssl - 如何创建自己的自签名根证书和中间 CA 以导入 Java keystore ?

转载 作者:行者123 更新时间:2023-12-04 09:03:18 25 4
gpt4 key购买 nike

如何创建要在 Java keystore 中导入的自签名根证书和中间 CA?

我们将其用于 SSL 和 TLS,稍后用于基于客户端证书的 CLIENT-AUTH 身份验证。

使用 OpenSSL 和 KeyTool。

最佳答案

对于任何想要生成链和许多证书的人来说,这只是一个旁注。精炼@EpicPandaForce 自己的答案,这是一个在 root-ca/ 中创建根 CA 的脚本, intermediate/ 中的中间 CA和三个证书到 out/ ,每个都用中间 CA 签名。

#!/bin/bash -x

set -e

for C in `echo root-ca intermediate`; do

mkdir $C
cd $C
mkdir certs crl newcerts private
cd ..

echo 1000 > $C/serial
touch $C/index.txt $C/index.txt.attr

echo '
[ ca ]
default_ca = CA_default
[ CA_default ]
dir = '$C' # Where everything is kept
certs = $dir/certs # Where the issued certs are kept
crl_dir = $dir/crl # Where the issued crl are kept
database = $dir/index.txt # database index file.
new_certs_dir = $dir/newcerts # default place for new certs.
certificate = $dir/cacert.pem # The CA certificate
serial = $dir/serial # The current serial number
crl = $dir/crl.pem # The current CRL
private_key = $dir/private/ca.key.pem # The private key
RANDFILE = $dir/.rnd # private random number file
nameopt = default_ca
certopt = default_ca
policy = policy_match
default_days = 365
default_md = sha256

[ policy_match ]
countryName = optional
stateOrProvinceName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional

[req]
req_extensions = v3_req
distinguished_name = req_distinguished_name

[req_distinguished_name]

[v3_req]
basicConstraints = CA:TRUE
' > $C/openssl.conf
done

openssl genrsa -out root-ca/private/ca.key 2048
openssl req -config root-ca/openssl.conf -new -x509 -days 3650 -key root-ca/private/ca.key -sha256 -extensions v3_req -out root-ca/certs/ca.crt -subj '/CN=Root-ca'

openssl genrsa -out intermediate/private/intermediate.key 2048
openssl req -config intermediate/openssl.conf -sha256 -new -key intermediate/private/intermediate.key -out intermediate/certs/intermediate.csr -subj '/CN=Interm.'
openssl ca -batch -config root-ca/openssl.conf -keyfile root-ca/private/ca.key -cert root-ca/certs/ca.crt -extensions v3_req -notext -md sha256 -in intermediate/certs/intermediate.csr -out intermediate/certs/intermediate.crt

mkdir out

for I in `seq 1 3` ; do
openssl req -new -keyout out/$I.key -out out/$I.request -days 365 -nodes -subj "/CN=$I.example.com" -newkey rsa:2048
openssl ca -batch -config root-ca/openssl.conf -keyfile intermediate/private/intermediate.key -cert intermediate/certs/intermediate.crt -out out/$I.crt -infiles out/$I.request
done

关于openssl - 如何创建自己的自签名根证书和中间 CA 以导入 Java keystore ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26759550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com