]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/importExport/importExportECDSA_P12_Tool
Security-57031.30.12.tar.gz
[apple/security.git] / SecurityTests / clxutils / importExport / importExportECDSA_P12_Tool
1 #! /bin/csh -f
2 #
3 # Run one iteration of ECDSA/PKC12 portion of import/export tests.
4 # Only used as a subroutine call from importExportECDSA_P12.
5 #
6 # Usage
7 # importExportECDSA_P12_Tool pfxFile clean(YES|NO) quiet(YES|NO)
8 #
9 if ( $#argv != 3 ) then
10 exit(1)
11 endif
12 set PFX=$argv[1]
13 set CLEAN=$argv[2]
14 set QUIET=$argv[3]
15 set QUIET_ARG=
16 set QUIET_FLAG=
17 if ($QUIET == YES) then
18 set QUIET_ARG=-q
19 set QUIET_FLAG=q
20 endif
21
22 source setupCommon
23
24 set PFX_PASSWORD=password
25 set KEYBASE=${BUILD_DIR}/ecdsaP12
26 set PRIV_KEY=${KEYBASE}_priv.der
27 set PUB_KEY=${KEYBASE}_pub.der
28 set CERT_PEM=${BUILD_DIR}/ecdsa_certs.pem
29 set CERT_DER=${BUILD_DIR}/ecdsa_certs.der
30 set PLAINTEXT=somePlainText
31 set SIGFILE=${BUILD_DIR}/ecdsasig
32
33 # empty the keychain
34 if ($QUIET == NO) then
35 echo $CLEANKC
36 endif
37 $CLEANKC || exit(1)
38
39 # import the p12 - No ACL, extractable in the clear
40 set cmd="$KCIMPORT $PFX -k $KEYCHAIN -z $PFX_PASSWORD -t agg -f pkcs12 -n -e $QUIET_ARG"
41 if ($QUIET == NO) then
42 echo $cmd
43 endif
44 $cmd || exit(1)
45
46 # export key to clear OpenSSL form
47 set cmd="$KCEXPORT $KEYCHAIN -t privKeys -f openssl -o $PRIV_KEY $QUIET_ARG"
48 if ($QUIET == NO) then
49 echo $cmd
50 endif
51 $cmd || exit(1)
52
53 # export cert
54 set cmd="$KCEXPORT $KEYCHAIN -t certs -o $CERT_PEM -f pemseq $QUIET_ARG"
55 if ($QUIET == NO) then
56 echo $cmd
57 endif
58 $cmd || exit(1)
59
60 # convert cert to DER
61 set cmd="$PEMTOOL d $CERT_PEM $CERT_DER $QUIET_FLAG"
62 if ($QUIET == NO) then
63 echo $cmd
64 endif
65 $cmd || exit(1)
66
67 # extract pub key from cert
68 set cmd="$KEY_FROM_CERT $QUIET_ARG $CERT_DER $PUB_KEY"
69 if ($QUIET == NO) then
70 echo $cmd
71 endif
72 $cmd || exit(1)
73
74 # sign
75 set cmd="$RSATOOL s a=e v=o k=$KEYBASE p=$PLAINTEXT s=$SIGFILE $QUIET_FLAG"
76 if ($QUIET == NO) then
77 echo $cmd
78 endif
79 $cmd || exit(1)
80
81 # verify
82 set cmd="$RSATOOL v a=e k=$KEYBASE p=$PLAINTEXT s=$SIGFILE $QUIET_FLAG"
83 if ($QUIET == NO) then
84 echo $cmd
85 endif
86 $cmd || exit(1)
87
88 if($CLEAN == YES) then
89 set cmd="rm -f $PRIV_KEY $PUB_KEY $CERT_PEM $CERT_DER $SIGFILE"
90 if ($QUIET == NO) then
91 echo $cmd
92 endif
93 $cmd || exit(1)
94 endif
95