151 #define REUSE_CIPHER_BUG
152 #define NETSCAPE_HANG_BUG
163 #ifndef OPENSSL_NO_DH
167 #ifndef OPENSSL_NO_KRB5
172 static const SSL_METHOD *ssl3_get_server_method(
int ver);
174 static const SSL_METHOD *ssl3_get_server_method(
int ver)
182 #ifndef OPENSSL_NO_SRP
183 static int ssl_check_srp_ext_ClientHello(
SSL *s,
int *al)
210 ssl3_get_server_method)
215 unsigned long alg_k,Time=(
unsigned long)time(NULL);
218 int new_state,state,skip=0;
224 if (s->info_callback != NULL)
226 else if (s->ctx->info_callback != NULL)
227 cb=s->ctx->info_callback;
239 #ifndef OPENSSL_NO_HEARTBEATS
244 if (s->tlsext_hb_pending)
246 s->tlsext_hb_pending = 0;
269 if ((s->version>>8) != 3)
276 if (s->init_buf == NULL)
309 s->ctx->stats.sess_accept++;
311 else if (!s->s3->send_connection_binding &&
327 s->ctx->stats.sess_accept_renegotiate++;
337 if (ret <= 0)
goto end;
357 if (ret <= 0)
goto end;
359 #ifndef OPENSSL_NO_SRP
362 if ((ret = ssl_check_srp_ext_ClientHello(s,&al)) < 0)
389 if (ret <= 0)
goto end;
390 #ifndef OPENSSL_NO_TLSEXT
393 if (s->tlsext_ticket_expected)
411 if (!(s->s3->tmp.new_cipher->algorithm_auth &
SSL_aNULL)
412 && !(s->s3->tmp.new_cipher->algorithm_mkey &
SSL_kPSK)
413 && !(s->s3->tmp.new_cipher->algorithm_auth &
SSL_aKRB5))
416 if (ret <= 0)
goto end;
417 #ifndef OPENSSL_NO_TLSEXT
418 if (s->tlsext_status_expected)
440 alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
453 s->s3->tmp.use_rsa_tmp=1;
455 s->s3->tmp.use_rsa_tmp=0;
469 if (s->s3->tmp.use_rsa_tmp
472 #ifndef OPENSSL_NO_PSK
473 || ((alg_k &
SSL_kPSK) && s->ctx->psk_identity_hint)
475 #ifndef OPENSSL_NO_SRP
491 if (ret <= 0)
goto end;
506 ((s->session->peer != NULL) &&
511 ((s->s3->tmp.new_cipher->algorithm_auth &
SSL_aNULL) &&
516 (s->s3->tmp.new_cipher->algorithm_auth &
SSL_aKRB5)
519 || (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK))
523 s->s3->tmp.cert_request=0;
525 if (s->s3->handshake_buffer)
531 s->s3->tmp.cert_request=1;
533 if (ret <= 0)
goto end;
534 #ifndef NETSCAPE_HANG_BUG
547 if (ret <= 0)
goto end;
573 s->state=s->s3->tmp.next_state;
585 if (s->s3->tmp.cert_request)
588 if (ret <= 0)
goto end;
610 #if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
613 if (s->s3->next_proto_neg_seen)
624 if (!s->session->peer)
629 if (!s->s3->handshake_buffer)
651 if (s->s3->handshake_buffer)
655 if (s->s3->handshake_dgst[dgst_num])
659 s->method->ssl3_enc->cert_verify_mac(s,
EVP_MD_CTX_type(s->s3->handshake_dgst[dgst_num]),&(s->s3->tmp.cert_verify_md[offset]));
676 if (ret <= 0)
goto end;
678 #if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
681 if (s->s3->next_proto_neg_seen)
689 #if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
693 if (ret <= 0)
goto end;
703 if (ret <= 0)
goto end;
706 #ifndef OPENSSL_NO_TLSEXT
707 else if (s->tlsext_ticket_expected)
715 #ifndef OPENSSL_NO_TLSEXT
719 if (ret <= 0)
goto end;
727 if (ret <= 0)
goto end;
737 s->session->cipher=s->s3->tmp.new_cipher;
738 if (!s->method->ssl3_enc->setup_key_block(s))
739 { ret= -1;
goto end; }
744 if (ret <= 0)
goto end;
748 if (!s->method->ssl3_enc->change_cipher_state(s,
761 s->method->ssl3_enc->server_finished_label,
762 s->method->ssl3_enc->server_finished_label_len);
763 if (ret <= 0)
goto end;
767 #if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
770 if (s->s3->next_proto_neg_seen)
793 if (s->renegotiate == 2)
800 s->ctx->stats.sess_accept_good++;
818 if (!s->s3->tmp.reuse_message && !skip)
827 if ((
cb != NULL) && (s->state != state))
881 if (!ok)
return((
int)n);
894 #ifndef OPENSSL_NO_DH
901 #ifndef OPENSSL_NO_ECDH
916 int i,j,ok,al,ret= -1;
917 unsigned int cookie_len;
920 unsigned char *
p,*d,*
q;
922 #ifndef OPENSSL_NO_COMP
946 if (!ok)
return((
int)n);
974 unsigned int session_length, cookie_length;
979 if (cookie_length == 0)
1028 cookie_len = *(p++);
1077 if ((i == 0) && (j != 0))
1091 if ((i > 0) && (ssl_bytes_to_cipher_list(s,p,i,&(ciphers))
1099 if ((s->
hit) && (i > 0))
1105 printf(
"client sent %d ciphers\n",
sk_num(ciphers));
1111 printf(
"client [%2d of %2d]:%s\n",
1161 if (p[j] == 0)
break;
1173 #ifndef OPENSSL_NO_TLSEXT
1196 Time=(
unsigned long)time(NULL);
1222 if (pref_cipher == NULL)
1234 if (s->cipher_list_by_id)
1247 #ifndef OPENSSL_NO_COMP
1264 if (comp_id == comp->
id)
1277 for (m = 0; m < i; m++)
1279 if (q[m] == comp_id)
1293 int m,nn,o,v,done=0;
1296 for (m=0; m<nn; m++)
1332 #ifdef OPENSSL_NO_COMP
1340 if (ciphers == NULL)
1348 SSL_get_ciphers(s));
1361 #ifdef REUSE_CIPHER_BUG
1379 else if (ec != NULL)
1420 unsigned char *
p,*d;
1423 #ifdef OPENSSL_NO_TLSEXT
1430 #ifdef OPENSSL_NO_TLSEXT
1433 Time=(
unsigned long)time(NULL);
1482 #ifdef OPENSSL_NO_COMP
1490 #ifndef OPENSSL_NO_TLSEXT
1544 #ifndef OPENSSL_NO_RSA
1551 #ifndef OPENSSL_NO_DH
1554 #ifndef OPENSSL_NO_ECDH
1555 EC_KEY *ecdh=NULL, *ecdhp;
1556 unsigned char *encodedPoint = NULL;
1563 unsigned char *
p,*d;
1581 r[0]=r[1]=r[2]=r[3]=NULL;
1583 #ifndef OPENSSL_NO_RSA
1613 #ifndef OPENSSL_NO_DH
1641 if ((dhp->pub_key == NULL ||
1642 dhp->priv_key == NULL ||
1669 #ifndef OPENSSL_NO_ECDH
1754 encodedPoint = (
unsigned char *)
1757 if ((encodedPoint == NULL) || (bn_ctx == NULL))
1767 encodedPoint, encodedlen, bn_ctx);
1769 if (encodedlen == 0)
1795 #ifndef OPENSSL_NO_PSK
1803 #ifndef OPENSSL_NO_SRP
1826 for (i=0; r[i] != NULL && i<4; i++)
1829 #ifndef OPENSSL_NO_SRP
1830 if ((i == 2) && (type & SSL_kSRP))
1862 for (i=0; r[i] != NULL && i<4; i++)
1864 #ifndef OPENSSL_NO_SRP
1877 #ifndef OPENSSL_NO_ECDH
1878 if (type & SSL_kEECDH)
1894 memcpy((
unsigned char*)p,
1895 (
unsigned char *)encodedPoint,
1898 encodedPoint = NULL;
1903 #ifndef OPENSSL_NO_PSK
1904 if (type & SSL_kPSK)
1918 #ifndef OPENSSL_NO_RSA
1924 for (num=2; num > 0; num--)
1934 (
unsigned int *)&i);
1939 &(p[2]), &u, pkey->
pkey.
rsa) <= 0)
1965 fprintf(stderr,
"Using hash %s\n",
1973 (
unsigned int *)&i,pkey))
2007 #ifndef OPENSSL_NO_ECDH
2017 unsigned char *
p,*d;
2027 d=p=(
unsigned char *)&(buf->
data[4]);
2048 sk=SSL_get_client_CA_list(s);
2055 j=i2d_X509_NAME(name,NULL);
2061 p=(
unsigned char *)&(buf->
data[4+n]);
2065 i2d_X509_NAME(name,&p);
2072 i2d_X509_NAME(name,&p);
2073 j-=2;
s2n(j,d); j+=2;
2080 p=(
unsigned char *)&(buf->
data[4+off]);
2083 d=(
unsigned char *)buf->
data;
2092 #ifdef NETSCAPE_HANG_BUG
2116 unsigned long alg_k;
2118 #ifndef OPENSSL_NO_RSA
2122 #ifndef OPENSSL_NO_DH
2126 #ifndef OPENSSL_NO_KRB5
2130 #ifndef OPENSSL_NO_ECDH
2131 EC_KEY *srvr_ecdh = NULL;
2144 if (!ok)
return((
int)n);
2149 #ifndef OPENSSL_NO_RSA
2170 if ( (pkey == NULL) ||
2255 #ifndef OPENSSL_NO_DH
2319 #ifndef OPENSSL_NO_KRB5
2322 krb5_error_code krb5rc;
2323 krb5_data enc_ticket;
2324 krb5_data authenticator;
2333 krb5_timestamp authtime = 0;
2334 krb5_ticket_times ttimes;
2341 enc_ticket.length = i;
2343 if (n < (
long)(enc_ticket.length + 6))
2350 enc_ticket.data = (
char *)p;
2351 p+=enc_ticket.length;
2354 authenticator.length = i;
2356 if (n < (
long)(enc_ticket.length + authenticator.length + 6))
2363 authenticator.data = (
char *)p;
2364 p+=authenticator.length;
2368 enc_pms.data = (
char *)p;
2374 if(enc_pms.length >
sizeof pms)
2381 if (n != (
long)(enc_ticket.length + authenticator.length +
2382 enc_pms.length + 6))
2393 printf(
"kssl_sget_tkt rtn %d [%d]\n",
2394 krb5rc, kssl_err.
reason);
2396 printf(
"kssl_err text= %s\n", kssl_err.
text);
2407 &authtime, &kssl_err)) != 0)
2410 printf(
"kssl_check_authent rtn %d [%d]\n",
2411 krb5rc, kssl_err.
reason);
2413 printf(
"kssl_err text= %s\n", kssl_err.
text);
2434 memset(iv, 0,
sizeof iv);
2443 (
unsigned char *)enc_pms.data, enc_pms.length))
2512 #ifndef OPENSSL_NO_ECDH
2624 clnt_ecpoint, p, i, bn_ctx) == 0)
2638 if (field_size <= 0)
2668 #ifndef OPENSSL_NO_PSK
2671 unsigned char *
t = NULL;
2673 unsigned int pre_ms_len = 0, psk_len = 0;
2701 memcpy(tmp_id, p, i);
2704 psk_or_pre_ms,
sizeof(psk_or_pre_ms));
2713 else if (psk_len == 0)
2723 pre_ms_len=2+psk_len+2+psk_len;
2725 memmove(psk_or_pre_ms+psk_len+4, psk_or_pre_ms, psk_len);
2727 memset(t, 0, psk_len);
2763 #ifndef OPENSSL_NO_SRP
2805 EVP_PKEY *client_pub_pkey = NULL, *pk = NULL;
2806 unsigned char premaster_secret[32], *start;
2807 size_t outlen=32, inlen;
2808 unsigned long alg_a;
2824 if (client_pub_pkey)
2840 else if (p[1] < 0x80)
2884 #if !defined(OPENSSL_NO_DH) || !defined(OPENSSL_NO_RSA) || !defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_SRP)
2887 #ifndef OPENSSL_NO_ECDH
2890 if (srvr_ecdh != NULL)
2916 if (!ok)
return((
int)n);
2987 if (sigalg != (
int)p[1])
3001 fprintf(stderr,
"USING TLSv1.2 HASH %s\n",
EVP_MD_name(md));
3016 if ((i > j) || (n > j) || (n <= 0))
3035 fprintf(stderr,
"Using TLS 1.2 with client verify alg %s\n",
3054 #ifndef OPENSSL_NO_RSA
3075 #ifndef OPENSSL_NO_DSA
3091 #ifndef OPENSSL_NO_ECDSA
3109 {
unsigned char signature[64];
3114 fprintf(stderr,
"GOST signature length is %d",i);
3116 for (idx=0;idx<64;idx++) {
3117 signature[63-idx]=p[idx];
3157 int i,ok,al,ret= -1;
3159 unsigned long l,nc,llen,n;
3160 const unsigned char *
p,*
q;
3171 if (!ok)
return((
int)n);
3214 for (nc=0; nc<llen; )
3217 if ((l+nc+3) > llen)
3225 x=d2i_X509(NULL,&p,l);
3312 if (x != NULL) X509_free(x);
3346 #ifndef OPENSSL_NO_TLSEXT
3352 unsigned char *
p, *senc, *macstart;
3353 const unsigned char *const_p;
3354 int len, slen_full, slen;
3361 unsigned char key_name[16];
3368 if (slen_full > 0xFF00)
3387 if (slen > slen_full)
3448 memcpy(p, key_name, 16);
3519 # ifndef OPENSSL_NO_NEXTPROTONEG
3525 int proto_len, padding_len;
3527 const unsigned char *
p;
3570 padding_len = p[proto_len + 1];
3571 if (proto_len + padding_len + 2 != s->
init_num)