OpenSSL作为CA而不涉及certs / crl / index / etc环境
我认为我有正确的OpenSSL命令来签署证书,但我被卡住了,我发现的教程使用了不同的参数格式(我使用的是OpenSSL 0.9.8o 2010年6月1日)。
openssl ca -cert cert.pem -keyfile key.pem
(私钥没有加密,CSR在stdin上。)
它给出了这个错误
Using configuration from /usr/lib/ssl/openssl.cnf
./demoCA/index.txt: No such file or directory
unable to open './demoCA/index.txt'
查看该配置文件:
[ ca ]
default_ca = CA_default # The default ca section
[ CA_default ]
dir = ./demoCA # Where everything is kept
certs = $dir/certs # Where the issued certs are kepp
crl_dir = $dir/crl # Where the issued crl are kept
database = $dir/index.txt # database index file.
我没有任何设置。 我不想设置这些。
这是严格的nessecary,还是有“不要打扰”选项?
我试图创建空目录和文件,但我陷入混乱。 我真正想要的是像上面这样的命令,在stdout上输出,而不触及文件系统上的任何东西。
我不知道任何“不要打扰”选项,但是这里是你如何设置一个快速演示CA:
#!/bin/bash
CAROOT=/path/to/ca
mkdir -p ${CAROOT}/ca.db.certs # Signed certificates storage
touch ${CAROOT}/ca.db.index # Index of signed certificates
echo 01 > ${CAROOT}/ca.db.serial # Next (sequential) serial number
# Configuration
cat>${CAROOT}/ca.conf<<'EOF'
[ ca ]
default_ca = ca_default
[ ca_default ]
dir = REPLACE_LATER
certs = $dir
new_certs_dir = $dir/ca.db.certs
database = $dir/ca.db.index
serial = $dir/ca.db.serial
RANDFILE = $dir/ca.db.rand
certificate = $dir/ca.crt
private_key = $dir/ca.key
default_days = 365
default_crl_days = 30
default_md = md5
preserve = no
policy = generic_policy
[ generic_policy ]
countryName = optional
stateOrProvinceName = optional
localityName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
EOF
sed -i "s|REPLACE_LATER|${CAROOT}|" ${CAROOT}/ca.conf
cd ${CAROOT}
# Generate CA private key
openssl genrsa -out ca.key 1024
# Create Certificate Signing Request
openssl req -new -key ca.key
-out ca.csr
# Create self-signed certificate
openssl x509 -req -days 10000
-in ca.csr
-out ca.crt
-signkey ca.key
现在您可以生成并签署密钥:
# Create private/public key pair
openssl genrsa -out server.key 1024
# Create Certificate Signing Request
openssl req -new -key server.key
-out server.csr
# Sign key
openssl ca -config ${CAROOT}/ca.conf
-in server.csr
-cert ${CAROOT}/ca.crt
-keyfile ${CAROOT}/ca.key
-out server.crt
与使用ca选项不同,请使用-req尝试x509选项。 你会添加-CAfile来指向你的权限。 这将签署您的证书而不添加条目到索引。 这里有更多关于使用x509作为“小型CA”的信息。
http://www.openssl.org/docs/apps/x509.html#SIGNING_OPTIONS
根据snow6oy的回答,我做了以下工作:
openssl x509 -req -CA CACert.pem -CAkey CAKey.pem -CAcreateserial -in YourCSR.csr -out YourCert.pem
可能有用的几个可选标志:
-days 1095
(默认是30天)
-sha256
(RHEL 7默认为SHA-1)
上一篇: OpenSSL as a CA without touching the certs/crl/index/etc environment