122 #ifndef OPENSSL_NO_TLSEXT
123 static int tls_decrypt_ticket(
SSL *s,
const unsigned char *tick,
int ticklen,
124 const unsigned char *sess_id,
int sesslen,
159 #ifndef OPENSSL_NO_TLSEXT
174 #ifndef OPENSSL_NO_EC
176 static int nid_list[] =
205 static int pref_list[] =
237 if ((curve_id < 1) || ((
unsigned int)curve_id >
238 sizeof(nid_list)/
sizeof(nid_list[0])))
240 return nid_list[curve_id-1];
304 #ifndef OPENSSL_NO_TLSEXT
310 #ifdef OPENSSL_NO_RSA
311 #define tlsext_sigalg_rsa(md)
313 #define tlsext_sigalg_rsa(md) md, TLSEXT_signature_rsa,
316 #ifdef OPENSSL_NO_DSA
317 #define tlsext_sigalg_dsa(md)
319 #define tlsext_sigalg_dsa(md) md, TLSEXT_signature_dsa,
322 #ifdef OPENSSL_NO_ECDSA
323 #define tlsext_sigalg_ecdsa(md)
325 #define tlsext_sigalg_ecdsa(md) md, TLSEXT_signature_ecdsa,
328 #define tlsext_sigalg(md) \
329 tlsext_sigalg_rsa(md) \
330 tlsext_sigalg_dsa(md) \
331 tlsext_sigalg_ecdsa(md)
333 static unsigned char tls12_sigalgs[] = {
334 #ifndef OPENSSL_NO_SHA512
338 #ifndef OPENSSL_NO_SHA256
342 #ifndef OPENSSL_NO_SHA
345 #ifndef OPENSSL_NO_MD5
352 size_t slen =
sizeof(tls12_sigalgs);
359 memcpy(p, tls12_sigalgs, slen);
366 unsigned char *ret =
p;
375 if (ret>=limit)
return NULL;
380 unsigned long size_str;
391 if ((lenmax = limit - ret - 9) < 0
420 if((limit - p - 4 - el) < 0)
return NULL;
434 #ifndef OPENSSL_NO_SRP
440 if (login_len > 255 || login_len == 0)
451 if ((limit - ret - 5 - login_len) < 0)
return NULL;
455 s2n(login_len+1,ret);
456 (*ret++) = (
unsigned char) login_len;
462 #ifndef OPENSSL_NO_EC
469 if ((lenmax = limit - ret - 5) < 0)
return NULL;
489 if ((lenmax = limit - ret - 6) < 0)
return NULL;
536 if ((
long)(limit - ret - 4 - ticklen) < 0)
return NULL;
549 if ((
size_t)(limit - ret) <
sizeof(tls12_sigalgs) + 6)
552 s2n(
sizeof(tls12_sigalgs) + 2, ret);
553 s2n(
sizeof(tls12_sigalgs), ret);
554 memcpy(ret, tls12_sigalgs,
sizeof(tls12_sigalgs));
555 ret +=
sizeof(tls12_sigalgs);
558 #ifdef TLSEXT_TYPE_opaque_prf_input
564 if ((
long)(limit - ret - 6 - col < 0))
569 s2n(TLSEXT_TYPE_opaque_prf_input, ret);
581 long extlen, idlen, itmp;
588 itmp = i2d_OCSP_RESPID(
id, NULL);
603 if ((
long)(limit - ret - 7 - extlen - idlen) < 0)
return NULL;
605 if (extlen + idlen > 0xFFF0)
607 s2n(extlen + idlen + 5, ret);
613 unsigned char *
q = ret;
617 itmp = i2d_OCSP_RESPID(
id, &ret);
626 #ifndef OPENSSL_NO_HEARTBEATS
640 #ifndef OPENSSL_NO_NEXTPROTONEG
645 if (limit - ret - 4 < 0)
652 if(SSL_get_srtp_profiles(s))
658 if((limit - p - 4 - el) < 0)
return NULL;
671 if ((extdatalen = ret-p-2)== 0)
681 unsigned char *ret =
p;
682 #ifndef OPENSSL_NO_NEXTPROTONEG
683 int next_proto_neg_seen;
691 if (ret>=limit)
return NULL;
695 if ((
long)(limit - ret - 4) < 0)
return NULL;
711 if((limit - p - 4 - el) < 0)
return NULL;
725 #ifndef OPENSSL_NO_EC
732 if ((lenmax = limit - ret - 5) < 0)
return NULL;
753 if ((
long)(limit - ret - 4) < 0)
return NULL;
760 if ((
long)(limit - ret - 4) < 0)
return NULL;
765 #ifdef TLSEXT_TYPE_opaque_prf_input
771 if ((
long)(limit - ret - 6 - sol) < 0)
776 s2n(TLSEXT_TYPE_opaque_prf_input, ret);
790 if((limit - p - 4 - el) < 0)
return NULL;
805 {
const unsigned char cryptopro_ext[36] = {
808 0x30, 0x1e, 0x30, 0x08, 0x06, 0x06, 0x2a, 0x85,
809 0x03, 0x02, 0x02, 0x09, 0x30, 0x08, 0x06, 0x06,
810 0x2a, 0x85, 0x03, 0x02, 0x02, 0x16, 0x30, 0x08,
811 0x06, 0x06, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x17};
812 if (limit-ret<36)
return NULL;
813 memcpy(ret,cryptopro_ext,36);
818 #ifndef OPENSSL_NO_HEARTBEATS
836 #ifndef OPENSSL_NO_NEXTPROTONEG
841 const unsigned char *npa;
848 if ((
long)(limit - ret - 4 - npalen) < 0)
return NULL;
851 memcpy(ret, npa, npalen);
858 if ((extdatalen = ret-p-2)== 0)
870 unsigned char *
data = *
p;
871 int renegotiate_seen = 0;
876 #ifndef OPENSSL_NO_NEXTPROTONEG
880 #ifndef OPENSSL_NO_HEARTBEATS
889 if (data > (d+n-len))
892 while (data <= (d+n-4))
897 if (data+size > (d+n))
900 fprintf(stderr,
"Received extension type %d size %d\n",type,size);
930 unsigned char *sdata;
950 servname_type = *(sdata++);
960 switch (servname_type)
1011 #ifndef OPENSSL_NO_SRP
1014 if (size <= 0 || ((len = data[0])) != (size -1))
1037 #ifndef OPENSSL_NO_EC
1041 unsigned char *sdata =
data;
1042 int ecpointformatlist_length = *(sdata++);
1044 if (ecpointformatlist_length != size - 1)
1069 fprintf(stderr,
"%i ",*(sdata++));
1070 fprintf(stderr,
"\n");
1076 unsigned char *sdata =
data;
1077 int ellipticcurvelist_length = (*(sdata++) << 8);
1078 ellipticcurvelist_length += (*(sdata++));
1080 if (ellipticcurvelist_length != size - 2)
1105 fprintf(stderr,
"%i ",*(sdata++));
1106 fprintf(stderr,
"\n");
1110 #ifdef TLSEXT_TYPE_opaque_prf_input
1111 else if (type == TLSEXT_TYPE_opaque_prf_input &&
1114 unsigned char *sdata =
data;
1154 renegotiate_seen = 1;
1159 if (sigalg_seen || size < 2)
1167 if (dsize != size || dsize & 1)
1192 const unsigned char *sdata;
1212 dsize -= 2 + idsize;
1221 id = d2i_OCSP_RESPID(NULL,
1230 OCSP_RESPID_free(
id);
1234 if (!s->tlsext_ocsp_ids
1235 && !(s->tlsext_ocsp_ids =
1238 OCSP_RESPID_free(
id);
1243 s->tlsext_ocsp_ids,
id))
1245 OCSP_RESPID_free(
id);
1270 X509_EXTENSION_free);
1274 d2i_X509_EXTENSIONS(NULL,
1277 || (data + dsize != sdata))
1290 #ifndef OPENSSL_NO_HEARTBEATS
1307 #ifndef OPENSSL_NO_NEXTPROTONEG
1359 #ifndef OPENSSL_NO_NEXTPROTONEG
1363 static char ssl_next_proto_validate(
unsigned char *d,
unsigned len)
1365 unsigned int off = 0;
1382 unsigned short type;
1383 unsigned short size;
1384 unsigned char *
data = *
p;
1385 int tlsext_servername = 0;
1386 int renegotiate_seen = 0;
1388 #ifndef OPENSSL_NO_NEXTPROTONEG
1392 #ifndef OPENSSL_NO_HEARTBEATS
1397 if (data >= (d+n-2))
1401 if (data+length != d+n)
1407 while(data <= (d+n-4))
1412 if (data+size > (d+n))
1426 tlsext_servername = 1;
1429 #ifndef OPENSSL_NO_EC
1433 unsigned char *sdata =
data;
1434 int ecpointformatlist_length = *(sdata++);
1436 if (ecpointformatlist_length != size - 1)
1451 fprintf(stderr,
"ssl_parse_serverhello_tlsext s->session->tlsext_ecpointformatlist ");
1454 fprintf(stderr,
"%i ",*(sdata++));
1455 fprintf(stderr,
"\n");
1476 #ifdef TLSEXT_TYPE_opaque_prf_input
1477 else if (type == TLSEXT_TYPE_opaque_prf_input &&
1480 unsigned char *sdata =
data;
1522 #ifndef OPENSSL_NO_NEXTPROTONEG
1526 unsigned char *selected;
1527 unsigned char selected_len;
1536 if (!ssl_next_proto_validate(data, size))
1561 renegotiate_seen = 1;
1563 #ifndef OPENSSL_NO_HEARTBEATS
1596 if (!s->
hit && tlsext_servername == 1)
1628 if (!renegotiate_seen
1644 #ifndef OPENSSL_NO_EC
1651 unsigned long alg_k, alg_a;
1690 sizeof(pref_list)/
sizeof(pref_list[0]); i++)
1698 #ifdef TLSEXT_TYPE_opaque_prf_input
1737 #ifndef OPENSSL_NO_EC
1771 #ifndef OPENSSL_NO_EC
1816 #ifdef TLSEXT_TYPE_opaque_prf_input
1896 #ifndef OPENSSL_NO_EC
1909 unsigned char *list;
1910 int found_uncompressed = 0;
1916 found_uncompressed = 1;
1920 if (!found_uncompressed)
1934 #ifdef TLSEXT_TYPE_opaque_prf_input
2040 const unsigned char *
p = session_id +
len;
2074 if ((p + 2) >= limit)
2077 while ((p + 4) <= limit)
2079 unsigned short type, size;
2082 if (p + size > limit)
2103 r = tls_decrypt_ticket(s, p, size, session_id, len, ret);
2138 static int tls_decrypt_ticket(
SSL *s,
const unsigned char *etick,
int eticklen,
2139 const unsigned char *sess_id,
int sesslen,
2143 unsigned char *sdec;
2144 const unsigned char *
p;
2145 int slen, mlen, renew_ticket = 0;
2158 unsigned char *nctick = (
unsigned char *)etick;
2192 if (memcmp(tick_hmac, etick + eticklen, mlen))
2244 #ifndef OPENSSL_NO_MD5
2247 #ifndef OPENSSL_NO_SHA
2250 #ifndef OPENSSL_NO_SHA256
2254 #ifndef OPENSSL_NO_SHA512
2261 #ifndef OPENSSL_NO_RSA
2264 #ifndef OPENSSL_NO_DSA
2267 #ifndef OPENSSL_NO_ECDSA
2275 for (i = 0; i < tlen; i++)
2277 if (table[i].nid == nid)
2283 static int tls12_find_nid(
int id,
tls12_lookup *table,
size_t tlen)
2286 for (i = 0; i < tlen; i++)
2288 if (table[i].
id ==
id)
2289 return table[i].
nid;
2307 p[0] = (
unsigned char)md_id;
2308 p[1] = (
unsigned char)sig_id;
2314 return tls12_find_id(pk->
type, tls12_sig,
2322 #ifndef OPENSSL_NO_MD5
2330 #ifndef OPENSSL_NO_SHA
2334 #ifndef OPENSSL_NO_SHA256
2341 #ifndef OPENSSL_NO_SHA512
2373 for (i = 0; i < dsize; i += 2)
2375 unsigned char hash_alg = data[i], sig_alg = data[i+1];
2379 #ifndef OPENSSL_NO_RSA
2384 #ifndef OPENSSL_NO_DSA
2389 #ifndef OPENSSL_NO_ECDSA
2415 #ifndef OPENSSL_NO_DSA
2419 #ifndef OPENSSL_NO_RSA
2426 #ifndef OPENSSL_NO_ECDSA
2435 #ifndef OPENSSL_NO_HEARTBEATS
2439 unsigned char *p = &s->
s3->
rrec.
data[0], *pl;
2440 unsigned short hbtype;
2441 unsigned int payload;
2442 unsigned int padding = 16;
2456 unsigned char *buffer, *
bp;
2469 memcpy(bp, pl, payload);
2478 buffer, 3 + payload + padding,
2508 unsigned char *buf, *
p;
2510 unsigned int payload = 18;
2511 unsigned int padding = 16;
2568 buf, 3 + payload + padding,