ocsp-stapling2.test 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. #!/bin/bash
  2. # ocsp-stapling.test
  3. ./examples/client/client -v 3 2>&1 | grep -- 'Bad SSL version'
  4. if [ $? -eq 0 ]; then
  5. echo "TLS 1.2 or lower required"
  6. echo "Skipped"
  7. exit 0
  8. fi
  9. WORKSPACE=`pwd`
  10. CERT_DIR="certs/ocsp"
  11. resume_port=0
  12. ready_file1=`pwd`/wolf_ocsp_s2_readyF1$$
  13. ready_file2=`pwd`/wolf_ocsp_s2_readyF2$$
  14. ready_file3=`pwd`/wolf_ocsp_s2_readyF3$$
  15. ready_file4=`pwd`/wolf_ocsp_s2_readyF4$$
  16. ready_file5=`pwd`/wolf_ocsp_s2_readyF5$$
  17. printf '%s\n' "ready file 1: $ready_file1"
  18. printf '%s\n' "ready file 2: $ready_file2"
  19. printf '%s\n' "ready file 3: $ready_file3"
  20. printf '%s\n' "ready file 4: $ready_file4"
  21. printf '%s\n' "ready file 5: $ready_file5"
  22. test_cnf="ocsp_s2.cnf"
  23. copy_originals() {
  24. cd $CERT_DIR
  25. cp intermediate1-ca-cert.pem bak-intermediate1-ca-cert.pem
  26. cp intermediate2-ca-cert.pem bak-intermediate2-ca-cert.pem
  27. cp intermediate3-ca-cert.pem bak-intermediate3-ca-cert.pem
  28. cp ocsp-responder-cert.pem bak-ocsp-responder-cert.pem
  29. cp root-ca-cert.pem bak-root-ca-cert.pem
  30. cp server1-cert.pem bak-server1-cert.pem
  31. cp server2-cert.pem bak-server2-cert.pem
  32. cp server3-cert.pem bak-server3-cert.pem
  33. cp server4-cert.pem bak-server4-cert.pem
  34. cp server5-cert.pem bak-server5-cert.pem
  35. cd $WORKSPACE
  36. }
  37. restore_originals() {
  38. cd $CERT_DIR
  39. mv bak-intermediate1-ca-cert.pem intermediate1-ca-cert.pem
  40. mv bak-intermediate2-ca-cert.pem intermediate2-ca-cert.pem
  41. mv bak-intermediate3-ca-cert.pem intermediate3-ca-cert.pem
  42. mv bak-ocsp-responder-cert.pem ocsp-responder-cert.pem
  43. mv bak-root-ca-cert.pem root-ca-cert.pem
  44. mv bak-server1-cert.pem server1-cert.pem
  45. mv bak-server2-cert.pem server2-cert.pem
  46. mv bak-server3-cert.pem server3-cert.pem
  47. mv bak-server4-cert.pem server4-cert.pem
  48. mv bak-server5-cert.pem server5-cert.pem
  49. }
  50. wait_for_readyFile(){
  51. counter=0
  52. while [ ! -s $1 -a "$counter" -lt 20 ]; do
  53. echo -e "waiting for ready file..."
  54. sleep 0.1
  55. counter=$((counter+ 1))
  56. done
  57. if test -e $1; then
  58. echo -e "found ready file, starting client..."
  59. else
  60. echo -e "NO ready file ending test..."
  61. exit 1
  62. fi
  63. }
  64. remove_single_rF(){
  65. if test -e $1; then
  66. printf '%s\n' "removing ready file: $1"
  67. rm $1
  68. fi
  69. }
  70. #create a configure file for cert generation with the port 0 solution
  71. create_new_cnf() {
  72. copy_originals
  73. printf '%s\n' "Random Port Selected: $RPORTSELECTED"
  74. printf '%s\n' "#" > $test_cnf
  75. printf '%s\n' "# openssl configuration file for OCSP certificates" >> $test_cnf
  76. printf '%s\n' "#" >> $test_cnf
  77. printf '%s\n' "" >> $test_cnf
  78. printf '%s\n' "# Extensions to add to a certificate request (intermediate1-ca)" >> $test_cnf
  79. printf '%s\n' "[ v3_req1 ]" >> $test_cnf
  80. printf '%s\n' "basicConstraints = CA:false" >> $test_cnf
  81. printf '%s\n' "subjectKeyIdentifier = hash" >> $test_cnf
  82. printf '%s\n' "authorityKeyIdentifier = keyid:always,issuer:always" >> $test_cnf
  83. printf '%s\n' "keyUsage = nonRepudiation, digitalSignature, keyEncipherment" >> $test_cnf
  84. printf '%s\n' "authorityInfoAccess = OCSP;URI:http://127.0.0.1:$1" >> $test_cnf
  85. printf '%s\n' "" >> $test_cnf
  86. printf '%s\n' "# Extensions to add to a certificate request (intermediate2-ca)" >> $test_cnf
  87. printf '%s\n' "[ v3_req2 ]" >> $test_cnf
  88. printf '%s\n' "basicConstraints = CA:false" >> $test_cnf
  89. printf '%s\n' "subjectKeyIdentifier = hash" >> $test_cnf
  90. printf '%s\n' "authorityKeyIdentifier = keyid:always,issuer:always" >> $test_cnf
  91. printf '%s\n' "keyUsage = nonRepudiation, digitalSignature, keyEncipherment" >> $test_cnf
  92. printf '%s\n' "authorityInfoAccess = OCSP;URI:http://127.0.0.1:$2" >> $test_cnf
  93. printf '%s\n' "" >> $test_cnf
  94. printf '%s\n' "# Extensions to add to a certificate request (intermediate3-ca)" >> $test_cnf
  95. printf '%s\n' "[ v3_req3 ]" >> $test_cnf
  96. printf '%s\n' "basicConstraints = CA:false" >> $test_cnf
  97. printf '%s\n' "subjectKeyIdentifier = hash" >> $test_cnf
  98. printf '%s\n' "authorityKeyIdentifier = keyid:always,issuer:always" >> $test_cnf
  99. printf '%s\n' "keyUsage = nonRepudiation, digitalSignature, keyEncipherment" >> $test_cnf
  100. printf '%s\n' "authorityInfoAccess = OCSP;URI:http://127.0.0.1:$3" >> $test_cnf
  101. printf '%s\n' "" >> $test_cnf
  102. printf '%s\n' "# Extensions for a typical CA" >> $test_cnf
  103. printf '%s\n' "[ v3_ca ]" >> $test_cnf
  104. printf '%s\n' "basicConstraints = CA:true" >> $test_cnf
  105. printf '%s\n' "subjectKeyIdentifier = hash" >> $test_cnf
  106. printf '%s\n' "authorityKeyIdentifier = keyid:always,issuer:always" >> $test_cnf
  107. printf '%s\n' "keyUsage = keyCertSign, cRLSign" >> $test_cnf
  108. printf '%s\n' "authorityInfoAccess = OCSP;URI:http://127.0.0.1:$4" >> $test_cnf
  109. printf '%s\n' "" >> $test_cnf
  110. printf '%s\n' "# OCSP extensions." >> $test_cnf
  111. printf '%s\n' "[ v3_ocsp ]" >> $test_cnf
  112. printf '%s\n' "basicConstraints = CA:false" >> $test_cnf
  113. printf '%s\n' "subjectKeyIdentifier = hash" >> $test_cnf
  114. printf '%s\n' "authorityKeyIdentifier = keyid:always,issuer:always" >> $test_cnf
  115. printf '%s\n' "extendedKeyUsage = OCSPSigning" >> $test_cnf
  116. mv $test_cnf $CERT_DIR/$test_cnf
  117. cd $CERT_DIR
  118. CURR_LOC=`pwd`
  119. printf '%s\n' "echo now in $CURR_LOC"
  120. ./renewcerts-for-test.sh $test_cnf
  121. cd $WORKSPACE
  122. }
  123. remove_ready_file(){
  124. if test -e $ready_file1; then
  125. printf '%s\n' "removing ready file: $ready_file1"
  126. rm $ready_file1
  127. fi
  128. if test -e $ready_file2; then
  129. printf '%s\n' "removing ready file: $ready_file2"
  130. rm $ready_file2
  131. fi
  132. if test -e $ready_file3; then
  133. printf '%s\n' "removing ready file: $ready_file3"
  134. rm $ready_file3
  135. fi
  136. if test -e $ready_file4; then
  137. printf '%s\n' "removing ready file: $ready_file4"
  138. rm $ready_file4
  139. fi
  140. if test -e $ready_file5; then
  141. printf '%s\n' "removing ready file: $ready_file5"
  142. rm $ready_file5
  143. fi
  144. }
  145. cleanup()
  146. {
  147. for i in $(jobs -pr)
  148. do
  149. kill -s HUP "$i"
  150. done
  151. remove_ready_file
  152. rm $CERT_DIR/$test_cnf
  153. restore_originals
  154. }
  155. trap cleanup EXIT INT TERM HUP
  156. [ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1
  157. # check if supported key size is large enough to handle 4096 bit RSA
  158. size=`./examples/client/client -? | grep "Max RSA key"`
  159. size=`echo ${size//[^0-9]/}`
  160. if [ ! -z "$size" ]; then
  161. printf 'check on max key size of %d ...' $size
  162. if [ $size -lt 4096 ]; then
  163. printf '%s\n' "4096 bit RSA keys not supported"
  164. exit 0
  165. fi
  166. printf 'OK\n'
  167. fi
  168. #get four unique ports
  169. # 1:
  170. ./examples/server/server -R $ready_file1 -p $resume_port &
  171. wait_for_readyFile $ready_file1
  172. if [ ! -f $ready_file1 ]; then
  173. printf '%s\n' "Failed to create ready file1: \"$ready_file1\""
  174. exit 1
  175. fi
  176. # 2:
  177. ./examples/server/server -R $ready_file2 -p $resume_port &
  178. wait_for_readyFile $ready_file2
  179. if [ ! -f $ready_file2 ]; then
  180. printf '%s\n' "Failed to create ready file2: \"$ready_file2\""
  181. exit 1
  182. fi
  183. # 3:
  184. ./examples/server/server -R $ready_file3 -p $resume_port &
  185. wait_for_readyFile $ready_file3
  186. if [ ! -f $ready_file3 ]; then
  187. printf '%s\n' "Failed to create ready file3: \"$ready_file3\""
  188. exit 1
  189. fi
  190. # 4:
  191. ./examples/server/server -R $ready_file4 -p $resume_port &
  192. wait_for_readyFile $ready_file4
  193. if [ ! -f $ready_file4 ]; then
  194. printf '%s\n' "Failed to create ready file4: \"$ready_file4\""
  195. exit 1
  196. else
  197. RPORTSELECTED1=`cat $ready_file1`
  198. RPORTSELECTED2=`cat $ready_file2`
  199. RPORTSELECTED3=`cat $ready_file3`
  200. RPORTSELECTED4=`cat $ready_file4`
  201. printf '%s\n' "------------- PORTS ---------------"
  202. printf '%s' "Random ports selected: $RPORTSELECTED1 $RPORTSELECTED2"
  203. printf '%s\n' " $RPORTSELECTED3 $RPORTSELECTED4"
  204. printf '%s\n' "-----------------------------------"
  205. # Use client connections to cleanly shutdown the servers
  206. ./examples/client/client -p $RPORTSELECTED1
  207. ./examples/client/client -p $RPORTSELECTED2
  208. ./examples/client/client -p $RPORTSELECTED3
  209. ./examples/client/client -p $RPORTSELECTED4
  210. create_new_cnf $RPORTSELECTED1 $RPORTSELECTED2 $RPORTSELECTED3 \
  211. $RPORTSELECTED4
  212. fi
  213. sleep 1
  214. # setup ocsp responders
  215. # OLD: ./certs/ocsp/ocspd-root-ca-and-intermediate-cas.sh &
  216. # NEW: openssl isn't being cleaned up, invoke directly in script for cleanup
  217. # purposes!
  218. openssl ocsp -port $RPORTSELECTED1 -nmin 1 \
  219. -index certs/ocsp/index-ca-and-intermediate-cas.txt \
  220. -rsigner certs/ocsp/ocsp-responder-cert.pem \
  221. -rkey certs/ocsp/ocsp-responder-key.pem \
  222. -CA certs/ocsp/root-ca-cert.pem \
  223. $@ \
  224. &
  225. # OLD: ./certs/ocsp/ocspd-intermediate2-ca-issued-certs.sh &
  226. # NEW: openssl isn't being cleaned up, invoke directly in script for cleanup
  227. # purposes!
  228. openssl ocsp -port $RPORTSELECTED2 -nmin 1 \
  229. -index certs/ocsp/index-intermediate2-ca-issued-certs.txt \
  230. -rsigner certs/ocsp/ocsp-responder-cert.pem \
  231. -rkey certs/ocsp/ocsp-responder-key.pem \
  232. -CA certs/ocsp/intermediate2-ca-cert.pem \
  233. $@ \
  234. &
  235. # OLD: ./certs/ocsp/ocspd-intermediate3-ca-issued-certs.sh &
  236. # NEW: openssl isn't being cleaned up, invoke directly in script for cleanup
  237. # purposes!
  238. openssl ocsp -port $RPORTSELECTED3 -nmin 1 \
  239. -index certs/ocsp/index-intermediate3-ca-issued-certs.txt \
  240. -rsigner certs/ocsp/ocsp-responder-cert.pem \
  241. -rkey certs/ocsp/ocsp-responder-key.pem \
  242. -CA certs/ocsp/intermediate3-ca-cert.pem \
  243. $@ \
  244. &
  245. sleep 1
  246. # "jobs" is not portable for posix. Must use bash interpreter!
  247. [ $(jobs -r | wc -l) -ne 3 ] && printf '\n\n%s\n' "Setup ocsp responder failed, skipping" && exit 0
  248. printf '\n\n%s\n\n' "All OCSP responders started successfully!"
  249. printf '%s\n\n' "------------- TEST CASE 1 SHOULD PASS ------------------------"
  250. # client test against our own server - GOOD CERTS
  251. ./examples/server/server -c certs/ocsp/server3-cert.pem \
  252. -k certs/ocsp/server3-key.pem -R $ready_file5 \
  253. -p $resume_port &
  254. wait_for_readyFile $ready_file5
  255. CLI_PORT=`cat $ready_file5`
  256. ./examples/client/client -C -A certs/ocsp/root-ca-cert.pem -W 2 -v 3 \
  257. -p $CLI_PORT
  258. RESULT=$?
  259. [ $RESULT -ne 0 ] && printf '\n\n%s\n' "Client connection 1 failed" && exit 1
  260. printf '%s\n\n' "Test PASSED!"
  261. printf '%s\n\n' "TEST CASE 2 DISABLED PENDING REVIEW"
  262. #printf '%s\n\n' "------------- TEST CASE 2 SHOULD PASS ------------------------"
  263. #remove_single_rF $ready_file5
  264. #./examples/server/server -c certs/ocsp/server3-cert.pem \
  265. # -k certs/ocsp/server3-key.pem -R $ready_file5 \
  266. # -p $resume_port &
  267. #wait_for_readyFile $ready_file5
  268. #CLI_PORT=`cat $ready_file5`
  269. #./examples/client/client -C -A certs/ocsp/root-ca-cert.pem -W 3 -v 3 \
  270. # -p $CLI_PORT
  271. #RESULT=$?
  272. #[ $RESULT -ne 0 ] && printf '\n\n%s\n' "Client connection 2 failed" && exit 1
  273. #printf '%s\n\n' "Test PASSED!"
  274. printf '%s\n\n' "------------- TEST CASE 3 SHOULD REVOKE ----------------------"
  275. # client test against our own server - REVOKED SERVER CERT
  276. remove_single_rF $ready_file5
  277. ./examples/server/server -c certs/ocsp/server4-cert.pem \
  278. -k certs/ocsp/server4-key.pem -R $ready_file5 \
  279. -p $resume_port &
  280. wait_for_readyFile $ready_file5
  281. CLI_PORT=`cat $ready_file5`
  282. ./examples/client/client -C -A certs/ocsp/root-ca-cert.pem -W 2 -v 3 \
  283. -p $CLI_PORT
  284. RESULT=$?
  285. [ $RESULT -ne 1 ] && printf '\n\n%s\n' "Client connection suceeded $RESULT" && exit 1
  286. printf '%s\n\n' "Test successfully REVOKED!"
  287. printf '%s\n\n' "------------- TEST CASE 4 SHOULD REVOKE ----------------------"
  288. remove_single_rF $ready_file5
  289. ./examples/server/server -c certs/ocsp/server4-cert.pem \
  290. -k certs/ocsp/server4-key.pem -R $ready_file5 \
  291. -p $resume_port &
  292. sleep 1
  293. CLI_PORT=`cat $ready_file5`
  294. ./examples/client/client -C -A certs/ocsp/root-ca-cert.pem -W 3 -v 3 \
  295. -p $CLI_PORT
  296. RESULT=$?
  297. [ $RESULT -ne 1 ] && printf '\n\n%s\n' "Client connection suceeded $RESULT" && exit 1
  298. printf '%s\n\n' "Test successfully REVOKED!"
  299. printf '%s\n\n' "------------- TEST CASE 5 SHOULD PASS ------------------------"
  300. # client test against our own server - REVOKED INTERMEDIATE CERT
  301. remove_single_rF $ready_file5
  302. ./examples/server/server -c certs/ocsp/server5-cert.pem \
  303. -k certs/ocsp/server5-key.pem -R $ready_file5 \
  304. -p $resume_port &
  305. wait_for_readyFile $ready_file5
  306. CLI_PORT=`cat $ready_file5`
  307. ./examples/client/client -C -A certs/ocsp/root-ca-cert.pem -W 2 -v 3 \
  308. -p $CLI_PORT
  309. RESULT=$?
  310. [ $RESULT -ne 0 ] && printf '\n\n%s\n' "Client connection 3 failed $RESULT" && exit 1
  311. printf '%s\n\n' "Test PASSED!"
  312. printf '%s\n\n' "------------- TEST CASE 6 SHOULD REVOKE ----------------------"
  313. remove_single_rF $ready_file5
  314. ./examples/server/server -c certs/ocsp/server5-cert.pem \
  315. -k certs/ocsp/server5-key.pem -R $ready_file5 \
  316. -p $resume_port &
  317. wait_for_readyFile $ready_file5
  318. CLI_PORT=`cat $ready_file5`
  319. ./examples/client/client -C -A certs/ocsp/root-ca-cert.pem -W 3 -v 3 \
  320. -p $CLI_PORT
  321. RESULT=$?
  322. [ $RESULT -ne 1 ] && printf '\n\n%s\n' "Client connection suceeded $RESULT" && exit 1
  323. printf '%s\n\n' "Test successfully REVOKED!"
  324. printf '%s\n\n' "------------- TEST CASE 7 LOAD CERT IN SSL -------------------"
  325. remove_single_rF $ready_file5
  326. ./examples/server/server -c certs/ocsp/server1-cert.pem \
  327. -k certs/ocsp/server1-key.pem -R $ready_file5 \
  328. -p $resume_port -H loadSSL &
  329. wolf_pid=$!
  330. wait_for_readyFile $ready_file5
  331. CLI_PORT=`cat $ready_file5`
  332. echo "test connection" | openssl s_client -status -connect 127.0.0.1:$CLI_PORT -cert ./certs/client-cert.pem -key ./certs/client-key.pem -CAfile ./certs/ocsp/root-ca-cert.pem
  333. RESULT=$?
  334. [ $RESULT -ne 0 ] && printf '\n\n%s\n' "Client connection failed $RESULT" && exit 1
  335. wait $wolf_pid
  336. if [ $? -ne 0 ]; then
  337. printf '%s\n' "Unexpected server result"
  338. exit 1
  339. fi
  340. printf '%s\n\n' "Test successful"
  341. printf '%s\n\n' "------------- TEST CASE 8 SHOULD REVOKE ----------------------"
  342. remove_single_rF $ready_file5
  343. ./examples/server/server -c certs/ocsp/server4-cert.pem \
  344. -k certs/ocsp/server4-key.pem -R $ready_file5 \
  345. -p $resume_port -H loadSSL &
  346. wolf_pid=$!
  347. sleep 1
  348. CLI_PORT=`cat $ready_file5`
  349. ./examples/client/client -C -A certs/ocsp/root-ca-cert.pem -W 3 -v 3 \
  350. -p $CLI_PORT
  351. RESULT=$?
  352. [ $RESULT -ne 1 ] && printf '\n\n%s\n' "Client connection suceeded $RESULT" && exit 1
  353. wait $wolf_pid
  354. if [ $? -ne 1 ]; then
  355. printf '%s\n' "Unexpected server result"
  356. exit 1
  357. fi
  358. printf '%s\n\n' "Test successfully REVOKED!"
  359. printf '%s\n\n' "------------------- TESTS COMPLETE ---------------------------"
  360. exit 0