2
0

setup.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. #! /bin/sh
  2. # Primary root: root-cert
  3. # root cert variants: CA:false, key2, DN2
  4. # trust variants: +serverAuth -serverAuth +clientAuth -clientAuth +anyEKU -anyEKU
  5. #
  6. ./mkcert.sh genroot "Root CA" root-key root-cert
  7. ./mkcert.sh genss "Root CA" root-key root-nonca
  8. ./mkcert.sh genroot "Root CA" root-key2 root-cert2
  9. ./mkcert.sh genroot "Root Cert 2" root-key root-name2
  10. #
  11. openssl x509 -in root-cert.pem -trustout \
  12. -addtrust serverAuth -out root+serverAuth.pem
  13. openssl x509 -in root-cert.pem -trustout \
  14. -addreject serverAuth -out root-serverAuth.pem
  15. openssl x509 -in root-cert.pem -trustout \
  16. -addtrust clientAuth -out root+clientAuth.pem
  17. openssl x509 -in root-cert.pem -trustout \
  18. -addreject clientAuth -out root-clientAuth.pem
  19. openssl x509 -in root-cert.pem -trustout \
  20. -addreject anyExtendedKeyUsage -out root-anyEKU.pem
  21. openssl x509 -in root-cert.pem -trustout \
  22. -addtrust anyExtendedKeyUsage -out root+anyEKU.pem
  23. openssl x509 -in root-cert2.pem -trustout \
  24. -addtrust serverAuth -out root2+serverAuth.pem
  25. openssl x509 -in root-cert2.pem -trustout \
  26. -addreject serverAuth -out root2-serverAuth.pem
  27. openssl x509 -in root-cert2.pem -trustout \
  28. -addtrust clientAuth -out root2+clientAuth.pem
  29. openssl x509 -in root-nonca.pem -trustout \
  30. -addtrust serverAuth -out nroot+serverAuth.pem
  31. openssl x509 -in root-nonca.pem -trustout \
  32. -addtrust anyExtendedKeyUsage -out nroot+anyEKU.pem
  33. # Root CA security level variants:
  34. # MD5 self-signature
  35. OPENSSL_SIGALG=md5 \
  36. ./mkcert.sh genroot "Root CA" root-key root-cert-md5
  37. # 768-bit key
  38. OPENSSL_KEYBITS=768 \
  39. ./mkcert.sh genroot "Root CA" root-key-768 root-cert-768
  40. # primary client-EKU root: croot-cert
  41. # trust variants: +serverAuth -serverAuth +clientAuth +anyEKU -anyEKU
  42. #
  43. ./mkcert.sh genroot "Root CA" root-key croot-cert clientAuth
  44. #
  45. openssl x509 -in croot-cert.pem -trustout \
  46. -addtrust serverAuth -out croot+serverAuth.pem
  47. openssl x509 -in croot-cert.pem -trustout \
  48. -addreject serverAuth -out croot-serverAuth.pem
  49. openssl x509 -in croot-cert.pem -trustout \
  50. -addtrust clientAuth -out croot+clientAuth.pem
  51. openssl x509 -in croot-cert.pem -trustout \
  52. -addreject clientAuth -out croot-clientAuth.pem
  53. openssl x509 -in croot-cert.pem -trustout \
  54. -addreject anyExtendedKeyUsage -out croot-anyEKU.pem
  55. openssl x509 -in croot-cert.pem -trustout \
  56. -addtrust anyExtendedKeyUsage -out croot+anyEKU.pem
  57. # primary server-EKU root: sroot-cert
  58. # trust variants: +serverAuth -serverAuth +clientAuth +anyEKU -anyEKU
  59. #
  60. ./mkcert.sh genroot "Root CA" root-key sroot-cert serverAuth
  61. #
  62. openssl x509 -in sroot-cert.pem -trustout \
  63. -addtrust serverAuth -out sroot+serverAuth.pem
  64. openssl x509 -in sroot-cert.pem -trustout \
  65. -addreject serverAuth -out sroot-serverAuth.pem
  66. openssl x509 -in sroot-cert.pem -trustout \
  67. -addtrust clientAuth -out sroot+clientAuth.pem
  68. openssl x509 -in sroot-cert.pem -trustout \
  69. -addreject clientAuth -out sroot-clientAuth.pem
  70. openssl x509 -in sroot-cert.pem -trustout \
  71. -addreject anyExtendedKeyUsage -out sroot-anyEKU.pem
  72. openssl x509 -in sroot-cert.pem -trustout \
  73. -addtrust anyExtendedKeyUsage -out sroot+anyEKU.pem
  74. # Primary intermediate ca: ca-cert
  75. # ca variants: CA:false, key2, DN2, issuer2, expired
  76. # trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth, -anyEKU, +anyEKU
  77. #
  78. ./mkcert.sh genca "CA" ca-key ca-cert root-key root-cert
  79. ./mkcert.sh genee "CA" ca-key ca-nonca root-key root-cert
  80. ./mkcert.sh gen_nonbc_ca "CA" ca-key ca-nonbc root-key root-cert
  81. ./mkcert.sh genca "CA" ca-key2 ca-cert2 root-key root-cert
  82. ./mkcert.sh genca "CA2" ca-key ca-name2 root-key root-cert
  83. ./mkcert.sh genca "CA" ca-key ca-root2 root-key2 root-cert2
  84. DAYS=-1 ./mkcert.sh genca "CA" ca-key ca-expired root-key root-cert
  85. #
  86. openssl x509 -in ca-cert.pem -trustout \
  87. -addtrust serverAuth -out ca+serverAuth.pem
  88. openssl x509 -in ca-cert.pem -trustout \
  89. -addreject serverAuth -out ca-serverAuth.pem
  90. openssl x509 -in ca-cert.pem -trustout \
  91. -addtrust clientAuth -out ca+clientAuth.pem
  92. openssl x509 -in ca-cert.pem -trustout \
  93. -addreject clientAuth -out ca-clientAuth.pem
  94. openssl x509 -in ca-cert.pem -trustout \
  95. -addreject anyExtendedKeyUsage -out ca-anyEKU.pem
  96. openssl x509 -in ca-cert.pem -trustout \
  97. -addtrust anyExtendedKeyUsage -out ca+anyEKU.pem
  98. openssl x509 -in ca-nonca.pem -trustout \
  99. -addtrust serverAuth -out nca+serverAuth.pem
  100. openssl x509 -in ca-nonca.pem -trustout \
  101. -addtrust serverAuth -out nca+anyEKU.pem
  102. # Intermediate CA security variants:
  103. # MD5 issuer signature,
  104. OPENSSL_SIGALG=md5 \
  105. ./mkcert.sh genca "CA" ca-key ca-cert-md5 root-key root-cert
  106. openssl x509 -in ca-cert-md5.pem -trustout \
  107. -addtrust anyExtendedKeyUsage -out ca-cert-md5-any.pem
  108. # Issuer has 768-bit key
  109. ./mkcert.sh genca "CA" ca-key ca-cert-768i root-key-768 root-cert-768
  110. # CA has 768-bit key
  111. OPENSSL_KEYBITS=768 \
  112. ./mkcert.sh genca "CA" ca-key-768 ca-cert-768 root-key root-cert
  113. # client intermediate ca: cca-cert
  114. # trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth
  115. #
  116. ./mkcert.sh genca "CA" ca-key cca-cert root-key root-cert clientAuth
  117. #
  118. openssl x509 -in cca-cert.pem -trustout \
  119. -addtrust serverAuth -out cca+serverAuth.pem
  120. openssl x509 -in cca-cert.pem -trustout \
  121. -addreject serverAuth -out cca-serverAuth.pem
  122. openssl x509 -in cca-cert.pem -trustout \
  123. -addtrust clientAuth -out cca+clientAuth.pem
  124. openssl x509 -in cca-cert.pem -trustout \
  125. -addtrust clientAuth -out cca-clientAuth.pem
  126. openssl x509 -in cca-cert.pem -trustout \
  127. -addreject anyExtendedKeyUsage -out cca-anyEKU.pem
  128. openssl x509 -in cca-cert.pem -trustout \
  129. -addtrust anyExtendedKeyUsage -out cca+anyEKU.pem
  130. # server intermediate ca: sca-cert
  131. # trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth, -anyEKU, +anyEKU
  132. #
  133. ./mkcert.sh genca "CA" ca-key sca-cert root-key root-cert serverAuth
  134. #
  135. openssl x509 -in sca-cert.pem -trustout \
  136. -addtrust serverAuth -out sca+serverAuth.pem
  137. openssl x509 -in sca-cert.pem -trustout \
  138. -addreject serverAuth -out sca-serverAuth.pem
  139. openssl x509 -in sca-cert.pem -trustout \
  140. -addtrust clientAuth -out sca+clientAuth.pem
  141. openssl x509 -in sca-cert.pem -trustout \
  142. -addreject clientAuth -out sca-clientAuth.pem
  143. openssl x509 -in sca-cert.pem -trustout \
  144. -addreject anyExtendedKeyUsage -out sca-anyEKU.pem
  145. openssl x509 -in sca-cert.pem -trustout \
  146. -addtrust anyExtendedKeyUsage -out sca+anyEKU.pem
  147. # Primary leaf cert: ee-cert
  148. # ee variants: expired, issuer-key2, issuer-name2
  149. # trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth
  150. # purpose variants: client
  151. #
  152. ./mkcert.sh genee server.example ee-key ee-cert ca-key ca-cert
  153. ./mkcert.sh genee server.example ee-key ee-expired ca-key ca-cert -days -1
  154. ./mkcert.sh genee server.example ee-key ee-cert2 ca-key2 ca-cert2
  155. ./mkcert.sh genee server.example ee-key ee-name2 ca-key ca-name2
  156. ./mkcert.sh genee -p clientAuth server.example ee-key ee-client ca-key ca-cert
  157. #
  158. openssl x509 -in ee-cert.pem -trustout \
  159. -addtrust serverAuth -out ee+serverAuth.pem
  160. openssl x509 -in ee-cert.pem -trustout \
  161. -addreject serverAuth -out ee-serverAuth.pem
  162. openssl x509 -in ee-client.pem -trustout \
  163. -addtrust clientAuth -out ee+clientAuth.pem
  164. openssl x509 -in ee-client.pem -trustout \
  165. -addreject clientAuth -out ee-clientAuth.pem
  166. # Leaf cert security level variants
  167. # MD5 issuer signature
  168. OPENSSL_SIGALG=md5 \
  169. ./mkcert.sh genee server.example ee-key ee-cert-md5 ca-key ca-cert
  170. # 768-bit issuer key
  171. ./mkcert.sh genee server.example ee-key ee-cert-768i ca-key-768 ca-cert-768
  172. # 768-bit leaf key
  173. OPENSSL_KEYBITS=768 \
  174. ./mkcert.sh genee server.example ee-key-768 ee-cert-768 ca-key ca-cert
  175. # Proxy certificates, off of ee-client
  176. # Start with some good ones
  177. ./mkcert.sh req pc1-key "0.CN = server.example" "1.CN = proxy 1" | \
  178. ./mkcert.sh genpc pc1-key pc1-cert ee-key ee-client \
  179. "language = id-ppl-anyLanguage" "pathlen = 1" "policy = text:AB"
  180. ./mkcert.sh req pc2-key "0.CN = server.example" "1.CN = proxy 1" "2.CN = proxy 2" | \
  181. ./mkcert.sh genpc pc2-key pc2-cert pc1-key pc1-cert \
  182. "language = id-ppl-anyLanguage" "pathlen = 0" "policy = text:AB"
  183. # And now a couple of bad ones
  184. # pc3: incorrect CN
  185. ./mkcert.sh req bad-pc3-key "0.CN = server.example" "1.CN = proxy 3" | \
  186. ./mkcert.sh genpc bad-pc3-key bad-pc3-cert pc1-key pc1-cert \
  187. "language = id-ppl-anyLanguage" "pathlen = 0" "policy = text:AB"
  188. # pc4: incorrect pathlen
  189. ./mkcert.sh req bad-pc4-key "0.CN = server.example" "1.CN = proxy 1" "2.CN = proxy 4" | \
  190. ./mkcert.sh genpc bad-pc4-key bad-pc4-cert pc1-key pc1-cert \
  191. "language = id-ppl-anyLanguage" "pathlen = 1" "policy = text:AB"
  192. # pc5: no policy
  193. ./mkcert.sh req pc5-key "0.CN = server.example" "1.CN = proxy 1" "2.CN = proxy 5" | \
  194. ./mkcert.sh genpc pc5-key pc5-cert pc1-key pc1-cert \
  195. "language = id-ppl-anyLanguage" "pathlen = 0"
  196. # pc6: incorrect CN (made into a component of a multivalue RDN)
  197. ./mkcert.sh req bad-pc6-key "0.CN = server.example" "1.CN = proxy 1" "2.+CN = proxy 6" | \
  198. ./mkcert.sh genpc bad-pc6-key bad-pc6-cert pc1-key pc1-cert \
  199. "language = id-ppl-anyLanguage" "pathlen = 0" "policy = text:AB"
  200. # Name constraints test certificates.
  201. # NC CA1 only permits the host www.good.org and *.good.com email address
  202. # good@good.org and *@good.com and IP addresses 127.0.0.1 and
  203. # 192.168.0.0/16
  204. NC="permitted;DNS:www.good.org, permitted;DNS:good.com,"
  205. NC="$NC permitted;email:good@good.org, permitted;email:good.com,"
  206. NC="$NC permitted;IP:127.0.0.1/255.255.255.255, permitted;IP:192.168.0.0/255.255.0.0"
  207. NC=$NC ./mkcert.sh genca "Test NC CA 1" ncca1-key ncca1-cert root-key root-cert
  208. # NC CA2 allows anything apart from hosts www.bad.org and *.bad.com
  209. # and email addresses bad@bad.org and *@bad.com
  210. NC="excluded;DNS:www.bad.org, excluded;DNS:bad.com,"
  211. NC="$NC excluded;email:bad@bad.org, excluded;email:bad.com, "
  212. NC="$NC excluded;IP:10.0.0.0/255.0.0.0"
  213. NC=$NC ./mkcert.sh genca "Test NC CA 2" ncca2-key ncca2-cert root-key root-cert
  214. # Name constraints subordinate CA. Adds www.good.net (which should be
  215. # disallowed because parent CA doesn't permit it) adds ok.good.com
  216. # (which should be allowed because parent allows *.good.com
  217. # and now excludes bad.ok.good.com (allowed in permitted subtrees
  218. # but explicitly excluded).
  219. NC="permitted;DNS:www.good.net, permitted;DNS:ok.good.com, "
  220. NC="$NC excluded;DNS:bad.ok.good.com"
  221. NC=$NC ./mkcert.sh genca "Test NC sub CA" ncca3-key ncca3-cert \
  222. ncca1-key ncca1-cert
  223. # all subjectAltNames allowed by CA1. Some CNs are not!
  224. ./mkcert.sh req alt1-key "O = Good NC Test Certificate 1" \
  225. "1.CN=www.example.net" "2.CN=Joe Bloggs" | \
  226. ./mkcert.sh geneealt alt1-key alt1-cert ncca1-key ncca1-cert \
  227. "DNS.1 = www.good.org" "DNS.2 = any.good.com" \
  228. "email.1 = good@good.org" "email.2 = any@good.com" \
  229. "IP = 127.0.0.1" "IP = 192.168.0.1"
  230. # all DNS-like CNs allowed by CA1, no DNS SANs.
  231. ./mkcert.sh req goodcn1-key "O = Good NC Test Certificate 1" \
  232. "1.CN=www.good.org" "2.CN=any.good.com" \
  233. "3.CN=not..dns" "4.CN=not@dns" "5.CN=not-.dns" "6.CN=not.dns." | \
  234. ./mkcert.sh geneealt goodcn1-key goodcn1-cert ncca1-key ncca1-cert \
  235. "IP = 127.0.0.1" "IP = 192.168.0.1"
  236. # Some DNS-like CNs not permitted by CA1, no DNS SANs.
  237. ./mkcert.sh req badcn1-key "O = Good NC Test Certificate 1" \
  238. "1.CN=www.good.org" "3.CN=bad.net" | \
  239. ./mkcert.sh geneealt badcn1-key badcn1-cert ncca1-key ncca1-cert \
  240. "IP = 127.0.0.1" "IP = 192.168.0.1"
  241. # no subjectAltNames excluded by CA2.
  242. ./mkcert.sh req alt2-key "O = Good NC Test Certificate 2" | \
  243. ./mkcert.sh geneealt alt2-key alt2-cert ncca2-key ncca2-cert \
  244. "DNS.1 = www.anything.org" "DNS.2 = any.other.com" \
  245. "email.1 = other@bad.org" "email.2 = any@something.com"
  246. # hostname other.good.org which is not allowed by CA1.
  247. ./mkcert.sh req badalt1-key "O = Bad NC Test Certificate 1" | \
  248. ./mkcert.sh geneealt badalt1-key badalt1-cert ncca1-key ncca1-cert \
  249. "DNS.1 = other.good.org" "DNS.2 = any.good.com" \
  250. "email.1 = good@good.org" "email.2 = any@good.com"
  251. # any.bad.com is excluded by CA2.
  252. ./mkcert.sh req badalt2-key 'O = Bad NC Test Certificate 2' | \
  253. ./mkcert.sh geneealt badalt2-key badalt2-cert ncca2-key ncca2-cert \
  254. "DNS.1 = www.good.org" "DNS.2 = any.bad.com" \
  255. "email.1 = good@good.org" "email.2 = any@good.com"
  256. # other@good.org not permitted by CA1
  257. ./mkcert.sh req badalt3-key "O = Bad NC Test Certificate 3" | \
  258. ./mkcert.sh geneealt badalt3-key badalt1-cert ncca1-key ncca1-cert \
  259. "DNS.1 = www.good.org" "DNS.2 = any.good.com" \
  260. "email.1 = other@good.org" "email.2 = any@good.com"
  261. # all subject alt names OK but subject email address not allowed by CA1.
  262. ./mkcert.sh req badalt4-key 'O = Bad NC Test Certificate 4' \
  263. "emailAddress = any@other.com" | \
  264. ./mkcert.sh geneealt badalt4-key badalt4-cert ncca1-key ncca1-cert \
  265. "DNS.1 = www.good.org" "DNS.2 = any.good.com" \
  266. "email.1 = good@good.org" "email.2 = any@good.com"
  267. # IP address not allowed by CA1
  268. ./mkcert.sh req badalt5-key "O = Bad NC Test Certificate 5" | \
  269. ./mkcert.sh geneealt badalt5-key badalt5-cert ncca1-key ncca1-cert \
  270. "DNS.1 = www.good.org" "DNS.2 = any.good.com" \
  271. "email.1 = good@good.org" "email.2 = any@good.com" \
  272. "IP = 127.0.0.2"
  273. # No DNS-ID SANs and subject CN not allowed by CA1.
  274. ./mkcert.sh req badalt6-key "O = Bad NC Test Certificate 6" \
  275. "1.CN=other.good.org" "2.CN=Joe Bloggs" "3.CN=any.good.com" | \
  276. ./mkcert.sh geneealt badalt6-key badalt6-cert ncca1-key ncca1-cert \
  277. "email.1 = good@good.org" "email.2 = any@good.com" \
  278. "IP = 127.0.0.1" "IP = 192.168.0.1"
  279. # No DNS-ID SANS and subject CN not allowed by CA1, BMPSTRING
  280. REQMASK=MASK:0x800 ./mkcert.sh req badalt7-key "O = Bad NC Test Certificate 7" \
  281. "1.CN=other.good.org" "2.CN=Joe Bloggs" "3.CN=any.good.com" | \
  282. ./mkcert.sh geneealt badalt7-key badalt7-cert ncca1-key ncca1-cert \
  283. "email.1 = good@good.org" "email.2 = any@good.com" \
  284. "IP = 127.0.0.1" "IP = 192.168.0.1"
  285. # all subjectAltNames allowed by chain
  286. ./mkcert.sh req alt3-key "O = Good NC Test Certificate 3" \
  287. "1.CN=www.ok.good.com" "2.CN=Joe Bloggs" | \
  288. ./mkcert.sh geneealt alt3-key alt3-cert ncca3-key ncca3-cert \
  289. "DNS.1 = www.ok.good.com" \
  290. "email.1 = good@good.org" "email.2 = any@good.com" \
  291. "IP = 127.0.0.1" "IP = 192.168.0.1"
  292. # www.good.net allowed by parent CA but not parent of parent
  293. ./mkcert.sh req badalt8-key "O = Bad NC Test Certificate 8" \
  294. "1.CN=www.good.com" "2.CN=Joe Bloggs" | \
  295. ./mkcert.sh geneealt badalt8-key badalt8-cert ncca3-key ncca3-cert \
  296. "DNS.1 = www.ok.good.com" "DNS.2 = www.good.net" \
  297. "email.1 = good@good.org" "email.2 = any@good.com" \
  298. "IP = 127.0.0.1" "IP = 192.168.0.1"
  299. # other.good.com not allowed by parent CA but allowed by parent of parent
  300. ./mkcert.sh req badalt9-key "O = Bad NC Test Certificate 9" \
  301. "1.CN=www.good.com" "2.CN=Joe Bloggs" | \
  302. ./mkcert.sh geneealt badalt9-key badalt9-cert ncca3-key ncca3-cert \
  303. "DNS.1 = www.good.com" "DNS.2 = other.good.com" \
  304. "email.1 = good@good.org" "email.2 = any@good.com" \
  305. "IP = 127.0.0.1" "IP = 192.168.0.1"
  306. # www.bad.net excluded by parent CA.
  307. ./mkcert.sh req badalt10-key "O = Bad NC Test Certificate 10" \
  308. "1.CN=www.ok.good.com" "2.CN=Joe Bloggs" | \
  309. ./mkcert.sh geneealt badalt10-key badalt10-cert ncca3-key ncca3-cert \
  310. "DNS.1 = www.ok.good.com" "DNS.2 = bad.ok.good.com" \
  311. "email.1 = good@good.org" "email.2 = any@good.com" \
  312. "IP = 127.0.0.1" "IP = 192.168.0.1"