|
Lines 646-655
unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *buf, unsigned c
Link Here
|
| 646 |
s2n(TLSEXT_TYPE_next_proto_neg,ret); |
646 |
s2n(TLSEXT_TYPE_next_proto_neg,ret); |
| 647 |
s2n(0,ret); |
647 |
s2n(0,ret); |
| 648 |
} |
648 |
} |
| 649 |
#endif |
649 |
#endif |
| 650 |
|
650 |
|
|
|
651 |
if (s->alpn_client_proto_list && !s->s3->tmp.finish_md_len) |
| 652 |
{ |
| 653 |
if ((size_t)(limit - ret) < 6 + s->alpn_client_proto_list_len) |
| 654 |
return NULL; |
| 655 |
s2n(TLSEXT_TYPE_application_layer_protocol_negotiation,ret); |
| 656 |
s2n(2 + s->alpn_client_proto_list_len,ret); |
| 657 |
s2n(s->alpn_client_proto_list_len,ret); |
| 658 |
memcpy(ret, s->alpn_client_proto_list, |
| 659 |
s->alpn_client_proto_list_len); |
| 660 |
ret += s->alpn_client_proto_list_len; |
| 661 |
} |
| 662 |
|
| 651 |
#ifndef OPENSSL_NO_SRTP |
663 |
#ifndef OPENSSL_NO_SRTP |
| 652 |
if(SSL_IS_DTLS(s) && SSL_get_srtp_profiles(s)) |
664 |
if(SSL_IS_DTLS(s) && SSL_get_srtp_profiles(s)) |
| 653 |
{ |
665 |
{ |
| 654 |
int el; |
666 |
int el; |
| 655 |
|
667 |
|
|
Lines 887-903
unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *buf, unsigned c
Link Here
|
| 887 |
s->s3->next_proto_neg_seen = 1; |
899 |
s->s3->next_proto_neg_seen = 1; |
| 888 |
} |
900 |
} |
| 889 |
} |
901 |
} |
| 890 |
#endif |
902 |
#endif |
| 891 |
|
903 |
|
|
|
904 |
if (s->s3->alpn_selected) |
| 905 |
{ |
| 906 |
const unsigned char *selected = s->s3->alpn_selected; |
| 907 |
unsigned len = s->s3->alpn_selected_len; |
| 908 |
|
| 909 |
if ((long)(limit - ret - 4 - 2 - 1 - len) < 0) |
| 910 |
return NULL; |
| 911 |
s2n(TLSEXT_TYPE_application_layer_protocol_negotiation,ret); |
| 912 |
s2n(3 + len,ret); |
| 913 |
s2n(1 + len,ret); |
| 914 |
*ret++ = len; |
| 915 |
memcpy(ret, selected, len); |
| 916 |
ret += len; |
| 917 |
} |
| 918 |
|
| 892 |
if ((extdatalen = ret-orig-2)== 0) |
919 |
if ((extdatalen = ret-orig-2)== 0) |
| 893 |
return orig; |
920 |
return orig; |
| 894 |
|
921 |
|
| 895 |
s2n(extdatalen, orig); |
922 |
s2n(extdatalen, orig); |
| 896 |
return ret; |
923 |
return ret; |
| 897 |
} |
924 |
} |
| 898 |
|
925 |
|
|
|
926 |
/* tls1_alpn_handle_client_hello is called to process the ALPN extension in a |
| 927 |
* ClientHello. |
| 928 |
* data: the contents of the extension, not including the type and length. |
| 929 |
* data_len: the number of bytes in |data| |
| 930 |
* al: a pointer to the alert value to send in the event of a non-zero |
| 931 |
* return. |
| 932 |
* |
| 933 |
* returns: 0 on success. */ |
| 934 |
static int tls1_alpn_handle_client_hello(SSL *s, const unsigned char *data, |
| 935 |
unsigned data_len, int *al) |
| 936 |
{ |
| 937 |
unsigned i; |
| 938 |
unsigned proto_len; |
| 939 |
const unsigned char *selected; |
| 940 |
unsigned char selected_len; |
| 941 |
int r; |
| 942 |
|
| 943 |
if (s->ctx->alpn_select_cb == NULL) |
| 944 |
return 0; |
| 945 |
|
| 946 |
if (data_len < 2) |
| 947 |
goto parse_error; |
| 948 |
|
| 949 |
/* data should contain a uint16 length followed by a series of 8-bit, |
| 950 |
* length-prefixed strings. */ |
| 951 |
i = ((unsigned) data[0]) << 8 | |
| 952 |
((unsigned) data[1]); |
| 953 |
data_len -= 2; |
| 954 |
data += 2; |
| 955 |
if (data_len != i) |
| 956 |
goto parse_error; |
| 957 |
|
| 958 |
if (data_len < 2) |
| 959 |
goto parse_error; |
| 960 |
|
| 961 |
for (i = 0; i < data_len;) |
| 962 |
{ |
| 963 |
proto_len = data[i]; |
| 964 |
i++; |
| 965 |
|
| 966 |
if (proto_len == 0) |
| 967 |
goto parse_error; |
| 968 |
|
| 969 |
if (i + proto_len < i || i + proto_len > data_len) |
| 970 |
goto parse_error; |
| 971 |
|
| 972 |
i += proto_len; |
| 973 |
} |
| 974 |
|
| 975 |
r = s->ctx->alpn_select_cb(s, &selected, &selected_len, data, data_len, |
| 976 |
s->ctx->alpn_select_cb_arg); |
| 977 |
if (r == SSL_TLSEXT_ERR_OK) { |
| 978 |
if (s->s3->alpn_selected) |
| 979 |
OPENSSL_free(s->s3->alpn_selected); |
| 980 |
s->s3->alpn_selected = OPENSSL_malloc(selected_len); |
| 981 |
if (!s->s3->alpn_selected) |
| 982 |
{ |
| 983 |
*al = SSL_AD_INTERNAL_ERROR; |
| 984 |
return -1; |
| 985 |
} |
| 986 |
memcpy(s->s3->alpn_selected, selected, selected_len); |
| 987 |
s->s3->alpn_selected_len = selected_len; |
| 988 |
} |
| 989 |
return 0; |
| 990 |
|
| 991 |
parse_error: |
| 992 |
*al = SSL_AD_DECODE_ERROR; |
| 993 |
return -1; |
| 994 |
} |
| 995 |
|
| 899 |
#ifndef OPENSSL_NO_EC |
996 |
#ifndef OPENSSL_NO_EC |
| 900 |
/* ssl_check_for_safari attempts to fingerprint Safari using OS X |
997 |
/* ssl_check_for_safari attempts to fingerprint Safari using OS X |
| 901 |
* SecureTransport using the TLS extension block in |d|, of length |n|. |
998 |
* SecureTransport using the TLS extension block in |d|, of length |n|. |
| 902 |
* Safari, since 10.6, sends exactly these extensions, in this order: |
999 |
* Safari, since 10.6, sends exactly these extensions, in this order: |
| 903 |
* SNI, |
1000 |
* SNI, |
|
Lines 992-1001
int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
Link Here
|
| 992 |
s->tlsext_status_type = -1; |
1089 |
s->tlsext_status_type = -1; |
| 993 |
#ifndef OPENSSL_NO_NEXTPROTONEG |
1090 |
#ifndef OPENSSL_NO_NEXTPROTONEG |
| 994 |
s->s3->next_proto_neg_seen = 0; |
1091 |
s->s3->next_proto_neg_seen = 0; |
| 995 |
#endif |
1092 |
#endif |
| 996 |
|
1093 |
|
|
|
1094 |
if (s->s3->alpn_selected) |
| 1095 |
{ |
| 1096 |
OPENSSL_free(s->s3->alpn_selected); |
| 1097 |
s->s3->alpn_selected = NULL; |
| 1098 |
} |
| 1099 |
|
| 997 |
#ifndef OPENSSL_NO_HEARTBEATS |
1100 |
#ifndef OPENSSL_NO_HEARTBEATS |
| 998 |
s->tlsext_heartbeat &= ~(SSL_TLSEXT_HB_ENABLED | |
1101 |
s->tlsext_heartbeat &= ~(SSL_TLSEXT_HB_ENABLED | |
| 999 |
SSL_TLSEXT_HB_DONT_SEND_REQUESTS); |
1102 |
SSL_TLSEXT_HB_DONT_SEND_REQUESTS); |
| 1000 |
#endif |
1103 |
#endif |
| 1001 |
|
1104 |
|
|
Lines 1425-1435
int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
Link Here
|
| 1425 |
} |
1528 |
} |
| 1426 |
} |
1529 |
} |
| 1427 |
#endif |
1530 |
#endif |
| 1428 |
#ifndef OPENSSL_NO_NEXTPROTONEG |
1531 |
#ifndef OPENSSL_NO_NEXTPROTONEG |
| 1429 |
else if (type == TLSEXT_TYPE_next_proto_neg && |
1532 |
else if (type == TLSEXT_TYPE_next_proto_neg && |
| 1430 |
s->s3->tmp.finish_md_len == 0) |
1533 |
s->s3->tmp.finish_md_len == 0 && |
|
|
1534 |
s->s3->alpn_selected == NULL) |
| 1431 |
{ |
1535 |
{ |
| 1432 |
/* We shouldn't accept this extension on a |
1536 |
/* We shouldn't accept this extension on a |
| 1433 |
* renegotiation. |
1537 |
* renegotiation. |
| 1434 |
* |
1538 |
* |
| 1435 |
* s->new_session will be set on renegotiation, but we |
1539 |
* s->new_session will be set on renegotiation, but we |
|
Lines 1446-1455
int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
Link Here
|
| 1446 |
* Finished message could have been computed.) */ |
1550 |
* Finished message could have been computed.) */ |
| 1447 |
s->s3->next_proto_neg_seen = 1; |
1551 |
s->s3->next_proto_neg_seen = 1; |
| 1448 |
} |
1552 |
} |
| 1449 |
#endif |
1553 |
#endif |
| 1450 |
|
1554 |
|
|
|
1555 |
else if (type == TLSEXT_TYPE_application_layer_protocol_negotiation && |
| 1556 |
s->ctx->alpn_select_cb && |
| 1557 |
s->s3->tmp.finish_md_len == 0) |
| 1558 |
{ |
| 1559 |
if (tls1_alpn_handle_client_hello(s, data, size, al) != 0) |
| 1560 |
return 0; |
| 1561 |
/* ALPN takes precedence over NPN. */ |
| 1562 |
s->s3->next_proto_neg_seen = 0; |
| 1563 |
} |
| 1564 |
|
| 1451 |
/* session ticket processed earlier */ |
1565 |
/* session ticket processed earlier */ |
| 1452 |
#ifndef OPENSSL_NO_SRTP |
1566 |
#ifndef OPENSSL_NO_SRTP |
| 1453 |
else if (SSL_IS_DTLS(s) && SSL_get_srtp_profiles(s) |
1567 |
else if (SSL_IS_DTLS(s) && SSL_get_srtp_profiles(s) |
| 1454 |
&& type == TLSEXT_TYPE_use_srtp) |
1568 |
&& type == TLSEXT_TYPE_use_srtp) |
| 1455 |
{ |
1569 |
{ |
|
Lines 1511-1520
int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
Link Here
|
| 1511 |
|
1625 |
|
| 1512 |
#ifndef OPENSSL_NO_NEXTPROTONEG |
1626 |
#ifndef OPENSSL_NO_NEXTPROTONEG |
| 1513 |
s->s3->next_proto_neg_seen = 0; |
1627 |
s->s3->next_proto_neg_seen = 0; |
| 1514 |
#endif |
1628 |
#endif |
| 1515 |
|
1629 |
|
|
|
1630 |
if (s->s3->alpn_selected) |
| 1631 |
{ |
| 1632 |
OPENSSL_free(s->s3->alpn_selected); |
| 1633 |
s->s3->alpn_selected = NULL; |
| 1634 |
} |
| 1635 |
|
| 1516 |
#ifndef OPENSSL_NO_HEARTBEATS |
1636 |
#ifndef OPENSSL_NO_HEARTBEATS |
| 1517 |
s->tlsext_heartbeat &= ~(SSL_TLSEXT_HB_ENABLED | |
1637 |
s->tlsext_heartbeat &= ~(SSL_TLSEXT_HB_ENABLED | |
| 1518 |
SSL_TLSEXT_HB_DONT_SEND_REQUESTS); |
1638 |
SSL_TLSEXT_HB_DONT_SEND_REQUESTS); |
| 1519 |
#endif |
1639 |
#endif |
| 1520 |
|
1640 |
|
|
Lines 1679-1688
int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
Link Here
|
| 1679 |
memcpy(s->next_proto_negotiated, selected, selected_len); |
1799 |
memcpy(s->next_proto_negotiated, selected, selected_len); |
| 1680 |
s->next_proto_negotiated_len = selected_len; |
1800 |
s->next_proto_negotiated_len = selected_len; |
| 1681 |
s->s3->next_proto_neg_seen = 1; |
1801 |
s->s3->next_proto_neg_seen = 1; |
| 1682 |
} |
1802 |
} |
| 1683 |
#endif |
1803 |
#endif |
|
|
1804 |
|
| 1805 |
else if (type == TLSEXT_TYPE_application_layer_protocol_negotiation) |
| 1806 |
{ |
| 1807 |
unsigned len; |
| 1808 |
|
| 1809 |
/* We must have requested it. */ |
| 1810 |
if (s->alpn_client_proto_list == NULL) |
| 1811 |
{ |
| 1812 |
*al = TLS1_AD_UNSUPPORTED_EXTENSION; |
| 1813 |
return 0; |
| 1814 |
} |
| 1815 |
if (size < 4) |
| 1816 |
{ |
| 1817 |
*al = TLS1_AD_DECODE_ERROR; |
| 1818 |
return 0; |
| 1819 |
} |
| 1820 |
/* The extension data consists of: |
| 1821 |
* uint16 list_length |
| 1822 |
* uint8 proto_length; |
| 1823 |
* uint8 proto[proto_length]; */ |
| 1824 |
len = data[0]; |
| 1825 |
len <<= 8; |
| 1826 |
len |= data[1]; |
| 1827 |
if (len != (unsigned) size - 2) |
| 1828 |
{ |
| 1829 |
*al = TLS1_AD_DECODE_ERROR; |
| 1830 |
return 0; |
| 1831 |
} |
| 1832 |
len = data[2]; |
| 1833 |
if (len != (unsigned) size - 3) |
| 1834 |
{ |
| 1835 |
*al = TLS1_AD_DECODE_ERROR; |
| 1836 |
return 0; |
| 1837 |
} |
| 1838 |
if (s->s3->alpn_selected) |
| 1839 |
OPENSSL_free(s->s3->alpn_selected); |
| 1840 |
s->s3->alpn_selected = OPENSSL_malloc(len); |
| 1841 |
if (!s->s3->alpn_selected) |
| 1842 |
{ |
| 1843 |
*al = TLS1_AD_INTERNAL_ERROR; |
| 1844 |
return 0; |
| 1845 |
} |
| 1846 |
memcpy(s->s3->alpn_selected, data + 3, len); |
| 1847 |
s->s3->alpn_selected_len = len; |
| 1848 |
} |
| 1849 |
|
| 1684 |
else if (type == TLSEXT_TYPE_renegotiate) |
1850 |
else if (type == TLSEXT_TYPE_renegotiate) |
| 1685 |
{ |
1851 |
{ |
| 1686 |
if(!ssl_parse_serverhello_renegotiate_ext(s, data, size, al)) |
1852 |
if(!ssl_parse_serverhello_renegotiate_ext(s, data, size, al)) |
| 1687 |
return 0; |
1853 |
return 0; |
| 1688 |
renegotiate_seen = 1; |
1854 |
renegotiate_seen = 1; |