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-2006 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 * ECC cipher suite support in OpenSSL originally written by
121 * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
126 #include <openssl/objects.h>
127 #include "ssl_locl.h"
128 #include "kssl_lcl.h"
129 #include <openssl/md5.h>
130 #ifndef OPENSSL_NO_DH
131 #include <openssl/dh.h>
133 #include <openssl/pq_compat.h>
135 const char ssl3_version_str
[]="SSLv3" OPENSSL_VERSION_PTEXT
;
137 #define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
139 /* list of available SSLv3 ciphers (sorted by id) */
140 OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers
[]={
141 /* The RSA ciphers */
145 SSL3_TXT_RSA_NULL_MD5
,
146 SSL3_CK_RSA_NULL_MD5
,
147 SSL_kRSA
|SSL_aRSA
|SSL_eNULL
|SSL_MD5
|SSL_SSLV3
,
148 SSL_NOT_EXP
|SSL_STRONG_NONE
,
158 SSL3_TXT_RSA_NULL_SHA
,
159 SSL3_CK_RSA_NULL_SHA
,
160 SSL_kRSA
|SSL_aRSA
|SSL_eNULL
|SSL_SHA1
|SSL_SSLV3
,
161 SSL_NOT_EXP
|SSL_STRONG_NONE
,
171 SSL3_TXT_RSA_RC4_40_MD5
,
172 SSL3_CK_RSA_RC4_40_MD5
,
173 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
174 SSL_EXPORT
|SSL_EXP40
,
184 SSL3_TXT_RSA_RC4_128_MD5
,
185 SSL3_CK_RSA_RC4_128_MD5
,
186 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
187 SSL_NOT_EXP
|SSL_MEDIUM
,
197 SSL3_TXT_RSA_RC4_128_SHA
,
198 SSL3_CK_RSA_RC4_128_SHA
,
199 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_SHA1
|SSL_SSLV3
,
200 SSL_NOT_EXP
|SSL_MEDIUM
,
210 SSL3_TXT_RSA_RC2_40_MD5
,
211 SSL3_CK_RSA_RC2_40_MD5
,
212 SSL_kRSA
|SSL_aRSA
|SSL_RC2
|SSL_MD5
|SSL_SSLV3
,
213 SSL_EXPORT
|SSL_EXP40
,
221 #ifndef OPENSSL_NO_IDEA
224 SSL3_TXT_RSA_IDEA_128_SHA
,
225 SSL3_CK_RSA_IDEA_128_SHA
,
226 SSL_kRSA
|SSL_aRSA
|SSL_IDEA
|SSL_SHA1
|SSL_SSLV3
,
227 SSL_NOT_EXP
|SSL_MEDIUM
,
238 SSL3_TXT_RSA_DES_40_CBC_SHA
,
239 SSL3_CK_RSA_DES_40_CBC_SHA
,
240 SSL_kRSA
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
241 SSL_EXPORT
|SSL_EXP40
,
251 SSL3_TXT_RSA_DES_64_CBC_SHA
,
252 SSL3_CK_RSA_DES_64_CBC_SHA
,
253 SSL_kRSA
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
264 SSL3_TXT_RSA_DES_192_CBC3_SHA
,
265 SSL3_CK_RSA_DES_192_CBC3_SHA
,
266 SSL_kRSA
|SSL_aRSA
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
267 SSL_NOT_EXP
|SSL_HIGH
,
278 SSL3_TXT_DH_DSS_DES_40_CBC_SHA
,
279 SSL3_CK_DH_DSS_DES_40_CBC_SHA
,
280 SSL_kDHd
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
281 SSL_EXPORT
|SSL_EXP40
,
291 SSL3_TXT_DH_DSS_DES_64_CBC_SHA
,
292 SSL3_CK_DH_DSS_DES_64_CBC_SHA
,
293 SSL_kDHd
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
304 SSL3_TXT_DH_DSS_DES_192_CBC3_SHA
,
305 SSL3_CK_DH_DSS_DES_192_CBC3_SHA
,
306 SSL_kDHd
|SSL_aDH
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
307 SSL_NOT_EXP
|SSL_HIGH
,
317 SSL3_TXT_DH_RSA_DES_40_CBC_SHA
,
318 SSL3_CK_DH_RSA_DES_40_CBC_SHA
,
319 SSL_kDHr
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
320 SSL_EXPORT
|SSL_EXP40
,
330 SSL3_TXT_DH_RSA_DES_64_CBC_SHA
,
331 SSL3_CK_DH_RSA_DES_64_CBC_SHA
,
332 SSL_kDHr
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
343 SSL3_TXT_DH_RSA_DES_192_CBC3_SHA
,
344 SSL3_CK_DH_RSA_DES_192_CBC3_SHA
,
345 SSL_kDHr
|SSL_aDH
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
346 SSL_NOT_EXP
|SSL_HIGH
,
354 /* The Ephemeral DH ciphers */
358 SSL3_TXT_EDH_DSS_DES_40_CBC_SHA
,
359 SSL3_CK_EDH_DSS_DES_40_CBC_SHA
,
360 SSL_kEDH
|SSL_aDSS
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
361 SSL_EXPORT
|SSL_EXP40
,
371 SSL3_TXT_EDH_DSS_DES_64_CBC_SHA
,
372 SSL3_CK_EDH_DSS_DES_64_CBC_SHA
,
373 SSL_kEDH
|SSL_aDSS
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
384 SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA
,
385 SSL3_CK_EDH_DSS_DES_192_CBC3_SHA
,
386 SSL_kEDH
|SSL_aDSS
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
387 SSL_NOT_EXP
|SSL_HIGH
,
397 SSL3_TXT_EDH_RSA_DES_40_CBC_SHA
,
398 SSL3_CK_EDH_RSA_DES_40_CBC_SHA
,
399 SSL_kEDH
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
400 SSL_EXPORT
|SSL_EXP40
,
410 SSL3_TXT_EDH_RSA_DES_64_CBC_SHA
,
411 SSL3_CK_EDH_RSA_DES_64_CBC_SHA
,
412 SSL_kEDH
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
423 SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA
,
424 SSL3_CK_EDH_RSA_DES_192_CBC3_SHA
,
425 SSL_kEDH
|SSL_aRSA
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
426 SSL_NOT_EXP
|SSL_HIGH
,
436 SSL3_TXT_ADH_RC4_40_MD5
,
437 SSL3_CK_ADH_RC4_40_MD5
,
438 SSL_kEDH
|SSL_aNULL
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
439 SSL_EXPORT
|SSL_EXP40
,
449 SSL3_TXT_ADH_RC4_128_MD5
,
450 SSL3_CK_ADH_RC4_128_MD5
,
451 SSL_kEDH
|SSL_aNULL
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
452 SSL_NOT_EXP
|SSL_MEDIUM
,
462 SSL3_TXT_ADH_DES_40_CBC_SHA
,
463 SSL3_CK_ADH_DES_40_CBC_SHA
,
464 SSL_kEDH
|SSL_aNULL
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
465 SSL_EXPORT
|SSL_EXP40
,
475 SSL3_TXT_ADH_DES_64_CBC_SHA
,
476 SSL3_CK_ADH_DES_64_CBC_SHA
,
477 SSL_kEDH
|SSL_aNULL
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
488 SSL3_TXT_ADH_DES_192_CBC_SHA
,
489 SSL3_CK_ADH_DES_192_CBC_SHA
,
490 SSL_kEDH
|SSL_aNULL
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
491 SSL_NOT_EXP
|SSL_HIGH
,
503 SSL3_TXT_FZA_DMS_NULL_SHA
,
504 SSL3_CK_FZA_DMS_NULL_SHA
,
505 SSL_kFZA
|SSL_aFZA
|SSL_eNULL
|SSL_SHA1
|SSL_SSLV3
,
506 SSL_NOT_EXP
|SSL_STRONG_NONE
,
517 SSL3_TXT_FZA_DMS_FZA_SHA
,
518 SSL3_CK_FZA_DMS_FZA_SHA
,
519 SSL_kFZA
|SSL_aFZA
|SSL_eFZA
|SSL_SHA1
|SSL_SSLV3
,
520 SSL_NOT_EXP
|SSL_STRONG_NONE
,
532 SSL3_TXT_FZA_DMS_RC4_SHA
,
533 SSL3_CK_FZA_DMS_RC4_SHA
,
534 SSL_kFZA
|SSL_aFZA
|SSL_RC4
|SSL_SHA1
|SSL_SSLV3
,
535 SSL_NOT_EXP
|SSL_MEDIUM
,
544 #ifndef OPENSSL_NO_KRB5
545 /* The Kerberos ciphers
546 ** 20000107 VRS: And the first shall be last,
547 ** in hopes of avoiding the lynx ssl renegotiation problem.
552 SSL3_TXT_KRB5_DES_64_CBC_SHA
,
553 SSL3_CK_KRB5_DES_64_CBC_SHA
,
554 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
566 SSL3_TXT_KRB5_DES_192_CBC3_SHA
,
567 SSL3_CK_KRB5_DES_192_CBC3_SHA
,
568 SSL_kKRB5
|SSL_aKRB5
| SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
569 SSL_NOT_EXP
|SSL_HIGH
,
580 SSL3_TXT_KRB5_RC4_128_SHA
,
581 SSL3_CK_KRB5_RC4_128_SHA
,
582 SSL_kKRB5
|SSL_aKRB5
| SSL_RC4
|SSL_SHA1
|SSL_SSLV3
,
583 SSL_NOT_EXP
|SSL_MEDIUM
,
594 SSL3_TXT_KRB5_IDEA_128_CBC_SHA
,
595 SSL3_CK_KRB5_IDEA_128_CBC_SHA
,
596 SSL_kKRB5
|SSL_aKRB5
| SSL_IDEA
|SSL_SHA1
|SSL_SSLV3
,
597 SSL_NOT_EXP
|SSL_MEDIUM
,
608 SSL3_TXT_KRB5_DES_64_CBC_MD5
,
609 SSL3_CK_KRB5_DES_64_CBC_MD5
,
610 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_MD5
|SSL_SSLV3
,
622 SSL3_TXT_KRB5_DES_192_CBC3_MD5
,
623 SSL3_CK_KRB5_DES_192_CBC3_MD5
,
624 SSL_kKRB5
|SSL_aKRB5
| SSL_3DES
|SSL_MD5
|SSL_SSLV3
,
625 SSL_NOT_EXP
|SSL_HIGH
,
636 SSL3_TXT_KRB5_RC4_128_MD5
,
637 SSL3_CK_KRB5_RC4_128_MD5
,
638 SSL_kKRB5
|SSL_aKRB5
| SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
639 SSL_NOT_EXP
|SSL_MEDIUM
,
650 SSL3_TXT_KRB5_IDEA_128_CBC_MD5
,
651 SSL3_CK_KRB5_IDEA_128_CBC_MD5
,
652 SSL_kKRB5
|SSL_aKRB5
| SSL_IDEA
|SSL_MD5
|SSL_SSLV3
,
653 SSL_NOT_EXP
|SSL_MEDIUM
,
664 SSL3_TXT_KRB5_DES_40_CBC_SHA
,
665 SSL3_CK_KRB5_DES_40_CBC_SHA
,
666 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
667 SSL_EXPORT
|SSL_EXP40
,
678 SSL3_TXT_KRB5_RC2_40_CBC_SHA
,
679 SSL3_CK_KRB5_RC2_40_CBC_SHA
,
680 SSL_kKRB5
|SSL_aKRB5
| SSL_RC2
|SSL_SHA1
|SSL_SSLV3
,
681 SSL_EXPORT
|SSL_EXP40
,
692 SSL3_TXT_KRB5_RC4_40_SHA
,
693 SSL3_CK_KRB5_RC4_40_SHA
,
694 SSL_kKRB5
|SSL_aKRB5
| SSL_RC4
|SSL_SHA1
|SSL_SSLV3
,
695 SSL_EXPORT
|SSL_EXP40
,
706 SSL3_TXT_KRB5_DES_40_CBC_MD5
,
707 SSL3_CK_KRB5_DES_40_CBC_MD5
,
708 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_MD5
|SSL_SSLV3
,
709 SSL_EXPORT
|SSL_EXP40
,
720 SSL3_TXT_KRB5_RC2_40_CBC_MD5
,
721 SSL3_CK_KRB5_RC2_40_CBC_MD5
,
722 SSL_kKRB5
|SSL_aKRB5
| SSL_RC2
|SSL_MD5
|SSL_SSLV3
,
723 SSL_EXPORT
|SSL_EXP40
,
734 SSL3_TXT_KRB5_RC4_40_MD5
,
735 SSL3_CK_KRB5_RC4_40_MD5
,
736 SSL_kKRB5
|SSL_aKRB5
| SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
737 SSL_EXPORT
|SSL_EXP40
,
744 #endif /* OPENSSL_NO_KRB5 */
745 /* New AES ciphersuites */
750 TLS1_TXT_RSA_WITH_AES_128_SHA
,
751 TLS1_CK_RSA_WITH_AES_128_SHA
,
752 SSL_kRSA
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
753 SSL_NOT_EXP
|SSL_HIGH
,
763 TLS1_TXT_DH_DSS_WITH_AES_128_SHA
,
764 TLS1_CK_DH_DSS_WITH_AES_128_SHA
,
765 SSL_kDHd
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
766 SSL_NOT_EXP
|SSL_HIGH
,
776 TLS1_TXT_DH_RSA_WITH_AES_128_SHA
,
777 TLS1_CK_DH_RSA_WITH_AES_128_SHA
,
778 SSL_kDHr
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
779 SSL_NOT_EXP
|SSL_HIGH
,
789 TLS1_TXT_DHE_DSS_WITH_AES_128_SHA
,
790 TLS1_CK_DHE_DSS_WITH_AES_128_SHA
,
791 SSL_kEDH
|SSL_aDSS
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
792 SSL_NOT_EXP
|SSL_HIGH
,
802 TLS1_TXT_DHE_RSA_WITH_AES_128_SHA
,
803 TLS1_CK_DHE_RSA_WITH_AES_128_SHA
,
804 SSL_kEDH
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
805 SSL_NOT_EXP
|SSL_HIGH
,
815 TLS1_TXT_ADH_WITH_AES_128_SHA
,
816 TLS1_CK_ADH_WITH_AES_128_SHA
,
817 SSL_kEDH
|SSL_aNULL
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
818 SSL_NOT_EXP
|SSL_HIGH
,
829 TLS1_TXT_RSA_WITH_AES_256_SHA
,
830 TLS1_CK_RSA_WITH_AES_256_SHA
,
831 SSL_kRSA
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
832 SSL_NOT_EXP
|SSL_HIGH
,
842 TLS1_TXT_DH_DSS_WITH_AES_256_SHA
,
843 TLS1_CK_DH_DSS_WITH_AES_256_SHA
,
844 SSL_kDHd
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
845 SSL_NOT_EXP
|SSL_HIGH
,
855 TLS1_TXT_DH_RSA_WITH_AES_256_SHA
,
856 TLS1_CK_DH_RSA_WITH_AES_256_SHA
,
857 SSL_kDHr
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
858 SSL_NOT_EXP
|SSL_HIGH
,
868 TLS1_TXT_DHE_DSS_WITH_AES_256_SHA
,
869 TLS1_CK_DHE_DSS_WITH_AES_256_SHA
,
870 SSL_kEDH
|SSL_aDSS
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
871 SSL_NOT_EXP
|SSL_HIGH
,
881 TLS1_TXT_DHE_RSA_WITH_AES_256_SHA
,
882 TLS1_CK_DHE_RSA_WITH_AES_256_SHA
,
883 SSL_kEDH
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
884 SSL_NOT_EXP
|SSL_HIGH
,
894 TLS1_TXT_ADH_WITH_AES_256_SHA
,
895 TLS1_CK_ADH_WITH_AES_256_SHA
,
896 SSL_kEDH
|SSL_aNULL
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
897 SSL_NOT_EXP
|SSL_HIGH
,
905 #ifndef OPENSSL_NO_CAMELLIA
906 /* Camellia ciphersuites from RFC4132 (128-bit portion) */
911 TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA
,
912 TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA
,
913 SSL_kRSA
|SSL_aRSA
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
914 SSL_NOT_EXP
|SSL_HIGH
,
923 0, /* not implemented (non-ephemeral DH) */
924 TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA
,
925 TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA
,
926 SSL_kDHd
|SSL_aDH
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
927 SSL_NOT_EXP
|SSL_HIGH
,
936 0, /* not implemented (non-ephemeral DH) */
937 TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA
,
938 TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA
,
939 SSL_kDHr
|SSL_aDH
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
940 SSL_NOT_EXP
|SSL_HIGH
,
950 TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA
,
951 TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA
,
952 SSL_kEDH
|SSL_aDSS
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
953 SSL_NOT_EXP
|SSL_HIGH
,
963 TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
,
964 TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
,
965 SSL_kEDH
|SSL_aRSA
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
966 SSL_NOT_EXP
|SSL_HIGH
,
976 TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA
,
977 TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA
,
978 SSL_kEDH
|SSL_aNULL
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
979 SSL_NOT_EXP
|SSL_HIGH
,
986 #endif /* OPENSSL_NO_CAMELLIA */
988 #if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES
989 /* New TLS Export CipherSuites from expired ID */
994 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5
,
995 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5
,
996 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_MD5
|SSL_TLSV1
,
997 SSL_EXPORT
|SSL_EXP56
,
1007 TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5
,
1008 TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5
,
1009 SSL_kRSA
|SSL_aRSA
|SSL_RC2
|SSL_MD5
|SSL_TLSV1
,
1010 SSL_EXPORT
|SSL_EXP56
,
1021 TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA
,
1022 TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA
,
1023 SSL_kRSA
|SSL_aRSA
|SSL_DES
|SSL_SHA
|SSL_TLSV1
,
1024 SSL_EXPORT
|SSL_EXP56
,
1034 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA
,
1035 TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA
,
1036 SSL_kEDH
|SSL_aDSS
|SSL_DES
|SSL_SHA
|SSL_TLSV1
,
1037 SSL_EXPORT
|SSL_EXP56
,
1047 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA
,
1048 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA
,
1049 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
1050 SSL_EXPORT
|SSL_EXP56
,
1060 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA
,
1061 TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA
,
1062 SSL_kEDH
|SSL_aDSS
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
1063 SSL_EXPORT
|SSL_EXP56
,
1073 TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA
,
1074 TLS1_CK_DHE_DSS_WITH_RC4_128_SHA
,
1075 SSL_kEDH
|SSL_aDSS
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
1076 SSL_NOT_EXP
|SSL_MEDIUM
,
1085 #ifndef OPENSSL_NO_CAMELLIA
1086 /* Camellia ciphersuites from RFC4132 (256-bit portion) */
1091 TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1092 TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1093 SSL_kRSA
|SSL_aRSA
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
1094 SSL_NOT_EXP
|SSL_HIGH
,
1103 0, /* not implemented (non-ephemeral DH) */
1104 TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA
,
1105 TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA
,
1106 SSL_kDHd
|SSL_aDH
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
1107 SSL_NOT_EXP
|SSL_HIGH
,
1116 0, /* not implemented (non-ephemeral DH) */
1117 TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1118 TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1119 SSL_kDHr
|SSL_aDH
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
1120 SSL_NOT_EXP
|SSL_HIGH
,
1130 TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA
,
1131 TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA
,
1132 SSL_kEDH
|SSL_aDSS
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
1133 SSL_NOT_EXP
|SSL_HIGH
,
1143 TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1144 TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1145 SSL_kEDH
|SSL_aRSA
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
1146 SSL_NOT_EXP
|SSL_HIGH
,
1156 TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA
,
1157 TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA
,
1158 SSL_kEDH
|SSL_aNULL
|SSL_CAMELLIA
|SSL_SHA
|SSL_TLSV1
,
1159 SSL_NOT_EXP
|SSL_HIGH
,
1166 #endif /* OPENSSL_NO_CAMELLIA */
1168 #ifndef OPENSSL_NO_ECDH
1172 TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA
,
1173 TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA
,
1174 SSL_kECDH
|SSL_aECDSA
|SSL_eNULL
|SSL_SHA
|SSL_TLSV1
,
1186 TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA
,
1187 TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA
,
1188 SSL_kECDH
|SSL_aECDSA
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
1200 TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA
,
1201 TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA
,
1202 SSL_kECDH
|SSL_aECDSA
|SSL_3DES
|SSL_SHA
|SSL_TLSV1
,
1203 SSL_NOT_EXP
|SSL_HIGH
,
1214 TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA
,
1215 TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA
,
1216 SSL_kECDH
|SSL_aECDSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
1217 SSL_NOT_EXP
|SSL_HIGH
,
1228 TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA
,
1229 TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA
,
1230 SSL_kECDH
|SSL_aECDSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
1231 SSL_NOT_EXP
|SSL_HIGH
,
1242 TLS1_TXT_ECDHE_ECDSA_WITH_NULL_SHA
,
1243 TLS1_CK_ECDHE_ECDSA_WITH_NULL_SHA
,
1244 SSL_kECDHE
|SSL_aECDSA
|SSL_eNULL
|SSL_SHA
|SSL_TLSV1
,
1256 TLS1_TXT_ECDHE_ECDSA_WITH_RC4_128_SHA
,
1257 TLS1_CK_ECDHE_ECDSA_WITH_RC4_128_SHA
,
1258 SSL_kECDHE
|SSL_aECDSA
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
1270 TLS1_TXT_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA
,
1271 TLS1_CK_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA
,
1272 SSL_kECDHE
|SSL_aECDSA
|SSL_3DES
|SSL_SHA
|SSL_TLSV1
,
1273 SSL_NOT_EXP
|SSL_HIGH
,
1284 TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
,
1285 TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
,
1286 SSL_kECDHE
|SSL_aECDSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
1287 SSL_NOT_EXP
|SSL_HIGH
,
1298 TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
,
1299 TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
,
1300 SSL_kECDHE
|SSL_aECDSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
1301 SSL_NOT_EXP
|SSL_HIGH
,
1312 TLS1_TXT_ECDH_RSA_WITH_NULL_SHA
,
1313 TLS1_CK_ECDH_RSA_WITH_NULL_SHA
,
1314 SSL_kECDH
|SSL_aRSA
|SSL_eNULL
|SSL_SHA
|SSL_TLSV1
,
1326 TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA
,
1327 TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA
,
1328 SSL_kECDH
|SSL_aRSA
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
1340 TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA
,
1341 TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA
,
1342 SSL_kECDH
|SSL_aRSA
|SSL_3DES
|SSL_SHA
|SSL_TLSV1
,
1343 SSL_NOT_EXP
|SSL_HIGH
,
1354 TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA
,
1355 TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA
,
1356 SSL_kECDH
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
1357 SSL_NOT_EXP
|SSL_HIGH
,
1368 TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA
,
1369 TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA
,
1370 SSL_kECDH
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
1371 SSL_NOT_EXP
|SSL_HIGH
,
1382 TLS1_TXT_ECDHE_RSA_WITH_NULL_SHA
,
1383 TLS1_CK_ECDHE_RSA_WITH_NULL_SHA
,
1384 SSL_kECDHE
|SSL_aRSA
|SSL_eNULL
|SSL_SHA
|SSL_TLSV1
,
1396 TLS1_TXT_ECDHE_RSA_WITH_RC4_128_SHA
,
1397 TLS1_CK_ECDHE_RSA_WITH_RC4_128_SHA
,
1398 SSL_kECDHE
|SSL_aRSA
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
1410 TLS1_TXT_ECDHE_RSA_WITH_DES_192_CBC3_SHA
,
1411 TLS1_CK_ECDHE_RSA_WITH_DES_192_CBC3_SHA
,
1412 SSL_kECDHE
|SSL_aRSA
|SSL_3DES
|SSL_SHA
|SSL_TLSV1
,
1413 SSL_NOT_EXP
|SSL_HIGH
,
1424 TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA
,
1425 TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA
,
1426 SSL_kECDHE
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
1427 SSL_NOT_EXP
|SSL_HIGH
,
1438 TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA
,
1439 TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA
,
1440 SSL_kECDHE
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
1441 SSL_NOT_EXP
|SSL_HIGH
,
1452 TLS1_TXT_ECDH_anon_WITH_NULL_SHA
,
1453 TLS1_CK_ECDH_anon_WITH_NULL_SHA
,
1454 SSL_kECDHE
|SSL_aNULL
|SSL_eNULL
|SSL_SHA
|SSL_TLSV1
,
1466 TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA
,
1467 TLS1_CK_ECDH_anon_WITH_RC4_128_SHA
,
1468 SSL_kECDHE
|SSL_aNULL
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
1480 TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA
,
1481 TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA
,
1482 SSL_kECDHE
|SSL_aNULL
|SSL_3DES
|SSL_SHA
|SSL_TLSV1
,
1483 SSL_NOT_EXP
|SSL_HIGH
,
1494 TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA
,
1495 TLS1_CK_ECDH_anon_WITH_AES_128_CBC_SHA
,
1496 SSL_kECDHE
|SSL_aNULL
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
1497 SSL_NOT_EXP
|SSL_HIGH
,
1508 TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA
,
1509 TLS1_CK_ECDH_anon_WITH_AES_256_CBC_SHA
,
1510 SSL_kECDHE
|SSL_aNULL
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
1511 SSL_NOT_EXP
|SSL_HIGH
,
1518 #endif /* OPENSSL_NO_ECDH */
1524 SSL3_ENC_METHOD SSLv3_enc_data
={
1527 ssl3_setup_key_block
,
1528 ssl3_generate_master_secret
,
1529 ssl3_change_cipher_state
,
1530 ssl3_final_finish_mac
,
1531 MD5_DIGEST_LENGTH
+SHA_DIGEST_LENGTH
,
1532 ssl3_cert_verify_mac
,
1533 SSL3_MD_CLIENT_FINISHED_CONST
,4,
1534 SSL3_MD_SERVER_FINISHED_CONST
,4,
1538 long ssl3_default_timeout(void)
1540 /* 2 hours, the 24 hours mentioned in the SSLv3 spec
1541 * is way too long for http, the cache would over fill */
1545 IMPLEMENT_ssl3_meth_func(sslv3_base_method
,
1546 ssl_undefined_function
,
1547 ssl_undefined_function
,
1550 int ssl3_num_ciphers(void)
1552 return(SSL3_NUM_CIPHERS
);
1555 SSL_CIPHER
*ssl3_get_cipher(unsigned int u
)
1557 if (u
< SSL3_NUM_CIPHERS
)
1558 return(&(ssl3_ciphers
[SSL3_NUM_CIPHERS
-1-u
]));
1563 int ssl3_pending(const SSL
*s
)
1565 if (s
->rstate
== SSL_ST_READ_BODY
)
1568 return (s
->s3
->rrec
.type
== SSL3_RT_APPLICATION_DATA
) ? s
->s3
->rrec
.length
: 0;
1571 int ssl3_new(SSL
*s
)
1575 if ((s3
=OPENSSL_malloc(sizeof *s3
)) == NULL
) goto err
;
1576 memset(s3
,0,sizeof *s3
);
1577 EVP_MD_CTX_init(&s3
->finish_dgst1
);
1578 EVP_MD_CTX_init(&s3
->finish_dgst2
);
1579 pq_64bit_init(&(s3
->rrec
.seq_num
));
1580 pq_64bit_init(&(s3
->wrec
.seq_num
));
1584 s
->method
->ssl_clear(s
);
1590 void ssl3_free(SSL
*s
)
1595 ssl3_cleanup_key_block(s
);
1596 if (s
->s3
->rbuf
.buf
!= NULL
)
1597 OPENSSL_free(s
->s3
->rbuf
.buf
);
1598 if (s
->s3
->wbuf
.buf
!= NULL
)
1599 OPENSSL_free(s
->s3
->wbuf
.buf
);
1600 if (s
->s3
->rrec
.comp
!= NULL
)
1601 OPENSSL_free(s
->s3
->rrec
.comp
);
1602 #ifndef OPENSSL_NO_DH
1603 if (s
->s3
->tmp
.dh
!= NULL
)
1604 DH_free(s
->s3
->tmp
.dh
);
1606 #ifndef OPENSSL_NO_ECDH
1607 if (s
->s3
->tmp
.ecdh
!= NULL
)
1608 EC_KEY_free(s
->s3
->tmp
.ecdh
);
1611 if (s
->s3
->tmp
.ca_names
!= NULL
)
1612 sk_X509_NAME_pop_free(s
->s3
->tmp
.ca_names
,X509_NAME_free
);
1613 EVP_MD_CTX_cleanup(&s
->s3
->finish_dgst1
);
1614 EVP_MD_CTX_cleanup(&s
->s3
->finish_dgst2
);
1615 pq_64bit_free(&(s
->s3
->rrec
.seq_num
));
1616 pq_64bit_free(&(s
->s3
->wrec
.seq_num
));
1618 OPENSSL_cleanse(s
->s3
,sizeof *s
->s3
);
1619 OPENSSL_free(s
->s3
);
1623 void ssl3_clear(SSL
*s
)
1625 unsigned char *rp
,*wp
;
1628 ssl3_cleanup_key_block(s
);
1629 if (s
->s3
->tmp
.ca_names
!= NULL
)
1630 sk_X509_NAME_pop_free(s
->s3
->tmp
.ca_names
,X509_NAME_free
);
1632 if (s
->s3
->rrec
.comp
!= NULL
)
1634 OPENSSL_free(s
->s3
->rrec
.comp
);
1635 s
->s3
->rrec
.comp
=NULL
;
1637 #ifndef OPENSSL_NO_DH
1638 if (s
->s3
->tmp
.dh
!= NULL
)
1639 DH_free(s
->s3
->tmp
.dh
);
1641 #ifndef OPENSSL_NO_ECDH
1642 if (s
->s3
->tmp
.ecdh
!= NULL
)
1643 EC_KEY_free(s
->s3
->tmp
.ecdh
);
1646 rp
= s
->s3
->rbuf
.buf
;
1647 wp
= s
->s3
->wbuf
.buf
;
1648 rlen
= s
->s3
->rbuf
.len
;
1649 wlen
= s
->s3
->wbuf
.len
;
1651 EVP_MD_CTX_cleanup(&s
->s3
->finish_dgst1
);
1652 EVP_MD_CTX_cleanup(&s
->s3
->finish_dgst2
);
1654 memset(s
->s3
,0,sizeof *s
->s3
);
1655 s
->s3
->rbuf
.buf
= rp
;
1656 s
->s3
->wbuf
.buf
= wp
;
1657 s
->s3
->rbuf
.len
= rlen
;
1658 s
->s3
->wbuf
.len
= wlen
;
1660 ssl_free_wbio_buffer(s
);
1663 s
->s3
->renegotiate
=0;
1664 s
->s3
->total_renegotiations
=0;
1665 s
->s3
->num_renegotiations
=0;
1666 s
->s3
->in_read_app_data
=0;
1667 s
->version
=SSL3_VERSION
;
1670 long ssl3_ctrl(SSL
*s
, int cmd
, long larg
, void *parg
)
1674 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
1676 #ifndef OPENSSL_NO_RSA
1677 cmd
== SSL_CTRL_SET_TMP_RSA
||
1678 cmd
== SSL_CTRL_SET_TMP_RSA_CB
||
1680 #ifndef OPENSSL_NO_DSA
1681 cmd
== SSL_CTRL_SET_TMP_DH
||
1682 cmd
== SSL_CTRL_SET_TMP_DH_CB
||
1686 if (!ssl_cert_inst(&s
->cert
))
1688 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_MALLOC_FAILURE
);
1696 case SSL_CTRL_GET_SESSION_REUSED
:
1699 case SSL_CTRL_GET_CLIENT_CERT_REQUEST
:
1701 case SSL_CTRL_GET_NUM_RENEGOTIATIONS
:
1702 ret
=s
->s3
->num_renegotiations
;
1704 case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS
:
1705 ret
=s
->s3
->num_renegotiations
;
1706 s
->s3
->num_renegotiations
=0;
1708 case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS
:
1709 ret
=s
->s3
->total_renegotiations
;
1711 case SSL_CTRL_GET_FLAGS
:
1712 ret
=(int)(s
->s3
->flags
);
1714 #ifndef OPENSSL_NO_RSA
1715 case SSL_CTRL_NEED_TMP_RSA
:
1716 if ((s
->cert
!= NULL
) && (s
->cert
->rsa_tmp
== NULL
) &&
1717 ((s
->cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
== NULL
) ||
1718 (EVP_PKEY_size(s
->cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
) > (512/8))))
1721 case SSL_CTRL_SET_TMP_RSA
:
1723 RSA
*rsa
= (RSA
*)parg
;
1726 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_PASSED_NULL_PARAMETER
);
1729 if ((rsa
= RSAPrivateKey_dup(rsa
)) == NULL
)
1731 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_RSA_LIB
);
1734 if (s
->cert
->rsa_tmp
!= NULL
)
1735 RSA_free(s
->cert
->rsa_tmp
);
1736 s
->cert
->rsa_tmp
= rsa
;
1740 case SSL_CTRL_SET_TMP_RSA_CB
:
1742 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1747 #ifndef OPENSSL_NO_DH
1748 case SSL_CTRL_SET_TMP_DH
:
1750 DH
*dh
= (DH
*)parg
;
1753 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_PASSED_NULL_PARAMETER
);
1756 if ((dh
= DHparams_dup(dh
)) == NULL
)
1758 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_DH_LIB
);
1761 if (!(s
->options
& SSL_OP_SINGLE_DH_USE
))
1763 if (!DH_generate_key(dh
))
1766 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_DH_LIB
);
1770 if (s
->cert
->dh_tmp
!= NULL
)
1771 DH_free(s
->cert
->dh_tmp
);
1772 s
->cert
->dh_tmp
= dh
;
1776 case SSL_CTRL_SET_TMP_DH_CB
:
1778 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1783 #ifndef OPENSSL_NO_ECDH
1784 case SSL_CTRL_SET_TMP_ECDH
:
1786 EC_KEY
*ecdh
= NULL
;
1790 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_PASSED_NULL_PARAMETER
);
1793 if (!EC_KEY_up_ref((EC_KEY
*)parg
))
1795 SSLerr(SSL_F_SSL3_CTRL
,ERR_R_ECDH_LIB
);
1798 ecdh
= (EC_KEY
*)parg
;
1799 if (!(s
->options
& SSL_OP_SINGLE_ECDH_USE
))
1801 if (!EC_KEY_generate_key(ecdh
))
1804 SSLerr(SSL_F_SSL3_CTRL
,ERR_R_ECDH_LIB
);
1808 if (s
->cert
->ecdh_tmp
!= NULL
)
1809 EC_KEY_free(s
->cert
->ecdh_tmp
);
1810 s
->cert
->ecdh_tmp
= ecdh
;
1814 case SSL_CTRL_SET_TMP_ECDH_CB
:
1816 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1820 #endif /* !OPENSSL_NO_ECDH */
1827 long ssl3_callback_ctrl(SSL
*s
, int cmd
, void (*fp
)(void))
1831 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
1833 #ifndef OPENSSL_NO_RSA
1834 cmd
== SSL_CTRL_SET_TMP_RSA_CB
||
1836 #ifndef OPENSSL_NO_DSA
1837 cmd
== SSL_CTRL_SET_TMP_DH_CB
||
1841 if (!ssl_cert_inst(&s
->cert
))
1843 SSLerr(SSL_F_SSL3_CALLBACK_CTRL
, ERR_R_MALLOC_FAILURE
);
1851 #ifndef OPENSSL_NO_RSA
1852 case SSL_CTRL_SET_TMP_RSA_CB
:
1854 s
->cert
->rsa_tmp_cb
= (RSA
*(*)(SSL
*, int, int))fp
;
1858 #ifndef OPENSSL_NO_DH
1859 case SSL_CTRL_SET_TMP_DH_CB
:
1861 s
->cert
->dh_tmp_cb
= (DH
*(*)(SSL
*, int, int))fp
;
1865 #ifndef OPENSSL_NO_ECDH
1866 case SSL_CTRL_SET_TMP_ECDH_CB
:
1868 s
->cert
->ecdh_tmp_cb
= (EC_KEY
*(*)(SSL
*, int, int))fp
;
1878 long ssl3_ctx_ctrl(SSL_CTX
*ctx
, int cmd
, long larg
, void *parg
)
1886 #ifndef OPENSSL_NO_RSA
1887 case SSL_CTRL_NEED_TMP_RSA
:
1888 if ( (cert
->rsa_tmp
== NULL
) &&
1889 ((cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
== NULL
) ||
1890 (EVP_PKEY_size(cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
) > (512/8)))
1896 case SSL_CTRL_SET_TMP_RSA
:
1907 if ((rsa
=RSAPrivateKey_dup(rsa
)) == NULL
)
1912 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_RSA_LIB
);
1917 if (cert
->rsa_tmp
!= NULL
)
1918 RSA_free(cert
->rsa_tmp
);
1924 case SSL_CTRL_SET_TMP_RSA_CB
:
1926 SSLerr(SSL_F_SSL3_CTX_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1931 #ifndef OPENSSL_NO_DH
1932 case SSL_CTRL_SET_TMP_DH
:
1937 if ((new=DHparams_dup(dh
)) == NULL
)
1939 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_DH_LIB
);
1942 if (!(ctx
->options
& SSL_OP_SINGLE_DH_USE
))
1944 if (!DH_generate_key(new))
1946 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_DH_LIB
);
1951 if (cert
->dh_tmp
!= NULL
)
1952 DH_free(cert
->dh_tmp
);
1957 case SSL_CTRL_SET_TMP_DH_CB
:
1959 SSLerr(SSL_F_SSL3_CTX_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1964 #ifndef OPENSSL_NO_ECDH
1965 case SSL_CTRL_SET_TMP_ECDH
:
1967 EC_KEY
*ecdh
= NULL
;
1971 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_ECDH_LIB
);
1974 ecdh
= EC_KEY_dup((EC_KEY
*)parg
);
1977 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_EC_LIB
);
1980 if (!(ctx
->options
& SSL_OP_SINGLE_ECDH_USE
))
1982 if (!EC_KEY_generate_key(ecdh
))
1985 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_ECDH_LIB
);
1990 if (cert
->ecdh_tmp
!= NULL
)
1992 EC_KEY_free(cert
->ecdh_tmp
);
1994 cert
->ecdh_tmp
= ecdh
;
1998 case SSL_CTRL_SET_TMP_ECDH_CB
:
2000 SSLerr(SSL_F_SSL3_CTX_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2004 #endif /* !OPENSSL_NO_ECDH */
2005 /* A Thawte special :-) */
2006 case SSL_CTRL_EXTRA_CHAIN_CERT
:
2007 if (ctx
->extra_certs
== NULL
)
2009 if ((ctx
->extra_certs
=sk_X509_new_null()) == NULL
)
2012 sk_X509_push(ctx
->extra_certs
,(X509
*)parg
);
2021 long ssl3_ctx_callback_ctrl(SSL_CTX
*ctx
, int cmd
, void (*fp
)(void))
2029 #ifndef OPENSSL_NO_RSA
2030 case SSL_CTRL_SET_TMP_RSA_CB
:
2032 cert
->rsa_tmp_cb
= (RSA
*(*)(SSL
*, int, int))fp
;
2036 #ifndef OPENSSL_NO_DH
2037 case SSL_CTRL_SET_TMP_DH_CB
:
2039 cert
->dh_tmp_cb
= (DH
*(*)(SSL
*, int, int))fp
;
2043 #ifndef OPENSSL_NO_ECDH
2044 case SSL_CTRL_SET_TMP_ECDH_CB
:
2046 cert
->ecdh_tmp_cb
= (EC_KEY
*(*)(SSL
*, int, int))fp
;
2056 /* This function needs to check if the ciphers required are actually
2058 SSL_CIPHER
*ssl3_get_cipher_by_char(const unsigned char *p
)
2063 id
=0x03000000L
|((unsigned long)p
[0]<<8L)|(unsigned long)p
[1];
2065 cp
= (SSL_CIPHER
*)OBJ_bsearch((char *)&c
,
2066 (char *)ssl3_ciphers
,
2067 SSL3_NUM_CIPHERS
,sizeof(SSL_CIPHER
),
2068 FP_ICC ssl_cipher_id_cmp
);
2069 if (cp
== NULL
|| cp
->valid
== 0)
2075 int ssl3_put_cipher_by_char(const SSL_CIPHER
*c
, unsigned char *p
)
2082 if ((l
& 0xff000000) != 0x03000000) return(0);
2083 p
[0]=((unsigned char)(l
>> 8L))&0xFF;
2084 p
[1]=((unsigned char)(l
))&0xFF;
2089 SSL_CIPHER
*ssl3_choose_cipher(SSL
*s
, STACK_OF(SSL_CIPHER
) *clnt
,
2090 STACK_OF(SSL_CIPHER
) *srvr
)
2092 SSL_CIPHER
*c
,*ret
=NULL
;
2093 STACK_OF(SSL_CIPHER
) *prio
, *allow
;
2096 unsigned long alg
,mask
,emask
;
2098 /* Let's see which ciphers we can support */
2102 /* Do not set the compare functions, because this may lead to a
2103 * reordering by "id". We want to keep the original ordering.
2104 * We may pay a price in performance during sk_SSL_CIPHER_find(),
2105 * but would have to pay with the price of sk_SSL_CIPHER_dup().
2107 sk_SSL_CIPHER_set_cmp_func(srvr
, ssl_cipher_ptr_id_cmp
);
2108 sk_SSL_CIPHER_set_cmp_func(clnt
, ssl_cipher_ptr_id_cmp
);
2112 printf("Server has %d from %p:\n", sk_SSL_CIPHER_num(srvr
), srvr
);
2113 for(i
=0 ; i
< sk_SSL_CIPHER_num(srvr
) ; ++i
)
2115 c
=sk_SSL_CIPHER_value(srvr
,i
);
2116 printf("%p:%s\n",c
,c
->name
);
2118 printf("Client sent %d from %p:\n", sk_SSL_CIPHER_num(clnt
), clnt
);
2119 for(i
=0 ; i
< sk_SSL_CIPHER_num(clnt
) ; ++i
)
2121 c
=sk_SSL_CIPHER_value(clnt
,i
);
2122 printf("%p:%s\n",c
,c
->name
);
2126 if (s
->options
& SSL_OP_CIPHER_SERVER_PREFERENCE
)
2137 for (i
=0; i
<sk_SSL_CIPHER_num(prio
); i
++)
2139 c
=sk_SSL_CIPHER_value(prio
,i
);
2141 ssl_set_cert_masks(cert
,c
);
2143 emask
=cert
->export_mask
;
2146 printf("ssl3_choose_cipher %d alg= %lx\n", i
,c
->algorithms
);
2147 #endif /* KSSL_DEBUG */
2149 alg
=c
->algorithms
&(SSL_MKEY_MASK
|SSL_AUTH_MASK
);
2150 #ifndef OPENSSL_NO_KRB5
2153 if ( !kssl_keytab_is_available(s
->kssl_ctx
) )
2156 #endif /* OPENSSL_NO_KRB5 */
2157 if (SSL_C_IS_EXPORT(c
))
2159 ok
=((alg
& emask
) == alg
)?1:0;
2161 printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok
,alg
,emask
,
2167 ok
=((alg
& mask
) == alg
)?1:0;
2169 printf("%d:[%08lX:%08lX]%p:%s\n",ok
,alg
,mask
,c
,
2175 j
=sk_SSL_CIPHER_find(allow
,c
);
2178 ret
=sk_SSL_CIPHER_value(allow
,j
);
2185 int ssl3_get_req_cert_type(SSL
*s
, unsigned char *p
)
2190 alg
=s
->s3
->tmp
.new_cipher
->algorithms
;
2192 #ifndef OPENSSL_NO_DH
2193 if (alg
& (SSL_kDHr
|SSL_kEDH
))
2195 # ifndef OPENSSL_NO_RSA
2196 p
[ret
++]=SSL3_CT_RSA_FIXED_DH
;
2198 # ifndef OPENSSL_NO_DSA
2199 p
[ret
++]=SSL3_CT_DSS_FIXED_DH
;
2202 if ((s
->version
== SSL3_VERSION
) &&
2203 (alg
& (SSL_kEDH
|SSL_kDHd
|SSL_kDHr
)))
2205 # ifndef OPENSSL_NO_RSA
2206 p
[ret
++]=SSL3_CT_RSA_EPHEMERAL_DH
;
2208 # ifndef OPENSSL_NO_DSA
2209 p
[ret
++]=SSL3_CT_DSS_EPHEMERAL_DH
;
2212 #endif /* !OPENSSL_NO_DH */
2213 #ifndef OPENSSL_NO_RSA
2214 p
[ret
++]=SSL3_CT_RSA_SIGN
;
2216 #ifndef OPENSSL_NO_DSA
2217 p
[ret
++]=SSL3_CT_DSS_SIGN
;
2219 #ifndef OPENSSL_NO_ECDH
2220 /* We should ask for fixed ECDH certificates only
2221 * for SSL_kECDH (and not SSL_kECDHE)
2223 if ((alg
& SSL_kECDH
) && (s
->version
>= TLS1_VERSION
))
2225 p
[ret
++]=TLS_CT_RSA_FIXED_ECDH
;
2226 p
[ret
++]=TLS_CT_ECDSA_FIXED_ECDH
;
2230 #ifndef OPENSSL_NO_ECDSA
2231 /* ECDSA certs can be used with RSA cipher suites as well
2232 * so we don't need to check for SSL_kECDH or SSL_kECDHE
2234 if (s
->version
>= TLS1_VERSION
)
2236 p
[ret
++]=TLS_CT_ECDSA_SIGN
;
2242 int ssl3_shutdown(SSL
*s
)
2245 /* Don't do anything much if we have not done the handshake or
2246 * we don't want to send messages :-) */
2247 if ((s
->quiet_shutdown
) || (s
->state
== SSL_ST_BEFORE
))
2249 s
->shutdown
=(SSL_SENT_SHUTDOWN
|SSL_RECEIVED_SHUTDOWN
);
2253 if (!(s
->shutdown
& SSL_SENT_SHUTDOWN
))
2255 s
->shutdown
|=SSL_SENT_SHUTDOWN
;
2257 ssl3_send_alert(s
,SSL3_AL_WARNING
,SSL_AD_CLOSE_NOTIFY
);
2259 /* our shutdown alert has been sent now, and if it still needs
2260 * to be written, s->s3->alert_dispatch will be true */
2262 else if (s
->s3
->alert_dispatch
)
2264 /* resend it if not sent */
2266 s
->method
->ssl_dispatch_alert(s
);
2269 else if (!(s
->shutdown
& SSL_RECEIVED_SHUTDOWN
))
2271 /* If we are waiting for a close from our peer, we are closed */
2272 s
->method
->ssl_read_bytes(s
,0,NULL
,0,0);
2275 if ((s
->shutdown
== (SSL_SENT_SHUTDOWN
|SSL_RECEIVED_SHUTDOWN
)) &&
2276 !s
->s3
->alert_dispatch
)
2282 int ssl3_write(SSL
*s
, const void *buf
, int len
)
2287 if (s
->shutdown
& SSL_SEND_SHUTDOWN
)
2289 s
->rwstate
=SSL_NOTHING
;
2294 if (s
->s3
->renegotiate
) ssl3_renegotiate_check(s
);
2296 /* This is an experimental flag that sends the
2297 * last handshake message in the same packet as the first
2298 * use data - used to see if it helps the TCP protocol during
2299 * session-id reuse */
2300 /* The second test is because the buffer may have been removed */
2301 if ((s
->s3
->flags
& SSL3_FLAGS_POP_BUFFER
) && (s
->wbio
== s
->bbio
))
2303 /* First time through, we write into the buffer */
2304 if (s
->s3
->delay_buf_pop_ret
== 0)
2306 ret
=ssl3_write_bytes(s
,SSL3_RT_APPLICATION_DATA
,
2308 if (ret
<= 0) return(ret
);
2310 s
->s3
->delay_buf_pop_ret
=ret
;
2313 s
->rwstate
=SSL_WRITING
;
2314 n
=BIO_flush(s
->wbio
);
2315 if (n
<= 0) return(n
);
2316 s
->rwstate
=SSL_NOTHING
;
2318 /* We have flushed the buffer, so remove it */
2319 ssl_free_wbio_buffer(s
);
2320 s
->s3
->flags
&= ~SSL3_FLAGS_POP_BUFFER
;
2322 ret
=s
->s3
->delay_buf_pop_ret
;
2323 s
->s3
->delay_buf_pop_ret
=0;
2327 ret
=s
->method
->ssl_write_bytes(s
,SSL3_RT_APPLICATION_DATA
,
2329 if (ret
<= 0) return(ret
);
2335 static int ssl3_read_internal(SSL
*s
, void *buf
, int len
, int peek
)
2340 if (s
->s3
->renegotiate
) ssl3_renegotiate_check(s
);
2341 s
->s3
->in_read_app_data
=1;
2342 ret
=s
->method
->ssl_read_bytes(s
,SSL3_RT_APPLICATION_DATA
,buf
,len
,peek
);
2343 if ((ret
== -1) && (s
->s3
->in_read_app_data
== 2))
2345 /* ssl3_read_bytes decided to call s->handshake_func, which
2346 * called ssl3_read_bytes to read handshake data.
2347 * However, ssl3_read_bytes actually found application data
2348 * and thinks that application data makes sense here; so disable
2349 * handshake processing and try to read application data again. */
2351 ret
=s
->method
->ssl_read_bytes(s
,SSL3_RT_APPLICATION_DATA
,buf
,len
,peek
);
2355 s
->s3
->in_read_app_data
=0;
2360 int ssl3_read(SSL
*s
, void *buf
, int len
)
2362 return ssl3_read_internal(s
, buf
, len
, 0);
2365 int ssl3_peek(SSL
*s
, void *buf
, int len
)
2367 return ssl3_read_internal(s
, buf
, len
, 1);
2370 int ssl3_renegotiate(SSL
*s
)
2372 if (s
->handshake_func
== NULL
)
2375 if (s
->s3
->flags
& SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS
)
2378 s
->s3
->renegotiate
=1;
2382 int ssl3_renegotiate_check(SSL
*s
)
2386 if (s
->s3
->renegotiate
)
2388 if ( (s
->s3
->rbuf
.left
== 0) &&
2389 (s
->s3
->wbuf
.left
== 0) &&
2393 if we are the server, and we have sent a 'RENEGOTIATE' message, we
2394 need to go to SSL_ST_ACCEPT.
2397 s
->state
=SSL_ST_RENEGOTIATE
;
2398 s
->s3
->renegotiate
=0;
2399 s
->s3
->num_renegotiations
++;
2400 s
->s3
->total_renegotiations
++;