]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
pkcs11: tests for RSA, ECC, DSA private key import
authorJan Vcelak <jan.vcelak@nic.cz>
Fri, 26 Feb 2016 15:17:48 +0000 (16:17 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 27 Feb 2016 20:44:49 +0000 (21:44 +0100)
Signed-off-by: Jan Vcelak <jan.vcelak@nic.cz>
tests/suite/testpkcs11.sh

index 2c04dff48dcd0b02db253b7800b23b444e49f940..3b9c45085ac64a424edb7b3b9eef71b7a7e5f1d0 100755 (executable)
@@ -322,6 +322,53 @@ generate_temp_ecc_privkey () {
        fi
 }
 
+# $1: name
+# $2: label prefix
+# $3: generate option
+# $4: token
+# $5: PIN
+# $6: bits
+import_privkey () {
+       export GNUTLS_PIN="$5"
+       name="$1"
+       prefix="$2"
+       gen_option="$3"
+       token="$4"
+       bits="$6"
+
+       outfile="tmp-${prefix}-${bits}.pem"
+
+       echo -n "* Importing ${name} private key (${bits})... "
+
+       "${CERTTOOL}" ${CERTTOOL_PARAM} --generate-privkey "${gen_option}" --pkcs8 --password= --outfile "${outfile}" >>"${TMPFILE}" 2>&1
+       if test $? != 0; then
+               RETCODE=1
+               echo failed
+               return
+       fi
+
+       ${P11TOOL} ${ADDITIONAL_PARAM} --login --write --label "${prefix}-${bits}" --load-privkey "${outfile}" "${token}" >>"${TMPFILE}" 2>&1
+       if test $? = 0; then
+               RETCODE=0
+               echo ok
+       else
+               echo failed
+               RETCODE=1
+       fi
+}
+
+import_temp_rsa_privkey () {
+       import_privkey RSA temp-rsa --rsa $@
+}
+
+import_temp_ecc_privkey () {
+       import_privkey ECC temp-ecc --ecc $@
+}
+
+import_temp_dsa_privkey () {
+       import_privkey DSA temp-dsa --dsa $@
+}
+
 # $1: token
 # $2: PIN
 # $3: cakey: ${srcdir}/pkcs11-certs/ca.key
@@ -556,6 +603,13 @@ delete_temp_privkey "${TOKEN}" "${GNUTLS_PIN}" rsa-2048
 generate_temp_dsa_privkey "${TOKEN}" "${GNUTLS_PIN}" 3072
 delete_temp_privkey "${TOKEN}" "${GNUTLS_PIN}" dsa-3072
 
+import_temp_rsa_privkey "${TOKEN}" "${GNUTLS_PIN}" 1024
+delete_temp_privkey "${TOKEN}" "${GNUTLS_PIN}" rsa-1024
+import_temp_ecc_privkey "${TOKEN}" "${GNUTLS_PIN}" 256
+delete_temp_privkey "${TOKEN}" "${GNUTLS_PIN}" ecc-256
+import_temp_dsa_privkey "${TOKEN}" "${GNUTLS_PIN}" 2048
+delete_temp_privkey "${TOKEN}" "${GNUTLS_PIN}" dsa-2048
+
 generate_rsa_privkey "${TOKEN}" "${GNUTLS_PIN}" 1024
 change_id_of_privkey "${TOKEN}" "${GNUTLS_PIN}"
 export_pubkey_of_privkey "${TOKEN}" "${GNUTLS_PIN}"