PageRenderTime 1727ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/usr/src/suites/security/kmf/tests/kmfcfg/kmfcfg_create_005.ksh

https://bitbucket.org/illumos/illumos-stc
Korn Shell | 253 lines | 167 code | 25 blank | 61 comment | 8 complexity | 33e2194040f32738aa20d6dd5d78ee1d MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. #! /usr/bin/ksh -p
  2. #
  3. # CDDL HEADER START
  4. #
  5. # The contents of this file are subject to the terms of the
  6. # Common Development and Distribution License (the "License").
  7. # You may not use this file except in compliance with the License.
  8. #
  9. # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10. # or http://www.opensolaris.org/os/licensing.
  11. # See the License for the specific language governing permissions
  12. # and limitations under the License.
  13. #
  14. # When distributing Covered Code, include this CDDL HEADER in each
  15. # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16. # If applicable, add the following below this CDDL HEADER, with the
  17. # fields enclosed by brackets "[]" replaced with your own identifying
  18. # information: Portions Copyright [yyyy] [name of copyright owner]
  19. #
  20. # CDDL HEADER END
  21. #
  22. #
  23. # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
  24. # Use is subject to license terms.
  25. #
  26. # ident "%Z%%M% %I% %E% SMI"
  27. #
  28. #########################################################################
  29. #
  30. # start __stf_assertion__
  31. #
  32. # ASSERTION: kmfcfg_create_005
  33. #
  34. # DESCRIPTION:
  35. #
  36. # Verify:
  37. # "kmfcfg create" with appropriate options can create policies with
  38. # extened key usage checking.
  39. #
  40. # STRATEGY:
  41. #
  42. # 1) Backup test.xml to test.xml.bak
  43. # 2) Run "kmfcfg create dbfile=test.xml policy=testpolicy" with ekunames
  44. # option and save the output to a temp variable
  45. # 3) Check the return value of command
  46. # 4) Verify the new policy with "kmfcfg list dbfile=test.xml policy=testpolicy"
  47. # 5) Restore the test.xml to the original one
  48. # 6) Repeat 2),3),4),5) for create subcommand with different ekunames
  49. # values
  50. # 7) Run "kmfcfg create dbfile=test.xml policy=testpolicy" with ekuoids
  51. # option, repeat 3),4),5)
  52. #
  53. # INTERFACE: kmfcfg
  54. #
  55. # end __stf_assertion__
  56. #
  57. #########################################################################
  58. . ${STF_TOOLS}/include/stf.kshlib
  59. . ${STF_TOOLS}/contrib/include/jnl.kshlib
  60. description() {
  61. cat <<-EOF
  62. Verify:
  63. "kmfcfg create" with appropriate options can create policies with
  64. extended key usage checking.
  65. EOF
  66. }
  67. jnl_assertion "$( description )" "kmfcfg create"
  68. test_db="/var/tmp/test.xml"
  69. cmd="/usr/bin/kmfcfg"
  70. common_options="create dbfile=$test_db policy=testpolicy ignore-trust-anchor=true"
  71. ekun_opt="ekunames="
  72. ekuo_opt="ekuoids="
  73. list_options="list dbfile=$test_db policy=testpolicy"
  74. set -A cmd_args \
  75. "serverauth" \
  76. "clientauth" \
  77. "codesigning" \
  78. "emailprotection" \
  79. "ipsecendsystem" \
  80. "ipsectunnel" \
  81. "ipsecuser" \
  82. "timestamping" \
  83. "ocspsigning"
  84. multi_usage="serverauth,clientauth,codesigning,emailprotection,ipsecendsystem,\
  85. ipsectunnel,ipsecuser,timestamping,ocspsigning"
  86. echo $multi_usage
  87. ekuoid="1.2.3.4"
  88. # Back up test.xml
  89. jnl_progress "Backup the original dbfile test.xml"
  90. cp $test_db test.xml.bak
  91. e=$?
  92. if [[ $e -ne 0 ]]; then
  93. jnl_diagnostic "Backup test dbfile" "0" $e "STF_UNRESOLVED"
  94. rm -f test.xml.bak
  95. exit $STF_UNRESOLVED
  96. fi
  97. integer i=0 len=0 j=0
  98. len=${#cmd_args[*]}
  99. output=""
  100. # Test single Extended Key Usage (ekunames)
  101. while (( i < len )); do
  102. jnl_progress "$cmd $common_options $ekun_opt${cmd_args[i]}"
  103. output=$($cmd $common_options $ekun_opt${cmd_args[i]})
  104. e=$?
  105. if [[ $e -ne 0 ]]; then
  106. jnl_diagnostic "$cmd $common_options $ekun_opt${cmd_args[i]} $output" 0 $e "STF_FAIL"
  107. jnl_result $STF_FAIL
  108. cp test.xml.bak $test_db
  109. rm -f test.xml.bak
  110. rm -f result.$$
  111. exit $STF_FAIL
  112. fi
  113. jnl_progress "$cmd $list_options"
  114. $cmd $list_options > result.$$
  115. e=$?
  116. if [[ $e -ne 0 ]]; then
  117. jnl_diagnostic "$cmd $list_options" 0 $e "STF_UNRESOLVED"
  118. jnl_result $STF_UNRESOLVED
  119. cp test.xml.bak $test_db
  120. rm -f test.xml.bak
  121. rm -f result.$$
  122. exit $STF_UNRESOLVED
  123. fi
  124. grep -i "${cmd_args[i]}" result.$$
  125. e=$?
  126. if [[ $e -ne 0 ]]; then
  127. jnl_error "Can't find policy from test.xml"
  128. jnl_result $STF_FAIL
  129. cp test.xml.bak $test_db
  130. rm -f test.xml.bak
  131. rm -f result.$$
  132. exit $STF_FAIL
  133. fi
  134. # Restore test.xml
  135. cp test.xml.bak $test_db
  136. (( i += 1 ))
  137. done
  138. # Test multiple Extended Key Usages (ekunames)
  139. jnl_progress "$cmd $common_options $ekun_opt${cmd_args[*]}"
  140. output=$($cmd $common_options $ekun_opt$multi_usage)
  141. e=$?
  142. if [[ $e -ne 0 ]]; then
  143. jnl_diagnostic "$cmd $common_options $ekun_opt$multi_usage $output" 0 $e "STF_FAIL"
  144. jnl_result $STF_FAIL
  145. cp test.xml.bak $test_db
  146. rm -f test.xml.bak
  147. rm -f result.$$
  148. exit $STF_FAIL
  149. fi
  150. jnl_progress "$cmd $list_options"
  151. $cmd $list_options > result.$$
  152. e=$?
  153. if [[ $e -ne 0 ]]; then
  154. jnl_diagnostic "$cmd $list_options" 0 $e "STF_UNRESOLVED"
  155. jnl_result $STF_UNRESOLVED
  156. cp test.xml.bak $test_db
  157. rm -f test.xml.bak
  158. rm -f result.$$
  159. exit $STF_UNRESOLVED
  160. fi
  161. i=0
  162. len=${#cmd_args[*]}
  163. while (( i < len )); do
  164. grep -i "${cmd_args[i]}" result.$$
  165. if [[ $? -eq 0 ]]; then
  166. ((j += 1))
  167. fi
  168. ((i +=1 ))
  169. done
  170. if (( j != 9 )); then
  171. jnl_error "Can't find policy from test.xml"
  172. jnl_result $STF_FAIL
  173. cp test.xml.bak $test_db
  174. rm -f test.xml.bak
  175. rm -f result.$$
  176. exit $STF_FAIL
  177. fi
  178. # Restore test.xml
  179. cp test.xml.bak $test_db
  180. # Create policy with ekuoids option
  181. jnl_progress "$cmd $common_options $ekuo_opt${cmd_args[*]}"
  182. output=$($cmd $common_options $ekuo_opt$ekuoid)
  183. e=$?
  184. if [[ $e -ne 0 ]]; then
  185. jnl_diagnostic "$cmd $common_options $ekuo_opt$ekuoid} $output" 0 $e "STF_FAIL"
  186. jnl_result $STF_FAIL
  187. cp test.xml.bak $test_db
  188. rm -f test.xml.bak
  189. rm -f result.$$
  190. exit $STF_FAIL
  191. fi
  192. jnl_progress "$cmd $list_options"
  193. $cmd $list_options > result.$$
  194. e=$?
  195. if [[ $e -ne 0 ]]; then
  196. jnl_diagnostic "$cmd $list_options" 0 $e "STF_UNRESOLVED"
  197. jnl_result $STF_UNRESOLVED
  198. cp test.xml.bak $test_db
  199. rm -f test.xml.bak
  200. rm -f result.$$
  201. exit $STF_UNRESOLVED
  202. fi
  203. grep $ekuoid result.$$
  204. e=$?
  205. if [[ $e -ne 0 ]]; then
  206. jnl_error "Can't find policy from test.xml"
  207. jnl_result $STF_FAIL
  208. cp test.xml.bak $test_db
  209. rm -f test.xml.bak
  210. rm -f result.$$
  211. exit $STF_FAIL
  212. fi
  213. # Restore test.xml
  214. cp test.xml.bak $test_db
  215. rm -f result.$$
  216. rm -f test.xml.bak
  217. jnl_result $STF_PASS
  218. exit $STF_PASS