]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/importExport/importExportKeyTool
Security-57031.10.10.tar.gz
[apple/security.git] / SecurityTests / clxutils / importExport / importExportKeyTool
1 #! /bin/csh -f
2 #
3 # Run one iteration of keypair portion of import/export tests.
4 # Only used as a subroutine call from importExport.
5 #
6 # Usage
7 # importExportKeyTool pubKey privKey keychain format quiet(YES|NO) noACL(YES|NO) noClean(YES|NO)
8 #
9 if ( $#argv != 7 ) then
10 exit(1)
11 endif
12 set PUBKEY=$argv[1]
13 set PRIVKEY=$argv[2]
14 set KEYCHAIN=$argv[3]
15 set FORMAT=$argv[4]
16 set QUIET=$argv[5]
17 set NOACL_ARG=
18 if ($argv[6] == YES) then
19 set NOACL_ARG=-n
20 endif
21 set NOCLEAN=$argv[7]
22
23 set BUILD_DIR=$LOCAL_BUILD_DIR
24
25 set TMP_PUB_KEY=${BUILD_DIR}/tmpPubKey.der
26 set TMP_PRIV_KEY=${BUILD_DIR}/tmpPrivKey.der
27
28 source setupCommon
29
30 #
31 # import both keys into empty keychain, typed and untyped
32 #
33 if ($QUIET == NO) then
34 echo Importing both keys into empty keychain, explicit type/format...
35 endif
36 if ($QUIET == NO) then
37 echo $CLEANKC
38 endif
39 $CLEANKC || exit(1)
40 set cmd="$KCIMPORT $PUBKEY -k $KEYCHAIN -t pub -f $FORMAT -K 1 -F $FORMAT -T pub -q"
41 if ($QUIET == NO) then
42 echo $cmd
43 endif
44 $cmd || exit(1)
45 set cmd="$KCIMPORT $PRIVKEY -k $KEYCHAIN -e -t priv -f $FORMAT -F $FORMAT -T priv -q $NOACL_ARG"
46 if ($QUIET == NO) then
47 echo $cmd
48 endif
49 $cmd || exit(1)
50
51 if ($QUIET == NO) then
52 echo Importing both keys into empty keychain, unspecified type/format...
53 endif
54 if ($QUIET == NO) then
55 echo $CLEANKC
56 endif
57 $CLEANKC || exit(1)
58 set cmd="$KCIMPORT $PUBKEY -k $KEYCHAIN -K 1 -F $FORMAT -T pub -q"
59 if ($QUIET == NO) then
60 echo $cmd
61 endif
62 $cmd || exit(1)
63 set cmd="$KCIMPORT $PRIVKEY -k $KEYCHAIN -e -F $FORMAT -T priv -q $NOACL_ARG"
64 if ($QUIET == NO) then
65 echo $cmd
66 endif
67 $cmd || exit(1)
68
69 #
70 # export both keys into tmp files, compare to original
71 #
72 if ($QUIET == NO) then
73 echo Exporting and verifying both keys in $FORMAT format...
74 endif
75 set cmd="$KCEXPORT $KEYCHAIN -t pubKeys -f $FORMAT -o $TMP_PUB_KEY -q"
76 if ($QUIET == NO) then
77 echo $cmd
78 endif
79 $cmd || exit(1)
80 set cmd="$KCEXPORT $KEYCHAIN -t privKeys -f $FORMAT -o $TMP_PRIV_KEY -q"
81 if ($QUIET == NO) then
82 echo $cmd
83 endif
84 $cmd || exit(1)
85 # compare
86 set cmd="$CMP $PUBKEY $TMP_PUB_KEY"
87 if ($QUIET == NO) then
88 echo $cmd
89 endif
90 $cmd
91 if ($status != 0) then
92 echo Raw $FORMAT public key differs after import/export
93 exit(1)
94 endif
95 set cmd="$CMP $PRIVKEY $TMP_PRIV_KEY"
96 if ($QUIET == NO) then
97 echo $cmd
98 endif
99 $cmd
100 if ($status != 0) then
101 echo Raw $FORMAT private key differs after import/export
102 exit(1)
103 endif
104
105 # clean up
106 if($NOCLEAN == NO) then
107 set cmd="rm -f $TMP_PUB_KEY $TMP_PRIV_KEY"
108 if ($QUIET == NO) then
109 echo $cmd
110 endif
111 $cmd || exit(1)
112 endif