Add private/public key conversion tests

Reviewed-by: Matt Caswell <matt@openssl.org>
This commit is contained in:
Dr. Stephen Henson 2015-03-26 15:56:00 +00:00
parent b1f3442857
commit 79a578b902
8 changed files with 145 additions and 87 deletions

View file

@ -231,8 +231,9 @@ test_x509: ../apps/openssl$(EXE_EXT) tx509 testx509.pem v3-cert1.pem v3-cert2.pe
echo test second x509v3 certificate echo test second x509v3 certificate
sh ./tx509 v3-cert2.pem 2>/dev/null sh ./tx509 v3-cert2.pem 2>/dev/null
test_rsa: $(RSATEST)$(EXE_EXT) ../apps/openssl$(EXE_EXT) trsa testrsa.pem test_rsa: $(RSATEST)$(EXE_EXT) ../apps/openssl$(EXE_EXT) tkey testrsa.pem
@sh ./trsa 2>/dev/null @sh ./tkey testrsa.pem rsa private 2>/dev/null
@sh ./tkey testrsapub.pem rsa public 2>/dev/null
../util/shlib_wrap.sh ./$(RSATEST) ../util/shlib_wrap.sh ./$(RSATEST)
test_crl: ../apps/openssl$(EXE_EXT) tcrl testcrl.pem test_crl: ../apps/openssl$(EXE_EXT) tcrl testcrl.pem
@ -258,9 +259,11 @@ test_bn: $(BNTEST)$(EXE_EXT) $(EXPTEST)$(EXE_EXT) bctest
@echo 'test a^b%c implementations' @echo 'test a^b%c implementations'
../util/shlib_wrap.sh ./$(EXPTEST) ../util/shlib_wrap.sh ./$(EXPTEST)
test_ec: $(ECTEST)$(EXE_EXT) test_ec: $(ECTEST)$(EXE_EXT) tkey testec-p256.pem
@echo 'test elliptic curves' @echo 'test elliptic curves'
../util/shlib_wrap.sh ./$(ECTEST) ../util/shlib_wrap.sh ./$(ECTEST)
@sh ./tkey testec-p256.pem ec private 2>/dev/null
@sh ./tkey testecpub-p256.pem ec public 2>/dev/null
test_ecdsa: $(ECDSATEST)$(EXE_EXT) test_ecdsa: $(ECDSATEST)$(EXE_EXT)
@echo 'test ecdsa' @echo 'test ecdsa'
@ -279,10 +282,12 @@ test_dh: $(DHTEST)$(EXE_EXT)
@echo "Generate a set of DH parameters" @echo "Generate a set of DH parameters"
../util/shlib_wrap.sh ./$(DHTEST) ../util/shlib_wrap.sh ./$(DHTEST)
test_dsa: $(DSATEST)$(EXE_EXT) test_dsa: $(DSATEST)$(EXE_EXT) tkey testdsa.pem
@echo "Generate a set of DSA parameters" @echo "Generate a set of DSA parameters"
../util/shlib_wrap.sh ./$(DSATEST) ../util/shlib_wrap.sh ./$(DSATEST)
../util/shlib_wrap.sh ./$(DSATEST) -app2_1 ../util/shlib_wrap.sh ./$(DSATEST) -app2_1
@sh ./tkey testdsa.pem dsa private 2>/dev/null
@sh ./tkey testdsapub.pem dsa public 2>/dev/null
test_gen testreq.pem: ../apps/openssl$(EXE_EXT) testgen test.cnf test_gen testreq.pem: ../apps/openssl$(EXE_EXT) testgen test.cnf
@echo "Generate and verify a certificate request" @echo "Generate and verify a certificate request"

12
test/testdsa.pem Normal file
View file

@ -0,0 +1,12 @@
-----BEGIN DSA PRIVATE KEY-----
MIIBvQIBAAKBgQD9Ko2Ezy2mKeOV4oJsjy8Ves9Av6bPvr5y6iFTVpGQewjzsAHS
l3eAxwyrvE0cx8cQ4ODieVRnWibZIEoF2NRUBw3l/6o8wo1BZTnF7wtZpNr6QcCQ
QNC3CaQZ0lw2rOewGxqZpeXmYurfceRnsZBSpQiw8kW+JTgCbRJtVAYF1wIVAN+X
sK/vqcIQlD6ZV055LoV4qv0jAoGBAL52x3C4paZkU61ZTiIgUKPXBpanQ4a7nsjd
iSjzgnto+rveVuFkZQKaD7Wts8SLpojBat7supr+qF1pWVpRwxOXofdO72XdKm5u
3co7sLnqf/WVCmzX9/unlAsGfDG1R6RqA71MnQJ5q56LwAzqK23ZfGt5v1Wpho36
FY/JnLZ2AoGBAMyZoH2YF7/wO7CbGD6bGet3q+zxksOp+6gz2+ae23Gajpd3u4Jz
bOxqjk4vrQaTrMPRRWXWJxC5WwLMalzwke75wi8gGT6+EUxFoLXlSmRQN+h4f+Ab
OHFQiiW9v3xrgUKPiYWPEz/bhYw5DC73vPfkHXxmV495KiSIx4fvfH1BAhUAv3HU
l7iXVdDF5BKF2B+Vd8w9+MI=
-----END DSA PRIVATE KEY-----

