main.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #!/bin/bash
  2. # This file is in the public domain.
  3. set -xeu
  4. # create root CA certificate and key.
  5. openssl req -x509 \
  6. -out rca-signed-cert.pem \
  7. -outform PEM \
  8. -extensions v3_ca \
  9. -days 3650 \
  10. -subj "/C=US/ST=Massachusetts/L=Boston/O=Root/CN=ca.gnu" \
  11. -passout 'pass:masterword'
  12. # private key was written to privkey.pem
  13. mv privkey.pem rca-private-key.pem
  14. # We can skip these with contemporary OpenSSL:
  15. # convert to certificate request:
  16. #openssl x509 -x509toreq \
  17. # -in rca-unsigned-cert.pem \
  18. # -out rca-csr.pem \
  19. # -passin 'pass:masterword' \
  20. # -signkey rca-private-key.pem
  21. # self-sign using:
  22. #openssl x509 -req \
  23. # -in rca-csr.pem \
  24. # -extfile openssl.cnf \
  25. # -extensions v3_ca \
  26. # -signkey rca-private-key.pem \
  27. # -passin 'pass:masterword' \
  28. # -out rca-signed-cert.pem
  29. #rm rca-csr.pem rca-unsigned-cert.pem
  30. # view using:
  31. # openssl x509 -in rca-signed-cert.pem -text -noout
  32. # Setup CA directory structure
  33. rm -rf dir/
  34. mkdir -p dir certdir
  35. echo 1000 > dir/serial.txt
  36. touch dir/index.txt dir/index.txt.attr
  37. # create client of root CA private key
  38. openssl genpkey \
  39. -algorithm RSA \
  40. -pass 'pass:clientword' \
  41. -out client-of-rca-private-key.pem \
  42. -aes-128-cbc \
  43. -pkeyopt \
  44. rsa_keygen_bits:2048
  45. # create CSR
  46. openssl req -new \
  47. -key client-of-rca-private-key.pem \
  48. -keyform PEM \
  49. -passin 'pass:clientword' \
  50. -subj "/C=US/ST=Massachusetts/L=Boston/O=Client/CN=client.ca.gnu" \
  51. -out client-of-rca-csr.pem \
  52. -outform PEM
  53. # Sign CSR as CA
  54. openssl ca \
  55. -in client-of-rca-csr.pem \
  56. -batch \
  57. -out client-of-rca-signed-cert.pem \
  58. -passin 'pass:masterword' \
  59. -config ca.conf
  60. rm client-of-rca-csr.pem
  61. # Setup ICA directory structure
  62. rm -rf idir
  63. mkdir -p idir icertdir
  64. echo 1000 > idir/serial.txt
  65. touch idir/index.txt idir/index.txt.attr
  66. # create ICA private key
  67. openssl genpkey \
  68. -algorithm RSA \
  69. -pass 'pass:icaword' \
  70. -out ica-private-key.pem \
  71. -aes-128-cbc \
  72. -pkeyopt \
  73. rsa_keygen_bits:2048
  74. # create CSR
  75. openssl req -new \
  76. -key ica-private-key.pem \
  77. -keyform PEM \
  78. -passin 'pass:icaword' \
  79. -subj "/C=US/ST=Massachusetts/L=Boston/O=ICA/CN=ica.gnu" \
  80. -out ica-csr.pem \
  81. -outform PEM
  82. # Sign CSR as CA
  83. openssl ca \
  84. -in ica-csr.pem \
  85. -batch \
  86. -extensions v3_intermediate_ca \
  87. -out ica-signed-cert.pem \
  88. -passin 'pass:masterword' \
  89. -config ca.conf
  90. rm ica-csr.pem
  91. # view using:
  92. # openssl x509 -in ica-signed-cert.pem -text -noout
  93. # Create certificate chain
  94. cat ica-signed-cert.pem rca-signed-cert.pem > ica-chain.pem
  95. # create ICA client private key
  96. openssl genpkey \
  97. -algorithm RSA \
  98. -pass 'pass:iclientword' \
  99. -out client-of-ica-private-key.pem \
  100. -aes-128-cbc \
  101. -pkeyopt \
  102. rsa_keygen_bits:2048
  103. # create CSR
  104. openssl req -new \
  105. -key client-of-ica-private-key.pem \
  106. -keyform PEM \
  107. -passin 'pass:iclientword' \
  108. -subj "/C=US/ST=Massachusetts/L=Boston/O=ICA-Client/CN=client.ica.gnu" \
  109. -out client-of-ica-csr.pem \
  110. -outform PEM
  111. # Sign CSR as CA
  112. openssl ca \
  113. -in client-of-ica-csr.pem \
  114. -batch \
  115. -section ICA_default \
  116. -out client-of-ica-signed-cert.pem \
  117. -passin 'pass:icaword' \
  118. -config ca.conf
  119. rm client-of-ica-csr.pem
  120. # create 2nd ICA client private key
  121. openssl genpkey \
  122. -algorithm RSA \
  123. -pass 'pass:iclientword' \
  124. -out client2-of-ica-private-key.pem \
  125. -aes-128-cbc \
  126. -pkeyopt \
  127. rsa_keygen_bits:2048
  128. # create CSR
  129. openssl req -new \
  130. -key client2-of-ica-private-key.pem \
  131. -keyform PEM \
  132. -passin 'pass:iclientword' \
  133. -subj "/C=US/ST=Massachusetts/L=Boston/O=ICA-Client/CN=other.ica.gnu" \
  134. -out client2-of-ica-csr.pem \
  135. -outform PEM
  136. # Sign CSR as CA
  137. openssl ca \
  138. -in client2-of-ica-csr.pem \
  139. -batch \
  140. -section ICA_default \
  141. -out client2-of-ica-signed-cert.pem \
  142. -passin 'pass:icaword' \
  143. -config ca.conf
  144. rm client2-of-ica-csr.pem