3 # Run import/export tests for PKCS12.
5 # Run this from SecurityTests/clxutils/importExport. The
6 # kcImport and kcExport programs must exist in the location
7 # specified by the LOCAL_BUILD_DIR env var.
12 # PKCS12 blob, we generate
13 set GEN_PKCS12_PFX
=${BUILD_DIR}/generated.p12
15 # parsed PEM sequence generated by openssl (parsing $GEN_PKCS12_PFX)
16 set PKCS12_PARSED_PEM
=${BUILD_DIR}/parsed.p12.pem
18 # PKCS12 blob, openssl generates
19 set GEN_OPENSSL_PKCS12_PFX
=${BUILD_DIR}/generatedOpenssl.p12
22 set PKCS12_PASSPHRASE
=somePassphrase
24 # user specified variables
34 # Verify existence of a few crucial things before we start.
36 if( ( ! -e $KCIMPORT ) || \
37 ( ! -e $KCEXPORT ) ) then
38 echo === You
do not seem to have all of the required executables.
39 echo === Please build all of cspxutils and clxutils.
40 echo === See the README files
in those directories
for info.
67 echo Usage
: importExportPkcs12 \
[q\
(uiet\
)\
] \
[n\
(oACL\
)\
] \
[s\
(ecurePassphrase\
)\
] \
[N\
(oClean\
)\
]
72 # Create keypair and cert using certtool
74 echo === Begin PKCS12
test ===
75 if ($QUIET == NO
) then
76 echo Creating keypair and cert with certtool...
80 set cmd
="$CERTTOOL c k=$KEYCHAIN_PATH Z"
81 if ($QUIET == NO
) then
84 $cmd > /dev
/null
|| exit(1)
88 if ($QUIET == NO
) then
89 echo ...Exporting private key and cert as PKCS12...
91 # note we export Identities, not All, since pub keys can't go in a P12
92 set cmd
="$KCEXPORT $KEYCHAIN -t identities -f pkcs12 -o $GEN_PKCS12_PFX -z $PKCS12_PASSPHRASE $SECURE_PASSPHR -q"
93 if ($QUIET == NO
) then
100 if ($QUIET == NO
) then
101 echo ...Importing PKCS12
, explicit format...
103 if ($QUIET == NO
) then
107 set cmd
="$KCIMPORT $GEN_PKCS12_PFX -k $KEYCHAIN -f pkcs12 -z $PKCS12_PASSPHRASE -C 0 -K 0 -I 1 -T agg -F pkcs12 -q $NOACL_ARG $SECURE_PASSPHR"
108 if ($QUIET == NO
) then
113 if ($QUIET == NO
) then
114 echo ...Importing PKCS12
, format inferred from filename...
116 if ($QUIET == NO
) then
120 set cmd
="$KCIMPORT $GEN_PKCS12_PFX -k $KEYCHAIN -z $PKCS12_PASSPHRASE -C 0 -K 0 -I 1 -T agg -F pkcs12 -q $NOACL_ARG $SECURE_PASSPHR"
121 if ($QUIET == NO
) then
125 if ($QUIET == NO
) then
131 # Exchange with openssl.
133 if ($QUIET == NO
) then
134 echo ...parsing our P12 PFX with openssl...
136 set cmd
="$RM -f $PKCS12_PARSED_PEM"
137 if ($QUIET == NO
) then
141 set cmd
="$OPENSSL pkcs12 -in $GEN_PKCS12_PFX -passin pass:$PKCS12_PASSPHRASE -nodes -out $PKCS12_PARSED_PEM"
142 if ($QUIET == NO
) then
145 $cmd >& /dev
/null
|| exit(1)
147 if ($QUIET == NO
) then
148 echo ...parsing openssl PEM sequence
152 set cmd
="$KCIMPORT $PKCS12_PARSED_PEM -k $KEYCHAIN -z $PKCS12_PASSPHRASE -q $NOACL_ARG $SECURE_PASSPHR"
153 if ($QUIET == NO
) then
158 if ($QUIET == NO
) then
159 echo ...creating PKCS12 with openssl
, import to empty keychain
161 set cmd
="$OPENSSL pkcs12 -in $PKCS12_PARSED_PEM -out $GEN_OPENSSL_PKCS12_PFX -passout pass:$PKCS12_PASSPHRASE -export"
162 if ($QUIET == NO
) then
166 if ($QUIET == NO
) then
170 set cmd
="$KCIMPORT $GEN_OPENSSL_PKCS12_PFX -z $PKCS12_PASSPHRASE -k $KEYCHAIN -K 0 -C 0 -I 1 -q $SECURE_PASSPHR"
171 if ($QUIET == NO
) then
175 set cmd
="$DBVERIFY $KEYCHAIN_PATH rsa priv $KEYSIZE $QUIET_ARG"
176 if ($QUIET == NO
) then
182 if ($NOCLEAN == NO
) then
183 set cmd
="rm -f $GEN_PKCS12_PFX $PKCS12_PARSED_PEM $GEN_OPENSSL_PKCS12_PFX"
184 if ($QUIET == NO
) then
190 if ($QUIET == NO
) then
191 echo === PKCS12
test complete
===