summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/ssl_lib.c43
-rw-r--r--src/lib/libssl/ssl_locl.h4
-rw-r--r--src/lib/libssl/t1_lib.c39
3 files changed, 52 insertions, 34 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index c593e7b42b..d933acb32d 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_lib.c,v 1.161 2017/05/07 04:22:24 beck Exp $ */ 1/* $OpenBSD: ssl_lib.c,v 1.162 2017/08/09 22:24:25 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1259,6 +1259,33 @@ ssl_get_ciphers_by_id(SSL *s)
1259 return (NULL); 1259 return (NULL);
1260} 1260}
1261 1261
1262/* See if we have any ECC cipher suites. */
1263int
1264ssl_has_ecc_ciphers(SSL *s)
1265{
1266 STACK_OF(SSL_CIPHER) *ciphers;
1267 unsigned long alg_k, alg_a;
1268 SSL_CIPHER *cipher;
1269 int i;
1270
1271 if (s->version == DTLS1_VERSION)
1272 return 0;
1273 if ((ciphers = SSL_get_ciphers(s)) == NULL)
1274 return 0;
1275
1276 for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
1277 cipher = sk_SSL_CIPHER_value(ciphers, i);
1278
1279 alg_k = cipher->algorithm_mkey;
1280 alg_a = cipher->algorithm_auth;
1281
1282 if ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA))
1283 return 1;
1284 }
1285
1286 return 0;
1287}
1288
1262/* The old interface to get the same thing as SSL_get_ciphers(). */ 1289/* The old interface to get the same thing as SSL_get_ciphers(). */
1263const char * 1290const char *
1264SSL_get_cipher_list(const SSL *s, int n) 1291SSL_get_cipher_list(const SSL *s, int n)
@@ -2085,6 +2112,20 @@ ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher)
2085 c->valid = 1; 2112 c->valid = 1;
2086} 2113}
2087 2114
2115/* See if this handshake is using an ECC cipher suite. */
2116int
2117ssl_using_ecc_cipher(SSL *s)
2118{
2119 unsigned long alg_a, alg_k;
2120
2121 alg_a = S3I(s)->hs.new_cipher->algorithm_auth;
2122 alg_k = S3I(s)->hs.new_cipher->algorithm_mkey;
2123
2124 return SSI(s)->tlsext_ecpointformatlist != NULL &&
2125 SSI(s)->tlsext_ecpointformatlist_length > 0 &&
2126 ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA));
2127}
2128
2088int 2129int
2089ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL *s) 2130ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL *s)
2090{ 2131{
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
index 0d48920471..f98ce681a2 100644
--- a/src/lib/libssl/ssl_locl.h
+++ b/src/lib/libssl/ssl_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_locl.h,v 1.182 2017/07/24 17:10:31 jsing Exp $ */ 1/* $OpenBSD: ssl_locl.h,v 1.183 2017/08/09 22:24:25 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1127,6 +1127,7 @@ DH *ssl_get_auto_dh(SSL *s);
1127int ssl_cert_type(X509 *x, EVP_PKEY *pkey); 1127int ssl_cert_type(X509 *x, EVP_PKEY *pkey);
1128void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher); 1128void ssl_set_cert_masks(CERT *c, const SSL_CIPHER *cipher);
1129STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s); 1129STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
1130int ssl_has_ecc_ciphers(SSL *s);
1130int ssl_verify_alarm_type(long type); 1131int ssl_verify_alarm_type(long type);
1131void ssl_load_ciphers(void); 1132void ssl_load_ciphers(void);
1132 1133
@@ -1312,6 +1313,7 @@ int tls1_export_keying_material(SSL *s, unsigned char *out, size_t olen,
1312int tls1_alert_code(int code); 1313int tls1_alert_code(int code);
1313int ssl_ok(SSL *s); 1314int ssl_ok(SSL *s);
1314 1315
1316int ssl_using_ecc_cipher(SSL *s);
1315int ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL *s); 1317int ssl_check_srvr_ecc_cert_and_alg(X509 *x, SSL *s);
1316 1318
1317int tls1_set_groups(uint16_t **out_group_ids, size_t *out_group_ids_len, 1319int tls1_set_groups(uint16_t **out_group_ids, size_t *out_group_ids_len,
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c
index b061bd1100..ea44e7579a 100644
--- a/src/lib/libssl/t1_lib.c
+++ b/src/lib/libssl/t1_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: t1_lib.c,v 1.122 2017/07/24 17:39:43 jsing Exp $ */ 1/* $OpenBSD: t1_lib.c,v 1.123 2017/08/09 22:24:25 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -679,28 +679,11 @@ ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit)
679{ 679{
680 int extdatalen = 0; 680 int extdatalen = 0;
681 unsigned char *ret = p; 681 unsigned char *ret = p;
682 int using_ecc = 0; 682 int using_ecc;
683 size_t len; 683 size_t len;
684 CBB cbb; 684 CBB cbb;
685 685
686 /* See if we support any ECC ciphersuites. */ 686 using_ecc = ssl_has_ecc_ciphers(s);
687 if (s->version != DTLS1_VERSION && s->version >= TLS1_VERSION) {
688 STACK_OF(SSL_CIPHER) *cipher_stack = SSL_get_ciphers(s);
689 unsigned long alg_k, alg_a;
690 int i;
691
692 for (i = 0; i < sk_SSL_CIPHER_num(cipher_stack); i++) {
693 SSL_CIPHER *c = sk_SSL_CIPHER_value(cipher_stack, i);
694
695 alg_k = c->algorithm_mkey;
696 alg_a = c->algorithm_auth;
697
698 if ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA)) {
699 using_ecc = 1;
700 break;
701 }
702 }
703 }
704 687
705 ret += 2; 688 ret += 2;
706 if (ret >= limit) 689 if (ret >= limit)
@@ -954,16 +937,12 @@ unsigned char *
954ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned char *limit) 937ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned char *limit)
955{ 938{
956 int using_ecc, extdatalen = 0; 939 int using_ecc, extdatalen = 0;
957 unsigned long alg_a, alg_k;
958 unsigned char *ret = p; 940 unsigned char *ret = p;
959 int next_proto_neg_seen; 941 int next_proto_neg_seen;
960 size_t len; 942 size_t len;
961 CBB cbb; 943 CBB cbb;
962 944
963 alg_a = S3I(s)->hs.new_cipher->algorithm_auth; 945 using_ecc = ssl_using_ecc_cipher(s);
964 alg_k = S3I(s)->hs.new_cipher->algorithm_mkey;
965 using_ecc = ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA)) &&
966 SSI(s)->tlsext_ecpointformatlist != NULL;
967 946
968 ret += 2; 947 ret += 2;
969 if (ret >= limit) 948 if (ret >= limit)
@@ -1809,13 +1788,9 @@ ssl_check_serverhello_tlsext(SSL *s)
1809 * suite, then if server returns an EC point formats lists extension 1788 * suite, then if server returns an EC point formats lists extension
1810 * it must contain uncompressed. 1789 * it must contain uncompressed.
1811 */ 1790 */
1812 unsigned long alg_k = S3I(s)->hs.new_cipher->algorithm_mkey; 1791 if (ssl_using_ecc_cipher(s) &&
1813 unsigned long alg_a = S3I(s)->hs.new_cipher->algorithm_auth; 1792 s->internal->tlsext_ecpointformatlist != NULL &&
1814 if ((s->internal->tlsext_ecpointformatlist != NULL) && 1793 s->internal->tlsext_ecpointformatlist_length > 0) {
1815 (s->internal->tlsext_ecpointformatlist_length > 0) &&
1816 (SSI(s)->tlsext_ecpointformatlist != NULL) &&
1817 (SSI(s)->tlsext_ecpointformatlist_length > 0) &&
1818 ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA))) {
1819 /* we are using an ECC cipher */ 1794 /* we are using an ECC cipher */
1820 size_t i; 1795 size_t i;
1821 unsigned char *list; 1796 unsigned char *list;