相关资料
https://en.wikipedia.org/wiki/X.509
https://segmentfault.com/q/1010000007085150
# man x509
In cryptography, X.509 is a standard that defines the format of public key certificates.
X.509是由国际电信联盟(ITU-T)制定的数字证书格式标准。
Certificate filename extensions
There are several commonly used filename extensions for X.509 certificates. Unfortunately, some of these extensions are also used for other data such as private keys.
.pem – Base64 encoded DER certificate, enclosed between "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----".
.cer, .crt, .der – usually in binary DER form.
证书结构
The structure foreseen by the standards is expressed in a formal language, Abstract Syntax Notation One (ASN.1).
The structure of an X.509 v3 digital certificate is as follows:
Certificate
Version Number // 版本号
Serial Number // 序列号(证书唯一标识符)
Signature Algorithm ID
Issuer Name // 签发机构
Validity period // 有效期
Not Before
Not After
Subject name // 证书主体(证书持有者)
Subject Public Key Info // 公钥信息
Public Key Algorithm // 公钥算法
Subject Public Key // 公钥
Issuer Unique Identifier (optional)
Subject Unique Identifier (optional)
Extensions (optional)
...
Certificate Signature Algorithm // 证书签名算法
Certificate Signature // 证书签名
证书签名用来保证证书的完整性。
x509
The x509 command is a multi purpose certificate utility.
It can be used to display certificate information, convert certificates to various forms, sign certificate requests like a "mini CA" or edit certificate trust settings.
# -signkey filename
this option causes the input file to be self signed using the supplied private key.
# -req
by default a certificate is expected on input. With this option a certificate request is expected instead.
# -set_serial n
specifies the serial number to use.
# -CA filename
specifies the CA certificate to be used for signing.
# -CAkey filename
sets the CA private key to sign a certificate with.
# -CAcreateserial
with this option the CA serial number file is created if it does not exist.
# -extfile filename
file containing certificate extensions to use. If not specified then no extensions are added to the certificate.
# -extensions section
the section to add certificate extensions from.
# openssl genrsa -out server.key 2048 // 生成私钥
# openssl req -new -key server.key -out server.csr // 生成证书签名请求
# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt // 生成自签名证书
# openssl x509 -in server.crt -text -noout // 查看证书内容
自签名证书
# openssl genrsa -out server.key 2048
# openssl req -new -key server.key -out server.csr
# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
CA签名证书
// 生成CA证书
# openssl genrsa -out ca.key 2048
# openssl req -new -key ca.key -x509 -days 365 -out ca.crt
// 生成CA签名证书
# openssl genrsa -out server.key 2048
# openssl req -new -key server.key -out server.csr
# openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt
叼茂SEO.bfbikes.com