testss 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/sh
  2. digest='-md5'
  3. reqcmd="../apps/openssl req"
  4. x509cmd="../apps/openssl x509 $digest"
  5. verifycmd="../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. echo
  17. echo "make a certificate request using 'req'"
  18. echo "string to make the random number generator think it has entropy" >> ./.rnd
  19. if ../apps/openssl no-rsa; then
  20. req_new='-newkey dsa:../apps/dsa512.pem'
  21. else
  22. req_new='-new'
  23. fi
  24. $reqcmd -config $CAconf -out $CAreq -keyout $CAkey $req_new #>err.ss
  25. if [ $? != 0 ]; then
  26. echo "error using 'req' to generate a certificate request"
  27. exit 1
  28. fi
  29. echo
  30. echo "convert the certificate request into a self signed certificate using 'x509'"
  31. $x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey >err.ss
  32. if [ $? != 0 ]; then
  33. echo "error using 'x509' to self sign a certificate request"
  34. exit 1
  35. fi
  36. echo
  37. echo "convert a certificate into a certificate request using 'x509'"
  38. $x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss
  39. if [ $? != 0 ]; then
  40. echo "error using 'x509' convert a certificate to a certificate request"
  41. exit 1
  42. fi
  43. $reqcmd -config $dummycnf -verify -in $CAreq -noout
  44. if [ $? != 0 ]; then
  45. echo first generated request is invalid
  46. exit 1
  47. fi
  48. $reqcmd -config $dummycnf -verify -in $CAreq2 -noout
  49. if [ $? != 0 ]; then
  50. echo second generated request is invalid
  51. exit 1
  52. fi
  53. $verifycmd -CAfile $CAcert $CAcert
  54. if [ $? != 0 ]; then
  55. echo first generated cert is invalid
  56. exit 1
  57. fi
  58. echo
  59. echo "make another certificate request using 'req'"
  60. $reqcmd -config $Uconf -out $Ureq -keyout $Ukey $req_new >err.ss
  61. if [ $? != 0 ]; then
  62. echo "error using 'req' to generate a certificate request"
  63. exit 1
  64. fi
  65. echo
  66. echo "sign certificate request with the just created CA via 'x509'"
  67. $x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey >err.ss
  68. if [ $? != 0 ]; then
  69. echo "error using 'x509' to sign a certificate request"
  70. exit 1
  71. fi
  72. $verifycmd -CAfile $CAcert $Ucert
  73. echo
  74. echo "Certificate details"
  75. $x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert
  76. echo
  77. echo The generated CA certificate is $CAcert
  78. echo The generated CA private key is $CAkey
  79. echo The generated user certificate is $Ucert
  80. echo The generated user private key is $Ukey
  81. /bin/rm err.ss
  82. exit 0