2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
67 /* SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,ERR_R_MALLOC_FAILURE);
68 * SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
69 * SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,ERR_R_MALLOC_FAILURE);
70 * SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
71 * SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
72 * SSLerr(SSL_F_SSL3_GET_SERVER_DONE,ERR_R_MALLOC_FAILURE);
73 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_SHORT);
77 static SSL_METHOD *ssl3_get_client_method(int ver);
78 static int ssl3_client_hello(SSL *s);
79 static int ssl3_get_server_hello(SSL *s);
80 static int ssl3_get_certificate_request(SSL *s);
81 static int ca_dn_cmp(X509_NAME **a,X509_NAME **b);
82 static int ssl3_get_server_done(SSL *s);
83 static int ssl3_send_client_verify(SSL *s);
84 static int ssl3_send_client_certificate(SSL *s);
85 static int ssl3_send_client_key_exchange(SSL *s);
86 static int ssl3_get_key_exchange(SSL *s);
87 static int ssl3_get_server_certificate(SSL *s);
88 static int ssl3_check_cert_and_algorithm(SSL *s);
90 static SSL_METHOD *ssl3_get_client_method();
91 static int ssl3_client_hello();
92 static int ssl3_get_server_hello();
93 static int ssl3_get_certificate_request();
94 static int ca_dn_cmp();
95 static int ssl3_get_server_done();
96 static int ssl3_send_client_verify();
97 static int ssl3_send_client_certificate();
98 static int ssl3_send_client_key_exchange();
99 static int ssl3_get_key_exchange();
100 static int ssl3_get_server_certificate();
101 static int ssl3_check_cert_and_algorithm();
104 static SSL_METHOD *ssl3_get_client_method(ver)
107 if (ver == SSL3_VERSION)
108 return(SSLv3_client_method());
113 SSL_METHOD *SSLv3_client_method()
116 static SSL_METHOD SSLv3_client_data;
121 memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(),
123 SSLv3_client_data.ssl_connect=ssl3_connect;
124 SSLv3_client_data.get_ssl_method=ssl3_get_client_method;
126 return(&SSLv3_client_data);
133 unsigned long Time=time(NULL),l;
137 int new_state,state,skip=0;;
139 RAND_seed(&Time,sizeof(Time));
143 if (s->info_callback != NULL)
145 else if (s->ctx->info_callback != NULL)
146 cb=s->ctx->info_callback;
148 if (!SSL_in_init(s) || SSL_in_before(s)) SSL_clear(s);
157 case SSL_ST_RENEGOTIATE:
159 s->state=SSL_ST_CONNECT;
160 s->ctx->stats.sess_connect_renegotiate++;
164 case SSL_ST_BEFORE|SSL_ST_CONNECT:
165 case SSL_ST_OK|SSL_ST_CONNECT:
168 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1);
170 if ((s->version & 0xff00 ) != 0x0300)
172 /* s->version=SSL3_VERSION; */
173 s->type=SSL_ST_CONNECT;
175 if (s->init_buf == NULL)
177 if ((buf=BUF_MEM_new()) == NULL)
182 if (!BUF_MEM_grow(buf,SSL3_RT_MAX_PLAIN_LENGTH))
190 if (!ssl3_setup_buffers(s)) { ret= -1; goto end; }
192 /* setup buffing BIO */
193 if (!ssl_init_wbio_buffer(s,0)) { ret= -1; goto end; }
195 /* don't push the buffering BIO quite yet */
197 ssl3_init_finished_mac(s);
199 s->state=SSL3_ST_CW_CLNT_HELLO_A;
200 s->ctx->stats.sess_connect++;
204 case SSL3_ST_CW_CLNT_HELLO_A:
205 case SSL3_ST_CW_CLNT_HELLO_B:
208 ret=ssl3_client_hello(s);
209 if (ret <= 0) goto end;
210 s->state=SSL3_ST_CR_SRVR_HELLO_A;
213 /* turn on buffering for the next lot of output */
214 if (s->bbio != s->wbio)
215 s->wbio=BIO_push(s->bbio,s->wbio);
219 case SSL3_ST_CR_SRVR_HELLO_A:
220 case SSL3_ST_CR_SRVR_HELLO_B:
221 ret=ssl3_get_server_hello(s);
222 if (ret <= 0) goto end;
224 s->state=SSL3_ST_CR_FINISHED_A;
226 s->state=SSL3_ST_CR_CERT_A;
230 case SSL3_ST_CR_CERT_A:
231 case SSL3_ST_CR_CERT_B:
232 /* Check if it is anon DH */
233 if (!(s->s3->tmp.new_cipher->algorithms & SSL_aNULL))
235 ret=ssl3_get_server_certificate(s);
236 if (ret <= 0) goto end;
240 s->state=SSL3_ST_CR_KEY_EXCH_A;
244 case SSL3_ST_CR_KEY_EXCH_A:
245 case SSL3_ST_CR_KEY_EXCH_B:
246 ret=ssl3_get_key_exchange(s);
247 if (ret <= 0) goto end;
248 s->state=SSL3_ST_CR_CERT_REQ_A;
251 /* at this point we check that we have the
252 * required stuff from the server */
253 if (!ssl3_check_cert_and_algorithm(s))
260 case SSL3_ST_CR_CERT_REQ_A:
261 case SSL3_ST_CR_CERT_REQ_B:
262 ret=ssl3_get_certificate_request(s);
263 if (ret <= 0) goto end;
264 s->state=SSL3_ST_CR_SRVR_DONE_A;
268 case SSL3_ST_CR_SRVR_DONE_A:
269 case SSL3_ST_CR_SRVR_DONE_B:
270 ret=ssl3_get_server_done(s);
271 if (ret <= 0) goto end;
272 if (s->s3->tmp.cert_req)
273 s->state=SSL3_ST_CW_CERT_A;
275 s->state=SSL3_ST_CW_KEY_EXCH_A;
280 case SSL3_ST_CW_CERT_A:
281 case SSL3_ST_CW_CERT_B:
282 case SSL3_ST_CW_CERT_C:
283 ret=ssl3_send_client_certificate(s);
284 if (ret <= 0) goto end;
285 s->state=SSL3_ST_CW_KEY_EXCH_A;
289 case SSL3_ST_CW_KEY_EXCH_A:
290 case SSL3_ST_CW_KEY_EXCH_B:
291 ret=ssl3_send_client_key_exchange(s);
292 if (ret <= 0) goto end;
293 l=s->s3->tmp.new_cipher->algorithms;
294 /* EAY EAY EAY need to check for DH fix cert
296 /* For TLS, cert_req is set to 2, so a cert chain
297 * of nothing is sent, but no verify packet is sent */
298 if (s->s3->tmp.cert_req == 1)
300 s->state=SSL3_ST_CW_CERT_VRFY_A;
304 s->state=SSL3_ST_CW_CHANGE_A;
305 s->s3->change_cipher_spec=0;
311 case SSL3_ST_CW_CERT_VRFY_A:
312 case SSL3_ST_CW_CERT_VRFY_B:
313 ret=ssl3_send_client_verify(s);
314 if (ret <= 0) goto end;
315 s->state=SSL3_ST_CW_CHANGE_A;
317 s->s3->change_cipher_spec=0;
320 case SSL3_ST_CW_CHANGE_A:
321 case SSL3_ST_CW_CHANGE_B:
322 ret=ssl3_send_change_cipher_spec(s,
323 SSL3_ST_CW_CHANGE_A,SSL3_ST_CW_CHANGE_B);
324 if (ret <= 0) goto end;
325 s->state=SSL3_ST_CW_FINISHED_A;
328 s->session->cipher=s->s3->tmp.new_cipher;
329 if (s->s3->tmp.new_compression == NULL)
330 s->session->compress_meth=0;
332 s->session->compress_meth=
333 s->s3->tmp.new_compression->id;
334 if (!s->method->ssl3_enc->setup_key_block(s))
340 if (!s->method->ssl3_enc->change_cipher_state(s,
341 SSL3_CHANGE_CIPHER_CLIENT_WRITE))
349 case SSL3_ST_CW_FINISHED_A:
350 case SSL3_ST_CW_FINISHED_B:
351 ret=ssl3_send_finished(s,
352 SSL3_ST_CW_FINISHED_A,SSL3_ST_CW_FINISHED_B,
353 s->method->ssl3_enc->client_finished,
354 s->method->ssl3_enc->client_finished_len);
355 if (ret <= 0) goto end;
356 s->state=SSL3_ST_CW_FLUSH;
359 s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
362 s->s3->tmp.next_state=SSL_ST_OK;
363 if (s->s3->flags & SSL3_FLAGS_DELAY_CLIENT_FINISHED)
366 s->s3->flags|=SSL3_FLAGS_POP_BUFFER;
367 s->s3->delay_buf_pop_ret=0;
372 s->s3->tmp.next_state=SSL3_ST_CR_FINISHED_A;
377 case SSL3_ST_CR_FINISHED_A:
378 case SSL3_ST_CR_FINISHED_B:
380 ret=ssl3_get_finished(s,SSL3_ST_CR_FINISHED_A,
381 SSL3_ST_CR_FINISHED_B);
382 if (ret <= 0) goto end;
385 s->state=SSL3_ST_CW_CHANGE_A;
391 case SSL3_ST_CW_FLUSH:
392 /* number of bytes to be flushed */
393 num1=BIO_ctrl(s->wbio,BIO_CTRL_INFO,0,NULL);
396 s->rwstate=SSL_WRITING;
397 num1=BIO_flush(s->wbio);
398 if (num1 <= 0) { ret= -1; goto end; }
399 s->rwstate=SSL_NOTHING;
402 s->state=s->s3->tmp.next_state;
406 /* clean a few things up */
407 ssl3_cleanup_key_block(s);
409 if (s->init_buf != NULL)
411 BUF_MEM_free(s->init_buf);
415 /* If we are not 'joining' the last two packets,
416 * remove the buffering now */
417 if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER))
418 ssl_free_wbio_buffer(s);
419 /* else do it later in ssl3_write */
424 ssl_update_cache(s,SSL_SESS_CACHE_CLIENT);
425 if (s->hit) s->ctx->stats.sess_hit++;
429 s->handshake_func=ssl3_connect;
430 s->ctx->stats.sess_connect_good++;
432 if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1);
438 SSLerr(SSL_F_SSL3_CONNECT,SSL_R_UNKNOWN_STATE);
444 /* did we do anything */
445 if (!s->s3->tmp.reuse_message && !skip)
449 if ((ret=BIO_flush(s->wbio)) <= 0)
453 if ((cb != NULL) && (s->state != state))
457 cb(s,SSL_CB_CONNECT_LOOP,1);
465 cb(s,SSL_CB_CONNECT_EXIT,ret);
471 static int ssl3_client_hello(s)
477 unsigned long Time,l;
480 buf=(unsigned char *)s->init_buf->data;
481 if (s->state == SSL3_ST_CW_CLNT_HELLO_A)
483 if ((s->session == NULL) ||
484 (s->session->ssl_version != s->version) ||
485 (s->session->not_resumable))
487 if (!ssl_get_new_session(s,0))
490 /* else use the pre-loaded session */
492 p=s->s3->client_random;
493 Time=time(NULL); /* Time */
495 RAND_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time));
497 /* Do the message type and length last */
500 *(p++)=s->version>>8;
501 *(p++)=s->version&0xff;
502 s->client_version=s->version;
505 memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE);
512 i=s->session->session_id_length;
516 memcpy(p,s->session->session_id,i);
520 /* Ciphers supported */
521 i=ssl_cipher_list_to_bytes(s,SSL_get_ciphers(s),&(p[2]));
524 SSLerr(SSL_F_SSL3_CLIENT_HELLO,SSL_R_NO_CIPHERS_AVAILABLE);
531 if (s->ctx->comp_methods == NULL)
534 j=sk_SSL_COMP_num(s->ctx->comp_methods);
538 comp=sk_SSL_COMP_value(s->ctx->comp_methods,i);
541 *(p++)=0; /* Add the NULL method */
545 *(d++)=SSL3_MT_CLIENT_HELLO;
548 s->state=SSL3_ST_CW_CLNT_HELLO_B;
549 /* number of bytes to write */
554 /* SSL3_ST_CW_CLNT_HELLO_B */
555 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
560 static int ssl3_get_server_hello(s)
563 STACK_OF(SSL_CIPHER) *sk;
571 n=ssl3_get_message(s,
572 SSL3_ST_CR_SRVR_HELLO_A,
573 SSL3_ST_CR_SRVR_HELLO_B,
574 SSL3_MT_SERVER_HELLO,
578 if (!ok) return((int)n);
579 d=p=(unsigned char *)s->init_buf->data;
581 if ((p[0] != (s->version>>8)) || (p[1] != (s->version&0xff)))
583 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_SSL_VERSION);
584 s->version=(s->version&0xff00)|p[1];
585 al=SSL_AD_PROTOCOL_VERSION;
590 /* load the server hello data */
591 /* load the server random */
592 memcpy(s->s3->server_random,p,SSL3_RANDOM_SIZE);
595 /* get the session-id */
598 if ((j != 0) && (j != SSL3_SESSION_ID_SIZE))
600 /* SSLref returns 16 :-( */
601 if (j < SSL2_SSL_SESSION_ID_LENGTH)
603 al=SSL_AD_ILLEGAL_PARAMETER;
604 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_SHORT);
608 if (j != 0 && j == s->session->session_id_length
609 && memcmp(p,s->session->session_id,j) == 0)
611 if(s->sid_ctx_length != s->session->sid_ctx_length
612 || memcmp(s->session->sid_ctx,s->sid_ctx,s->sid_ctx_length))
614 al=SSL_AD_ILLEGAL_PARAMETER;
615 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
620 else /* a miss or crap from the other end */
622 /* If we were trying for session-id reuse, make a new
623 * SSL_SESSION so we don't stuff up other people */
625 if (s->session->session_id_length > 0)
627 if (!ssl_get_new_session(s,0))
629 al=SSL_AD_INTERNAL_ERROR;
633 s->session->session_id_length=j;
634 memcpy(s->session->session_id,p,j); /* j could be 0 */
637 c=ssl_get_cipher_by_char(s,p);
641 al=SSL_AD_ILLEGAL_PARAMETER;
642 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNKNOWN_CIPHER_RETURNED);
645 p+=ssl_put_cipher_by_char(s,NULL,NULL);
647 sk=ssl_get_ciphers_by_id(s);
648 i=sk_SSL_CIPHER_find(sk,c);
651 /* we did not say we would use this cipher */
652 al=SSL_AD_ILLEGAL_PARAMETER;
653 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_WRONG_CIPHER_RETURNED);
657 if (s->hit && (s->session->cipher != c))
660 SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG))
662 al=SSL_AD_ILLEGAL_PARAMETER;
663 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);
667 s->s3->tmp.new_cipher=c;
669 /* lets get the compression algorithm */
675 comp=ssl3_comp_find(s->ctx->comp_methods,j);
677 if ((j != 0) && (comp == NULL))
679 al=SSL_AD_ILLEGAL_PARAMETER;
680 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
685 s->s3->tmp.new_compression=comp;
690 /* wrong packet length */
691 al=SSL_AD_DECODE_ERROR;
692 SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_BAD_PACKET_LENGTH);
698 ssl3_send_alert(s,SSL3_AL_FATAL,al);
703 static int ssl3_get_server_certificate(s)
707 unsigned long n,nc,llen,l;
709 unsigned char *p,*d,*q;
710 STACK_OF(X509) *sk=NULL;
714 n=ssl3_get_message(s,
718 #if defined(MSDOS) && !defined(WIN32)
719 1024*30, /* 30k max cert list :-) */
721 1024*100, /* 100k max cert list :-) */
725 if (!ok) return((int)n);
727 if (s->s3->tmp.message_type == SSL3_MT_SERVER_KEY_EXCHANGE)
729 s->s3->tmp.reuse_message=1;
733 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE)
735 al=SSL_AD_UNEXPECTED_MESSAGE;
736 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_BAD_MESSAGE_TYPE);
739 d=p=(unsigned char *)s->init_buf->data;
741 if ((sk=sk_X509_new_null()) == NULL)
743 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
750 al=SSL_AD_DECODE_ERROR;
751 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_LENGTH_MISMATCH);
754 for (nc=0; nc<llen; )
759 al=SSL_AD_DECODE_ERROR;
760 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
765 x=d2i_X509(NULL,&q,l);
768 al=SSL_AD_BAD_CERTIFICATE;
769 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_ASN1_LIB);
774 al=SSL_AD_DECODE_ERROR;
775 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH);
778 if (!sk_X509_push(sk,x))
780 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE);
788 i=ssl_verify_cert_chain(s,sk);
789 if ((s->verify_mode != SSL_VERIFY_NONE) && (!i))
791 al=ssl_verify_alarm_type(s->verify_result);
792 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED);
797 if (c == NULL) goto err;
799 if (s->session->cert) ssl_cert_free(s->session->cert);
803 x=sk_X509_value(sk,0);
806 pkey=X509_get_pubkey(x);
808 if ((pkey == NULL) || EVP_PKEY_missing_parameters(pkey))
812 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS);
816 i=ssl_cert_type(x,pkey);
821 SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
826 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
827 if (c->pkeys[i].x509 != NULL)
828 X509_free(c->pkeys[i].x509);
830 c->key= &(c->pkeys[i]);
832 if ((s->session != NULL) && (s->session->peer != NULL))
833 X509_free(s->session->peer);
834 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
843 ssl3_send_alert(s,SSL3_AL_FATAL,al);
848 sk_X509_pop_free(sk,X509_free);
852 static int ssl3_get_key_exchange(s)
856 unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2];
859 unsigned char *param,*p;
860 int al,i,j,param_len,ok;
868 n=ssl3_get_message(s,
869 SSL3_ST_CR_KEY_EXCH_A,
870 SSL3_ST_CR_KEY_EXCH_B,
875 if (!ok) return((int)n);
877 if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE)
879 s->s3->tmp.reuse_message=1;
883 param=p=(unsigned char *)s->init_buf->data;
885 if (s->session->cert != NULL)
888 if (s->session->cert->rsa_tmp != NULL)
890 RSA_free(s->session->cert->rsa_tmp);
891 s->session->cert->rsa_tmp=NULL;
895 if (s->session->cert->dh_tmp)
897 DH_free(s->session->cert->dh_tmp);
898 s->session->cert->dh_tmp=NULL;
904 s->session->cert=ssl_cert_new();
908 alg=s->s3->tmp.new_cipher->algorithms;
913 if ((rsa=RSA_new()) == NULL)
915 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE);
922 al=SSL_AD_DECODE_ERROR;
923 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_MODULUS_LENGTH);
926 if (!(rsa->n=BN_bin2bn(p,i,rsa->n)))
928 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
937 al=SSL_AD_DECODE_ERROR;
938 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_E_LENGTH);
941 if (!(rsa->e=BN_bin2bn(p,i,rsa->e)))
943 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
949 /* s->session->cert->rsa_tmp=rsa;*/
950 /* this should be because we are using an export cipher */
952 pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509);
955 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
958 s->session->cert->rsa_tmp=rsa;
965 if ((dh=DH_new()) == NULL)
967 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_DH_LIB);
974 al=SSL_AD_DECODE_ERROR;
975 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_P_LENGTH);
978 if (!(dh->p=BN_bin2bn(p,i,NULL)))
980 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
989 al=SSL_AD_DECODE_ERROR;
990 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_G_LENGTH);
993 if (!(dh->g=BN_bin2bn(p,i,NULL)))
995 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
1004 al=SSL_AD_DECODE_ERROR;
1005 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_DH_PUB_KEY_LENGTH);
1008 if (!(dh->pub_key=BN_bin2bn(p,i,NULL)))
1010 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_BN_LIB);
1018 pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509);
1023 pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_DSA_SIGN].x509);
1025 /* else anonymous DH, so no certificate or pkey. */
1027 s->session->cert->dh_tmp=dh;
1030 else if ((alg & SSL_kDHr) || (alg & SSL_kDHd))
1032 al=SSL_AD_ILLEGAL_PARAMETER;
1033 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
1039 al=SSL_AD_HANDSHAKE_FAILURE;
1040 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER);
1045 /* p points to the next byte, there are 'n' bytes left */
1048 /* if it was signed, check the signature */
1053 j=EVP_PKEY_size(pkey);
1055 if ((i != n) || (n > j) || (n <= 0))
1057 /* wrong packet length */
1058 al=SSL_AD_DECODE_ERROR;
1059 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH);
1064 if (pkey->type == EVP_PKEY_RSA)
1070 for (num=2; num > 0; num--)
1072 EVP_DigestInit(&md_ctx,(num == 2)
1073 ?s->ctx->md5:s->ctx->sha1);
1074 EVP_DigestUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1075 EVP_DigestUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1076 EVP_DigestUpdate(&md_ctx,param,param_len);
1077 EVP_DigestFinal(&md_ctx,q,(unsigned int *)&i);
1081 i=RSA_public_decrypt((int)n,p,p,pkey->pkey.rsa,
1085 al=SSL_AD_DECRYPT_ERROR;
1086 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT);
1089 if ((j != i) || (memcmp(p,md_buf,i) != 0))
1092 al=SSL_AD_DECRYPT_ERROR;
1093 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);
1100 if (pkey->type == EVP_PKEY_DSA)
1103 EVP_VerifyInit(&md_ctx,EVP_dss1());
1104 EVP_VerifyUpdate(&md_ctx,&(s->s3->client_random[0]),SSL3_RANDOM_SIZE);
1105 EVP_VerifyUpdate(&md_ctx,&(s->s3->server_random[0]),SSL3_RANDOM_SIZE);
1106 EVP_VerifyUpdate(&md_ctx,param,param_len);
1107 if (!EVP_VerifyFinal(&md_ctx,p,(int)n,pkey))
1110 al=SSL_AD_DECRYPT_ERROR;
1111 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_BAD_SIGNATURE);
1118 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1124 /* still data left over */
1125 if (!(alg & SSL_aNULL))
1127 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1132 al=SSL_AD_DECODE_ERROR;
1133 SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_EXTRA_DATA_IN_MESSAGE);
1137 EVP_PKEY_free(pkey);
1140 ssl3_send_alert(s,SSL3_AL_FATAL,al);
1142 EVP_PKEY_free(pkey);
1146 static int ssl3_get_certificate_request(s)
1150 unsigned long n,nc,l;
1151 unsigned int llen,ctype_num,i;
1153 unsigned char *p,*d,*q;
1154 STACK_OF(X509_NAME) *ca_sk=NULL;
1156 n=ssl3_get_message(s,
1157 SSL3_ST_CR_CERT_REQ_A,
1158 SSL3_ST_CR_CERT_REQ_B,
1160 #if defined(MSDOS) && !defined(WIN32)
1161 1024*30, /* 30k max cert list :-) */
1163 1024*100, /* 100k max cert list :-) */
1167 if (!ok) return((int)n);
1169 s->s3->tmp.cert_req=0;
1171 if (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE)
1173 s->s3->tmp.reuse_message=1;
1177 if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST)
1179 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1180 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_WRONG_MESSAGE_TYPE);
1184 /* TLS does not like anon-DH with client cert */
1185 if (s->version > SSL3_VERSION)
1187 l=s->s3->tmp.new_cipher->algorithms;
1190 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_UNEXPECTED_MESSAGE);
1191 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER);
1196 d=p=(unsigned char *)s->init_buf->data;
1198 if ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL)
1200 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1204 /* get the certificate types */
1206 if (ctype_num > SSL3_CT_NUMBER)
1207 ctype_num=SSL3_CT_NUMBER;
1208 for (i=0; i<ctype_num; i++)
1209 s->s3->tmp.ctype[i]= p[i];
1212 /* get the CA RDNs */
1217 out=fopen("/tmp/vsign.der","w");
1218 fwrite(p,1,llen,out);
1223 if ((llen+ctype_num+2+1) != n)
1225 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1226 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_LENGTH_MISMATCH);
1230 for (nc=0; nc<llen; )
1233 if ((l+nc+2) > llen)
1235 if ((s->options & SSL_OP_NETSCAPE_CA_DN_BUG))
1236 goto cont; /* netscape bugs */
1237 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1238 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_TOO_LONG);
1244 if ((xn=d2i_X509_NAME(NULL,&q,l)) == NULL)
1246 /* If netscape tollerance is on, ignore errors */
1247 if (s->options & SSL_OP_NETSCAPE_CA_DN_BUG)
1251 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1252 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_ASN1_LIB);
1259 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1260 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH);
1263 if (!sk_X509_NAME_push(ca_sk,xn))
1265 SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE);
1279 /* we should setup a certficate to return.... */
1280 s->s3->tmp.cert_req=1;
1281 s->s3->tmp.ctype_num=ctype_num;
1282 if (s->s3->tmp.ca_names != NULL)
1283 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
1284 s->s3->tmp.ca_names=ca_sk;
1289 if (ca_sk != NULL) sk_X509_NAME_pop_free(ca_sk,X509_NAME_free);
1293 static int ca_dn_cmp(a,b)
1296 return(X509_NAME_cmp(*a,*b));
1299 static int ssl3_get_server_done(s)
1305 n=ssl3_get_message(s,
1306 SSL3_ST_CR_SRVR_DONE_A,
1307 SSL3_ST_CR_SRVR_DONE_B,
1308 SSL3_MT_SERVER_DONE,
1309 30, /* should be very small, like 0 :-) */
1312 if (!ok) return((int)n);
1315 /* should contain no data */
1316 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR);
1317 SSLerr(SSL_F_SSL3_GET_SERVER_DONE,SSL_R_LENGTH_MISMATCH);
1323 static int ssl3_send_client_key_exchange(s)
1326 unsigned char *p,*q,*d;
1329 EVP_PKEY *pkey=NULL;
1331 if (s->state == SSL3_ST_CW_KEY_EXCH_A)
1333 d=(unsigned char *)s->init_buf->data;
1336 l=s->s3->tmp.new_cipher->algorithms;
1342 unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH];
1344 if (s->session->cert->rsa_tmp != NULL)
1345 rsa=s->session->cert->rsa_tmp;
1348 pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509);
1349 if ((pkey == NULL) ||
1350 (pkey->type != EVP_PKEY_RSA) ||
1351 (pkey->pkey.rsa == NULL))
1353 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1359 tmp_buf[0]=s->client_version>>8;
1360 tmp_buf[1]=s->client_version&0xff;
1361 RAND_bytes(&(tmp_buf[2]),SSL_MAX_MASTER_KEY_LENGTH-2);
1363 s->session->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
1366 /* Fix buf for TLS and beyond */
1367 if (s->version > SSL3_VERSION)
1369 n=RSA_public_encrypt(SSL_MAX_MASTER_KEY_LENGTH,
1370 tmp_buf,p,rsa,RSA_PKCS1_PADDING);
1372 if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++;
1373 if (s->options & SSL_OP_PKCS1_CHECK_2) tmp_buf[0]=0x70;
1377 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT);
1381 /* Fix buf for TLS and beyond */
1382 if (s->version > SSL3_VERSION)
1388 s->session->master_key_length=
1389 s->method->ssl3_enc->generate_master_secret(s,
1390 s->session->master_key,
1391 tmp_buf,SSL_MAX_MASTER_KEY_LENGTH);
1392 memset(tmp_buf,0,SSL_MAX_MASTER_KEY_LENGTH);
1397 if (l & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1399 DH *dh_srvr,*dh_clnt;
1401 if (s->session->cert->dh_tmp != NULL)
1402 dh_srvr=s->session->cert->dh_tmp;
1405 /* we get them from the cert */
1406 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1407 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_UNABLE_TO_FIND_DH_PARAMETERS);
1411 /* generate a new random key */
1412 if ((dh_clnt=DHparams_dup(dh_srvr)) == NULL)
1414 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1417 if (!DH_generate_key(dh_clnt))
1419 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1423 /* use the 'p' output buffer for the DH key, but
1424 * make sure to clear it out afterwards */
1426 n=DH_compute_key(p,dh_srvr->pub_key,dh_clnt);
1430 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,ERR_R_DH_LIB);
1434 /* generate master key from the result */
1435 s->session->master_key_length=
1436 s->method->ssl3_enc->generate_master_secret(s,
1437 s->session->master_key,p,n);
1441 /* send off the data */
1442 n=BN_num_bytes(dh_clnt->pub_key);
1444 BN_bn2bin(dh_clnt->pub_key,p);
1449 /* perhaps clean things up a bit EAY EAY EAY EAY*/
1454 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);
1455 SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR);
1459 *(d++)=SSL3_MT_CLIENT_KEY_EXCHANGE;
1462 s->state=SSL3_ST_CW_KEY_EXCH_B;
1463 /* number of bytes to write */
1468 /* SSL3_ST_CW_KEY_EXCH_B */
1469 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1474 static int ssl3_send_client_verify(s)
1477 unsigned char *p,*d;
1478 unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH];
1486 if (s->state == SSL3_ST_CW_CERT_VRFY_A)
1488 d=(unsigned char *)s->init_buf->data;
1490 pkey=s->cert->key->privatekey;
1492 s->method->ssl3_enc->cert_verify_mac(s,&(s->s3->finish_dgst2),
1493 &(data[MD5_DIGEST_LENGTH]));
1496 if (pkey->type == EVP_PKEY_RSA)
1498 s->method->ssl3_enc->cert_verify_mac(s,
1499 &(s->s3->finish_dgst1),&(data[0]));
1500 i=RSA_private_encrypt(
1501 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
1502 data,&(p[2]),pkey->pkey.rsa,
1506 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_RSA_LIB);
1515 if (pkey->type == EVP_PKEY_DSA)
1517 if (!DSA_sign(pkey->save_type,
1518 &(data[MD5_DIGEST_LENGTH]),
1519 SHA_DIGEST_LENGTH,&(p[2]),
1520 (unsigned int *)&j,pkey->pkey.dsa))
1522 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,ERR_R_DSA_LIB);
1531 SSLerr(SSL_F_SSL3_SEND_CLIENT_VERIFY,SSL_R_INTERNAL_ERROR);
1534 *(d++)=SSL3_MT_CERTIFICATE_VERIFY;
1537 s->init_num=(int)n+4;
1540 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1545 static int ssl3_send_client_certificate(s)
1549 EVP_PKEY *pkey=NULL;
1553 if (s->state == SSL3_ST_CW_CERT_A)
1555 if ((s->cert == NULL) ||
1556 (s->cert->key->x509 == NULL) ||
1557 (s->cert->key->privatekey == NULL))
1558 s->state=SSL3_ST_CW_CERT_B;
1560 s->state=SSL3_ST_CW_CERT_C;
1563 /* We need to get a client cert */
1564 if (s->state == SSL3_ST_CW_CERT_B)
1566 /* If we get an error, we need to
1567 * ssl->rwstate=SSL_X509_LOOKUP; return(-1);
1568 * We then get retied later */
1570 if (s->ctx->client_cert_cb != NULL)
1571 i=s->ctx->client_cert_cb(s,&(x509),&(pkey));
1574 s->rwstate=SSL_X509_LOOKUP;
1577 s->rwstate=SSL_NOTHING;
1578 if ((i == 1) && (pkey != NULL) && (x509 != NULL))
1580 s->state=SSL3_ST_CW_CERT_B;
1581 if ( !SSL_use_certificate(s,x509) ||
1582 !SSL_use_PrivateKey(s,pkey))
1588 SSLerr(SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
1591 if (x509 != NULL) X509_free(x509);
1592 if (pkey != NULL) EVP_PKEY_free(pkey);
1595 if (s->version == SSL3_VERSION)
1597 s->s3->tmp.cert_req=0;
1598 ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_NO_CERTIFICATE);
1603 s->s3->tmp.cert_req=2;
1607 /* Ok, we have a cert */
1608 s->state=SSL3_ST_CW_CERT_C;
1611 if (s->state == SSL3_ST_CW_CERT_C)
1613 s->state=SSL3_ST_CW_CERT_D;
1614 l=ssl3_output_cert_chain(s,
1615 (s->s3->tmp.cert_req == 2)?NULL:s->cert->key->x509);
1619 /* SSL3_ST_CW_CERT_D */
1620 return(ssl3_do_write(s,SSL3_RT_HANDSHAKE));
1623 #define has_bits(i,m) (((i)&(m)) == (m))
1625 static int ssl3_check_cert_and_algorithm(s)
1630 EVP_PKEY *pkey=NULL;
1639 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_INTERNAL_ERROR);
1643 algs=s->s3->tmp.new_cipher->algorithms;
1645 /* we don't have a certificate */
1646 if (algs & (SSL_aDH|SSL_aNULL))
1649 rsa=s->session->cert->rsa_tmp;
1650 dh=s->session->cert->dh_tmp;
1652 /* This is the passed certificate */
1655 pkey=X509_get_pubkey(c->pkeys[idx].x509);
1656 i=X509_certificate_type(c->pkeys[idx].x509,pkey);
1657 EVP_PKEY_free(pkey);
1660 /* Check that we have a certificate if we require one */
1661 if ((algs & SSL_aRSA) && !has_bits(i,EVP_PK_RSA|EVP_PKT_SIGN))
1663 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_SIGNING_CERT);
1667 else if ((algs & SSL_aDSS) && !has_bits(i,EVP_PK_DSA|EVP_PKT_SIGN))
1669 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DSA_SIGNING_CERT);
1674 if ((algs & SSL_kRSA) &&
1675 !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL)))
1677 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT);
1681 else if ((algs & SSL_kEDH) &&
1682 !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL)))
1684 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY);
1687 else if ((algs & SSL_kDHr) && !has_bits(i,EVP_PK_DH|EVP_PKS_RSA))
1689 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_RSA_CERT);
1693 else if ((algs & SSL_kDHd) && !has_bits(i,EVP_PK_DH|EVP_PKS_DSA))
1695 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_DSA_CERT);
1701 if (SSL_IS_EXPORT(algs) && !has_bits(i,EVP_PKT_EXP))
1704 if (algs & SSL_kRSA)
1707 || RSA_size(rsa) > SSL_EXPORT_PKEYLENGTH(algs))
1709 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY);
1716 if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd))
1719 || DH_size(dh) > SSL_EXPORT_PKEYLENGTH(algs))
1721 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY);
1728 SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
1734 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_HANDSHAKE_FAILURE);