summaryrefslogtreecommitdiff
path: root/src/lib/libssl/t1_lib.c
diff options
context:
space:
mode:
authordjm <>2011-11-03 02:32:23 +0000
committerdjm <>2011-11-03 02:32:23 +0000
commit113f799ec7d1728f0a5d7ab5b0e3b42e3de56407 (patch)
tree26d712b25a8fa580b8f2dfc6df470ba5ffea9eb7 /src/lib/libssl/t1_lib.c
parent829fd51d4f8dde4a7f3bf54754f3c1d1a502f5e2 (diff)
downloadopenbsd-113f799ec7d1728f0a5d7ab5b0e3b42e3de56407.tar.gz
openbsd-113f799ec7d1728f0a5d7ab5b0e3b42e3de56407.tar.bz2
openbsd-113f799ec7d1728f0a5d7ab5b0e3b42e3de56407.zip
import OpenSSL 1.0.0e
Diffstat (limited to 'src/lib/libssl/t1_lib.c')
-rw-r--r--src/lib/libssl/t1_lib.c88
1 files changed, 60 insertions, 28 deletions
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c
index e8bc34c111..85371c87b8 100644
--- a/src/lib/libssl/t1_lib.c
+++ b/src/lib/libssl/t1_lib.c
@@ -714,14 +714,23 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
714 switch (servname_type) 714 switch (servname_type)
715 { 715 {
716 case TLSEXT_NAMETYPE_host_name: 716 case TLSEXT_NAMETYPE_host_name:
717 if (s->session->tlsext_hostname == NULL) 717 if (!s->hit)
718 { 718 {
719 if (len > TLSEXT_MAXLEN_host_name || 719 if(s->session->tlsext_hostname)
720 ((s->session->tlsext_hostname = OPENSSL_malloc(len+1)) == NULL)) 720 {
721 *al = SSL_AD_DECODE_ERROR;
722 return 0;
723 }
724 if (len > TLSEXT_MAXLEN_host_name)
721 { 725 {
722 *al = TLS1_AD_UNRECOGNIZED_NAME; 726 *al = TLS1_AD_UNRECOGNIZED_NAME;
723 return 0; 727 return 0;
724 } 728 }
729 if ((s->session->tlsext_hostname = OPENSSL_malloc(len+1)) == NULL)
730 {
731 *al = TLS1_AD_INTERNAL_ERROR;
732 return 0;
733 }
725 memcpy(s->session->tlsext_hostname, sdata, len); 734 memcpy(s->session->tlsext_hostname, sdata, len);
726 s->session->tlsext_hostname[len]='\0'; 735 s->session->tlsext_hostname[len]='\0';
727 if (strlen(s->session->tlsext_hostname) != len) { 736 if (strlen(s->session->tlsext_hostname) != len) {
@@ -734,7 +743,8 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
734 743
735 } 744 }
736 else 745 else
737 s->servername_done = strlen(s->session->tlsext_hostname) == len 746 s->servername_done = s->session->tlsext_hostname
747 && strlen(s->session->tlsext_hostname) == len
738 && strncmp(s->session->tlsext_hostname, (char *)sdata, len) == 0; 748 && strncmp(s->session->tlsext_hostname, (char *)sdata, len) == 0;
739 749
740 break; 750 break;
@@ -765,15 +775,22 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
765 *al = TLS1_AD_DECODE_ERROR; 775 *al = TLS1_AD_DECODE_ERROR;
766 return 0; 776 return 0;
767 } 777 }
768 s->session->tlsext_ecpointformatlist_length = 0; 778 if (!s->hit)
769 if (s->session->tlsext_ecpointformatlist != NULL) OPENSSL_free(s->session->tlsext_ecpointformatlist);
770 if ((s->session->tlsext_ecpointformatlist = OPENSSL_malloc(ecpointformatlist_length)) == NULL)
771 { 779 {
772 *al = TLS1_AD_INTERNAL_ERROR; 780 if(s->session->tlsext_ecpointformatlist)
773 return 0; 781 {
782 OPENSSL_free(s->session->tlsext_ecpointformatlist);
783 s->session->tlsext_ecpointformatlist = NULL;
784 }
785 s->session->tlsext_ecpointformatlist_length = 0;
786 if ((s->session->tlsext_ecpointformatlist = OPENSSL_malloc(ecpointformatlist_length)) == NULL)
787 {
788 *al = TLS1_AD_INTERNAL_ERROR;
789 return 0;
790 }
791 s->session->tlsext_ecpointformatlist_length = ecpointformatlist_length;
792 memcpy(s->session->tlsext_ecpointformatlist, sdata, ecpointformatlist_length);
774 } 793 }
775 s->session->tlsext_ecpointformatlist_length = ecpointformatlist_length;
776 memcpy(s->session->tlsext_ecpointformatlist, sdata, ecpointformatlist_length);
777#if 0 794#if 0
778 fprintf(stderr,"ssl_parse_clienthello_tlsext s->session->tlsext_ecpointformatlist (length=%i) ", s->session->tlsext_ecpointformatlist_length); 795 fprintf(stderr,"ssl_parse_clienthello_tlsext s->session->tlsext_ecpointformatlist (length=%i) ", s->session->tlsext_ecpointformatlist_length);
779 sdata = s->session->tlsext_ecpointformatlist; 796 sdata = s->session->tlsext_ecpointformatlist;
@@ -794,15 +811,22 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
794 *al = TLS1_AD_DECODE_ERROR; 811 *al = TLS1_AD_DECODE_ERROR;
795 return 0; 812 return 0;
796 } 813 }
797 s->session->tlsext_ellipticcurvelist_length = 0; 814 if (!s->hit)
798 if (s->session->tlsext_ellipticcurvelist != NULL) OPENSSL_free(s->session->tlsext_ellipticcurvelist);
799 if ((s->session->tlsext_ellipticcurvelist = OPENSSL_malloc(ellipticcurvelist_length)) == NULL)
800 { 815 {
801 *al = TLS1_AD_INTERNAL_ERROR; 816 if(s->session->tlsext_ellipticcurvelist)
802 return 0; 817 {
818 *al = TLS1_AD_DECODE_ERROR;
819 return 0;
820 }
821 s->session->tlsext_ellipticcurvelist_length = 0;
822 if ((s->session->tlsext_ellipticcurvelist = OPENSSL_malloc(ellipticcurvelist_length)) == NULL)
823 {
824 *al = TLS1_AD_INTERNAL_ERROR;
825 return 0;
826 }
827 s->session->tlsext_ellipticcurvelist_length = ellipticcurvelist_length;
828 memcpy(s->session->tlsext_ellipticcurvelist, sdata, ellipticcurvelist_length);
803 } 829 }
804 s->session->tlsext_ellipticcurvelist_length = ellipticcurvelist_length;
805 memcpy(s->session->tlsext_ellipticcurvelist, sdata, ellipticcurvelist_length);
806#if 0 830#if 0
807 fprintf(stderr,"ssl_parse_clienthello_tlsext s->session->tlsext_ellipticcurvelist (length=%i) ", s->session->tlsext_ellipticcurvelist_length); 831 fprintf(stderr,"ssl_parse_clienthello_tlsext s->session->tlsext_ellipticcurvelist (length=%i) ", s->session->tlsext_ellipticcurvelist_length);
808 sdata = s->session->tlsext_ellipticcurvelist; 832 sdata = s->session->tlsext_ellipticcurvelist;
@@ -893,6 +917,7 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
893 } 917 }
894 n2s(data, idsize); 918 n2s(data, idsize);
895 dsize -= 2 + idsize; 919 dsize -= 2 + idsize;
920 size -= 2 + idsize;
896 if (dsize < 0) 921 if (dsize < 0)
897 { 922 {
898 *al = SSL_AD_DECODE_ERROR; 923 *al = SSL_AD_DECODE_ERROR;
@@ -931,9 +956,14 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
931 } 956 }
932 957
933 /* Read in request_extensions */ 958 /* Read in request_extensions */
959 if (size < 2)
960 {
961 *al = SSL_AD_DECODE_ERROR;
962 return 0;
963 }
934 n2s(data,dsize); 964 n2s(data,dsize);
935 size -= 2; 965 size -= 2;
936 if (dsize > size) 966 if (dsize != size)
937 { 967 {
938 *al = SSL_AD_DECODE_ERROR; 968 *al = SSL_AD_DECODE_ERROR;
939 return 0; 969 return 0;
@@ -983,9 +1013,9 @@ int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
983 1013
984int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, int n, int *al) 1014int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, int n, int *al)
985 { 1015 {
1016 unsigned short length;
986 unsigned short type; 1017 unsigned short type;
987 unsigned short size; 1018 unsigned short size;
988 unsigned short len;
989 unsigned char *data = *p; 1019 unsigned char *data = *p;
990 int tlsext_servername = 0; 1020 int tlsext_servername = 0;
991 int renegotiate_seen = 0; 1021 int renegotiate_seen = 0;
@@ -993,7 +1023,12 @@ int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **p, unsigned char *d, in
993 if (data >= (d+n-2)) 1023 if (data >= (d+n-2))
994 goto ri_check; 1024 goto ri_check;
995 1025
996 n2s(data,len); 1026 n2s(data,length);
1027 if (data+length != d+n)
1028 {
1029 *al = SSL_AD_DECODE_ERROR;
1030 return 0;
1031 }
997 1032
998 while(data <= (d+n-4)) 1033 while(data <= (d+n-4))
999 { 1034 {
@@ -1423,23 +1458,20 @@ int ssl_check_serverhello_tlsext(SSL *s)
1423 int al = SSL_AD_UNRECOGNIZED_NAME; 1458 int al = SSL_AD_UNRECOGNIZED_NAME;
1424 1459
1425#ifndef OPENSSL_NO_EC 1460#ifndef OPENSSL_NO_EC
1426 /* If we are client and using an elliptic curve cryptography cipher suite, then server 1461 /* If we are client and using an elliptic curve cryptography cipher
1427 * must return a an EC point formats lists containing uncompressed. 1462 * suite, then if server returns an EC point formats lists extension
1463 * it must contain uncompressed.
1428 */ 1464 */
1429 unsigned long alg_k = s->s3->tmp.new_cipher->algorithm_mkey; 1465 unsigned long alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
1430 unsigned long alg_a = s->s3->tmp.new_cipher->algorithm_auth; 1466 unsigned long alg_a = s->s3->tmp.new_cipher->algorithm_auth;
1431 if ((s->tlsext_ecpointformatlist != NULL) && (s->tlsext_ecpointformatlist_length > 0) && 1467 if ((s->tlsext_ecpointformatlist != NULL) && (s->tlsext_ecpointformatlist_length > 0) &&
1468 (s->session->tlsext_ecpointformatlist != NULL) && (s->session->tlsext_ecpointformatlist_length > 0) &&
1432 ((alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe)) || (alg_a & SSL_aECDSA))) 1469 ((alg_k & (SSL_kEECDH|SSL_kECDHr|SSL_kECDHe)) || (alg_a & SSL_aECDSA)))
1433 { 1470 {
1434 /* we are using an ECC cipher */ 1471 /* we are using an ECC cipher */
1435 size_t i; 1472 size_t i;
1436 unsigned char *list; 1473 unsigned char *list;
1437 int found_uncompressed = 0; 1474 int found_uncompressed = 0;
1438 if ((s->session->tlsext_ecpointformatlist == NULL) || (s->session->tlsext_ecpointformatlist_length == 0))
1439 {
1440 SSLerr(SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT,SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST);
1441 return -1;
1442 }
1443 list = s->session->tlsext_ecpointformatlist; 1475 list = s->session->tlsext_ecpointformatlist;
1444 for (i = 0; i < s->session->tlsext_ecpointformatlist_length; i++) 1476 for (i = 0; i < s->session->tlsext_ecpointformatlist_length; i++)
1445 { 1477 {