2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
58 /* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
87 * 6. Redistributions of any form whatsoever must retain the following
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
113 #include <openssl/objects.h>
114 #include "ssl_locl.h"
116 const char *ssl3_version_str
="SSLv3" OPENSSL_VERSION_PTEXT
;
118 #define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
120 static long ssl3_default_timeout(void );
122 OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers
[]={
123 /* The RSA ciphers */
127 SSL3_TXT_RSA_NULL_MD5
,
128 SSL3_CK_RSA_NULL_MD5
,
129 SSL_kRSA
|SSL_aRSA
|SSL_eNULL
|SSL_MD5
|SSL_SSLV3
,
140 SSL3_TXT_RSA_NULL_SHA
,
141 SSL3_CK_RSA_NULL_SHA
,
142 SSL_kRSA
|SSL_aRSA
|SSL_eNULL
|SSL_SHA1
|SSL_SSLV3
,
155 SSL3_TXT_ADH_RC4_40_MD5
,
156 SSL3_CK_ADH_RC4_40_MD5
,
157 SSL_kEDH
|SSL_aNULL
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
158 SSL_EXPORT
|SSL_EXP40
,
168 SSL3_TXT_ADH_RC4_128_MD5
,
169 SSL3_CK_ADH_RC4_128_MD5
,
170 SSL_kEDH
|SSL_aNULL
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
181 SSL3_TXT_ADH_DES_40_CBC_SHA
,
182 SSL3_CK_ADH_DES_40_CBC_SHA
,
183 SSL_kEDH
|SSL_aNULL
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
184 SSL_EXPORT
|SSL_EXP40
,
194 SSL3_TXT_ADH_DES_64_CBC_SHA
,
195 SSL3_CK_ADH_DES_64_CBC_SHA
,
196 SSL_kEDH
|SSL_aNULL
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
207 SSL3_TXT_ADH_DES_192_CBC_SHA
,
208 SSL3_CK_ADH_DES_192_CBC_SHA
,
209 SSL_kEDH
|SSL_aNULL
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
222 SSL3_TXT_RSA_RC4_40_MD5
,
223 SSL3_CK_RSA_RC4_40_MD5
,
224 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
225 SSL_EXPORT
|SSL_EXP40
,
235 SSL3_TXT_RSA_RC4_128_MD5
,
236 SSL3_CK_RSA_RC4_128_MD5
,
237 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_MD5
|SSL_SSLV3
,
238 SSL_NOT_EXP
|SSL_MEDIUM
,
248 SSL3_TXT_RSA_RC4_128_SHA
,
249 SSL3_CK_RSA_RC4_128_SHA
,
250 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_SHA1
|SSL_SSLV3
,
251 SSL_NOT_EXP
|SSL_MEDIUM
,
261 SSL3_TXT_RSA_RC2_40_MD5
,
262 SSL3_CK_RSA_RC2_40_MD5
,
263 SSL_kRSA
|SSL_aRSA
|SSL_RC2
|SSL_MD5
|SSL_SSLV3
,
264 SSL_EXPORT
|SSL_EXP40
,
274 SSL3_TXT_RSA_IDEA_128_SHA
,
275 SSL3_CK_RSA_IDEA_128_SHA
,
276 SSL_kRSA
|SSL_aRSA
|SSL_IDEA
|SSL_SHA1
|SSL_SSLV3
,
277 SSL_NOT_EXP
|SSL_MEDIUM
,
287 SSL3_TXT_RSA_DES_40_CBC_SHA
,
288 SSL3_CK_RSA_DES_40_CBC_SHA
,
289 SSL_kRSA
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
290 SSL_EXPORT
|SSL_EXP40
,
300 SSL3_TXT_RSA_DES_64_CBC_SHA
,
301 SSL3_CK_RSA_DES_64_CBC_SHA
,
302 SSL_kRSA
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
313 SSL3_TXT_RSA_DES_192_CBC3_SHA
,
314 SSL3_CK_RSA_DES_192_CBC3_SHA
,
315 SSL_kRSA
|SSL_aRSA
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
316 SSL_NOT_EXP
|SSL_HIGH
,
328 SSL3_TXT_DH_DSS_DES_40_CBC_SHA
,
329 SSL3_CK_DH_DSS_DES_40_CBC_SHA
,
330 SSL_kDHd
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
331 SSL_EXPORT
|SSL_EXP40
,
341 SSL3_TXT_DH_DSS_DES_64_CBC_SHA
,
342 SSL3_CK_DH_DSS_DES_64_CBC_SHA
,
343 SSL_kDHd
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
354 SSL3_TXT_DH_DSS_DES_192_CBC3_SHA
,
355 SSL3_CK_DH_DSS_DES_192_CBC3_SHA
,
356 SSL_kDHd
|SSL_aDH
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
357 SSL_NOT_EXP
|SSL_HIGH
,
367 SSL3_TXT_DH_RSA_DES_40_CBC_SHA
,
368 SSL3_CK_DH_RSA_DES_40_CBC_SHA
,
369 SSL_kDHr
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
370 SSL_EXPORT
|SSL_EXP40
,
380 SSL3_TXT_DH_RSA_DES_64_CBC_SHA
,
381 SSL3_CK_DH_RSA_DES_64_CBC_SHA
,
382 SSL_kDHr
|SSL_aDH
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
393 SSL3_TXT_DH_RSA_DES_192_CBC3_SHA
,
394 SSL3_CK_DH_RSA_DES_192_CBC3_SHA
,
395 SSL_kDHr
|SSL_aDH
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
396 SSL_NOT_EXP
|SSL_HIGH
,
404 /* The Ephemeral DH ciphers */
408 SSL3_TXT_EDH_DSS_DES_40_CBC_SHA
,
409 SSL3_CK_EDH_DSS_DES_40_CBC_SHA
,
410 SSL_kEDH
|SSL_aDSS
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
411 SSL_EXPORT
|SSL_EXP40
,
421 SSL3_TXT_EDH_DSS_DES_64_CBC_SHA
,
422 SSL3_CK_EDH_DSS_DES_64_CBC_SHA
,
423 SSL_kEDH
|SSL_aDSS
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
434 SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA
,
435 SSL3_CK_EDH_DSS_DES_192_CBC3_SHA
,
436 SSL_kEDH
|SSL_aDSS
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
437 SSL_NOT_EXP
|SSL_HIGH
,
447 SSL3_TXT_EDH_RSA_DES_40_CBC_SHA
,
448 SSL3_CK_EDH_RSA_DES_40_CBC_SHA
,
449 SSL_kEDH
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
450 SSL_EXPORT
|SSL_EXP40
,
460 SSL3_TXT_EDH_RSA_DES_64_CBC_SHA
,
461 SSL3_CK_EDH_RSA_DES_64_CBC_SHA
,
462 SSL_kEDH
|SSL_aRSA
|SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
473 SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA
,
474 SSL3_CK_EDH_RSA_DES_192_CBC3_SHA
,
475 SSL_kEDH
|SSL_aRSA
|SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
476 SSL_NOT_EXP
|SSL_HIGH
,
488 SSL3_TXT_FZA_DMS_NULL_SHA
,
489 SSL3_CK_FZA_DMS_NULL_SHA
,
490 SSL_kFZA
|SSL_aFZA
|SSL_eNULL
|SSL_SHA1
|SSL_SSLV3
,
502 SSL3_TXT_FZA_DMS_FZA_SHA
,
503 SSL3_CK_FZA_DMS_FZA_SHA
,
504 SSL_kFZA
|SSL_aFZA
|SSL_eFZA
|SSL_SHA1
|SSL_SSLV3
,
516 SSL3_TXT_FZA_DMS_RC4_SHA
,
517 SSL3_CK_FZA_DMS_RC4_SHA
,
518 SSL_kFZA
|SSL_aFZA
|SSL_RC4
|SSL_SHA1
|SSL_SSLV3
,
527 #ifndef OPENSSL_NO_KRB5
528 /* The Kerberos ciphers
529 ** 20000107 VRS: And the first shall be last,
530 ** in hopes of avoiding the lynx ssl renegotiation problem.
535 SSL3_TXT_KRB5_DES_40_CBC_SHA
,
536 SSL3_CK_KRB5_DES_40_CBC_SHA
,
537 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
538 SSL_EXPORT
|SSL_EXP40
,
549 SSL3_TXT_KRB5_DES_40_CBC_MD5
,
550 SSL3_CK_KRB5_DES_40_CBC_MD5
,
551 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_MD5
|SSL_SSLV3
,
552 SSL_EXPORT
|SSL_EXP40
,
563 SSL3_TXT_KRB5_DES_64_CBC_SHA
,
564 SSL3_CK_KRB5_DES_64_CBC_SHA
,
565 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_SHA1
|SSL_SSLV3
,
577 SSL3_TXT_KRB5_DES_64_CBC_MD5
,
578 SSL3_CK_KRB5_DES_64_CBC_MD5
,
579 SSL_kKRB5
|SSL_aKRB5
| SSL_DES
|SSL_MD5
|SSL_SSLV3
,
591 SSL3_TXT_KRB5_DES_192_CBC3_SHA
,
592 SSL3_CK_KRB5_DES_192_CBC3_SHA
,
593 SSL_kKRB5
|SSL_aKRB5
| SSL_3DES
|SSL_SHA1
|SSL_SSLV3
,
594 SSL_NOT_EXP
|SSL_HIGH
,
605 SSL3_TXT_KRB5_DES_192_CBC3_MD5
,
606 SSL3_CK_KRB5_DES_192_CBC3_MD5
,
607 SSL_kKRB5
|SSL_aKRB5
| SSL_3DES
|SSL_MD5
|SSL_SSLV3
,
608 SSL_NOT_EXP
|SSL_HIGH
,
615 #endif /* OPENSSL_NO_KRB5 */
618 #if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES
619 /* New TLS Export CipherSuites */
623 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5
,
624 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5
,
625 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_MD5
|SSL_TLSV1
,
626 SSL_EXPORT
|SSL_EXP56
,
636 TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5
,
637 TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5
,
638 SSL_kRSA
|SSL_aRSA
|SSL_RC2
|SSL_MD5
|SSL_TLSV1
,
639 SSL_EXPORT
|SSL_EXP56
,
649 TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA
,
650 TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA
,
651 SSL_kRSA
|SSL_aRSA
|SSL_DES
|SSL_SHA
|SSL_TLSV1
,
652 SSL_EXPORT
|SSL_EXP56
,
662 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA
,
663 TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA
,
664 SSL_kEDH
|SSL_aDSS
|SSL_DES
|SSL_SHA
|SSL_TLSV1
,
665 SSL_EXPORT
|SSL_EXP56
,
675 TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA
,
676 TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA
,
677 SSL_kRSA
|SSL_aRSA
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
678 SSL_EXPORT
|SSL_EXP56
,
688 TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA
,
689 TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA
,
690 SSL_kEDH
|SSL_aDSS
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
691 SSL_EXPORT
|SSL_EXP56
,
701 TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA
,
702 TLS1_CK_DHE_DSS_WITH_RC4_128_SHA
,
703 SSL_kEDH
|SSL_aDSS
|SSL_RC4
|SSL_SHA
|SSL_TLSV1
,
712 /* New AES ciphersuites */
717 TLS1_TXT_RSA_WITH_AES_128_SHA
,
718 TLS1_CK_RSA_WITH_AES_128_SHA
,
719 SSL_kRSA
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
720 SSL_NOT_EXP
|SSL_MEDIUM
,
730 TLS1_TXT_DH_DSS_WITH_AES_128_SHA
,
731 TLS1_CK_DH_DSS_WITH_AES_128_SHA
,
732 SSL_kDHd
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
733 SSL_NOT_EXP
|SSL_MEDIUM
,
743 TLS1_TXT_DH_RSA_WITH_AES_128_SHA
,
744 TLS1_CK_DH_RSA_WITH_AES_128_SHA
,
745 SSL_kDHr
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
746 SSL_NOT_EXP
|SSL_MEDIUM
,
756 TLS1_TXT_DHE_DSS_WITH_AES_128_SHA
,
757 TLS1_CK_DHE_DSS_WITH_AES_128_SHA
,
758 SSL_kEDH
|SSL_aDSS
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
759 SSL_NOT_EXP
|SSL_MEDIUM
,
769 TLS1_TXT_DHE_RSA_WITH_AES_128_SHA
,
770 TLS1_CK_DHE_RSA_WITH_AES_128_SHA
,
771 SSL_kEDH
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
772 SSL_NOT_EXP
|SSL_MEDIUM
,
782 TLS1_TXT_ADH_WITH_AES_128_SHA
,
783 TLS1_CK_ADH_WITH_AES_128_SHA
,
784 SSL_kEDH
|SSL_aNULL
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
785 SSL_NOT_EXP
|SSL_MEDIUM
,
796 TLS1_TXT_RSA_WITH_AES_256_SHA
,
797 TLS1_CK_RSA_WITH_AES_256_SHA
,
798 SSL_kRSA
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
799 SSL_NOT_EXP
|SSL_HIGH
,
809 TLS1_TXT_DH_DSS_WITH_AES_256_SHA
,
810 TLS1_CK_DH_DSS_WITH_AES_256_SHA
,
811 SSL_kDHd
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
812 SSL_NOT_EXP
|SSL_HIGH
,
822 TLS1_TXT_DH_RSA_WITH_AES_256_SHA
,
823 TLS1_CK_DH_RSA_WITH_AES_256_SHA
,
824 SSL_kDHr
|SSL_aDH
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
825 SSL_NOT_EXP
|SSL_HIGH
,
835 TLS1_TXT_DHE_DSS_WITH_AES_256_SHA
,
836 TLS1_CK_DHE_DSS_WITH_AES_256_SHA
,
837 SSL_kEDH
|SSL_aDSS
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
838 SSL_NOT_EXP
|SSL_HIGH
,
848 TLS1_TXT_DHE_RSA_WITH_AES_256_SHA
,
849 TLS1_CK_DHE_RSA_WITH_AES_256_SHA
,
850 SSL_kEDH
|SSL_aRSA
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
851 SSL_NOT_EXP
|SSL_HIGH
,
861 TLS1_TXT_ADH_WITH_AES_256_SHA
,
862 TLS1_CK_ADH_WITH_AES_256_SHA
,
863 SSL_kEDH
|SSL_aNULL
|SSL_AES
|SSL_SHA
|SSL_TLSV1
,
864 SSL_NOT_EXP
|SSL_HIGH
,
875 static SSL3_ENC_METHOD SSLv3_enc_data
={
878 ssl3_setup_key_block
,
879 ssl3_generate_master_secret
,
880 ssl3_change_cipher_state
,
881 ssl3_final_finish_mac
,
882 MD5_DIGEST_LENGTH
+SHA_DIGEST_LENGTH
,
883 ssl3_cert_verify_mac
,
884 SSL3_MD_CLIENT_FINISHED_CONST
,4,
885 SSL3_MD_SERVER_FINISHED_CONST
,4,
889 static SSL_METHOD SSLv3_data
= {
894 ssl_undefined_function
,
895 ssl_undefined_function
,
901 ssl3_renegotiate_check
,
904 ssl3_get_cipher_by_char
,
905 ssl3_put_cipher_by_char
,
910 ssl3_default_timeout
,
912 ssl_undefined_function
,
914 ssl3_ctx_callback_ctrl
,
917 static long ssl3_default_timeout(void)
919 /* 2 hours, the 24 hours mentioned in the SSLv3 spec
920 * is way too long for http, the cache would over fill */
924 SSL_METHOD
*sslv3_base_method(void)
929 int ssl3_num_ciphers(void)
931 return(SSL3_NUM_CIPHERS
);
934 SSL_CIPHER
*ssl3_get_cipher(unsigned int u
)
936 if (u
< SSL3_NUM_CIPHERS
)
937 return(&(ssl3_ciphers
[SSL3_NUM_CIPHERS
-1-u
]));
942 int ssl3_pending(SSL
*s
)
944 return (s
->s3
->rrec
.type
== SSL3_RT_APPLICATION_DATA
) ? s
->s3
->rrec
.length
: 0;
951 if ((s3
=OPENSSL_malloc(sizeof *s3
)) == NULL
) goto err
;
952 memset(s3
,0,sizeof *s3
);
956 s
->method
->ssl_clear(s
);
962 void ssl3_free(SSL
*s
)
967 ssl3_cleanup_key_block(s
);
968 if (s
->s3
->rbuf
.buf
!= NULL
)
969 OPENSSL_free(s
->s3
->rbuf
.buf
);
970 if (s
->s3
->wbuf
.buf
!= NULL
)
971 OPENSSL_free(s
->s3
->wbuf
.buf
);
972 if (s
->s3
->rrec
.comp
!= NULL
)
973 OPENSSL_free(s
->s3
->rrec
.comp
);
974 #ifndef OPENSSL_NO_DH
975 if (s
->s3
->tmp
.dh
!= NULL
)
976 DH_free(s
->s3
->tmp
.dh
);
978 if (s
->s3
->tmp
.ca_names
!= NULL
)
979 sk_X509_NAME_pop_free(s
->s3
->tmp
.ca_names
,X509_NAME_free
);
980 memset(s
->s3
,0,sizeof *s
->s3
);
985 void ssl3_clear(SSL
*s
)
987 unsigned char *rp
,*wp
;
989 ssl3_cleanup_key_block(s
);
990 if (s
->s3
->tmp
.ca_names
!= NULL
)
991 sk_X509_NAME_pop_free(s
->s3
->tmp
.ca_names
,X509_NAME_free
);
993 if (s
->s3
->rrec
.comp
!= NULL
)
995 OPENSSL_free(s
->s3
->rrec
.comp
);
996 s
->s3
->rrec
.comp
=NULL
;
998 #ifndef OPENSSL_NO_DH
999 if (s
->s3
->tmp
.dh
!= NULL
)
1000 DH_free(s
->s3
->tmp
.dh
);
1006 memset(s
->s3
,0,sizeof *s
->s3
);
1007 if (rp
!= NULL
) s
->s3
->rbuf
.buf
=rp
;
1008 if (wp
!= NULL
) s
->s3
->wbuf
.buf
=wp
;
1010 ssl_free_wbio_buffer(s
);
1013 s
->s3
->renegotiate
=0;
1014 s
->s3
->total_renegotiations
=0;
1015 s
->s3
->num_renegotiations
=0;
1016 s
->s3
->in_read_app_data
=0;
1017 s
->version
=SSL3_VERSION
;
1020 long ssl3_ctrl(SSL
*s
, int cmd
, long larg
, char *parg
)
1024 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
1026 #ifndef OPENSSL_NO_RSA
1027 cmd
== SSL_CTRL_SET_TMP_RSA
||
1028 cmd
== SSL_CTRL_SET_TMP_RSA_CB
||
1030 #ifndef OPENSSL_NO_DSA
1031 cmd
== SSL_CTRL_SET_TMP_DH
||
1032 cmd
== SSL_CTRL_SET_TMP_DH_CB
||
1036 if (!ssl_cert_inst(&s
->cert
))
1038 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_MALLOC_FAILURE
);
1046 case SSL_CTRL_GET_SESSION_REUSED
:
1049 case SSL_CTRL_GET_CLIENT_CERT_REQUEST
:
1051 case SSL_CTRL_GET_NUM_RENEGOTIATIONS
:
1052 ret
=s
->s3
->num_renegotiations
;
1054 case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS
:
1055 ret
=s
->s3
->num_renegotiations
;
1056 s
->s3
->num_renegotiations
=0;
1058 case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS
:
1059 ret
=s
->s3
->total_renegotiations
;
1061 case SSL_CTRL_GET_FLAGS
:
1062 ret
=(int)(s
->s3
->flags
);
1064 #ifndef OPENSSL_NO_RSA
1065 case SSL_CTRL_NEED_TMP_RSA
:
1066 if ((s
->cert
!= NULL
) && (s
->cert
->rsa_tmp
== NULL
) &&
1067 ((s
->cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
== NULL
) ||
1068 (EVP_PKEY_size(s
->cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
) > (512/8))))
1071 case SSL_CTRL_SET_TMP_RSA
:
1073 RSA
*rsa
= (RSA
*)parg
;
1076 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_PASSED_NULL_PARAMETER
);
1079 if ((rsa
= RSAPrivateKey_dup(rsa
)) == NULL
)
1081 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_RSA_LIB
);
1084 if (s
->cert
->rsa_tmp
!= NULL
)
1085 RSA_free(s
->cert
->rsa_tmp
);
1086 s
->cert
->rsa_tmp
= rsa
;
1090 case SSL_CTRL_SET_TMP_RSA_CB
:
1092 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1097 #ifndef OPENSSL_NO_DH
1098 case SSL_CTRL_SET_TMP_DH
:
1100 DH
*dh
= (DH
*)parg
;
1103 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_PASSED_NULL_PARAMETER
);
1106 if ((dh
= DHparams_dup(dh
)) == NULL
)
1108 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_DH_LIB
);
1111 if (!(s
->options
& SSL_OP_SINGLE_DH_USE
))
1113 if (!DH_generate_key(dh
))
1116 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_DH_LIB
);
1120 if (s
->cert
->dh_tmp
!= NULL
)
1121 DH_free(s
->cert
->dh_tmp
);
1122 s
->cert
->dh_tmp
= dh
;
1126 case SSL_CTRL_SET_TMP_DH_CB
:
1128 SSLerr(SSL_F_SSL3_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1139 long ssl3_callback_ctrl(SSL
*s
, int cmd
, void (*fp
)())
1143 #if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_RSA)
1145 #ifndef OPENSSL_NO_RSA
1146 cmd
== SSL_CTRL_SET_TMP_RSA_CB
||
1148 #ifndef OPENSSL_NO_DSA
1149 cmd
== SSL_CTRL_SET_TMP_DH_CB
||
1153 if (!ssl_cert_inst(&s
->cert
))
1155 SSLerr(SSL_F_SSL3_CALLBACK_CTRL
, ERR_R_MALLOC_FAILURE
);
1163 #ifndef OPENSSL_NO_RSA
1164 case SSL_CTRL_SET_TMP_RSA_CB
:
1166 s
->cert
->rsa_tmp_cb
= (RSA
*(*)(SSL
*, int, int))fp
;
1170 #ifndef OPENSSL_NO_DH
1171 case SSL_CTRL_SET_TMP_DH_CB
:
1173 s
->cert
->dh_tmp_cb
= (DH
*(*)(SSL
*, int, int))fp
;
1183 long ssl3_ctx_ctrl(SSL_CTX
*ctx
, int cmd
, long larg
, char *parg
)
1191 #ifndef OPENSSL_NO_RSA
1192 case SSL_CTRL_NEED_TMP_RSA
:
1193 if ( (cert
->rsa_tmp
== NULL
) &&
1194 ((cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
== NULL
) ||
1195 (EVP_PKEY_size(cert
->pkeys
[SSL_PKEY_RSA_ENC
].privatekey
) > (512/8)))
1201 case SSL_CTRL_SET_TMP_RSA
:
1212 if ((rsa
=RSAPrivateKey_dup(rsa
)) == NULL
)
1217 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_RSA_LIB
);
1222 if (cert
->rsa_tmp
!= NULL
)
1223 RSA_free(cert
->rsa_tmp
);
1229 case SSL_CTRL_SET_TMP_RSA_CB
:
1231 SSLerr(SSL_F_SSL3_CTX_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1236 #ifndef OPENSSL_NO_DH
1237 case SSL_CTRL_SET_TMP_DH
:
1242 if ((new=DHparams_dup(dh
)) == NULL
)
1244 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_DH_LIB
);
1247 if (!(ctx
->options
& SSL_OP_SINGLE_DH_USE
))
1249 if (!DH_generate_key(new))
1251 SSLerr(SSL_F_SSL3_CTX_CTRL
,ERR_R_DH_LIB
);
1256 if (cert
->dh_tmp
!= NULL
)
1257 DH_free(cert
->dh_tmp
);
1262 case SSL_CTRL_SET_TMP_DH_CB
:
1264 SSLerr(SSL_F_SSL3_CTX_CTRL
, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED
);
1269 /* A Thawte special :-) */
1270 case SSL_CTRL_EXTRA_CHAIN_CERT
:
1271 if (ctx
->extra_certs
== NULL
)
1273 if ((ctx
->extra_certs
=sk_X509_new_null()) == NULL
)
1276 sk_X509_push(ctx
->extra_certs
,(X509
*)parg
);
1285 long ssl3_ctx_callback_ctrl(SSL_CTX
*ctx
, int cmd
, void (*fp
)())
1293 #ifndef OPENSSL_NO_RSA
1294 case SSL_CTRL_SET_TMP_RSA_CB
:
1296 cert
->rsa_tmp_cb
= (RSA
*(*)(SSL
*, int, int))fp
;
1300 #ifndef OPENSSL_NO_DH
1301 case SSL_CTRL_SET_TMP_DH_CB
:
1303 cert
->dh_tmp_cb
= (DH
*(*)(SSL
*, int, int))fp
;
1313 /* This function needs to check if the ciphers required are actually
1315 SSL_CIPHER
*ssl3_get_cipher_by_char(const unsigned char *p
)
1318 static SSL_CIPHER
*sorted
[SSL3_NUM_CIPHERS
];
1319 SSL_CIPHER c
,*cp
= &c
,**cpp
;
1325 CRYPTO_w_lock(CRYPTO_LOCK_SSL
);
1327 for (i
=0; i
<SSL3_NUM_CIPHERS
; i
++)
1328 sorted
[i
]= &(ssl3_ciphers
[i
]);
1330 qsort( (char *)sorted
,
1331 SSL3_NUM_CIPHERS
,sizeof(SSL_CIPHER
*),
1332 FP_ICC ssl_cipher_ptr_id_cmp
);
1334 CRYPTO_w_unlock(CRYPTO_LOCK_SSL
);
1339 id
=0x03000000L
|((unsigned long)p
[0]<<8L)|(unsigned long)p
[1];
1341 cpp
=(SSL_CIPHER
**)OBJ_bsearch((char *)&cp
,
1343 SSL3_NUM_CIPHERS
,sizeof(SSL_CIPHER
*),
1344 FP_ICC ssl_cipher_ptr_id_cmp
);
1345 if ((cpp
== NULL
) || !(*cpp
)->valid
)
1351 int ssl3_put_cipher_by_char(const SSL_CIPHER
*c
, unsigned char *p
)
1358 if ((l
& 0xff000000) != 0x03000000) return(0);
1359 p
[0]=((unsigned char)(l
>> 8L))&0xFF;
1360 p
[1]=((unsigned char)(l
))&0xFF;
1365 SSL_CIPHER
*ssl3_choose_cipher(SSL
*s
, STACK_OF(SSL_CIPHER
) *clnt
,
1366 STACK_OF(SSL_CIPHER
) *srvr
)
1368 SSL_CIPHER
*c
,*ret
=NULL
;
1369 STACK_OF(SSL_CIPHER
) *prio
, *allow
;
1372 unsigned long alg
,mask
,emask
;
1374 /* Let's see which ciphers we can support */
1378 /* Do not set the compare functions, because this may lead to a
1379 * reordering by "id". We want to keep the original ordering.
1380 * We may pay a price in performance during sk_SSL_CIPHER_find(),
1381 * but would have to pay with the price of sk_SSL_CIPHER_dup().
1383 sk_SSL_CIPHER_set_cmp_func(srvr
, ssl_cipher_ptr_id_cmp
);
1384 sk_SSL_CIPHER_set_cmp_func(clnt
, ssl_cipher_ptr_id_cmp
);
1388 printf("Server has %d from %p:\n", sk_SSL_CIPHER_num(srvr
), srvr
);
1389 for(i
=0 ; i
< sk_SSL_CIPHER_num(srvr
) ; ++i
)
1391 c
=sk_SSL_CIPHER_value(srvr
,i
);
1392 printf("%p:%s\n",c
,c
->name
);
1394 printf("Client sent %d from %p:\n", sk_SSL_CIPHER_num(clnt
), clnt
);
1395 for(i
=0 ; i
< sk_SSL_CIPHER_num(clnt
) ; ++i
)
1397 c
=sk_SSL_CIPHER_value(clnt
,i
);
1398 printf("%p:%s\n",c
,c
->name
);
1402 if (s
->options
& SSL_OP_CIPHER_SERVER_PREFERENCE
)
1413 for (i
=0; i
<sk_SSL_CIPHER_num(prio
); i
++)
1415 c
=sk_SSL_CIPHER_value(prio
,i
);
1417 ssl_set_cert_masks(cert
,c
);
1419 emask
=cert
->export_mask
;
1422 printf("ssl3_choose_cipher %d alg= %lx\n", i
,c
->algorithms
);
1423 #endif /* KSSL_DEBUG */
1425 alg
=c
->algorithms
&(SSL_MKEY_MASK
|SSL_AUTH_MASK
);
1426 #ifndef OPENSSL_NO_KRB5
1429 if ( !kssl_keytab_is_available(s
->kssl_ctx
) )
1432 #endif /* OPENSSL_NO_KRB5 */
1433 if (SSL_C_IS_EXPORT(c
))
1435 ok
=((alg
& emask
) == alg
)?1:0;
1437 printf("%d:[%08lX:%08lX]%p:%s (export)\n",ok
,alg
,emask
,
1443 ok
=((alg
& mask
) == alg
)?1:0;
1445 printf("%d:[%08lX:%08lX]%p:%s\n",ok
,alg
,mask
,c
,
1452 j
=sk_SSL_CIPHER_find(allow
,c
);
1455 ret
=sk_SSL_CIPHER_value(allow
,j
);
1462 int ssl3_get_req_cert_type(SSL
*s
, unsigned char *p
)
1467 alg
=s
->s3
->tmp
.new_cipher
->algorithms
;
1469 #ifndef OPENSSL_NO_DH
1470 if (alg
& (SSL_kDHr
|SSL_kEDH
))
1472 # ifndef OPENSSL_NO_RSA
1473 p
[ret
++]=SSL3_CT_RSA_FIXED_DH
;
1475 # ifndef OPENSSL_NO_DSA
1476 p
[ret
++]=SSL3_CT_DSS_FIXED_DH
;
1479 if ((s
->version
== SSL3_VERSION
) &&
1480 (alg
& (SSL_kEDH
|SSL_kDHd
|SSL_kDHr
)))
1482 # ifndef OPENSSL_NO_RSA
1483 p
[ret
++]=SSL3_CT_RSA_EPHEMERAL_DH
;
1485 # ifndef OPENSSL_NO_DSA
1486 p
[ret
++]=SSL3_CT_DSS_EPHEMERAL_DH
;
1489 #endif /* !OPENSSL_NO_DH */
1490 #ifndef OPENSSL_NO_RSA
1491 p
[ret
++]=SSL3_CT_RSA_SIGN
;
1493 #ifndef OPENSSL_NO_DSA
1494 p
[ret
++]=SSL3_CT_DSS_SIGN
;
1499 int ssl3_shutdown(SSL
*s
)
1502 /* Don't do anything much if we have not done the handshake or
1503 * we don't want to send messages :-) */
1504 if ((s
->quiet_shutdown
) || (s
->state
== SSL_ST_BEFORE
))
1506 s
->shutdown
=(SSL_SENT_SHUTDOWN
|SSL_RECEIVED_SHUTDOWN
);
1510 if (!(s
->shutdown
& SSL_SENT_SHUTDOWN
))
1512 s
->shutdown
|=SSL_SENT_SHUTDOWN
;
1514 ssl3_send_alert(s
,SSL3_AL_WARNING
,SSL_AD_CLOSE_NOTIFY
);
1516 /* our shutdown alert has been sent now, and if it still needs
1517 * to be written, s->s3->alert_dispatch will be true */
1519 else if (s
->s3
->alert_dispatch
)
1521 /* resend it if not sent */
1523 ssl3_dispatch_alert(s
);
1526 else if (!(s
->shutdown
& SSL_RECEIVED_SHUTDOWN
))
1528 /* If we are waiting for a close from our peer, we are closed */
1529 ssl3_read_bytes(s
,0,NULL
,0,0);
1532 if ((s
->shutdown
== (SSL_SENT_SHUTDOWN
|SSL_RECEIVED_SHUTDOWN
)) &&
1533 !s
->s3
->alert_dispatch
)
1539 int ssl3_write(SSL
*s
, const void *buf
, int len
)
1544 if (s
->shutdown
& SSL_SEND_SHUTDOWN
)
1546 s
->rwstate
=SSL_NOTHING
;
1551 if (s
->s3
->renegotiate
) ssl3_renegotiate_check(s
);
1553 /* This is an experimental flag that sends the
1554 * last handshake message in the same packet as the first
1555 * use data - used to see if it helps the TCP protocol during
1556 * session-id reuse */
1557 /* The second test is because the buffer may have been removed */
1558 if ((s
->s3
->flags
& SSL3_FLAGS_POP_BUFFER
) && (s
->wbio
== s
->bbio
))
1560 /* First time through, we write into the buffer */
1561 if (s
->s3
->delay_buf_pop_ret
== 0)
1563 ret
=ssl3_write_bytes(s
,SSL3_RT_APPLICATION_DATA
,
1565 if (ret
<= 0) return(ret
);
1567 s
->s3
->delay_buf_pop_ret
=ret
;
1570 s
->rwstate
=SSL_WRITING
;
1571 n
=BIO_flush(s
->wbio
);
1572 if (n
<= 0) return(n
);
1573 s
->rwstate
=SSL_NOTHING
;
1575 /* We have flushed the buffer, so remove it */
1576 ssl_free_wbio_buffer(s
);
1577 s
->s3
->flags
&= ~SSL3_FLAGS_POP_BUFFER
;
1579 ret
=s
->s3
->delay_buf_pop_ret
;
1580 s
->s3
->delay_buf_pop_ret
=0;
1584 ret
=ssl3_write_bytes(s
,SSL3_RT_APPLICATION_DATA
,
1586 if (ret
<= 0) return(ret
);
1592 static int ssl3_read_internal(SSL
*s
, void *buf
, int len
, int peek
)
1597 if (s
->s3
->renegotiate
) ssl3_renegotiate_check(s
);
1598 s
->s3
->in_read_app_data
=1;
1599 ret
=ssl3_read_bytes(s
,SSL3_RT_APPLICATION_DATA
,buf
,len
,peek
);
1600 if ((ret
== -1) && (s
->s3
->in_read_app_data
== 0))
1602 /* ssl3_read_bytes decided to call s->handshake_func, which
1603 * called ssl3_read_bytes to read handshake data.
1604 * However, ssl3_read_bytes actually found application data
1605 * and thinks that application data makes sense here (signalled
1606 * by resetting 'in_read_app_data', strangely); so disable
1607 * handshake processing and try to read application data again. */
1609 ret
=ssl3_read_bytes(s
,SSL3_RT_APPLICATION_DATA
,buf
,len
,peek
);
1613 s
->s3
->in_read_app_data
=0;
1618 int ssl3_read(SSL
*s
, void *buf
, int len
)
1620 return ssl3_read_internal(s
, buf
, len
, 0);
1623 int ssl3_peek(SSL
*s
, void *buf
, int len
)
1625 return ssl3_read_internal(s
, buf
, len
, 1);
1628 int ssl3_renegotiate(SSL
*s
)
1630 if (s
->handshake_func
== NULL
)
1633 if (s
->s3
->flags
& SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS
)
1636 s
->s3
->renegotiate
=1;
1640 int ssl3_renegotiate_check(SSL
*s
)
1644 if (s
->s3
->renegotiate
)
1646 if ( (s
->s3
->rbuf
.left
== 0) &&
1647 (s
->s3
->wbuf
.left
== 0) &&
1651 if we are the server, and we have sent a 'RENEGOTIATE' message, we
1652 need to go to SSL_ST_ACCEPT.
1655 s
->state
=SSL_ST_RENEGOTIATE
;
1656 s
->s3
->renegotiate
=0;
1657 s
->s3
->num_renegotiations
++;
1658 s
->s3
->total_renegotiations
++;