sl@0
|
1 |
/* ssl/ssl_ciph.c */
|
sl@0
|
2 |
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
*
|
sl@0
|
5 |
* This package is an SSL implementation written
|
sl@0
|
6 |
* by Eric Young (eay@cryptsoft.com).
|
sl@0
|
7 |
* The implementation was written so as to conform with Netscapes SSL.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* This library is free for commercial and non-commercial use as long as
|
sl@0
|
10 |
* the following conditions are aheared to. The following conditions
|
sl@0
|
11 |
* apply to all code found in this distribution, be it the RC4, RSA,
|
sl@0
|
12 |
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
sl@0
|
13 |
* included with this distribution is covered by the same copyright terms
|
sl@0
|
14 |
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
sl@0
|
15 |
*
|
sl@0
|
16 |
* Copyright remains Eric Young's, and as such any Copyright notices in
|
sl@0
|
17 |
* the code are not to be removed.
|
sl@0
|
18 |
* If this package is used in a product, Eric Young should be given attribution
|
sl@0
|
19 |
* as the author of the parts of the library used.
|
sl@0
|
20 |
* This can be in the form of a textual message at program startup or
|
sl@0
|
21 |
* in documentation (online or textual) provided with the package.
|
sl@0
|
22 |
*
|
sl@0
|
23 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
24 |
* modification, are permitted provided that the following conditions
|
sl@0
|
25 |
* are met:
|
sl@0
|
26 |
* 1. Redistributions of source code must retain the copyright
|
sl@0
|
27 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
28 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
29 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
30 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
31 |
* 3. All advertising materials mentioning features or use of this software
|
sl@0
|
32 |
* must display the following acknowledgement:
|
sl@0
|
33 |
* "This product includes cryptographic software written by
|
sl@0
|
34 |
* Eric Young (eay@cryptsoft.com)"
|
sl@0
|
35 |
* The word 'cryptographic' can be left out if the rouines from the library
|
sl@0
|
36 |
* being used are not cryptographic related :-).
|
sl@0
|
37 |
* 4. If you include any Windows specific code (or a derivative thereof) from
|
sl@0
|
38 |
* the apps directory (application code) you must include an acknowledgement:
|
sl@0
|
39 |
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
sl@0
|
40 |
*
|
sl@0
|
41 |
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
sl@0
|
42 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
43 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
44 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
sl@0
|
45 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
sl@0
|
46 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
sl@0
|
47 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
48 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
sl@0
|
49 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
sl@0
|
50 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
sl@0
|
51 |
* SUCH DAMAGE.
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* The licence and distribution terms for any publically available version or
|
sl@0
|
54 |
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
sl@0
|
55 |
* copied and put under another distribution licence
|
sl@0
|
56 |
* [including the GNU Public Licence.]
|
sl@0
|
57 |
* Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
|
sl@0
|
58 |
*
|
sl@0
|
59 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
60 |
* modification, are permitted provided that the following conditions
|
sl@0
|
61 |
* are met:
|
sl@0
|
62 |
*
|
sl@0
|
63 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
64 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
65 |
*
|
sl@0
|
66 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
67 |
* notice, this list of conditions and the following disclaimer in
|
sl@0
|
68 |
* the documentation and/or other materials provided with the
|
sl@0
|
69 |
* distribution.
|
sl@0
|
70 |
*
|
sl@0
|
71 |
* 3. All advertising materials mentioning features or use of this
|
sl@0
|
72 |
* software must display the following acknowledgment:
|
sl@0
|
73 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
74 |
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
sl@0
|
75 |
*
|
sl@0
|
76 |
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
sl@0
|
77 |
* endorse or promote products derived from this software without
|
sl@0
|
78 |
* prior written permission. For written permission, please contact
|
sl@0
|
79 |
* openssl-core@openssl.org.
|
sl@0
|
80 |
*
|
sl@0
|
81 |
* 5. Products derived from this software may not be called "OpenSSL"
|
sl@0
|
82 |
* nor may "OpenSSL" appear in their names without prior written
|
sl@0
|
83 |
* permission of the OpenSSL Project.
|
sl@0
|
84 |
*
|
sl@0
|
85 |
* 6. Redistributions of any form whatsoever must retain the following
|
sl@0
|
86 |
* acknowledgment:
|
sl@0
|
87 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
88 |
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
sl@0
|
89 |
*
|
sl@0
|
90 |
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
sl@0
|
91 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
92 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
sl@0
|
93 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
sl@0
|
94 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
sl@0
|
95 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
sl@0
|
96 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
sl@0
|
97 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
98 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
99 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
sl@0
|
100 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
sl@0
|
101 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
102 |
* ====================================================================
|
sl@0
|
103 |
*
|
sl@0
|
104 |
* This product includes cryptographic software written by Eric Young
|
sl@0
|
105 |
* (eay@cryptsoft.com). This product includes software written by Tim
|
sl@0
|
106 |
* Hudson (tjh@cryptsoft.com).
|
sl@0
|
107 |
*
|
sl@0
|
108 |
*/
|
sl@0
|
109 |
/* ====================================================================
|
sl@0
|
110 |
*/
|
sl@0
|
111 |
/* ====================================================================
|
sl@0
|
112 |
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
|
sl@0
|
113 |
* ECC cipher suite support in OpenSSL originally developed by
|
sl@0
|
114 |
* SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
|
sl@0
|
115 |
*/
|
sl@0
|
116 |
/*
|
sl@0
|
117 |
© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
sl@0
|
118 |
*/
|
sl@0
|
119 |
|
sl@0
|
120 |
#include <stdio.h>
|
sl@0
|
121 |
#include <openssl/objects.h>
|
sl@0
|
122 |
#include <openssl/comp.h>
|
sl@0
|
123 |
#include "ssl_locl.h"
|
sl@0
|
124 |
|
sl@0
|
125 |
#define SSL_ENC_DES_IDX 0
|
sl@0
|
126 |
#define SSL_ENC_3DES_IDX 1
|
sl@0
|
127 |
#define SSL_ENC_RC4_IDX 2
|
sl@0
|
128 |
#define SSL_ENC_RC2_IDX 3
|
sl@0
|
129 |
#define SSL_ENC_IDEA_IDX 4
|
sl@0
|
130 |
#define SSL_ENC_eFZA_IDX 5
|
sl@0
|
131 |
#define SSL_ENC_NULL_IDX 6
|
sl@0
|
132 |
#define SSL_ENC_AES128_IDX 7
|
sl@0
|
133 |
#define SSL_ENC_AES256_IDX 8
|
sl@0
|
134 |
#define SSL_ENC_NUM_IDX 9
|
sl@0
|
135 |
|
sl@0
|
136 |
#ifndef EMULATOR
|
sl@0
|
137 |
static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={
|
sl@0
|
138 |
NULL,NULL,NULL,NULL,NULL,NULL,
|
sl@0
|
139 |
};
|
sl@0
|
140 |
#else
|
sl@0
|
141 |
GET_STATIC_ARRAY_FROM_TLS(ssl_cipher_methods,ssl_ciph,const EVP_CIPHER *)
|
sl@0
|
142 |
|
sl@0
|
143 |
#define ssl_cipher_methods (GET_WSD_VAR_NAME(ssl_cipher_methods,ssl_ciph,s)())
|
sl@0
|
144 |
#endif
|
sl@0
|
145 |
|
sl@0
|
146 |
#define SSL_COMP_NULL_IDX 0
|
sl@0
|
147 |
#define SSL_COMP_ZLIB_IDX 1
|
sl@0
|
148 |
#define SSL_COMP_NUM_IDX 2
|
sl@0
|
149 |
|
sl@0
|
150 |
#ifndef EMULATOR
|
sl@0
|
151 |
static STACK_OF(SSL_COMP) *ssl_comp_methods=NULL;
|
sl@0
|
152 |
#else
|
sl@0
|
153 |
GET_STATIC_VAR_FROM_TLS(ssl_comp_methods,ssl_ciph,STACK_OF(SSL_COMP) *)
|
sl@0
|
154 |
|
sl@0
|
155 |
#define ssl_comp_methods (*GET_WSD_VAR_NAME(ssl_comp_methods,ssl_ciph,s)())
|
sl@0
|
156 |
#endif
|
sl@0
|
157 |
|
sl@0
|
158 |
#define SSL_MD_MD5_IDX 0
|
sl@0
|
159 |
#define SSL_MD_SHA1_IDX 1
|
sl@0
|
160 |
#define SSL_MD_NUM_IDX 2
|
sl@0
|
161 |
#ifndef EMULATOR
|
sl@0
|
162 |
static const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={
|
sl@0
|
163 |
NULL,NULL,
|
sl@0
|
164 |
};
|
sl@0
|
165 |
#else /* EMULATOR */
|
sl@0
|
166 |
GET_STATIC_ARRAY_FROM_TLS(ssl_digest_methods,ssl_ciph,const EVP_MD *)
|
sl@0
|
167 |
|
sl@0
|
168 |
#define ssl_digest_methods (GET_WSD_VAR_NAME(ssl_digest_methods,ssl_ciph,s)())
|
sl@0
|
169 |
#endif
|
sl@0
|
170 |
#define CIPHER_ADD 1
|
sl@0
|
171 |
#define CIPHER_KILL 2
|
sl@0
|
172 |
#define CIPHER_DEL 3
|
sl@0
|
173 |
#define CIPHER_ORD 4
|
sl@0
|
174 |
#define CIPHER_SPECIAL 5
|
sl@0
|
175 |
|
sl@0
|
176 |
typedef struct cipher_order_st
|
sl@0
|
177 |
{
|
sl@0
|
178 |
SSL_CIPHER *cipher;
|
sl@0
|
179 |
int active;
|
sl@0
|
180 |
int dead;
|
sl@0
|
181 |
struct cipher_order_st *next,*prev;
|
sl@0
|
182 |
} CIPHER_ORDER;
|
sl@0
|
183 |
|
sl@0
|
184 |
static const SSL_CIPHER cipher_aliases[]={
|
sl@0
|
185 |
/* Don't include eNULL unless specifically enabled. */
|
sl@0
|
186 |
/* Don't include ECC in ALL because these ciphers are not yet official. */
|
sl@0
|
187 |
{0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL & ~SSL_kECDH & ~SSL_kECDHE, SSL_ALL ,0,0,0,SSL_ALL,SSL_ALL}, /* must be first */
|
sl@0
|
188 |
/* TODO: COMPLEMENT OF ALL and COMPLEMENT OF DEFAULT do not have ECC cipher suites handled properly. */
|
sl@0
|
189 |
{0,SSL_TXT_CMPALL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0}, /* COMPLEMENT OF ALL */
|
sl@0
|
190 |
{0,SSL_TXT_CMPDEF,0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK,0},
|
sl@0
|
191 |
{0,SSL_TXT_kKRB5,0,SSL_kKRB5,0,0,0,0,SSL_MKEY_MASK,0}, /* VRS Kerberos5 */
|
sl@0
|
192 |
{0,SSL_TXT_kRSA,0,SSL_kRSA, 0,0,0,0,SSL_MKEY_MASK,0},
|
sl@0
|
193 |
{0,SSL_TXT_kDHr,0,SSL_kDHr, 0,0,0,0,SSL_MKEY_MASK,0},
|
sl@0
|
194 |
{0,SSL_TXT_kDHd,0,SSL_kDHd, 0,0,0,0,SSL_MKEY_MASK,0},
|
sl@0
|
195 |
{0,SSL_TXT_kEDH,0,SSL_kEDH, 0,0,0,0,SSL_MKEY_MASK,0},
|
sl@0
|
196 |
{0,SSL_TXT_kFZA,0,SSL_kFZA, 0,0,0,0,SSL_MKEY_MASK,0},
|
sl@0
|
197 |
{0,SSL_TXT_DH, 0,SSL_DH, 0,0,0,0,SSL_MKEY_MASK,0},
|
sl@0
|
198 |
{0,SSL_TXT_ECC, 0,(SSL_kECDH|SSL_kECDHE), 0,0,0,0,SSL_MKEY_MASK,0},
|
sl@0
|
199 |
{0,SSL_TXT_EDH, 0,SSL_EDH, 0,0,0,0,SSL_MKEY_MASK|SSL_AUTH_MASK,0},
|
sl@0
|
200 |
{0,SSL_TXT_aKRB5,0,SSL_aKRB5,0,0,0,0,SSL_AUTH_MASK,0}, /* VRS Kerberos5 */
|
sl@0
|
201 |
{0,SSL_TXT_aRSA,0,SSL_aRSA, 0,0,0,0,SSL_AUTH_MASK,0},
|
sl@0
|
202 |
{0,SSL_TXT_aDSS,0,SSL_aDSS, 0,0,0,0,SSL_AUTH_MASK,0},
|
sl@0
|
203 |
{0,SSL_TXT_aFZA,0,SSL_aFZA, 0,0,0,0,SSL_AUTH_MASK,0},
|
sl@0
|
204 |
{0,SSL_TXT_aNULL,0,SSL_aNULL,0,0,0,0,SSL_AUTH_MASK,0},
|
sl@0
|
205 |
{0,SSL_TXT_aDH, 0,SSL_aDH, 0,0,0,0,SSL_AUTH_MASK,0},
|
sl@0
|
206 |
{0,SSL_TXT_DSS, 0,SSL_DSS, 0,0,0,0,SSL_AUTH_MASK,0},
|
sl@0
|
207 |
|
sl@0
|
208 |
{0,SSL_TXT_DES, 0,SSL_DES, 0,0,0,0,SSL_ENC_MASK,0},
|
sl@0
|
209 |
{0,SSL_TXT_3DES,0,SSL_3DES, 0,0,0,0,SSL_ENC_MASK,0},
|
sl@0
|
210 |
{0,SSL_TXT_RC4, 0,SSL_RC4, 0,0,0,0,SSL_ENC_MASK,0},
|
sl@0
|
211 |
{0,SSL_TXT_RC2, 0,SSL_RC2, 0,0,0,0,SSL_ENC_MASK,0},
|
sl@0
|
212 |
#ifndef OPENSSL_NO_IDEA
|
sl@0
|
213 |
{0,SSL_TXT_IDEA,0,SSL_IDEA, 0,0,0,0,SSL_ENC_MASK,0},
|
sl@0
|
214 |
#endif
|
sl@0
|
215 |
{0,SSL_TXT_eNULL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0},
|
sl@0
|
216 |
{0,SSL_TXT_eFZA,0,SSL_eFZA, 0,0,0,0,SSL_ENC_MASK,0},
|
sl@0
|
217 |
{0,SSL_TXT_AES, 0,SSL_AES, 0,0,0,0,SSL_ENC_MASK,0},
|
sl@0
|
218 |
|
sl@0
|
219 |
{0,SSL_TXT_MD5, 0,SSL_MD5, 0,0,0,0,SSL_MAC_MASK,0},
|
sl@0
|
220 |
{0,SSL_TXT_SHA1,0,SSL_SHA1, 0,0,0,0,SSL_MAC_MASK,0},
|
sl@0
|
221 |
{0,SSL_TXT_SHA, 0,SSL_SHA, 0,0,0,0,SSL_MAC_MASK,0},
|
sl@0
|
222 |
|
sl@0
|
223 |
{0,SSL_TXT_NULL,0,SSL_NULL, 0,0,0,0,SSL_ENC_MASK,0},
|
sl@0
|
224 |
{0,SSL_TXT_KRB5,0,SSL_KRB5, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
|
sl@0
|
225 |
{0,SSL_TXT_RSA, 0,SSL_RSA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
|
sl@0
|
226 |
{0,SSL_TXT_ADH, 0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
|
sl@0
|
227 |
{0,SSL_TXT_FZA, 0,SSL_FZA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK,0},
|
sl@0
|
228 |
|
sl@0
|
229 |
{0,SSL_TXT_SSLV2, 0,SSL_SSLV2, 0,0,0,0,SSL_SSL_MASK,0},
|
sl@0
|
230 |
{0,SSL_TXT_SSLV3, 0,SSL_SSLV3, 0,0,0,0,SSL_SSL_MASK,0},
|
sl@0
|
231 |
{0,SSL_TXT_TLSV1, 0,SSL_TLSV1, 0,0,0,0,SSL_SSL_MASK,0},
|
sl@0
|
232 |
|
sl@0
|
233 |
{0,SSL_TXT_EXP ,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
|
sl@0
|
234 |
{0,SSL_TXT_EXPORT,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
|
sl@0
|
235 |
{0,SSL_TXT_EXP40, 0, 0, SSL_EXP40, 0,0,0,0,SSL_STRONG_MASK},
|
sl@0
|
236 |
{0,SSL_TXT_EXP56, 0, 0, SSL_EXP56, 0,0,0,0,SSL_STRONG_MASK},
|
sl@0
|
237 |
{0,SSL_TXT_LOW, 0, 0, SSL_LOW, 0,0,0,0,SSL_STRONG_MASK},
|
sl@0
|
238 |
{0,SSL_TXT_MEDIUM,0, 0,SSL_MEDIUM, 0,0,0,0,SSL_STRONG_MASK},
|
sl@0
|
239 |
{0,SSL_TXT_HIGH, 0, 0, SSL_HIGH, 0,0,0,0,SSL_STRONG_MASK},
|
sl@0
|
240 |
};
|
sl@0
|
241 |
|
sl@0
|
242 |
void ssl_load_ciphers(void)
|
sl@0
|
243 |
{
|
sl@0
|
244 |
ssl_cipher_methods[SSL_ENC_DES_IDX]=
|
sl@0
|
245 |
EVP_get_cipherbyname(SN_des_cbc);
|
sl@0
|
246 |
ssl_cipher_methods[SSL_ENC_3DES_IDX]=
|
sl@0
|
247 |
EVP_get_cipherbyname(SN_des_ede3_cbc);
|
sl@0
|
248 |
ssl_cipher_methods[SSL_ENC_RC4_IDX]=
|
sl@0
|
249 |
EVP_get_cipherbyname(SN_rc4);
|
sl@0
|
250 |
ssl_cipher_methods[SSL_ENC_RC2_IDX]=
|
sl@0
|
251 |
EVP_get_cipherbyname(SN_rc2_cbc);
|
sl@0
|
252 |
#ifndef OPENSSL_NO_IDEA
|
sl@0
|
253 |
ssl_cipher_methods[SSL_ENC_IDEA_IDX]=
|
sl@0
|
254 |
EVP_get_cipherbyname(SN_idea_cbc);
|
sl@0
|
255 |
#else
|
sl@0
|
256 |
ssl_cipher_methods[SSL_ENC_IDEA_IDX]= NULL;
|
sl@0
|
257 |
#endif
|
sl@0
|
258 |
ssl_cipher_methods[SSL_ENC_AES128_IDX]=
|
sl@0
|
259 |
EVP_get_cipherbyname(SN_aes_128_cbc);
|
sl@0
|
260 |
ssl_cipher_methods[SSL_ENC_AES256_IDX]=
|
sl@0
|
261 |
EVP_get_cipherbyname(SN_aes_256_cbc);
|
sl@0
|
262 |
|
sl@0
|
263 |
ssl_digest_methods[SSL_MD_MD5_IDX]=
|
sl@0
|
264 |
EVP_get_digestbyname(SN_md5);
|
sl@0
|
265 |
ssl_digest_methods[SSL_MD_SHA1_IDX]=
|
sl@0
|
266 |
EVP_get_digestbyname(SN_sha1);
|
sl@0
|
267 |
}
|
sl@0
|
268 |
|
sl@0
|
269 |
|
sl@0
|
270 |
#ifndef OPENSSL_NO_COMP
|
sl@0
|
271 |
|
sl@0
|
272 |
static int sk_comp_cmp(const SSL_COMP * const *a,
|
sl@0
|
273 |
const SSL_COMP * const *b)
|
sl@0
|
274 |
{
|
sl@0
|
275 |
return((*a)->id-(*b)->id);
|
sl@0
|
276 |
}
|
sl@0
|
277 |
|
sl@0
|
278 |
static void load_builtin_compressions(void)
|
sl@0
|
279 |
{
|
sl@0
|
280 |
int got_write_lock = 0;
|
sl@0
|
281 |
|
sl@0
|
282 |
CRYPTO_r_lock(CRYPTO_LOCK_SSL);
|
sl@0
|
283 |
if (ssl_comp_methods == NULL)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
CRYPTO_r_unlock(CRYPTO_LOCK_SSL);
|
sl@0
|
286 |
CRYPTO_w_lock(CRYPTO_LOCK_SSL);
|
sl@0
|
287 |
got_write_lock = 1;
|
sl@0
|
288 |
|
sl@0
|
289 |
if (ssl_comp_methods == NULL)
|
sl@0
|
290 |
{
|
sl@0
|
291 |
SSL_COMP *comp = NULL;
|
sl@0
|
292 |
|
sl@0
|
293 |
MemCheck_off();
|
sl@0
|
294 |
ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp);
|
sl@0
|
295 |
if (ssl_comp_methods != NULL)
|
sl@0
|
296 |
{
|
sl@0
|
297 |
comp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP));
|
sl@0
|
298 |
if (comp != NULL)
|
sl@0
|
299 |
{
|
sl@0
|
300 |
comp->method=COMP_zlib();
|
sl@0
|
301 |
if (comp->method
|
sl@0
|
302 |
&& comp->method->type == NID_undef)
|
sl@0
|
303 |
OPENSSL_free(comp);
|
sl@0
|
304 |
else
|
sl@0
|
305 |
{
|
sl@0
|
306 |
comp->id=SSL_COMP_ZLIB_IDX;
|
sl@0
|
307 |
comp->name=comp->method->name;
|
sl@0
|
308 |
sk_SSL_COMP_push(ssl_comp_methods,comp);
|
sl@0
|
309 |
}
|
sl@0
|
310 |
}
|
sl@0
|
311 |
}
|
sl@0
|
312 |
MemCheck_on();
|
sl@0
|
313 |
}
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
if (got_write_lock)
|
sl@0
|
317 |
CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
|
sl@0
|
318 |
else
|
sl@0
|
319 |
CRYPTO_r_unlock(CRYPTO_LOCK_SSL);
|
sl@0
|
320 |
}
|
sl@0
|
321 |
#endif
|
sl@0
|
322 |
|
sl@0
|
323 |
int ssl_cipher_get_evp(const SSL_SESSION *s, const EVP_CIPHER **enc,
|
sl@0
|
324 |
const EVP_MD **md, SSL_COMP **comp)
|
sl@0
|
325 |
{
|
sl@0
|
326 |
int i;
|
sl@0
|
327 |
SSL_CIPHER *c;
|
sl@0
|
328 |
|
sl@0
|
329 |
c=s->cipher;
|
sl@0
|
330 |
if (c == NULL) return(0);
|
sl@0
|
331 |
if (comp != NULL)
|
sl@0
|
332 |
{
|
sl@0
|
333 |
SSL_COMP ctmp;
|
sl@0
|
334 |
#ifndef OPENSSL_NO_COMP
|
sl@0
|
335 |
load_builtin_compressions();
|
sl@0
|
336 |
#endif
|
sl@0
|
337 |
|
sl@0
|
338 |
*comp=NULL;
|
sl@0
|
339 |
ctmp.id=s->compress_meth;
|
sl@0
|
340 |
if (ssl_comp_methods != NULL)
|
sl@0
|
341 |
{
|
sl@0
|
342 |
i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp);
|
sl@0
|
343 |
if (i >= 0)
|
sl@0
|
344 |
*comp=sk_SSL_COMP_value(ssl_comp_methods,i);
|
sl@0
|
345 |
else
|
sl@0
|
346 |
*comp=NULL;
|
sl@0
|
347 |
}
|
sl@0
|
348 |
}
|
sl@0
|
349 |
|
sl@0
|
350 |
if ((enc == NULL) || (md == NULL)) return(0);
|
sl@0
|
351 |
|
sl@0
|
352 |
switch (c->algorithms & SSL_ENC_MASK)
|
sl@0
|
353 |
{
|
sl@0
|
354 |
case SSL_DES:
|
sl@0
|
355 |
i=SSL_ENC_DES_IDX;
|
sl@0
|
356 |
break;
|
sl@0
|
357 |
case SSL_3DES:
|
sl@0
|
358 |
i=SSL_ENC_3DES_IDX;
|
sl@0
|
359 |
break;
|
sl@0
|
360 |
case SSL_RC4:
|
sl@0
|
361 |
i=SSL_ENC_RC4_IDX;
|
sl@0
|
362 |
break;
|
sl@0
|
363 |
case SSL_RC2:
|
sl@0
|
364 |
i=SSL_ENC_RC2_IDX;
|
sl@0
|
365 |
break;
|
sl@0
|
366 |
case SSL_IDEA:
|
sl@0
|
367 |
i=SSL_ENC_IDEA_IDX;
|
sl@0
|
368 |
break;
|
sl@0
|
369 |
case SSL_eNULL:
|
sl@0
|
370 |
i=SSL_ENC_NULL_IDX;
|
sl@0
|
371 |
break;
|
sl@0
|
372 |
case SSL_AES:
|
sl@0
|
373 |
switch(c->alg_bits)
|
sl@0
|
374 |
{
|
sl@0
|
375 |
case 128: i=SSL_ENC_AES128_IDX; break;
|
sl@0
|
376 |
case 256: i=SSL_ENC_AES256_IDX; break;
|
sl@0
|
377 |
default: i=-1; break;
|
sl@0
|
378 |
}
|
sl@0
|
379 |
break;
|
sl@0
|
380 |
default:
|
sl@0
|
381 |
i= -1;
|
sl@0
|
382 |
break;
|
sl@0
|
383 |
}
|
sl@0
|
384 |
|
sl@0
|
385 |
if ((i < 0) || (i > SSL_ENC_NUM_IDX))
|
sl@0
|
386 |
*enc=NULL;
|
sl@0
|
387 |
else
|
sl@0
|
388 |
{
|
sl@0
|
389 |
if (i == SSL_ENC_NULL_IDX)
|
sl@0
|
390 |
*enc=EVP_enc_null();
|
sl@0
|
391 |
else
|
sl@0
|
392 |
*enc=ssl_cipher_methods[i];
|
sl@0
|
393 |
}
|
sl@0
|
394 |
|
sl@0
|
395 |
switch (c->algorithms & SSL_MAC_MASK)
|
sl@0
|
396 |
{
|
sl@0
|
397 |
case SSL_MD5:
|
sl@0
|
398 |
i=SSL_MD_MD5_IDX;
|
sl@0
|
399 |
break;
|
sl@0
|
400 |
case SSL_SHA1:
|
sl@0
|
401 |
i=SSL_MD_SHA1_IDX;
|
sl@0
|
402 |
break;
|
sl@0
|
403 |
default:
|
sl@0
|
404 |
i= -1;
|
sl@0
|
405 |
break;
|
sl@0
|
406 |
}
|
sl@0
|
407 |
if ((i < 0) || (i > SSL_MD_NUM_IDX))
|
sl@0
|
408 |
*md=NULL;
|
sl@0
|
409 |
else
|
sl@0
|
410 |
*md=ssl_digest_methods[i];
|
sl@0
|
411 |
|
sl@0
|
412 |
if ((*enc != NULL) && (*md != NULL))
|
sl@0
|
413 |
return(1);
|
sl@0
|
414 |
else
|
sl@0
|
415 |
return(0);
|
sl@0
|
416 |
}
|
sl@0
|
417 |
|
sl@0
|
418 |
#define ITEM_SEP(a) \
|
sl@0
|
419 |
(((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
|
sl@0
|
420 |
|
sl@0
|
421 |
static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr,
|
sl@0
|
422 |
CIPHER_ORDER **tail)
|
sl@0
|
423 |
{
|
sl@0
|
424 |
if (curr == *tail) return;
|
sl@0
|
425 |
if (curr == *head)
|
sl@0
|
426 |
*head=curr->next;
|
sl@0
|
427 |
if (curr->prev != NULL)
|
sl@0
|
428 |
curr->prev->next=curr->next;
|
sl@0
|
429 |
if (curr->next != NULL) /* should always be true */
|
sl@0
|
430 |
curr->next->prev=curr->prev;
|
sl@0
|
431 |
(*tail)->next=curr;
|
sl@0
|
432 |
curr->prev= *tail;
|
sl@0
|
433 |
curr->next=NULL;
|
sl@0
|
434 |
*tail=curr;
|
sl@0
|
435 |
}
|
sl@0
|
436 |
|
sl@0
|
437 |
static unsigned long ssl_cipher_get_disabled(void)
|
sl@0
|
438 |
{
|
sl@0
|
439 |
unsigned long mask;
|
sl@0
|
440 |
|
sl@0
|
441 |
mask = SSL_kFZA;
|
sl@0
|
442 |
#ifdef OPENSSL_NO_RSA
|
sl@0
|
443 |
mask |= SSL_aRSA|SSL_kRSA;
|
sl@0
|
444 |
#endif
|
sl@0
|
445 |
#ifdef OPENSSL_NO_DSA
|
sl@0
|
446 |
mask |= SSL_aDSS;
|
sl@0
|
447 |
#endif
|
sl@0
|
448 |
#ifdef OPENSSL_NO_DH
|
sl@0
|
449 |
mask |= SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH;
|
sl@0
|
450 |
#endif
|
sl@0
|
451 |
#ifdef OPENSSL_NO_KRB5
|
sl@0
|
452 |
mask |= SSL_kKRB5|SSL_aKRB5;
|
sl@0
|
453 |
#endif
|
sl@0
|
454 |
#ifdef OPENSSL_NO_ECDH
|
sl@0
|
455 |
mask |= SSL_kECDH|SSL_kECDHE;
|
sl@0
|
456 |
#endif
|
sl@0
|
457 |
#ifdef SSL_FORBID_ENULL
|
sl@0
|
458 |
mask |= SSL_eNULL;
|
sl@0
|
459 |
#endif
|
sl@0
|
460 |
|
sl@0
|
461 |
mask |= (ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL) ? SSL_DES :0;
|
sl@0
|
462 |
mask |= (ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL) ? SSL_3DES:0;
|
sl@0
|
463 |
mask |= (ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL) ? SSL_RC4 :0;
|
sl@0
|
464 |
mask |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0;
|
sl@0
|
465 |
mask |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0;
|
sl@0
|
466 |
mask |= (ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL) ? SSL_eFZA:0;
|
sl@0
|
467 |
mask |= (ssl_cipher_methods[SSL_ENC_AES128_IDX] == NULL) ? SSL_AES:0;
|
sl@0
|
468 |
|
sl@0
|
469 |
mask |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0;
|
sl@0
|
470 |
mask |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0;
|
sl@0
|
471 |
|
sl@0
|
472 |
return(mask);
|
sl@0
|
473 |
}
|
sl@0
|
474 |
|
sl@0
|
475 |
static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method,
|
sl@0
|
476 |
int num_of_ciphers, unsigned long mask, CIPHER_ORDER *co_list,
|
sl@0
|
477 |
CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
|
sl@0
|
478 |
{
|
sl@0
|
479 |
int i, co_list_num;
|
sl@0
|
480 |
SSL_CIPHER *c;
|
sl@0
|
481 |
|
sl@0
|
482 |
/*
|
sl@0
|
483 |
* We have num_of_ciphers descriptions compiled in, depending on the
|
sl@0
|
484 |
* method selected (SSLv2 and/or SSLv3, TLSv1 etc).
|
sl@0
|
485 |
* These will later be sorted in a linked list with at most num
|
sl@0
|
486 |
* entries.
|
sl@0
|
487 |
*/
|
sl@0
|
488 |
|
sl@0
|
489 |
/* Get the initial list of ciphers */
|
sl@0
|
490 |
co_list_num = 0; /* actual count of ciphers */
|
sl@0
|
491 |
for (i = 0; i < num_of_ciphers; i++)
|
sl@0
|
492 |
{
|
sl@0
|
493 |
c = ssl_method->get_cipher(i);
|
sl@0
|
494 |
/* drop those that use any of that is not available */
|
sl@0
|
495 |
if ((c != NULL) && c->valid && !(c->algorithms & mask))
|
sl@0
|
496 |
{
|
sl@0
|
497 |
co_list[co_list_num].cipher = c;
|
sl@0
|
498 |
co_list[co_list_num].next = NULL;
|
sl@0
|
499 |
co_list[co_list_num].prev = NULL;
|
sl@0
|
500 |
co_list[co_list_num].active = 0;
|
sl@0
|
501 |
co_list_num++;
|
sl@0
|
502 |
#ifdef KSSL_DEBUG
|
sl@0
|
503 |
printf("\t%d: %s %lx %lx\n",i,c->name,c->id,c->algorithms);
|
sl@0
|
504 |
#endif /* KSSL_DEBUG */
|
sl@0
|
505 |
/*
|
sl@0
|
506 |
if (!sk_push(ca_list,(char *)c)) goto err;
|
sl@0
|
507 |
*/
|
sl@0
|
508 |
}
|
sl@0
|
509 |
}
|
sl@0
|
510 |
|
sl@0
|
511 |
/*
|
sl@0
|
512 |
* Prepare linked list from list entries
|
sl@0
|
513 |
*/
|
sl@0
|
514 |
for (i = 1; i < co_list_num - 1; i++)
|
sl@0
|
515 |
{
|
sl@0
|
516 |
co_list[i].prev = &(co_list[i-1]);
|
sl@0
|
517 |
co_list[i].next = &(co_list[i+1]);
|
sl@0
|
518 |
}
|
sl@0
|
519 |
if (co_list_num > 0)
|
sl@0
|
520 |
{
|
sl@0
|
521 |
(*head_p) = &(co_list[0]);
|
sl@0
|
522 |
(*head_p)->prev = NULL;
|
sl@0
|
523 |
(*head_p)->next = &(co_list[1]);
|
sl@0
|
524 |
(*tail_p) = &(co_list[co_list_num - 1]);
|
sl@0
|
525 |
(*tail_p)->prev = &(co_list[co_list_num - 2]);
|
sl@0
|
526 |
(*tail_p)->next = NULL;
|
sl@0
|
527 |
}
|
sl@0
|
528 |
}
|
sl@0
|
529 |
|
sl@0
|
530 |
static void ssl_cipher_collect_aliases(SSL_CIPHER **ca_list,
|
sl@0
|
531 |
int num_of_group_aliases, unsigned long mask,
|
sl@0
|
532 |
CIPHER_ORDER *head)
|
sl@0
|
533 |
{
|
sl@0
|
534 |
CIPHER_ORDER *ciph_curr;
|
sl@0
|
535 |
SSL_CIPHER **ca_curr;
|
sl@0
|
536 |
int i;
|
sl@0
|
537 |
|
sl@0
|
538 |
/*
|
sl@0
|
539 |
* First, add the real ciphers as already collected
|
sl@0
|
540 |
*/
|
sl@0
|
541 |
ciph_curr = head;
|
sl@0
|
542 |
ca_curr = ca_list;
|
sl@0
|
543 |
while (ciph_curr != NULL)
|
sl@0
|
544 |
{
|
sl@0
|
545 |
*ca_curr = ciph_curr->cipher;
|
sl@0
|
546 |
ca_curr++;
|
sl@0
|
547 |
ciph_curr = ciph_curr->next;
|
sl@0
|
548 |
}
|
sl@0
|
549 |
|
sl@0
|
550 |
/*
|
sl@0
|
551 |
* Now we add the available ones from the cipher_aliases[] table.
|
sl@0
|
552 |
* They represent either an algorithm, that must be fully
|
sl@0
|
553 |
* supported (not match any bit in mask) or represent a cipher
|
sl@0
|
554 |
* strength value (will be added in any case because algorithms=0).
|
sl@0
|
555 |
*/
|
sl@0
|
556 |
for (i = 0; i < num_of_group_aliases; i++)
|
sl@0
|
557 |
{
|
sl@0
|
558 |
if ((i == 0) || /* always fetch "ALL" */
|
sl@0
|
559 |
!(cipher_aliases[i].algorithms & mask))
|
sl@0
|
560 |
{
|
sl@0
|
561 |
*ca_curr = (SSL_CIPHER *)(cipher_aliases + i);
|
sl@0
|
562 |
ca_curr++;
|
sl@0
|
563 |
}
|
sl@0
|
564 |
}
|
sl@0
|
565 |
|
sl@0
|
566 |
*ca_curr = NULL; /* end of list */
|
sl@0
|
567 |
}
|
sl@0
|
568 |
|
sl@0
|
569 |
static void ssl_cipher_apply_rule(unsigned long cipher_id, unsigned long ssl_version,
|
sl@0
|
570 |
unsigned long algorithms, unsigned long mask,
|
sl@0
|
571 |
unsigned long algo_strength, unsigned long mask_strength,
|
sl@0
|
572 |
int rule, int strength_bits, CIPHER_ORDER *co_list,
|
sl@0
|
573 |
CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
|
sl@0
|
574 |
{
|
sl@0
|
575 |
CIPHER_ORDER *head, *tail, *curr, *curr2, *tail2;
|
sl@0
|
576 |
SSL_CIPHER *cp;
|
sl@0
|
577 |
unsigned long ma, ma_s;
|
sl@0
|
578 |
|
sl@0
|
579 |
#ifdef CIPHER_DEBUG
|
sl@0
|
580 |
printf("Applying rule %d with %08lx %08lx %08lx %08lx (%d)\n",
|
sl@0
|
581 |
rule, algorithms, mask, algo_strength, mask_strength,
|
sl@0
|
582 |
strength_bits);
|
sl@0
|
583 |
#endif
|
sl@0
|
584 |
|
sl@0
|
585 |
curr = head = *head_p;
|
sl@0
|
586 |
curr2 = head;
|
sl@0
|
587 |
tail2 = tail = *tail_p;
|
sl@0
|
588 |
for (;;)
|
sl@0
|
589 |
{
|
sl@0
|
590 |
if ((curr == NULL) || (curr == tail2)) break;
|
sl@0
|
591 |
curr = curr2;
|
sl@0
|
592 |
curr2 = curr->next;
|
sl@0
|
593 |
|
sl@0
|
594 |
cp = curr->cipher;
|
sl@0
|
595 |
|
sl@0
|
596 |
/* If explicit cipher suite, match only that one for its own protocol version.
|
sl@0
|
597 |
* Usual selection criteria will be used for similar ciphersuites from other version! */
|
sl@0
|
598 |
|
sl@0
|
599 |
if (cipher_id && (cp->algorithms & SSL_SSL_MASK) == ssl_version)
|
sl@0
|
600 |
{
|
sl@0
|
601 |
if (cp->id != cipher_id)
|
sl@0
|
602 |
continue;
|
sl@0
|
603 |
}
|
sl@0
|
604 |
|
sl@0
|
605 |
/*
|
sl@0
|
606 |
* Selection criteria is either the number of strength_bits
|
sl@0
|
607 |
* or the algorithm used.
|
sl@0
|
608 |
*/
|
sl@0
|
609 |
else if (strength_bits == -1)
|
sl@0
|
610 |
{
|
sl@0
|
611 |
ma = mask & cp->algorithms;
|
sl@0
|
612 |
ma_s = mask_strength & cp->algo_strength;
|
sl@0
|
613 |
|
sl@0
|
614 |
#ifdef CIPHER_DEBUG
|
sl@0
|
615 |
printf("\nName: %s:\nAlgo = %08lx Algo_strength = %08lx\nMask = %08lx Mask_strength %08lx\n", cp->name, cp->algorithms, cp->algo_strength, mask, mask_strength);
|
sl@0
|
616 |
printf("ma = %08lx ma_s %08lx, ma&algo=%08lx, ma_s&algos=%08lx\n", ma, ma_s, ma&algorithms, ma_s&algo_strength);
|
sl@0
|
617 |
#endif
|
sl@0
|
618 |
/*
|
sl@0
|
619 |
* Select: if none of the mask bit was met from the
|
sl@0
|
620 |
* cipher or not all of the bits were met, the
|
sl@0
|
621 |
* selection does not apply.
|
sl@0
|
622 |
*/
|
sl@0
|
623 |
if (((ma == 0) && (ma_s == 0)) ||
|
sl@0
|
624 |
((ma & algorithms) != ma) ||
|
sl@0
|
625 |
((ma_s & algo_strength) != ma_s))
|
sl@0
|
626 |
continue; /* does not apply */
|
sl@0
|
627 |
}
|
sl@0
|
628 |
else if (strength_bits != cp->strength_bits)
|
sl@0
|
629 |
continue; /* does not apply */
|
sl@0
|
630 |
|
sl@0
|
631 |
#ifdef CIPHER_DEBUG
|
sl@0
|
632 |
printf("Action = %d\n", rule);
|
sl@0
|
633 |
#endif
|
sl@0
|
634 |
|
sl@0
|
635 |
/* add the cipher if it has not been added yet. */
|
sl@0
|
636 |
if (rule == CIPHER_ADD)
|
sl@0
|
637 |
{
|
sl@0
|
638 |
if (!curr->active)
|
sl@0
|
639 |
{
|
sl@0
|
640 |
int add_this_cipher = 1;
|
sl@0
|
641 |
|
sl@0
|
642 |
if (((cp->algorithms & (SSL_kECDHE|SSL_kECDH|SSL_aECDSA)) != 0))
|
sl@0
|
643 |
{
|
sl@0
|
644 |
/* Make sure "ECCdraft" ciphersuites are activated only if
|
sl@0
|
645 |
* *explicitly* requested, but not implicitly (such as
|
sl@0
|
646 |
* as part of the "AES" alias). */
|
sl@0
|
647 |
|
sl@0
|
648 |
add_this_cipher = (mask & (SSL_kECDHE|SSL_kECDH|SSL_aECDSA)) != 0 || cipher_id != 0;
|
sl@0
|
649 |
}
|
sl@0
|
650 |
|
sl@0
|
651 |
if (add_this_cipher)
|
sl@0
|
652 |
{
|
sl@0
|
653 |
ll_append_tail(&head, curr, &tail);
|
sl@0
|
654 |
curr->active = 1;
|
sl@0
|
655 |
}
|
sl@0
|
656 |
}
|
sl@0
|
657 |
}
|
sl@0
|
658 |
/* Move the added cipher to this location */
|
sl@0
|
659 |
else if (rule == CIPHER_ORD)
|
sl@0
|
660 |
{
|
sl@0
|
661 |
if (curr->active)
|
sl@0
|
662 |
{
|
sl@0
|
663 |
ll_append_tail(&head, curr, &tail);
|
sl@0
|
664 |
}
|
sl@0
|
665 |
}
|
sl@0
|
666 |
else if (rule == CIPHER_DEL)
|
sl@0
|
667 |
curr->active = 0;
|
sl@0
|
668 |
else if (rule == CIPHER_KILL)
|
sl@0
|
669 |
{
|
sl@0
|
670 |
if (head == curr)
|
sl@0
|
671 |
head = curr->next;
|
sl@0
|
672 |
else
|
sl@0
|
673 |
curr->prev->next = curr->next;
|
sl@0
|
674 |
if (tail == curr)
|
sl@0
|
675 |
tail = curr->prev;
|
sl@0
|
676 |
curr->active = 0;
|
sl@0
|
677 |
if (curr->next != NULL)
|
sl@0
|
678 |
curr->next->prev = curr->prev;
|
sl@0
|
679 |
if (curr->prev != NULL)
|
sl@0
|
680 |
curr->prev->next = curr->next;
|
sl@0
|
681 |
curr->next = NULL;
|
sl@0
|
682 |
curr->prev = NULL;
|
sl@0
|
683 |
}
|
sl@0
|
684 |
}
|
sl@0
|
685 |
|
sl@0
|
686 |
*head_p = head;
|
sl@0
|
687 |
*tail_p = tail;
|
sl@0
|
688 |
}
|
sl@0
|
689 |
|
sl@0
|
690 |
static int ssl_cipher_strength_sort(CIPHER_ORDER *co_list,
|
sl@0
|
691 |
CIPHER_ORDER **head_p,
|
sl@0
|
692 |
CIPHER_ORDER **tail_p)
|
sl@0
|
693 |
{
|
sl@0
|
694 |
int max_strength_bits, i, *number_uses;
|
sl@0
|
695 |
CIPHER_ORDER *curr;
|
sl@0
|
696 |
|
sl@0
|
697 |
/*
|
sl@0
|
698 |
* This routine sorts the ciphers with descending strength. The sorting
|
sl@0
|
699 |
* must keep the pre-sorted sequence, so we apply the normal sorting
|
sl@0
|
700 |
* routine as '+' movement to the end of the list.
|
sl@0
|
701 |
*/
|
sl@0
|
702 |
max_strength_bits = 0;
|
sl@0
|
703 |
curr = *head_p;
|
sl@0
|
704 |
while (curr != NULL)
|
sl@0
|
705 |
{
|
sl@0
|
706 |
if (curr->active &&
|
sl@0
|
707 |
(curr->cipher->strength_bits > max_strength_bits))
|
sl@0
|
708 |
max_strength_bits = curr->cipher->strength_bits;
|
sl@0
|
709 |
curr = curr->next;
|
sl@0
|
710 |
}
|
sl@0
|
711 |
|
sl@0
|
712 |
number_uses = OPENSSL_malloc((max_strength_bits + 1) * sizeof(int));
|
sl@0
|
713 |
if (!number_uses)
|
sl@0
|
714 |
{
|
sl@0
|
715 |
SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT,ERR_R_MALLOC_FAILURE);
|
sl@0
|
716 |
return(0);
|
sl@0
|
717 |
}
|
sl@0
|
718 |
memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int));
|
sl@0
|
719 |
|
sl@0
|
720 |
/*
|
sl@0
|
721 |
* Now find the strength_bits values actually used
|
sl@0
|
722 |
*/
|
sl@0
|
723 |
curr = *head_p;
|
sl@0
|
724 |
while (curr != NULL)
|
sl@0
|
725 |
{
|
sl@0
|
726 |
if (curr->active)
|
sl@0
|
727 |
number_uses[curr->cipher->strength_bits]++;
|
sl@0
|
728 |
curr = curr->next;
|
sl@0
|
729 |
}
|
sl@0
|
730 |
/*
|
sl@0
|
731 |
* Go through the list of used strength_bits values in descending
|
sl@0
|
732 |
* order.
|
sl@0
|
733 |
*/
|
sl@0
|
734 |
for (i = max_strength_bits; i >= 0; i--)
|
sl@0
|
735 |
if (number_uses[i] > 0)
|
sl@0
|
736 |
ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, CIPHER_ORD, i,
|
sl@0
|
737 |
co_list, head_p, tail_p);
|
sl@0
|
738 |
|
sl@0
|
739 |
OPENSSL_free(number_uses);
|
sl@0
|
740 |
return(1);
|
sl@0
|
741 |
}
|
sl@0
|
742 |
|
sl@0
|
743 |
static int ssl_cipher_process_rulestr(const char *rule_str,
|
sl@0
|
744 |
CIPHER_ORDER *co_list, CIPHER_ORDER **head_p,
|
sl@0
|
745 |
CIPHER_ORDER **tail_p, SSL_CIPHER **ca_list)
|
sl@0
|
746 |
{
|
sl@0
|
747 |
unsigned long algorithms, mask, algo_strength, mask_strength;
|
sl@0
|
748 |
const char *l, *start, *buf;
|
sl@0
|
749 |
int j, multi, found, rule, retval, ok, buflen;
|
sl@0
|
750 |
unsigned long cipher_id = 0, ssl_version = 0;
|
sl@0
|
751 |
char ch;
|
sl@0
|
752 |
|
sl@0
|
753 |
retval = 1;
|
sl@0
|
754 |
l = rule_str;
|
sl@0
|
755 |
for (;;)
|
sl@0
|
756 |
{
|
sl@0
|
757 |
ch = *l;
|
sl@0
|
758 |
|
sl@0
|
759 |
if (ch == '\0')
|
sl@0
|
760 |
break; /* done */
|
sl@0
|
761 |
if (ch == '-')
|
sl@0
|
762 |
{ rule = CIPHER_DEL; l++; }
|
sl@0
|
763 |
else if (ch == '+')
|
sl@0
|
764 |
{ rule = CIPHER_ORD; l++; }
|
sl@0
|
765 |
else if (ch == '!')
|
sl@0
|
766 |
{ rule = CIPHER_KILL; l++; }
|
sl@0
|
767 |
else if (ch == '@')
|
sl@0
|
768 |
{ rule = CIPHER_SPECIAL; l++; }
|
sl@0
|
769 |
else
|
sl@0
|
770 |
{ rule = CIPHER_ADD; }
|
sl@0
|
771 |
|
sl@0
|
772 |
if (ITEM_SEP(ch))
|
sl@0
|
773 |
{
|
sl@0
|
774 |
l++;
|
sl@0
|
775 |
continue;
|
sl@0
|
776 |
}
|
sl@0
|
777 |
|
sl@0
|
778 |
algorithms = mask = algo_strength = mask_strength = 0;
|
sl@0
|
779 |
|
sl@0
|
780 |
start=l;
|
sl@0
|
781 |
for (;;)
|
sl@0
|
782 |
{
|
sl@0
|
783 |
ch = *l;
|
sl@0
|
784 |
buf = l;
|
sl@0
|
785 |
buflen = 0;
|
sl@0
|
786 |
#ifndef CHARSET_EBCDIC
|
sl@0
|
787 |
while ( ((ch >= 'A') && (ch <= 'Z')) ||
|
sl@0
|
788 |
((ch >= '0') && (ch <= '9')) ||
|
sl@0
|
789 |
((ch >= 'a') && (ch <= 'z')) ||
|
sl@0
|
790 |
(ch == '-'))
|
sl@0
|
791 |
#else
|
sl@0
|
792 |
while ( isalnum(ch) || (ch == '-'))
|
sl@0
|
793 |
#endif
|
sl@0
|
794 |
{
|
sl@0
|
795 |
ch = *(++l);
|
sl@0
|
796 |
buflen++;
|
sl@0
|
797 |
}
|
sl@0
|
798 |
|
sl@0
|
799 |
if (buflen == 0)
|
sl@0
|
800 |
{
|
sl@0
|
801 |
/*
|
sl@0
|
802 |
* We hit something we cannot deal with,
|
sl@0
|
803 |
* it is no command or separator nor
|
sl@0
|
804 |
* alphanumeric, so we call this an error.
|
sl@0
|
805 |
*/
|
sl@0
|
806 |
SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
|
sl@0
|
807 |
SSL_R_INVALID_COMMAND);
|
sl@0
|
808 |
retval = found = 0;
|
sl@0
|
809 |
l++;
|
sl@0
|
810 |
break;
|
sl@0
|
811 |
}
|
sl@0
|
812 |
|
sl@0
|
813 |
if (rule == CIPHER_SPECIAL)
|
sl@0
|
814 |
{
|
sl@0
|
815 |
found = 0; /* unused -- avoid compiler warning */
|
sl@0
|
816 |
break; /* special treatment */
|
sl@0
|
817 |
}
|
sl@0
|
818 |
|
sl@0
|
819 |
/* check for multi-part specification */
|
sl@0
|
820 |
if (ch == '+')
|
sl@0
|
821 |
{
|
sl@0
|
822 |
multi=1;
|
sl@0
|
823 |
l++;
|
sl@0
|
824 |
}
|
sl@0
|
825 |
else
|
sl@0
|
826 |
multi=0;
|
sl@0
|
827 |
|
sl@0
|
828 |
/*
|
sl@0
|
829 |
* Now search for the cipher alias in the ca_list. Be careful
|
sl@0
|
830 |
* with the strncmp, because the "buflen" limitation
|
sl@0
|
831 |
* will make the rule "ADH:SOME" and the cipher
|
sl@0
|
832 |
* "ADH-MY-CIPHER" look like a match for buflen=3.
|
sl@0
|
833 |
* So additionally check whether the cipher name found
|
sl@0
|
834 |
* has the correct length. We can save a strlen() call:
|
sl@0
|
835 |
* just checking for the '\0' at the right place is
|
sl@0
|
836 |
* sufficient, we have to strncmp() anyway. (We cannot
|
sl@0
|
837 |
* use strcmp(), because buf is not '\0' terminated.)
|
sl@0
|
838 |
*/
|
sl@0
|
839 |
j = found = 0;
|
sl@0
|
840 |
cipher_id = 0;
|
sl@0
|
841 |
ssl_version = 0;
|
sl@0
|
842 |
|
sl@0
|
843 |
while (ca_list[j])
|
sl@0
|
844 |
{
|
sl@0
|
845 |
if (!strncmp(buf, ca_list[j]->name, buflen) &&
|
sl@0
|
846 |
(ca_list[j]->name[buflen] == '\0'))
|
sl@0
|
847 |
{
|
sl@0
|
848 |
found = 1;
|
sl@0
|
849 |
break;
|
sl@0
|
850 |
}
|
sl@0
|
851 |
else
|
sl@0
|
852 |
j++;
|
sl@0
|
853 |
}
|
sl@0
|
854 |
if (!found)
|
sl@0
|
855 |
break; /* ignore this entry */
|
sl@0
|
856 |
|
sl@0
|
857 |
/* New algorithms:
|
sl@0
|
858 |
* 1 - any old restrictions apply outside new mask
|
sl@0
|
859 |
* 2 - any new restrictions apply outside old mask
|
sl@0
|
860 |
* 3 - enforce old & new where masks intersect
|
sl@0
|
861 |
*/
|
sl@0
|
862 |
algorithms = (algorithms & ~ca_list[j]->mask) | /* 1 */
|
sl@0
|
863 |
(ca_list[j]->algorithms & ~mask) | /* 2 */
|
sl@0
|
864 |
(algorithms & ca_list[j]->algorithms); /* 3 */
|
sl@0
|
865 |
mask |= ca_list[j]->mask;
|
sl@0
|
866 |
algo_strength = (algo_strength & ~ca_list[j]->mask_strength) |
|
sl@0
|
867 |
(ca_list[j]->algo_strength & ~mask_strength) |
|
sl@0
|
868 |
(algo_strength & ca_list[j]->algo_strength);
|
sl@0
|
869 |
mask_strength |= ca_list[j]->mask_strength;
|
sl@0
|
870 |
|
sl@0
|
871 |
/* explicit ciphersuite found */
|
sl@0
|
872 |
if (ca_list[j]->valid)
|
sl@0
|
873 |
{
|
sl@0
|
874 |
cipher_id = ca_list[j]->id;
|
sl@0
|
875 |
ssl_version = ca_list[j]->algorithms & SSL_SSL_MASK;
|
sl@0
|
876 |
break;
|
sl@0
|
877 |
}
|
sl@0
|
878 |
|
sl@0
|
879 |
if (!multi) break;
|
sl@0
|
880 |
}
|
sl@0
|
881 |
|
sl@0
|
882 |
/*
|
sl@0
|
883 |
* Ok, we have the rule, now apply it
|
sl@0
|
884 |
*/
|
sl@0
|
885 |
if (rule == CIPHER_SPECIAL)
|
sl@0
|
886 |
{ /* special command */
|
sl@0
|
887 |
ok = 0;
|
sl@0
|
888 |
if ((buflen == 8) &&
|
sl@0
|
889 |
!strncmp(buf, "STRENGTH", 8))
|
sl@0
|
890 |
ok = ssl_cipher_strength_sort(co_list,
|
sl@0
|
891 |
head_p, tail_p);
|
sl@0
|
892 |
else
|
sl@0
|
893 |
SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
|
sl@0
|
894 |
SSL_R_INVALID_COMMAND);
|
sl@0
|
895 |
if (ok == 0)
|
sl@0
|
896 |
retval = 0;
|
sl@0
|
897 |
/*
|
sl@0
|
898 |
* We do not support any "multi" options
|
sl@0
|
899 |
* together with "@", so throw away the
|
sl@0
|
900 |
* rest of the command, if any left, until
|
sl@0
|
901 |
* end or ':' is found.
|
sl@0
|
902 |
*/
|
sl@0
|
903 |
while ((*l != '\0') && !ITEM_SEP(*l))
|
sl@0
|
904 |
l++;
|
sl@0
|
905 |
}
|
sl@0
|
906 |
else if (found)
|
sl@0
|
907 |
{
|
sl@0
|
908 |
ssl_cipher_apply_rule(cipher_id, ssl_version, algorithms, mask,
|
sl@0
|
909 |
algo_strength, mask_strength, rule, -1,
|
sl@0
|
910 |
co_list, head_p, tail_p);
|
sl@0
|
911 |
}
|
sl@0
|
912 |
else
|
sl@0
|
913 |
{
|
sl@0
|
914 |
while ((*l != '\0') && !ITEM_SEP(*l))
|
sl@0
|
915 |
l++;
|
sl@0
|
916 |
}
|
sl@0
|
917 |
if (*l == '\0') break; /* done */
|
sl@0
|
918 |
}
|
sl@0
|
919 |
|
sl@0
|
920 |
return(retval);
|
sl@0
|
921 |
}
|
sl@0
|
922 |
|
sl@0
|
923 |
STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
|
sl@0
|
924 |
STACK_OF(SSL_CIPHER) **cipher_list,
|
sl@0
|
925 |
STACK_OF(SSL_CIPHER) **cipher_list_by_id,
|
sl@0
|
926 |
const char *rule_str)
|
sl@0
|
927 |
{
|
sl@0
|
928 |
int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases;
|
sl@0
|
929 |
unsigned long disabled_mask;
|
sl@0
|
930 |
STACK_OF(SSL_CIPHER) *cipherstack, *tmp_cipher_list;
|
sl@0
|
931 |
const char *rule_p;
|
sl@0
|
932 |
CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr;
|
sl@0
|
933 |
SSL_CIPHER **ca_list = NULL;
|
sl@0
|
934 |
|
sl@0
|
935 |
/*
|
sl@0
|
936 |
* Return with error if nothing to do.
|
sl@0
|
937 |
*/
|
sl@0
|
938 |
if (rule_str == NULL || cipher_list == NULL || cipher_list_by_id == NULL)
|
sl@0
|
939 |
return NULL;
|
sl@0
|
940 |
|
sl@0
|
941 |
/*
|
sl@0
|
942 |
* To reduce the work to do we only want to process the compiled
|
sl@0
|
943 |
* in algorithms, so we first get the mask of disabled ciphers.
|
sl@0
|
944 |
*/
|
sl@0
|
945 |
disabled_mask = ssl_cipher_get_disabled();
|
sl@0
|
946 |
|
sl@0
|
947 |
/*
|
sl@0
|
948 |
* Now we have to collect the available ciphers from the compiled
|
sl@0
|
949 |
* in ciphers. We cannot get more than the number compiled in, so
|
sl@0
|
950 |
* it is used for allocation.
|
sl@0
|
951 |
*/
|
sl@0
|
952 |
num_of_ciphers = ssl_method->num_ciphers();
|
sl@0
|
953 |
#ifdef KSSL_DEBUG
|
sl@0
|
954 |
printf("ssl_create_cipher_list() for %d ciphers\n", num_of_ciphers);
|
sl@0
|
955 |
#endif /* KSSL_DEBUG */
|
sl@0
|
956 |
co_list = (CIPHER_ORDER *)OPENSSL_malloc(sizeof(CIPHER_ORDER) * num_of_ciphers);
|
sl@0
|
957 |
if (co_list == NULL)
|
sl@0
|
958 |
{
|
sl@0
|
959 |
SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
|
sl@0
|
960 |
return(NULL); /* Failure */
|
sl@0
|
961 |
}
|
sl@0
|
962 |
|
sl@0
|
963 |
ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, disabled_mask,
|
sl@0
|
964 |
co_list, &head, &tail);
|
sl@0
|
965 |
|
sl@0
|
966 |
/*
|
sl@0
|
967 |
* We also need cipher aliases for selecting based on the rule_str.
|
sl@0
|
968 |
* There might be two types of entries in the rule_str: 1) names
|
sl@0
|
969 |
* of ciphers themselves 2) aliases for groups of ciphers.
|
sl@0
|
970 |
* For 1) we need the available ciphers and for 2) the cipher
|
sl@0
|
971 |
* groups of cipher_aliases added together in one list (otherwise
|
sl@0
|
972 |
* we would be happy with just the cipher_aliases table).
|
sl@0
|
973 |
*/
|
sl@0
|
974 |
num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER);
|
sl@0
|
975 |
num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
|
sl@0
|
976 |
ca_list =
|
sl@0
|
977 |
(SSL_CIPHER **)OPENSSL_malloc(sizeof(SSL_CIPHER *) * num_of_alias_max);
|
sl@0
|
978 |
if (ca_list == NULL)
|
sl@0
|
979 |
{
|
sl@0
|
980 |
OPENSSL_free(co_list);
|
sl@0
|
981 |
SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
|
sl@0
|
982 |
return(NULL); /* Failure */
|
sl@0
|
983 |
}
|
sl@0
|
984 |
ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, disabled_mask,
|
sl@0
|
985 |
head);
|
sl@0
|
986 |
|
sl@0
|
987 |
/*
|
sl@0
|
988 |
* If the rule_string begins with DEFAULT, apply the default rule
|
sl@0
|
989 |
* before using the (possibly available) additional rules.
|
sl@0
|
990 |
*/
|
sl@0
|
991 |
ok = 1;
|
sl@0
|
992 |
rule_p = rule_str;
|
sl@0
|
993 |
if (strncmp(rule_str,"DEFAULT",7) == 0)
|
sl@0
|
994 |
{
|
sl@0
|
995 |
ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST,
|
sl@0
|
996 |
co_list, &head, &tail, ca_list);
|
sl@0
|
997 |
rule_p += 7;
|
sl@0
|
998 |
if (*rule_p == ':')
|
sl@0
|
999 |
rule_p++;
|
sl@0
|
1000 |
}
|
sl@0
|
1001 |
|
sl@0
|
1002 |
if (ok && (strlen(rule_p) > 0))
|
sl@0
|
1003 |
ok = ssl_cipher_process_rulestr(rule_p, co_list, &head, &tail,
|
sl@0
|
1004 |
ca_list);
|
sl@0
|
1005 |
|
sl@0
|
1006 |
OPENSSL_free(ca_list); /* Not needed anymore */
|
sl@0
|
1007 |
|
sl@0
|
1008 |
if (!ok)
|
sl@0
|
1009 |
{ /* Rule processing failure */
|
sl@0
|
1010 |
OPENSSL_free(co_list);
|
sl@0
|
1011 |
return(NULL);
|
sl@0
|
1012 |
}
|
sl@0
|
1013 |
/*
|
sl@0
|
1014 |
* Allocate new "cipherstack" for the result, return with error
|
sl@0
|
1015 |
* if we cannot get one.
|
sl@0
|
1016 |
*/
|
sl@0
|
1017 |
if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL)
|
sl@0
|
1018 |
{
|
sl@0
|
1019 |
OPENSSL_free(co_list);
|
sl@0
|
1020 |
return(NULL);
|
sl@0
|
1021 |
}
|
sl@0
|
1022 |
|
sl@0
|
1023 |
/*
|
sl@0
|
1024 |
* The cipher selection for the list is done. The ciphers are added
|
sl@0
|
1025 |
* to the resulting precedence to the STACK_OF(SSL_CIPHER).
|
sl@0
|
1026 |
*/
|
sl@0
|
1027 |
for (curr = head; curr != NULL; curr = curr->next)
|
sl@0
|
1028 |
{
|
sl@0
|
1029 |
if (curr->active)
|
sl@0
|
1030 |
{
|
sl@0
|
1031 |
sk_SSL_CIPHER_push(cipherstack, curr->cipher);
|
sl@0
|
1032 |
#ifdef CIPHER_DEBUG
|
sl@0
|
1033 |
printf("<%s>\n",curr->cipher->name);
|
sl@0
|
1034 |
#endif
|
sl@0
|
1035 |
}
|
sl@0
|
1036 |
}
|
sl@0
|
1037 |
OPENSSL_free(co_list); /* Not needed any longer */
|
sl@0
|
1038 |
|
sl@0
|
1039 |
tmp_cipher_list = sk_SSL_CIPHER_dup(cipherstack);
|
sl@0
|
1040 |
if (tmp_cipher_list == NULL)
|
sl@0
|
1041 |
{
|
sl@0
|
1042 |
sk_SSL_CIPHER_free(cipherstack);
|
sl@0
|
1043 |
return NULL;
|
sl@0
|
1044 |
}
|
sl@0
|
1045 |
if (*cipher_list != NULL)
|
sl@0
|
1046 |
sk_SSL_CIPHER_free(*cipher_list);
|
sl@0
|
1047 |
*cipher_list = cipherstack;
|
sl@0
|
1048 |
if (*cipher_list_by_id != NULL)
|
sl@0
|
1049 |
sk_SSL_CIPHER_free(*cipher_list_by_id);
|
sl@0
|
1050 |
*cipher_list_by_id = tmp_cipher_list;
|
sl@0
|
1051 |
(void)sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp);
|
sl@0
|
1052 |
|
sl@0
|
1053 |
return(cipherstack);
|
sl@0
|
1054 |
}
|
sl@0
|
1055 |
|
sl@0
|
1056 |
EXPORT_C char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len)
|
sl@0
|
1057 |
{
|
sl@0
|
1058 |
int is_export,pkl,kl;
|
sl@0
|
1059 |
const char *ver,*exp_str;
|
sl@0
|
1060 |
const char *kx,*au,*enc,*mac;
|
sl@0
|
1061 |
unsigned long alg,alg2,alg_s;
|
sl@0
|
1062 |
#ifndef EMULATOR
|
sl@0
|
1063 |
#ifdef KSSL_DEBUG
|
sl@0
|
1064 |
static const char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s AL=%lx\n";
|
sl@0
|
1065 |
#else
|
sl@0
|
1066 |
static const char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n";
|
sl@0
|
1067 |
#endif /* KSSL_DEBUG */
|
sl@0
|
1068 |
#else /* EMULATOR */
|
sl@0
|
1069 |
#ifdef KSSL_DEBUG
|
sl@0
|
1070 |
static const char *const format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s AL=%lx\n";
|
sl@0
|
1071 |
#else
|
sl@0
|
1072 |
static const char *const format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n";
|
sl@0
|
1073 |
#endif /* KSSL_DEBUG */
|
sl@0
|
1074 |
|
sl@0
|
1075 |
#endif /* EMULATOR */
|
sl@0
|
1076 |
alg=cipher->algorithms;
|
sl@0
|
1077 |
alg_s=cipher->algo_strength;
|
sl@0
|
1078 |
alg2=cipher->algorithm2;
|
sl@0
|
1079 |
|
sl@0
|
1080 |
is_export=SSL_C_IS_EXPORT(cipher);
|
sl@0
|
1081 |
pkl=SSL_C_EXPORT_PKEYLENGTH(cipher);
|
sl@0
|
1082 |
kl=SSL_C_EXPORT_KEYLENGTH(cipher);
|
sl@0
|
1083 |
exp_str=is_export?" export":"";
|
sl@0
|
1084 |
|
sl@0
|
1085 |
if (alg & SSL_SSLV2)
|
sl@0
|
1086 |
ver="SSLv2";
|
sl@0
|
1087 |
else if (alg & SSL_SSLV3)
|
sl@0
|
1088 |
ver="SSLv3";
|
sl@0
|
1089 |
else
|
sl@0
|
1090 |
ver="unknown";
|
sl@0
|
1091 |
|
sl@0
|
1092 |
switch (alg&SSL_MKEY_MASK)
|
sl@0
|
1093 |
{
|
sl@0
|
1094 |
case SSL_kRSA:
|
sl@0
|
1095 |
kx=is_export?(pkl == 512 ? "RSA(512)" : "RSA(1024)"):"RSA";
|
sl@0
|
1096 |
break;
|
sl@0
|
1097 |
case SSL_kDHr:
|
sl@0
|
1098 |
kx="DH/RSA";
|
sl@0
|
1099 |
break;
|
sl@0
|
1100 |
case SSL_kDHd:
|
sl@0
|
1101 |
kx="DH/DSS";
|
sl@0
|
1102 |
break;
|
sl@0
|
1103 |
case SSL_kKRB5: /* VRS */
|
sl@0
|
1104 |
case SSL_KRB5: /* VRS */
|
sl@0
|
1105 |
kx="KRB5";
|
sl@0
|
1106 |
break;
|
sl@0
|
1107 |
case SSL_kFZA:
|
sl@0
|
1108 |
kx="Fortezza";
|
sl@0
|
1109 |
break;
|
sl@0
|
1110 |
case SSL_kEDH:
|
sl@0
|
1111 |
kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH";
|
sl@0
|
1112 |
break;
|
sl@0
|
1113 |
case SSL_kECDH:
|
sl@0
|
1114 |
case SSL_kECDHE:
|
sl@0
|
1115 |
kx=is_export?"ECDH(<=163)":"ECDH";
|
sl@0
|
1116 |
break;
|
sl@0
|
1117 |
default:
|
sl@0
|
1118 |
kx="unknown";
|
sl@0
|
1119 |
}
|
sl@0
|
1120 |
|
sl@0
|
1121 |
switch (alg&SSL_AUTH_MASK)
|
sl@0
|
1122 |
{
|
sl@0
|
1123 |
case SSL_aRSA:
|
sl@0
|
1124 |
au="RSA";
|
sl@0
|
1125 |
break;
|
sl@0
|
1126 |
case SSL_aDSS:
|
sl@0
|
1127 |
au="DSS";
|
sl@0
|
1128 |
break;
|
sl@0
|
1129 |
case SSL_aDH:
|
sl@0
|
1130 |
au="DH";
|
sl@0
|
1131 |
break;
|
sl@0
|
1132 |
case SSL_aKRB5: /* VRS */
|
sl@0
|
1133 |
case SSL_KRB5: /* VRS */
|
sl@0
|
1134 |
au="KRB5";
|
sl@0
|
1135 |
break;
|
sl@0
|
1136 |
case SSL_aFZA:
|
sl@0
|
1137 |
case SSL_aNULL:
|
sl@0
|
1138 |
au="None";
|
sl@0
|
1139 |
break;
|
sl@0
|
1140 |
case SSL_aECDSA:
|
sl@0
|
1141 |
au="ECDSA";
|
sl@0
|
1142 |
break;
|
sl@0
|
1143 |
default:
|
sl@0
|
1144 |
au="unknown";
|
sl@0
|
1145 |
break;
|
sl@0
|
1146 |
}
|
sl@0
|
1147 |
|
sl@0
|
1148 |
switch (alg&SSL_ENC_MASK)
|
sl@0
|
1149 |
{
|
sl@0
|
1150 |
case SSL_DES:
|
sl@0
|
1151 |
enc=(is_export && kl == 5)?"DES(40)":"DES(56)";
|
sl@0
|
1152 |
break;
|
sl@0
|
1153 |
case SSL_3DES:
|
sl@0
|
1154 |
enc="3DES(168)";
|
sl@0
|
1155 |
break;
|
sl@0
|
1156 |
case SSL_RC4:
|
sl@0
|
1157 |
enc=is_export?(kl == 5 ? "RC4(40)" : "RC4(56)")
|
sl@0
|
1158 |
:((alg2&SSL2_CF_8_BYTE_ENC)?"RC4(64)":"RC4(128)");
|
sl@0
|
1159 |
break;
|
sl@0
|
1160 |
case SSL_RC2:
|
sl@0
|
1161 |
enc=is_export?(kl == 5 ? "RC2(40)" : "RC2(56)"):"RC2(128)";
|
sl@0
|
1162 |
break;
|
sl@0
|
1163 |
case SSL_IDEA:
|
sl@0
|
1164 |
enc="IDEA(128)";
|
sl@0
|
1165 |
break;
|
sl@0
|
1166 |
case SSL_eFZA:
|
sl@0
|
1167 |
enc="Fortezza";
|
sl@0
|
1168 |
break;
|
sl@0
|
1169 |
case SSL_eNULL:
|
sl@0
|
1170 |
enc="None";
|
sl@0
|
1171 |
break;
|
sl@0
|
1172 |
case SSL_AES:
|
sl@0
|
1173 |
switch(cipher->strength_bits)
|
sl@0
|
1174 |
{
|
sl@0
|
1175 |
case 128: enc="AES(128)"; break;
|
sl@0
|
1176 |
case 192: enc="AES(192)"; break;
|
sl@0
|
1177 |
case 256: enc="AES(256)"; break;
|
sl@0
|
1178 |
default: enc="AES(?""?""?)"; break;
|
sl@0
|
1179 |
}
|
sl@0
|
1180 |
break;
|
sl@0
|
1181 |
default:
|
sl@0
|
1182 |
enc="unknown";
|
sl@0
|
1183 |
break;
|
sl@0
|
1184 |
}
|
sl@0
|
1185 |
|
sl@0
|
1186 |
switch (alg&SSL_MAC_MASK)
|
sl@0
|
1187 |
{
|
sl@0
|
1188 |
case SSL_MD5:
|
sl@0
|
1189 |
mac="MD5";
|
sl@0
|
1190 |
break;
|
sl@0
|
1191 |
case SSL_SHA1:
|
sl@0
|
1192 |
mac="SHA1";
|
sl@0
|
1193 |
break;
|
sl@0
|
1194 |
default:
|
sl@0
|
1195 |
mac="unknown";
|
sl@0
|
1196 |
break;
|
sl@0
|
1197 |
}
|
sl@0
|
1198 |
|
sl@0
|
1199 |
if (buf == NULL)
|
sl@0
|
1200 |
{
|
sl@0
|
1201 |
len=128;
|
sl@0
|
1202 |
buf=OPENSSL_malloc(len);
|
sl@0
|
1203 |
if (buf == NULL) return("OPENSSL_malloc Error");
|
sl@0
|
1204 |
}
|
sl@0
|
1205 |
else if (len < 128)
|
sl@0
|
1206 |
return("Buffer too small");
|
sl@0
|
1207 |
|
sl@0
|
1208 |
#ifdef KSSL_DEBUG
|
sl@0
|
1209 |
BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp_str,alg);
|
sl@0
|
1210 |
#else
|
sl@0
|
1211 |
BIO_snprintf(buf,len,format,cipher->name,ver,kx,au,enc,mac,exp_str);
|
sl@0
|
1212 |
#endif /* KSSL_DEBUG */
|
sl@0
|
1213 |
return(buf);
|
sl@0
|
1214 |
}
|
sl@0
|
1215 |
|
sl@0
|
1216 |
EXPORT_C char *SSL_CIPHER_get_version(const SSL_CIPHER *c)
|
sl@0
|
1217 |
{
|
sl@0
|
1218 |
int i;
|
sl@0
|
1219 |
|
sl@0
|
1220 |
if (c == NULL) return("(NONE)");
|
sl@0
|
1221 |
i=(int)(c->id>>24L);
|
sl@0
|
1222 |
if (i == 3)
|
sl@0
|
1223 |
return("TLSv1/SSLv3");
|
sl@0
|
1224 |
else if (i == 2)
|
sl@0
|
1225 |
return("SSLv2");
|
sl@0
|
1226 |
else
|
sl@0
|
1227 |
return("unknown");
|
sl@0
|
1228 |
}
|
sl@0
|
1229 |
|
sl@0
|
1230 |
/* return the actual cipher being used */
|
sl@0
|
1231 |
EXPORT_C const char *SSL_CIPHER_get_name(const SSL_CIPHER *c)
|
sl@0
|
1232 |
{
|
sl@0
|
1233 |
if (c != NULL)
|
sl@0
|
1234 |
return(c->name);
|
sl@0
|
1235 |
return("(NONE)");
|
sl@0
|
1236 |
}
|
sl@0
|
1237 |
|
sl@0
|
1238 |
/* number of bits for symmetric cipher */
|
sl@0
|
1239 |
EXPORT_C int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits)
|
sl@0
|
1240 |
{
|
sl@0
|
1241 |
int ret=0;
|
sl@0
|
1242 |
|
sl@0
|
1243 |
if (c != NULL)
|
sl@0
|
1244 |
{
|
sl@0
|
1245 |
if (alg_bits != NULL) *alg_bits = c->alg_bits;
|
sl@0
|
1246 |
ret = c->strength_bits;
|
sl@0
|
1247 |
}
|
sl@0
|
1248 |
return(ret);
|
sl@0
|
1249 |
}
|
sl@0
|
1250 |
|
sl@0
|
1251 |
SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n)
|
sl@0
|
1252 |
{
|
sl@0
|
1253 |
SSL_COMP *ctmp;
|
sl@0
|
1254 |
int i,nn;
|
sl@0
|
1255 |
|
sl@0
|
1256 |
if ((n == 0) || (sk == NULL)) return(NULL);
|
sl@0
|
1257 |
nn=sk_SSL_COMP_num(sk);
|
sl@0
|
1258 |
for (i=0; i<nn; i++)
|
sl@0
|
1259 |
{
|
sl@0
|
1260 |
ctmp=sk_SSL_COMP_value(sk,i);
|
sl@0
|
1261 |
if (ctmp->id == n)
|
sl@0
|
1262 |
return(ctmp);
|
sl@0
|
1263 |
}
|
sl@0
|
1264 |
return(NULL);
|
sl@0
|
1265 |
}
|
sl@0
|
1266 |
|
sl@0
|
1267 |
#ifdef OPENSSL_NO_COMP
|
sl@0
|
1268 |
EXPORT_C void *SSL_COMP_get_compression_methods(void)
|
sl@0
|
1269 |
{
|
sl@0
|
1270 |
return NULL;
|
sl@0
|
1271 |
}
|
sl@0
|
1272 |
EXPORT_C int SSL_COMP_add_compression_method(int id, void *cm)
|
sl@0
|
1273 |
{
|
sl@0
|
1274 |
return 1;
|
sl@0
|
1275 |
}
|
sl@0
|
1276 |
|
sl@0
|
1277 |
EXPORT_C const char *SSL_COMP_get_name(const void *comp)
|
sl@0
|
1278 |
{
|
sl@0
|
1279 |
return NULL;
|
sl@0
|
1280 |
}
|
sl@0
|
1281 |
#else
|
sl@0
|
1282 |
EXPORT_C STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void)
|
sl@0
|
1283 |
{
|
sl@0
|
1284 |
load_builtin_compressions();
|
sl@0
|
1285 |
return(ssl_comp_methods);
|
sl@0
|
1286 |
}
|
sl@0
|
1287 |
|
sl@0
|
1288 |
EXPORT_C int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)
|
sl@0
|
1289 |
{
|
sl@0
|
1290 |
SSL_COMP *comp;
|
sl@0
|
1291 |
|
sl@0
|
1292 |
if (cm == NULL || cm->type == NID_undef)
|
sl@0
|
1293 |
return 1;
|
sl@0
|
1294 |
|
sl@0
|
1295 |
/* According to draft-ietf-tls-compression-04.txt, the
|
sl@0
|
1296 |
compression number ranges should be the following:
|
sl@0
|
1297 |
|
sl@0
|
1298 |
0 to 63: methods defined by the IETF
|
sl@0
|
1299 |
64 to 192: external party methods assigned by IANA
|
sl@0
|
1300 |
193 to 255: reserved for private use */
|
sl@0
|
1301 |
if (id < 193 || id > 255)
|
sl@0
|
1302 |
{
|
sl@0
|
1303 |
SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE);
|
sl@0
|
1304 |
return 0;
|
sl@0
|
1305 |
}
|
sl@0
|
1306 |
|
sl@0
|
1307 |
MemCheck_off();
|
sl@0
|
1308 |
comp=(SSL_COMP *)OPENSSL_malloc(sizeof(SSL_COMP));
|
sl@0
|
1309 |
comp->id=id;
|
sl@0
|
1310 |
comp->method=cm;
|
sl@0
|
1311 |
load_builtin_compressions();
|
sl@0
|
1312 |
if (ssl_comp_methods
|
sl@0
|
1313 |
&& !sk_SSL_COMP_find(ssl_comp_methods,comp))
|
sl@0
|
1314 |
{
|
sl@0
|
1315 |
OPENSSL_free(comp);
|
sl@0
|
1316 |
MemCheck_on();
|
sl@0
|
1317 |
SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,SSL_R_DUPLICATE_COMPRESSION_ID);
|
sl@0
|
1318 |
return(1);
|
sl@0
|
1319 |
}
|
sl@0
|
1320 |
else if ((ssl_comp_methods == NULL)
|
sl@0
|
1321 |
|| !sk_SSL_COMP_push(ssl_comp_methods,comp))
|
sl@0
|
1322 |
{
|
sl@0
|
1323 |
OPENSSL_free(comp);
|
sl@0
|
1324 |
MemCheck_on();
|
sl@0
|
1325 |
SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE);
|
sl@0
|
1326 |
return(1);
|
sl@0
|
1327 |
}
|
sl@0
|
1328 |
else
|
sl@0
|
1329 |
{
|
sl@0
|
1330 |
MemCheck_on();
|
sl@0
|
1331 |
return(0);
|
sl@0
|
1332 |
}
|
sl@0
|
1333 |
}
|
sl@0
|
1334 |
|
sl@0
|
1335 |
EXPORT_C const char *SSL_COMP_get_name(const COMP_METHOD *comp)
|
sl@0
|
1336 |
{
|
sl@0
|
1337 |
if (comp)
|
sl@0
|
1338 |
return comp->name;
|
sl@0
|
1339 |
return NULL;
|
sl@0
|
1340 |
}
|
sl@0
|
1341 |
|
sl@0
|
1342 |
#endif
|