3 # Run one iteration of OpenSSH portion of import/export tests.
4 # Only used as a subroutine call from importExportOpenssh.
6 # Arguments (all required):
9 # privKeyFormat -- ssh1|ssh1Wrap|ssh2|ssh2Wrap
11 # pubKeyFormat -- ssh1|ssh2
12 # algorithm -- rsa|dsa
15 # securePassphrase -- YES|NO
18 # If incoming private key is wrapped, we assume it has password "password"
21 # We assume the presence of keychain $KEYCHAIN_PATH, which we clean out before
24 if ( $#argv != 9 ) then
25 echo See importExportOpensshTool
script for usage.
31 set PRIV_KEY_IN
=$argv[1]
32 set PRIV_KEY_FORM
=$argv[2]
33 set PUB_KEY_IN
=$argv[3]
34 set PUB_KEY_FORM
=$argv[4]
37 if($KEY_ALG == dsa
) then
42 if ($QUIET == YES
) then
46 if ($argv[7] == YES
) then
49 set SECURE_PHRASE_ARG
=
50 if ($argv[8] == YES
) then
51 set SECURE_PHRASE_ARG
=-Z
55 set SSHKEY
=$BUILD_DIR/sshKey
57 if ($QUIET == NO
) then
58 echo -- Testing SSH privFormat
$PRIV_KEY_FORM pubFormat
$PUB_KEY_FORM --
62 # rsatool filename - it has particular requirements here...
63 # All of are produced by exporting from a keychain.
65 set RSA_TOOL_FILENAME
=$BUILD_DIR/rawSshKey
66 set RAW_PRIV_KEY
=${RSA_TOOL_FILENAME}_priv.der
67 set RAW_PUB_KEY
=${RSA_TOOL_FILENAME}_pub.der
70 # The file we sign with rsatool, in cwd, and a signature file.
72 set PLAINTEXT
=somePlainText
73 set SIGFILE
=$BUILD_DIR/sig
78 if ($QUIET == NO
) then
84 # Import incoming private key, export to unencrypted format.
85 # Wrapped SSH1 --> SSH1
86 # Wrapped SSH2 = Wrapped Openssl --> OpenSSL = PKCS1.
87 # SSH2 = OpenSSL/PEM = PKCS1/PEM --> OpenSSL = PKCS1.
91 set RAW_PRIV_KEY_FORM
=$PRIV_KEY_FORM
93 # these are for kcImport/kcExport
96 # these are for rsatool
100 switch
( $PRIV_KEY_FORM )
104 set OUT_FORM
=openssh1
111 if($KEY_ALG == rsa
) then
120 set OUT_FORM
=openssh1
127 if($KEY_ALG == rsa
) then
134 echo See importExportOpensshTool
script for usage.
139 # Note we always import private keys with the -e option so we can export in the clear.
141 if($DO_CONVERT == yes) then
142 if ($QUIET == NO
) then
143 echo Importing wrapped private key...
145 set cmd
="$KCIMPORT $PRIV_KEY_IN -k $KEYCHAIN -z $PASSWORD -t priv -f $IN_FORM -w -e -K 1 $QUIET_ARG $NOACL_ARG $SECURE_PHRASE_ARG"
146 if ($QUIET == NO
) then
151 if ($QUIET == NO
) then
152 echo Importing cleartext private key...
154 set cmd
="$KCIMPORT $PRIV_KEY_IN -k $KEYCHAIN -t priv -f $IN_FORM -e -K 1 $QUIET_ARG $NOACL_ARG"
155 if ($QUIET == NO
) then
162 # Export to cleartext private key format
164 if ($QUIET == NO
) then
165 echo Exporting to cleartext private key...
167 set cmd
="$KCEXPORT $KEYCHAIN -t privKeys -f $OUT_FORM -o $RAW_PRIV_KEY $QUIET_ARG"
168 if ($QUIET == NO
) then
174 # Import public key, and re-export it. When we're thru with this for all combinations
175 # of keys sent to us by importExportOpenssh, we know we can read every format that
176 # OpenSSH can generate.
178 switch
( $PUB_KEY_FORM )
181 set OUT_FORM
=openssh1
186 set OUT_FORM
=openssh2
190 echo See importExportOpensshTool
script for usage.
194 if ($QUIET == NO
) then
195 echo Importing public...
197 set cmd
="$KCIMPORT $PUB_KEY_IN -k $KEYCHAIN -t pub -f $IN_FORM -K 1 $QUIET_ARG"
198 if ($QUIET == NO
) then
206 if ($QUIET == NO
) then
207 echo Exporting public key...
209 set cmd
="$KCEXPORT $KEYCHAIN -t pubKeys -f $OUT_FORM -o $RAW_PUB_KEY $QUIET_ARG"
210 if ($QUIET == NO
) then
218 set cmd
="$RSATOOL s p=$PLAINTEXT s=$SIGFILE k=$RSA_TOOL_FILENAME v=$RSA_PRIV_FORM $ALG_ARG q"
219 if ($QUIET == NO
) then
223 set cmd
="$RSATOOL v p=$PLAINTEXT s=$SIGFILE k=$RSA_TOOL_FILENAME b=$RSA_PUB_FORM $ALG_ARG q"
224 if ($QUIET == NO
) then
230 # The incoming public key and the one we exported from the keychain should be identical.
232 set cmd
="$CMP $PUB_KEY_IN $RAW_PUB_KEY"
233 if ($QUIET == NO
) then
237 if($status != 0) then
238 echo MISCOMPARE on public key form
$PUB_KEY_FORM
243 # Verifying private keys is a little tricker. Only cleartext ssh2 keys can be
244 # verified by byte-for-byte compare, and then only after exporting them again
245 # in PEM armour. All the others have random data added.
247 set PEM_PRIV_KEY
=$BUILD_DIR/pemPrivKey
248 if($PRIV_KEY_FORM == ssh2
) then
249 set cmd
="$KCEXPORT $KEYCHAIN -t privKeys -f openssl -p -o $PEM_PRIV_KEY $QUIET_ARG"
250 if ($QUIET == NO
) then
254 set cmd
="$CMP $PRIV_KEY_IN $PEM_PRIV_KEY"
255 if ($QUIET == NO
) then
259 if($status != 0) then
260 echo MISCOMPARE on private key form
$PRIV_KEY_FORM
266 # We've verified that we write the following formats identically to OpenSSH:
269 # -- private unwrapped ssh2 (a.k.a. OpenSSL w/PEM)
271 # Since private wrapped SSH2 keys are in a format that we've verified
272 # extensively elsewhere (OpenSSL, in the importExportOpensslWrap script),
273 # all we really need to test here is ssh1 format. We'll test that
274 # via parsing keys with the sshKey program and comparing the output.
275 # This also verifies the comments in the generated keys, which should
276 # always match the comment of the original key (ssh-keygen key, import
277 # that, the resulting C item's PrintName has the comment; export that
278 # KC item and the original comment gets embedded in the new key).
282 switch
( $PRIV_KEY_FORM )
287 set PWDARG
="-p $PASSWORD"
294 echo BRRZZZAP
! Missed one here
! PRIV_KEY_FORM
$PRIV_KEY_FORM
298 set PARSE_REF
=$BUILD_DIR/parseRef
299 set PARSE_GEN
=$BUILD_DIR/parseGen
303 if ($QUIET == NO
) then
304 echo Parsing
$PRIV_KEY_IN and
$RAW_PRIV_KEY....
306 set cmd
="$SSHKEY -i $PRIV_KEY_IN -r -f ssh1 -v $PWDARG"
307 if ($QUIET == NO
) then
311 if($status != 0) then
312 echo Error parsing
$PRIV_KEY_IN.
315 set cmd
="$SSHKEY -i $RAW_PRIV_KEY -r -f ssh1 -v -P"
316 if ($QUIET == NO
) then
320 if($status != 0) then
321 echo Error parsing
$RAW_PRIV_KEY.
324 set cmd
="$CMP $PARSE_GEN $PARSE_REF"
325 if ($QUIET == NO
) then
329 if($status != 0) then
330 echo MISCOMPARE on parsed private keys
338 if($NOCLEAN == NO
) then
339 set cmd
="rm -f $RAW_PRIV_KEY $RAW_PUB_KEY $SIGFILE $PEM_PRIV_KEY $PARSE_REF $PARSE_GEN"
340 if ($QUIET == NO
) then