当前位置:   article > 正文

openssl创建CA并签发证书_openssl生成ca根证书

openssl生成ca根证书

一、创建私有CA根证书

1、创建CA目录

  1. root@DESKTOP-JP3S3AN:/home/wsl/openssl_pro# mkdir -pv /etc/pki/CA/{private,certs,crl,newcerts}
  2. mkdir: created directory '/etc/pki/CA'
  3. mkdir: created directory '/etc/pki/CA/private'
  4. mkdir: created directory '/etc/pki/CA/certs'
  5. mkdir: created directory '/etc/pki/CA/crl'
  6. mkdir: created directory '/etc/pki/CA/newcerts'

2、新建数据库文件并初始化

  1. root@DESKTOP-JP3S3AN:/home/wsl/openssl_pro# touch /etc/pki/CA/{serial,index.txt}
  2. root@DESKTOP-JP3S3AN:/home/wsl/openssl_pro# echo 01 > /etc/pki/CA/serial

3、创建CA私钥

  1. root@DESKTOP-JP3S3AN:/home/wsl/openssl_pro# openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096
  2. Generating RSA private key, 4096 bit long modulus (2 primes)
  3. ........................................++++
  4. ....................................................................................................................................................................................................................................................................++++
  5. e is 65537 (0x010001)

4、创建自签CA根证书

  1. root@DESKTOP-JP3S3AN:/home/wsl/openssl_pro# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3655
  2. You are about to be asked to enter information that will be incorporated
  3. into your certificate request.
  4. What you are about to enter is what is called a Distinguished Name or a DN.
  5. There are quite a few fields but you can leave some blank
  6. For some fields there will be a default value,
  7. If you enter '.', the field will be left blank.
  8. -----
  9. Country Name (2 letter code) [AU]:CN
  10. State or Province Name (full name) [Some-State]:sc
  11. Locality Name (eg, city) []:cd
  12. Organization Name (eg, company) [Internet Widgits Pty Ltd]:tsinghua-eiri
  13. Organizational Unit Name (eg, section) []:xxxx
  14. Common Name (e.g. server FQDN or YOUR name) []:xxxxxx
  15. Email Address []:

二、签发证书

1、创建客户私钥

  1. root@DESKTOP-JP3S3AN:/home/wsl/openssl_pro/client# openssl genrsa -out client0001.key 2048
  2. Generating RSA private key, 2048 bit long modulus (2 primes)
  3. ....+++++
  4. ....+++++
  5. e is 65537 (0x010001)

2、提取客户公钥(备用)

  1. root@DESKTOP-JP3S3AN:/home/wsl/openssl_pro/client# openssl rsa -in client0001.key -pubout -out client0001.pub
  2. writing RSA key

3、生成客户证书请求

  1. root@DESKTOP-JP3S3AN:/home/wsl/openssl_pro/client# openssl req -new -key client0001.key -out client0001.csr -days 3650
  2. Ignoring -days; not generating a certificate
  3. You are about to be asked to enter information that will be incorporated
  4. into your certificate request.
  5. What you are about to enter is what is called a Distinguished Name or a DN.
  6. There are quite a few fields but you can leave some blank
  7. For some fields there will be a default value,
  8. If you enter '.', the field will be left blank.
  9. -----
  10. Country Name (2 letter code) [AU]:CN
  11. State or Province Name (full name) [Some-State]:sc
  12. Locality Name (eg, city) []:cd
  13. Organization Name (eg, company) [Internet Widgits Pty Ltd]:tsinghua-eiri
  14. Organizational Unit Name (eg, section) []:scu
  15. Common Name (e.g. server FQDN or YOUR name) []:jackwang
  16. Email Address []:
  17. Please enter the following 'extra' attributes
  18. to be sent with your certificate request
  19. A challenge password []:
  20. An optional company name []:

