X509certutil.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # SPDX-License-Identifier: BSD-3-Clause
  2. source helpers.sh
  3. # We don't need a TPM for this test, so unset the EXIT handler.
  4. trap - EXIT
  5. outfile="test.cert"
  6. daysvalid=10
  7. fail=0
  8. # Generate a new cert and parse it with openssl
  9. tpm2 certifyX509certutil -o $outfile -d $daysvalid
  10. openssl asn1parse -in $outfile -inform DER
  11. if [ $? -ne 0 ]; then
  12. rm $outfile
  13. exit 1
  14. fi
  15. rm $outfile
  16. # Use valid issuer and subjec options
  17. tpm2 certifyX509certutil -o $outfile -d $daysvalid -i "C=US;CN=cname;O=My Org;OU=Org Unit" -s "C=US;CN=cname;O=Sub Org;OU=Org Unit"
  18. openssl asn1parse -in $outfile -inform DER | grep "cname"
  19. if [ $? -ne 0 ]; then
  20. rm $outfile
  21. exit 1
  22. fi
  23. rm $outfile
  24. # Use invalid issuer and subjec options - defaults should be used
  25. tpm2 certifyX509certutil -o $outfile -i "C=USA;CN=12345678901234567890;O=12345678901234567890;OU=12345678901234567890" -s "C=USA;CN=12345678901234567890;O=1234567890;OU=1234567890"
  26. openssl asn1parse -in $outfile -inform DER | grep "CA Org"
  27. if [ $? -ne 0 ]; then
  28. rm $outfile
  29. exit 1
  30. fi
  31. rm $outfile
  32. # Use unsupported fields for issuer and subjec options - defaults should be used
  33. tpm2 certifyX509certutil -o $outfile -i "B=USA;CN=12345678901234567890;X=12345678901234567890;YXZ=12345678901234567890;O=XXXXXXXX;CN=1234567890;" -s "ABC=USA;CNN=12345678901234567890;CCCCCC=1234567890;@#$=1234567890;O=XXXXXXXX;CN=1234567890;"
  34. openssl asn1parse -in $outfile -inform DER | grep "default"
  35. if [ $? -ne 0 ]; then
  36. # rm $outfile
  37. exit 1
  38. fi
  39. rm $outfile
  40. # Negative tests
  41. # generate cert in non-existing path
  42. if tpm2 certifyX509certutil -o /non/existing/path/$outfile &>/dev/null; then
  43. echo "Expected \"$cmd\" to fail."
  44. exit 1
  45. else
  46. true
  47. fi
  48. # Use only invalid fields for issuer - should fail
  49. if tpm2 certifyX509certutil -i "B=USA;Y=12345678901234567890;X=12345678901234567890;YXZ=12345678901234567890" &> /dev/null; then
  50. echo "Expected \"$cmd\" to fail."
  51. exit 1
  52. else
  53. true
  54. fi
  55. exit "$fail"