12
test/testdsapub.pem Normal file
View file

@ -0,0 +1,12 @@
-----BEGIN PUBLIC KEY-----
MIIBuDCCASwGByqGSM44BAEwggEfAoGBAP0qjYTPLaYp45XigmyPLxV6z0C/ps++
vnLqIVNWkZB7CPOwAdKXd4DHDKu8TRzHxxDg4OJ5VGdaJtkgSgXY1FQHDeX/qjzC
jUFlOcXvC1mk2vpBwJBA0LcJpBnSXDas57AbGpml5eZi6t9x5GexkFKlCLDyRb4l
OAJtEm1UBgXXAhUA35ewr++pwhCUPplXTnkuhXiq/SMCgYEAvnbHcLilpmRTrVlO
IiBQo9cGlqdDhrueyN2JKPOCe2j6u95W4WRlApoPta2zxIumiMFq3uy6mv6oXWlZ
WlHDE5eh907vZd0qbm7dyjuwuep/9ZUKbNf3+6eUCwZ8MbVHpGoDvUydAnmrnovA
DOorbdl8a3m/VamGjfoVj8mctnYDgYUAAoGBAMyZoH2YF7/wO7CbGD6bGet3q+zx
ksOp+6gz2+ae23Gajpd3u4JzbOxqjk4vrQaTrMPRRWXWJxC5WwLMalzwke75wi8g
GT6+EUxFoLXlSmRQN+h4f+AbOHFQiiW9v3xrgUKPiYWPEz/bhYw5DC73vPfkHXxm
V495KiSIx4fvfH1B
-----END PUBLIC KEY-----

5
test/testec-p256.pem Normal file
View file

@ -0,0 +1,5 @@
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIDYEX2yQlhJXDIwBEwcfyAn2eICEKJxqsAPGChey1a2toAoGCCqGSM49
AwEHoUQDQgAEJXwAdITiPFcSUsaRI2nlzTNRn++q6F38XrH8m8sf28DQ+2Oob5SU
zvgjVS0e70pIqH6bSXDgPc8mKtSs9Zi26Q==
-----END EC PRIVATE KEY-----

4
test/testecpub-p256.pem Normal file
View file

@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEJXwAdITiPFcSUsaRI2nlzTNRn++q
6F38XrH8m8sf28DQ+2Oob5SUzvgjVS0e70pIqH6bSXDgPc8mKtSs9Zi26Q==
-----END PUBLIC KEY-----

4
test/testrsapub.pem Normal file
View file

@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6diz
WW3DwaffznyHGAFwUJ/ITv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQ==
-----END PUBLIC KEY-----

99
test/tkey Normal file
View file

@ -0,0 +1,99 @@
#!/bin/sh
t=$1
ktype=$2
ptype=$3
if ../util/shlib_wrap.sh ../apps/openssl no-$ktype; then
echo skipping $ktype $ptype conversion test
exit 0
fi
if [ $ptype = "public" ]; then
cmd="../util/shlib_wrap.sh ../apps/openssl $ktype -pubin -pubout"
else
cmd="../util/shlib_wrap.sh ../apps/openssl $ktype"
fi
echo testing $ktype $ptype conversions
cp $t $ktype-fff.p
echo "p -> d"
$cmd -in $ktype-fff.p -inform p -outform d >$ktype-f.d
if [ $? != 0 ]; then exit 1; fi
echo "p -> p"
$cmd -in $ktype-fff.p -inform p -outform p >$ktype-f.p
if [ $? != 0 ]; then exit 1; fi
echo "d -> d"
$cmd -in $ktype-f.d -inform d -outform d >$ktype-ff.d1
if [ $? != 0 ]; then exit 1; fi
echo "p -> d"
$cmd -in $ktype-f.p -inform p -outform d >$ktype-ff.d3
if [ $? != 0 ]; then exit 1; fi
echo "d -> p"
$cmd -in $ktype-f.d -inform d -outform p >$ktype-ff.p1
if [ $? != 0 ]; then exit 1; fi
echo "p -> p"
$cmd -in $ktype-f.p -inform p -outform p >$ktype-ff.p3
if [ $? != 0 ]; then exit 1; fi
cmp $ktype-fff.p $ktype-f.p
if [ $? != 0 ]; then exit 1; fi
cmp $ktype-fff.p $ktype-ff.p1
if [ $? != 0 ]; then exit 1; fi
cmp $ktype-fff.p $ktype-ff.p3
if [ $? != 0 ]; then exit 1; fi
cmp $ktype-f.p $ktype-ff.p1
if [ $? != 0 ]; then exit 1; fi
cmp $ktype-f.p $ktype-ff.p3
if [ $? != 0 ]; then exit 1; fi
/bin/rm -f $ktype-f.* $ktype-ff.* $ktype-fff.*
if [ $ptype = "public" ]; then
exit 0
fi
cmd="../util/shlib_wrap.sh ../apps/openssl pkey"
echo testing $ktype PKCS#8 conversions
$cmd -in $t -out $ktype-fff.p
echo "p -> d"
$cmd -in $ktype-fff.p -inform p -outform d >$ktype-f.d
if [ $? != 0 ]; then exit 1; fi
echo "p -> p"
$cmd -in $ktype-fff.p -inform p -outform p >$ktype-f.p
if [ $? != 0 ]; then exit 1; fi
echo "d -> d"
$cmd -in $ktype-f.d -inform d -outform d >$ktype-ff.d1
if [ $? != 0 ]; then exit 1; fi
echo "p -> d"
$cmd -in $ktype-f.p -inform p -outform d >$ktype-ff.d3
if [ $? != 0 ]; then exit 1; fi
echo "d -> p"
$cmd -in $ktype-f.d -inform d -outform p >$ktype-ff.p1
if [ $? != 0 ]; then exit 1; fi
echo "p -> p"
$cmd -in $ktype-f.p -inform p -outform p >$ktype-ff.p3
if [ $? != 0 ]; then exit 1; fi
cmp $ktype-fff.p $ktype-f.p
if [ $? != 0 ]; then exit 1; fi
cmp $ktype-fff.p $ktype-ff.p1
if [ $? != 0 ]; then exit 1; fi
cmp $ktype-fff.p $ktype-ff.p3
if [ $? != 0 ]; then exit 1; fi
cmp $ktype-f.p $ktype-ff.p1
if [ $? != 0 ]; then exit 1; fi
cmp $ktype-f.p $ktype-ff.p3
if [ $? != 0 ]; then exit 1; fi
/bin/rm -f $ktype-f.* $ktype-ff.* $ktype-fff.*

