|
| 1 | +#!/bin/bash -e |
| 2 | +# Copyright (C) 2023 Simo Sorce <[email protected]> |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +# On Fedora they completely removed support for explicit EC from libcrypto, |
| 6 | +# so skip the test completely |
| 7 | +if [ -f /etc/fedora-release ]; then |
| 8 | + exit 0 |
| 9 | +fi |
| 10 | + |
| 11 | +source "${TESTSSRCDIR}/helpers.sh" |
| 12 | + |
| 13 | +title PARA "Export EC Public key to a file" |
| 14 | +ossl 'pkey -in $ECXPUBURI -pubin -pubout -out ${TMPPDIR}/ecout.pub' |
| 15 | +title LINE "Print EC Public key from private" |
| 16 | +ossl 'pkey -in $ECXPRIURI -pubout -text' "$helper_emit" |
| 17 | +output="$helper_output" |
| 18 | +FAIL=0 |
| 19 | +echo "$output" | grep "PKCS11 EC Public Key (190 bits)" > /dev/null 2>&1 || FAIL=1 |
| 20 | +if [ $FAIL -eq 1 ]; then |
| 21 | + echo "Pkcs11 encoder function failed" |
| 22 | + echo |
| 23 | + echo "Original command output:" |
| 24 | + echo "$output" |
| 25 | + echo |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +title PARA "Sign and Verify with provided Hash and EC" |
| 30 | +ossl 'dgst -sha256 -binary -out ${TMPPDIR}/sha256.bin ${SEEDFILE}' |
| 31 | +ossl ' |
| 32 | +pkeyutl -sign -inkey "${ECXBASEURI}" |
| 33 | + -in ${TMPPDIR}/sha256.bin |
| 34 | + -out ${TMPPDIR}/sha256-ecsig.bin' |
| 35 | + |
| 36 | +ossl ' |
| 37 | +pkeyutl -verify -inkey "${ECXBASEURI}" -pubin |
| 38 | + -in ${TMPPDIR}/sha256.bin |
| 39 | + -sigfile ${TMPPDIR}/sha256-ecsig.bin' |
| 40 | + |
| 41 | +ossl ' |
| 42 | +pkeyutl -verify -inkey "${TMPPDIR}/ecout.pub" -pubin |
| 43 | + -in ${TMPPDIR}/sha256.bin |
| 44 | + -sigfile ${TMPPDIR}/sha256-ecsig.bin' |
| 45 | + |
| 46 | +title PARA "DigestSign and DigestVerify with ECC (SHA-256)" |
| 47 | +ossl ' |
| 48 | +pkeyutl -sign -inkey "${ECXBASEURI}" |
| 49 | + -digest sha256 |
| 50 | + -in ${RAND64FILE} |
| 51 | + -rawin |
| 52 | + -out ${TMPPDIR}/sha256-ecdgstsig.bin' |
| 53 | +ossl ' |
| 54 | +pkeyutl -verify -inkey "${ECXBASEURI}" -pubin |
| 55 | + -digest sha256 |
| 56 | + -in ${RAND64FILE} |
| 57 | + -rawin |
| 58 | + -sigfile ${TMPPDIR}/sha256-ecdgstsig.bin' |
| 59 | + |
| 60 | +title PARA "DigestSign and DigestVerify with ECC (SHA-384)" |
| 61 | +ossl ' |
| 62 | +pkeyutl -sign -inkey "${ECXBASEURI}" |
| 63 | + -digest sha384 |
| 64 | + -in ${RAND64FILE} |
| 65 | + -rawin |
| 66 | + -out ${TMPPDIR}/sha384-ecdgstsig.bin' |
| 67 | +ossl ' |
| 68 | +pkeyutl -verify -inkey "${ECXBASEURI}" -pubin |
| 69 | + -digest sha384 |
| 70 | + -in ${RAND64FILE} |
| 71 | + -rawin |
| 72 | + -sigfile ${TMPPDIR}/sha384-ecdgstsig.bin' |
| 73 | + |
| 74 | +title PARA "DigestSign and DigestVerify with ECC (SHA-512)" |
| 75 | +ossl ' |
| 76 | +pkeyutl -sign -inkey "${ECXBASEURI}" |
| 77 | + -digest sha512 |
| 78 | + -in ${RAND64FILE} |
| 79 | + -rawin |
| 80 | + -out ${TMPPDIR}/sha512-ecdgstsig.bin' |
| 81 | +ossl ' |
| 82 | +pkeyutl -verify -inkey "${ECXBASEURI}" -pubin |
| 83 | + -digest sha512 |
| 84 | + -in ${RAND64FILE} |
| 85 | + -rawin |
| 86 | + -sigfile ${TMPPDIR}/sha512-ecdgstsig.bin' |
| 87 | + |
| 88 | +title PARA "DigestSign and DigestVerify with ECC (SHA3-256)" |
| 89 | +ossl ' |
| 90 | +pkeyutl -sign -inkey "${ECXBASEURI}" |
| 91 | + -digest sha3-256 |
| 92 | + -in ${RAND64FILE} |
| 93 | + -rawin |
| 94 | + -out ${TMPPDIR}/sha3-256-ecdgstsig.bin' |
| 95 | +ossl ' |
| 96 | +pkeyutl -verify -inkey "${ECXBASEURI}" -pubin |
| 97 | + -digest sha3-256 |
| 98 | + -in ${RAND64FILE} |
| 99 | + -rawin |
| 100 | + -sigfile ${TMPPDIR}/sha3-256-ecdgstsig.bin' |
| 101 | + |
| 102 | +title PARA "DigestSign and DigestVerify with ECC (SHA3-384)" |
| 103 | +ossl ' |
| 104 | +pkeyutl -sign -inkey "${ECXBASEURI}" |
| 105 | + -digest sha3-384 |
| 106 | + -in ${RAND64FILE} |
| 107 | + -rawin |
| 108 | + -out ${TMPPDIR}/sha3-384-ecdgstsig.bin' |
| 109 | +ossl ' |
| 110 | +pkeyutl -verify -inkey "${ECXBASEURI}" -pubin |
| 111 | + -digest sha3-384 |
| 112 | + -in ${RAND64FILE} |
| 113 | + -rawin |
| 114 | + -sigfile ${TMPPDIR}/sha3-384-ecdgstsig.bin' |
| 115 | + |
| 116 | +title PARA "DigestSign and DigestVerify with ECC (SHA3-512)" |
| 117 | +ossl ' |
| 118 | +pkeyutl -sign -inkey "${ECXBASEURI}" |
| 119 | + -digest sha3-512 |
| 120 | + -in ${RAND64FILE} |
| 121 | + -rawin |
| 122 | + -out ${TMPPDIR}/sha3-512-ecdgstsig.bin' |
| 123 | +ossl ' |
| 124 | +pkeyutl -verify -inkey "${ECXBASEURI}" -pubin |
| 125 | + -digest sha3-512 |
| 126 | + -in ${RAND64FILE} |
| 127 | + -rawin |
| 128 | + -sigfile ${TMPPDIR}/sha3-512-ecdgstsig.bin' |
| 129 | + |
| 130 | +title PARA "Test CSR generation from private ECC keys" |
| 131 | +ossl ' |
| 132 | +req -new -batch -key "${ECXPRIURI}" -out ${TMPPDIR}/ecdsa_csr.pem' |
| 133 | +ossl ' |
| 134 | +req -in ${TMPPDIR}/ecdsa_csr.pem -verify -noout' |
| 135 | + |
| 136 | +exit 0 |
0 commit comments