Skip to content

Commit c70a1fe

Browse files
committed
Reorganise supported signature algorithm extension processing.
Only store encoded versions of peer and configured signature algorithms. Determine shared signature algorithms and cache the result along with NID equivalents of each algorithm. (backport from HEAD)
1 parent 0b362de commit c70a1fe

File tree

11 files changed

+283
-116
lines changed

11 files changed

+283
-116
lines changed

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
Changes between 1.0.1 and 1.0.2 [xx XXX xxxx]
66

7+
*) Update and tidy signature algorithm extension processing. Work out
8+
shared signature algorithms based on preferences and peer algorithms
9+
and print them out in s_client and s_server. Abort handshake if no
10+
shared signature algorithms.
11+
[Steve Henson]
12+
713
*) Add new functions to allow customised supported signature algorithms
814
for SSL and SSL_CTX structures. Add options to s_client and s_server
915
to support them.

apps/s_apps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key,
160160
int set_cert_key_and_authz(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key,
161161
unsigned char *authz, size_t authz_length);
162162
# endif
163-
int ssl_print_sigalgs(BIO *out, SSL *s);
163+
int ssl_print_sigalgs(BIO *out, SSL *s, int client);
164164
int ssl_print_curves(BIO *out, SSL *s);
165165
#endif
166166
int init_client(int *sock, char *server, int port, int type);

apps/s_cb.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,33 @@ int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key,
285285
return 1;
286286
}
287287