4、签发客户请求

  1. root@DESKTOP-JP3S3AN:/home/wsl/openssl_pro/client# openssl ca -in client0001.csr -out /etc/pki/CA/certs/client0001.crt -days 3650
  2. Using configuration from /usr/lib/ssl/openssl.cnf
  3. Check that the request matches the signature
  4. Signature ok
  5. Certificate Details:
  6. Serial Number: 1 (0x1)
  7. Validity
  8. Not Before: Feb 16 09:03:43 2022 GMT
  9. Not After : Feb 14 09:03:43 2032 GMT
  10. Subject:
  11. countryName = CN
  12. stateOrProvinceName = sc
  13. organizationName = tsinghua-eiri
  14. organizationalUnitName = scu
  15. commonName = jackwang
  16. X509v3 extensions:
  17. X509v3 Basic Constraints:
  18. CA:FALSE
  19. Netscape Comment:
  20. OpenSSL Generated Certificate
  21. X509v3 Subject Key Identifier:
  22. D3:38:BA:C9:C5:50:C9:51:14:E0:1A:F2:7C:42:70:50:70:F5:92:81
  23. X509v3 Authority Key Identifier:
  24. keyid:4D:1E:75:EE:8A:DD:69:3E:6C:FE:FB:D2:AA:34:2D:91:48:8D:D7:55
  25. Certificate is to be certified until Feb 14 09:03:43 2032 GMT (3650 days)
  26. Sign the certificate? [y/n]:y
  27. 1 out of 1 certificate requests certified, commit? [y/n]y
  28. Write out database with 1 new entries
  29. Data Base Updated

