Sign server and client certificates
Sign server and client certificates
秋风醉了 发表于2年前
Sign server and client certificates
  • 发表于 2年前
  • 阅读 60
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   

摘要: Sign server and client certificates

Sign server and client certificates

We will be signing certificates using our intermediate CA. You can use these signed certificates in a variety of situations, such as to secure connections to a web server or to authenticate clients connecting to a service.

Note

The steps below are from your perspective as the certificate authority. A third-party, however, can instead create their own private key and certificate signing request (CSR) without revealing their private key to you. They give you their CSR, and you give back a signed certificate. In that scenario, skip the genrsa and req commands.


Create a key

Our root and intermediate pairs are 4096 bits. Server and client certificates normally expire after one year, so we can safely use 2048 bits instead.

Note

Although 4096 bits is slightly more secure than 2048 bits, it slows down TLS handshakes and significantly increases processor load during handshakes. For this reason, most websites use 2048-bit pairs.

If you’re creating a cryptographic pair for use with a web server (eg, Apache), you’ll need to enter this password every time you restart the web server. You may want to omit the -aes256 option to create a key without a password.

➜  CA  openssl genrsa -aes256 -out intermediate/private/www.example.com.key.pem 2048
Generating RSA private key, 2048 bit long modulus
...+++
................................................+++
e is 65537 (0x10001)
Enter pass phrase for intermediate/private/www.example.com.key.pem:
Verifying - Enter pass phrase for intermediate/private/www.example.com.key.pem:
➜  CA  chmod 400 intermediate/private/www.example.com.key.pem


Create a certificate

Use the private key to create a certificate signing request (CSR). The CSR details don’t need to match the intermediate CA. For server certificates, the Common Name must be a fully qualified domain name (eg, www.example.com), whereas for client certificates it can be any unique identifier (eg, an e-mail address). Note that the Common Name cannot be the same as either your root or intermediate certificate.

➜  CA  openssl req -config intermediate/openssl.cnf -key intermediate/private/www.example.com.key.pem -new -sha256 -out intermediate/csr/www.example.com.csr.pem
Enter pass phrase for intermediate/private/www.example.com.key.pem:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [CN]:CN
State or Province Name [Beijing]:Beijing
Locality Name []:Haidian
Organization Name [Usoft Ltd]:Usoft Ltd
Organizational Unit Name []:Usoft Ltd gRPC services
Common Name []:www.example.com
Email Address []:345@qq.com

To create a certificate, use the intermediate CA to sign the CSR. If the certificate is going to be used on a server, use the server_cert extension. If the certificate is going to be used for user authentication, use the usr_cert extension. Certificates are usually given a validity of one year, though a CA will typically give a few days extra for convenience.

➜  CA  openssl ca -config intermediate/openssl.cnf -extensions server_cert -days 375 -notext -md sha256 -in intermediate/csr/www.example.com.csr.pem -out intermediate/certs/www.example.com.cert.pem
Using configuration from intermediate/openssl.cnf
Enter pass phrase for /Users/xinxingegeya/CA/intermediate/private/intermediate.key.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 4096 (0x1000)
        Validity
            Not Before: Jan  3 07:45:47 2016 GMT
            Not After : Jan 12 07:45:47 2017 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = Beijing
            localityName              = Haidian
            organizationName          = Usoft Ltd
            organizationalUnitName    = Usoft Ltd gRPC services
            commonName                = www.example.com
            emailAddress              = 345@qq.com
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Cert Type:
                SSL Server
            Netscape Comment:
                OpenSSL Generated Server Certificate
            X509v3 Subject Key Identifier:
                98:F0:98:CC:DF:DA:FF:F5:2B:FE:B0:95:6F:E8:1F:FA:55:53:A0:45
            X509v3 Authority Key Identifier:
                keyid:1A:29:51:6C:66:90:9D:57:8E:41:5E:19:2A:74:E1:D9:B0:8E:9D:8B
                DirName:/C=CN/ST=Beijing/L=Beijing/O=Usoft Ltd/OU=dev/CN=usoft.com/emailAddress=123@qq.com
                serial:10:01

            X509v3 Key Usage: critical
                Digital Signature, Key Encipherment
            X509v3 Extended Key Usage:
                TLS Web Server Authentication
Certificate is to be certified until Jan 12 07:45:47 2017 GMT (375 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

The intermediate/index.txt file should contain a line referring to this new certificate.

V       170112074547Z           1000    unknown /C=CN/ST=Beijing/L=Haidian/O=Usoft Ltd/OU=Usoft Ltd gRPC services/CN=www.example.com/emailAddress=345@qq.com


Verify the certificate

➜  CA  openssl x509 -noout -text -in intermediate/certs/www.example.com.cert.pem

The output will also show the X509v3 extensions. When creating the certificate, you used either the server_cert or usr_cert extension. The options from the corresponding configuration section will be reflected in the output.

Use the CA certificate chain file we created earlier (ca-chain.cert.pem) to verify that the new certificate has a valid chain of trust.

➜  CA  openssl verify -CAfile intermediate/certs/ca-chain.cert.pem intermediate/certs/www.example.com.cert.pem
intermediate/certs/www.example.com.cert.pem: OK


Deploy the certificate

You can now either deploy your new certificate to a server, or distribute the certificate to a client. When deploying to a server application (eg, Apache), you need to make the following files available:

  • ca-chain.cert.pem

  • www.example.com.key.pem

  • www.example.com.cert.pem

If you’re signing a CSR from a third-party, you don’t have access to their private key so you only need to give them back the chain file (ca-chain.cert.pem) and the certificate (www.example.com.cert.pem).

==========END==========

共有 人打赏支持
粉丝 215
博文 610
码字总数 434752
×
秋风醉了
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: