一 ) 首先创建CA根证书 1) 生成RSA private key 给CA (3 DES 加密, PEM 格式): $ openssl genrsa -des3 -out rootca.key 1024 2) 产生一个X509结构,PEM格式的自签名证书(当然也可以由CA机构签名) $ openssl req -new -x509 -days 365 -key rootca.key -out rootca.crt 3) 查看该根证书的详细内容 $ openssl x509 -noout -text -in rootca.crt 4) 验证证书有效性 $ openssl verify -CAfile rootca.crt rootca.crt 第一个为根证书,第二个为需要验证的子证书,由于是自签名,相当于自己给自己颁发的证书。 二 ) 用根证书颁发子证书 1) 生成一个3DES 加密,PEM格式的RSA private KEY . $ openssl genrsa -des3 -out user.key 1024 2) 产生证书签名请求文件(PEM格式) $ openssl req -new -key user.key -out user.csr 3) 使用CA根证书签名 A 生成配置文件如下ca.config : [ ca ] default_ca=CA_own [ CA_own ] dir=C:/openssl/bin certs=C:/openssl/bin new_certs_dir=C:/openssl/bin //生成子证书的目录 database=C:/openssl/bin/index.txt //生成子证书后会更新内容到此文件 serial=C:/openssl/bin/serial.txt //子证书的序列号从此文件读取 certificate=C:/openssl/bin/rootca.crt //根证书 private_key=C:/openssl/bin/rootca.key //根证书的私钥 default_days=365 default_crl_days=30 default_md=md5 preserve=no policy=policy_anything [ policy_anything ] countryName=optional stateOrProvinceName=optional localityName=optional organizationName=optional organizationalUnitName=optional commonName=supplied emailAddress=optional B 执行如下命令来签名 openssl ca -config ca.config -out user.crt -infiles user.csr 4) 验证证书有效性 openssl verify -CAfile rootca.crt user.crt 用rootca.crt的公钥验证user.crt的签名是否合法。 |
|