5、查看证书信息

  1. root@DESKTOP-JP3S3AN:/home/wsl/openssl_pro/client# openssl x509 -in client0001.crt -noout -text
  2. Certificate:
  3. Data:
  4. Version: 3 (0x2)
  5. Serial Number: 1 (0x1)
  6. Signature Algorithm: sha256WithRSAEncryption
  7. Issuer: C = CN, ST = sichuan, L = cd, O = tsinghua-eiri, OU = eiri-iot, CN = root
  8. Validity
  9. Not Before: Feb 16 09:03:43 2022 GMT
  10. Not After : Feb 14 09:03:43 2032 GMT
  11. Subject: C = CN, ST = sc, O = tsinghua-eiri, OU = scu, CN = jackwang
  12. Subject Public Key Info:
  13. Public Key Algorithm: rsaEncryption
  14. RSA Public-Key: (2048 bit)
  15. Modulus:
  16. 00:94:c6:ca:08:6e:08:26:47:39:6d:78:92:d6:a5:
  17. 6f:3e:3b:cc:b7:0d:fa:9c:eb:dd:5f:12:87:40:0f:
  18. ad:c1:21:83:fe:7e:b8:c0:6c:a6:30:d4:e9:03:99:
  19. 4a:03:b5:88:59:11:12:ef:8b:f1:62:f1:f1:ee:d0:
  20. f8:f2:03:35:12:16:b9:44:14:bb:69:89:83:c3:44:
  21. 9d:17:49:32:de:10:43:49:cb:70:2e:89:33:07:57:
  22. f7:ed:da:06:1d:25:45:dc:ad:b9:da:55:30:05:02:
  23. 9f:e1:63:51:8a:cb:39:30:a1:71:86:5a:8e:a3:b3:
  24. c7:71:50:19:74:f8:93:da:1b:9d:0a:b5:de:27:c8:
  25. 55:14:f8:e6:9b:02:2c:ea:75:bf:44:d6:08:49:3c:
  26. 9b:a1:b4:97:1e:a8:88:cf:23:83:eb:03:b6:6d:e6:
  27. be:74:60:f8:88:29:0e:a7:7f:1a:ec:2e:c4:ff:4d:
  28. 2f:f2:6b:53:0e:a9:35:99:d1:0f:cc:ed:ef:41:eb:
  29. a8:b2:27:7a:4c:d1:e9:b7:1c:1b:29:80:a6:b2:b8:
  30. 9f:1f:3a:35:e0:05:05:f6:a9:77:a0:bd:98:51:e2:
  31. 0b:38:9d:ca:3c:48:c2:02:5d:7b:ba:01:cd:5c:48:
  32. 8b:ef:38:03:f2:ed:ee:90:c5:31:b8:dd:40:49:c4:
  33. ce:79
  34. Exponent: 65537 (0x10001)
  35. X509v3 extensions:
  36. X509v3 Basic Constraints:
  37. CA:FALSE
  38. Netscape Comment:
  39. OpenSSL Generated Certificate
  40. X509v3 Subject Key Identifier:
  41. D3:38:BA:C9:C5:50:C9:51:14:E0:8A:F2:7C:45:70:50:70:F5:92:81
  42. X509v3 Authority Key Identifier:
  43. keyid:4D:BE:75:EE:8A:DD:69:3E:6C:FE:FB:D2:AA:34:2D:91:48:8D:D7:55
  44. Signature Algorithm: sha256WithRSAEncryption
  45. 45:1c:29:cd:ad:18:10:6d:9f:50:f6:2c:08:1e:22:3a:90:fd:
  46. 36:36:c3:fa:ea:01:89:34:e3:c5:2b:e0:04:3f:39:c2:62:87:
  47. a7:29:24:9a:40:47:d6:77:b3:49:53:c8:3f:1e:6c:b1:a0:0a:
  48. 26:36:d5:df:f7:f6:97:54:46:75:6b:97:2e:f5:7c:60:2f:96:
  49. af:1c:65:94:58:30:22:3f:b5:31:30:f4:76:10:57:a6:12:51:
  50. 96:f7:ab:88:18:07:44:b7:d4:7a:4e:d7:bd:35:ec:4f:ec:00:
  51. 45:50:57:75:8c:1a:d1:9b:fb:81:9c:f0:d3:13:f6:75:06:1a:
  52. 65:b9:1e:51:8d:ec:d1:52:b2:e2:07:b7:6c:66:b2:66:e9:79:
  53. 3a:fc:eb:11:7d:c8:23:2c:c4:d6:f6:62:c4:a9:c3:87:a7:fa:
  54. 68:a1:1c:d4:28:d6:e1:bd:fa:7e:f0:00:f4:40:6d:45:7f:d7:
  55. 66:32:06:16:22:16:61:84:f4:a1:90:8e:29:2a:c7:07:7f:4f:
  56. 73:09:6b:da:d9:0a:80:bd:da:ba:a2:77:b9:c4:2a:3c:fd:69:
  57. b3:0b:ac:d9:16:12:a3:f1:cd:3d:2f:21:3f:ca:78:d3:f0:9d:
  58. 7b:ac:80:51:0f:c3:2a:9b:80:73:ef:ab:e3:98:d4:c8:e3:e2:
  59. a8:ff:dc:15:c9:00:ef:74:83:ca:68:71:e8:a4:62:dc:6c:3d:
  60. 32:95:aa:ac:f2:d8:a6:ae:3a:23:35:a6:df:95:ed:d6:05:0e:
  61. 03:e6:7b:d0:bf:c5:c2:0b:5f:b9:53:83:be:83:87:af:86:4b:
  62. b1:a7:c5:36:17:29:d8:9f:9f:5e:4d:ff:05:4b:75:0d:fe:e5:
  63. fe:cf:33:cd:8f:37:4a:c3:01:1c:22:11:e0:7c:f4:ae:5c:42:
  64. 5f:b2:69:b3:14:d1:f2:d2:5e:7f:77:53:1f:96:b2:df:e7:cd:
  65. 10:79:5b:2c:d9:1c:af:95:a3:bf:dc:6b:ea:21:c2:4f:d4:5c:
  66. ff:df:3c:8a:6b:ce:9b:0b:c6:3f:2b:02:a6:5a:78:a5:4d:14:
  67. c1:fa:1a:0e:3c:91:bd:de:c0:09:e4:5d:19:1c:c1:b6:3d:aa:
  68. e5:ea:41:fb:ea:67:ed:14:ae:52:76:95:cd:d3:da:6a:9b:ce:
  69. e7:4f:f5:3f:de:4f:e9:7c:48:f9:8d:18:ff:8a:16:a2:1c:3f:
  70. a5:48:d9:81:ad:a4:2f:ae:d4:a9:8b:4a:a5:8d:83:2d:92:b9:
  71. 90:f3:0f:23:f0:62:5c:00:26:cd:b7:72:7c:98:c4:6b:98:bc:
  72. ab:13:a6:3c:d7:c8:34:bf:9c:e2:06:26:ca:62:ec:dc:c9:49:
  73. 4a:58:db:07:c0:80:46:6d

三、目录结构

  1. root@DESKTOP-JP3S3AN:/home/wsl/openssl_pro/client# tree /etc/pki/CA
  2. /etc/pki/CA
  3. ├── cacert.pem
  4. ├── certs
  5. │ └── client0001.crt
  6. ├── crl
  7. ├── index.txt
  8. ├── index.txt.attr
  9. ├── index.txt.old
  10. ├── newcerts
  11. │ └── 01.pem
  12. ├── private
  13. │ └── cakey.pem
  14. ├── serial
  15. └── serial.old
  16. 4 directories, 9 files

qt工程源码配套下载链接:https://x-x.fun/e/UEd02e914dZsC

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/781022
推荐阅读
相关标签
  

闽ICP备14008679号