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-2007 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.
124 /* ====================================================================
125 * Copyright 2005 Nokia. All rights reserved.
127 * The portions of the attached software ("Contribution") is developed by
128 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
131 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
132 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
133 * support (see RFC 4279) to OpenSSL.
135 * No patent licenses or other rights except those expressly stated in
136 * the OpenSSL open source license shall be deemed granted or received
137 * expressly, by implication, estoppel, or otherwise.
139 * No assurances are provided by Nokia that the Contribution does not
140 * infringe the patent or other intellectual property rights of any third
141 * party or that the license provides you with all the necessary rights
142 * to make use of the Contribution.
144 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
145 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
146 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
147 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
152 #include <openssl/objects.h>
153 #include "ssl_locl.h"
154 #include "kssl_lcl.h"
155 #ifndef OPENSSL_NO_TLSEXT
156 #ifndef OPENSSL_NO_EC
157 #include "../crypto/ec/ec_lcl.h"
158 #endif /* OPENSSL_NO_EC */
159 #endif /* OPENSSL_NO_TLSEXT */
160 #include <openssl/md5.h>
161 #ifndef OPENSSL_NO_DH
162 #include <openssl/dh.h>
165 const char ssl3_version_str
[]="SSLv3" OPENSSL_VERSION_PTEXT
;
167 #define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
169 /* list of available SSLv3 ciphers (sorted by id) */
170 OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers
[]={
172 /* The RSA ciphers */
176 SSL3_TXT_RSA_NULL_MD5
,
177 SSL3_CK_RSA_NULL_MD5
,
183 SSL_NOT_EXP
|SSL_STRONG_NONE
,
192 SSL3_TXT_RSA_NULL_SHA
,
193 SSL3_CK_RSA_NULL_SHA
,
199 SSL_NOT_EXP
|SSL_STRONG_NONE
,
208 SSL3_TXT_RSA_RC4_40_MD5
,
209 SSL3_CK_RSA_RC4_40_MD5
,
215 SSL_EXPORT
|SSL_EXP40
,
224 SSL3_TXT_RSA_RC4_128_MD5
,
225 SSL3_CK_RSA_RC4_128_MD5
,
231 SSL_NOT_EXP
|SSL_MEDIUM
,
240 SSL3_TXT_RSA_RC4_128_SHA
,
241 SSL3_CK_RSA_RC4_128_SHA
,
247 SSL_NOT_EXP
|SSL_MEDIUM
,
256 SSL3_TXT_RSA_RC2_40_MD5
,
257 SSL3_CK_RSA_RC2_40_MD5
,
263 SSL_EXPORT
|SSL_EXP40
,
270 #ifndef OPENSSL_NO_IDEA
273 SSL3_TXT_RSA_IDEA_128_SHA
,
274 SSL3_CK_RSA_IDEA_128_SHA
,
280 SSL_NOT_EXP
|SSL_MEDIUM
,
290 SSL3_TXT_RSA_DES_40_CBC_SHA
,
291 SSL3_CK_RSA_DES_40_CBC_SHA
,
297 SSL_EXPORT
|SSL_EXP40
,
306 SSL3_TXT_RSA_DES_64_CBC_SHA
,
307 SSL3_CK_RSA_DES_64_CBC_SHA
,
322 SSL3_TXT_RSA_DES_192_CBC3_SHA
,
323 SSL3_CK_RSA_DES_192_CBC3_SHA
,
329 SSL_NOT_EXP
|SSL_HIGH
,
339 SSL3_TXT_DH_DSS_DES_40_CBC_SHA
,
340 SSL3_CK_DH_DSS_DES_40_CBC_SHA
,
346 SSL_EXPORT
|SSL_EXP40
,
354 0, /* not implemented (non-ephemeral DH) */
355 SSL3_TXT_DH_DSS_DES_64_CBC_SHA
,
356 SSL3_CK_DH_DSS_DES_64_CBC_SHA
,
370 0, /* not implemented (non-ephemeral DH) */
371 SSL3_TXT_DH_DSS_DES_192_CBC3_SHA
,
372 SSL3_CK_DH_DSS_DES_192_CBC3_SHA
,
378 SSL_NOT_EXP
|SSL_HIGH
,
386 0, /* not implemented (non-ephemeral DH) */
387 SSL3_TXT_DH_RSA_DES_40_CBC_SHA
,
388 SSL3_CK_DH_RSA_DES_40_CBC_SHA
,
394 SSL_EXPORT
|SSL_EXP40
,
402 0, /* not implemented (non-ephemeral DH) */
403 SSL3_TXT_DH_RSA_DES_64_CBC_SHA
,
404 SSL3_CK_DH_RSA_DES_64_CBC_SHA
,
418 0, /* not implemented (non-ephemeral DH) */
419 SSL3_TXT_DH_RSA_DES_192_CBC3_SHA
,
420 SSL3_CK_DH_RSA_DES_192_CBC3_SHA
,
426 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
,
443 SSL_EXPORT
|SSL_EXP40
,
452 SSL3_TXT_EDH_DSS_DES_64_CBC_SHA
,
453 SSL3_CK_EDH_DSS_DES_64_CBC_SHA
,
468 SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA
,
469 SSL3_CK_EDH_DSS_DES_192_CBC3_SHA
,
475 SSL_NOT_EXP
|SSL_HIGH
,
484 SSL3_TXT_EDH_RSA_DES_40_CBC_SHA
,
485 SSL3_CK_EDH_RSA_DES_40_CBC_SHA
,
491 SSL_EXPORT
|SSL_EXP40
,
500 SSL3_TXT_EDH_RSA_DES_64_CBC_SHA
,
501 SSL3_CK_EDH_RSA_DES_64_CBC_SHA
,
516 SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA
,
517 SSL3_CK_EDH_RSA_DES_192_CBC3_SHA
,
523 SSL_NOT_EXP
|SSL_HIGH
,
532 SSL3_TXT_ADH_RC4_40_MD5
,
533 SSL3_CK_ADH_RC4_40_MD5
,
539 SSL_EXPORT
|SSL_EXP40
,
548 SSL3_TXT_ADH_RC4_128_MD5
,
549 SSL3_CK_ADH_RC4_128_MD5
,
555 SSL_NOT_EXP
|SSL_MEDIUM
,
564 SSL3_TXT_ADH_DES_40_CBC_SHA
,
565 SSL3_CK_ADH_DES_40_CBC_SHA
,
571 SSL_EXPORT
|SSL_EXP40
,
580 SSL3_TXT_ADH_DES_64_CBC_SHA
,
581 SSL3_CK_ADH_DES_64_CBC_SHA
,
596 SSL3_TXT_ADH_DES_192_CBC_SHA
,
597 SSL3_CK_ADH_DES_192_CBC_SHA
,
603 SSL_NOT_EXP
|SSL_HIGH
,
609 /* Fortezza ciphersuite from SSL 3.0 spec */
614 SSL3_TXT_FZA_DMS_NULL_SHA
,
615 SSL3_CK_FZA_DMS_NULL_SHA
,
621 SSL_NOT_EXP
|SSL_STRONG_NONE
,
630 SSL3_TXT_FZA_DMS_FZA_SHA
,
631 SSL3_CK_FZA_DMS_FZA_SHA
,
637 SSL_NOT_EXP
|SSL_STRONG_NONE
,
646 SSL3_TXT_FZA_DMS_RC4_SHA
,
647 SSL3_CK_FZA_DMS_RC4_SHA
,
653 SSL_NOT_EXP
|SSL_MEDIUM
,
660 #ifndef OPENSSL_NO_KRB5
661 /* The Kerberos ciphers
662 ** 20000107 VRS: And the first shall be last,
663 ** in hopes of avoiding the lynx ssl renegotiation problem.
668 SSL3_TXT_KRB5_DES_64_CBC_SHA
,
669 SSL3_CK_KRB5_DES_64_CBC_SHA
,
684 SSL3_TXT_KRB5_DES_192_CBC3_SHA
,
685 SSL3_CK_KRB5_DES_192_CBC3_SHA
,
691 SSL_NOT_EXP
|SSL_HIGH
,
700 SSL3_TXT_KRB5_RC4_128_SHA
,
701 SSL3_CK_KRB5_RC4_128_SHA
,
707 SSL_NOT_EXP
|SSL_MEDIUM
,
716 SSL3_TXT_KRB5_IDEA_128_CBC_SHA
,
717 SSL3_CK_KRB5_IDEA_128_CBC_SHA
,
723 SSL_NOT_EXP
|SSL_MEDIUM
,
732 SSL3_TXT_KRB5_DES_64_CBC_MD5
,
733 SSL3_CK_KRB5_DES_64_CBC_MD5
,
748 SSL3_TXT_KRB5_DES_192_CBC3_MD5
,
749 SSL3_CK_KRB5_DES_192_CBC3_MD5
,
755 SSL_NOT_EXP
|SSL_HIGH
,
764 SSL3_TXT_KRB5_RC4_128_MD5
,
765 SSL3_CK_KRB5_RC4_128_MD5
,
771 SSL_NOT_EXP
|SSL_MEDIUM
,
780 SSL3_TXT_KRB5_IDEA_128_CBC_MD5
,
781 SSL3_CK_KRB5_IDEA_128_CBC_MD5
,
787 SSL_NOT_EXP
|SSL_MEDIUM
,
796 SSL3_TXT_KRB5_DES_40_CBC_SHA
,
797 SSL3_CK_KRB5_DES_40_CBC_SHA
,
803 SSL_EXPORT
|SSL_EXP40
,
812 SSL3_TXT_KRB5_RC2_40_CBC_SHA
,
813 SSL3_CK_KRB5_RC2_40_CBC_SHA
,
819 SSL_EXPORT
|SSL_EXP40
,
828 SSL3_TXT_KRB5_RC4_40_SHA
,
829 SSL3_CK_KRB5_RC4_40_SHA
,
835 SSL_EXPORT
|SSL_EXP40
,
844 SSL3_TXT_KRB5_DES_40_CBC_MD5
,
845 SSL3_CK_KRB5_DES_40_CBC_MD5
,
851 SSL_EXPORT
|SSL_EXP40
,
860 SSL3_TXT_KRB5_RC2_40_CBC_MD5
,
861 SSL3_CK_KRB5_RC2_40_CBC_MD5
,
867 SSL_EXPORT
|SSL_EXP40
,
876 SSL3_TXT_KRB5_RC4_40_MD5
,
877 SSL3_CK_KRB5_RC4_40_MD5
,
883 SSL_EXPORT
|SSL_EXP40
,
888 #endif /* OPENSSL_NO_KRB5 */
890 /* New AES ciphersuites */
894 TLS1_TXT_RSA_WITH_AES_128_SHA
,
895 TLS1_CK_RSA_WITH_AES_128_SHA
,
901 SSL_NOT_EXP
|SSL_HIGH
,
909 TLS1_TXT_DH_DSS_WITH_AES_128_SHA
,
910 TLS1_CK_DH_DSS_WITH_AES_128_SHA
,
916 SSL_NOT_EXP
|SSL_HIGH
,
924 TLS1_TXT_DH_RSA_WITH_AES_128_SHA
,
925 TLS1_CK_DH_RSA_WITH_AES_128_SHA
,
931 SSL_NOT_EXP
|SSL_HIGH
,
939 TLS1_TXT_DHE_DSS_WITH_AES_128_SHA
,
940 TLS1_CK_DHE_DSS_WITH_AES_128_SHA
,
946 SSL_NOT_EXP
|SSL_HIGH
,
954 TLS1_TXT_DHE_RSA_WITH_AES_128_SHA
,
955 TLS1_CK_DHE_RSA_WITH_AES_128_SHA
,
961 SSL_NOT_EXP
|SSL_HIGH
,
969 TLS1_TXT_ADH_WITH_AES_128_SHA
,
970 TLS1_CK_ADH_WITH_AES_128_SHA
,
976 SSL_NOT_EXP
|SSL_HIGH
,
985 TLS1_TXT_RSA_WITH_AES_256_SHA
,
986 TLS1_CK_RSA_WITH_AES_256_SHA
,
992 SSL_NOT_EXP
|SSL_HIGH
,
1000 TLS1_TXT_DH_DSS_WITH_AES_256_SHA
,
1001 TLS1_CK_DH_DSS_WITH_AES_256_SHA
,
1007 SSL_NOT_EXP
|SSL_HIGH
,
1015 0, /* not implemented (non-ephemeral DH) */
1016 TLS1_TXT_DH_RSA_WITH_AES_256_SHA
,
1017 TLS1_CK_DH_RSA_WITH_AES_256_SHA
,
1023 SSL_NOT_EXP
|SSL_HIGH
,
1032 TLS1_TXT_DHE_DSS_WITH_AES_256_SHA
,
1033 TLS1_CK_DHE_DSS_WITH_AES_256_SHA
,
1039 SSL_NOT_EXP
|SSL_HIGH
,
1048 TLS1_TXT_DHE_RSA_WITH_AES_256_SHA
,
1049 TLS1_CK_DHE_RSA_WITH_AES_256_SHA
,
1055 SSL_NOT_EXP
|SSL_HIGH
,
1064 TLS1_TXT_ADH_WITH_AES_256_SHA
,
1065 TLS1_CK_ADH_WITH_AES_256_SHA
,
1071 SSL_NOT_EXP
|SSL_HIGH
,
1077 #ifndef OPENSSL_NO_CAMELLIA
1078 /* Camellia ciphersuites from RFC4132 (128-bit portion) */
1083 TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA
,
1084 TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA
,
1090 SSL_NOT_EXP
|SSL_HIGH
,
1098 0, /* not implemented (non-ephemeral DH) */
1099 TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA
,
1100 TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA
,
1106 SSL_NOT_EXP
|SSL_HIGH
,
1114 0, /* not implemented (non-ephemeral DH) */
1115 TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA
,
1116 TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA
,
1122 SSL_NOT_EXP
|SSL_HIGH
,
1131 TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA
,
1132 TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA
,
1138 SSL_NOT_EXP
|SSL_HIGH
,
1147 TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
,
1148 TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
,
1154 SSL_NOT_EXP
|SSL_HIGH
,
1163 TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA
,
1164 TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA
,
1170 SSL_NOT_EXP
|SSL_HIGH
,
1175 #endif /* OPENSSL_NO_CAMELLIA */
1177 #if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES
1178 /* New TLS Export CipherSuites from expired ID */
1183 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5
,
1184 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5
,
1190 SSL_EXPORT
|SSL_EXP56
,
1199 TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5
,
1200 TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5
,
1206 SSL_EXPORT
|SSL_EXP56
,
1216 TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA
,
1217 TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA
,
1223 SSL_EXPORT
|SSL_EXP56
,
1232 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA
,
1233 TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA
,
1239 SSL_EXPORT
|SSL_EXP56
,
1248 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA
,
1249 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA
,
1255 SSL_EXPORT
|SSL_EXP56
,
1264 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA
,
1265 TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA
,
1271 SSL_EXPORT
|SSL_EXP56
,
1280 TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA
,
1281 TLS1_CK_DHE_DSS_WITH_RC4_128_SHA
,
1287 SSL_NOT_EXP
|SSL_MEDIUM
,
1294 #ifndef OPENSSL_NO_CAMELLIA
1295 /* Camellia ciphersuites from RFC4132 (256-bit portion) */
1300 TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1301 TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1307 SSL_NOT_EXP
|SSL_HIGH
,
1314 0, /* not implemented (non-ephemeral DH) */
1315 TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA
,
1316 TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA
,
1322 SSL_NOT_EXP
|SSL_HIGH
,
1330 0, /* not implemented (non-ephemeral DH) */
1331 TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1332 TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1338 SSL_NOT_EXP
|SSL_HIGH
,
1347 TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA
,
1348 TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA
,
1354 SSL_NOT_EXP
|SSL_HIGH
,
1363 TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1364 TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
,
1370 SSL_NOT_EXP
|SSL_HIGH
,
1379 TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA
,
1380 TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA
,
1386 SSL_NOT_EXP
|SSL_HIGH
,
1391 #endif /* OPENSSL_NO_CAMELLIA */
1393 #ifndef OPENSSL_NO_PSK
1397 TLS1_TXT_PSK_WITH_RC4_128_SHA
,
1398 TLS1_CK_PSK_WITH_RC4_128_SHA
,
1404 SSL_NOT_EXP
|SSL_MEDIUM
,
1413 TLS1_TXT_PSK_WITH_3DES_EDE_CBC_SHA
,
1414 TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA
,
1420 SSL_NOT_EXP
|SSL_HIGH
,
1429 TLS1_TXT_PSK_WITH_AES_128_CBC_SHA
,
1430 TLS1_CK_PSK_WITH_AES_128_CBC_SHA
,
1436 SSL_NOT_EXP
|SSL_HIGH
,
1445 TLS1_TXT_PSK_WITH_AES_256_CBC_SHA
,
1446 TLS1_CK_PSK_WITH_AES_256_CBC_SHA
,
1452 SSL_NOT_EXP
|SSL_HIGH
,
1457 #endif /* OPENSSL_NO_PSK */
1459 #ifndef OPENSSL_NO_ECDH
1463 TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA
,
1464 TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA
,
1479 TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA
,
1480 TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA
,
1495 TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA
,
1496 TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA
,
1502 SSL_NOT_EXP
|SSL_HIGH
,
1511 TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA
,
1512 TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA
,
1518 SSL_NOT_EXP
|SSL_HIGH
,
1527 TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA
,
1528 TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA
,
1534 SSL_NOT_EXP
|SSL_HIGH
,
1543 TLS1_TXT_ECDHE_ECDSA_WITH_NULL_SHA
,
1544 TLS1_CK_ECDHE_ECDSA_WITH_NULL_SHA
,
1559 TLS1_TXT_ECDHE_ECDSA_WITH_RC4_128_SHA
,
1560 TLS1_CK_ECDHE_ECDSA_WITH_RC4_128_SHA
,
1575 TLS1_TXT_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA
,
1576 TLS1_CK_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA
,
1582 SSL_NOT_EXP
|SSL_HIGH
,
1591 TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
,
1592 TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
,
1598 SSL_NOT_EXP
|SSL_HIGH
,
1607 TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
,
1608 TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
,
1614 SSL_NOT_EXP
|SSL_HIGH
,
1623 TLS1_TXT_ECDH_RSA_WITH_NULL_SHA
,
1624 TLS1_CK_ECDH_RSA_WITH_NULL_SHA
,
1639 TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA
,
1640 TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA
,
1655 TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA
,
1656 TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA
,
1662 SSL_NOT_EXP
|SSL_HIGH
,
1671 TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA
,
1672 TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA
,
1678 SSL_NOT_EXP
|SSL_HIGH
,
1687 TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA
,
1688 TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA
,
1694 SSL_NOT_EXP
|SSL_HIGH
,
1703 TLS1_TXT_ECDHE_RSA_WITH_NULL_SHA
,
1704 TLS1_CK_ECDHE_RSA_WITH_NULL_SHA
,
1719 TLS1_TXT_ECDHE_RSA_WITH_RC4_128_SHA
,
1720 TLS1_CK_ECDHE_RSA_WITH_RC4_128_SHA
,
1735 TLS1_TXT_ECDHE_RSA_WITH_DES_192_CBC3_SHA
,
1736 TLS1_CK_ECDHE_RSA_WITH_DES_192_CBC3_SHA
,
1742 SSL_NOT_EXP
|SSL_HIGH
,
1751 TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA
,
1752 TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA
,
1758 SSL_NOT_EXP
|SSL_HIGH
,
1767 TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA
,
1768 TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA
,
1774 SSL_NOT_EXP
|SSL_HIGH
,
1783 TLS1_TXT_ECDH_anon_WITH_NULL_SHA
,
1784 TLS1_CK_ECDH_anon_WITH_NULL_SHA
,
1799 TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA
,
1800 TLS1_CK_ECDH_anon_WITH_RC4_128_SHA
,
1815 TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA
,
1816 TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA
,
1822 SSL_NOT_EXP
|SSL_HIGH
,
1831 TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA
,
1832 TLS1_CK_ECDH_anon_WITH_AES_128_CBC_SHA
,
1838 SSL_NOT_EXP
|SSL_HIGH
,
1847 TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA
,
1848 TLS1_CK_ECDH_anon_WITH_AES_256_CBC_SHA
,
1854 SSL_NOT_EXP
|SSL_HIGH
,
1859 #endif /* OPENSSL_NO_ECDH */
1864 SSL3_ENC_METHOD SSLv3_enc_data
={
1867 ssl3_setup_key_block
,
1868 ssl3_generate_master_secret
,
1869 ssl3_change_cipher_state
,
1870 ssl3_final_finish_mac
,
1871 MD5_DIGEST_LENGTH
+SHA_DIGEST_LENGTH
,
1872 ssl3_cert_verify_mac
,
1873 SSL3_MD_CLIENT_FINISHED_CONST
,4,
1874 SSL3_MD_SERVER_FINISHED_CONST
,4,
1878 long ssl3_default_timeout(void)
1880 /* 2 hours, the 24 hours mentioned in the SSLv3 spec
1881 * is way too long for http, the cache would over fill */
1885 int ssl3_num_ciphers(void)
1887 return(SSL3_NUM_CIPHERS
);
1890 SSL_CIPHER
*ssl3_get_cipher(unsigned int u
)
1892 if (u
< SSL3_NUM_CIPHERS
)
1893 return(&(ssl3_ciphers
[SSL3_NUM_CIPHERS
-1-u
]));
1898 int ssl3_pending(const SSL
*s
)
1900 if (s
->rstate
== SSL_ST_READ_BODY
)
1903 return (s
->s3
->rrec
.type
== SSL3_RT_APPLICATION_DATA
) ? s
->s3
->rrec
.length
: 0;
1906 int ssl3_new(SSL
*s
)
1910 if ((s3
=OPENSSL_malloc(sizeof *s3
)) == NULL
) goto err
;
1911 memset(s3
,0,sizeof *s3
);
1912 EVP_MD_CTX_init(&s3
->finish_dgst1
);
1913 EVP_MD_CTX_init(&s3
->finish_dgst2
);
1914 memset(s3
->rrec
.seq_num
,0,sizeof(s3
->rrec
.seq_num
));
1915 memset(s3
->wrec
.seq_num
,0,sizeof(s3
->wrec
.seq_num
));
1919 s
->method
->ssl_clear(s
);
1925 void ssl3_free(SSL
*s
)
1930 ssl3_cleanup_key_block(s
);
1931 if (s
->s3
->rbuf
.buf
!= NULL
)
1932 OPENSSL_free(s
->s3
->rbuf
.buf
);
1933 if (s
->s3
->wbuf
.buf
!= NULL
)
1934 OPENSSL_free(s
->s3
->wbuf
.buf
);
1935 if (s
->s3
->rrec
.comp
!= NULL
)
1936 OPENSSL_free(s
->s3
->rrec
.comp
);
1937 #ifndef OPENSSL_NO_DH
1938 if (s
->s3
->tmp
.dh
!= NULL
)
1939 DH_free(s
->s3
->tmp
.dh
);
1941 #ifndef OPENSSL_NO_ECDH
1942 if (s
->s3
->tmp
.ecdh
!= NULL
)
1943 EC_KEY_free(s
->s3
->tmp
.ecdh
);
1946 if (s
->s3
->tmp
.ca_names
!= NULL
)
1947 sk_X509_NAME_pop_free(s
->s3
->tmp
.ca_names
,X509_NAME_free
);
1948 EVP_MD_CTX_cleanup(&s
->s3
->finish_dgst1
);
1949 EVP_MD_CTX_cleanup(&s
->s3
->finish_dgst2
);
1951 OPENSSL_cleanse(s
->s3
,sizeof *s
->s3
);
1952 OPENSSL_free(s
->s3
);
1956 void ssl3_clear(SSL
*s
)
1958 unsigned char *rp
,*wp
;
1961 ssl3_cleanup_key_block(s
);
1962 if (s
->s3
->tmp
.ca_names
!= NULL
)
1963 sk_X509_NAME_pop_free(s
->s3
->tmp
.ca_names
,X509_NAME_free
);
1965 if (s
->s3
->rrec
.comp
!= NULL
)
1967 OPENSSL_free(s
->s3
->rrec
.comp
);
1968 s
->s3
->rrec
.comp
=NULL
;
1970 #ifndef OPENSSL_NO_DH
1971 if (s
->s3
->tmp
.dh
!= NULL
)
1972 DH_free(s
->s3
->tmp
.dh
);
1974 #ifndef OPENSSL_NO_ECDH
1975 if (s
->s3
->tmp
.ecdh
!= NULL
)
1976 EC_KEY_free(s
->s3
->tmp
.ecdh
);
1979 rp
= s
->s3
->rbuf
.buf
;
1980 wp
= s
->s3
->wbuf
.buf
;
1981 rlen
= s
->s3
->rbuf
.len
;
1982 wlen
= s
->s3
->wbuf
.len
;
1984 EVP_MD_CTX_cleanup(&s
->s3
->finish_dgst1
);
1985 EVP_MD_CTX_cleanup(&s
->s3
->finish_dgst2
);
1987 memset(s
->s3
,0,sizeof *s
->s3
);
1988 s
->s3
->rbuf
.buf
= rp
;
1989 s
->s3
->wbuf
.buf
= wp
;
1990 s
->s3
->rbuf
.len
= rlen
;
1991 s
->s3
->wbuf
.len
= wlen
;
1993 ssl_free_wbio_buffer(s
);
1996 s
->s3
->renegotiate
=0;
1997 s
->s3
->total_renegotiations
=0;
1998 s
->s3
->num_renegotiations
=0;
1999 s
->s3
->in_read_app_data
=0;
2000 s
->version
=SSL3_VERSION
;
2003 long ssl3_ctrl(SSL
*s
, int cmd
, long larg
, void *parg
)
2007 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
2009 #ifndef OPENSSL_NO_RSA
2010 cmd
== SSL_CTRL_SET_TMP_RSA
||
2011 cmd
== SSL_CTRL_SET_TMP_RSA_CB
||
2013 #ifndef OPENSSL_NO_DSA
2014 cmd
== SSL_CTRL_SET_TMP_DH
||
2015 cmd
== SSL_CTRL_SET_TMP_DH_CB
||
2019 if (!ssl_cert_inst(&s
->cert
))
2021 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_MALLOC_FAILURE
);
2029 case SSL_CTRL_GET_SESSION_REUSED
:
2032 case SSL_CTRL_GET_CLIENT_CERT_REQUEST
:
2034 case SSL_CTRL_GET_NUM_RENEGOTIATIONS
:
2035 ret
=s
->s3
->num_renegotiations
;
2037 case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS
:
2038 ret
=s
->s3
->num_renegotiations
;
2039 s
->s3
->num_renegotiations
=0;
2041 case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS
:
2042 ret
=s
->s3
->total_renegotiations
;
2044 case SSL_CTRL_GET_FLAGS
:
2045 ret
=(int)(s
->s3
->flags
);
2047 #ifndef OPENSSL_NO_RSA
2048 case SSL_CTRL_NEED_TMP_RSA
:
2049 if ((s
->cert
!= NULL
) && (s
->cert
->rsa_tmp
== NULL
) &&
2050 ((s
->cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
== NULL
) ||
2051 (EVP_PKEY_size(s
->cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
) > (512/8))))
2054 case SSL_CTRL_SET_TMP_RSA
:
2056 RSA
*rsa
= (RSA
*)parg
;
2059 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_PASSED_NULL_PARAMETER
);
2062 if ((rsa
= RSAPrivateKey_dup(rsa
)) == NULL
)
2064 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_RSA_LIB
);
2067 if (s
->cert
->rsa_tmp
!= NULL
)
2068 RSA_free(s
->cert
->rsa_tmp
);
2069 s
->cert
->rsa_tmp
= rsa
;
2073 case SSL_CTRL_SET_TMP_RSA_CB
:
2075 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2080 #ifndef OPENSSL_NO_DH
2081 case SSL_CTRL_SET_TMP_DH
:
2083 DH
*dh
= (DH
*)parg
;
2086 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_PASSED_NULL_PARAMETER
);
2089 if ((dh
= DHparams_dup(dh
)) == NULL
)
2091 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_DH_LIB
);
2094 if (!(s
->options
& SSL_OP_SINGLE_DH_USE
))
2096 if (!DH_generate_key(dh
))
2099 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_DH_LIB
);
2103 if (s
->cert
->dh_tmp
!= NULL
)
2104 DH_free(s
->cert
->dh_tmp
);
2105 s
->cert
->dh_tmp
= dh
;
2109 case SSL_CTRL_SET_TMP_DH_CB
:
2111 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2116 #ifndef OPENSSL_NO_ECDH
2117 case SSL_CTRL_SET_TMP_ECDH
:
2119 EC_KEY
*ecdh
= NULL
;
2123 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_PASSED_NULL_PARAMETER
);
2126 if (!EC_KEY_up_ref((EC_KEY
*)parg
))
2128 SSLerr(SSL_F_SSL3_CTRL
,ERR_R_ECDH_LIB
);
2131 ecdh
= (EC_KEY
*)parg
;
2132 if (!(s
->options
& SSL_OP_SINGLE_ECDH_USE
))
2134 if (!EC_KEY_generate_key(ecdh
))
2137 SSLerr(SSL_F_SSL3_CTRL
,ERR_R_ECDH_LIB
);
2141 if (s
->cert
->ecdh_tmp
!= NULL
)
2142 EC_KEY_free(s
->cert
->ecdh_tmp
);
2143 s
->cert
->ecdh_tmp
= ecdh
;
2147 case SSL_CTRL_SET_TMP_ECDH_CB
:
2149 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2153 #endif /* !OPENSSL_NO_ECDH */
2154 #ifndef OPENSSL_NO_TLSEXT
2155 case SSL_CTRL_SET_TLSEXT_HOSTNAME
:
2156 if (larg
== TLSEXT_NAMETYPE_host_name
)
2158 if (s
->tlsext_hostname
!= NULL
)
2159 OPENSSL_free(s
->tlsext_hostname
);
2160 s
->tlsext_hostname
= NULL
;
2165 if (strlen((char *)parg
) > TLSEXT_MAXLEN_host_name
)
2167 SSLerr(SSL_F_SSL3_CTRL
, SSL_R_SSL3_EXT_INVALID_SERVERNAME
);
2170 if ((s
->tlsext_hostname
= BUF_strdup((char *)parg
)) == NULL
)
2172 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_INTERNAL_ERROR
);
2178 SSLerr(SSL_F_SSL3_CTRL
, SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE
);
2181 s
->options
|= SSL_OP_NO_SSLv2
; /* can't use extension w/ SSL 2.0 format */
2183 #endif /* !OPENSSL_NO_TLSEXT */
2190 long ssl3_callback_ctrl(SSL
*s
, int cmd
, void (*fp
)(void))
2194 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
2196 #ifndef OPENSSL_NO_RSA
2197 cmd
== SSL_CTRL_SET_TMP_RSA_CB
||
2199 #ifndef OPENSSL_NO_DSA
2200 cmd
== SSL_CTRL_SET_TMP_DH_CB
||
2204 if (!ssl_cert_inst(&s
->cert
))
2206 SSLerr(SSL_F_SSL3_CALLBACK_CTRL
, ERR_R_MALLOC_FAILURE
);
2214 #ifndef OPENSSL_NO_RSA
2215 case SSL_CTRL_SET_TMP_RSA_CB
:
2217 s
->cert
->rsa_tmp_cb
= (RSA
*(*)(SSL
*, int, int))fp
;
2221 #ifndef OPENSSL_NO_DH
2222 case SSL_CTRL_SET_TMP_DH_CB
:
2224 s
->cert
->dh_tmp_cb
= (DH
*(*)(SSL
*, int, int))fp
;
2228 #ifndef OPENSSL_NO_ECDH
2229 case SSL_CTRL_SET_TMP_ECDH_CB
:
2231 s
->cert
->ecdh_tmp_cb
= (EC_KEY
*(*)(SSL
*, int, int))fp
;
2241 long ssl3_ctx_ctrl(SSL_CTX
*ctx
, int cmd
, long larg
, void *parg
)
2249 #ifndef OPENSSL_NO_RSA
2250 case SSL_CTRL_NEED_TMP_RSA
:
2251 if ( (cert
->rsa_tmp
== NULL
) &&
2252 ((cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
== NULL
) ||
2253 (EVP_PKEY_size(cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
) > (512/8)))
2259 case SSL_CTRL_SET_TMP_RSA
:
2270 if ((rsa
=RSAPrivateKey_dup(rsa
)) == NULL
)
2275 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_RSA_LIB
);
2280 if (cert
->rsa_tmp
!= NULL
)
2281 RSA_free(cert
->rsa_tmp
);
2287 case SSL_CTRL_SET_TMP_RSA_CB
:
2289 SSLerr(SSL_F_SSL3_CTX_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2294 #ifndef OPENSSL_NO_DH
2295 case SSL_CTRL_SET_TMP_DH
:
2300 if ((new=DHparams_dup(dh
)) == NULL
)
2302 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_DH_LIB
);
2305 if (!(ctx
->options
& SSL_OP_SINGLE_DH_USE
))
2307 if (!DH_generate_key(new))
2309 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_DH_LIB
);
2314 if (cert
->dh_tmp
!= NULL
)
2315 DH_free(cert
->dh_tmp
);
2320 case SSL_CTRL_SET_TMP_DH_CB
:
2322 SSLerr(SSL_F_SSL3_CTX_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2327 #ifndef OPENSSL_NO_ECDH
2328 case SSL_CTRL_SET_TMP_ECDH
:
2330 EC_KEY
*ecdh
= NULL
;
2334 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_ECDH_LIB
);
2337 ecdh
= EC_KEY_dup((EC_KEY
*)parg
);
2340 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_EC_LIB
);
2343 if (!(ctx
->options
& SSL_OP_SINGLE_ECDH_USE
))
2345 if (!EC_KEY_generate_key(ecdh
))
2348 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_ECDH_LIB
);
2353 if (cert
->ecdh_tmp
!= NULL
)
2355 EC_KEY_free(cert
->ecdh_tmp
);
2357 cert
->ecdh_tmp
= ecdh
;
2361 case SSL_CTRL_SET_TMP_ECDH_CB
:
2363 SSLerr(SSL_F_SSL3_CTX_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
2367 #endif /* !OPENSSL_NO_ECDH */
2368 #ifndef OPENSSL_NO_TLSEXT
2369 case SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG
:
2370 ctx
->tlsext_servername_arg
=parg
;
2372 #endif /* !OPENSSL_NO_TLSEXT */
2373 /* A Thawte special :-) */
2374 case SSL_CTRL_EXTRA_CHAIN_CERT
:
2375 if (ctx
->extra_certs
== NULL
)
2377 if ((ctx
->extra_certs
=sk_X509_new_null()) == NULL
)
2380 sk_X509_push(ctx
->extra_certs
,(X509
*)parg
);
2389 long ssl3_ctx_callback_ctrl(SSL_CTX
*ctx
, int cmd
, void (*fp
)(void))
2397 #ifndef OPENSSL_NO_RSA
2398 case SSL_CTRL_SET_TMP_RSA_CB
:
2400 cert
->rsa_tmp_cb
= (RSA
*(*)(SSL
*, int, int))fp
;
2404 #ifndef OPENSSL_NO_DH
2405 case SSL_CTRL_SET_TMP_DH_CB
:
2407 cert
->dh_tmp_cb
= (DH
*(*)(SSL
*, int, int))fp
;
2411 #ifndef OPENSSL_NO_ECDH
2412 case SSL_CTRL_SET_TMP_ECDH_CB
:
2414 cert
->ecdh_tmp_cb
= (EC_KEY
*(*)(SSL
*, int, int))fp
;
2418 #ifndef OPENSSL_NO_TLSEXT
2419 case SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
:
2420 ctx
->tlsext_servername_callback
=(int (*)(SSL
*,int *,void *))fp
;
2429 /* This function needs to check if the ciphers required are actually
2431 SSL_CIPHER
*ssl3_get_cipher_by_char(const unsigned char *p
)
2436 id
=0x03000000L
|((unsigned long)p
[0]<<8L)|(unsigned long)p
[1];
2438 cp
= (SSL_CIPHER
*)OBJ_bsearch((char *)&c
,
2439 (char *)ssl3_ciphers
,
2440 SSL3_NUM_CIPHERS
,sizeof(SSL_CIPHER
),
2441 FP_ICC ssl_cipher_id_cmp
);
2442 if (cp
== NULL
|| cp
->valid
== 0)
2448 int ssl3_put_cipher_by_char(const SSL_CIPHER
*c
, unsigned char *p
)
2455 if ((l
& 0xff000000) != 0x03000000) return(0);
2456 p
[0]=((unsigned char)(l
>> 8L))&0xFF;
2457 p
[1]=((unsigned char)(l
))&0xFF;
2462 SSL_CIPHER
*ssl3_choose_cipher(SSL
*s
, STACK_OF(SSL_CIPHER
) *clnt
,
2463 STACK_OF(SSL_CIPHER
) *srvr
)
2465 SSL_CIPHER
*c
,*ret
=NULL
;
2466 STACK_OF(SSL_CIPHER
) *prio
, *allow
;
2469 #ifndef OPENSSL_NO_TLSEXT
2470 #ifndef OPENSSL_NO_EC
2472 unsigned char ec_search1
= 0, ec_search2
= 0;
2473 #endif /* OPENSSL_NO_EC */
2474 #endif /* OPENSSL_NO_TLSEXT */
2476 unsigned long alg_k
,alg_a
,mask_k
,mask_a
,emask_k
,emask_a
;
2478 /* Let's see which ciphers we can support */
2482 /* Do not set the compare functions, because this may lead to a
2483 * reordering by "id". We want to keep the original ordering.
2484 * We may pay a price in performance during sk_SSL_CIPHER_find(),
2485 * but would have to pay with the price of sk_SSL_CIPHER_dup().
2487 sk_SSL_CIPHER_set_cmp_func(srvr
, ssl_cipher_ptr_id_cmp
);
2488 sk_SSL_CIPHER_set_cmp_func(clnt
, ssl_cipher_ptr_id_cmp
);
2492 printf("Server has %d from %p:\n", sk_SSL_CIPHER_num(srvr
), srvr
);
2493 for(i
=0 ; i
< sk_SSL_CIPHER_num(srvr
) ; ++i
)
2495 c
=sk_SSL_CIPHER_value(srvr
,i
);
2496 printf("%p:%s\n",c
,c
->name
);
2498 printf("Client sent %d from %p:\n", sk_SSL_CIPHER_num(clnt
), clnt
);
2499 for(i
=0 ; i
< sk_SSL_CIPHER_num(clnt
) ; ++i
)
2501 c
=sk_SSL_CIPHER_value(clnt
,i
);
2502 printf("%p:%s\n",c
,c
->name
);
2506 if (s
->options
& SSL_OP_CIPHER_SERVER_PREFERENCE
)
2517 for (i
=0; i
<sk_SSL_CIPHER_num(prio
); i
++)
2519 c
=sk_SSL_CIPHER_value(prio
,i
);
2521 ssl_set_cert_masks(cert
,c
);
2522 mask_k
= cert
->mask_k
;
2523 mask_a
= cert
->mask_a
;
2524 emask_k
= cert
->export_mask_k
;
2525 emask_a
= cert
->export_mask_a
;
2528 printf("ssl3_choose_cipher %d alg= %lx\n", i
,c
->algorithms
);
2529 #endif /* KSSL_DEBUG */
2531 alg_k
=c
->algorithm_mkey
;
2532 alg_a
=c
->algorithm_auth
;
2534 #ifndef OPENSSL_NO_KRB5
2535 if (alg_k
& SSL_kKRB5
)
2537 if ( !kssl_keytab_is_available(s
->kssl_ctx
) )
2540 #endif /* OPENSSL_NO_KRB5 */
2541 #ifndef OPENSSL_NO_PSK
2542 /* with PSK there must be server callback set */
2543 if ((alg_k
& SSL_kPSK
) && s
->psk_server_callback
== NULL
)
2545 #endif /* OPENSSL_NO_PSK */
2547 if (SSL_C_IS_EXPORT(c
))
2549 ok
= (alg_k
& emask_k
) && (alg_a
& emask_a
);
2551 printf("%d:[%08lX:%08lX:%08lX:%08lX]%p:%s (export)\n",ok
,alg_k
,alg_a
,emask_k
,emask_a
,
2557 ok
= (alg_k
& mask_k
) && (alg_a
& mask_a
);
2559 printf("%d:[%08lX:%08lX:%08lX:%08lX]%p:%s\n",ok
,alg_k
,alg_a
,mask_k
,mask_a
,c
,
2564 #ifndef OPENSSL_NO_TLSEXT
2565 #ifndef OPENSSL_NO_EC
2567 /* if we are considering an ECC cipher suite that uses our certificate */
2568 (alg_a
& SSL_aECDSA
|| alg_a
& SSL_aECDH
)
2569 /* and we have an ECC certificate */
2570 && (s
->cert
->pkeys
[SSL_PKEY_ECC
].x509
!= NULL
)
2571 /* and the client specified a Supported Point Formats extension */
2572 && ((s
->session
->tlsext_ecpointformatlist_length
> 0) && (s
->session
->tlsext_ecpointformatlist
!= NULL
))
2573 /* and our certificate's point is compressed */
2575 (s
->cert
->pkeys
[SSL_PKEY_ECC
].x509
->cert_info
!= NULL
)
2576 && (s
->cert
->pkeys
[SSL_PKEY_ECC
].x509
->cert_info
->key
!= NULL
)
2577 && (s
->cert
->pkeys
[SSL_PKEY_ECC
].x509
->cert_info
->key
->public_key
!= NULL
)
2578 && (s
->cert
->pkeys
[SSL_PKEY_ECC
].x509
->cert_info
->key
->public_key
->data
!= NULL
)
2580 (*(s
->cert
->pkeys
[SSL_PKEY_ECC
].x509
->cert_info
->key
->public_key
->data
) == POINT_CONVERSION_COMPRESSED
)
2581 || (*(s
->cert
->pkeys
[SSL_PKEY_ECC
].x509
->cert_info
->key
->public_key
->data
) == POINT_CONVERSION_COMPRESSED
+ 1)
2587 /* if our certificate's curve is over a field type that the client does not support
2588 * then do not allow this cipher suite to be negotiated */
2590 (s
->cert
->pkeys
[SSL_PKEY_ECC
].privatekey
->pkey
.ec
!= NULL
)
2591 && (s
->cert
->pkeys
[SSL_PKEY_ECC
].privatekey
->pkey
.ec
->group
!= NULL
)
2592 && (s
->cert
->pkeys
[SSL_PKEY_ECC
].privatekey
->pkey
.ec
->group
->meth
!= NULL
)
2593 && (EC_METHOD_get_field_type(s
->cert
->pkeys
[SSL_PKEY_ECC
].privatekey
->pkey
.ec
->group
->meth
) == NID_X9_62_prime_field
)
2596 for (j
= 0; j
< s
->session
->tlsext_ecpointformatlist_length
; j
++)
2598 if (s
->session
->tlsext_ecpointformatlist
[j
] == TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime
)
2605 else if (EC_METHOD_get_field_type(s
->cert
->pkeys
[SSL_PKEY_ECC
].privatekey
->pkey
.ec
->group
->meth
) == NID_X9_62_characteristic_two_field
)
2607 for (j
= 0; j
< s
->session
->tlsext_ecpointformatlist_length
; j
++)
2609 if (s
->session
->tlsext_ecpointformatlist
[j
] == TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2
)
2619 /* if we are considering an ECC cipher suite that uses our certificate */
2620 (alg_a
& SSL_aECDSA
|| alg_a
& SSL_aECDH
)
2621 /* and we have an ECC certificate */
2622 && (s
->cert
->pkeys
[SSL_PKEY_ECC
].x509
!= NULL
)
2623 /* and the client specified an EllipticCurves extension */
2624 && ((s
->session
->tlsext_ellipticcurvelist_length
> 0) && (s
->session
->tlsext_ellipticcurvelist
!= NULL
))
2629 (s
->cert
->pkeys
[SSL_PKEY_ECC
].privatekey
->pkey
.ec
!= NULL
)
2630 && (s
->cert
->pkeys
[SSL_PKEY_ECC
].privatekey
->pkey
.ec
->group
!= NULL
)
2633 ec_nid
= EC_GROUP_get_curve_name(s
->cert
->pkeys
[SSL_PKEY_ECC
].privatekey
->pkey
.ec
->group
);
2635 && (s
->cert
->pkeys
[SSL_PKEY_ECC
].privatekey
->pkey
.ec
->group
->meth
!= NULL
)
2638 if (EC_METHOD_get_field_type(s
->cert
->pkeys
[SSL_PKEY_ECC
].privatekey
->pkey
.ec
->group
->meth
) == NID_X9_62_prime_field
)
2643 else if (EC_METHOD_get_field_type(s
->cert
->pkeys
[SSL_PKEY_ECC
].privatekey
->pkey
.ec
->group
->meth
) == NID_X9_62_characteristic_two_field
)
2652 ec_search2
= tls1_ec_nid2curve_id(ec_nid
);
2654 if ((ec_search1
!= 0) || (ec_search2
!= 0))
2656 for (j
= 0; j
< s
->session
->tlsext_ellipticcurvelist_length
/ 2; j
++)
2658 if ((s
->session
->tlsext_ellipticcurvelist
[2*j
] == ec_search1
) && (s
->session
->tlsext_ellipticcurvelist
[2*j
+1] == ec_search2
))
2669 /* if we are considering an ECC cipher suite that uses an ephemeral EC key */
2670 (alg_k
& SSL_kEECDH
)
2671 /* and we have an ephemeral EC key */
2672 && (s
->cert
->ecdh_tmp
!= NULL
)
2673 /* and the client specified an EllipticCurves extension */
2674 && ((s
->session
->tlsext_ellipticcurvelist_length
> 0) && (s
->session
->tlsext_ellipticcurvelist
!= NULL
))
2678 if (s
->cert
->ecdh_tmp
->group
!= NULL
)
2680 ec_nid
= EC_GROUP_get_curve_name(s
->cert
->ecdh_tmp
->group
);
2682 && (s
->cert
->ecdh_tmp
->group
->meth
!= NULL
)
2685 if (EC_METHOD_get_field_type(s
->cert
->ecdh_tmp
->group
->meth
) == NID_X9_62_prime_field
)
2690 else if (EC_METHOD_get_field_type(s
->cert
->ecdh_tmp
->group
->meth
) == NID_X9_62_characteristic_two_field
)
2699 ec_search2
= tls1_ec_nid2curve_id(ec_nid
);
2701 if ((ec_search1
!= 0) || (ec_search2
!= 0))
2703 for (j
= 0; j
< s
->session
->tlsext_ellipticcurvelist_length
/ 2; j
++)
2705 if ((s
->session
->tlsext_ellipticcurvelist
[2*j
] == ec_search1
) && (s
->session
->tlsext_ellipticcurvelist
[2*j
+1] == ec_search2
))
2715 #endif /* OPENSSL_NO_EC */
2716 #endif /* OPENSSL_NO_TLSEXT */
2719 ii
=sk_SSL_CIPHER_find(allow
,c
);
2722 ret
=sk_SSL_CIPHER_value(allow
,ii
);
2729 int ssl3_get_req_cert_type(SSL
*s
, unsigned char *p
)
2732 unsigned long alg_k
;
2734 alg_k
= s
->s3
->tmp
.new_cipher
->algorithm_mkey
;
2736 #ifndef OPENSSL_NO_DH
2737 if (alg_k
& (SSL_kDHr
|SSL_kEDH
))
2739 # ifndef OPENSSL_NO_RSA
2740 p
[ret
++]=SSL3_CT_RSA_FIXED_DH
;
2742 # ifndef OPENSSL_NO_DSA
2743 p
[ret
++]=SSL3_CT_DSS_FIXED_DH
;
2746 if ((s
->version
== SSL3_VERSION
) &&
2747 (alg_k
& (SSL_kEDH
|SSL_kDHd
|SSL_kDHr
)))
2749 # ifndef OPENSSL_NO_RSA
2750 p
[ret
++]=SSL3_CT_RSA_EPHEMERAL_DH
;
2752 # ifndef OPENSSL_NO_DSA
2753 p
[ret
++]=SSL3_CT_DSS_EPHEMERAL_DH
;
2756 #endif /* !OPENSSL_NO_DH */
2757 #ifndef OPENSSL_NO_RSA
2758 p
[ret
++]=SSL3_CT_RSA_SIGN
;
2760 #ifndef OPENSSL_NO_DSA
2761 p
[ret
++]=SSL3_CT_DSS_SIGN
;
2763 #ifndef OPENSSL_NO_ECDH
2764 if ((alg_k
& (SSL_kECDHr
|SSL_kECDHe
)) && (s
->version
>= TLS1_VERSION
))
2766 p
[ret
++]=TLS_CT_RSA_FIXED_ECDH
;
2767 p
[ret
++]=TLS_CT_ECDSA_FIXED_ECDH
;
2771 #ifndef OPENSSL_NO_ECDSA
2772 /* ECDSA certs can be used with RSA cipher suites as well
2773 * so we don't need to check for SSL_kECDH or SSL_kEECDH
2775 if (s
->version
>= TLS1_VERSION
)
2777 p
[ret
++]=TLS_CT_ECDSA_SIGN
;
2783 int ssl3_shutdown(SSL
*s
)
2786 /* Don't do anything much if we have not done the handshake or
2787 * we don't want to send messages :-) */
2788 if ((s
->quiet_shutdown
) || (s
->state
== SSL_ST_BEFORE
))
2790 s
->shutdown
=(SSL_SENT_SHUTDOWN
|SSL_RECEIVED_SHUTDOWN
);
2794 if (!(s
->shutdown
& SSL_SENT_SHUTDOWN
))
2796 s
->shutdown
|=SSL_SENT_SHUTDOWN
;
2798 ssl3_send_alert(s
,SSL3_AL_WARNING
,SSL_AD_CLOSE_NOTIFY
);
2800 /* our shutdown alert has been sent now, and if it still needs
2801 * to be written, s->s3->alert_dispatch will be true */
2803 else if (s
->s3
->alert_dispatch
)
2805 /* resend it if not sent */
2807 s
->method
->ssl_dispatch_alert(s
);
2810 else if (!(s
->shutdown
& SSL_RECEIVED_SHUTDOWN
))
2812 /* If we are waiting for a close from our peer, we are closed */
2813 s
->method
->ssl_read_bytes(s
,0,NULL
,0,0);
2816 if ((s
->shutdown
== (SSL_SENT_SHUTDOWN
|SSL_RECEIVED_SHUTDOWN
)) &&
2817 !s
->s3
->alert_dispatch
)
2823 int ssl3_write(SSL
*s
, const void *buf
, int len
)
2828 if (s
->shutdown
& SSL_SEND_SHUTDOWN
)
2830 s
->rwstate
=SSL_NOTHING
;
2835 if (s
->s3
->renegotiate
) ssl3_renegotiate_check(s
);
2837 /* This is an experimental flag that sends the
2838 * last handshake message in the same packet as the first
2839 * use data - used to see if it helps the TCP protocol during
2840 * session-id reuse */
2841 /* The second test is because the buffer may have been removed */
2842 if ((s
->s3
->flags
& SSL3_FLAGS_POP_BUFFER
) && (s
->wbio
== s
->bbio
))
2844 /* First time through, we write into the buffer */
2845 if (s
->s3
->delay_buf_pop_ret
== 0)
2847 ret
=ssl3_write_bytes(s
,SSL3_RT_APPLICATION_DATA
,
2849 if (ret
<= 0) return(ret
);
2851 s
->s3
->delay_buf_pop_ret
=ret
;
2854 s
->rwstate
=SSL_WRITING
;
2855 n
=BIO_flush(s
->wbio
);
2856 if (n
<= 0) return(n
);
2857 s
->rwstate
=SSL_NOTHING
;
2859 /* We have flushed the buffer, so remove it */
2860 ssl_free_wbio_buffer(s
);
2861 s
->s3
->flags
&= ~SSL3_FLAGS_POP_BUFFER
;
2863 ret
=s
->s3
->delay_buf_pop_ret
;
2864 s
->s3
->delay_buf_pop_ret
=0;
2868 ret
=s
->method
->ssl_write_bytes(s
,SSL3_RT_APPLICATION_DATA
,
2870 if (ret
<= 0) return(ret
);
2876 static int ssl3_read_internal(SSL
*s
, void *buf
, int len
, int peek
)
2881 if (s
->s3
->renegotiate
) ssl3_renegotiate_check(s
);
2882 s
->s3
->in_read_app_data
=1;
2883 ret
=s
->method
->ssl_read_bytes(s
,SSL3_RT_APPLICATION_DATA
,buf
,len
,peek
);
2884 if ((ret
== -1) && (s
->s3
->in_read_app_data
== 2))
2886 /* ssl3_read_bytes decided to call s->handshake_func, which
2887 * called ssl3_read_bytes to read handshake data.
2888 * However, ssl3_read_bytes actually found application data
2889 * and thinks that application data makes sense here; so disable
2890 * handshake processing and try to read application data again. */
2892 ret
=s
->method
->ssl_read_bytes(s
,SSL3_RT_APPLICATION_DATA
,buf
,len
,peek
);
2896 s
->s3
->in_read_app_data
=0;
2901 int ssl3_read(SSL
*s
, void *buf
, int len
)
2903 return ssl3_read_internal(s
, buf
, len
, 0);
2906 int ssl3_peek(SSL
*s
, void *buf
, int len
)
2908 return ssl3_read_internal(s
, buf
, len
, 1);
2911 int ssl3_renegotiate(SSL
*s
)
2913 if (s
->handshake_func
== NULL
)
2916 if (s
->s3
->flags
& SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS
)
2919 s
->s3
->renegotiate
=1;
2923 int ssl3_renegotiate_check(SSL
*s
)
2927 if (s
->s3
->renegotiate
)
2929 if ( (s
->s3
->rbuf
.left
== 0) &&
2930 (s
->s3
->wbuf
.left
== 0) &&
2934 if we are the server, and we have sent a 'RENEGOTIATE' message, we
2935 need to go to SSL_ST_ACCEPT.
2938 s
->state
=SSL_ST_RENEGOTIATE
;
2939 s
->s3
->renegotiate
=0;
2940 s
->s3
->num_renegotiations
++;
2941 s
->s3
->total_renegotiations
++;