CA-HOWTO.txt 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. How to setup your own Certificate Authority
  2. ===========================================
  3. Note: this howto requires the openssl binary, as well as classic
  4. UNIX tools (cat, touch, echo). If you use Windows, please consider
  5. installing Cygwin -- see http://cygwin.com/
  6. 1. Configure OpenSSL
  7. --------------------
  8. First of all, create sslconf.txt in the current directory
  9. (a basic example is provided at the end of this file).
  10. cat > sslconf.txt <<"EOF"
  11. [paste contents here]
  12. EOF
  13. Then you need to create the database and a starting serial number:
  14. touch index
  15. echo "01" > serial
  16. mkdir newcerts
  17. 2. Generate the CA certificate
  18. ------------------------------
  19. openssl req -config sslconf.txt -days 3653 -x509 -newkey rsa:2048 \
  20. -set_serial 0 -text -keyout test-ca.key -out test-ca.crt
  21. 3. Generate the private keys and certificate requests
  22. -----------------------------------------------------
  23. openssl genrsa -out server1.key 2048
  24. openssl genrsa -out server2.key 2048
  25. openssl genrsa -out client1.key 2048
  26. openssl genrsa -out client2.key 2048
  27. openssl req -config sslconf.txt -new -key server1.key -out server1.req
  28. openssl req -config sslconf.txt -new -key server2.key -out server2.req
  29. openssl req -config sslconf.txt -new -key client1.key -out client1.req
  30. openssl req -config sslconf.txt -new -key client2.key -out client2.req
  31. 4. Issue and sign the certificates
  32. ----------------------------------
  33. openssl ca -config sslconf.txt -in server1.req -out server1.crt
  34. openssl ca -config sslconf.txt -in server2.req -out server2.crt
  35. openssl ca -config sslconf.txt -in client1.req -out client1.crt
  36. openssl ca -config sslconf.txt -in client2.req -out client2.crt
  37. 5. To revoke a certificate and update the CRL
  38. ---------------------------------------------
  39. openssl ca -config sslconf.txt -revoke server1.crt
  40. openssl ca -config sslconf.txt -revoke client1.crt
  41. openssl ca -config sslconf.txt -gencrl -out crl.pem
  42. 6. To display a certificate and verify its validity
  43. ---------------------------------------------------
  44. openssl x509 -in server2.crt -text -noout
  45. cat test-ca.crt crl.pem > ca_crl.pem
  46. openssl verify -CAfile ca_crl.pem -crl_check server2.crt
  47. rm ca_crl.pem
  48. 7. To export a certificate into a .pfx file
  49. -------------------------------------------
  50. openssl pkcs12 -export -in client2.crt -inkey client2.key \
  51. -out client2.pfx
  52. ##================================================================
  53. ##============== Example OpenSSL configuration file ==============
  54. ##================================================================
  55. # References:
  56. #
  57. # /etc/ssl/openssl.conf
  58. # http://www.openssl.org/docs/apps/config.html
  59. # http://www.openssl.org/docs/apps/x509v3_config.html
  60. [ ca ]
  61. default_ca = my_ca
  62. [ my_ca ]
  63. certificate = test-ca.crt
  64. private_key = test-ca.key
  65. database = index
  66. serial = serial
  67. new_certs_dir = newcerts
  68. default_crl_days = 60
  69. default_days = 730
  70. default_md = sha1
  71. policy = my_policy
  72. x509_extensions = v3_usr
  73. [ my_policy ]
  74. countryName = optional
  75. stateOrProvinceName = optional
  76. organizationName = match
  77. organizationalUnitName = optional
  78. commonName = supplied
  79. emailAddress = optional
  80. [ req ]
  81. distinguished_name = my_req_dn
  82. x509_extensions = v3_ca
  83. [ my_req_dn ]
  84. countryName = Country Name..............
  85. countryName_min = 2
  86. countryName_max = 2
  87. stateOrProvinceName = State or Province Name....
  88. localityName = Locality Name.............
  89. 0.organizationName = Organization Name.........
  90. organizationalUnitName = Org. Unit Name............
  91. commonName = Common Name (required)....
  92. commonName_max = 64
  93. emailAddress = Email Address.............
  94. emailAddress_max = 64
  95. [ v3_ca ]
  96. basicConstraints = CA:TRUE
  97. subjectKeyIdentifier = hash
  98. authorityKeyIdentifier = keyid:always,issuer:always
  99. [ v3_usr ]
  100. basicConstraints = CA:FALSE
  101. subjectKeyIdentifier = hash
  102. authorityKeyIdentifier = keyid,issuer