288-
int ssl_print_sigalgs(BIO *out, SSL *s)
288+
static int do_print_sigalgs(BIO *out, SSL *s, int client, int shared)
289289
{
290290
int i, nsig;
291-
nsig = SSL_get_sigalgs(s, -1, NULL, NULL, NULL, NULL, NULL);
291+
if (shared)
292+
nsig = SSL_get_shared_sigalgs(s, -1, NULL, NULL, NULL,
293+
NULL, NULL);
294+
else
295+
nsig = SSL_get_sigalgs(s, -1, NULL, NULL, NULL, NULL, NULL);
292296
if (nsig == 0)
293297
return 1;
294298

299+
if (shared)
300+
BIO_puts(out, "Shared ");
301+
302+
if (client)
303+
BIO_puts(out, "Requested ");
295304
BIO_puts(out, "Signature Algorithms: ");
296305
for (i = 0; i < nsig; i++)
297306
{
298307
int hash_nid, sign_nid;
299308
unsigned char rhash, rsign;
300309
const char *sstr = NULL;
301-
SSL_get_sigalgs(s, i, &sign_nid, &hash_nid, NULL,
310+
if (shared)
311+
SSL_get_shared_sigalgs(s, i, &sign_nid, &hash_nid, NULL,
312+
&rsign, &rhash);
313+
else
314+
SSL_get_sigalgs(s, i, &sign_nid, &hash_nid, NULL,
302315
&rsign, &rhash);
303316
if (i)
304317
BIO_puts(out, ":");
@@ -321,6 +334,13 @@ int ssl_print_sigalgs(BIO *out, SSL *s)
321334
return 1;
322335
}
323336

337+
int ssl_print_sigalgs(BIO *out, SSL *s, int client)
338+
{
339+
do_print_sigalgs(out, s, client, 0);
340+
do_print_sigalgs(out, s, client, 1);
341+
return 1;
342+
}
343+
324344
int ssl_print_curves(BIO *out, SSL *s)
325345
{
326346
int i, ncurves, *curves, nid;

apps/s_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2049,7 +2049,7 @@ static void print_stuff(BIO *bio, SSL *s, int full)
20492049
BIO_write(bio,"\n",1);
20502050
}
20512051

2052-
ssl_print_sigalgs(bio, s);
2052+
ssl_print_sigalgs(bio, s, 1);
20532053

20542054
BIO_printf(bio,"---\nSSL handshake has read %ld bytes and written %ld bytes\n",
20552055
BIO_number_read(SSL_get_rbio(s)),

apps/s_server.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@ static int init_ssl_connection(SSL *con)
25362536
if (SSL_get_shared_ciphers(con,buf,sizeof buf) != NULL)
25372537
BIO_printf(bio_s_out,"Shared ciphers:%s\n",buf);
25382538
str=SSL_CIPHER_get_name(SSL_get_current_cipher(con));
2539-
ssl_print_sigalgs(bio_s_out, con);
2539+
ssl_print_sigalgs(bio_s_out, con, 0);
25402540
ssl_print_curves(bio_s_out, con);
25412541
BIO_printf(bio_s_out,"CIPHER is %s\n",(str != NULL)?str:"(NONE)");
25422542

@@ -2851,7 +2851,7 @@ static int www_body(char *hostname, int s, unsigned char *context)
28512851
}
28522852
BIO_puts(io,"\n");
28532853
}
2854-
ssl_print_sigalgs(io, con);
2854+
ssl_print_sigalgs(io, con, 0);
28552855
ssl_print_curves(io, con);
28562856
BIO_printf(io,(SSL_cache_hit(con)
28572857
?"---\nReused, "

ssl/ssl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,6 +2532,7 @@ void ERR_load_SSL_strings(void);
25322532
#define SSL_R_NO_RENEGOTIATION 339
25332533
#define SSL_R_NO_REQUIRED_DIGEST 324
25342534
#define SSL_R_NO_SHARED_CIPHER 193
2535+
#define SSL_R_NO_SHARED_SIGATURE_ALGORITHMS 376
25352536
#define SSL_R_NO_SRTP_PROFILES 359
25362537
#define SSL_R_NO_VERIFY_CALLBACK 194
25372538
#define SSL_R_NULL_SSL_CTX 195

ssl/ssl_cert.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ int SSL_get_ex_data_X509_STORE_CTX_idx(void)
160160
return ssl_x509_store_ctx_idx;
161161
}
162162

163-
static void ssl_cert_set_default_md(CERT *cert)
163+
void ssl_cert_set_default_md(CERT *cert)
164164
{
165165
/* Set digest values to defaults */
166166
#ifndef OPENSSL_NO_DSA
@@ -373,6 +373,8 @@ CERT *ssl_cert_dup(CERT *cert)
373373
}
374374
else
375375
ret->conf_sigalgs = NULL;
376+
/* Shared sigalgs also NULL */
377+
ret->shared_sigalgs = NULL;
376378

377379
return(ret);
378380

@@ -464,6 +466,8 @@ void ssl_cert_free(CERT *c)
464466
OPENSSL_free(c->peer_sigalgs);
465467
if (c->conf_sigalgs)
466468
OPENSSL_free(c->conf_sigalgs);
469+
if (c->shared_sigalgs)
470+
OPENSSL_free(c->shared_sigalgs);
467471
OPENSSL_free(c);
468472
}
469473

ssl/ssl_err.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ static ERR_STRING_DATA SSL_str_reasons[]=
463463
{ERR_REASON(SSL_R_NO_RENEGOTIATION) ,"no renegotiation"},
464464
{ERR_REASON(SSL_R_NO_REQUIRED_DIGEST) ,"digest requred for handshake isn't computed"},
465465
{ERR_REASON(SSL_R_NO_SHARED_CIPHER) ,"no shared cipher"},
466+
{ERR_REASON(SSL_R_NO_SHARED_SIGATURE_ALGORITHMS),"no shared sigature algorithms"},
466467
{ERR_REASON(SSL_R_NO_SRTP_PROFILES) ,"no srtp profiles"},
467468
{ERR_REASON(SSL_R_NO_VERIFY_CALLBACK) ,"no verify callback"},
468469
{ERR_REASON(SSL_R_NULL_SSL_CTX) ,"null ssl ctx"},

ssl/ssl_locl.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,15 +523,20 @@ typedef struct cert_st
523523
* algorithms extension for server or as part of a certificate
524524
* request for client.
525525
*/
526-
TLS_SIGALGS *peer_sigalgs;
526+
unsigned char *peer_sigalgs;
527527
/* Size of above array */
528528
size_t peer_sigalgslen;
529529
/* configured signature algorithms (can be NULL for default).
530530
* sent in signature algorithms extension or certificate request.
531531
*/
532-
TLS_SIGALGS *conf_sigalgs;
532+
unsigned char *conf_sigalgs;
533533
/* Size of above array */
534534
size_t conf_sigalgslen;
535+
/* Signature algorithms shared by client and server: cached
536+
* because these are used most often
537+
*/
538+
TLS_SIGALGS *shared_sigalgs;
539+
size_t shared_sigalgslen;
535540

536541
int references; /* >1 only if SSL_copy_session_id is used */
537542
} CERT;
@@ -841,6 +846,7 @@ void ssl_clear_cipher_ctx(SSL *s);
841846
int ssl_clear_bad_session(SSL *s);
842847
CERT *ssl_cert_new(void);
843848
CERT *ssl_cert_dup(CERT *cert);
849+
void ssl_cert_set_default_md(CERT *cert);
844850
int ssl_cert_inst(CERT **o);
845851
void ssl_cert_clear_certs(CERT *c);
846852
void ssl_cert_free(CERT *c);

0 commit comments

Comments
 (0)