Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Run more TLS tests when forcing all server operations on token #453

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/test-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ LOGFILE="${TESTBLDDIR}/${TEST_NAME}.${TOKEN_DRIVER}.log"
echo "Executing ${COMMAND}"
(
set -o pipefail
${COMMAND} | tee "${LOGFILE}"
${COMMAND} 2>&1 | tee "${LOGFILE}"
)
56 changes: 37 additions & 19 deletions tests/ttls
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ run_test() {
set timeout 60;
expect {
\"ACCEPT\" {};
eof { exit 2; }
default {
send \" NO ACCEPT \n\";
exit 1;
Expand All @@ -52,6 +53,7 @@ run_test() {
close \$server_ready;
expect {
\"END SSL SESSION PARAMETERS\" {};
eof { exit 2; }
default {
send \" NO SESSION PARAMETERS \n\";
exit 1;
Expand All @@ -65,15 +67,19 @@ run_test() {
send \" NO EOF \n\";
exit 1;
};
}" > "${TMPPDIR}/s_server_output" &
}" &> "${TMPPDIR}/s_server_output" &
SERVER_PID=$!

read -r < "${TMPPDIR}/s_server_ready"

# FIXME For now we strive to test the server. The client causes some unrelated issues that will have to
# be handled later
OPENSSL_CONF="${ORIG_OPENSSL_CONF}" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we want this, we want to be able to test forcing both server an client.
If we do this then we'd have to add a test matrix where we try all combinations of forcing server and client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yes. But it does not work without this, even the basic case fails now with:

########################################
## Forcing the provider for all server operations


## Run sanity test with default values (RSA)
spawn openssl s_client -connect localhost:23456 -CAfile /home/jjelen/devel/pkcs11-provider/builddir/tests/softokn/CAcert.pem
Connecting to ::1
CONNECTED(00000004)
Can't use SSL_get_servername
depth=1 CN=Issuer
verify return:1
depth=0 O=PKCS11 Provider, CN=My Test Cert
verify return:1
80D25E0D127F0000:error:40800070:pkcs11:p11prov_rsasig_set_ctx_params:An invalid mechanism was specified to the cryptographic operation:../src/signature.c:1532:CKM_RSA_PKCS_PSS unavailable
80D25E0D127F0000:error:0A080006:SSL routines:tls_process_cert_verify:EVP lib:ssl/statem/statem_lib.c:560:
---
Certificate chain
 0 s:O=PKCS11 Provider, CN=My Test Cert
   i:CN=Issuer
   a:PKEY: rsaEncryption, 2048 (bit); sigalg: RSA-SHA256
   v:NotBefore: Oct 21 07:58:11 2024 GMT; NotAfter: Oct 21 07:58:11 2025 GMT
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIDPzCCAiegAwIBAgIBAzANBgkqhkiG9w0BAQsFADARMQ8wDQYDVQQDEwZJc3N1
ZXIwHhcNMjQxMDIxMDc1ODExWhcNMjUxMDIxMDc1ODExWjAxMRgwFgYDVQQKEw9Q
S0NTMTEgUHJvdmlkZXIxFTATBgNVBAMTDE15IFRlc3QgQ2VydDCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBAMyqHVpQB9mfrimSiIdV34EU8FyVc+o1SIRq
jRsoo3F93VLhhaOpje1EQ3I0bDOKSr8fT+pjReHENkOycnbzw2eE6eAeaDlNYU51
MRNp0eZY0/K9WRZDppkc+i/Z9G5jj+wyZgNSUS2EmYvz9vTXcdG8cPLdyTBm2/U3
JIQDZPJ9UmavFa0Ojr2MiDDTY/dWxXPUIoMf4dQ/ppKa4e++XUteh9LvONqMY6RU
P9JhkbXGGmQiLyVVkD3pwSDZG7M3g3AdDl4BQhU5/v/G0ETHWbKmKnzpDCJ2FJah
VBWx0jZgbwNiGQ9j8shs12lEX5YMezDu/NCE3ZgaVORDwdtbpWUCAwEAAaOBgTB/
MAwGA1UdEwEB/wQCMAAwHwYDVR0RBBgwFoEUdGVzdGNlcnRAZXhhbXBsZS5vcmcw
DgYDVR0PAQH/BAQDAgWgMB0GA1UdDgQWBBSP4+rrZTwRXWi4OdqhdTseOJC2FTAf
BgNVHSMEGDAWgBRgYl8qthze3R6sKMpf02knjzgH9DANBgkqhkiG9w0BAQsFAAOC
AQEAA9qDTCeoOQox2oOkq/XlIek4XcCMjvCkiJdGmuPkDLit4sExalldkMPkds5W
n+BMAYObkPK7QmuZVXWtQYnMSm62N2ejNdSD+Dc/uUEp8KkznFhC6wsuScrjEwOh
oacfvKUS8BslUhRrTgDGQ9cvvI4gjHRzkQmNagmoR1vkbZGJGcQE9tte1WD+OtCZ
9t1uXr6q2hvb30jlsb/EUbfLYBEvC0sTyQ/n/ucmCcTg9GSBy/IcaiWYxng2grNl
Ox6zIE21D/5PUtD+nZsakdDZPuxAe/nfbys8yb5pPMGJ5mZQfUgdxvkO0+iGBtTP
pJrlJI/9/0yU94guAgco1Nwdbg==
-----END CERTIFICATE-----
subject=O=PKCS11 Provider, CN=My Test Cert
issuer=CN=Issuer
---
No client certificate CA names sent
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 1317 bytes and written 321 bytes
Verification: OK
---
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 2048 bit
This TLS version forbids renegotiation.
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
/home/jjelen/devel/pkcs11-provider/tests/ttls: line 28: wait: pid 380444 is not a child of this shell
Server output:
spawn openssl s_server -accept 23456 -naccept 1 -key pkcs11:type=private;id=%00%01 -cert pkcs11:type=cert;object=testCert
Using default temp DH parameters
ACCEPT
ERROR
80D23BA1F87F0000:error:40800091:pkcs11:p11prov_GetOperationState:There is no active operation of appropriate type in the specified session:../src/interface.gen.c:335:Error returned by C_GetOperationState
80D23BA1F87F0000:error:0A000438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error:ssl/record/rec_layer_s3.c:909:SSL alert number 80
shutting down SSL
CONNECTION CLOSED
   0 items in the session cache
   0 client connects (SSL_connect())
   0 client renegotiates (SSL_connect())
   0 client connects that finished
   1 server accepts (SSL_accept())
   0 server renegotiates (SSL_accept())
   0 server accepts that finished
   0 session cache hits
   0 session cache misses
   0 session cache timeouts
   0 callback cache hits
   0 cache full overflows (128 allowed)

I am not sure which of the failures is the problem, but I assume the mechanism issue? The debug log shows the following issues:

[../src/interface.gen.c:950] p11prov_VerifyFinal(): Calling C_VerifyFinal
[../src/objects.c:435] p11prov_obj_free(): Free Object: 0x555a26466fa0 (handle:1)
[../src/objects.c:442] p11prov_obj_free(): object free: reference held
[../src/objects.c:435] p11prov_obj_free(): Free Object: 0x555a26466fa0 (handle:1)
[../src/objects.c:442] p11prov_obj_free(): object free: reference held
[../src/keymgmt.c:713] p11prov_rsa_has(): rsa has 0x555a264a76d0 4
[../src/signature.c:1257] p11prov_rsasig_digest_verify_init(): rsa digest verify init (ctx=0x555a264b9ee0, key=0x555a264a76d0, params=(nil))
[../src/objects.c:404] p11prov_obj_ref_no_cache(): Ref Object: 0x555a264a76d0 (handle:18446744073709551614)
[../src/provider.c:607] p11prov_ctx_cache_keys(): cache_keys = 1
[../src/signature.c:1460] p11prov_rsasig_set_ctx_params(): rsasig set ctx params (ctx=0x555a264b9ee0, params=(nil))
[../src/signature.c:1460] p11prov_rsasig_set_ctx_params(): rsasig set ctx params (ctx=0x555a264b9ee0, params=0x7ffd3e343650)
[../src/signature.c:1494] p11prov_rsasig_set_ctx_params(): Set OSSL_SIGNATURE_PARAM_PAD_MODE to 6
[../src/signature.c:1532] p11prov_rsasig_set_ctx_params(): Error: 0x00000070; CKM_RSA_PKCS_PSS unavailable

This error condition has the following code comment:

/* some modules do not support PSS so we need to return
* an error early if we try to select this. Unfortunately
* although openssl has separate keymgmt for PKCS vs PSS
* padding, it consider RSA always capable to be performed
* regardless, and this is not the case in PKCS#11 */

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetOperationState failure is suspicious, sounds like we are simply not raising on the correct error, and that's the only thing left on the stack.

So the problem here is that OpenSSL is trying to do RSA PSS, can we change the options to force ECDSA and see if that makes it work?

Also all three tokens should support PSS, is this failing with on or all of them ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not try kryoptic, but the same test fails on both softhsm and softokn. If I switch to the second test (ecdsa), it fails with the test same way, but I do not see any obvious error except for the operation state error.

expect -c "spawn $CHECKER openssl s_client -connect \"localhost:${PORT}\" -CAfile \"${CACRT}\" $CLNT_ARGS;
set timeout 60;
expect {
\" TLS SUCCESSFUL \" {};
eof { exit 2; }
default {
send \" NO TLS SUCCESSFUL MESSAGE \n\";
exit 1;
Expand All @@ -85,41 +91,53 @@ run_test() {
send \" NO EOF \n\";
exit 1;
};
}"
}" || (wait_for_server_at_exit $SERVER_PID; exit 1; )

wait_for_server_at_exit $SERVER_PID
simo5 marked this conversation as resolved.
Show resolved Hide resolved
}

title PARA "Run sanity test with default values (RSA)"
run_test "$PRIURI" "$CRTURI"
run_tests() {

title PARA "Run sanity test with default values (ECDSA)"
run_test "$ECPRIURI" "$ECCRTURI"
title PARA "Run sanity test with default values (RSA)"
run_test "$PRIURI" "$CRTURI"

title PARA "Run test with TLS 1.2"
run_test "$PRIURI" "$CRTURI" "" "-tls1_2"
title PARA "Run sanity test with default values (ECDSA)"
run_test "$ECPRIURI" "$ECCRTURI"

title PARA "Run test with explicit TLS 1.3"
run_test "$PRIURI" "$CRTURI" "" "-tls1_3"
title PARA "Run test with TLS 1.2"
run_test "$PRIURI" "$CRTURI" "" "-tls1_2"

title PARA "Run test with TLS 1.2 (ECDSA)"
run_test "$ECPRIURI" "$ECCRTURI" "" "-tls1_2"
title PARA "Run test with explicit TLS 1.3"
run_test "$PRIURI" "$CRTURI" "" "-tls1_3"

title PARA "Run test with TLS 1.2 and ECDH"
run_test "$ECPRIURI" "$ECCRTURI" "" "-tls1_2 -cipher ECDHE-ECDSA-AES128-GCM-SHA256 -groups secp256r1"
title PARA "Run test with TLS 1.2 (ECDSA)"
run_test "$ECPRIURI" "$ECCRTURI" "-tls1_2" "-tls1_2"

title PARA "Run test with TLS 1.2 and ECDH"
run_test "$ECPRIURI" "$ECCRTURI" "" "-tls1_2 -cipher ECDHE-ECDSA-AES128-GCM-SHA256 -groups secp256r1"

title PARA "Run test with TLS 1.3 and specific suite"
run_test "$ECPRIURI" "$ECCRTURI" "" "-tls1_3 -ciphersuites TLS_AES_256_GCM_SHA384 -groups secp256r1"
}

title SECTION "TLS with key in provider"
# needed to restore the openssl conf for the client
ORIG_OPENSSL_CONF=${OPENSSL_CONF}
run_tests
title ENDSECTION

title SECTION "Forcing the provider for all server operations"
#Try again forcing all operations on the token
#We need to disable digest operations as OpenSSL depends on context duplication working
ORIG_OPENSSL_CONF=${OPENSSL_CONF}
sed -e "s/#MORECONF/alg_section = algorithm_sec\n\n[algorithm_sec]\ndefault_properties = ?provider=pkcs11/" \
-e "s/#pkcs11-module-block-operations/pkcs11-module-block-operations = digest/" \
sed -e "s/^#MORECONF/alg_section = algorithm_sec\n\n[algorithm_sec]\ndefault_properties = ?provider=pkcs11/" \
-e "s/^#pkcs11-module-block-operations/pkcs11-module-block-operations = digest/" \
"${OPENSSL_CONF}" > "${OPENSSL_CONF}.forcetoken"
OPENSSL_CONF=${OPENSSL_CONF}.forcetoken

title PARA "Run test with TLS 1.3 preferring token functions"
run_test "$ECPRIURI" "$ECCRTURI" "" "-tls1_3"
run_tests

OPENSSL_CONF=${ORIG_OPENSSL_CONF}

title ENDSECTION

exit 0;
Loading