View file

@ -1,83 +0,0 @@
#!/bin/sh
if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
echo skipping rsa conversion test
exit 0
fi
cmd='../util/shlib_wrap.sh ../apps/openssl rsa'
if [ "$1"x != "x" ]; then
t=$1
else
t=testrsa.pem
fi
echo testing rsa conversions
cp $t rsa-fff.p
echo "p -> d"
$cmd -in rsa-fff.p -inform p -outform d >rsa-f.d
if [ $? != 0 ]; then exit 1; fi
#echo "p -> t"
#$cmd -in rsa-fff.p -inform p -outform t >rsa-f.t
#if [ $? != 0 ]; then exit 1; fi
echo "p -> p"
$cmd -in rsa-fff.p -inform p -outform p >rsa-f.p
if [ $? != 0 ]; then exit 1; fi
echo "d -> d"
$cmd -in rsa-f.d -inform d -outform d >rsa-ff.d1
if [ $? != 0 ]; then exit 1; fi
#echo "t -> d"
#$cmd -in rsa-f.t -inform t -outform d >rsa-ff.d2
#if [ $? != 0 ]; then exit 1; fi
echo "p -> d"
$cmd -in rsa-f.p -inform p -outform d >rsa-ff.d3
if [ $? != 0 ]; then exit 1; fi
#echo "d -> t"
#$cmd -in rsa-f.d -inform d -outform t >rsa-ff.t1
#if [ $? != 0 ]; then exit 1; fi
#echo "t -> t"
#$cmd -in rsa-f.t -inform t -outform t >rsa-ff.t2
#if [ $? != 0 ]; then exit 1; fi
#echo "p -> t"
#$cmd -in rsa-f.p -inform p -outform t >rsa-ff.t3
#if [ $? != 0 ]; then exit 1; fi
echo "d -> p"
$cmd -in rsa-f.d -inform d -outform p >rsa-ff.p1
if [ $? != 0 ]; then exit 1; fi
#echo "t -> p"
#$cmd -in rsa-f.t -inform t -outform p >rsa-ff.p2
#if [ $? != 0 ]; then exit 1; fi
echo "p -> p"
$cmd -in rsa-f.p -inform p -outform p >rsa-ff.p3
if [ $? != 0 ]; then exit 1; fi
cmp rsa-fff.p rsa-f.p
if [ $? != 0 ]; then exit 1; fi
cmp rsa-fff.p rsa-ff.p1
if [ $? != 0 ]; then exit 1; fi
#cmp rsa-fff.p rsa-ff.p2
#if [ $? != 0 ]; then exit 1; fi
cmp rsa-fff.p rsa-ff.p3
if [ $? != 0 ]; then exit 1; fi
#cmp rsa-f.t rsa-ff.t1
#if [ $? != 0 ]; then exit 1; fi
#cmp rsa-f.t rsa-ff.t2
#if [ $? != 0 ]; then exit 1; fi
#cmp rsa-f.t rsa-ff.t3
#if [ $? != 0 ]; then exit 1; fi
cmp rsa-f.p rsa-ff.p1
if [ $? != 0 ]; then exit 1; fi
#cmp rsa-f.p rsa-ff.p2
#if [ $? != 0 ]; then exit 1; fi
cmp rsa-f.p rsa-ff.p3
if [ $? != 0 ]; then exit 1; fi
/bin/rm -f rsa-f.* rsa-ff.* rsa-fff.*
exit 0