From: Viktor Dukhovni Date: Thu, 13 Feb 2025 15:07:14 +0000 (+1100) Subject: Accessors for the IANA signature scheme name X-Git-Tag: openssl-3.5.0-alpha1~475 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=594cef49b4e85839983aea083ed9497330421abb;p=thirdparty%2Fopenssl.git Accessors for the IANA signature scheme name This is the official name of the signature algorithm(s) used by the peer and/or local end of the connection, and should be available, e.g. for logging. Reviewed-by: Tim Hudson Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/26738) --- diff --git a/apps/lib/s_cb.c b/apps/lib/s_cb.c index ca665685a06..99a23bffc11 100644 --- a/apps/lib/s_cb.c +++ b/apps/lib/s_cb.c @@ -1306,6 +1306,7 @@ void print_verify_detail(SSL *s, BIO *bio) void print_ssl_summary(SSL *s) { + const char *sigalg; const SSL_CIPHER *c; X509 *peer = SSL_get0_peer_certificate(s); EVP_PKEY *peer_rpk = SSL_get0_peer_rpk(s); @@ -1323,13 +1324,13 @@ void print_ssl_summary(SSL *s) BIO_puts(bio_err, "\n"); if (SSL_get_peer_signature_nid(s, &nid)) BIO_printf(bio_err, "Hash used: %s\n", OBJ_nid2sn(nid)); - if (SSL_get_peer_signature_type_nid(s, &nid)) - BIO_printf(bio_err, "Signature type: %s\n", get_sigtype(nid)); + if (SSL_get0_peer_signature_name(s, &sigalg)) + BIO_printf(bio_err, "Signature type: %s\n", sigalg); print_verify_detail(s, bio_err); } else if (peer_rpk != NULL) { BIO_printf(bio_err, "Peer used raw public key\n"); - if (SSL_get_peer_signature_type_nid(s, &nid)) - BIO_printf(bio_err, "Signature type: %s\n", get_sigtype(nid)); + if (SSL_get0_peer_signature_name(s, &sigalg)) + BIO_printf(bio_err, "Signature type: %s\n", sigalg); print_verify_detail(s, bio_err); } else { BIO_puts(bio_err, "No peer certificate or raw public key\n"); diff --git a/doc/man3/SSL_get_peer_signature_nid.pod b/doc/man3/SSL_get_peer_signature_nid.pod index 7776f3e2573..5518a9cfc78 100644 --- a/doc/man3/SSL_get_peer_signature_nid.pod +++ b/doc/man3/SSL_get_peer_signature_nid.pod @@ -2,21 +2,31 @@ =head1 NAME -SSL_get_peer_signature_nid, SSL_get_peer_signature_type_nid, -SSL_get_signature_nid, SSL_get_signature_type_nid - get TLS message signing -types +SSL_get0_peer_signature_name, SSL_get_peer_signature_nid, +SSL_get_peer_signature_type_nid, SSL_get0_signature_name, +SSL_get_signature_nid, SSL_get_signature_type_nid - +get TLS message signing types =head1 SYNOPSIS #include + int SSL_get0_peer_signature_name(const SSL *ssl, const char **sigalg); int SSL_get_peer_signature_nid(SSL *ssl, int *psig_nid); int SSL_get_peer_signature_type_nid(const SSL *ssl, int *psigtype_nid); + int SSL_get0_signature_name(SSL *ssl, const char **sigalg); int SSL_get_signature_nid(SSL *ssl, int *psig_nid); int SSL_get_signature_type_nid(const SSL *ssl, int *psigtype_nid); =head1 DESCRIPTION +SSL_get0_peer_signature_name() sets I<*sigalg> to the IANA name of the +L +used by the peer to sign the TLS handshake. +The caller must not free the returned pointer. +The returned string should be copied if it is to be retained beyond the +lifetime of the SSL connection. + SSL_get_peer_signature_nid() sets B<*psig_nid> to the NID of the digest used by the peer to sign TLS messages. It is implemented as a macro. @@ -27,23 +37,31 @@ where it is B. To differentiate between B and B signatures, it's necessary to check the type of public key in the peer's certificate. -SSL_get_signature_nid() and SSL_get_signature_type_nid() return the equivalent -information for the local end of the connection. +SSL_get0_signature_name(), SSL_get_signature_nid() and +SSL_get_signature_type_nid() return the equivalent information for the local +end of the connection. =head1 RETURN VALUES These functions return 1 for success and 0 for failure. There are several -possible reasons for failure: the cipher suite has no signature (e.g. it -uses RSA key exchange or is anonymous), the TLS version is below 1.2 or -the functions were called too early, e.g. before the peer signed a message. +possible reasons for failure: the peer or local end is a client and did not +sign the handshake (did not use a client certificate), the cipher suite has no +signature (e.g. it uses RSA key exchange or is anonymous), the TLS version is +below 1.2 or the functions were called too early, e.g. before the peer signed a +message. =head1 SEE ALSO L, L, +=head1 HISTORY + +The SSL_get0_peer_signature_name() and SSL_get0_signature_name() functions were +added in OpenSSL 3.5. + =head1 COPYRIGHT -Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2017-2025 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man7/EVP_KEM-ML-KEM.pod b/doc/man7/EVP_KEM-ML-KEM.pod index ea763b93a29..982721af3f8 100644 --- a/doc/man7/EVP_KEM-ML-KEM.pod +++ b/doc/man7/EVP_KEM-ML-KEM.pod @@ -54,7 +54,7 @@ This functionality was added in OpenSSL 3.5. =head1 COPYRIGHT -Copyright 2024 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/doc/man7/EVP_PKEY-ML-KEM.pod b/doc/man7/EVP_PKEY-ML-KEM.pod index 07ede01cf02..f1cbf9104d4 100644 --- a/doc/man7/EVP_PKEY-ML-KEM.pod +++ b/doc/man7/EVP_PKEY-ML-KEM.pod @@ -304,7 +304,7 @@ This functionality was added in OpenSSL 3.5. =head1 COPYRIGHT -Copyright 2024 The OpenSSL Project Authors. All Rights Reserved. +Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved. Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy diff --git a/include/openssl/ssl.h.in b/include/openssl/ssl.h.in index 9036e23f7d0..4cd9f3292ae 100644 --- a/include/openssl/ssl.h.in +++ b/include/openssl/ssl.h.in @@ -1337,6 +1337,8 @@ DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION) # define SSL_CTRL_GET_VERIFY_CERT_STORE 137 # define SSL_CTRL_GET_CHAIN_CERT_STORE 138 # define SSL_CTRL_GET0_IMPLEMENTED_GROUPS 139 +# define SSL_CTRL_GET_SIGNATURE_NAME 140 +# define SSL_CTRL_GET_PEER_SIGNATURE_NAME 141 # define SSL_CERT_SET_FIRST 1 # define SSL_CERT_SET_NEXT 2 # define SSL_CERT_SET_SERVER 3 @@ -1479,8 +1481,12 @@ DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION) (char *)(clist)) # define SSL_set1_client_certificate_types(s, clist, clistlen) \ SSL_ctrl(s,SSL_CTRL_SET_CLIENT_CERT_TYPES,clistlen,(char *)(clist)) +# define SSL_get0_signature_name(s, str) \ + SSL_ctrl(s,SSL_CTRL_GET_SIGNATURE_NAME,0,(1?(str):(const char **)NULL)) # define SSL_get_signature_nid(s, pn) \ SSL_ctrl(s,SSL_CTRL_GET_SIGNATURE_NID,0,pn) +# define SSL_get0_peer_signature_name(s, str) \ + SSL_ctrl(s,SSL_CTRL_GET_PEER_SIGNATURE_NAME,0,(1?(str):(const char **)NULL)) # define SSL_get_peer_signature_nid(s, pn) \ SSL_ctrl(s,SSL_CTRL_GET_PEER_SIGNATURE_NID,0,pn) # define SSL_get_peer_tmp_key(s, pk) \ diff --git a/ssl/s3_lib.c b/ssl/s3_lib.c index 8ff338a8fda..05f9e3753d6 100644 --- a/ssl/s3_lib.c +++ b/ssl/s3_lib.c @@ -3825,12 +3825,24 @@ long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg) case SSL_CTRL_GET_CHAIN_CERT_STORE: return ssl_cert_get_cert_store(sc->cert, parg, 1); + case SSL_CTRL_GET_PEER_SIGNATURE_NAME: + if (parg == NULL && sc->s3.tmp.peer_sigalg == NULL) + return 0; + *(const char **)parg = sc->s3.tmp.peer_sigalg->name; + return 1; + case SSL_CTRL_GET_PEER_SIGNATURE_NID: if (sc->s3.tmp.peer_sigalg == NULL) return 0; *(int *)parg = sc->s3.tmp.peer_sigalg->hash; return 1; + case SSL_CTRL_GET_SIGNATURE_NAME: + if (parg == NULL || sc->s3.tmp.sigalg == NULL) + return 0; + *(const char **)parg = sc->s3.tmp.sigalg->name; + return 1; + case SSL_CTRL_GET_SIGNATURE_NID: if (sc->s3.tmp.sigalg == NULL) return 0; diff --git a/test/sslapitest.c b/test/sslapitest.c index 22d1523d00c..daa46606f08 100644 --- a/test/sslapitest.c +++ b/test/sslapitest.c @@ -4062,7 +4062,7 @@ static int early_data_skip_helper(int testtype, int cipher, int idx) sizeof(bad_early_data), &written))) goto end; } - /* fallthrough */ + /* FALLTHROUGH */ case 3: /* @@ -9928,7 +9928,8 @@ static int test_sigalgs_available(int idx) OSSL_LIB_CTX *tmpctx = OSSL_LIB_CTX_new(); OSSL_LIB_CTX *clientctx = libctx, *serverctx = libctx; OSSL_PROVIDER *filterprov = NULL; - int sig, hash; + int sig, hash, numshared, numshared_expected, hash_expected, sig_expected; + const char *sigalg_name, *signame_expected; if (!TEST_ptr(tmpctx)) goto end; @@ -9977,6 +9978,7 @@ static int test_sigalgs_available(int idx) goto end; if (idx != 5) { + /* RSA first server key */ if (!TEST_true(create_ssl_ctx_pair(libctx, TLS_server_method(), TLS_client_method(), TLS1_VERSION, @@ -9984,6 +9986,7 @@ static int test_sigalgs_available(int idx) &sctx, &cctx, cert, privkey))) goto end; } else { + /* ECDSA P-256 first server key */ if (!TEST_true(create_ssl_ctx_pair(libctx, TLS_server_method(), TLS_client_method(), TLS1_VERSION, @@ -10018,6 +10021,7 @@ static int test_sigalgs_available(int idx) goto end; } + /* ECDSA P-256 second server key, unless already first */ if (idx != 5 && (!TEST_int_eq(SSL_CTX_use_certificate_file(sctx, cert2, SSL_FILETYPE_PEM), 1) @@ -10035,16 +10039,32 @@ static int test_sigalgs_available(int idx) goto end; /* For tests 0 and 3 we expect 2 shared sigalgs, otherwise exactly 1 */ - if (!TEST_int_eq(SSL_get_shared_sigalgs(serverssl, 0, &sig, &hash, NULL, - NULL, NULL), - (idx == 0 || idx == 3) ? 2 : 1)) - goto end; - - if (!TEST_int_eq(hash, idx == 0 ? NID_sha384 : NID_sha256)) - goto end; - - if (!TEST_int_eq(sig, (idx == 4 || idx == 5) ? EVP_PKEY_EC - : NID_rsassaPss)) + numshared = SSL_get_shared_sigalgs(serverssl, 0, &sig, &hash, + NULL, NULL, NULL); + numshared_expected = 1; + hash_expected = NID_sha256; + sig_expected = NID_rsassaPss; + signame_expected = "rsa_pss_rsae_sha256"; + switch (idx) { + case 0: + hash_expected = NID_sha384; + signame_expected = "rsa_pss_rsae_sha384"; + /* FALLTHROUGH */ + case 3: + numshared_expected = 2; + break; + case 4: + case 5: + sig_expected = EVP_PKEY_EC; + signame_expected = "ecdsa_secp256r1_sha256"; + break; + } + if (!TEST_int_eq(numshared, numshared_expected) + || !TEST_int_eq(hash, hash_expected) + || !TEST_int_eq(sig, sig_expected) + || !TEST_true(SSL_get0_peer_signature_name(clientssl, &sigalg_name)) + || !TEST_ptr(sigalg_name) + || !TEST_str_eq(sigalg_name, signame_expected)) goto end; testresult = filter_provider_check_clean_finish(); @@ -10185,6 +10205,7 @@ static int test_pluggable_signature(int idx) OSSL_PROVIDER *defaultprov = OSSL_PROVIDER_load(libctx, "default"); char *certfilename = "tls-prov-cert.pem"; char *privkeyfilename = "tls-prov-key.pem"; + const char *sigalg_name = NULL, *expected_sigalg_name; int sigidx = idx % 3; int rpkidx = idx / 3; int do_conf_cmd = 0; @@ -10194,6 +10215,9 @@ static int test_pluggable_signature(int idx) do_conf_cmd = 1; } + /* See create_cert_key() above */ + expected_sigalg_name = (sigidx == 0) ? "xorhmacsig" : "xorhmacsha2sig"; + /* create key and certificate for the different algorithm types */ if (!TEST_ptr(tlsprov) || !TEST_true(create_cert_key(sigidx, certfilename, privkeyfilename))) @@ -10263,6 +10287,11 @@ static int test_pluggable_signature(int idx) if (rpkidx && !TEST_long_eq(SSL_get_verify_result(clientssl), X509_V_ERR_RPK_UNTRUSTED)) goto end; + if (!TEST_true(SSL_get0_peer_signature_name(clientssl, &sigalg_name)) + || !TEST_str_eq(sigalg_name, expected_sigalg_name) + || !TEST_ptr(sigalg_name)) + goto end; + testresult = 1; end: diff --git a/util/other.syms b/util/other.syms index a0b85606078..bf8eeca6524 100644 --- a/util/other.syms +++ b/util/other.syms @@ -633,6 +633,7 @@ SSL_get_max_proto_version define SSL_get_min_proto_version define SSL_get_mode define SSL_get_peer_certificate define deprecated 3.0.0 +SSL_get0_peer_signature_name define SSL_get_peer_signature_nid define SSL_get_peer_tmp_key define SSL_get_secure_renegotiation_support define @@ -640,6 +641,7 @@ SSL_get_server_tmp_key define SSL_get_shared_curve define SSL_get_shared_group define SSL_get_negotiated_group define +SSL_get0_signature_name define SSL_get_signature_nid define SSL_get_time define SSL_get_timeout define