/security/nss/tests/smime/smime.sh

http://github.com/zpao/v8monkey · Shell · 292 lines · 181 code · 45 blank · 66 comment · 11 complexity · 56bb61031cd3b84678cb05c674cfaee0 MD5 · raw file

  1. #! /bin/sh
  2. #
  3. # ***** BEGIN LICENSE BLOCK *****
  4. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. #
  6. # The contents of this file are subject to the Mozilla Public License Version
  7. # 1.1 (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. # http://www.mozilla.org/MPL/
  10. #
  11. # Software distributed under the License is distributed on an "AS IS" basis,
  12. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. # for the specific language governing rights and limitations under the
  14. # License.
  15. #
  16. # The Original Code is the Netscape security libraries.
  17. #
  18. # The Initial Developer of the Original Code is
  19. # Netscape Communications Corporation.
  20. # Portions created by the Initial Developer are Copyright (C) 1994-2000
  21. # the Initial Developer. All Rights Reserved.
  22. #
  23. # Contributor(s):
  24. # Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
  25. #
  26. # Alternatively, the contents of this file may be used under the terms of
  27. # either the GNU General Public License Version 2 or later (the "GPL"), or
  28. # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. # in which case the provisions of the GPL or the LGPL are applicable instead
  30. # of those above. If you wish to allow use of your version of this file only
  31. # under the terms of either the GPL or the LGPL, and not to allow others to
  32. # use your version of this file under the terms of the MPL, indicate your
  33. # decision by deleting the provisions above and replace them with the notice
  34. # and other provisions required by the GPL or the LGPL. If you do not delete
  35. # the provisions above, a recipient may use your version of this file under
  36. # the terms of any one of the MPL, the GPL or the LGPL.
  37. #
  38. # ***** END LICENSE BLOCK *****
  39. ########################################################################
  40. #
  41. # mozilla/security/nss/tests/smime/smime.sh
  42. #
  43. # Script to test NSS smime
  44. #
  45. # needs to work on all Unix and Windows platforms
  46. #
  47. # special strings
  48. # ---------------
  49. # FIXME ... known problems, search for this string
  50. # NOTE .... unexpected behavior
  51. #
  52. ########################################################################
  53. ############################## smime_init ##############################
  54. # local shell function to initialize this script
  55. ########################################################################
  56. smime_init()
  57. {
  58. SCRIPTNAME=smime.sh # sourced - $0 would point to all.sh
  59. if [ -z "${CLEANUP}" ] ; then # if nobody else is responsible for
  60. CLEANUP="${SCRIPTNAME}" # cleaning this script will do it
  61. fi
  62. if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then
  63. cd ../common
  64. . ./init.sh
  65. fi
  66. if [ ! -r $CERT_LOG_FILE ]; then # we need certificates here
  67. cd ../cert
  68. . ./cert.sh
  69. fi
  70. SCRIPTNAME=smime.sh
  71. if [ -n "$NSS_ENABLE_ECC" ] ; then
  72. html_head "S/MIME Tests with ECC"
  73. else
  74. html_head "S/MIME Tests"
  75. fi
  76. grep "SUCCESS: SMIME passed" $CERT_LOG_FILE >/dev/null || {
  77. Exit 11 "Fatal - S/MIME of cert.sh needs to pass first"
  78. }
  79. SMIMEDIR=${HOSTDIR}/smime
  80. R_SMIMEDIR=../smime
  81. mkdir -p ${SMIMEDIR}
  82. cd ${SMIMEDIR}
  83. cp ${QADIR}/smime/alice.txt ${SMIMEDIR}
  84. }
  85. smime_sign()
  86. {
  87. HASH_CMD="-H ${HASH}"
  88. SIG=sig.${HASH}
  89. echo "$SCRIPTNAME: Signing Detached Message {$HASH} ------------------"
  90. echo "cmsutil -S -T -N Alice ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice.d${SIG}"
  91. ${PROFTOOL} ${BINDIR}/cmsutil -S -T -N Alice ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice.d${SIG}
  92. html_msg $? 0 "Create Detached Signature Alice (${HASH})" "."
  93. echo "cmsutil -D -i alice.d${SIG} -c alice.txt -d ${P_R_BOBDIR} "
  94. ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice.d${SIG} -c alice.txt -d ${P_R_BOBDIR}
  95. html_msg $? 0 "Verifying Alice's Detached Signature (${HASH})" "."
  96. echo "$SCRIPTNAME: Signing Attached Message (${HASH}) ------------------"
  97. echo "cmsutil -S -N Alice ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice.${SIG}"
  98. ${PROFTOOL} ${BINDIR}/cmsutil -S -N Alice ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice.${SIG}
  99. html_msg $? 0 "Create Attached Signature Alice (${HASH})" "."
  100. echo "cmsutil -D -i alice.${SIG} -d ${P_R_BOBDIR} -o alice.data.${HASH}"
  101. ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice.${SIG} -d ${P_R_BOBDIR} -o alice.data.${HASH}
  102. html_msg $? 0 "Decode Alice's Attached Signature (${HASH})" "."
  103. echo "diff alice.txt alice.data.${HASH}"
  104. diff alice.txt alice.data.${HASH}
  105. html_msg $? 0 "Compare Attached Signed Data and Original (${HASH})" "."
  106. # Test ECDSA signing for all hash algorithms.
  107. if [ -n "$NSS_ENABLE_ECC" ] ; then
  108. echo "$SCRIPTNAME: Signing Detached Message ECDSA w/ {$HASH} ------------------"
  109. echo "cmsutil -S -T -N Alice-ec ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice-ec.d${SIG}"
  110. ${PROFTOOL} ${BINDIR}/cmsutil -S -T -N Alice-ec ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice-ec.d${SIG}
  111. html_msg $? 0 "Create Detached Signature Alice (ECDSA w/ ${HASH})" "."
  112. echo "cmsutil -D -i alice-ec.d${SIG} -c alice.txt -d ${P_R_BOBDIR} "
  113. ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice-ec.d${SIG} -c alice.txt -d ${P_R_BOBDIR}
  114. html_msg $? 0 "Verifying Alice's Detached Signature (ECDSA w/ ${HASH})" "."
  115. echo "$SCRIPTNAME: Signing Attached Message (ECDSA w/ ${HASH}) ------------------"
  116. echo "cmsutil -S -N Alice-ec ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice-ec.${SIG}"
  117. ${PROFTOOL} ${BINDIR}/cmsutil -S -N Alice-ec ${HASH_CMD} -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice-ec.${SIG}
  118. html_msg $? 0 "Create Attached Signature Alice (ECDSA w/ ${HASH})" "."
  119. echo "cmsutil -D -i alice-ec.${SIG} -d ${P_R_BOBDIR} -o alice-ec.data.${HASH}"
  120. ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice-ec.${SIG} -d ${P_R_BOBDIR} -o alice-ec.data.${HASH}
  121. html_msg $? 0 "Decode Alice's Attached Signature (ECDSA w/ ${HASH})" "."
  122. echo "diff alice.txt alice-ec.data.${HASH}"
  123. diff alice.txt alice-ec.data.${HASH}
  124. html_msg $? 0 "Compare Attached Signed Data and Original (ECDSA w/ ${HASH})" "."
  125. fi
  126. }
  127. smime_p7()
  128. {
  129. echo "$SCRIPTNAME: p7 util Data Tests ------------------------------"
  130. echo "p7env -d ${P_R_ALICEDIR} -r Alice -i alice.txt -o alice_p7.env"
  131. ${PROFTOOL} ${BINDIR}/p7env -d ${P_R_ALICEDIR} -r Alice -i alice.txt -o alice.env
  132. html_msg $? 0 "Creating envelope for user Alice" "."
  133. echo "p7content -d ${P_R_ALICEDIR} -i alice.env -o alice_p7.data"
  134. ${PROFTOOL} ${BINDIR}/p7content -d ${P_R_ALICEDIR} -i alice.env -o alice_p7.data -p nss
  135. html_msg $? 0 "Verifying file delivered to user Alice" "."
  136. sed -e '3,8p' -n alice_p7.data > alice_p7.data.sed
  137. echo "diff alice.txt alice_p7.data.sed"
  138. diff alice.txt alice_p7.data.sed
  139. html_msg $? 0 "Compare Decoded Enveloped Data and Original" "."
  140. echo "p7sign -d ${P_R_ALICEDIR} -k Alice -i alice.txt -o alice.sig -p nss -e"
  141. ${PROFTOOL} ${BINDIR}/p7sign -d ${P_R_ALICEDIR} -k Alice -i alice.txt -o alice.sig -p nss -e
  142. html_msg $? 0 "Signing file for user Alice" "."
  143. echo "p7verify -d ${P_R_ALICEDIR} -c alice.txt -s alice.sig"
  144. ${PROFTOOL} ${BINDIR}/p7verify -d ${P_R_ALICEDIR} -c alice.txt -s alice.sig
  145. html_msg $? 0 "Verifying file delivered to user Alice" "."
  146. }
  147. ############################## smime_main ##############################
  148. # local shell function to test basic signed and enveloped messages
  149. # from 1 --> 2"
  150. ########################################################################
  151. smime_main()
  152. {
  153. HASH=SHA1
  154. smime_sign
  155. HASH=SHA256
  156. smime_sign
  157. HASH=SHA384
  158. smime_sign
  159. HASH=SHA512
  160. smime_sign
  161. echo "$SCRIPTNAME: Enveloped Data Tests ------------------------------"
  162. echo "cmsutil -E -r bob@bogus.com -i alice.txt -d ${P_R_ALICEDIR} -p nss \\"
  163. echo " -o alice.env"
  164. ${PROFTOOL} ${BINDIR}/cmsutil -E -r bob@bogus.com -i alice.txt -d ${P_R_ALICEDIR} -p nss -o alice.env
  165. html_msg $? 0 "Create Enveloped Data Alice" "."
  166. echo "cmsutil -D -i alice.env -d ${P_R_BOBDIR} -p nss -o alice.data1"
  167. ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice.env -d ${P_R_BOBDIR} -p nss -o alice.data1
  168. html_msg $? 0 "Decode Enveloped Data Alice" "."
  169. echo "diff alice.txt alice.data1"
  170. diff alice.txt alice.data1
  171. html_msg $? 0 "Compare Decoded Enveloped Data and Original" "."
  172. # multiple recip
  173. echo "$SCRIPTNAME: Testing multiple recipients ------------------------------"
  174. echo "cmsutil -E -i alice.txt -d ${P_R_ALICEDIR} -o alicecc.env \\"
  175. echo " -r bob@bogus.com,dave@bogus.com"
  176. ${PROFTOOL} ${BINDIR}/cmsutil -E -i alice.txt -d ${P_R_ALICEDIR} -o alicecc.env \
  177. -r bob@bogus.com,dave@bogus.com
  178. ret=$?
  179. html_msg $ret 0 "Create Multiple Recipients Enveloped Data Alice" "."
  180. if [ $ret != 0 ] ; then
  181. echo "certutil -L -d ${P_R_ALICEDIR}"
  182. ${BINDIR}/certutil -L -d ${P_R_ALICEDIR}
  183. echo "certutil -L -d ${P_R_ALICEDIR} -n dave@bogus.com"
  184. ${BINDIR}/certutil -L -d ${P_R_ALICEDIR} -n dave@bogus.com
  185. fi
  186. echo "$SCRIPTNAME: Testing multiple email addrs ------------------------------"
  187. echo "cmsutil -E -i alice.txt -d ${P_R_ALICEDIR} -o aliceve.env \\"
  188. echo " -r eve@bogus.net"
  189. ${PROFTOOL} ${BINDIR}/cmsutil -E -i alice.txt -d ${P_R_ALICEDIR} -o aliceve.env \
  190. -r eve@bogus.net
  191. ret=$?
  192. html_msg $ret 0 "Encrypt to a Multiple Email cert" "."
  193. echo "cmsutil -D -i alicecc.env -d ${P_R_BOBDIR} -p nss -o alice.data2"
  194. ${PROFTOOL} ${BINDIR}/cmsutil -D -i alicecc.env -d ${P_R_BOBDIR} -p nss -o alice.data2
  195. html_msg $? 0 "Decode Multiple Recipients Enveloped Data Alice by Bob" "."
  196. echo "cmsutil -D -i alicecc.env -d ${P_R_DAVEDIR} -p nss -o alice.data3"
  197. ${PROFTOOL} ${BINDIR}/cmsutil -D -i alicecc.env -d ${P_R_DAVEDIR} -p nss -o alice.data3
  198. html_msg $? 0 "Decode Multiple Recipients Enveloped Data Alice by Dave" "."
  199. echo "cmsutil -D -i aliceve.env -d ${P_R_EVEDIR} -p nss -o alice.data4"
  200. ${PROFTOOL} ${BINDIR}/cmsutil -D -i aliceve.env -d ${P_R_EVEDIR} -p nss -o alice.data4
  201. html_msg $? 0 "Decrypt with a Multiple Email cert" "."
  202. diff alice.txt alice.data2
  203. html_msg $? 0 "Compare Decoded Mult. Recipients Enveloped Data Alice/Bob" "."
  204. diff alice.txt alice.data3
  205. html_msg $? 0 "Compare Decoded Mult. Recipients Enveloped Data Alice/Dave" "."
  206. diff alice.txt alice.data4
  207. html_msg $? 0 "Compare Decoded with Multiple Email cert" "."
  208. echo "$SCRIPTNAME: Sending CERTS-ONLY Message ------------------------------"
  209. echo "cmsutil -O -r \"Alice,bob@bogus.com,dave@bogus.com\" \\"
  210. echo " -d ${P_R_ALICEDIR} > co.der"
  211. ${PROFTOOL} ${BINDIR}/cmsutil -O -r "Alice,bob@bogus.com,dave@bogus.com" -d ${P_R_ALICEDIR} > co.der
  212. html_msg $? 0 "Create Certs-Only Alice" "."
  213. echo "cmsutil -D -i co.der -d ${P_R_BOBDIR}"
  214. ${PROFTOOL} ${BINDIR}/cmsutil -D -i co.der -d ${P_R_BOBDIR}
  215. html_msg $? 0 "Verify Certs-Only by CA" "."
  216. echo "$SCRIPTNAME: Encrypted-Data Message ---------------------------------"
  217. echo "cmsutil -C -i alice.txt -e alicehello.env -d ${P_R_ALICEDIR} \\"
  218. echo " -r \"bob@bogus.com\" > alice.enc"
  219. ${PROFTOOL} ${BINDIR}/cmsutil -C -i alice.txt -e alicehello.env -d ${P_R_ALICEDIR} \
  220. -r "bob@bogus.com" > alice.enc
  221. html_msg $? 0 "Create Encrypted-Data" "."
  222. echo "cmsutil -D -i alice.enc -d ${P_R_BOBDIR} -e alicehello.env -p nss \\"
  223. echo " -o alice.data2"
  224. ${PROFTOOL} ${BINDIR}/cmsutil -D -i alice.enc -d ${P_R_BOBDIR} -e alicehello.env -p nss -o alice.data2
  225. html_msg $? 0 "Decode Encrypted-Data" "."
  226. diff alice.txt alice.data2
  227. html_msg $? 0 "Compare Decoded and Original Data" "."
  228. }
  229. ############################## smime_cleanup ###########################
  230. # local shell function to finish this script (no exit since it might be
  231. # sourced)
  232. ########################################################################
  233. smime_cleanup()
  234. {
  235. html "</TABLE><BR>"
  236. cd ${QADIR}
  237. . common/cleanup.sh
  238. }
  239. ################## main #################################################
  240. smime_init
  241. smime_main
  242. smime_p7
  243. smime_cleanup