160 #include <openssl/fips.h>
162 #ifndef OPENSSL_NO_DH
166 #ifndef OPENSSL_NO_ENGINE
170 static const SSL_METHOD *ssl3_get_client_method(
int ver);
173 static const SSL_METHOD *ssl3_get_client_method(
int ver)
184 ssl3_get_client_method)
189 unsigned long Time=(
unsigned long)time(NULL);
192 int new_state,state,skip=0;
198 if (s->info_callback != NULL)
200 else if (s->ctx->info_callback != NULL)
201 cb=s->ctx->info_callback;
206 #ifndef OPENSSL_NO_HEARTBEATS
211 if (s->tlsext_hb_pending)
213 s->tlsext_hb_pending = 0;
227 s->ctx->stats.sess_connect_renegotiate++;
237 if ((s->version & 0xff00 ) != 0x0300)
247 if (s->init_buf == NULL)
273 s->ctx->stats.sess_connect++;
282 if (ret <= 0)
goto end;
287 if (s->bbio != s->wbio)
295 if (ret <= 0)
goto end;
300 #ifndef OPENSSL_NO_TLSEXT
301 if (s->tlsext_ticket_expected)
315 #ifndef OPENSSL_NO_TLSEXT
317 if (ret <= 0)
goto end;
321 if (s->tlsext_ticket_expected)
331 if (!(s->s3->tmp.new_cipher->algorithm_auth &
SSL_aNULL) &&
332 !(s->s3->tmp.new_cipher->algorithm_mkey &
SSL_kPSK))
335 if (ret <= 0)
goto end;
336 #ifndef OPENSSL_NO_TLSEXT
337 if (s->tlsext_status_expected)
360 if (ret <= 0)
goto end;
376 if (ret <= 0)
goto end;
384 if (ret <= 0)
goto end;
385 #ifndef OPENSSL_NO_SRP
386 if (s->s3->tmp.new_cipher->algorithm_mkey &
SSL_kSRP)
396 if (s->s3->tmp.cert_req)
409 if (ret <= 0)
goto end;
417 if (ret <= 0)
goto end;
429 if (s->s3->tmp.cert_req == 1)
436 s->s3->change_cipher_spec=0;
441 s->s3->change_cipher_spec=0;
450 if (ret <= 0)
goto end;
453 s->s3->change_cipher_spec=0;
460 if (ret <= 0)
goto end;
463 #if defined(OPENSSL_NO_TLSEXT) || defined(OPENSSL_NO_NEXTPROTONEG)
466 if (s->s3->next_proto_neg_seen)
473 s->session->cipher=s->s3->tmp.new_cipher;
474 #ifdef OPENSSL_NO_COMP
475 s->session->compress_meth=0;
477 if (s->s3->tmp.new_compression == NULL)
478 s->session->compress_meth=0;
480 s->session->compress_meth=
481 s->s3->tmp.new_compression->id;
483 if (!s->method->ssl3_enc->setup_key_block(s))
489 if (!s->method->ssl3_enc->change_cipher_state(s,
498 #if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
502 if (ret <= 0)
goto end;
511 s->method->ssl3_enc->client_finished_label,
512 s->method->ssl3_enc->client_finished_label_len);
513 if (ret <= 0)
goto end;
525 s->s3->delay_buf_pop_ret=0;
530 #ifndef OPENSSL_NO_TLSEXT
532 if (s->tlsext_ticket_expected)
542 #ifndef OPENSSL_NO_TLSEXT
546 if (ret <= 0)
goto end;
554 if (ret <= 0)
goto end;
565 if (ret <= 0)
goto end;
582 s->state=s->s3->tmp.next_state;
589 if (s->init_buf != NULL)
606 if (s->hit) s->ctx->stats.sess_hit++;
611 s->ctx->stats.sess_connect_good++;
626 if (!s->s3->tmp.reuse_message && !skip)
634 if ((
cb != NULL) && (s->state != state))
659 unsigned long Time,l;
660 #ifndef OPENSSL_NO_COMP
669 if ((sess == NULL) ||
671 #ifdef OPENSSL_NO_TLSEXT
684 Time=(
unsigned long)time(NULL);
758 #ifdef OPENSSL_MAX_TLS1_2_CIPHER_LENGTH
764 && i > OPENSSL_MAX_TLS1_2_CIPHER_LENGTH)
765 i = OPENSSL_MAX_TLS1_2_CIPHER_LENGTH & ~1;
771 #ifdef OPENSSL_NO_COMP
776 || !s->
ctx->comp_methods)
789 #ifndef OPENSSL_NO_TLSEXT
828 #ifndef OPENSSL_NO_COMP
839 if (!ok)
return((
int)n);
892 #ifndef OPENSSL_NO_TLSEXT
957 sk=ssl_get_ciphers_by_id(s);
993 #ifdef OPENSSL_NO_COMP
1028 if ((j != 0) && (comp == NULL))
1040 #ifndef OPENSSL_NO_TLSEXT
1075 int al,i,ok,ret= -1;
1076 unsigned long n,nc,llen,l;
1078 const unsigned char *
q,*
p;
1092 if (!ok)
return((
int)n);
1123 for (nc=0; nc<llen; )
1126 if ((l+nc+3) > llen)
1134 x=d2i_X509(NULL,&q,l);
1172 if (sc == NULL)
goto err;
1192 printf(
"pkey,x = %p, %p\n", pkey,x);
1193 printf(
"ssl_cert_type(x,pkey) = %d\n",
ssl_cert_type(x,pkey));
1208 if (need_cert && i < 0)
1261 #ifndef OPENSSL_NO_RSA
1265 unsigned char *param,*
p;
1266 int al,i,j,param_len,ok;
1270 #ifndef OPENSSL_NO_RSA
1273 #ifndef OPENSSL_NO_DH
1276 #ifndef OPENSSL_NO_ECDH
1281 int encoded_pt_len = 0;
1292 if (!ok)
return((
int)n);
1296 #ifndef OPENSSL_NO_PSK
1313 param=p=(
unsigned char *)s->
init_msg;
1316 #ifndef OPENSSL_NO_RSA
1323 #ifndef OPENSSL_NO_DH
1330 #ifndef OPENSSL_NO_ECDH
1348 #ifndef OPENSSL_NO_PSK
1377 memcpy(tmp_id_hint, p, i);
1393 #ifndef OPENSSL_NO_SRP
1426 i = (
unsigned int)(p[0]);
1459 #ifndef OPENSSL_NO_RSA
1466 #ifndef OPENSSL_NO_DSA
1473 #ifndef OPENSSL_NO_RSA
1527 #ifndef OPENSSL_NO_DH
1530 if ((dh=
DH_new()) == NULL)
1581 #ifndef OPENSSL_NO_RSA
1588 #ifndef OPENSSL_NO_DSA
1605 #ifndef OPENSSL_NO_ECDH
1627 if ((param_len > n) ||
1669 encoded_pt_len = *
p;
1671 param_len += (1 + encoded_pt_len);
1672 if ((param_len > n) ||
1674 p, encoded_pt_len, bn_ctx) == 0))
1689 #ifndef OPENSSL_NO_RSA
1693 #ifndef OPENSSL_NO_ECDSA
1704 srvr_ecpoint = NULL;
1730 if (sigalg != (
int)p[1])
1744 fprintf(stderr,
"USING TLSv1.2 HASH %s\n",
EVP_MD_name(md));
1756 if ((i != n) || (n > j) || (n <= 0))
1764 #ifndef OPENSSL_NO_RSA
1771 for (num=2; num > 0; num--)
1818 if (!(alg_a &
SSL_aNULL) && !(alg_k & SSL_kPSK))
1839 #ifndef OPENSSL_NO_RSA
1843 #ifndef OPENSSL_NO_DH
1847 #ifndef OPENSSL_NO_ECDH
1860 unsigned long n,nc,l;
1861 unsigned int llen, ctype_num,i;
1863 const unsigned char *
p,*
q;
1874 if (!ok)
return((
int)n);
1922 for (i=0; i<ctype_num; i++)
1931 if ((
unsigned long)(p - d + llen + 2) > n)
1951 out=fopen(
"/tmp/vsign.der",
"w");
1952 fwrite(p,1,llen,out);
1957 if ((
unsigned long)(p - d + llen) != n)
1964 for (nc=0; nc<llen; )
1967 if ((l+nc+2) > llen)
1978 if ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL)
2016 if (s->
s3->
tmp.ca_names != NULL)
2018 s->
s3->
tmp.ca_names=ca_sk;
2031 #ifndef OPENSSL_NO_TLSEXT
2034 int ok,al,ret=0, ticklen;
2036 const unsigned char *
p;
2072 if (ticklen + 6 != n)
2108 #ifndef OPENSSL_NO_SHA256
2124 unsigned long resplen,n;
2125 const unsigned char *
p;
2134 if (!ok)
return((
int)n);
2150 if (resplen + 4 != n)
2202 if (!ok)
return((
int)n);
2217 unsigned char *
p,*d;
2219 unsigned long alg_k;
2220 #ifndef OPENSSL_NO_RSA
2224 #ifndef OPENSSL_NO_KRB5
2227 #ifndef OPENSSL_NO_ECDH
2228 EC_KEY *clnt_ecdh = NULL;
2229 const EC_POINT *srvr_ecpoint = NULL;
2231 unsigned char *encodedPoint = NULL;
2232 int encoded_pt_len = 0;
2245 #ifndef OPENSSL_NO_RSA
2256 if ((pkey == NULL) ||
2269 if (
RAND_bytes(&(tmp_buf[2]),
sizeof tmp_buf-2) <= 0)
2300 tmp_buf,
sizeof tmp_buf);
2304 #ifndef OPENSSL_NO_KRB5
2307 krb5_error_code krb5rc;
2310 krb5_data *enc_ticket;
2311 krb5_data authenticator, *authp = NULL;
2318 int padl, outl =
sizeof(epms);
2323 printf(
"ssl3_send_client_key_exchange(%lx & %lx)\n",
2339 printf(
"kssl_cget_tkt rtn %d\n", krb5rc);
2340 if (krb5rc && kssl_err.
text)
2341 printf(
"kssl_cget_tkt kssl_err=%s\n", kssl_err.
text);
2374 s2n(enc_ticket->length,p);
2375 memcpy(p, enc_ticket->data, enc_ticket->length);
2376 p+= enc_ticket->length;
2377 n = enc_ticket->length + 2;
2380 if (authp && authp->length)
2382 s2n(authp->length,p);
2383 memcpy(p, authp->data, authp->length);
2385 n+= authp->length + 2;
2399 if (
RAND_bytes(&(tmp_buf[2]),
sizeof tmp_buf-2) <= 0)
2409 memset(iv, 0,
sizeof iv);
2416 if (outl > (
int)
sizeof epms)
2425 memcpy(p, epms, outl);
2432 tmp_buf,
sizeof tmp_buf);
2438 #ifndef OPENSSL_NO_DH
2441 DH *dh_srvr,*dh_clnt;
2504 #ifndef OPENSSL_NO_ECDH
2509 int ecdh_clnt_cert = 0;
2549 if ((srvr_pub_pkey == NULL) ||
2551 (srvr_pub_pkey->
pkey.
ec == NULL))
2558 tkey = srvr_pub_pkey->
pkey.
ec;
2564 if ((srvr_group == NULL) || (srvr_ecpoint == NULL))
2591 if (priv_key == NULL)
2617 if (field_size <= 0)
2633 -> generate_master_secret(s,
2655 encodedPoint = (
unsigned char *)
2657 sizeof(
unsigned char));
2659 if ((encodedPoint == NULL) ||
2670 encodedPoint, encoded_pt_len, bn_ctx);
2676 memcpy((
unsigned char *)p, encodedPoint, n);
2684 if (clnt_ecdh != NULL)
2695 unsigned int md_len;
2697 unsigned char premaster_secret[32],shared_ukm[32], tmp[256];
2757 *(p++)= msglen & 0xff;
2762 *(p++)= msglen & 0xff;
2765 memcpy(p, tmp, msglen);
2779 #ifndef OPENSSL_NO_SRP
2812 #ifndef OPENSSL_NO_PSK
2816 unsigned char *
t = NULL;
2818 unsigned int pre_ms_len = 0, psk_len = 0;
2831 psk_or_pre_ms,
sizeof(psk_or_pre_ms));
2838 else if (psk_len == 0)
2846 pre_ms_len = 2+psk_len+2+psk_len;
2848 memmove(psk_or_pre_ms+psk_len+4, psk_or_pre_ms, psk_len);
2850 memset(t, 0, psk_len);
2878 psk_or_pre_ms, pre_ms_len);
2879 n = strlen(identity);
2881 memcpy(p, identity, n);
2915 #ifndef OPENSSL_NO_ECDH
2918 if (clnt_ecdh != NULL)
2927 unsigned char *
p,*d;
2975 fprintf(stderr,
"Using TLS 1.2 with client alg %s\n",
2992 #ifndef OPENSSL_NO_RSA
3000 &(p[2]), &u, pkey->
pkey.
rsa) <= 0 )
3010 #ifndef OPENSSL_NO_DSA
3016 (
unsigned int *)&j,pkey->
pkey.
dsa))
3026 #ifndef OPENSSL_NO_ECDSA
3032 (
unsigned int *)&j,pkey->
pkey.
ec))
3045 unsigned char signbuf[64];
3051 if (
EVP_PKEY_sign(pctx, signbuf, &sigsize, data, 32) <= 0) {
3056 for (i=63,j=0; i>=0; j++, i--) {
3092 if ((s->
cert == NULL) ||
3114 if ((i == 1) && (pkey != NULL) && (x509 != NULL))
3127 if (x509 != NULL) X509_free(x509);
3159 #define has_bits(i,m) (((i)&(m)) == (m))
3167 #ifndef OPENSSL_NO_RSA
3170 #ifndef OPENSSL_NO_DH
3188 #ifndef OPENSSL_NO_RSA
3191 #ifndef OPENSSL_NO_DH
3198 #ifndef OPENSSL_NO_ECDH
3224 #ifndef OPENSSL_NO_DSA
3231 #ifndef OPENSSL_NO_RSA
3239 #ifndef OPENSSL_NO_DH
3251 #ifndef OPENSSL_NO_DSA
3262 #ifndef OPENSSL_NO_RSA
3263 if (alg_k & SSL_kRSA)
3274 #ifndef OPENSSL_NO_DH
3275 if (alg_k & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
3298 #if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
3301 unsigned int len, padding_len;
3307 padding_len = 32 - ((len + 2) % 32);
3311 d[5 +
len] = padding_len;
3312 memset(d + 6 + len, 0, padding_len);
3314 l2n3(2 + len + padding_len, d);
3316 s->
init_num = 4 + 2 + len + padding_len;
3329 #ifndef OPENSSL_NO_TLSEXT
3345 if (!ok)
return((
int)n);
3358 #ifndef OPENSSL_NO_ENGINE
3362 SSL_get_client_CA_list(s),
3363 px509, ppkey, NULL, NULL, NULL);