testss 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/sh
  2. digest='-sha1'
  3. reqcmd="../util/shlib_wrap.sh ../apps/openssl req"
  4. x509cmd="../util/shlib_wrap.sh ../apps/openssl x509 $digest"
  5. verifycmd="../util/shlib_wrap.sh ../apps/openssl verify"
  6. dummycnf="../apps/openssl.cnf"
  7. CAkey="keyCA.ss"
  8. CAcert="certCA.ss"
  9. CAreq="reqCA.ss"
  10. CAconf="CAss.cnf"
  11. CAreq2="req2CA.ss" # temp
  12. Uconf="Uss.cnf"
  13. Ukey="keyU.ss"
  14. Ureq="reqU.ss"
  15. Ucert="certU.ss"
  16. P1conf="P1ss.cnf"
  17. P1key="keyP1.ss"
  18. P1req="reqP1.ss"
  19. P1cert="certP1.ss"
  20. P1intermediate="tmp_intP1.ss"
  21. P2conf="P2ss.cnf"
  22. P2key="keyP2.ss"
  23. P2req="reqP2.ss"
  24. P2cert="certP2.ss"
  25. P2intermediate="tmp_intP2.ss"
  26. echo
  27. echo "make a certificate request using 'req'"
  28. echo "string to make the random number generator think it has entropy" >> ./.rnd
  29. if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
  30. req_new='-newkey dsa:../apps/dsa512.pem'
  31. else
  32. req_new='-new'
  33. fi
  34. $reqcmd -config $CAconf -out $CAreq -keyout $CAkey $req_new #>err.ss
  35. if [ $? != 0 ]; then
  36. echo "error using 'req' to generate a certificate request"
  37. exit 1
  38. fi
  39. echo
  40. echo "convert the certificate request into a self signed certificate using 'x509'"
  41. $x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey -extfile $CAconf -extensions v3_ca >err.ss
  42. if [ $? != 0 ]; then
  43. echo "error using 'x509' to self sign a certificate request"
  44. exit 1
  45. fi
  46. echo
  47. echo "convert a certificate into a certificate request using 'x509'"
  48. $x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss
  49. if [ $? != 0 ]; then
  50. echo "error using 'x509' convert a certificate to a certificate request"
  51. exit 1
  52. fi
  53. $reqcmd -config $dummycnf -verify -in $CAreq -noout
  54. if [ $? != 0 ]; then
  55. echo first generated request is invalid
  56. exit 1
  57. fi
  58. $reqcmd -config $dummycnf -verify -in $CAreq2 -noout
  59. if [ $? != 0 ]; then
  60. echo second generated request is invalid
  61. exit 1
  62. fi
  63. $verifycmd -CAfile $CAcert $CAcert
  64. if [ $? != 0 ]; then
  65. echo first generated cert is invalid
  66. exit 1
  67. fi
  68. echo
  69. echo "make a user certificate request using 'req'"
  70. $reqcmd -config $Uconf -out $Ureq -keyout $Ukey $req_new >err.ss
  71. if [ $? != 0 ]; then
  72. echo "error using 'req' to generate a user certificate request"
  73. exit 1
  74. fi
  75. echo
  76. echo "sign user certificate request with the just created CA via 'x509'"
  77. $x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -extfile $Uconf -extensions v3_ee >err.ss
  78. if [ $? != 0 ]; then
  79. echo "error using 'x509' to sign a user certificate request"
  80. exit 1
  81. fi
  82. $verifycmd -CAfile $CAcert $Ucert
  83. echo
  84. echo "Certificate details"
  85. $x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert
  86. echo
  87. echo "make a proxy certificate request using 'req'"
  88. $reqcmd -config $P1conf -out $P1req -keyout $P1key $req_new >err.ss
  89. if [ $? != 0 ]; then
  90. echo "error using 'req' to generate a proxy certificate request"
  91. exit 1
  92. fi
  93. echo
  94. echo "sign proxy certificate request with the just created user certificate via 'x509'"
  95. $x509cmd -CAcreateserial -in $P1req -days 30 -req -out $P1cert -CA $Ucert -CAkey $Ukey -extfile $P1conf -extensions v3_proxy >err.ss
  96. if [ $? != 0 ]; then
  97. echo "error using 'x509' to sign a proxy certificate request"
  98. exit 1
  99. fi
  100. cat $Ucert > $P1intermediate
  101. $verifycmd -CAfile $CAcert -untrusted $P1intermediate $P1cert
  102. echo
  103. echo "Certificate details"
  104. $x509cmd -subject -issuer -startdate -enddate -noout -in $P1cert
  105. echo
  106. echo "make another proxy certificate request using 'req'"
  107. $reqcmd -config $P2conf -out $P2req -keyout $P2key $req_new >err.ss
  108. if [ $? != 0 ]; then
  109. echo "error using 'req' to generate another proxy certificate request"
  110. exit 1
  111. fi
  112. echo
  113. echo "sign second proxy certificate request with the first proxy certificate via 'x509'"
  114. $x509cmd -CAcreateserial -in $P2req -days 30 -req -out $P2cert -CA $P1cert -CAkey $P1key -extfile $P2conf -extensions v3_proxy >err.ss
  115. if [ $? != 0 ]; then
  116. echo "error using 'x509' to sign a second proxy certificate request"
  117. exit 1
  118. fi
  119. cat $Ucert $P1cert > $P2intermediate
  120. $verifycmd -CAfile $CAcert -untrusted $P2intermediate $P2cert
  121. echo
  122. echo "Certificate details"
  123. $x509cmd -subject -issuer -startdate -enddate -noout -in $P2cert
  124. echo
  125. echo The generated CA certificate is $CAcert
  126. echo The generated CA private key is $CAkey
  127. echo The generated user certificate is $Ucert
  128. echo The generated user private key is $Ukey
  129. echo The first generated proxy certificate is $P1cert
  130. echo The first generated proxy private key is $P1key
  131. echo The second generated proxy certificate is $P2cert
  132. echo The second generated proxy private key is $P2key
  133. /bin/rm err.ss
  134. #/bin/rm $P1intermediate
  135. #/bin/rm $P2intermediate
  136. exit 0