- CA证书介绍
CA是证书的签发机构,它是公钥基础设施(Public Key Infrastructure,PKI)的核心。CA是负责签发证书、认证证书、管理已颁发证书的机关。
CA 拥有一个证书(内含公钥和私钥)。网上的公众用户通过验证 CA 的签字从而信任 CA ,任何人都可以得到 CA 的证书(含公钥),用以验证它所签发的证书。
如果用户想得到一份属于自己的证书,他应先向 CA 提出申请。在 CA 判明申请者的身份后,便为他分配一个公钥,并且 CA 将该公钥与申请者的身份信息绑在一起,并为之签字后,便形成证书发给申请者。
如果一个用户想鉴别另一个证书的真伪,需要用 CA 的公钥对那个证书上的签字进行验证,一旦验证通过,该证书就被认为是有效的。证书实际是由证书签证机关(CA)签发的对用户的公钥的认证。
证书的内容包括:电子签证机关的信息、公钥用户信息、公钥、权威机构的签字和有效期等等。证书的格式和验证方法普遍遵循X.509 国际标准。
- CA证书制作
-
在使用https协议进行传输事,会出现不安全连接警告,此时需要在客户端、服务器端分别导入CA证书,浏览器才会信任该网站。CA证书制作需要使用openssl工具。
-
修改/etc/pki/tls/openssl.cnf(建议不在默认文件中修改,可复制一份,在生成证书相关文件时,使用-config进行指定,具体参数按照实际情况填写,域名(IP)写对即可)
-
# 确保req下存在以下2行(默认第一行是有的,第2行被注释了)
[ req ]
distinguished_name = req_distinguished_name
req_extensions = v3_req
-
# 确保req_distinguished_name下没有 0.xxx 的标签,有的话把0.xxx的0. 去掉
[ req_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = CN
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = GuangDong
localityName = Locality Name (eg, city)
localityName_default = ShenZhen
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = Company
commonName = Internet Widgits Ltd
commonName_max = 64
-
# 新增最后一行内容 subjectAltName = @alt_names(前2行默认存在)
[ v3_req ]
# Extensions to add to a certificate request
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names
-
# 新增 alt_names,注意括号前后的空格,DNS.x 的数量可以自己加,IP.x为添加IP
[ alt_names ]
IP.1 = 10.1.2.11
IP.1 = 10.1.2.12 -
生成相关目录及文件(默认没有,需要手动创建)
mkdir -p /etc/pki/CA/{certs,crl,newcerts,private}
touch /etc/pki/CA/index.txt
echo 00 > /etc/pki/CA/serial - 生成ca.key并自签署
-
openssl req -new -x509 -days 3650 -keyout ca.key -out ca.crt
- 生成server.key
-
openssl genrsa -out server.key 2048
-
生成证书签名请求
openssl req -new -key server.key -out server.csr
-
查看请求文件
openssl req -text -noout -in server.csr
内容如下:
Certificate Request: Data: Version: 1 (0x0) Subject: C = CN, ST = GuangDong, L = ShenZhen, O = Company, OU = ST, CN = 10.1.2.11, emailAddress = it.com.cn Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public-Key: (2048 bit) Modulus: 00:ad:7c:c3:d0:76:5b:66:fb:07:ad:5b:f1:88:9e: 10:7b:76:b9:c5:c5:4e:7b:10:e5:31:16:15:f7:55: 7a:e0:a2:bb:74:05:2b:59:ac:8f:2a:5e:58:16:6a: cd:04:04:ab:67:48:fa:04:42:55:1d:af:27:a2:29: 6e:f2:e6:d5:64:ce:06:18:cc:2a:1e:21:c5:78:51: a0:22:63:e3:39:9e:21:20:98:59:6e:6d:90:e3:53: f0:e5:9c:e9:ef:ca:13:ce:74:d3:8d:86:ef:1f:08: e1:6c:f7:48:1f:3c:52:9d:76:92:c6:d3:54:b3:ac: 00:c8:74:cf:75:44:f6:e7:f7:a6:bd:61:c4:37:ad: fa:e2:49:c4:45:75:e3:f1:78:d1:d2:e0:0b:7d:81: 72:07:4f:70:0d:05:49:30:9c:85:c5:48:04:33:0d: 18:90:42:ee:30:03:10:f2:fd:83:19:e4:4d:d5:51: e2:0e:51:77:e7:6e:d5:48:11:64:24:d1:79:5c:c9: 00:e1:4c:e3:b4:c2:d3:0a:8f:19:17:38:06:ce:10: 06:8e:be:6c:ac:b1:6b:95:0a:54:81:79:24:f0:2c: e4:aa:9f:33:08:c7:24:ea:14:0e:db:4b:5e:97:ea: 69:c6:26:3b:2a:4d:35:b6:82:ad:54:07:54:7b:78: 20:39 Exponent: 65537 (0x10001) Attributes: Requested Extensions: X509v3 Basic Constraints: CA:FALSE X509v3 Key Usage: Digital Signature, Non Repudiation, Key Encipherment X509v3 Subject Alternative Name: IP Address:10.1.2.11, IP Address:10.1.2.12 Signature Algorithm: sha256WithRSAEncryption 1a:5a:b3:0e:c0:41:61:70:bb:bb:f9:aa:06:ec:4f:b6:a7:2d: 27:68:4d:d1:92:32:78:1b:c0:13:43:94:e3:83:e0:60:6b:a2: 5e:bd:cc:3e:c0:6a:f4:e6:cc:27:8b:5d:c6:0d:8a:36:01:f7: ff:d8:b3:2e:f8:51:f0:d3:23:01:61:10:cd:ae:24:c9:de:6a: 82:9b:6f:07:6c:37:a0:c1:5d:80:b2:ef:ba:9f:b2:68:7b:08: d4:34:06:f1:10:35:37:f7:a4:bc:15:4c:64:93:bc:54:b5:98: ce:ff:86:57:8a:da:b6:b4:68:81:07:f8:82:92:17:5b:a0:7e: ce:9a:6a:8e:b3:89:15:c0:f1:d3:ea:70:a6:2b:4c:16:15:5c: 08:1a:6f:23:e1:00:07:8b:3e:12:a4:47:2f:d2:4e:e4:92:29: c4:56:16:89:20:63:cb:67:c2:18:c2:81:14:01:9e:ab:78:e1: 68:a1:eb:64:af:f7:1c:bb:40:d8:84:4b:16:ab:c5:84:20:b6: c4:1a:0f:55:f8:84:d3:2c:37:a8:e5:c2:b3:bb:f6:09:13:8f: 98:be:5b:67:08:9e:9f:9b:02:53:26:21:3a:47:28:97:77:87: 33:4d:39:86:94:ed:ed:a4:79:77:3d:94:b1:b6:99:bf:9e:92: 94:82:f9:52
-
使用自签署的CA,签署server.scr
openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -extensions v3_req
#输入第一步设置的密码,一直按y就可以了
-
生成个人证书(双向认证时需要,一般用不到)
openssl pkcs12 -export -inkey xxx.key -in xxx.crt -out xxx.pfx
- CA证书使用(Apache https)
- 生成的server.crt、server.key、ca.crt放到服务器端,进行配置(httpd-ssl.conf),重启Apache服务。
-
Apache配置项:
SSLCertificateFile "/usr/local/apache2/conf/server.crt"SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"
SSLCertificateChainFile "/usr/local/apache2/conf/ca.crt"
-
本地客户端导入证书配置
打开ie浏览器,选择设置-internet选项-内容-证书点击证书,选择“受信任的根证书颁发机构”,导入ca.crt文件
导入后打开其他浏览器,访问域名(ip),不再提示风险,证书有效。
-
CA证书制作导入完成!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)