3 # Run PKCS8 import/export tests.
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 set PKCS8SUBTOOL
=.
/importExportPkcs8Tool
13 set PKCS8EXPORTTOOL
=.
/exportPkcs8Tool
15 set P8_PASSWORD
=foobar
17 # RSA private key, PEM, generated by openssl
18 set RSA_PRIV_KEY
=${BUILD_DIR}/rsapriv.
clear.pem
20 # DSA private key, PEM, generated by openssl
21 set DSA_PRIV_KEY
=${BUILD_DIR}/dsapriv.
clear.pem
24 set DSA_PARAMS
=dsaParamOpenssl.pem
26 # PKCS8 blob, generated by openssl
27 set PKCS8_KEY_OS
=${BUILD_DIR}/pkcs8.p8
29 # PKCS8 blob, generated by kcExport
30 set PKCS8_KEY_EXP
=${BUILD_DIR}/pkcs8_exp.p8
32 # raw key, generated by openssl after parsing our p8
33 set PKCS8_KEY_PARSE_OS
=${BUILD_DIR}/pkcs8_parse
36 set DSA_PARAMS_512_DER
=dsaParams_512.der
37 set DSA_PARAMS_512_PEM
=dsaParamOpenssl.pem
39 # user specified variables
46 set SECURE_PHRASE_ARG
=
65 set SECURE_PHRASE_ARG
=-Z
73 echo Usage
: importExportPkcs8 \
[q\
(uiet\
)\
] \
[n\
(oACL\
)\
] \
[s\
(ecurePassphrase\
)\
] \
[N\
(oClean\
)\
]
78 echo === Begin PKCS8
test ===
79 if ($QUIET == NO
) then
88 # Create RSA key pair using openssl
89 # private keys are only generated in PEM format
90 if ($QUIET == NO
) then
91 echo ...RSA key testing
, openssl generated
92 echo Creating RSA private key using openssl...
94 set cmd
="$RM -f $RSA_PRIV_KEY"
95 if ($QUIET == NO
) then
99 set cmd
="$OPENSSL genrsa -out $RSA_PRIV_KEY $KEYSIZE"
100 if ($QUIET == NO
) then
103 $cmd >& /dev
/null
|| exit(1)
107 # PKCS5 v1.5 algorithms:
109 if ($QUIET == NO
) then
110 echo ...testing PKCS5 v1.5 PBE with RSA keys
112 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-MD5-DES rsa 512 $QUIET $NOACL DER $SECURE_PHRASE"
114 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-MD2-DES rsa 512 $QUIET $NOACL PEM $SECURE_PHRASE"
116 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-SHA1-RC2-64 rsa 512 $QUIET $NOACL DER $SECURE_PHRASE"
118 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-MD2-RC2-64 rsa 512 $QUIET $NOACL PEM $SECURE_PHRASE"
120 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-MD5-RC2-64 rsa 512 $QUIET $NOACL DER $SECURE_PHRASE"
122 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-SHA1-DES rsa 512 $QUIET $NOACL PEM $SECURE_PHRASE"
126 # PKCS5 v2.0 PBE algorithms
128 if ($QUIET == NO
) then
129 echo ...testing PKCS5 v2.0 PBE with RSA keys
131 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v2 des3 rsa 512 $QUIET $NOACL DER $SECURE_PHRASE"
133 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v2 des rsa 512 $QUIET $NOACL PEM $SECURE_PHRASE"
135 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v2 rc2 rsa 512 $QUIET $NOACL DER $SECURE_PHRASE"
139 # PKCS12 PBE algorithms
140 # NOTE we do not support PBE-SHA1-2DES (no double DES in the CSP)
142 if ($QUIET == NO
) then
143 echo ...testing PKCS12 PBE with RSA keys
145 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-SHA1-RC4-128 rsa 512 $QUIET $NOACL DER $SECURE_PHRASE"
147 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-SHA1-RC4-40 rsa 512 $QUIET $NOACL PEM $SECURE_PHRASE"
149 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-SHA1-3DES rsa 512 $QUIET $NOACL DER $SECURE_PHRASE"
151 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-SHA1-RC2-128 rsa 512 $QUIET $NOACL PEM $SECURE_PHRASE"
153 set cmd
="$PKCS8SUBTOOL $RSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-SHA1-RC2-40 rsa 512 $QUIET $NOACL DER $SECURE_PHRASE"
157 # PKCS8 import, DSA form.
158 # The PKCS8 logic is (mostly) algorithm independent so we'll just do a few of these
159 # to make sure the CSP can import and export correctly.
161 if ($QUIET == NO
) then
162 echo ...testing PKCS8 import with DSA keys
164 set cmd
="$RM -f $DSA_PRIV_KEY"
165 if ($QUIET == NO
) then
169 set cmd
="$OPENSSL gendsa -out $DSA_PRIV_KEY $DSA_PARAMS"
170 if ($QUIET == NO
) then
173 $cmd >& /dev
/null
|| exit(1)
174 set cmd
="$PKCS8SUBTOOL $DSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v1 PBE-SHA1-RC2-40 dsa 512 $QUIET $NOACL DER $SECURE_PHRASE"
176 set cmd
="$PKCS8SUBTOOL $DSA_PRIV_KEY $PKCS8_KEY_OS $KEYCHAIN -v2 des3 dsa 512 $QUIET $NOACL PEM $SECURE_PHRASE"
182 if ($QUIET == NO
) then
183 echo ...testing PKCS8 Export of RSA private key
185 set cmd
="$PKCS8EXPORTTOOL $RSA_PRIV_KEY $PKCS8_KEY_EXP $PKCS8_KEY_PARSE_OS $KEYCHAIN PEM rsa 512 $QUIET $NOACL $SECURE_PHRASE"
187 set cmd
="$PKCS8EXPORTTOOL $RSA_PRIV_KEY $PKCS8_KEY_EXP $PKCS8_KEY_PARSE_OS $KEYCHAIN DER rsa 512 $QUIET $NOACL $SECURE_PHRASE"
190 if ($QUIET == NO
) then
191 echo ...testing PKCS8 Export of DSA private key
193 set cmd
="$PKCS8EXPORTTOOL $DSA_PRIV_KEY $PKCS8_KEY_EXP $PKCS8_KEY_PARSE_OS $KEYCHAIN PEM dsa 512 $QUIET $NOACL $SECURE_PHRASE"
195 set cmd
="$PKCS8EXPORTTOOL $DSA_PRIV_KEY $PKCS8_KEY_EXP $PKCS8_KEY_PARSE_OS $KEYCHAIN DER dsa 512 $QUIET $NOACL $SECURE_PHRASE"
199 if($NOCLEAN == NO
) then
200 set cmd
="rm -f $RSA_PRIV_KEY $DSA_PRIV_KEY $PKCS8_KEY_OS $PKCS8_KEY_EXP $PKCS8_KEY_PARSE_OS"
201 if ($QUIET == NO
) then
207 if ($QUIET == NO
) then
208 echo === PKCS8
test complete
===