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.]
58 /* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
87 * 6. Redistributions of any form whatsoever must retain the following
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
113 #include <openssl/md5.h>
114 #include <openssl/sha.h>
115 #include <openssl/objects.h>
116 #include "ssl_locl.h"
118 const char *ssl3_version_str
="SSLv3" OPENSSL_VERSION_PTEXT
;
120 #define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
122 static long ssl3_default_timeout(void );
124 OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers
[]={
125 /* The RSA ciphers */
129 SSL3_TXT_RSA_NULL_MD5
,
130 SSL3_CK_RSA_NULL_MD5
,
131 SSL_kRSA
|SSL_aRSA
|SSL_eNULL
|SSL_MD5
|SSL_SSLV3
,
142 SSL3_TXT_RSA_NULL_SHA
,
143 SSL3_CK_RSA_NULL_SHA
,
144 SSL_kRSA
|SSL_aRSA
|SSL_eNULL
|SSL_SHA1
|SSL_SSLV3
,
157 SSL3_TXT_ADH_RC4_40_MD5
,
158 SSL3_CK_ADH_RC4_40_MD5
,
159 SSL_kEDH
|SSL_aNULL
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
160 SSL_EXPORT
|SSL_EXP40
,
170 SSL3_TXT_ADH_RC4_128_MD5
,
171 SSL3_CK_ADH_RC4_128_MD5
,
172 SSL_kEDH
|SSL_aNULL
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
183 SSL3_TXT_ADH_DES_40_CBC_SHA
,
184 SSL3_CK_ADH_DES_40_CBC_SHA
,
185 SSL_kEDH
|SSL_aNULL
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
186 SSL_EXPORT
|SSL_EXP40
,
196 SSL3_TXT_ADH_DES_64_CBC_SHA
,
197 SSL3_CK_ADH_DES_64_CBC_SHA
,
198 SSL_kEDH
|SSL_aNULL
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
209 SSL3_TXT_ADH_DES_192_CBC_SHA
,
210 SSL3_CK_ADH_DES_192_CBC_SHA
,
211 SSL_kEDH
|SSL_aNULL
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
224 SSL3_TXT_RSA_RC4_40_MD5
,
225 SSL3_CK_RSA_RC4_40_MD5
,
226 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
227 SSL_EXPORT
|SSL_EXP40
,
237 SSL3_TXT_RSA_RC4_128_MD5
,
238 SSL3_CK_RSA_RC4_128_MD5
,
239 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
240 SSL_NOT_EXP
|SSL_MEDIUM
,
250 SSL3_TXT_RSA_RC4_128_SHA
,
251 SSL3_CK_RSA_RC4_128_SHA
,
252 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_SHA1
|SSL_SSLV3
,
253 SSL_NOT_EXP
|SSL_MEDIUM
,
263 SSL3_TXT_RSA_RC2_40_MD5
,
264 SSL3_CK_RSA_RC2_40_MD5
,
265 SSL_kRSA
|SSL_aRSA
|SSL_RC2
|SSL_MD5
|SSL_SSLV3
,
266 SSL_EXPORT
|SSL_EXP40
,
276 SSL3_TXT_RSA_IDEA_128_SHA
,
277 SSL3_CK_RSA_IDEA_128_SHA
,
278 SSL_kRSA
|SSL_aRSA
|SSL_IDEA
|SSL_SHA1
|SSL_SSLV3
,
279 SSL_NOT_EXP
|SSL_MEDIUM
,
289 SSL3_TXT_RSA_DES_40_CBC_SHA
,
290 SSL3_CK_RSA_DES_40_CBC_SHA
,
291 SSL_kRSA
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
292 SSL_EXPORT
|SSL_EXP40
,
302 SSL3_TXT_RSA_DES_64_CBC_SHA
,
303 SSL3_CK_RSA_DES_64_CBC_SHA
,
304 SSL_kRSA
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
315 SSL3_TXT_RSA_DES_192_CBC3_SHA
,
316 SSL3_CK_RSA_DES_192_CBC3_SHA
,
317 SSL_kRSA
|SSL_aRSA
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
318 SSL_NOT_EXP
|SSL_HIGH
,
330 SSL3_TXT_DH_DSS_DES_40_CBC_SHA
,
331 SSL3_CK_DH_DSS_DES_40_CBC_SHA
,
332 SSL_kDHd
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
333 SSL_EXPORT
|SSL_EXP40
,
343 SSL3_TXT_DH_DSS_DES_64_CBC_SHA
,
344 SSL3_CK_DH_DSS_DES_64_CBC_SHA
,
345 SSL_kDHd
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
356 SSL3_TXT_DH_DSS_DES_192_CBC3_SHA
,
357 SSL3_CK_DH_DSS_DES_192_CBC3_SHA
,
358 SSL_kDHd
|SSL_aDH
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
359 SSL_NOT_EXP
|SSL_HIGH
,
369 SSL3_TXT_DH_RSA_DES_40_CBC_SHA
,
370 SSL3_CK_DH_RSA_DES_40_CBC_SHA
,
371 SSL_kDHr
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
372 SSL_EXPORT
|SSL_EXP40
,
382 SSL3_TXT_DH_RSA_DES_64_CBC_SHA
,
383 SSL3_CK_DH_RSA_DES_64_CBC_SHA
,
384 SSL_kDHr
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
395 SSL3_TXT_DH_RSA_DES_192_CBC3_SHA
,
396 SSL3_CK_DH_RSA_DES_192_CBC3_SHA
,
397 SSL_kDHr
|SSL_aDH
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
398 SSL_NOT_EXP
|SSL_HIGH
,
406 /* The Ephemeral DH ciphers */
410 SSL3_TXT_EDH_DSS_DES_40_CBC_SHA
,
411 SSL3_CK_EDH_DSS_DES_40_CBC_SHA
,
412 SSL_kEDH
|SSL_aDSS
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
413 SSL_EXPORT
|SSL_EXP40
,
423 SSL3_TXT_EDH_DSS_DES_64_CBC_SHA
,
424 SSL3_CK_EDH_DSS_DES_64_CBC_SHA
,
425 SSL_kEDH
|SSL_aDSS
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
436 SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA
,
437 SSL3_CK_EDH_DSS_DES_192_CBC3_SHA
,
438 SSL_kEDH
|SSL_aDSS
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
439 SSL_NOT_EXP
|SSL_HIGH
,
449 SSL3_TXT_EDH_RSA_DES_40_CBC_SHA
,
450 SSL3_CK_EDH_RSA_DES_40_CBC_SHA
,
451 SSL_kEDH
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
452 SSL_EXPORT
|SSL_EXP40
,
462 SSL3_TXT_EDH_RSA_DES_64_CBC_SHA
,
463 SSL3_CK_EDH_RSA_DES_64_CBC_SHA
,
464 SSL_kEDH
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
475 SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA
,
476 SSL3_CK_EDH_RSA_DES_192_CBC3_SHA
,
477 SSL_kEDH
|SSL_aRSA
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
478 SSL_NOT_EXP
|SSL_HIGH
,
490 SSL3_TXT_FZA_DMS_NULL_SHA
,
491 SSL3_CK_FZA_DMS_NULL_SHA
,
492 SSL_kFZA
|SSL_aFZA
|SSL_eNULL
|SSL_SHA1
|SSL_SSLV3
,
504 SSL3_TXT_FZA_DMS_FZA_SHA
,
505 SSL3_CK_FZA_DMS_FZA_SHA
,
506 SSL_kFZA
|SSL_aFZA
|SSL_eFZA
|SSL_SHA1
|SSL_SSLV3
,
518 SSL3_TXT_FZA_DMS_RC4_SHA
,
519 SSL3_CK_FZA_DMS_RC4_SHA
,
520 SSL_kFZA
|SSL_aFZA
|SSL_RC4
|SSL_SHA1
|SSL_SSLV3
,
530 /* The Kerberos ciphers
531 ** 20000107 VRS: And the first shall be last,
532 ** in hopes of avoiding the lynx ssl renegotiation problem.
537 SSL3_TXT_KRB5_DES_40_CBC_SHA
,
538 SSL3_CK_KRB5_DES_40_CBC_SHA
,
539 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
540 SSL_EXPORT
|SSL_EXP40
,
551 SSL3_TXT_KRB5_DES_40_CBC_MD5
,
552 SSL3_CK_KRB5_DES_40_CBC_MD5
,
553 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_MD5
|SSL_SSLV3
,
554 SSL_EXPORT
|SSL_EXP40
,
565 SSL3_TXT_KRB5_DES_64_CBC_SHA
,
566 SSL3_CK_KRB5_DES_64_CBC_SHA
,
567 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
579 SSL3_TXT_KRB5_DES_64_CBC_MD5
,
580 SSL3_CK_KRB5_DES_64_CBC_MD5
,
581 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_MD5
|SSL_SSLV3
,
593 SSL3_TXT_KRB5_DES_192_CBC3_SHA
,
594 SSL3_CK_KRB5_DES_192_CBC3_SHA
,
595 SSL_kKRB5
|SSL_aKRB5
| SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
596 SSL_NOT_EXP
|SSL_HIGH
,
607 SSL3_TXT_KRB5_DES_192_CBC3_MD5
,
608 SSL3_CK_KRB5_DES_192_CBC3_MD5
,
609 SSL_kKRB5
|SSL_aKRB5
| SSL_3DES
|SSL_MD5
|SSL_SSLV3
,
610 SSL_NOT_EXP
|SSL_HIGH
,
620 #if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES
621 /* New TLS Export CipherSuites */
625 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5
,
626 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5
,
627 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_MD5
|SSL_TLSV1
,
628 SSL_EXPORT
|SSL_EXP56
,
638 TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5
,
639 TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5
,
640 SSL_kRSA
|SSL_aRSA
|SSL_RC2
|SSL_MD5
|SSL_TLSV1
,
641 SSL_EXPORT
|SSL_EXP56
,
651 TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA
,
652 TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA
,
653 SSL_kRSA
|SSL_aRSA
|SSL_DES
|SSL_SHA
|SSL_TLSV1
,
654 SSL_EXPORT
|SSL_EXP56
,
664 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA
,
665 TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA
,
666 SSL_kEDH
|SSL_aDSS
|SSL_DES
|SSL_SHA
|SSL_TLSV1
,
667 SSL_EXPORT
|SSL_EXP56
,
677 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA
,
678 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA
,
679 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
680 SSL_EXPORT
|SSL_EXP56
,
690 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA
,
691 TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA
,
692 SSL_kEDH
|SSL_aDSS
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
693 SSL_EXPORT
|SSL_EXP56
,
703 TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA
,
704 TLS1_CK_DHE_DSS_WITH_RC4_128_SHA
,
705 SSL_kEDH
|SSL_aDSS
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
714 /* New AES ciphersuites */
719 TLS1_TXT_RSA_WITH_AES_128_SHA
,
720 TLS1_CK_RSA_WITH_AES_128_SHA
,
721 SSL_kRSA
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
722 SSL_NOT_EXP
|SSL_MEDIUM
,
732 TLS1_TXT_DH_DSS_WITH_AES_128_SHA
,
733 TLS1_CK_DH_DSS_WITH_AES_128_SHA
,
734 SSL_kDHd
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
735 SSL_NOT_EXP
|SSL_MEDIUM
,
745 TLS1_TXT_DH_RSA_WITH_AES_128_SHA
,
746 TLS1_CK_DH_RSA_WITH_AES_128_SHA
,
747 SSL_kDHr
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
748 SSL_NOT_EXP
|SSL_MEDIUM
,
758 TLS1_TXT_DHE_DSS_WITH_AES_128_SHA
,
759 TLS1_CK_DHE_DSS_WITH_AES_128_SHA
,
760 SSL_kEDH
|SSL_aDSS
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
761 SSL_NOT_EXP
|SSL_MEDIUM
,
771 TLS1_TXT_DHE_RSA_WITH_AES_128_SHA
,
772 TLS1_CK_DHE_RSA_WITH_AES_128_SHA
,
773 SSL_kEDH
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
774 SSL_NOT_EXP
|SSL_MEDIUM
,
784 TLS1_TXT_ADH_WITH_AES_128_SHA
,
785 TLS1_CK_ADH_WITH_AES_128_SHA
,
786 SSL_kEDH
|SSL_aNULL
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
787 SSL_NOT_EXP
|SSL_MEDIUM
,
798 TLS1_TXT_RSA_WITH_AES_256_SHA
,
799 TLS1_CK_RSA_WITH_AES_256_SHA
,
800 SSL_kRSA
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
801 SSL_NOT_EXP
|SSL_HIGH
,
811 TLS1_TXT_DH_DSS_WITH_AES_256_SHA
,
812 TLS1_CK_DH_DSS_WITH_AES_256_SHA
,
813 SSL_kDHd
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
814 SSL_NOT_EXP
|SSL_HIGH
,
824 TLS1_TXT_DH_RSA_WITH_AES_256_SHA
,
825 TLS1_CK_DH_RSA_WITH_AES_256_SHA
,
826 SSL_kDHr
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
827 SSL_NOT_EXP
|SSL_HIGH
,
837 TLS1_TXT_DHE_DSS_WITH_AES_256_SHA
,
838 TLS1_CK_DHE_DSS_WITH_AES_256_SHA
,
839 SSL_kEDH
|SSL_aDSS
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
840 SSL_NOT_EXP
|SSL_HIGH
,
850 TLS1_TXT_DHE_RSA_WITH_AES_256_SHA
,
851 TLS1_CK_DHE_RSA_WITH_AES_256_SHA
,
852 SSL_kEDH
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
853 SSL_NOT_EXP
|SSL_HIGH
,
863 TLS1_TXT_ADH_WITH_AES_256_SHA
,
864 TLS1_CK_ADH_WITH_AES_256_SHA
,
865 SSL_kEDH
|SSL_aNULL
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
866 SSL_NOT_EXP
|SSL_HIGH
,
877 static SSL3_ENC_METHOD SSLv3_enc_data
={
880 ssl3_setup_key_block
,
881 ssl3_generate_master_secret
,
882 ssl3_change_cipher_state
,
883 ssl3_final_finish_mac
,
884 MD5_DIGEST_LENGTH
+SHA_DIGEST_LENGTH
,
885 ssl3_cert_verify_mac
,
886 SSL3_MD_CLIENT_FINISHED_CONST
,4,
887 SSL3_MD_SERVER_FINISHED_CONST
,4,
891 static SSL_METHOD SSLv3_data
= {
896 ssl_undefined_function
,
897 ssl_undefined_function
,
903 ssl3_renegotiate_check
,
906 ssl3_get_cipher_by_char
,
907 ssl3_put_cipher_by_char
,
912 ssl3_default_timeout
,
914 ssl_undefined_function
,
916 ssl3_ctx_callback_ctrl
,
919 static long ssl3_default_timeout(void)
921 /* 2 hours, the 24 hours mentioned in the SSLv3 spec
922 * is way too long for http, the cache would over fill */
926 SSL_METHOD
*sslv3_base_method(void)
931 int ssl3_num_ciphers(void)
933 return(SSL3_NUM_CIPHERS
);
936 SSL_CIPHER
*ssl3_get_cipher(unsigned int u
)
938 if (u
< SSL3_NUM_CIPHERS
)
939 return(&(ssl3_ciphers
[SSL3_NUM_CIPHERS
-1-u
]));
944 int ssl3_pending(SSL
*s
)
946 return (s
->s3
->rrec
.type
== SSL3_RT_APPLICATION_DATA
) ? s
->s3
->rrec
.length
: 0;
953 if ((s3
=OPENSSL_malloc(sizeof *s3
)) == NULL
) goto err
;
954 memset(s3
,0,sizeof *s3
);
958 s
->method
->ssl_clear(s
);
964 void ssl3_free(SSL
*s
)
969 ssl3_cleanup_key_block(s
);
970 if (s
->s3
->rbuf
.buf
!= NULL
)
971 OPENSSL_free(s
->s3
->rbuf
.buf
);
972 if (s
->s3
->wbuf
.buf
!= NULL
)
973 OPENSSL_free(s
->s3
->wbuf
.buf
);
974 if (s
->s3
->rrec
.comp
!= NULL
)
975 OPENSSL_free(s
->s3
->rrec
.comp
);
977 if (s
->s3
->tmp
.dh
!= NULL
)
978 DH_free(s
->s3
->tmp
.dh
);
980 if (s
->s3
->tmp
.ca_names
!= NULL
)
981 sk_X509_NAME_pop_free(s
->s3
->tmp
.ca_names
,X509_NAME_free
);
982 memset(s
->s3
,0,sizeof *s
->s3
);
987 void ssl3_clear(SSL
*s
)
989 unsigned char *rp
,*wp
;
991 ssl3_cleanup_key_block(s
);
992 if (s
->s3
->tmp
.ca_names
!= NULL
)
993 sk_X509_NAME_pop_free(s
->s3
->tmp
.ca_names
,X509_NAME_free
);
995 if (s
->s3
->rrec
.comp
!= NULL
)
997 OPENSSL_free(s
->s3
->rrec
.comp
);
998 s
->s3
->rrec
.comp
=NULL
;
1001 if (s
->s3
->tmp
.dh
!= NULL
)
1002 DH_free(s
->s3
->tmp
.dh
);
1008 memset(s
->s3
,0,sizeof *s
->s3
);
1009 if (rp
!= NULL
) s
->s3
->rbuf
.buf
=rp
;
1010 if (wp
!= NULL
) s
->s3
->wbuf
.buf
=wp
;
1012 ssl_free_wbio_buffer(s
);
1015 s
->s3
->renegotiate
=0;
1016 s
->s3
->total_renegotiations
=0;
1017 s
->s3
->num_renegotiations
=0;
1018 s
->s3
->in_read_app_data
=0;
1019 s
->version
=SSL3_VERSION
;
1022 long ssl3_ctrl(SSL
*s
, int cmd
, long larg
, char *parg
)
1026 #if !defined(NO_DSA) || !defined(NO_RSA)
1029 cmd
== SSL_CTRL_SET_TMP_RSA
||
1030 cmd
== SSL_CTRL_SET_TMP_RSA_CB
||
1033 cmd
== SSL_CTRL_SET_TMP_DH
||
1034 cmd
== SSL_CTRL_SET_TMP_DH_CB
||
1038 if (!ssl_cert_inst(&s
->cert
))
1040 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_MALLOC_FAILURE
);
1048 case SSL_CTRL_GET_SESSION_REUSED
:
1051 case SSL_CTRL_GET_CLIENT_CERT_REQUEST
:
1053 case SSL_CTRL_GET_NUM_RENEGOTIATIONS
:
1054 ret
=s
->s3
->num_renegotiations
;
1056 case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS
:
1057 ret
=s
->s3
->num_renegotiations
;
1058 s
->s3
->num_renegotiations
=0;
1060 case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS
:
1061 ret
=s
->s3
->total_renegotiations
;
1063 case SSL_CTRL_GET_FLAGS
:
1064 ret
=(int)(s
->s3
->flags
);
1067 case SSL_CTRL_NEED_TMP_RSA
:
1068 if ((s
->cert
!= NULL
) && (s
->cert
->rsa_tmp
== NULL
) &&
1069 ((s
->cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
== NULL
) ||
1070 (EVP_PKEY_size(s
->cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
) > (512/8))))
1073 case SSL_CTRL_SET_TMP_RSA
:
1075 RSA
*rsa
= (RSA
*)parg
;
1078 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_PASSED_NULL_PARAMETER
);
1081 if ((rsa
= RSAPrivateKey_dup(rsa
)) == NULL
)
1083 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_RSA_LIB
);
1086 if (s
->cert
->rsa_tmp
!= NULL
)
1087 RSA_free(s
->cert
->rsa_tmp
);
1088 s
->cert
->rsa_tmp
= rsa
;
1092 case SSL_CTRL_SET_TMP_RSA_CB
:
1094 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1100 case SSL_CTRL_SET_TMP_DH
:
1102 DH
*dh
= (DH
*)parg
;
1105 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_PASSED_NULL_PARAMETER
);
1108 if ((dh
= DHparams_dup(dh
)) == NULL
)
1110 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_DH_LIB
);
1113 if (!(s
->options
& SSL_OP_SINGLE_DH_USE
))
1115 if (!DH_generate_key(dh
))
1118 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_DH_LIB
);
1122 if (s
->cert
->dh_tmp
!= NULL
)
1123 DH_free(s
->cert
->dh_tmp
);
1124 s
->cert
->dh_tmp
= dh
;
1128 case SSL_CTRL_SET_TMP_DH_CB
:
1130 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1141 long ssl3_callback_ctrl(SSL
*s
, int cmd
, void (*fp
)())
1145 #if !defined(NO_DSA) || !defined(NO_RSA)
1148 cmd
== SSL_CTRL_SET_TMP_RSA_CB
||
1151 cmd
== SSL_CTRL_SET_TMP_DH_CB
||
1155 if (!ssl_cert_inst(&s
->cert
))
1157 SSLerr(SSL_F_SSL3_CALLBACK_CTRL
, ERR_R_MALLOC_FAILURE
);
1166 case SSL_CTRL_SET_TMP_RSA_CB
:
1168 s
->cert
->rsa_tmp_cb
= (RSA
*(*)(SSL
*, int, int))fp
;
1173 case SSL_CTRL_SET_TMP_DH_CB
:
1175 s
->cert
->dh_tmp_cb
= (DH
*(*)(SSL
*, int, int))fp
;
1185 long ssl3_ctx_ctrl(SSL_CTX
*ctx
, int cmd
, long larg
, char *parg
)
1194 case SSL_CTRL_NEED_TMP_RSA
:
1195 if ( (cert
->rsa_tmp
== NULL
) &&
1196 ((cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
== NULL
) ||
1197 (EVP_PKEY_size(cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
) > (512/8)))
1203 case SSL_CTRL_SET_TMP_RSA
:
1214 if ((rsa
=RSAPrivateKey_dup(rsa
)) == NULL
)
1219 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_RSA_LIB
);
1224 if (cert
->rsa_tmp
!= NULL
)
1225 RSA_free(cert
->rsa_tmp
);
1231 case SSL_CTRL_SET_TMP_RSA_CB
:
1233 SSLerr(SSL_F_SSL3_CTX_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1239 case SSL_CTRL_SET_TMP_DH
:
1244 if ((new=DHparams_dup(dh
)) == NULL
)
1246 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_DH_LIB
);
1249 if (!(ctx
->options
& SSL_OP_SINGLE_DH_USE
))
1251 if (!DH_generate_key(new))
1253 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_DH_LIB
);
1258 if (cert
->dh_tmp
!= NULL
)
1259 DH_free(cert
->dh_tmp
);
1264 case SSL_CTRL_SET_TMP_DH_CB
:
1266 SSLerr(SSL_F_SSL3_CTX_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1271 /* A Thawte special :-) */
1272 case SSL_CTRL_EXTRA_CHAIN_CERT
:
1273 if (ctx
->extra_certs
== NULL
)
1275 if ((ctx
->extra_certs
=sk_X509_new_null()) == NULL
)
1278 sk_X509_push(ctx
->extra_certs
,(X509
*)parg
);
1287 long ssl3_ctx_callback_ctrl(SSL_CTX
*ctx
, int cmd
, void (*fp
)())
1296 case SSL_CTRL_SET_TMP_RSA_CB
:
1298 cert
->rsa_tmp_cb
= (RSA
*(*)(SSL
*, int, int))fp
;
1303 case SSL_CTRL_SET_TMP_DH_CB
:
1305 cert
->dh_tmp_cb
= (DH
*(*)(SSL
*, int, int))fp
;
1315 /* This function needs to check if the ciphers required are actually
1317 SSL_CIPHER
*ssl3_get_cipher_by_char(const unsigned char *p
)
1320 static SSL_CIPHER
*sorted
[SSL3_NUM_CIPHERS
];
1321 SSL_CIPHER c
,*cp
= &c
,**cpp
;
1327 CRYPTO_w_lock(CRYPTO_LOCK_SSL
);
1329 for (i
=0; i
<SSL3_NUM_CIPHERS
; i
++)
1330 sorted
[i
]= &(ssl3_ciphers
[i
]);
1332 qsort( (char *)sorted
,
1333 SSL3_NUM_CIPHERS
,sizeof(SSL_CIPHER
*),
1334 FP_ICC ssl_cipher_ptr_id_cmp
);
1336 CRYPTO_w_unlock(CRYPTO_LOCK_SSL
);
1341 id
=0x03000000L
|((unsigned long)p
[0]<<8L)|(unsigned long)p
[1];
1343 cpp
=(SSL_CIPHER
**)OBJ_bsearch((char *)&cp
,
1345 SSL3_NUM_CIPHERS
,sizeof(SSL_CIPHER
*),
1346 FP_ICC ssl_cipher_ptr_id_cmp
);
1347 if ((cpp
== NULL
) || !(*cpp
)->valid
)
1353 int ssl3_put_cipher_by_char(const SSL_CIPHER
*c
, unsigned char *p
)
1360 if ((l
& 0xff000000) != 0x03000000) return(0);
1361 p
[0]=((unsigned char)(l
>> 8L))&0xFF;
1362 p
[1]=((unsigned char)(l
))&0xFF;
1367 SSL_CIPHER
*ssl3_choose_cipher(SSL
*s
, STACK_OF(SSL_CIPHER
) *have
,
1368 STACK_OF(SSL_CIPHER
) *pref
)
1370 SSL_CIPHER
*c
,*ret
=NULL
;
1373 unsigned long alg
,mask
,emask
;
1375 /* Let's see which ciphers we can support */
1378 sk_SSL_CIPHER_set_cmp_func(pref
,ssl_cipher_ptr_id_cmp
);
1381 printf("Have %d from %p:\n", sk_SSL_CIPHER_num(pref
), pref
);
1382 for(i
=0 ; i
< sk_SSL_CIPHER_num(pref
) ; ++i
)
1384 c
=sk_SSL_CIPHER_value(pref
,i
);
1385 printf("%p:%s\n",c
,c
->name
);
1389 for (i
=0; i
<sk_SSL_CIPHER_num(have
); i
++)
1391 c
=sk_SSL_CIPHER_value(have
,i
);
1393 ssl_set_cert_masks(cert
,c
);
1395 emask
=cert
->export_mask
;
1398 printf("ssl3_choose_cipher %d alg= %lx\n", i
,c
->algorithms
);
1399 #endif /* KSSL_DEBUG */
1401 alg
=c
->algorithms
&(SSL_MKEY_MASK
|SSL_AUTH_MASK
);
1402 if (SSL_C_IS_EXPORT(c
))
1404 ok
=((alg
& emask
) == alg
)?1:0;
1406 printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok
,alg
,emask
,
1412 ok
=((alg
& mask
) == alg
)?1:0;
1414 printf("%d:[%08lX:%08lX]%p:%s\n",ok
,alg
,mask
,c
,
1421 j
=sk_SSL_CIPHER_find(pref
,c
);
1424 ret
=sk_SSL_CIPHER_value(pref
,j
);
1431 int ssl3_get_req_cert_type(SSL
*s
, unsigned char *p
)
1436 alg
=s
->s3
->tmp
.new_cipher
->algorithms
;
1439 if (alg
& (SSL_kDHr
|SSL_kEDH
))
1442 p
[ret
++]=SSL3_CT_RSA_FIXED_DH
;
1445 p
[ret
++]=SSL3_CT_DSS_FIXED_DH
;
1448 if ((s
->version
== SSL3_VERSION
) &&
1449 (alg
& (SSL_kEDH
|SSL_kDHd
|SSL_kDHr
)))
1452 p
[ret
++]=SSL3_CT_RSA_EPHEMERAL_DH
;
1455 p
[ret
++]=SSL3_CT_DSS_EPHEMERAL_DH
;
1460 p
[ret
++]=SSL3_CT_RSA_SIGN
;
1463 p
[ret
++]=SSL3_CT_DSS_SIGN
;
1468 int ssl3_shutdown(SSL
*s
)
1471 /* Don't do anything much if we have not done the handshake or
1472 * we don't want to send messages :-) */
1473 if ((s
->quiet_shutdown
) || (s
->state
== SSL_ST_BEFORE
))
1475 s
->shutdown
=(SSL_SENT_SHUTDOWN
|SSL_RECEIVED_SHUTDOWN
);
1479 if (!(s
->shutdown
& SSL_SENT_SHUTDOWN
))
1481 s
->shutdown
|=SSL_SENT_SHUTDOWN
;
1483 ssl3_send_alert(s
,SSL3_AL_WARNING
,SSL_AD_CLOSE_NOTIFY
);
1485 /* our shutdown alert has been sent now, and if it still needs
1486 * to be written, s->s3->alert_dispatch will be true */
1488 else if (s
->s3
->alert_dispatch
)
1490 /* resend it if not sent */
1492 ssl3_dispatch_alert(s
);
1495 else if (!(s
->shutdown
& SSL_RECEIVED_SHUTDOWN
))
1497 /* If we are waiting for a close from our peer, we are closed */
1498 ssl3_read_bytes(s
,0,NULL
,0,0);
1501 if ((s
->shutdown
== (SSL_SENT_SHUTDOWN
|SSL_RECEIVED_SHUTDOWN
)) &&
1502 !s
->s3
->alert_dispatch
)
1508 int ssl3_write(SSL
*s
, const void *buf
, int len
)
1513 if (s
->shutdown
& SSL_SEND_SHUTDOWN
)
1515 s
->rwstate
=SSL_NOTHING
;
1520 if (s
->s3
->renegotiate
) ssl3_renegotiate_check(s
);
1522 /* This is an experimental flag that sends the
1523 * last handshake message in the same packet as the first
1524 * use data - used to see if it helps the TCP protocol during
1525 * session-id reuse */
1526 /* The second test is because the buffer may have been removed */
1527 if ((s
->s3
->flags
& SSL3_FLAGS_POP_BUFFER
) && (s
->wbio
== s
->bbio
))
1529 /* First time through, we write into the buffer */
1530 if (s
->s3
->delay_buf_pop_ret
== 0)
1532 ret
=ssl3_write_bytes(s
,SSL3_RT_APPLICATION_DATA
,
1534 if (ret
<= 0) return(ret
);
1536 s
->s3
->delay_buf_pop_ret
=ret
;
1539 s
->rwstate
=SSL_WRITING
;
1540 n
=BIO_flush(s
->wbio
);
1541 if (n
<= 0) return(n
);
1542 s
->rwstate
=SSL_NOTHING
;
1544 /* We have flushed the buffer, so remove it */
1545 ssl_free_wbio_buffer(s
);
1546 s
->s3
->flags
&= ~SSL3_FLAGS_POP_BUFFER
;
1548 ret
=s
->s3
->delay_buf_pop_ret
;
1549 s
->s3
->delay_buf_pop_ret
=0;
1553 ret
=ssl3_write_bytes(s
,SSL3_RT_APPLICATION_DATA
,
1555 if (ret
<= 0) return(ret
);
1561 static int ssl3_read_internal(SSL
*s
, void *buf
, int len
, int peek
)
1566 if (s
->s3
->renegotiate
) ssl3_renegotiate_check(s
);
1567 s
->s3
->in_read_app_data
=1;
1568 ret
=ssl3_read_bytes(s
,SSL3_RT_APPLICATION_DATA
,buf
,len
,peek
);
1569 if ((ret
== -1) && (s
->s3
->in_read_app_data
== 0))
1571 /* ssl3_read_bytes decided to call s->handshake_func, which
1572 * called ssl3_read_bytes to read handshake data.
1573 * However, ssl3_read_bytes actually found application data
1574 * and thinks that application data makes sense here (signalled
1575 * by resetting 'in_read_app_data', strangely); so disable
1576 * handshake processing and try to read application data again. */
1578 ret
=ssl3_read_bytes(s
,SSL3_RT_APPLICATION_DATA
,buf
,len
,peek
);
1582 s
->s3
->in_read_app_data
=0;
1587 int ssl3_read(SSL
*s
, void *buf
, int len
)
1589 return ssl3_read_internal(s
, buf
, len
, 0);
1592 int ssl3_peek(SSL
*s
, char *buf
, int len
)
1594 return ssl3_read_internal(s
, buf
, len
, 1);
1597 int ssl3_renegotiate(SSL
*s
)
1599 if (s
->handshake_func
== NULL
)
1602 if (s
->s3
->flags
& SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS
)
1605 s
->s3
->renegotiate
=1;
1609 int ssl3_renegotiate_check(SSL
*s
)
1613 if (s
->s3
->renegotiate
)
1615 if ( (s
->s3
->rbuf
.left
== 0) &&
1616 (s
->s3
->wbuf
.left
== 0) &&
1620 if we are the server, and we have sent a 'RENEGOTIATE' message, we
1621 need to go to SSL_ST_ACCEPT.
1624 s
->state
=SSL_ST_RENEGOTIATE
;
1625 s
->s3
->renegotiate
=0;
1626 s
->s3
->num_renegotiations
++;
1627 s
->s3
->total_renegotiations
++;