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-2002 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).
111 /* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
114 * Portions of the attached software ("Contribution") are developed by
115 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
117 * The Contribution is licensed pursuant to the OpenSSL open source
118 * license provided above.
120 * In addition, Sun covenants to all licensees who provide a reciprocal
121 * covenant with respect to their own patents if any, not to sue under
122 * current and future patent claims necessarily infringed by the making,
123 * using, practicing, selling, offering for sale and/or otherwise
124 * disposing of the Contribution as delivered hereunder
125 * (or portions thereof), provided that such covenant shall not apply:
126 * 1) for code that a licensee deletes from the Contribution;
127 * 2) separates from the Contribution; or
128 * 3) for infringements caused by:
129 * i) the modification of the Contribution or
130 * ii) the combination of the Contribution with other software or
131 * devices where such combination causes the infringement.
133 * ECC cipher suite support in OpenSSL originally written by
134 * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
139 #include <openssl/objects.h>
140 #include "ssl_locl.h"
141 #include "kssl_lcl.h"
142 #include <openssl/md5.h>
144 const char *ssl3_version_str="SSLv3" OPENSSL_VERSION_PTEXT;
146 #define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
148 static long ssl3_default_timeout(void );
150 OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={
151 /* The RSA ciphers */
155 SSL3_TXT_RSA_NULL_MD5,
156 SSL3_CK_RSA_NULL_MD5,
157 SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_MD5|SSL_SSLV3,
158 SSL_NOT_EXP|SSL_STRONG_NONE,
168 SSL3_TXT_RSA_NULL_SHA,
169 SSL3_CK_RSA_NULL_SHA,
170 SSL_kRSA|SSL_aRSA|SSL_eNULL |SSL_SHA1|SSL_SSLV3,
171 SSL_NOT_EXP|SSL_STRONG_NONE,
183 SSL3_TXT_ADH_RC4_40_MD5,
184 SSL3_CK_ADH_RC4_40_MD5,
185 SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
186 SSL_EXPORT|SSL_EXP40,
196 SSL3_TXT_ADH_RC4_128_MD5,
197 SSL3_CK_ADH_RC4_128_MD5,
198 SSL_kEDH |SSL_aNULL|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
199 SSL_NOT_EXP|SSL_MEDIUM,
209 SSL3_TXT_ADH_DES_40_CBC_SHA,
210 SSL3_CK_ADH_DES_40_CBC_SHA,
211 SSL_kEDH |SSL_aNULL|SSL_DES|SSL_SHA1|SSL_SSLV3,
212 SSL_EXPORT|SSL_EXP40,
222 SSL3_TXT_ADH_DES_64_CBC_SHA,
223 SSL3_CK_ADH_DES_64_CBC_SHA,
224 SSL_kEDH |SSL_aNULL|SSL_DES |SSL_SHA1|SSL_SSLV3,
235 SSL3_TXT_ADH_DES_192_CBC_SHA,
236 SSL3_CK_ADH_DES_192_CBC_SHA,
237 SSL_kEDH |SSL_aNULL|SSL_3DES |SSL_SHA1|SSL_SSLV3,
238 SSL_NOT_EXP|SSL_HIGH,
250 SSL3_TXT_RSA_RC4_40_MD5,
251 SSL3_CK_RSA_RC4_40_MD5,
252 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5 |SSL_SSLV3,
253 SSL_EXPORT|SSL_EXP40,
263 SSL3_TXT_RSA_RC4_128_MD5,
264 SSL3_CK_RSA_RC4_128_MD5,
265 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_MD5|SSL_SSLV3,
266 SSL_NOT_EXP|SSL_MEDIUM,
276 SSL3_TXT_RSA_RC4_128_SHA,
277 SSL3_CK_RSA_RC4_128_SHA,
278 SSL_kRSA|SSL_aRSA|SSL_RC4 |SSL_SHA1|SSL_SSLV3,
279 SSL_NOT_EXP|SSL_MEDIUM,
289 SSL3_TXT_RSA_RC2_40_MD5,
290 SSL3_CK_RSA_RC2_40_MD5,
291 SSL_kRSA|SSL_aRSA|SSL_RC2 |SSL_MD5 |SSL_SSLV3,
292 SSL_EXPORT|SSL_EXP40,
302 SSL3_TXT_RSA_IDEA_128_SHA,
303 SSL3_CK_RSA_IDEA_128_SHA,
304 SSL_kRSA|SSL_aRSA|SSL_IDEA |SSL_SHA1|SSL_SSLV3,
305 SSL_NOT_EXP|SSL_MEDIUM,
315 SSL3_TXT_RSA_DES_40_CBC_SHA,
316 SSL3_CK_RSA_DES_40_CBC_SHA,
317 SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3,
318 SSL_EXPORT|SSL_EXP40,
328 SSL3_TXT_RSA_DES_64_CBC_SHA,
329 SSL3_CK_RSA_DES_64_CBC_SHA,
330 SSL_kRSA|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3,
341 SSL3_TXT_RSA_DES_192_CBC3_SHA,
342 SSL3_CK_RSA_DES_192_CBC3_SHA,
343 SSL_kRSA|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3,
344 SSL_NOT_EXP|SSL_HIGH,
356 SSL3_TXT_DH_DSS_DES_40_CBC_SHA,
357 SSL3_CK_DH_DSS_DES_40_CBC_SHA,
358 SSL_kDHd |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3,
359 SSL_EXPORT|SSL_EXP40,
369 SSL3_TXT_DH_DSS_DES_64_CBC_SHA,
370 SSL3_CK_DH_DSS_DES_64_CBC_SHA,
371 SSL_kDHd |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3,
382 SSL3_TXT_DH_DSS_DES_192_CBC3_SHA,
383 SSL3_CK_DH_DSS_DES_192_CBC3_SHA,
384 SSL_kDHd |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3,
385 SSL_NOT_EXP|SSL_HIGH,
395 SSL3_TXT_DH_RSA_DES_40_CBC_SHA,
396 SSL3_CK_DH_RSA_DES_40_CBC_SHA,
397 SSL_kDHr |SSL_aDH|SSL_DES|SSL_SHA1|SSL_SSLV3,
398 SSL_EXPORT|SSL_EXP40,
408 SSL3_TXT_DH_RSA_DES_64_CBC_SHA,
409 SSL3_CK_DH_RSA_DES_64_CBC_SHA,
410 SSL_kDHr |SSL_aDH|SSL_DES |SSL_SHA1|SSL_SSLV3,
421 SSL3_TXT_DH_RSA_DES_192_CBC3_SHA,
422 SSL3_CK_DH_RSA_DES_192_CBC3_SHA,
423 SSL_kDHr |SSL_aDH|SSL_3DES |SSL_SHA1|SSL_SSLV3,
424 SSL_NOT_EXP|SSL_HIGH,
432 /* The Ephemeral DH ciphers */
436 SSL3_TXT_EDH_DSS_DES_40_CBC_SHA,
437 SSL3_CK_EDH_DSS_DES_40_CBC_SHA,
438 SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA1|SSL_SSLV3,
439 SSL_EXPORT|SSL_EXP40,
449 SSL3_TXT_EDH_DSS_DES_64_CBC_SHA,
450 SSL3_CK_EDH_DSS_DES_64_CBC_SHA,
451 SSL_kEDH|SSL_aDSS|SSL_DES |SSL_SHA1|SSL_SSLV3,
462 SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA,
463 SSL3_CK_EDH_DSS_DES_192_CBC3_SHA,
464 SSL_kEDH|SSL_aDSS|SSL_3DES |SSL_SHA1|SSL_SSLV3,
465 SSL_NOT_EXP|SSL_HIGH,
475 SSL3_TXT_EDH_RSA_DES_40_CBC_SHA,
476 SSL3_CK_EDH_RSA_DES_40_CBC_SHA,
477 SSL_kEDH|SSL_aRSA|SSL_DES|SSL_SHA1|SSL_SSLV3,
478 SSL_EXPORT|SSL_EXP40,
488 SSL3_TXT_EDH_RSA_DES_64_CBC_SHA,
489 SSL3_CK_EDH_RSA_DES_64_CBC_SHA,
490 SSL_kEDH|SSL_aRSA|SSL_DES |SSL_SHA1|SSL_SSLV3,
501 SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA,
502 SSL3_CK_EDH_RSA_DES_192_CBC3_SHA,
503 SSL_kEDH|SSL_aRSA|SSL_3DES |SSL_SHA1|SSL_SSLV3,
504 SSL_NOT_EXP|SSL_HIGH,
516 SSL3_TXT_FZA_DMS_NULL_SHA,
517 SSL3_CK_FZA_DMS_NULL_SHA,
518 SSL_kFZA|SSL_aFZA |SSL_eNULL |SSL_SHA1|SSL_SSLV3,
519 SSL_NOT_EXP|SSL_STRONG_NONE,
530 SSL3_TXT_FZA_DMS_FZA_SHA,
531 SSL3_CK_FZA_DMS_FZA_SHA,
532 SSL_kFZA|SSL_aFZA |SSL_eFZA |SSL_SHA1|SSL_SSLV3,
533 SSL_NOT_EXP|SSL_STRONG_NONE,
544 SSL3_TXT_FZA_DMS_RC4_SHA,
545 SSL3_CK_FZA_DMS_RC4_SHA,
546 SSL_kFZA|SSL_aFZA |SSL_RC4 |SSL_SHA1|SSL_SSLV3,
547 SSL_NOT_EXP|SSL_MEDIUM,
555 #ifndef OPENSSL_NO_KRB5
556 /* The Kerberos ciphers
557 ** 20000107 VRS: And the first shall be last,
558 ** in hopes of avoiding the lynx ssl renegotiation problem.
563 SSL3_TXT_KRB5_DES_40_CBC_SHA,
564 SSL3_CK_KRB5_DES_40_CBC_SHA,
565 SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3,
566 SSL_EXPORT|SSL_EXP40,
577 SSL3_TXT_KRB5_DES_40_CBC_MD5,
578 SSL3_CK_KRB5_DES_40_CBC_MD5,
579 SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_MD5 |SSL_SSLV3,
580 SSL_EXPORT|SSL_EXP40,
591 SSL3_TXT_KRB5_DES_64_CBC_SHA,
592 SSL3_CK_KRB5_DES_64_CBC_SHA,
593 SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3,
605 SSL3_TXT_KRB5_DES_64_CBC_MD5,
606 SSL3_CK_KRB5_DES_64_CBC_MD5,
607 SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_MD5 |SSL_SSLV3,
619 SSL3_TXT_KRB5_DES_192_CBC3_SHA,
620 SSL3_CK_KRB5_DES_192_CBC3_SHA,
621 SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_SHA1 |SSL_SSLV3,
622 SSL_NOT_EXP|SSL_HIGH,
633 SSL3_TXT_KRB5_DES_192_CBC3_MD5,
634 SSL3_CK_KRB5_DES_192_CBC3_MD5,
635 SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_MD5 |SSL_SSLV3,
636 SSL_NOT_EXP|SSL_HIGH,
643 #endif /* OPENSSL_NO_KRB5 */
646 #if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES
647 /* New TLS Export CipherSuites */
651 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5,
652 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5,
653 SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_MD5|SSL_TLSV1,
654 SSL_EXPORT|SSL_EXP56,
664 TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
665 TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5,
666 SSL_kRSA|SSL_aRSA|SSL_RC2|SSL_MD5|SSL_TLSV1,
667 SSL_EXPORT|SSL_EXP56,
677 TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA,
678 TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA,
679 SSL_kRSA|SSL_aRSA|SSL_DES|SSL_SHA|SSL_TLSV1,
680 SSL_EXPORT|SSL_EXP56,
690 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
691 TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA,
692 SSL_kEDH|SSL_aDSS|SSL_DES|SSL_SHA|SSL_TLSV1,
693 SSL_EXPORT|SSL_EXP56,
703 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA,
704 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA,
705 SSL_kRSA|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
706 SSL_EXPORT|SSL_EXP56,
716 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
717 TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA,
718 SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
719 SSL_EXPORT|SSL_EXP56,
729 TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA,
730 TLS1_CK_DHE_DSS_WITH_RC4_128_SHA,
731 SSL_kEDH|SSL_aDSS|SSL_RC4|SSL_SHA|SSL_TLSV1,
732 SSL_NOT_EXP|SSL_MEDIUM,
740 /* New AES ciphersuites */
745 TLS1_TXT_RSA_WITH_AES_128_SHA,
746 TLS1_CK_RSA_WITH_AES_128_SHA,
747 SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1,
748 SSL_NOT_EXP|SSL_MEDIUM,
758 TLS1_TXT_DH_DSS_WITH_AES_128_SHA,
759 TLS1_CK_DH_DSS_WITH_AES_128_SHA,
760 SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
761 SSL_NOT_EXP|SSL_MEDIUM,
771 TLS1_TXT_DH_RSA_WITH_AES_128_SHA,
772 TLS1_CK_DH_RSA_WITH_AES_128_SHA,
773 SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
774 SSL_NOT_EXP|SSL_MEDIUM,
784 TLS1_TXT_DHE_DSS_WITH_AES_128_SHA,
785 TLS1_CK_DHE_DSS_WITH_AES_128_SHA,
786 SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1,
787 SSL_NOT_EXP|SSL_MEDIUM,
797 TLS1_TXT_DHE_RSA_WITH_AES_128_SHA,
798 TLS1_CK_DHE_RSA_WITH_AES_128_SHA,
799 SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
800 SSL_NOT_EXP|SSL_MEDIUM,
810 TLS1_TXT_ADH_WITH_AES_128_SHA,
811 TLS1_CK_ADH_WITH_AES_128_SHA,
812 SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1,
813 SSL_NOT_EXP|SSL_MEDIUM,
824 TLS1_TXT_RSA_WITH_AES_256_SHA,
825 TLS1_CK_RSA_WITH_AES_256_SHA,
826 SSL_kRSA|SSL_aRSA|SSL_AES|SSL_SHA |SSL_TLSV1,
827 SSL_NOT_EXP|SSL_HIGH,
837 TLS1_TXT_DH_DSS_WITH_AES_256_SHA,
838 TLS1_CK_DH_DSS_WITH_AES_256_SHA,
839 SSL_kDHd|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
840 SSL_NOT_EXP|SSL_HIGH,
850 TLS1_TXT_DH_RSA_WITH_AES_256_SHA,
851 TLS1_CK_DH_RSA_WITH_AES_256_SHA,
852 SSL_kDHr|SSL_aDH|SSL_AES|SSL_SHA|SSL_TLSV1,
853 SSL_NOT_EXP|SSL_HIGH,
863 TLS1_TXT_DHE_DSS_WITH_AES_256_SHA,
864 TLS1_CK_DHE_DSS_WITH_AES_256_SHA,
865 SSL_kEDH|SSL_aDSS|SSL_AES|SSL_SHA|SSL_TLSV1,
866 SSL_NOT_EXP|SSL_HIGH,
876 TLS1_TXT_DHE_RSA_WITH_AES_256_SHA,
877 TLS1_CK_DHE_RSA_WITH_AES_256_SHA,
878 SSL_kEDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
879 SSL_NOT_EXP|SSL_HIGH,
889 TLS1_TXT_ADH_WITH_AES_256_SHA,
890 TLS1_CK_ADH_WITH_AES_256_SHA,
891 SSL_kEDH|SSL_aNULL|SSL_AES|SSL_SHA|SSL_TLSV1,
892 SSL_NOT_EXP|SSL_HIGH,
900 #ifndef OPENSSL_NO_ECDH
904 TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA,
905 TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA,
906 SSL_kECDH|SSL_aECDSA|SSL_eNULL|SSL_SHA|SSL_TLSV1,
918 TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA,
919 TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA,
920 SSL_kECDH|SSL_aECDSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
932 TLS1_TXT_ECDH_ECDSA_WITH_DES_CBC_SHA,
933 TLS1_CK_ECDH_ECDSA_WITH_DES_CBC_SHA,
934 SSL_kECDH|SSL_aECDSA|SSL_DES|SSL_SHA|SSL_TLSV1,
946 TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA,
947 TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA,
948 SSL_kECDH|SSL_aECDSA|SSL_3DES|SSL_SHA|SSL_TLSV1,
949 SSL_NOT_EXP|SSL_HIGH,
960 TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
961 TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA,
962 SSL_kECDH|SSL_aECDSA|SSL_AES|SSL_SHA|SSL_TLSV1,
963 SSL_NOT_EXP|SSL_MEDIUM,
974 TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
975 TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA,
976 SSL_kECDH|SSL_aECDSA|SSL_AES|SSL_SHA|SSL_TLSV1,
977 SSL_NOT_EXP|SSL_HIGH,
986 /* XXX NOTE: The ECC/TLS draft has a bug and reuses 4B for this */
989 TLS1_TXT_ECDH_ECDSA_EXPORT_WITH_RC4_40_SHA,
990 TLS1_CK_ECDH_ECDSA_EXPORT_WITH_RC4_40_SHA,
991 SSL_kECDH|SSL_aECDSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
992 SSL_EXPORT|SSL_EXP40,
1001 /* XXX NOTE: The ECC/TLS draft has a bug and reuses 4C for this */
1004 TLS1_TXT_ECDH_ECDSA_EXPORT_WITH_RC4_56_SHA,
1005 TLS1_CK_ECDH_ECDSA_EXPORT_WITH_RC4_56_SHA,
1006 SSL_kECDH|SSL_aECDSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
1007 SSL_EXPORT|SSL_EXP56,
1018 TLS1_TXT_ECDH_RSA_WITH_NULL_SHA,
1019 TLS1_CK_ECDH_RSA_WITH_NULL_SHA,
1020 SSL_kECDH|SSL_aRSA|SSL_eNULL|SSL_SHA|SSL_TLSV1,
1032 TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA,
1033 TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA,
1034 SSL_kECDH|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
1046 TLS1_TXT_ECDH_RSA_WITH_DES_CBC_SHA,
1047 TLS1_CK_ECDH_RSA_WITH_DES_CBC_SHA,
1048 SSL_kECDH|SSL_aRSA|SSL_DES|SSL_SHA|SSL_TLSV1,
1049 SSL_NOT_EXP|SSL_LOW,
1060 TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA,
1061 TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA,
1062 SSL_kECDH|SSL_aRSA|SSL_3DES|SSL_SHA|SSL_TLSV1,
1063 SSL_NOT_EXP|SSL_HIGH,
1074 TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA,
1075 TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA,
1076 SSL_kECDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
1077 SSL_NOT_EXP|SSL_MEDIUM,
1088 TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA,
1089 TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA,
1090 SSL_kECDH|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
1091 SSL_NOT_EXP|SSL_HIGH,
1102 TLS1_TXT_ECDH_RSA_EXPORT_WITH_RC4_40_SHA,
1103 TLS1_CK_ECDH_RSA_EXPORT_WITH_RC4_40_SHA,
1104 SSL_kECDH|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
1105 SSL_EXPORT|SSL_EXP40,
1116 TLS1_TXT_ECDH_RSA_EXPORT_WITH_RC4_56_SHA,
1117 TLS1_CK_ECDH_RSA_EXPORT_WITH_RC4_56_SHA,
1118 SSL_kECDH|SSL_aRSA|SSL_RC4|SSL_SHA|SSL_TLSV1,
1119 SSL_EXPORT|SSL_EXP56,
1130 TLS1_TXT_ECDH_anon_WITH_NULL_SHA,
1131 TLS1_CK_ECDH_anon_WITH_NULL_SHA,
1132 SSL_kECDHE|SSL_aNULL|SSL_eNULL|SSL_SHA|SSL_TLSV1,
1144 TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA,
1145 TLS1_CK_ECDH_anon_WITH_RC4_128_SHA,
1146 SSL_kECDHE|SSL_aNULL|SSL_RC4|SSL_SHA|SSL_TLSV1,
1158 TLS1_TXT_ECDH_anon_WITH_DES_CBC_SHA,
1159 TLS1_CK_ECDH_anon_WITH_DES_CBC_SHA,
1160 SSL_kECDHE|SSL_aNULL|SSL_DES|SSL_SHA|SSL_TLSV1,
1161 SSL_NOT_EXP|SSL_LOW,
1172 TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA,
1173 TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA,
1174 SSL_kECDHE|SSL_aNULL|SSL_3DES|SSL_SHA|SSL_TLSV1,
1175 SSL_NOT_EXP|SSL_HIGH,
1186 TLS1_TXT_ECDH_anon_EXPORT_WITH_DES_40_CBC_SHA,
1187 TLS1_CK_ECDH_anon_EXPORT_WITH_DES_40_CBC_SHA,
1188 SSL_kECDHE|SSL_aNULL|SSL_DES|SSL_SHA|SSL_TLSV1,
1189 SSL_EXPORT|SSL_EXP40,
1200 TLS1_TXT_ECDH_anon_EXPORT_WITH_RC4_40_SHA,
1201 TLS1_CK_ECDH_anon_EXPORT_WITH_RC4_40_SHA,
1202 SSL_kECDHE|SSL_aNULL|SSL_RC4|SSL_SHA|SSL_TLSV1,
1203 SSL_EXPORT|SSL_EXP40,
1211 /* Cipher 77 XXX: ECC ciphersuites offering forward secrecy
1212 * are not yet specified in the ECC/TLS draft but our code
1213 * allows them to be implemented very easily. To add such
1214 * a cipher suite, one needs to add two constant definitions
1215 * to tls1.h and a new structure in this file as shown below. We
1216 * illustrate the process for the made-up cipher
1217 * ECDHE-ECDSA-AES128-SHA.
1221 TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
1222 TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
1223 SSL_kECDHE|SSL_aECDSA|SSL_AES|SSL_SHA|SSL_TLSV1,
1224 SSL_NOT_EXP|SSL_MEDIUM,
1232 /* Cipher 78 XXX: Another made-up ECC cipher suite that
1233 * offers forward secrecy (ECDHE-RSA-AES128-SHA).
1237 TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA,
1238 TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA,
1239 SSL_kECDHE|SSL_aRSA|SSL_AES|SSL_SHA|SSL_TLSV1,
1240 SSL_NOT_EXP|SSL_MEDIUM,
1248 #endif /* !OPENSSL_NO_ECDH */
1253 static SSL3_ENC_METHOD SSLv3_enc_data={
1256 ssl3_setup_key_block,
1257 ssl3_generate_master_secret,
1258 ssl3_change_cipher_state,
1259 ssl3_final_finish_mac,
1260 MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH,
1261 ssl3_cert_verify_mac,
1262 SSL3_MD_CLIENT_FINISHED_CONST,4,
1263 SSL3_MD_SERVER_FINISHED_CONST,4,
1267 static SSL_METHOD SSLv3_data= {
1272 ssl_undefined_function,
1273 ssl_undefined_function,
1279 ssl3_renegotiate_check,
1282 ssl3_get_cipher_by_char,
1283 ssl3_put_cipher_by_char,
1288 ssl3_default_timeout,
1290 ssl_undefined_function,
1292 ssl3_ctx_callback_ctrl,
1295 static long ssl3_default_timeout(void)
1297 /* 2 hours, the 24 hours mentioned in the SSLv3 spec
1298 * is way too long for http, the cache would over fill */
1302 SSL_METHOD *sslv3_base_method(void)
1304 return(&SSLv3_data);
1307 int ssl3_num_ciphers(void)
1309 return(SSL3_NUM_CIPHERS);
1312 SSL_CIPHER *ssl3_get_cipher(unsigned int u)
1314 if (u < SSL3_NUM_CIPHERS)
1315 return(&(ssl3_ciphers[SSL3_NUM_CIPHERS-1-u]));
1320 int ssl3_pending(SSL *s)
1322 if (s->rstate == SSL_ST_READ_BODY)
1325 return (s->s3->rrec.type == SSL3_RT_APPLICATION_DATA) ? s->s3->rrec.length : 0;
1328 int ssl3_new(SSL *s)
1332 if ((s3=OPENSSL_malloc(sizeof *s3)) == NULL) goto err;
1333 memset(s3,0,sizeof *s3);
1334 EVP_MD_CTX_init(&s3->finish_dgst1);
1335 EVP_MD_CTX_init(&s3->finish_dgst2);
1339 s->method->ssl_clear(s);
1345 void ssl3_free(SSL *s)
1350 ssl3_cleanup_key_block(s);
1351 if (s->s3->rbuf.buf != NULL)
1352 OPENSSL_free(s->s3->rbuf.buf);
1353 if (s->s3->wbuf.buf != NULL)
1354 OPENSSL_free(s->s3->wbuf.buf);
1355 if (s->s3->rrec.comp != NULL)
1356 OPENSSL_free(s->s3->rrec.comp);
1357 #ifndef OPENSSL_NO_DH
1358 if (s->s3->tmp.dh != NULL)
1359 DH_free(s->s3->tmp.dh);
1361 #ifndef OPENSSL_NO_ECDH
1362 if (s->s3->tmp.ecdh != NULL)
1363 EC_KEY_free(s->s3->tmp.ecdh);
1366 if (s->s3->tmp.ca_names != NULL)
1367 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
1368 EVP_MD_CTX_cleanup(&s->s3->finish_dgst1);
1369 EVP_MD_CTX_cleanup(&s->s3->finish_dgst2);
1370 memset(s->s3,0,sizeof *s->s3);
1371 OPENSSL_free(s->s3);
1375 void ssl3_clear(SSL *s)
1377 unsigned char *rp,*wp;
1380 ssl3_cleanup_key_block(s);
1381 if (s->s3->tmp.ca_names != NULL)
1382 sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free);
1384 if (s->s3->rrec.comp != NULL)
1386 OPENSSL_free(s->s3->rrec.comp);
1387 s->s3->rrec.comp=NULL;
1389 #ifndef OPENSSL_NO_DH
1390 if (s->s3->tmp.dh != NULL)
1391 DH_free(s->s3->tmp.dh);
1393 #ifndef OPENSSL_NO_ECDH
1394 if (s->s3->tmp.ecdh != NULL)
1395 EC_KEY_free(s->s3->tmp.ecdh);
1398 rp = s->s3->rbuf.buf;
1399 wp = s->s3->wbuf.buf;
1400 rlen = s->s3->rbuf.len;
1401 wlen = s->s3->wbuf.len;
1403 EVP_MD_CTX_cleanup(&s->s3->finish_dgst1);
1404 EVP_MD_CTX_cleanup(&s->s3->finish_dgst2);
1406 memset(s->s3,0,sizeof *s->s3);
1407 s->s3->rbuf.buf = rp;
1408 s->s3->wbuf.buf = wp;
1409 s->s3->rbuf.len = rlen;
1410 s->s3->wbuf.len = wlen;
1412 ssl_free_wbio_buffer(s);
1415 s->s3->renegotiate=0;
1416 s->s3->total_renegotiations=0;
1417 s->s3->num_renegotiations=0;
1418 s->s3->in_read_app_data=0;
1419 s->version=SSL3_VERSION;
1422 long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
1426 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
1428 #ifndef OPENSSL_NO_RSA
1429 cmd == SSL_CTRL_SET_TMP_RSA ||
1430 cmd == SSL_CTRL_SET_TMP_RSA_CB ||
1432 #ifndef OPENSSL_NO_DSA
1433 cmd == SSL_CTRL_SET_TMP_DH ||
1434 cmd == SSL_CTRL_SET_TMP_DH_CB ||
1438 if (!ssl_cert_inst(&s->cert))
1440 SSLerr(SSL_F_SSL3_CTRL, ERR_R_MALLOC_FAILURE);
1448 case SSL_CTRL_GET_SESSION_REUSED:
1451 case SSL_CTRL_GET_CLIENT_CERT_REQUEST:
1453 case SSL_CTRL_GET_NUM_RENEGOTIATIONS:
1454 ret=s->s3->num_renegotiations;
1456 case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS:
1457 ret=s->s3->num_renegotiations;
1458 s->s3->num_renegotiations=0;
1460 case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS:
1461 ret=s->s3->total_renegotiations;
1463 case SSL_CTRL_GET_FLAGS:
1464 ret=(int)(s->s3->flags);
1466 #ifndef OPENSSL_NO_RSA
1467 case SSL_CTRL_NEED_TMP_RSA:
1468 if ((s->cert != NULL) && (s->cert->rsa_tmp == NULL) &&
1469 ((s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
1470 (EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8))))
1473 case SSL_CTRL_SET_TMP_RSA:
1475 RSA *rsa = (RSA *)parg;
1478 SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
1481 if ((rsa = RSAPrivateKey_dup(rsa)) == NULL)
1483 SSLerr(SSL_F_SSL3_CTRL, ERR_R_RSA_LIB);
1486 if (s->cert->rsa_tmp != NULL)
1487 RSA_free(s->cert->rsa_tmp);
1488 s->cert->rsa_tmp = rsa;
1492 case SSL_CTRL_SET_TMP_RSA_CB:
1494 SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1499 #ifndef OPENSSL_NO_DH
1500 case SSL_CTRL_SET_TMP_DH:
1502 DH *dh = (DH *)parg;
1505 SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
1508 if ((dh = DHparams_dup(dh)) == NULL)
1510 SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
1513 if (!(s->options & SSL_OP_SINGLE_DH_USE))
1515 if (!DH_generate_key(dh))
1518 SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
1522 if (s->cert->dh_tmp != NULL)
1523 DH_free(s->cert->dh_tmp);
1524 s->cert->dh_tmp = dh;
1528 case SSL_CTRL_SET_TMP_DH_CB:
1530 SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1535 #ifndef OPENSSL_NO_ECDH
1536 case SSL_CTRL_SET_TMP_ECDH:
1538 EC_KEY *ecdh = NULL;
1542 SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
1545 if (!EC_KEY_up_ref((EC_KEY *)parg))
1547 SSLerr(SSL_F_SSL3_CTRL,ERR_R_ECDH_LIB);
1550 ecdh = (EC_KEY *)parg;
1551 if (!(s->options & SSL_OP_SINGLE_ECDH_USE))
1553 if (!EC_KEY_generate_key(ecdh))
1556 SSLerr(SSL_F_SSL3_CTRL,ERR_R_ECDH_LIB);
1560 if (s->cert->ecdh_tmp != NULL)
1561 EC_KEY_free(s->cert->ecdh_tmp);
1562 s->cert->ecdh_tmp = ecdh;
1566 case SSL_CTRL_SET_TMP_ECDH_CB:
1568 SSLerr(SSL_F_SSL3_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1572 #endif /* !OPENSSL_NO_ECDH */
1579 long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)())
1583 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
1585 #ifndef OPENSSL_NO_RSA
1586 cmd == SSL_CTRL_SET_TMP_RSA_CB ||
1588 #ifndef OPENSSL_NO_DSA
1589 cmd == SSL_CTRL_SET_TMP_DH_CB ||
1593 if (!ssl_cert_inst(&s->cert))
1595 SSLerr(SSL_F_SSL3_CALLBACK_CTRL, ERR_R_MALLOC_FAILURE);
1603 #ifndef OPENSSL_NO_RSA
1604 case SSL_CTRL_SET_TMP_RSA_CB:
1606 s->cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp;
1610 #ifndef OPENSSL_NO_DH
1611 case SSL_CTRL_SET_TMP_DH_CB:
1613 s->cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp;
1617 #ifndef OPENSSL_NO_ECDH
1618 case SSL_CTRL_SET_TMP_ECDH_CB:
1620 s->cert->ecdh_tmp_cb = (EC_KEY *(*)(SSL *, int, int))fp;
1630 long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
1638 #ifndef OPENSSL_NO_RSA
1639 case SSL_CTRL_NEED_TMP_RSA:
1640 if ( (cert->rsa_tmp == NULL) &&
1641 ((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
1642 (EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8)))
1648 case SSL_CTRL_SET_TMP_RSA:
1659 if ((rsa=RSAPrivateKey_dup(rsa)) == NULL)
1664 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_RSA_LIB);
1669 if (cert->rsa_tmp != NULL)
1670 RSA_free(cert->rsa_tmp);
1676 case SSL_CTRL_SET_TMP_RSA_CB:
1678 SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1683 #ifndef OPENSSL_NO_DH
1684 case SSL_CTRL_SET_TMP_DH:
1689 if ((new=DHparams_dup(dh)) == NULL)
1691 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
1694 if (!(ctx->options & SSL_OP_SINGLE_DH_USE))
1696 if (!DH_generate_key(new))
1698 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);
1703 if (cert->dh_tmp != NULL)
1704 DH_free(cert->dh_tmp);
1709 case SSL_CTRL_SET_TMP_DH_CB:
1711 SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1716 #ifndef OPENSSL_NO_ECDH
1717 case SSL_CTRL_SET_TMP_ECDH:
1719 EC_KEY *ecdh = NULL;
1723 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_ECDH_LIB);
1726 if (!EC_KEY_up_ref((EC_KEY *)parg))
1728 SSLerr(SSL_F_SSL3_CTRL,ERR_R_ECDH_LIB);
1731 ecdh = (EC_KEY *)parg;
1732 if (!(ctx->options & SSL_OP_SINGLE_ECDH_USE))
1734 if (!EC_KEY_generate_key(ecdh))
1737 SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_ECDH_LIB);
1742 if (cert->ecdh_tmp != NULL)
1744 EC_KEY_free(cert->ecdh_tmp);
1746 cert->ecdh_tmp = ecdh;
1750 case SSL_CTRL_SET_TMP_ECDH_CB:
1752 SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1756 #endif /* !OPENSSL_NO_ECDH */
1757 /* A Thawte special :-) */
1758 case SSL_CTRL_EXTRA_CHAIN_CERT:
1759 if (ctx->extra_certs == NULL)
1761 if ((ctx->extra_certs=sk_X509_new_null()) == NULL)
1764 sk_X509_push(ctx->extra_certs,(X509 *)parg);
1773 long ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)())
1781 #ifndef OPENSSL_NO_RSA
1782 case SSL_CTRL_SET_TMP_RSA_CB:
1784 cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))fp;
1788 #ifndef OPENSSL_NO_DH
1789 case SSL_CTRL_SET_TMP_DH_CB:
1791 cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))fp;
1795 #ifndef OPENSSL_NO_ECDH
1796 case SSL_CTRL_SET_TMP_ECDH_CB:
1798 cert->ecdh_tmp_cb = (EC_KEY *(*)(SSL *, int, int))fp;
1808 /* This function needs to check if the ciphers required are actually
1810 SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p)
1813 static SSL_CIPHER *sorted[SSL3_NUM_CIPHERS];
1814 SSL_CIPHER c,*cp= &c,**cpp;
1820 CRYPTO_w_lock(CRYPTO_LOCK_SSL);
1822 for (i=0; i<SSL3_NUM_CIPHERS; i++)
1823 sorted[i]= &(ssl3_ciphers[i]);
1825 qsort( (char *)sorted,
1826 SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
1827 FP_ICC ssl_cipher_ptr_id_cmp);
1829 CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
1834 id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1];
1836 cpp=(SSL_CIPHER **)OBJ_bsearch((char *)&cp,
1838 SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *),
1839 FP_ICC ssl_cipher_ptr_id_cmp);
1840 if ((cpp == NULL) || !(*cpp)->valid)
1846 int ssl3_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p)
1853 if ((l & 0xff000000) != 0x03000000) return(0);
1854 p[0]=((unsigned char)(l>> 8L))&0xFF;
1855 p[1]=((unsigned char)(l ))&0xFF;
1860 SSL_CIPHER *ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
1861 STACK_OF(SSL_CIPHER) *srvr)
1863 SSL_CIPHER *c,*ret=NULL;
1864 STACK_OF(SSL_CIPHER) *prio, *allow;
1867 unsigned long alg,mask,emask;
1869 /* Let's see which ciphers we can support */
1873 /* Do not set the compare functions, because this may lead to a
1874 * reordering by "id". We want to keep the original ordering.
1875 * We may pay a price in performance during sk_SSL_CIPHER_find(),
1876 * but would have to pay with the price of sk_SSL_CIPHER_dup().
1878 sk_SSL_CIPHER_set_cmp_func(srvr, ssl_cipher_ptr_id_cmp);
1879 sk_SSL_CIPHER_set_cmp_func(clnt, ssl_cipher_ptr_id_cmp);
1883 printf("Server has %d from %p:\n", sk_SSL_CIPHER_num(srvr), srvr);
1884 for(i=0 ; i < sk_SSL_CIPHER_num(srvr) ; ++i)
1886 c=sk_SSL_CIPHER_value(srvr,i);
1887 printf("%p:%s\n",c,c->name);
1889 printf("Client sent %d from %p:\n", sk_SSL_CIPHER_num(clnt), clnt);
1890 for(i=0 ; i < sk_SSL_CIPHER_num(clnt) ; ++i)
1892 c=sk_SSL_CIPHER_value(clnt,i);
1893 printf("%p:%s\n",c,c->name);
1897 if (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE)
1908 for (i=0; i<sk_SSL_CIPHER_num(prio); i++)
1910 c=sk_SSL_CIPHER_value(prio,i);
1912 ssl_set_cert_masks(cert,c);
1914 emask=cert->export_mask;
1917 printf("ssl3_choose_cipher %d alg= %lx\n", i,c->algorithms);
1918 #endif /* KSSL_DEBUG */
1920 alg=c->algorithms&(SSL_MKEY_MASK|SSL_AUTH_MASK);
1921 #ifndef OPENSSL_NO_KRB5
1924 if ( !kssl_keytab_is_available(s->kssl_ctx) )
1927 #endif /* OPENSSL_NO_KRB5 */
1928 if (SSL_C_IS_EXPORT(c))
1930 ok=((alg & emask) == alg)?1:0;
1932 printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok,alg,emask,
1938 ok=((alg & mask) == alg)?1:0;
1940 printf("%d:[%08lX:%08lX]%p:%s\n",ok,alg,mask,c,
1946 j=sk_SSL_CIPHER_find(allow,c);
1949 ret=sk_SSL_CIPHER_value(allow,j);
1956 int ssl3_get_req_cert_type(SSL *s, unsigned char *p)
1961 alg=s->s3->tmp.new_cipher->algorithms;
1963 #ifndef OPENSSL_NO_DH
1964 if (alg & (SSL_kDHr|SSL_kEDH))
1966 # ifndef OPENSSL_NO_RSA
1967 p[ret++]=SSL3_CT_RSA_FIXED_DH;
1969 # ifndef OPENSSL_NO_DSA
1970 p[ret++]=SSL3_CT_DSS_FIXED_DH;
1973 if ((s->version == SSL3_VERSION) &&
1974 (alg & (SSL_kEDH|SSL_kDHd|SSL_kDHr)))
1976 # ifndef OPENSSL_NO_RSA
1977 p[ret++]=SSL3_CT_RSA_EPHEMERAL_DH;
1979 # ifndef OPENSSL_NO_DSA
1980 p[ret++]=SSL3_CT_DSS_EPHEMERAL_DH;
1983 #endif /* !OPENSSL_NO_DH */
1984 #ifndef OPENSSL_NO_RSA
1985 p[ret++]=SSL3_CT_RSA_SIGN;
1987 #ifndef OPENSSL_NO_DSA
1988 p[ret++]=SSL3_CT_DSS_SIGN;
1990 #ifndef OPENSSL_NO_ECDH
1991 /* We should ask for fixed ECDH certificates only
1992 * for SSL_kECDH (and not SSL_kECDHE)
1994 if ((alg & SSL_kECDH) && (s->version >= TLS1_VERSION))
1996 p[ret++]=TLS_CT_RSA_FIXED_ECDH;
1997 p[ret++]=TLS_CT_ECDSA_FIXED_ECDH;
2001 #ifndef OPENSSL_NO_ECDSA
2002 /* ECDSA certs can be used with RSA cipher suites as well
2003 * so we don't need to check for SSL_kECDH or SSL_kECDHE
2005 if (s->version >= TLS1_VERSION)
2007 p[ret++]=TLS_CT_ECDSA_SIGN;
2013 int ssl3_shutdown(SSL *s)
2016 /* Don't do anything much if we have not done the handshake or
2017 * we don't want to send messages :-) */
2018 if ((s->quiet_shutdown) || (s->state == SSL_ST_BEFORE))
2020 s->shutdown=(SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
2024 if (!(s->shutdown & SSL_SENT_SHUTDOWN))
2026 s->shutdown|=SSL_SENT_SHUTDOWN;
2028 ssl3_send_alert(s,SSL3_AL_WARNING,SSL_AD_CLOSE_NOTIFY);
2030 /* our shutdown alert has been sent now, and if it still needs
2031 * to be written, s->s3->alert_dispatch will be true */
2033 else if (s->s3->alert_dispatch)
2035 /* resend it if not sent */
2037 ssl3_dispatch_alert(s);
2040 else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN))
2042 /* If we are waiting for a close from our peer, we are closed */
2043 ssl3_read_bytes(s,0,NULL,0,0);
2046 if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) &&
2047 !s->s3->alert_dispatch)
2053 int ssl3_write(SSL *s, const void *buf, int len)
2058 if (s->shutdown & SSL_SEND_SHUTDOWN)
2060 s->rwstate=SSL_NOTHING;
2065 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
2067 /* This is an experimental flag that sends the
2068 * last handshake message in the same packet as the first
2069 * use data - used to see if it helps the TCP protocol during
2070 * session-id reuse */
2071 /* The second test is because the buffer may have been removed */
2072 if ((s->s3->flags & SSL3_FLAGS_POP_BUFFER) && (s->wbio == s->bbio))
2074 /* First time through, we write into the buffer */
2075 if (s->s3->delay_buf_pop_ret == 0)
2077 ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
2079 if (ret <= 0) return(ret);
2081 s->s3->delay_buf_pop_ret=ret;
2084 s->rwstate=SSL_WRITING;
2085 n=BIO_flush(s->wbio);
2086 if (n <= 0) return(n);
2087 s->rwstate=SSL_NOTHING;
2089 /* We have flushed the buffer, so remove it */
2090 ssl_free_wbio_buffer(s);
2091 s->s3->flags&= ~SSL3_FLAGS_POP_BUFFER;
2093 ret=s->s3->delay_buf_pop_ret;
2094 s->s3->delay_buf_pop_ret=0;
2098 ret=ssl3_write_bytes(s,SSL3_RT_APPLICATION_DATA,
2100 if (ret <= 0) return(ret);
2106 static int ssl3_read_internal(SSL *s, void *buf, int len, int peek)
2111 if (s->s3->renegotiate) ssl3_renegotiate_check(s);
2112 s->s3->in_read_app_data=1;
2113 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
2114 if ((ret == -1) && (s->s3->in_read_app_data == 2))
2116 /* ssl3_read_bytes decided to call s->handshake_func, which
2117 * called ssl3_read_bytes to read handshake data.
2118 * However, ssl3_read_bytes actually found application data
2119 * and thinks that application data makes sense here; so disable
2120 * handshake processing and try to read application data again. */
2122 ret=ssl3_read_bytes(s,SSL3_RT_APPLICATION_DATA,buf,len,peek);
2126 s->s3->in_read_app_data=0;
2131 int ssl3_read(SSL *s, void *buf, int len)
2133 return ssl3_read_internal(s, buf, len, 0);
2136 int ssl3_peek(SSL *s, void *buf, int len)
2138 return ssl3_read_internal(s, buf, len, 1);
2141 int ssl3_renegotiate(SSL *s)
2143 if (s->handshake_func == NULL)
2146 if (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)
2149 s->s3->renegotiate=1;
2153 int ssl3_renegotiate_check(SSL *s)
2157 if (s->s3->renegotiate)
2159 if ( (s->s3->rbuf.left == 0) &&
2160 (s->s3->wbuf.left == 0) &&
2164 if we are the server, and we have sent a 'RENEGOTIATE' message, we
2165 need to go to SSL_ST_ACCEPT.
2168 s->state=SSL_ST_RENEGOTIATE;
2169 s->s3->renegotiate=0;
2170 s->s3->num_renegotiations++;
2171 s->s3->total_renegotiations++;