Skip to content

Commit 33a8de6

Browse files
committed
new ctrl to retrive value of received temporary key in server key exchange message, print out details in s_client
1 parent 319354e commit 33a8de6

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

apps/s_apps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ int set_cert_key_and_authz(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key,
163163
int ssl_print_sigalgs(BIO *out, SSL *s);
164164
int ssl_print_curves(BIO *out, SSL *s);
165165
#endif
166+
int ssl_print_tmp_key(BIO *out, SSL *s);
166167
int init_client(int *sock, char *server, int port, int type);
167168
int should_retry(int i);
168169
int extract_port(char *str, short *port_ptr);

apps/s_cb.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,40 @@ int ssl_print_curves(BIO *out, SSL *s)
466466
return 1;
467467
}
468468

469+
int ssl_print_tmp_key(BIO *out, SSL *s)
470+
{
471+
EVP_PKEY *key;
472+
if (!SSL_get_server_tmp_key(s, &key))
473+
return 1;
474+
BIO_puts(out, "Server Temp Key: ");
475+
switch (EVP_PKEY_id(key))
476+
{
477+
case EVP_PKEY_RSA:
478+
BIO_printf(out, "RSA, %d bits\n", EVP_PKEY_bits(key));
479+
break;
480+
481+
case EVP_PKEY_DH:
482+
BIO_printf(out, "DH, %d bits\n", EVP_PKEY_bits(key));
483+
break;
484+
485+
case EVP_PKEY_EC:
486+
{
487+
EC_KEY *ec = EVP_PKEY_get1_EC_KEY(key);
488+
int nid;
489+
const char *cname;
490+
nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
491+
EC_KEY_free(ec);
492+
cname = EC_curve_nid2nist(nid);
493+
if (!cname)
494+
cname = OBJ_nid2sn(nid);
495+
BIO_printf(out, "ECDH, %s, %d bits\n",
496+
cname, EVP_PKEY_bits(key));
497+
}
498+
}
499+
EVP_PKEY_free(key);
500+
return 1;
501+
}
502+
469503

470504
long MS_CALLBACK bio_dump_callback(BIO *bio, int cmd, const char *argp,
471505
int argi, long argl, long ret)

apps/s_client.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,6 +2105,7 @@ static void print_stuff(BIO *bio, SSL *s, int full)
21052105
}
21062106

21072107
ssl_print_sigalgs(bio, s);
2108+
ssl_print_tmp_key(bio, s);
21082109

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

ssl/s3_lib.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,6 +3477,43 @@ long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
34773477
else
34783478
return 0;
34793479

3480+
case SSL_CTRL_GET_SERVER_TMP_KEY:
3481+
if (s->server || !s->session || !s->session->sess_cert)
3482+
return 0;
3483+
else
3484+
{
3485+
SESS_CERT *sc;
3486+
EVP_PKEY *ptmp;
3487+
int rv = 0;
3488+
sc = s->session->sess_cert;
3489+
if (!sc->peer_rsa_tmp && !sc->peer_dh_tmp
3490+
&& !sc->peer_ecdh_tmp)
3491+
return 0;
3492+
ptmp = EVP_PKEY_new();
3493+
if (!ptmp)
3494+
return 0;
3495+
if (0);
3496+
#ifndef OPENSSL_NO_RSA
3497+
else if (sc->peer_rsa_tmp)
3498+
rv = EVP_PKEY_set1_RSA(ptmp, sc->peer_rsa_tmp);
3499+
#endif
3500+
#ifndef OPENSSL_NO_DH
3501+
else if (sc->peer_dh_tmp)
3502+
rv = EVP_PKEY_set1_DH(ptmp, sc->peer_dh_tmp);
3503+
#endif
3504+
#ifndef OPENSSL_NO_ECDH
3505+
else if (sc->peer_ecdh_tmp)
3506+
rv = EVP_PKEY_set1_EC_KEY(ptmp, sc->peer_ecdh_tmp);
3507+
#endif
3508+
if (rv)
3509+
{
3510+
*(EVP_PKEY **)parg = ptmp;
3511+
return 1;
3512+
}
3513+
EVP_PKEY_free(ptmp);
3514+
return 0;
3515+
}
3516+
34803517
default:
34813518
break;
34823519
}

ssl/ssl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,7 @@ DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)
17081708
#define SSL_CTRL_SET_VERIFY_CERT_STORE 106
17091709
#define SSL_CTRL_SET_CHAIN_CERT_STORE 107
17101710
#define SSL_CTRL_GET_PEER_SIGNATURE_NID 108
1711+
#define SSL_CTRL_GET_SERVER_TMP_KEY 109
17111712

17121713
#define DTLSv1_get_timeout(ssl, arg) \
17131714
SSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)arg)
@@ -1835,6 +1836,9 @@ DECLARE_PEM_rw(SSL_SESSION, SSL_SESSION)
18351836
#define SSL_get_peer_signature_nid(s, pn) \
18361837
SSL_ctrl(s,SSL_CTRL_GET_PEER_SIGNATURE_NID,0,pn)
18371838

1839+
#define SSL_get_server_tmp_key(s, pk) \
1840+
SSL_ctrl(s,SSL_CTRL_GET_SERVER_TMP_KEY,0,pk)
1841+
18381842
#ifndef OPENSSL_NO_BIO
18391843
BIO_METHOD *BIO_f_ssl(void);
18401844
BIO *BIO_new_ssl(SSL_CTX *ctx,int client);

0 commit comments

Comments
 (0)