summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2000-10-25 15:23:17 +0000
committercvs2svn <admin@example.com>2000-10-25 15:23:17 +0000
commit690af28bdf827ab9c81648f507eb492c9076d5d3 (patch)
tree1ced1775de07c13c2a5a1d9e3bde843578ac541d /src/lib/libssl/ssl
parent463e714935b9651a5eb2c08fcf3f8844fc6b653d (diff)
downloadopenbsd-OPENBSD_2_8.tar.gz
openbsd-OPENBSD_2_8.tar.bz2
openbsd-OPENBSD_2_8.zip
This commit was manufactured by cvs2git to create branch 'OPENBSD_2_8'.OPENBSD_2_8
Diffstat (limited to '')
-rw-r--r--src/lib/libssl/ssl.h1533
-rw-r--r--src/lib/libssl/ssl2.h265
-rw-r--r--src/lib/libssl/ssl23.h83
-rw-r--r--src/lib/libssl/ssl3.h426
-rw-r--r--src/lib/libssl/ssl_algs.c103
-rw-r--r--src/lib/libssl/ssl_asn1.c349
-rw-r--r--src/lib/libssl/ssl_cert.c753
-rw-r--r--src/lib/libssl/ssl_ciph.c1069
-rw-r--r--src/lib/libssl/ssl_err.c430
-rw-r--r--src/lib/libssl/ssl_err2.c70
-rw-r--r--src/lib/libssl/ssl_lib.c2061
-rw-r--r--src/lib/libssl/ssl_locl.h555
-rw-r--r--src/lib/libssl/ssl_rsa.c815
-rw-r--r--src/lib/libssl/ssl_sess.c680
-rw-r--r--src/lib/libssl/ssl_stat.c454
-rw-r--r--src/lib/libssl/ssl_txt.c176
16 files changed, 0 insertions, 9822 deletions
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
deleted file mode 100644
index bb846f491c..0000000000
--- a/src/lib/libssl/ssl.h
+++ /dev/null
@@ -1,1533 +0,0 @@
1/* ssl/ssl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#ifndef HEADER_SSL_H
60#define HEADER_SSL_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#include <openssl/safestack.h>
67
68/* SSLeay version number for ASN.1 encoding of the session information */
69/* Version 0 - initial version
70 * Version 1 - added the optional peer certificate
71 */
72#define SSL_SESSION_ASN1_VERSION 0x0001
73
74/* text strings for the ciphers */
75#define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5
76#define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5
77#define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5
78#define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5
79#define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5
80#define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5
81#define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5
82#define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA
83#define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5
84#define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA
85
86#define SSL_MAX_SSL_SESSION_ID_LENGTH 32
87#define SSL_MAX_SID_CTX_LENGTH 32
88
89#define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8)
90#define SSL_MAX_KEY_ARG_LENGTH 8
91#define SSL_MAX_MASTER_KEY_LENGTH 48
92
93/* These are used to specify which ciphers to use and not to use */
94#define SSL_TXT_LOW "LOW"
95#define SSL_TXT_MEDIUM "MEDIUM"
96#define SSL_TXT_HIGH "HIGH"
97#define SSL_TXT_kFZA "kFZA"
98#define SSL_TXT_aFZA "aFZA"
99#define SSL_TXT_eFZA "eFZA"
100#define SSL_TXT_FZA "FZA"
101
102#define SSL_TXT_aNULL "aNULL"
103#define SSL_TXT_eNULL "eNULL"
104#define SSL_TXT_NULL "NULL"
105
106#define SSL_TXT_kRSA "kRSA"
107#define SSL_TXT_kDHr "kDHr"
108#define SSL_TXT_kDHd "kDHd"
109#define SSL_TXT_kEDH "kEDH"
110#define SSL_TXT_aRSA "aRSA"
111#define SSL_TXT_aDSS "aDSS"
112#define SSL_TXT_aDH "aDH"
113#define SSL_TXT_DSS "DSS"
114#define SSL_TXT_DH "DH"
115#define SSL_TXT_EDH "EDH"
116#define SSL_TXT_ADH "ADH"
117#define SSL_TXT_RSA "RSA"
118#define SSL_TXT_DES "DES"
119#define SSL_TXT_3DES "3DES"
120#define SSL_TXT_RC4 "RC4"
121#define SSL_TXT_RC2 "RC2"
122#define SSL_TXT_IDEA "IDEA"
123#define SSL_TXT_MD5 "MD5"
124#define SSL_TXT_SHA1 "SHA1"
125#define SSL_TXT_SHA "SHA"
126#define SSL_TXT_EXP "EXP"
127#define SSL_TXT_EXPORT "EXPORT"
128#define SSL_TXT_EXP40 "EXPORT40"
129#define SSL_TXT_EXP56 "EXPORT56"
130#define SSL_TXT_SSLV2 "SSLv2"
131#define SSL_TXT_SSLV3 "SSLv3"
132#define SSL_TXT_TLSV1 "TLSv1"
133#define SSL_TXT_ALL "ALL"
134
135/* 'DEFAULT' at the start of the cipher list insert the following string
136 * in addition to this being the default cipher string */
137#define SSL_DEFAULT_CIPHER_LIST "ALL:!ADH:RC4+RSA:+SSLv2:@STRENGTH"
138
139/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
140#define SSL_SENT_SHUTDOWN 1
141#define SSL_RECEIVED_SHUTDOWN 2
142
143#include <openssl/crypto.h>
144#include <openssl/lhash.h>
145#include <openssl/buffer.h>
146#include <openssl/bio.h>
147#include <openssl/pem.h>
148#include <openssl/x509.h>
149
150#if (defined(NO_RSA) || defined(NO_MD5)) && !defined(NO_SSL2)
151#define NO_SSL2
152#endif
153
154#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1
155#define SSL_FILETYPE_PEM X509_FILETYPE_PEM
156
157/* This is needed to stop compilers complaining about the
158 * 'struct ssl_st *' function parameters used to prototype callbacks
159 * in SSL_CTX. */
160typedef struct ssl_st *ssl_crock_st;
161
162/* used to hold info on the particular ciphers used */
163typedef struct ssl_cipher_st
164 {
165 int valid;
166 const char *name; /* text name */
167 unsigned long id; /* id, 4 bytes, first is version */
168 unsigned long algorithms; /* what ciphers are used */
169 unsigned long algo_strength; /* strength and export flags */
170 unsigned long algorithm2; /* Extra flags */
171 int strength_bits; /* Number of bits really used */
172 int alg_bits; /* Number of bits for algorithm */
173 unsigned long mask; /* used for matching */
174 unsigned long mask_strength; /* also used for matching */
175 } SSL_CIPHER;
176
177DECLARE_STACK_OF(SSL_CIPHER)
178
179typedef struct ssl_st SSL;
180typedef struct ssl_ctx_st SSL_CTX;
181
182/* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
183typedef struct ssl_method_st
184 {
185 int version;
186 int (*ssl_new)(SSL *s);
187 void (*ssl_clear)(SSL *s);
188 void (*ssl_free)(SSL *s);
189 int (*ssl_accept)(SSL *s);
190 int (*ssl_connect)(SSL *s);
191 int (*ssl_read)(SSL *s,void *buf,int len);
192 int (*ssl_peek)(SSL *s,char *buf,int len);
193 int (*ssl_write)(SSL *s,const void *buf,int len);
194 int (*ssl_shutdown)(SSL *s);
195 int (*ssl_renegotiate)(SSL *s);
196 int (*ssl_renegotiate_check)(SSL *s);
197 long (*ssl_ctrl)(SSL *s,int cmd,long larg,char *parg);
198 long (*ssl_ctx_ctrl)(SSL_CTX *ctx,int cmd,long larg,char *parg);
199 SSL_CIPHER *(*get_cipher_by_char)(const unsigned char *ptr);
200 int (*put_cipher_by_char)(const SSL_CIPHER *cipher,unsigned char *ptr);
201 int (*ssl_pending)(SSL *s);
202 int (*num_ciphers)(void);
203 SSL_CIPHER *(*get_cipher)(unsigned ncipher);
204 struct ssl_method_st *(*get_ssl_method)(int version);
205 long (*get_timeout)(void);
206 struct ssl3_enc_method *ssl3_enc; /* Extra SSLv3/TLS stuff */
207 int (*ssl_version)();
208 long (*ssl_callback_ctrl)(SSL *s, int cb_id, void (*fp)());
209 long (*ssl_ctx_callback_ctrl)(SSL_CTX *s, int cb_id, void (*fp)());
210 } SSL_METHOD;
211
212/* Lets make this into an ASN.1 type structure as follows
213 * SSL_SESSION_ID ::= SEQUENCE {
214 * version INTEGER, -- structure version number
215 * SSLversion INTEGER, -- SSL version number
216 * Cipher OCTET_STRING, -- the 3 byte cipher ID
217 * Session_ID OCTET_STRING, -- the Session ID
218 * Master_key OCTET_STRING, -- the master key
219 * Key_Arg [ 0 ] IMPLICIT OCTET_STRING, -- the optional Key argument
220 * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time
221 * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds
222 * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate
223 * Session_ID_context [ 4 ] EXPLICIT OCTET_STRING, -- the Session ID context
224 * Verify_result [ 5 ] EXPLICIT INTEGER -- X509_V_... code for `Peer'
225 * Compression [6] IMPLICIT ASN1_OBJECT -- compression OID XXXXX
226 * }
227 * Look in ssl/ssl_asn1.c for more details
228 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
229 */
230typedef struct ssl_session_st
231 {
232 int ssl_version; /* what ssl version session info is
233 * being kept in here? */
234
235 /* only really used in SSLv2 */
236 unsigned int key_arg_length;
237 unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH];
238 int master_key_length;
239 unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
240 /* session_id - valid? */
241 unsigned int session_id_length;
242 unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
243 /* this is used to determine whether the session is being reused in
244 * the appropriate context. It is up to the application to set this,
245 * via SSL_new */
246 unsigned int sid_ctx_length;
247 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
248
249 int not_resumable;
250
251 /* The cert is the certificate used to establish this connection */
252 struct sess_cert_st /* SESS_CERT */ *sess_cert;
253
254 /* This is the cert for the other end.
255 * On clients, it will be the same as sess_cert->peer_key->x509
256 * (the latter is not enough as sess_cert is not retained
257 * in the external representation of sessions, see ssl_asn1.c). */
258 X509 *peer;
259 /* when app_verify_callback accepts a session where the peer's certificate
260 * is not ok, we must remember the error for session reuse: */
261 long verify_result; /* only for servers */
262
263 int references;
264 long timeout;
265 long time;
266
267 int compress_meth; /* Need to lookup the method */
268
269 SSL_CIPHER *cipher;
270 unsigned long cipher_id; /* when ASN.1 loaded, this
271 * needs to be used to load
272 * the 'cipher' structure */
273
274 STACK_OF(SSL_CIPHER) *ciphers; /* shared ciphers? */
275
276 CRYPTO_EX_DATA ex_data; /* application specific data */
277
278 /* These are used to make removal of session-ids more
279 * efficient and to implement a maximum cache size. */
280 struct ssl_session_st *prev,*next;
281 } SSL_SESSION;
282
283#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x00000001L
284#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x00000002L
285#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x00000008L
286#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x00000010L
287#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x00000020L
288#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x00000040L
289#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x00000080L
290#define SSL_OP_TLS_D5_BUG 0x00000100L
291#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x00000200L
292#define SSL_OP_TLS_ROLLBACK_BUG 0x00000400L
293
294/* If set, always create a new key when using tmp_dh parameters */
295#define SSL_OP_SINGLE_DH_USE 0x00100000L
296/* Set to also use the tmp_rsa key when doing RSA operations. */
297#define SSL_OP_EPHEMERAL_RSA 0x00200000L
298
299/* The next flag deliberately changes the ciphertest, this is a check
300 * for the PKCS#1 attack */
301#define SSL_OP_PKCS1_CHECK_1 0x08000000L
302#define SSL_OP_PKCS1_CHECK_2 0x10000000L
303#define SSL_OP_NETSCAPE_CA_DN_BUG 0x20000000L
304/* SSL_OP_NON_EXPORT_FIRST looks utterly broken .. */
305#define SSL_OP_NON_EXPORT_FIRST 0x40000000L
306#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x80000000L
307#define SSL_OP_ALL 0x000FFFFFL
308
309#define SSL_OP_NO_SSLv2 0x01000000L
310#define SSL_OP_NO_SSLv3 0x02000000L
311#define SSL_OP_NO_TLSv1 0x04000000L
312
313/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
314 * when just a single record has been written): */
315#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L
316/* Make it possible to retry SSL_write() with changed buffer location
317 * (buffer contents must stay the same!); this is not the default to avoid
318 * the misconception that non-blocking SSL_write() behaves like
319 * non-blocking write(): */
320#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
321
322/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
323 * they cannot be used to clear bits. */
324
325#define SSL_CTX_set_options(ctx,op) \
326 SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,op,NULL)
327#define SSL_CTX_get_options(ctx) \
328 SSL_CTX_ctrl(ctx,SSL_CTRL_OPTIONS,0,NULL)
329#define SSL_set_options(ssl,op) \
330 SSL_ctrl(ssl,SSL_CTRL_OPTIONS,op,NULL)
331#define SSL_get_options(ssl) \
332 SSL_ctrl(ssl,SSL_CTRL_OPTIONS,0,NULL)
333
334#define SSL_CTX_set_mode(ctx,op) \
335 SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,op,NULL)
336#define SSL_CTX_get_mode(ctx) \
337 SSL_CTX_ctrl(ctx,SSL_CTRL_MODE,0,NULL)
338#define SSL_set_mode(ssl,op) \
339 SSL_ctrl(ssl,SSL_CTRL_MODE,op,NULL)
340#define SSL_get_mode(ssl) \
341 SSL_ctrl(ssl,SSL_CTRL_MODE,0,NULL)
342
343#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20)
344
345typedef struct ssl_comp_st
346{
347 int id;
348 char *name;
349#ifdef HEADER_COMP_H
350 COMP_METHOD *method;
351#else
352 char *method;
353#endif
354} SSL_COMP;
355
356DECLARE_STACK_OF(SSL_COMP)
357
358struct ssl_ctx_st
359 {
360 SSL_METHOD *method;
361 unsigned long options;
362 unsigned long mode;
363
364 STACK_OF(SSL_CIPHER) *cipher_list;
365 /* same as above but sorted for lookup */
366 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
367
368 struct x509_store_st /* X509_STORE */ *cert_store;
369 struct lhash_st /* LHASH */ *sessions; /* a set of SSL_SESSIONs */
370 /* Most session-ids that will be cached, default is
371 * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */
372 unsigned long session_cache_size;
373 struct ssl_session_st *session_cache_head;
374 struct ssl_session_st *session_cache_tail;
375
376 /* This can have one of 2 values, ored together,
377 * SSL_SESS_CACHE_CLIENT,
378 * SSL_SESS_CACHE_SERVER,
379 * Default is SSL_SESSION_CACHE_SERVER, which means only
380 * SSL_accept which cache SSL_SESSIONS. */
381 int session_cache_mode;
382
383 /* If timeout is not 0, it is the default timeout value set
384 * when SSL_new() is called. This has been put in to make
385 * life easier to set things up */
386 long session_timeout;
387
388 /* If this callback is not null, it will be called each
389 * time a session id is added to the cache. If this function
390 * returns 1, it means that the callback will do a
391 * SSL_SESSION_free() when it has finished using it. Otherwise,
392 * on 0, it means the callback has finished with it.
393 * If remove_session_cb is not null, it will be called when
394 * a session-id is removed from the cache. After the call,
395 * OpenSSL will SSL_SESSION_free() it. */
396 int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess);
397 void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess);
398 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
399 unsigned char *data,int len,int *copy);
400 struct
401 {
402 int sess_connect; /* SSL new conn - started */
403 int sess_connect_renegotiate;/* SSL reneg - requested */
404 int sess_connect_good; /* SSL new conne/reneg - finished */
405 int sess_accept; /* SSL new accept - started */
406 int sess_accept_renegotiate;/* SSL reneg - requested */
407 int sess_accept_good; /* SSL accept/reneg - finished */
408 int sess_miss; /* session lookup misses */
409 int sess_timeout; /* reuse attempt on timeouted session */
410 int sess_cache_full; /* session removed due to full cache */
411 int sess_hit; /* session reuse actually done */
412 int sess_cb_hit; /* session-id that was not
413 * in the cache was
414 * passed back via the callback. This
415 * indicates that the application is
416 * supplying session-id's from other
417 * processes - spooky :-) */
418 } stats;
419
420 int references;
421
422/**/ void (*info_callback)();
423
424 /* if defined, these override the X509_verify_cert() calls */
425/**/ int (*app_verify_callback)();
426/**/ char *app_verify_arg; /* never used; should be void * */
427
428 /* default values to use in SSL structures */
429/**/ struct cert_st /* CERT */ *cert;
430/**/ int read_ahead;
431/**/ int verify_mode;
432/**/ int verify_depth;
433/**/ unsigned int sid_ctx_length;
434/**/ unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
435/**/ int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx);
436
437 int purpose; /* Purpose setting */
438 int trust; /* Trust setting */
439
440 /* Default password callback. */
441/**/ pem_password_cb *default_passwd_callback;
442
443 /* Default password callback user data. */
444/**/ void *default_passwd_callback_userdata;
445
446 /* get client cert callback */
447/**/ int (*client_cert_cb)(/* SSL *ssl, X509 **x509, EVP_PKEY **pkey */);
448
449 /* what we put in client cert requests */
450 STACK_OF(X509_NAME) *client_CA;
451
452/**/ int quiet_shutdown;
453
454 CRYPTO_EX_DATA ex_data;
455
456 const EVP_MD *rsa_md5;/* For SSLv2 - name is 'ssl2-md5' */
457 const EVP_MD *md5; /* For SSLv3/TLSv1 'ssl3-md5' */
458 const EVP_MD *sha1; /* For SSLv3/TLSv1 'ssl3->sha1' */
459
460 STACK_OF(X509) *extra_certs;
461 STACK_OF(SSL_COMP) *comp_methods; /* stack of SSL_COMP, SSLv3/TLSv1 */
462 };
463
464#define SSL_SESS_CACHE_OFF 0x0000
465#define SSL_SESS_CACHE_CLIENT 0x0001
466#define SSL_SESS_CACHE_SERVER 0x0002
467#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
468#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080
469/* This one, when set, makes the server session-id lookup not look
470 * in the cache. If there is an application get_session callback
471 * defined, this will still get called. */
472#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100
473
474 struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx);
475#define SSL_CTX_sess_number(ctx) \
476 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
477#define SSL_CTX_sess_connect(ctx) \
478 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
479#define SSL_CTX_sess_connect_good(ctx) \
480 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
481#define SSL_CTX_sess_connect_renegotiate(ctx) \
482 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
483#define SSL_CTX_sess_accept(ctx) \
484 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
485#define SSL_CTX_sess_accept_renegotiate(ctx) \
486 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
487#define SSL_CTX_sess_accept_good(ctx) \
488 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
489#define SSL_CTX_sess_hits(ctx) \
490 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
491#define SSL_CTX_sess_cb_hits(ctx) \
492 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
493#define SSL_CTX_sess_misses(ctx) \
494 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
495#define SSL_CTX_sess_timeouts(ctx) \
496 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
497#define SSL_CTX_sess_cache_full(ctx) \
498 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)
499
500#define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb))
501#define SSL_CTX_sess_get_new_cb(ctx) ((ctx)->new_session_cb)
502#define SSL_CTX_sess_set_remove_cb(ctx,cb) ((ctx)->remove_session_cb=(cb))
503#define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb)
504#define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb))
505#define SSL_CTX_sess_get_get_cb(ctx) ((ctx)->get_session_cb)
506#define SSL_CTX_set_info_callback(ctx,cb) ((ctx)->info_callback=(cb))
507#define SSL_CTX_get_info_callback(ctx) ((ctx)->info_callback)
508#define SSL_CTX_set_client_cert_cb(ctx,cb) ((ctx)->client_cert_cb=(cb))
509#define SSL_CTX_get_client_cert_cb(ctx) ((ctx)->client_cert_cb)
510
511#define SSL_NOTHING 1
512#define SSL_WRITING 2
513#define SSL_READING 3
514#define SSL_X509_LOOKUP 4
515
516/* These will only be used when doing non-blocking IO */
517#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING)
518#define SSL_want_read(s) (SSL_want(s) == SSL_READING)
519#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING)
520#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP)
521
522struct ssl_st
523 {
524 /* protocol version
525 * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION)
526 */
527 int version;
528 int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
529
530 SSL_METHOD *method; /* SSLv3 */
531
532 /* There are 2 BIO's even though they are normally both the
533 * same. This is so data can be read and written to different
534 * handlers */
535
536#ifdef HEADER_BIO_H
537 BIO *rbio; /* used by SSL_read */
538 BIO *wbio; /* used by SSL_write */
539 BIO *bbio; /* used during session-id reuse to concatinate
540 * messages */
541#else
542 char *rbio; /* used by SSL_read */
543 char *wbio; /* used by SSL_write */
544 char *bbio;
545#endif
546 /* This holds a variable that indicates what we were doing
547 * when a 0 or -1 is returned. This is needed for
548 * non-blocking IO so we know what request needs re-doing when
549 * in SSL_accept or SSL_connect */
550 int rwstate;
551
552 /* true when we are actually in SSL_accept() or SSL_connect() */
553 int in_handshake;
554 int (*handshake_func)();
555
556 /* Imagine that here's a boolean member "init" that is
557 * switched as soon as SSL_set_{accept/connect}_state
558 * is called for the first time, so that "state" and
559 * "handshake_func" are properly initialized. But as
560 * handshake_func is == 0 until then, we use this
561 * test instead of an "init" member.
562 */
563
564 int server; /* are we the server side? - mostly used by SSL_clear*/
565
566 int new_session;/* 1 if we are to use a new session */
567 int quiet_shutdown;/* don't send shutdown packets */
568 int shutdown; /* we have shut things down, 0x01 sent, 0x02
569 * for received */
570 int state; /* where we are */
571 int rstate; /* where we are when reading */
572
573 BUF_MEM *init_buf; /* buffer used during init */
574 int init_num; /* amount read/written */
575 int init_off; /* amount read/written */
576
577 /* used internally to point at a raw packet */
578 unsigned char *packet;
579 unsigned int packet_length;
580
581 struct ssl2_state_st *s2; /* SSLv2 variables */
582 struct ssl3_state_st *s3; /* SSLv3 variables */
583
584 int read_ahead; /* Read as many input bytes as possible
585 * (for non-blocking reads) */
586 int hit; /* reusing a previous session */
587
588 int purpose; /* Purpose setting */
589 int trust; /* Trust setting */
590
591 /* crypto */
592 STACK_OF(SSL_CIPHER) *cipher_list;
593 STACK_OF(SSL_CIPHER) *cipher_list_by_id;
594
595 /* These are the ones being used, the ones in SSL_SESSION are
596 * the ones to be 'copied' into these ones */
597
598 EVP_CIPHER_CTX *enc_read_ctx; /* cryptographic state */
599 const EVP_MD *read_hash; /* used for mac generation */
600#ifdef HEADER_COMP_H
601 COMP_CTX *expand; /* uncompress */
602#else
603 char *expand;
604#endif
605
606 EVP_CIPHER_CTX *enc_write_ctx; /* cryptographic state */
607 const EVP_MD *write_hash; /* used for mac generation */
608#ifdef HEADER_COMP_H
609 COMP_CTX *compress; /* compression */
610#else
611 char *compress;
612#endif
613
614 /* session info */
615
616 /* client cert? */
617 /* This is used to hold the server certificate used */
618 struct cert_st /* CERT */ *cert;
619
620 /* the session_id_context is used to ensure sessions are only reused
621 * in the appropriate context */
622 unsigned int sid_ctx_length;
623 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
624
625 /* This can also be in the session once a session is established */
626 SSL_SESSION *session;
627
628 /* Used in SSL2 and SSL3 */
629 int verify_mode; /* 0 don't care about verify failure.
630 * 1 fail if verify fails */
631 int verify_depth;
632 int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */
633 void (*info_callback)(); /* optional informational callback */
634
635 int error; /* error bytes to be written */
636 int error_code; /* actual code */
637
638 SSL_CTX *ctx;
639 /* set this flag to 1 and a sleep(1) is put into all SSL_read()
640 * and SSL_write() calls, good for nbio debuging :-) */
641 int debug;
642
643 /* extra application data */
644 long verify_result;
645 CRYPTO_EX_DATA ex_data;
646
647 /* for server side, keep the list of CA_dn we can use */
648 STACK_OF(X509_NAME) *client_CA;
649
650 int references;
651 unsigned long options; /* protocol behaviour */
652 unsigned long mode; /* API behaviour */
653 int first_packet;
654 int client_version; /* what was passed, used for
655 * SSLv3/TLS rollback check */
656 };
657
658#include <openssl/ssl2.h>
659#include <openssl/ssl3.h>
660#include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */
661#include <openssl/ssl23.h>
662
663/* compatibility */
664#define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg))
665#define SSL_get_app_data(s) (SSL_get_ex_data(s,0))
666#define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a))
667#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0))
668#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0))
669#define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg))
670
671/* The following are the possible values for ssl->state are are
672 * used to indicate where we are up to in the SSL connection establishment.
673 * The macros that follow are about the only things you should need to use
674 * and even then, only when using non-blocking IO.
675 * It can also be useful to work out where you were when the connection
676 * failed */
677
678#define SSL_ST_CONNECT 0x1000
679#define SSL_ST_ACCEPT 0x2000
680#define SSL_ST_MASK 0x0FFF
681#define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT)
682#define SSL_ST_BEFORE 0x4000
683#define SSL_ST_OK 0x03
684#define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT)
685
686#define SSL_CB_LOOP 0x01
687#define SSL_CB_EXIT 0x02
688#define SSL_CB_READ 0x04
689#define SSL_CB_WRITE 0x08
690#define SSL_CB_ALERT 0x4000 /* used in callback */
691#define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
692#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
693#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
694#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
695#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
696#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
697#define SSL_CB_HANDSHAKE_START 0x10
698#define SSL_CB_HANDSHAKE_DONE 0x20
699
700/* Is the SSL_connection established? */
701#define SSL_get_state(a) SSL_state(a)
702#define SSL_is_init_finished(a) (SSL_state(a) == SSL_ST_OK)
703#define SSL_in_init(a) (SSL_state(a)&SSL_ST_INIT)
704#define SSL_in_before(a) (SSL_state(a)&SSL_ST_BEFORE)
705#define SSL_in_connect_init(a) (SSL_state(a)&SSL_ST_CONNECT)
706#define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT)
707
708/* The following 2 states are kept in ssl->rstate when reads fail,
709 * you should not need these */
710#define SSL_ST_READ_HEADER 0xF0
711#define SSL_ST_READ_BODY 0xF1
712#define SSL_ST_READ_DONE 0xF2
713
714/* Obtain latest Finished message
715 * -- that we sent (SSL_get_finished)
716 * -- that we expected from peer (SSL_get_peer_finished).
717 * Returns length (0 == no Finished so far), copies up to 'count' bytes. */
718size_t SSL_get_finished(SSL *s, void *buf, size_t count);
719size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count);
720
721/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options
722 * are 'ored' with SSL_VERIFY_PEER if they are desired */
723#define SSL_VERIFY_NONE 0x00
724#define SSL_VERIFY_PEER 0x01
725#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
726#define SSL_VERIFY_CLIENT_ONCE 0x04
727
728#define OpenSSL_add_ssl_algorithms() SSL_library_init()
729#define SSLeay_add_ssl_algorithms() SSL_library_init()
730
731/* this is for backward compatibility */
732#if 0 /* NEW_SSLEAY */
733#define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c)
734#define SSL_set_pref_cipher(c,n) SSL_set_cipher_list(c,n)
735#define SSL_add_session(a,b) SSL_CTX_add_session((a),(b))
736#define SSL_remove_session(a,b) SSL_CTX_remove_session((a),(b))
737#define SSL_flush_sessions(a,b) SSL_CTX_flush_sessions((a),(b))
738#endif
739/* More backward compatibility */
740#define SSL_get_cipher(s) \
741 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
742#define SSL_get_cipher_bits(s,np) \
743 SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
744#define SSL_get_cipher_version(s) \
745 SSL_CIPHER_get_version(SSL_get_current_cipher(s))
746#define SSL_get_cipher_name(s) \
747 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
748#define SSL_get_time(a) SSL_SESSION_get_time(a)
749#define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b))
750#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a)
751#define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b))
752
753#if 1 /*SSLEAY_MACROS*/
754#define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \
755 (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \
756 (bp),(unsigned char **)(s_id))
757#define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \
758 bp,(unsigned char *)s_id)
759#define PEM_read_SSL_SESSION(fp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read( \
760 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb,u)
761#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
762 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
763#define PEM_write_SSL_SESSION(fp,x) \
764 PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
765 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL,NULL)
766#define PEM_write_bio_SSL_SESSION(bp,x) \
767 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
768 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
769#endif
770
771#define SSL_AD_REASON_OFFSET 1000
772/* These alert types are for SSLv3 and TLSv1 */
773#define SSL_AD_CLOSE_NOTIFY SSL3_AD_CLOSE_NOTIFY
774#define SSL_AD_UNEXPECTED_MESSAGE SSL3_AD_UNEXPECTED_MESSAGE /* fatal */
775#define SSL_AD_BAD_RECORD_MAC SSL3_AD_BAD_RECORD_MAC /* fatal */
776#define SSL_AD_DECRYPTION_FAILED TLS1_AD_DECRYPTION_FAILED
777#define SSL_AD_RECORD_OVERFLOW TLS1_AD_RECORD_OVERFLOW
778#define SSL_AD_DECOMPRESSION_FAILURE SSL3_AD_DECOMPRESSION_FAILURE/* fatal */
779#define SSL_AD_HANDSHAKE_FAILURE SSL3_AD_HANDSHAKE_FAILURE/* fatal */
780#define SSL_AD_NO_CERTIFICATE SSL3_AD_NO_CERTIFICATE /* Not for TLS */
781#define SSL_AD_BAD_CERTIFICATE SSL3_AD_BAD_CERTIFICATE
782#define SSL_AD_UNSUPPORTED_CERTIFICATE SSL3_AD_UNSUPPORTED_CERTIFICATE
783#define SSL_AD_CERTIFICATE_REVOKED SSL3_AD_CERTIFICATE_REVOKED
784#define SSL_AD_CERTIFICATE_EXPIRED SSL3_AD_CERTIFICATE_EXPIRED
785#define SSL_AD_CERTIFICATE_UNKNOWN SSL3_AD_CERTIFICATE_UNKNOWN
786#define SSL_AD_ILLEGAL_PARAMETER SSL3_AD_ILLEGAL_PARAMETER /* fatal */
787#define SSL_AD_UNKNOWN_CA TLS1_AD_UNKNOWN_CA /* fatal */
788#define SSL_AD_ACCESS_DENIED TLS1_AD_ACCESS_DENIED /* fatal */
789#define SSL_AD_DECODE_ERROR TLS1_AD_DECODE_ERROR /* fatal */
790#define SSL_AD_DECRYPT_ERROR TLS1_AD_DECRYPT_ERROR
791#define SSL_AD_EXPORT_RESTRICTION TLS1_AD_EXPORT_RESTRICTION/* fatal */
792#define SSL_AD_PROTOCOL_VERSION TLS1_AD_PROTOCOL_VERSION /* fatal */
793#define SSL_AD_INSUFFICIENT_SECURITY TLS1_AD_INSUFFICIENT_SECURITY/* fatal */
794#define SSL_AD_INTERNAL_ERROR TLS1_AD_INTERNAL_ERROR /* fatal */
795#define SSL_AD_USER_CANCELLED TLS1_AD_USER_CANCELLED
796#define SSL_AD_NO_RENEGOTIATION TLS1_AD_NO_RENEGOTIATION
797
798#define SSL_ERROR_NONE 0
799#define SSL_ERROR_SSL 1
800#define SSL_ERROR_WANT_READ 2
801#define SSL_ERROR_WANT_WRITE 3
802#define SSL_ERROR_WANT_X509_LOOKUP 4
803#define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */
804#define SSL_ERROR_ZERO_RETURN 6
805#define SSL_ERROR_WANT_CONNECT 7
806
807#define SSL_CTRL_NEED_TMP_RSA 1
808#define SSL_CTRL_SET_TMP_RSA 2
809#define SSL_CTRL_SET_TMP_DH 3
810#define SSL_CTRL_SET_TMP_RSA_CB 4
811#define SSL_CTRL_SET_TMP_DH_CB 5
812/* Add these ones */
813#define SSL_CTRL_GET_SESSION_REUSED 6
814#define SSL_CTRL_GET_CLIENT_CERT_REQUEST 7
815#define SSL_CTRL_GET_NUM_RENEGOTIATIONS 8
816#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 9
817#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 10
818#define SSL_CTRL_GET_FLAGS 11
819#define SSL_CTRL_EXTRA_CHAIN_CERT 12
820
821/* Stats */
822#define SSL_CTRL_SESS_NUMBER 20
823#define SSL_CTRL_SESS_CONNECT 21
824#define SSL_CTRL_SESS_CONNECT_GOOD 22
825#define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23
826#define SSL_CTRL_SESS_ACCEPT 24
827#define SSL_CTRL_SESS_ACCEPT_GOOD 25
828#define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26
829#define SSL_CTRL_SESS_HIT 27
830#define SSL_CTRL_SESS_CB_HIT 28
831#define SSL_CTRL_SESS_MISSES 29
832#define SSL_CTRL_SESS_TIMEOUTS 30
833#define SSL_CTRL_SESS_CACHE_FULL 31
834#define SSL_CTRL_OPTIONS 32
835#define SSL_CTRL_MODE 33
836
837#define SSL_CTRL_GET_READ_AHEAD 40
838#define SSL_CTRL_SET_READ_AHEAD 41
839#define SSL_CTRL_SET_SESS_CACHE_SIZE 42
840#define SSL_CTRL_GET_SESS_CACHE_SIZE 43
841#define SSL_CTRL_SET_SESS_CACHE_MODE 44
842#define SSL_CTRL_GET_SESS_CACHE_MODE 45
843
844#define SSL_session_reused(ssl) \
845 SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL)
846#define SSL_num_renegotiations(ssl) \
847 SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
848#define SSL_clear_num_renegotiations(ssl) \
849 SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
850#define SSL_total_renegotiations(ssl) \
851 SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
852
853#define SSL_CTX_need_tmp_RSA(ctx) \
854 SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)
855#define SSL_CTX_set_tmp_rsa(ctx,rsa) \
856 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
857#define SSL_CTX_set_tmp_dh(ctx,dh) \
858 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
859
860#define SSL_need_tmp_RSA(ssl) \
861 SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL)
862#define SSL_set_tmp_rsa(ssl,rsa) \
863 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
864#define SSL_set_tmp_dh(ssl,dh) \
865 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
866
867#define SSL_CTX_add_extra_chain_cert(ctx,x509) \
868 SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)
869
870/* VMS uses only 31 characters for symbols. */
871#ifdef VMS
872#undef SSL_CTX_set_cert_verify_callback
873#define SSL_CTX_set_cert_verify_callback SSL_CTX_set_cert_verify_cb
874#undef SSL_CTX_use_certificate_chain_file
875#define SSL_CTX_use_certificate_chain_file SSL_CTX_use_cert_chain_file
876#undef SSL_CTX_set_default_verify_paths
877#define SSL_CTX_set_default_verify_paths SSL_CTX_set_def_verify_paths
878#undef SSL_get_ex_data_X509_STORE_CTX_idx
879#define SSL_get_ex_data_X509_STORE_CTX_idx SSL_get_ex_data_X509_STOR_CTX_i
880#undef SSL_add_file_cert_subjects_to_stack
881#define SSL_add_file_cert_subjects_to_stack SSL_add_file_cert_sub_to_stack
882#undef SSL_add_dir_cert_subjects_to_stack
883#define SSL_add_dir_cert_subjects_to_stack SSL_add_dir_cert_sub_to_stack
884#endif
885
886#ifdef HEADER_BIO_H
887BIO_METHOD *BIO_f_ssl(void);
888BIO *BIO_new_ssl(SSL_CTX *ctx,int client);
889BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
890BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
891int BIO_ssl_copy_session_id(BIO *to,BIO *from);
892void BIO_ssl_shutdown(BIO *ssl_bio);
893
894#endif
895
896int SSL_CTX_set_cipher_list(SSL_CTX *,const char *str);
897SSL_CTX *SSL_CTX_new(SSL_METHOD *meth);
898void SSL_CTX_free(SSL_CTX *);
899long SSL_CTX_set_timeout(SSL_CTX *ctx,long t);
900long SSL_CTX_get_timeout(SSL_CTX *ctx);
901X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *);
902void SSL_CTX_set_cert_store(SSL_CTX *,X509_STORE *);
903int SSL_want(SSL *s);
904int SSL_clear(SSL *s);
905
906void SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm);
907
908SSL_CIPHER *SSL_get_current_cipher(SSL *s);
909int SSL_CIPHER_get_bits(SSL_CIPHER *c,int *alg_bits);
910char * SSL_CIPHER_get_version(SSL_CIPHER *c);
911const char * SSL_CIPHER_get_name(SSL_CIPHER *c);
912
913int SSL_get_fd(SSL *s);
914const char * SSL_get_cipher_list(SSL *s,int n);
915char * SSL_get_shared_ciphers(SSL *s, char *buf, int len);
916int SSL_get_read_ahead(SSL * s);
917int SSL_pending(SSL *s);
918#ifndef NO_SOCK
919int SSL_set_fd(SSL *s, int fd);
920int SSL_set_rfd(SSL *s, int fd);
921int SSL_set_wfd(SSL *s, int fd);
922#endif
923#ifdef HEADER_BIO_H
924void SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio);
925BIO * SSL_get_rbio(SSL *s);
926BIO * SSL_get_wbio(SSL *s);
927#endif
928int SSL_set_cipher_list(SSL *s, const char *str);
929void SSL_set_read_ahead(SSL *s, int yes);
930int SSL_get_verify_mode(SSL *s);
931int SSL_get_verify_depth(SSL *s);
932int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *);
933void SSL_set_verify(SSL *s, int mode,
934 int (*callback)(int ok,X509_STORE_CTX *ctx));
935void SSL_set_verify_depth(SSL *s, int depth);
936#ifndef NO_RSA
937int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
938#endif
939int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
940int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
941int SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
942int SSL_use_certificate(SSL *ssl, X509 *x);
943int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len);
944
945#ifndef NO_STDIO
946int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
947int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
948int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
949int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
950int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
951int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
952int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */
953STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
954int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
955 const char *file);
956int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
957 const char *dir);
958#endif
959
960void ERR_load_SSL_strings(void );
961void SSL_load_error_strings(void );
962char * SSL_state_string(SSL *s);
963char * SSL_rstate_string(SSL *s);
964char * SSL_state_string_long(SSL *s);
965char * SSL_rstate_string_long(SSL *s);
966long SSL_SESSION_get_time(SSL_SESSION *s);
967long SSL_SESSION_set_time(SSL_SESSION *s, long t);
968long SSL_SESSION_get_timeout(SSL_SESSION *s);
969long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
970void SSL_copy_session_id(SSL *to,SSL *from);
971
972SSL_SESSION *SSL_SESSION_new(void);
973unsigned long SSL_SESSION_hash(SSL_SESSION *a);
974int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b);
975#ifndef NO_FP_API
976int SSL_SESSION_print_fp(FILE *fp,SSL_SESSION *ses);
977#endif
978#ifdef HEADER_BIO_H
979int SSL_SESSION_print(BIO *fp,SSL_SESSION *ses);
980#endif
981void SSL_SESSION_free(SSL_SESSION *ses);
982int i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
983int SSL_set_session(SSL *to, SSL_SESSION *session);
984int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
985int SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
986SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,unsigned char **pp,long length);
987
988#ifdef HEADER_X509_H
989X509 * SSL_get_peer_certificate(SSL *s);
990#endif
991
992STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s);
993
994#ifdef VMS
995#define SSL_CTX_set_default_passwd_cb_userdata SSL_CTX_set_def_passwd_cb_ud
996#endif
997
998int SSL_CTX_get_verify_mode(SSL_CTX *ctx);
999int SSL_CTX_get_verify_depth(SSL_CTX *ctx);
1000int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *);
1001void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,
1002 int (*callback)(int, X509_STORE_CTX *));
1003void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
1004void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(),char *arg);
1005#ifndef NO_RSA
1006int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
1007#endif
1008int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
1009int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
1010int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx,
1011 unsigned char *d, long len);
1012int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
1013int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
1014
1015void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
1016void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
1017
1018int SSL_CTX_check_private_key(SSL_CTX *ctx);
1019int SSL_check_private_key(SSL *ctx);
1020
1021int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
1022 unsigned int sid_ctx_len);
1023
1024SSL * SSL_new(SSL_CTX *ctx);
1025int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
1026 unsigned int sid_ctx_len);
1027
1028int SSL_CTX_set_purpose(SSL_CTX *s, int purpose);
1029int SSL_set_purpose(SSL *s, int purpose);
1030int SSL_CTX_set_trust(SSL_CTX *s, int trust);
1031int SSL_set_trust(SSL *s, int trust);
1032
1033void SSL_free(SSL *ssl);
1034int SSL_accept(SSL *ssl);
1035int SSL_connect(SSL *ssl);
1036int SSL_read(SSL *ssl,char *buf,int num);
1037int SSL_peek(SSL *ssl,char *buf,int num);
1038int SSL_write(SSL *ssl,const char *buf,int num);
1039long SSL_ctrl(SSL *ssl,int cmd, long larg, char *parg);
1040long SSL_callback_ctrl(SSL *, int, void (*)());
1041long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, char *parg);
1042long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)());
1043
1044int SSL_get_error(SSL *s,int ret_code);
1045const char *SSL_get_version(SSL *s);
1046
1047/* This sets the 'default' SSL version that SSL_new() will create */
1048int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth);
1049
1050SSL_METHOD *SSLv2_method(void); /* SSLv2 */
1051SSL_METHOD *SSLv2_server_method(void); /* SSLv2 */
1052SSL_METHOD *SSLv2_client_method(void); /* SSLv2 */
1053
1054SSL_METHOD *SSLv3_method(void); /* SSLv3 */
1055SSL_METHOD *SSLv3_server_method(void); /* SSLv3 */
1056SSL_METHOD *SSLv3_client_method(void); /* SSLv3 */
1057
1058SSL_METHOD *SSLv23_method(void); /* SSLv3 but can rollback to v2 */
1059SSL_METHOD *SSLv23_server_method(void); /* SSLv3 but can rollback to v2 */
1060SSL_METHOD *SSLv23_client_method(void); /* SSLv3 but can rollback to v2 */
1061
1062SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
1063SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */
1064SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */
1065
1066STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s);
1067
1068int SSL_do_handshake(SSL *s);
1069int SSL_renegotiate(SSL *s);
1070int SSL_shutdown(SSL *s);
1071
1072SSL_METHOD *SSL_get_ssl_method(SSL *s);
1073int SSL_set_ssl_method(SSL *s,SSL_METHOD *method);
1074char *SSL_alert_type_string_long(int value);
1075char *SSL_alert_type_string(int value);
1076char *SSL_alert_desc_string_long(int value);
1077char *SSL_alert_desc_string(int value);
1078
1079void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *list);
1080void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *list);
1081STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s);
1082STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *s);
1083int SSL_add_client_CA(SSL *ssl,X509 *x);
1084int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x);
1085
1086void SSL_set_connect_state(SSL *s);
1087void SSL_set_accept_state(SSL *s);
1088
1089long SSL_get_default_timeout(SSL *s);
1090
1091int SSL_library_init(void );
1092
1093char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size);
1094STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk);
1095
1096SSL *SSL_dup(SSL *ssl);
1097
1098X509 *SSL_get_certificate(SSL *ssl);
1099/* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl);
1100
1101void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode);
1102int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx);
1103void SSL_set_quiet_shutdown(SSL *ssl,int mode);
1104int SSL_get_quiet_shutdown(SSL *ssl);
1105void SSL_set_shutdown(SSL *ssl,int mode);
1106int SSL_get_shutdown(SSL *ssl);
1107int SSL_version(SSL *ssl);
1108int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
1109int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
1110 const char *CApath);
1111#define SSL_get0_session SSL_get_session /* just peek at pointer */
1112SSL_SESSION *SSL_get_session(SSL *ssl);
1113SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */
1114SSL_CTX *SSL_get_SSL_CTX(SSL *ssl);
1115void SSL_set_info_callback(SSL *ssl,void (*cb)());
1116void (*SSL_get_info_callback(SSL *ssl))();
1117int SSL_state(SSL *ssl);
1118
1119void SSL_set_verify_result(SSL *ssl,long v);
1120long SSL_get_verify_result(SSL *ssl);
1121
1122int SSL_set_ex_data(SSL *ssl,int idx,void *data);
1123void *SSL_get_ex_data(SSL *ssl,int idx);
1124int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1125 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1126
1127int SSL_SESSION_set_ex_data(SSL_SESSION *ss,int idx,void *data);
1128void *SSL_SESSION_get_ex_data(SSL_SESSION *ss,int idx);
1129int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1130 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1131
1132int SSL_CTX_set_ex_data(SSL_CTX *ssl,int idx,void *data);
1133void *SSL_CTX_get_ex_data(SSL_CTX *ssl,int idx);
1134int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1135 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1136
1137int SSL_get_ex_data_X509_STORE_CTX_idx(void );
1138
1139#define SSL_CTX_sess_set_cache_size(ctx,t) \
1140 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
1141#define SSL_CTX_sess_get_cache_size(ctx) \
1142 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
1143#define SSL_CTX_set_session_cache_mode(ctx,m) \
1144 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
1145#define SSL_CTX_get_session_cache_mode(ctx) \
1146 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)
1147
1148#define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
1149#define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
1150#define SSL_CTX_get_read_ahead(ctx) \
1151 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
1152#define SSL_CTX_set_read_ahead(ctx,m) \
1153 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,0,NULL)
1154
1155 /* NB: the keylength is only applicable when is_export is true */
1156#ifndef NO_RSA
1157void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
1158 RSA *(*cb)(SSL *ssl,int is_export,
1159 int keylength));
1160
1161void SSL_set_tmp_rsa_callback(SSL *ssl,
1162 RSA *(*cb)(SSL *ssl,int is_export,
1163 int keylength));
1164#endif
1165#ifndef NO_DH
1166void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
1167 DH *(*dh)(SSL *ssl,int is_export,
1168 int keylength));
1169void SSL_set_tmp_dh_callback(SSL *ssl,
1170 DH *(*dh)(SSL *ssl,int is_export,
1171 int keylength));
1172#endif
1173
1174#ifdef HEADER_COMP_H
1175int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm);
1176#else
1177int SSL_COMP_add_compression_method(int id,char *cm);
1178#endif
1179
1180/* BEGIN ERROR CODES */
1181/* The following lines are auto generated by the script mkerr.pl. Any changes
1182 * made after this point may be overwritten when the script is next run.
1183 */
1184
1185/* Error codes for the SSL functions. */
1186
1187/* Function codes. */
1188#define SSL_F_CLIENT_CERTIFICATE 100
1189#define SSL_F_CLIENT_HELLO 101
1190#define SSL_F_CLIENT_MASTER_KEY 102
1191#define SSL_F_D2I_SSL_SESSION 103
1192#define SSL_F_DO_SSL3_WRITE 104
1193#define SSL_F_GET_CLIENT_FINISHED 105
1194#define SSL_F_GET_CLIENT_HELLO 106
1195#define SSL_F_GET_CLIENT_MASTER_KEY 107
1196#define SSL_F_GET_SERVER_FINISHED 108
1197#define SSL_F_GET_SERVER_HELLO 109
1198#define SSL_F_GET_SERVER_VERIFY 110
1199#define SSL_F_I2D_SSL_SESSION 111
1200#define SSL_F_READ_N 112
1201#define SSL_F_REQUEST_CERTIFICATE 113
1202#define SSL_F_SERVER_HELLO 114
1203#define SSL_F_SSL23_ACCEPT 115
1204#define SSL_F_SSL23_CLIENT_HELLO 116
1205#define SSL_F_SSL23_CONNECT 117
1206#define SSL_F_SSL23_GET_CLIENT_HELLO 118
1207#define SSL_F_SSL23_GET_SERVER_HELLO 119
1208#define SSL_F_SSL23_READ 120
1209#define SSL_F_SSL23_WRITE 121
1210#define SSL_F_SSL2_ACCEPT 122
1211#define SSL_F_SSL2_CONNECT 123
1212#define SSL_F_SSL2_ENC_INIT 124
1213#define SSL_F_SSL2_READ 125
1214#define SSL_F_SSL2_SET_CERTIFICATE 126
1215#define SSL_F_SSL2_WRITE 127
1216#define SSL_F_SSL3_ACCEPT 128
1217#define SSL_F_SSL3_CALLBACK_CTRL 233
1218#define SSL_F_SSL3_CHANGE_CIPHER_STATE 129
1219#define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130
1220#define SSL_F_SSL3_CLIENT_HELLO 131
1221#define SSL_F_SSL3_CONNECT 132
1222#define SSL_F_SSL3_CTRL 213
1223#define SSL_F_SSL3_CTX_CTRL 133
1224#define SSL_F_SSL3_ENC 134
1225#define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135
1226#define SSL_F_SSL3_GET_CERT_VERIFY 136
1227#define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137
1228#define SSL_F_SSL3_GET_CLIENT_HELLO 138
1229#define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139
1230#define SSL_F_SSL3_GET_FINISHED 140
1231#define SSL_F_SSL3_GET_KEY_EXCHANGE 141
1232#define SSL_F_SSL3_GET_MESSAGE 142
1233#define SSL_F_SSL3_GET_RECORD 143
1234#define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144
1235#define SSL_F_SSL3_GET_SERVER_DONE 145
1236#define SSL_F_SSL3_GET_SERVER_HELLO 146
1237#define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147
1238#define SSL_F_SSL3_READ_BYTES 148
1239#define SSL_F_SSL3_READ_N 149
1240#define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150
1241#define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151
1242#define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152
1243#define SSL_F_SSL3_SEND_CLIENT_VERIFY 153
1244#define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154
1245#define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155
1246#define SSL_F_SSL3_SETUP_BUFFERS 156
1247#define SSL_F_SSL3_SETUP_KEY_BLOCK 157
1248#define SSL_F_SSL3_WRITE_BYTES 158
1249#define SSL_F_SSL3_WRITE_PENDING 159
1250#define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215
1251#define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216
1252#define SSL_F_SSL_BAD_METHOD 160
1253#define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161
1254#define SSL_F_SSL_CERT_DUP 221
1255#define SSL_F_SSL_CERT_INST 222
1256#define SSL_F_SSL_CERT_INSTANTIATE 214
1257#define SSL_F_SSL_CERT_NEW 162
1258#define SSL_F_SSL_CHECK_PRIVATE_KEY 163
1259#define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230
1260#define SSL_F_SSL_CIPHER_STRENGTH_SORT 231
1261#define SSL_F_SSL_CLEAR 164
1262#define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165
1263#define SSL_F_SSL_CREATE_CIPHER_LIST 166
1264#define SSL_F_SSL_CTRL 232
1265#define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168
1266#define SSL_F_SSL_CTX_NEW 169
1267#define SSL_F_SSL_CTX_SET_PURPOSE 226
1268#define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219
1269#define SSL_F_SSL_CTX_SET_SSL_VERSION 170
1270#define SSL_F_SSL_CTX_SET_TRUST 229
1271#define SSL_F_SSL_CTX_USE_CERTIFICATE 171
1272#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172
1273#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE 220
1274#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173
1275#define SSL_F_SSL_CTX_USE_PRIVATEKEY 174
1276#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175
1277#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176
1278#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177
1279#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178
1280#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179
1281#define SSL_F_SSL_DO_HANDSHAKE 180
1282#define SSL_F_SSL_GET_NEW_SESSION 181
1283#define SSL_F_SSL_GET_PREV_SESSION 217
1284#define SSL_F_SSL_GET_SERVER_SEND_CERT 182
1285#define SSL_F_SSL_GET_SIGN_PKEY 183
1286#define SSL_F_SSL_INIT_WBIO_BUFFER 184
1287#define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185
1288#define SSL_F_SSL_NEW 186
1289#define SSL_F_SSL_READ 223
1290#define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187
1291#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188
1292#define SSL_F_SSL_SESSION_NEW 189
1293#define SSL_F_SSL_SESSION_PRINT_FP 190
1294#define SSL_F_SSL_SESS_CERT_NEW 225
1295#define SSL_F_SSL_SET_CERT 191
1296#define SSL_F_SSL_SET_FD 192
1297#define SSL_F_SSL_SET_PKEY 193
1298#define SSL_F_SSL_SET_PURPOSE 227
1299#define SSL_F_SSL_SET_RFD 194
1300#define SSL_F_SSL_SET_SESSION 195
1301#define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218
1302#define SSL_F_SSL_SET_TRUST 228
1303#define SSL_F_SSL_SET_WFD 196
1304#define SSL_F_SSL_SHUTDOWN 224
1305#define SSL_F_SSL_UNDEFINED_FUNCTION 197
1306#define SSL_F_SSL_USE_CERTIFICATE 198
1307#define SSL_F_SSL_USE_CERTIFICATE_ASN1 199
1308#define SSL_F_SSL_USE_CERTIFICATE_FILE 200
1309#define SSL_F_SSL_USE_PRIVATEKEY 201
1310#define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202
1311#define SSL_F_SSL_USE_PRIVATEKEY_FILE 203
1312#define SSL_F_SSL_USE_RSAPRIVATEKEY 204
1313#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205
1314#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206
1315#define SSL_F_SSL_VERIFY_CERT_CHAIN 207
1316#define SSL_F_SSL_WRITE 208
1317#define SSL_F_TLS1_CHANGE_CIPHER_STATE 209
1318#define SSL_F_TLS1_ENC 210
1319#define SSL_F_TLS1_SETUP_KEY_BLOCK 211
1320#define SSL_F_WRITE_PENDING 212
1321
1322/* Reason codes. */
1323#define SSL_R_APP_DATA_IN_HANDSHAKE 100
1324#define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272
1325#define SSL_R_BAD_ALERT_RECORD 101
1326#define SSL_R_BAD_AUTHENTICATION_TYPE 102
1327#define SSL_R_BAD_CHANGE_CIPHER_SPEC 103
1328#define SSL_R_BAD_CHECKSUM 104
1329#define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106
1330#define SSL_R_BAD_DECOMPRESSION 107
1331#define SSL_R_BAD_DH_G_LENGTH 108
1332#define SSL_R_BAD_DH_PUB_KEY_LENGTH 109
1333#define SSL_R_BAD_DH_P_LENGTH 110
1334#define SSL_R_BAD_DIGEST_LENGTH 111
1335#define SSL_R_BAD_DSA_SIGNATURE 112
1336#define SSL_R_BAD_HELLO_REQUEST 105
1337#define SSL_R_BAD_LENGTH 271
1338#define SSL_R_BAD_MAC_DECODE 113
1339#define SSL_R_BAD_MESSAGE_TYPE 114
1340#define SSL_R_BAD_PACKET_LENGTH 115
1341#define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116
1342#define SSL_R_BAD_RESPONSE_ARGUMENT 117
1343#define SSL_R_BAD_RSA_DECRYPT 118
1344#define SSL_R_BAD_RSA_ENCRYPT 119
1345#define SSL_R_BAD_RSA_E_LENGTH 120
1346#define SSL_R_BAD_RSA_MODULUS_LENGTH 121
1347#define SSL_R_BAD_RSA_SIGNATURE 122
1348#define SSL_R_BAD_SIGNATURE 123
1349#define SSL_R_BAD_SSL_FILETYPE 124
1350#define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125
1351#define SSL_R_BAD_STATE 126
1352#define SSL_R_BAD_WRITE_RETRY 127
1353#define SSL_R_BIO_NOT_SET 128
1354#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129
1355#define SSL_R_BN_LIB 130
1356#define SSL_R_CA_DN_LENGTH_MISMATCH 131
1357#define SSL_R_CA_DN_TOO_LONG 132
1358#define SSL_R_CCS_RECEIVED_EARLY 133
1359#define SSL_R_CERTIFICATE_VERIFY_FAILED 134
1360#define SSL_R_CERT_LENGTH_MISMATCH 135
1361#define SSL_R_CHALLENGE_IS_DIFFERENT 136
1362#define SSL_R_CIPHER_CODE_WRONG_LENGTH 137
1363#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138
1364#define SSL_R_CIPHER_TABLE_SRC_ERROR 139
1365#define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140
1366#define SSL_R_COMPRESSION_FAILURE 141
1367#define SSL_R_COMPRESSION_LIBRARY_ERROR 142
1368#define SSL_R_CONNECTION_ID_IS_DIFFERENT 143
1369#define SSL_R_CONNECTION_TYPE_NOT_SET 144
1370#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145
1371#define SSL_R_DATA_LENGTH_TOO_LONG 146
1372#define SSL_R_DECRYPTION_FAILED 147
1373#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148
1374#define SSL_R_DIGEST_CHECK_FAILED 149
1375#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150
1376#define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 1092
1377#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151
1378#define SSL_R_EXCESSIVE_MESSAGE_SIZE 152
1379#define SSL_R_EXTRA_DATA_IN_MESSAGE 153
1380#define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154
1381#define SSL_R_HTTPS_PROXY_REQUEST 155
1382#define SSL_R_HTTP_REQUEST 156
1383#define SSL_R_INTERNAL_ERROR 157
1384#define SSL_R_INVALID_CHALLENGE_LENGTH 158
1385#define SSL_R_INVALID_COMMAND 280
1386#define SSL_R_INVALID_PURPOSE 278
1387#define SSL_R_INVALID_TRUST 279
1388#define SSL_R_LENGTH_MISMATCH 159
1389#define SSL_R_LENGTH_TOO_SHORT 160
1390#define SSL_R_LIBRARY_BUG 274
1391#define SSL_R_LIBRARY_HAS_NO_CIPHERS 161
1392#define SSL_R_MISSING_DH_DSA_CERT 162
1393#define SSL_R_MISSING_DH_KEY 163
1394#define SSL_R_MISSING_DH_RSA_CERT 164
1395#define SSL_R_MISSING_DSA_SIGNING_CERT 165
1396#define SSL_R_MISSING_EXPORT_TMP_DH_KEY 166
1397#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 167
1398#define SSL_R_MISSING_RSA_CERTIFICATE 168
1399#define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169
1400#define SSL_R_MISSING_RSA_SIGNING_CERT 170
1401#define SSL_R_MISSING_TMP_DH_KEY 171
1402#define SSL_R_MISSING_TMP_RSA_KEY 172
1403#define SSL_R_MISSING_TMP_RSA_PKEY 173
1404#define SSL_R_MISSING_VERIFY_MESSAGE 174
1405#define SSL_R_NON_SSLV2_INITIAL_PACKET 175
1406#define SSL_R_NO_CERTIFICATES_RETURNED 176
1407#define SSL_R_NO_CERTIFICATE_ASSIGNED 177
1408#define SSL_R_NO_CERTIFICATE_RETURNED 178
1409#define SSL_R_NO_CERTIFICATE_SET 179
1410#define SSL_R_NO_CERTIFICATE_SPECIFIED 180
1411#define SSL_R_NO_CIPHERS_AVAILABLE 181
1412#define SSL_R_NO_CIPHERS_PASSED 182
1413#define SSL_R_NO_CIPHERS_SPECIFIED 183
1414#define SSL_R_NO_CIPHER_LIST 184
1415#define SSL_R_NO_CIPHER_MATCH 185
1416#define SSL_R_NO_CLIENT_CERT_RECEIVED 186
1417#define SSL_R_NO_COMPRESSION_SPECIFIED 187
1418#define SSL_R_NO_METHOD_SPECIFIED 188
1419#define SSL_R_NO_PRIVATEKEY 189
1420#define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190
1421#define SSL_R_NO_PROTOCOLS_AVAILABLE 191
1422#define SSL_R_NO_PUBLICKEY 192
1423#define SSL_R_NO_SHARED_CIPHER 193
1424#define SSL_R_NO_VERIFY_CALLBACK 194
1425#define SSL_R_NULL_SSL_CTX 195
1426#define SSL_R_NULL_SSL_METHOD_PASSED 196
1427#define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197
1428#define SSL_R_PACKET_LENGTH_TOO_LONG 198
1429#define SSL_R_PATH_TOO_LONG 270
1430#define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199
1431#define SSL_R_PEER_ERROR 200
1432#define SSL_R_PEER_ERROR_CERTIFICATE 201
1433#define SSL_R_PEER_ERROR_NO_CERTIFICATE 202
1434#define SSL_R_PEER_ERROR_NO_CIPHER 203
1435#define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 204
1436#define SSL_R_PRE_MAC_LENGTH_TOO_LONG 205
1437#define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 206
1438#define SSL_R_PROTOCOL_IS_SHUTDOWN 207
1439#define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 208
1440#define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209
1441#define SSL_R_PUBLIC_KEY_NOT_RSA 210
1442#define SSL_R_READ_BIO_NOT_SET 211
1443#define SSL_R_READ_WRONG_PACKET_TYPE 212
1444#define SSL_R_RECORD_LENGTH_MISMATCH 213
1445#define SSL_R_RECORD_TOO_LARGE 214
1446#define SSL_R_REQUIRED_CIPHER_MISSING 215
1447#define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216
1448#define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217
1449#define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218
1450#define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277
1451#define SSL_R_SHORT_READ 219
1452#define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220
1453#define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221
1454#define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222
1455#define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
1456#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
1457#define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
1458#define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
1459#define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
1460#define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
1461#define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
1462#define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
1463#define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
1464#define SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE 223
1465#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE 224
1466#define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER 225
1467#define SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 226
1468#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
1469#define SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE 227
1470#define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
1471#define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228
1472#define SSL_R_SSL_HANDSHAKE_FAILURE 229
1473#define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230
1474#define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273
1475#define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 231
1476#define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
1477#define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
1478#define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
1479#define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
1480#define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
1481#define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
1482#define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
1483#define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
1484#define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
1485#define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
1486#define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
1487#define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
1488#define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232
1489#define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233
1490#define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234
1491#define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER 235
1492#define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236
1493#define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237
1494#define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238
1495#define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239
1496#define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240
1497#define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241
1498#define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242
1499#define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243
1500#define SSL_R_UNEXPECTED_MESSAGE 244
1501#define SSL_R_UNEXPECTED_RECORD 245
1502#define SSL_R_UNINITIALIZED 276
1503#define SSL_R_UNKNOWN_ALERT_TYPE 246
1504#define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247
1505#define SSL_R_UNKNOWN_CIPHER_RETURNED 248
1506#define SSL_R_UNKNOWN_CIPHER_TYPE 249
1507#define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250
1508#define SSL_R_UNKNOWN_PKEY_TYPE 251
1509#define SSL_R_UNKNOWN_PROTOCOL 252
1510#define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 253
1511#define SSL_R_UNKNOWN_SSL_VERSION 254
1512#define SSL_R_UNKNOWN_STATE 255
1513#define SSL_R_UNSUPPORTED_CIPHER 256
1514#define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257
1515#define SSL_R_UNSUPPORTED_OPTION 1091
1516#define SSL_R_UNSUPPORTED_PROTOCOL 258
1517#define SSL_R_UNSUPPORTED_SSL_VERSION 259
1518#define SSL_R_WRITE_BIO_NOT_SET 260
1519#define SSL_R_WRONG_CIPHER_RETURNED 261
1520#define SSL_R_WRONG_MESSAGE_TYPE 262
1521#define SSL_R_WRONG_NUMBER_OF_KEY_BITS 263
1522#define SSL_R_WRONG_SIGNATURE_LENGTH 264
1523#define SSL_R_WRONG_SIGNATURE_SIZE 265
1524#define SSL_R_WRONG_SSL_VERSION 266
1525#define SSL_R_WRONG_VERSION_NUMBER 267
1526#define SSL_R_X509_LIB 268
1527#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269
1528
1529#ifdef __cplusplus
1530}
1531#endif
1532#endif
1533
diff --git a/src/lib/libssl/ssl2.h b/src/lib/libssl/ssl2.h
deleted file mode 100644
index 01d41c88c5..0000000000
--- a/src/lib/libssl/ssl2.h
+++ /dev/null
@@ -1,265 +0,0 @@
1/* ssl/ssl2.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#ifndef HEADER_SSL2_H
60#define HEADER_SSL2_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66/* Protocol Version Codes */
67#define SSL2_VERSION 0x0002
68#define SSL2_VERSION_MAJOR 0x00
69#define SSL2_VERSION_MINOR 0x02
70/* #define SSL2_CLIENT_VERSION 0x0002 */
71/* #define SSL2_SERVER_VERSION 0x0002 */
72
73/* Protocol Message Codes */
74#define SSL2_MT_ERROR 0
75#define SSL2_MT_CLIENT_HELLO 1
76#define SSL2_MT_CLIENT_MASTER_KEY 2
77#define SSL2_MT_CLIENT_FINISHED 3
78#define SSL2_MT_SERVER_HELLO 4
79#define SSL2_MT_SERVER_VERIFY 5
80#define SSL2_MT_SERVER_FINISHED 6
81#define SSL2_MT_REQUEST_CERTIFICATE 7
82#define SSL2_MT_CLIENT_CERTIFICATE 8
83
84/* Error Message Codes */
85#define SSL2_PE_UNDEFINED_ERROR 0x0000
86#define SSL2_PE_NO_CIPHER 0x0001
87#define SSL2_PE_NO_CERTIFICATE 0x0002
88#define SSL2_PE_BAD_CERTIFICATE 0x0004
89#define SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006
90
91/* Cipher Kind Values */
92#define SSL2_CK_NULL_WITH_MD5 0x02000000 /* v3 */
93#define SSL2_CK_RC4_128_WITH_MD5 0x02010080
94#define SSL2_CK_RC4_128_EXPORT40_WITH_MD5 0x02020080
95#define SSL2_CK_RC2_128_CBC_WITH_MD5 0x02030080
96#define SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5 0x02040080
97#define SSL2_CK_IDEA_128_CBC_WITH_MD5 0x02050080
98#define SSL2_CK_DES_64_CBC_WITH_MD5 0x02060040
99#define SSL2_CK_DES_64_CBC_WITH_SHA 0x02060140 /* v3 */
100#define SSL2_CK_DES_192_EDE3_CBC_WITH_MD5 0x020700c0
101#define SSL2_CK_DES_192_EDE3_CBC_WITH_SHA 0x020701c0 /* v3 */
102#define SSL2_CK_RC4_64_WITH_MD5 0x02080080 /* MS hack */
103
104#define SSL2_CK_DES_64_CFB64_WITH_MD5_1 0x02ff0800 /* SSLeay */
105#define SSL2_CK_NULL 0x02ff0810 /* SSLeay */
106
107#define SSL2_TXT_DES_64_CFB64_WITH_MD5_1 "DES-CFB-M1"
108#define SSL2_TXT_NULL_WITH_MD5 "NULL-MD5"
109#define SSL2_TXT_RC4_128_WITH_MD5 "RC4-MD5"
110#define SSL2_TXT_RC4_128_EXPORT40_WITH_MD5 "EXP-RC4-MD5"
111#define SSL2_TXT_RC2_128_CBC_WITH_MD5 "RC2-CBC-MD5"
112#define SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 "EXP-RC2-CBC-MD5"
113#define SSL2_TXT_IDEA_128_CBC_WITH_MD5 "IDEA-CBC-MD5"
114#define SSL2_TXT_DES_64_CBC_WITH_MD5 "DES-CBC-MD5"
115#define SSL2_TXT_DES_64_CBC_WITH_SHA "DES-CBC-SHA"
116#define SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5 "DES-CBC3-MD5"
117#define SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA "DES-CBC3-SHA"
118#define SSL2_TXT_RC4_64_WITH_MD5 "RC4-64-MD5"
119
120#define SSL2_TXT_NULL "NULL"
121
122/* Flags for the SSL_CIPHER.algorithm2 field */
123#define SSL2_CF_5_BYTE_ENC 0x01
124#define SSL2_CF_8_BYTE_ENC 0x02
125
126/* Certificate Type Codes */
127#define SSL2_CT_X509_CERTIFICATE 0x01
128
129/* Authentication Type Code */
130#define SSL2_AT_MD5_WITH_RSA_ENCRYPTION 0x01
131
132#define SSL2_MAX_SSL_SESSION_ID_LENGTH 32
133
134/* Upper/Lower Bounds */
135#define SSL2_MAX_MASTER_KEY_LENGTH_IN_BITS 256
136#define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER (unsigned int)32767
137#define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER 16383 /**/
138
139#define SSL2_CHALLENGE_LENGTH 16
140/*#define SSL2_CHALLENGE_LENGTH 32 */
141#define SSL2_MIN_CHALLENGE_LENGTH 16
142#define SSL2_MAX_CHALLENGE_LENGTH 32
143#define SSL2_CONNECTION_ID_LENGTH 16
144#define SSL2_MAX_CONNECTION_ID_LENGTH 16
145#define SSL2_SSL_SESSION_ID_LENGTH 16
146#define SSL2_MAX_CERT_CHALLENGE_LENGTH 32
147#define SSL2_MIN_CERT_CHALLENGE_LENGTH 16
148#define SSL2_MAX_KEY_MATERIAL_LENGTH 24
149
150#ifndef HEADER_SSL_LOCL_H
151#define CERT char
152#endif
153
154typedef struct ssl2_state_st
155 {
156 int three_byte_header;
157 int clear_text; /* clear text */
158 int escape; /* not used in SSLv2 */
159 int ssl2_rollback; /* used if SSLv23 rolled back to SSLv2 */
160
161 /* non-blocking io info, used to make sure the same
162 * args were passwd */
163 unsigned int wnum; /* number of bytes sent so far */
164 int wpend_tot;
165 const unsigned char *wpend_buf;
166
167 int wpend_off; /* offset to data to write */
168 int wpend_len; /* number of bytes passwd to write */
169 int wpend_ret; /* number of bytes to return to caller */
170
171 /* buffer raw data */
172 int rbuf_left;
173 int rbuf_offs;
174 unsigned char *rbuf;
175 unsigned char *wbuf;
176
177 unsigned char *write_ptr;/* used to point to the start due to
178 * 2/3 byte header. */
179
180 unsigned int padding;
181 unsigned int rlength; /* passed to ssl2_enc */
182 int ract_data_length; /* Set when things are encrypted. */
183 unsigned int wlength; /* passed to ssl2_enc */
184 int wact_data_length; /* Set when things are decrypted. */
185 unsigned char *ract_data;
186 unsigned char *wact_data;
187 unsigned char *mac_data;
188 unsigned char *pad_data;
189
190 unsigned char *read_key;
191 unsigned char *write_key;
192
193 /* Stuff specifically to do with this SSL session */
194 unsigned int challenge_length;
195 unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH];
196 unsigned int conn_id_length;
197 unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH];
198 unsigned int key_material_length;
199 unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH*2];
200
201 unsigned long read_sequence;
202 unsigned long write_sequence;
203
204 struct {
205 unsigned int conn_id_length;
206 unsigned int cert_type;
207 unsigned int cert_length;
208 int csl;
209 int clear;
210 unsigned int enc;
211 unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH];
212 int cipher_spec_length;
213 unsigned int session_id_length;
214 unsigned int clen;
215 unsigned int rlen;
216 } tmp;
217 } SSL2_STATE;
218
219/* SSLv2 */
220/* client */
221#define SSL2_ST_SEND_CLIENT_HELLO_A (0x10|SSL_ST_CONNECT)
222#define SSL2_ST_SEND_CLIENT_HELLO_B (0x11|SSL_ST_CONNECT)
223#define SSL2_ST_GET_SERVER_HELLO_A (0x20|SSL_ST_CONNECT)
224#define SSL2_ST_GET_SERVER_HELLO_B (0x21|SSL_ST_CONNECT)
225#define SSL2_ST_SEND_CLIENT_MASTER_KEY_A (0x30|SSL_ST_CONNECT)
226#define SSL2_ST_SEND_CLIENT_MASTER_KEY_B (0x31|SSL_ST_CONNECT)
227#define SSL2_ST_SEND_CLIENT_FINISHED_A (0x40|SSL_ST_CONNECT)
228#define SSL2_ST_SEND_CLIENT_FINISHED_B (0x41|SSL_ST_CONNECT)
229#define SSL2_ST_SEND_CLIENT_CERTIFICATE_A (0x50|SSL_ST_CONNECT)
230#define SSL2_ST_SEND_CLIENT_CERTIFICATE_B (0x51|SSL_ST_CONNECT)
231#define SSL2_ST_SEND_CLIENT_CERTIFICATE_C (0x52|SSL_ST_CONNECT)
232#define SSL2_ST_SEND_CLIENT_CERTIFICATE_D (0x53|SSL_ST_CONNECT)
233#define SSL2_ST_GET_SERVER_VERIFY_A (0x60|SSL_ST_CONNECT)
234#define SSL2_ST_GET_SERVER_VERIFY_B (0x61|SSL_ST_CONNECT)
235#define SSL2_ST_GET_SERVER_FINISHED_A (0x70|SSL_ST_CONNECT)
236#define SSL2_ST_GET_SERVER_FINISHED_B (0x71|SSL_ST_CONNECT)
237#define SSL2_ST_CLIENT_START_ENCRYPTION (0x80|SSL_ST_CONNECT)
238#define SSL2_ST_X509_GET_CLIENT_CERTIFICATE (0x90|SSL_ST_CONNECT)
239/* server */
240#define SSL2_ST_GET_CLIENT_HELLO_A (0x10|SSL_ST_ACCEPT)
241#define SSL2_ST_GET_CLIENT_HELLO_B (0x11|SSL_ST_ACCEPT)
242#define SSL2_ST_GET_CLIENT_HELLO_C (0x12|SSL_ST_ACCEPT)
243#define SSL2_ST_SEND_SERVER_HELLO_A (0x20|SSL_ST_ACCEPT)
244#define SSL2_ST_SEND_SERVER_HELLO_B (0x21|SSL_ST_ACCEPT)
245#define SSL2_ST_GET_CLIENT_MASTER_KEY_A (0x30|SSL_ST_ACCEPT)
246#define SSL2_ST_GET_CLIENT_MASTER_KEY_B (0x31|SSL_ST_ACCEPT)
247#define SSL2_ST_SEND_SERVER_VERIFY_A (0x40|SSL_ST_ACCEPT)
248#define SSL2_ST_SEND_SERVER_VERIFY_B (0x41|SSL_ST_ACCEPT)
249#define SSL2_ST_SEND_SERVER_VERIFY_C (0x42|SSL_ST_ACCEPT)
250#define SSL2_ST_GET_CLIENT_FINISHED_A (0x50|SSL_ST_ACCEPT)
251#define SSL2_ST_GET_CLIENT_FINISHED_B (0x51|SSL_ST_ACCEPT)
252#define SSL2_ST_SEND_SERVER_FINISHED_A (0x60|SSL_ST_ACCEPT)
253#define SSL2_ST_SEND_SERVER_FINISHED_B (0x61|SSL_ST_ACCEPT)
254#define SSL2_ST_SEND_REQUEST_CERTIFICATE_A (0x70|SSL_ST_ACCEPT)
255#define SSL2_ST_SEND_REQUEST_CERTIFICATE_B (0x71|SSL_ST_ACCEPT)
256#define SSL2_ST_SEND_REQUEST_CERTIFICATE_C (0x72|SSL_ST_ACCEPT)
257#define SSL2_ST_SEND_REQUEST_CERTIFICATE_D (0x73|SSL_ST_ACCEPT)
258#define SSL2_ST_SERVER_START_ENCRYPTION (0x80|SSL_ST_ACCEPT)
259#define SSL2_ST_X509_GET_SERVER_CERTIFICATE (0x90|SSL_ST_ACCEPT)
260
261#ifdef __cplusplus
262}
263#endif
264#endif
265
diff --git a/src/lib/libssl/ssl23.h b/src/lib/libssl/ssl23.h
deleted file mode 100644
index d3228983c7..0000000000
--- a/src/lib/libssl/ssl23.h
+++ /dev/null
@@ -1,83 +0,0 @@
1/* ssl/ssl23.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#ifndef HEADER_SSL23_H
60#define HEADER_SSL23_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66/*client */
67/* write to server */
68#define SSL23_ST_CW_CLNT_HELLO_A (0x210|SSL_ST_CONNECT)
69#define SSL23_ST_CW_CLNT_HELLO_B (0x211|SSL_ST_CONNECT)
70/* read from server */
71#define SSL23_ST_CR_SRVR_HELLO_A (0x220|SSL_ST_CONNECT)
72#define SSL23_ST_CR_SRVR_HELLO_B (0x221|SSL_ST_CONNECT)
73
74/* server */
75/* read from client */
76#define SSL23_ST_SR_CLNT_HELLO_A (0x210|SSL_ST_ACCEPT)
77#define SSL23_ST_SR_CLNT_HELLO_B (0x211|SSL_ST_ACCEPT)
78
79#ifdef __cplusplus
80}
81#endif
82#endif
83
diff --git a/src/lib/libssl/ssl3.h b/src/lib/libssl/ssl3.h
deleted file mode 100644
index f616763830..0000000000
--- a/src/lib/libssl/ssl3.h
+++ /dev/null
@@ -1,426 +0,0 @@
1/* ssl/ssl3.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#ifndef HEADER_SSL3_H
60#define HEADER_SSL3_H
61
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64#include <openssl/ssl.h>
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70#define SSL3_CK_RSA_NULL_MD5 0x03000001
71#define SSL3_CK_RSA_NULL_SHA 0x03000002
72#define SSL3_CK_RSA_RC4_40_MD5 0x03000003
73#define SSL3_CK_RSA_RC4_128_MD5 0x03000004
74#define SSL3_CK_RSA_RC4_128_SHA 0x03000005
75#define SSL3_CK_RSA_RC2_40_MD5 0x03000006
76#define SSL3_CK_RSA_IDEA_128_SHA 0x03000007
77#define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008
78#define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009
79#define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A
80
81#define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B
82#define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C
83#define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D
84#define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E
85#define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F
86#define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010
87
88#define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011
89#define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012
90#define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013
91#define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014
92#define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015
93#define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016
94
95#define SSL3_CK_ADH_RC4_40_MD5 0x03000017
96#define SSL3_CK_ADH_RC4_128_MD5 0x03000018
97#define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019
98#define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A
99#define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B
100
101#define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C
102#define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D
103#define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E
104
105#define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5"
106#define SSL3_TXT_RSA_NULL_SHA "NULL-SHA"
107#define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5"
108#define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5"
109#define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA"
110#define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5"
111#define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA"
112#define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA"
113#define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA"
114#define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA"
115
116#define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA"
117#define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA"
118#define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA"
119#define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA"
120#define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA"
121#define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA"
122
123#define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA"
124#define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA"
125#define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA"
126#define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA"
127#define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA"
128#define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA"
129
130#define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5"
131#define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5"
132#define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA"
133#define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA"
134#define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA"
135
136#define SSL3_TXT_FZA_DMS_NULL_SHA "FZA-NULL-SHA"
137#define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA"
138#define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA"
139
140#define SSL3_SSL_SESSION_ID_LENGTH 32
141#define SSL3_MAX_SSL_SESSION_ID_LENGTH 32
142
143#define SSL3_MASTER_SECRET_SIZE 48
144#define SSL3_RANDOM_SIZE 32
145#define SSL3_SESSION_ID_SIZE 32
146#define SSL3_RT_HEADER_LENGTH 5
147
148/* Due to MS stuffing up, this can change.... */
149#if defined(WIN16) || (defined(MSDOS) && !defined(WIN32))
150#define SSL3_RT_MAX_EXTRA (14000)
151#else
152#define SSL3_RT_MAX_EXTRA (16384)
153#endif
154
155#define SSL3_RT_MAX_PLAIN_LENGTH 16384
156#define SSL3_RT_MAX_COMPRESSED_LENGTH (1024+SSL3_RT_MAX_PLAIN_LENGTH)
157#define SSL3_RT_MAX_ENCRYPTED_LENGTH (1024+SSL3_RT_MAX_COMPRESSED_LENGTH)
158#define SSL3_RT_MAX_PACKET_SIZE (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)
159#define SSL3_RT_MAX_DATA_SIZE (1024*1024)
160
161#define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54"
162#define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52"
163
164#define SSL3_VERSION 0x0300
165#define SSL3_VERSION_MAJOR 0x03
166#define SSL3_VERSION_MINOR 0x00
167
168#define SSL3_RT_CHANGE_CIPHER_SPEC 20
169#define SSL3_RT_ALERT 21
170#define SSL3_RT_HANDSHAKE 22
171#define SSL3_RT_APPLICATION_DATA 23
172
173#define SSL3_AL_WARNING 1
174#define SSL3_AL_FATAL 2
175
176#define SSL3_AD_CLOSE_NOTIFY 0
177#define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */
178#define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */
179#define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */
180#define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */
181#define SSL3_AD_NO_CERTIFICATE 41
182#define SSL3_AD_BAD_CERTIFICATE 42
183#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43
184#define SSL3_AD_CERTIFICATE_REVOKED 44
185#define SSL3_AD_CERTIFICATE_EXPIRED 45
186#define SSL3_AD_CERTIFICATE_UNKNOWN 46
187#define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */
188
189typedef struct ssl3_record_st
190 {
191/*r */ int type; /* type of record */
192/*rw*/ unsigned int length; /* How many bytes available */
193/*r */ unsigned int off; /* read/write offset into 'buf' */
194/*rw*/ unsigned char *data; /* pointer to the record data */
195/*rw*/ unsigned char *input; /* where the decode bytes are */
196/*r */ unsigned char *comp; /* only used with decompression - malloc()ed */
197 } SSL3_RECORD;
198
199typedef struct ssl3_buffer_st
200 {
201 unsigned char *buf; /* SSL3_RT_MAX_PACKET_SIZE bytes (more if
202 * SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER is set) */
203 int offset; /* where to 'copy from' */
204 int left; /* how many bytes left */
205 } SSL3_BUFFER;
206
207#define SSL3_CT_RSA_SIGN 1
208#define SSL3_CT_DSS_SIGN 2
209#define SSL3_CT_RSA_FIXED_DH 3
210#define SSL3_CT_DSS_FIXED_DH 4
211#define SSL3_CT_RSA_EPHEMERAL_DH 5
212#define SSL3_CT_DSS_EPHEMERAL_DH 6
213#define SSL3_CT_FORTEZZA_DMS 20
214#define SSL3_CT_NUMBER 7
215
216#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001
217#define SSL3_FLAGS_DELAY_CLIENT_FINISHED 0x0002
218#define SSL3_FLAGS_POP_BUFFER 0x0004
219#define TLS1_FLAGS_TLS_PADDING_BUG 0x0008
220
221typedef struct ssl3_state_st
222 {
223 long flags;
224 int delay_buf_pop_ret;
225
226 unsigned char read_sequence[8];
227 unsigned char read_mac_secret[EVP_MAX_MD_SIZE];
228 unsigned char write_sequence[8];
229 unsigned char write_mac_secret[EVP_MAX_MD_SIZE];
230
231 unsigned char server_random[SSL3_RANDOM_SIZE];
232 unsigned char client_random[SSL3_RANDOM_SIZE];
233
234 SSL3_BUFFER rbuf; /* read IO goes into here */
235 SSL3_BUFFER wbuf; /* write IO goes into here */
236
237 SSL3_RECORD rrec; /* each decoded record goes in here */
238 SSL3_RECORD wrec; /* goes out from here */
239
240 /* storage for Alert/Handshake protocol data received but not
241 * yet processed by ssl3_read_bytes: */
242 unsigned char alert_fragment[2];
243 unsigned int alert_fragment_len;
244 unsigned char handshake_fragment[4];
245 unsigned int handshake_fragment_len;
246
247 /* partial write - check the numbers match */
248 unsigned int wnum; /* number of bytes sent so far */
249 int wpend_tot; /* number bytes written */
250 int wpend_type;
251 int wpend_ret; /* number of bytes submitted */
252 const unsigned char *wpend_buf;
253
254 /* used during startup, digest all incoming/outgoing packets */
255 EVP_MD_CTX finish_dgst1;
256 EVP_MD_CTX finish_dgst2;
257
258 /* this is set whenerver we see a change_cipher_spec message
259 * come in when we are not looking for one */
260 int change_cipher_spec;
261
262 int warn_alert;
263 int fatal_alert;
264 /* we allow one fatal and one warning alert to be outstanding,
265 * send close alert via the warning alert */
266 int alert_dispatch;
267 unsigned char send_alert[2];
268
269 /* This flag is set when we should renegotiate ASAP, basically when
270 * there is no more data in the read or write buffers */
271 int renegotiate;
272 int total_renegotiations;
273 int num_renegotiations;
274
275 int in_read_app_data;
276
277 struct {
278 /* actually only needs to be 16+20 */
279 unsigned char cert_verify_md[EVP_MAX_MD_SIZE*2];
280
281 /* actually only need to be 16+20 for SSLv3 and 12 for TLS */
282 unsigned char finish_md[EVP_MAX_MD_SIZE*2];
283 int finish_md_len;
284 unsigned char peer_finish_md[EVP_MAX_MD_SIZE*2];
285 int peer_finish_md_len;
286
287 unsigned long message_size;
288 int message_type;
289
290 /* used to hold the new cipher we are going to use */
291 SSL_CIPHER *new_cipher;
292#ifndef NO_DH
293 DH *dh;
294#endif
295 /* used when SSL_ST_FLUSH_DATA is entered */
296 int next_state;
297
298 int reuse_message;
299
300 /* used for certificate requests */
301 int cert_req;
302 int ctype_num;
303 char ctype[SSL3_CT_NUMBER];
304 STACK_OF(X509_NAME) *ca_names;
305
306 int use_rsa_tmp;
307
308 int key_block_length;
309 unsigned char *key_block;
310
311 const EVP_CIPHER *new_sym_enc;
312 const EVP_MD *new_hash;
313#ifdef HEADER_COMP_H
314 const SSL_COMP *new_compression;
315#else
316 char *new_compression;
317#endif
318 int cert_request;
319 } tmp;
320
321 } SSL3_STATE;
322
323/* SSLv3 */
324/*client */
325/* extra state */
326#define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT)
327/* write to server */
328#define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT)
329#define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT)
330/* read from server */
331#define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT)
332#define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT)
333#define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT)
334#define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT)
335#define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT)
336#define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT)
337#define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT)
338#define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT)
339#define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT)
340#define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT)
341/* write to server */
342#define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT)
343#define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT)
344#define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT)
345#define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT)
346#define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT)
347#define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT)
348#define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT)
349#define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT)
350#define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT)
351#define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT)
352#define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT)
353#define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT)
354/* read from server */
355#define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT)
356#define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT)
357#define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT)
358#define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT)
359
360/* server */
361/* extra state */
362#define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT)
363/* read from client */
364/* Do not change the number values, they do matter */
365#define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT)
366#define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT)
367#define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT)
368/* write to client */
369#define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT)
370#define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT)
371#define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT)
372#define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT)
373#define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT)
374#define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT)
375#define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT)
376#define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT)
377#define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT)
378#define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT)
379#define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT)
380#define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT)
381#define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT)
382/* read from client */
383#define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT)
384#define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT)
385#define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT)
386#define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT)
387#define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT)
388#define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT)
389#define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT)
390#define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT)
391#define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT)
392#define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT)
393/* write to client */
394#define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT)
395#define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT)
396#define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT)
397#define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT)
398
399#define SSL3_MT_HELLO_REQUEST 0
400#define SSL3_MT_CLIENT_HELLO 1
401#define SSL3_MT_SERVER_HELLO 2
402#define SSL3_MT_CERTIFICATE 11
403#define SSL3_MT_SERVER_KEY_EXCHANGE 12
404#define SSL3_MT_CERTIFICATE_REQUEST 13
405#define SSL3_MT_SERVER_DONE 14
406#define SSL3_MT_CERTIFICATE_VERIFY 15
407#define SSL3_MT_CLIENT_KEY_EXCHANGE 16
408#define SSL3_MT_FINISHED 20
409
410#define SSL3_MT_CCS 1
411
412/* These are used when changing over to a new cipher */
413#define SSL3_CC_READ 0x01
414#define SSL3_CC_WRITE 0x02
415#define SSL3_CC_CLIENT 0x10
416#define SSL3_CC_SERVER 0x20
417#define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE)
418#define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ)
419#define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ)
420#define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE)
421
422#ifdef __cplusplus
423}
424#endif
425#endif
426
diff --git a/src/lib/libssl/ssl_algs.c b/src/lib/libssl/ssl_algs.c
deleted file mode 100644
index a91ee6d22e..0000000000
--- a/src/lib/libssl/ssl_algs.c
+++ /dev/null
@@ -1,103 +0,0 @@
1/* ssl/ssl_algs.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#include <stdio.h>
60#include <openssl/objects.h>
61#include <openssl/lhash.h>
62#include "ssl_locl.h"
63
64int SSL_library_init(void)
65 {
66#ifndef NO_DES
67 EVP_add_cipher(EVP_des_cbc());
68 EVP_add_cipher(EVP_des_ede3_cbc());
69#endif
70#ifndef NO_IDEA
71 EVP_add_cipher(EVP_idea_cbc());
72#endif
73#ifndef NO_RC4
74 EVP_add_cipher(EVP_rc4());
75#endif
76#ifndef NO_RC2
77 EVP_add_cipher(EVP_rc2_cbc());
78#endif
79
80#ifndef NO_MD2
81 EVP_add_digest(EVP_md2());
82#endif
83#ifndef NO_MD5
84 EVP_add_digest(EVP_md5());
85 EVP_add_digest_alias(SN_md5,"ssl2-md5");
86 EVP_add_digest_alias(SN_md5,"ssl3-md5");
87#endif
88#ifndef NO_SHA
89 EVP_add_digest(EVP_sha1()); /* RSA with sha1 */
90 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
91#endif
92#if !defined(NO_SHA) && !defined(NO_DSA)
93 EVP_add_digest(EVP_dss1()); /* DSA with sha1 */
94#endif
95
96 /* If you want support for phased out ciphers, add the following */
97#if 0
98 EVP_add_digest(EVP_sha());
99 EVP_add_digest(EVP_dss());
100#endif
101 return(1);
102 }
103
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c
deleted file mode 100644
index e77cdddfd3..0000000000
--- a/src/lib/libssl/ssl_asn1.c
+++ /dev/null
@@ -1,349 +0,0 @@
1/* ssl/ssl_asn1.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/asn1_mac.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64#include "ssl_locl.h"
65
66typedef struct ssl_session_asn1_st
67 {
68 ASN1_INTEGER version;
69 ASN1_INTEGER ssl_version;
70 ASN1_OCTET_STRING cipher;
71 ASN1_OCTET_STRING master_key;
72 ASN1_OCTET_STRING session_id;
73 ASN1_OCTET_STRING session_id_context;
74 ASN1_OCTET_STRING key_arg;
75 ASN1_INTEGER time;
76 ASN1_INTEGER timeout;
77 ASN1_INTEGER verify_result;
78 } SSL_SESSION_ASN1;
79
80int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp)
81 {
82#define LSIZE2 (sizeof(long)*2)
83 int v1=0,v2=0,v3=0,v4=0,v5=0;
84 unsigned char buf[4],ibuf1[LSIZE2],ibuf2[LSIZE2];
85 unsigned char ibuf3[LSIZE2],ibuf4[LSIZE2],ibuf5[LSIZE2];
86 long l;
87 SSL_SESSION_ASN1 a;
88 M_ASN1_I2D_vars(in);
89
90 if ((in == NULL) || ((in->cipher == NULL) && (in->cipher_id == 0)))
91 return(0);
92
93 /* Note that I cheat in the following 2 assignments. I know
94 * that if the ASN1_INTEGER passed to ASN1_INTEGER_set
95 * is > sizeof(long)+1, the buffer will not be re-Malloc()ed.
96 * This is a bit evil but makes things simple, no dynamic allocation
97 * to clean up :-) */
98 a.version.length=LSIZE2;
99 a.version.type=V_ASN1_INTEGER;
100 a.version.data=ibuf1;
101 ASN1_INTEGER_set(&(a.version),SSL_SESSION_ASN1_VERSION);
102
103 a.ssl_version.length=LSIZE2;
104 a.ssl_version.type=V_ASN1_INTEGER;
105 a.ssl_version.data=ibuf2;
106 ASN1_INTEGER_set(&(a.ssl_version),in->ssl_version);
107
108 a.cipher.type=V_ASN1_OCTET_STRING;
109 a.cipher.data=buf;
110
111 if (in->cipher == NULL)
112 l=in->cipher_id;
113 else
114 l=in->cipher->id;
115 if (in->ssl_version == SSL2_VERSION)
116 {
117 a.cipher.length=3;
118 buf[0]=((unsigned char)(l>>16L))&0xff;
119 buf[1]=((unsigned char)(l>> 8L))&0xff;
120 buf[2]=((unsigned char)(l ))&0xff;
121 }
122 else
123 {
124 a.cipher.length=2;
125 buf[0]=((unsigned char)(l>>8L))&0xff;
126 buf[1]=((unsigned char)(l ))&0xff;
127 }
128
129 a.master_key.length=in->master_key_length;
130 a.master_key.type=V_ASN1_OCTET_STRING;
131 a.master_key.data=in->master_key;
132
133 a.session_id.length=in->session_id_length;
134 a.session_id.type=V_ASN1_OCTET_STRING;
135 a.session_id.data=in->session_id;
136
137 a.session_id_context.length=in->sid_ctx_length;
138 a.session_id_context.type=V_ASN1_OCTET_STRING;
139 a.session_id_context.data=in->sid_ctx;
140
141 a.key_arg.length=in->key_arg_length;
142 a.key_arg.type=V_ASN1_OCTET_STRING;
143 a.key_arg.data=in->key_arg;
144
145 if (in->time != 0L)
146 {
147 a.time.length=LSIZE2;
148 a.time.type=V_ASN1_INTEGER;
149 a.time.data=ibuf3;
150 ASN1_INTEGER_set(&(a.time),in->time);
151 }
152
153 if (in->timeout != 0L)
154 {
155 a.timeout.length=LSIZE2;
156 a.timeout.type=V_ASN1_INTEGER;
157 a.timeout.data=ibuf4;
158 ASN1_INTEGER_set(&(a.timeout),in->timeout);
159 }
160
161 if (in->verify_result != X509_V_OK)
162 {
163 a.verify_result.length=LSIZE2;
164 a.verify_result.type=V_ASN1_INTEGER;
165 a.verify_result.data=ibuf5;
166 ASN1_INTEGER_set(&a.verify_result,in->verify_result);
167 }
168
169 M_ASN1_I2D_len(&(a.version), i2d_ASN1_INTEGER);
170 M_ASN1_I2D_len(&(a.ssl_version), i2d_ASN1_INTEGER);
171 M_ASN1_I2D_len(&(a.cipher), i2d_ASN1_OCTET_STRING);
172 M_ASN1_I2D_len(&(a.session_id), i2d_ASN1_OCTET_STRING);
173 M_ASN1_I2D_len(&(a.master_key), i2d_ASN1_OCTET_STRING);
174 if (in->key_arg_length > 0)
175 M_ASN1_I2D_len_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING);
176 if (in->time != 0L)
177 M_ASN1_I2D_len_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
178 if (in->timeout != 0L)
179 M_ASN1_I2D_len_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
180 if (in->peer != NULL)
181 M_ASN1_I2D_len_EXP_opt(in->peer,i2d_X509,3,v3);
182 M_ASN1_I2D_len_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,v4);
183 if (in->verify_result != X509_V_OK)
184 M_ASN1_I2D_len_EXP_opt(&(a.verify_result),i2d_ASN1_INTEGER,5,v5);
185
186 M_ASN1_I2D_seq_total();
187
188 M_ASN1_I2D_put(&(a.version), i2d_ASN1_INTEGER);
189 M_ASN1_I2D_put(&(a.ssl_version), i2d_ASN1_INTEGER);
190 M_ASN1_I2D_put(&(a.cipher), i2d_ASN1_OCTET_STRING);
191 M_ASN1_I2D_put(&(a.session_id), i2d_ASN1_OCTET_STRING);
192 M_ASN1_I2D_put(&(a.master_key), i2d_ASN1_OCTET_STRING);
193 if (in->key_arg_length > 0)
194 M_ASN1_I2D_put_IMP_opt(&(a.key_arg),i2d_ASN1_OCTET_STRING,0);
195 if (in->time != 0L)
196 M_ASN1_I2D_put_EXP_opt(&(a.time),i2d_ASN1_INTEGER,1,v1);
197 if (in->timeout != 0L)
198 M_ASN1_I2D_put_EXP_opt(&(a.timeout),i2d_ASN1_INTEGER,2,v2);
199 if (in->peer != NULL)
200 M_ASN1_I2D_put_EXP_opt(in->peer,i2d_X509,3,v3);
201 M_ASN1_I2D_put_EXP_opt(&a.session_id_context,i2d_ASN1_OCTET_STRING,4,
202 v4);
203 if (in->verify_result != X509_V_OK)
204 M_ASN1_I2D_put_EXP_opt(&a.verify_result,i2d_ASN1_INTEGER,5,v5);
205 M_ASN1_I2D_finish();
206 }
207
208SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, unsigned char **pp,
209 long length)
210 {
211 int version,ssl_version=0,i;
212 long id;
213 ASN1_INTEGER ai,*aip;
214 ASN1_OCTET_STRING os,*osp;
215 M_ASN1_D2I_vars(a,SSL_SESSION *,SSL_SESSION_new);
216
217 aip= &ai;
218 osp= &os;
219
220 M_ASN1_D2I_Init();
221 M_ASN1_D2I_start_sequence();
222
223 ai.data=NULL; ai.length=0;
224 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
225 version=(int)ASN1_INTEGER_get(aip);
226 if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; }
227
228 /* we don't care about the version right now :-) */
229 M_ASN1_D2I_get(aip,d2i_ASN1_INTEGER);
230 ssl_version=(int)ASN1_INTEGER_get(aip);
231 ret->ssl_version=ssl_version;
232 if (ai.data != NULL) { Free(ai.data); ai.data=NULL; ai.length=0; }
233
234 os.data=NULL; os.length=0;
235 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
236 if (ssl_version == SSL2_VERSION)
237 {
238 if (os.length != 3)
239 {
240 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
241 goto err;
242 }
243 id=0x02000000L|
244 ((unsigned long)os.data[0]<<16L)|
245 ((unsigned long)os.data[1]<< 8L)|
246 (unsigned long)os.data[2];
247 }
248 else if ((ssl_version>>8) == 3)
249 {
250 if (os.length != 2)
251 {
252 c.error=SSL_R_CIPHER_CODE_WRONG_LENGTH;
253 goto err;
254 }
255 id=0x03000000L|
256 ((unsigned long)os.data[0]<<8L)|
257 (unsigned long)os.data[1];
258 }
259 else
260 {
261 SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_UNKNOWN_SSL_VERSION);
262 return(NULL);
263 }
264
265 ret->cipher=NULL;
266 ret->cipher_id=id;
267
268 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
269 if ((ssl_version>>8) == SSL3_VERSION)
270 i=SSL3_MAX_SSL_SESSION_ID_LENGTH;
271 else /* if (ssl_version == SSL2_VERSION) */
272 i=SSL2_MAX_SSL_SESSION_ID_LENGTH;
273
274 if (os.length > i)
275 os.length=i;
276
277 ret->session_id_length=os.length;
278 memcpy(ret->session_id,os.data,os.length);
279
280 M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING);
281 if (ret->master_key_length > SSL_MAX_MASTER_KEY_LENGTH)
282 ret->master_key_length=SSL_MAX_MASTER_KEY_LENGTH;
283 else
284 ret->master_key_length=os.length;
285 memcpy(ret->master_key,os.data,ret->master_key_length);
286
287 os.length=0;
288 M_ASN1_D2I_get_IMP_opt(osp,d2i_ASN1_OCTET_STRING,0,V_ASN1_OCTET_STRING);
289 if (os.length > SSL_MAX_KEY_ARG_LENGTH)
290 ret->key_arg_length=SSL_MAX_KEY_ARG_LENGTH;
291 else
292 ret->key_arg_length=os.length;
293 memcpy(ret->key_arg,os.data,ret->key_arg_length);
294 if (os.data != NULL) Free(os.data);
295
296 ai.length=0;
297 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,1);
298 if (ai.data != NULL)
299 {
300 ret->time=ASN1_INTEGER_get(aip);
301 Free(ai.data); ai.data=NULL; ai.length=0;
302 }
303 else
304 ret->time=time(NULL);
305
306 ai.length=0;
307 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,2);
308 if (ai.data != NULL)
309 {
310 ret->timeout=ASN1_INTEGER_get(aip);
311 Free(ai.data); ai.data=NULL; ai.length=0;
312 }
313 else
314 ret->timeout=3;
315
316 if (ret->peer != NULL)
317 {
318 X509_free(ret->peer);
319 ret->peer=NULL;
320 }
321 M_ASN1_D2I_get_EXP_opt(ret->peer,d2i_X509,3);
322
323 os.length=0;
324 os.data=NULL;
325 M_ASN1_D2I_get_EXP_opt(osp,d2i_ASN1_OCTET_STRING,4);
326
327 if(os.data != NULL)
328 {
329 if (os.length > SSL_MAX_SID_CTX_LENGTH)
330 SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_BAD_LENGTH);
331 ret->sid_ctx_length=os.length;
332 memcpy(ret->sid_ctx,os.data,os.length);
333 Free(os.data); os.data=NULL; os.length=0;
334 }
335 else
336 ret->sid_ctx_length=0;
337
338 ai.length=0;
339 M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,5);
340 if (ai.data != NULL)
341 {
342 ret->verify_result=ASN1_INTEGER_get(aip);
343 Free(ai.data); ai.data=NULL; ai.length=0;
344 }
345 else
346 ret->verify_result=X509_V_OK;
347
348 M_ASN1_D2I_Finish(a,SSL_SESSION_free,SSL_F_D2I_SSL_SESSION);
349 }
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c
deleted file mode 100644
index f2335d5650..0000000000
--- a/src/lib/libssl/ssl_cert.c
+++ /dev/null
@@ -1,753 +0,0 @@
1/*! \file ssl/ssl_cert.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58/* ====================================================================
59 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
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
71 * distribution.
72 *
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/)"
77 *
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.
82 *
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.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
91 *
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 * ====================================================================
105 */
106
107#include <stdio.h>
108
109#include "openssl/e_os.h"
110
111#ifndef NO_SYS_TYPES_H
112# include <sys/types.h>
113#endif
114
115#if !defined(WIN32) && !defined(VSM) && !defined(NeXT) && !defined(MAC_OS_pre_X)
116#include <dirent.h>
117#endif
118
119#ifdef NeXT
120#include <sys/dir.h>
121#define dirent direct
122#endif
123
124#include <openssl/objects.h>
125#include <openssl/bio.h>
126#include <openssl/pem.h>
127#include <openssl/x509v3.h>
128#include "ssl_locl.h"
129
130int SSL_get_ex_data_X509_STORE_CTX_idx(void)
131 {
132 static int ssl_x509_store_ctx_idx= -1;
133
134 if (ssl_x509_store_ctx_idx < 0)
135 {
136 ssl_x509_store_ctx_idx=X509_STORE_CTX_get_ex_new_index(
137 0,"SSL for verify callback",NULL,NULL,NULL);
138 }
139 return(ssl_x509_store_ctx_idx);
140 }
141
142CERT *ssl_cert_new(void)
143 {
144 CERT *ret;
145
146 ret=(CERT *)Malloc(sizeof(CERT));
147 if (ret == NULL)
148 {
149 SSLerr(SSL_F_SSL_CERT_NEW,ERR_R_MALLOC_FAILURE);
150 return(NULL);
151 }
152 memset(ret,0,sizeof(CERT));
153
154 ret->key= &(ret->pkeys[SSL_PKEY_RSA_ENC]);
155 ret->references=1;
156
157 return(ret);
158 }
159
160CERT *ssl_cert_dup(CERT *cert)
161 {
162 CERT *ret;
163 int i;
164
165 ret = (CERT *)Malloc(sizeof(CERT));
166 if (ret == NULL)
167 {
168 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_MALLOC_FAILURE);
169 return(NULL);
170 }
171
172 memset(ret, 0, sizeof(CERT));
173
174 ret->key = &ret->pkeys[cert->key - &cert->pkeys[0]];
175 /* or ret->key = ret->pkeys + (cert->key - cert->pkeys),
176 * if you find that more readable */
177
178 ret->valid = cert->valid;
179 ret->mask = cert->mask;
180 ret->export_mask = cert->export_mask;
181
182#ifndef NO_RSA
183 if (cert->rsa_tmp != NULL)
184 {
185 ret->rsa_tmp = cert->rsa_tmp;
186 CRYPTO_add(&ret->rsa_tmp->references, 1, CRYPTO_LOCK_RSA);
187 }
188 ret->rsa_tmp_cb = cert->rsa_tmp_cb;
189#endif
190
191#ifndef NO_DH
192 if (cert->dh_tmp != NULL)
193 {
194 /* DH parameters don't have a reference count */
195 ret->dh_tmp = DHparams_dup(cert->dh_tmp);
196 if (ret->dh_tmp == NULL)
197 {
198 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_DH_LIB);
199 goto err;
200 }
201 if (cert->dh_tmp->priv_key)
202 {
203 BIGNUM *b = BN_dup(cert->dh_tmp->priv_key);
204 if (!b)
205 {
206 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB);
207 goto err;
208 }
209 ret->dh_tmp->priv_key = b;
210 }
211 if (cert->dh_tmp->pub_key)
212 {
213 BIGNUM *b = BN_dup(cert->dh_tmp->pub_key);
214 if (!b)
215 {
216 SSLerr(SSL_F_SSL_CERT_DUP, ERR_R_BN_LIB);
217 goto err;
218 }
219 ret->dh_tmp->pub_key = b;
220 }
221 }
222 ret->dh_tmp_cb = cert->dh_tmp_cb;
223#endif
224
225 for (i = 0; i < SSL_PKEY_NUM; i++)
226 {
227 if (cert->pkeys[i].x509 != NULL)
228 {
229 ret->pkeys[i].x509 = cert->pkeys[i].x509;
230 CRYPTO_add(&ret->pkeys[i].x509->references, 1,
231 CRYPTO_LOCK_X509);
232 }
233
234 if (cert->pkeys[i].privatekey != NULL)
235 {
236 ret->pkeys[i].privatekey = cert->pkeys[i].privatekey;
237 CRYPTO_add(&ret->pkeys[i].privatekey->references, 1,
238 CRYPTO_LOCK_EVP_PKEY);
239
240 switch(i)
241 {
242 /* If there was anything special to do for
243 * certain types of keys, we'd do it here.
244 * (Nothing at the moment, I think.) */
245
246 case SSL_PKEY_RSA_ENC:
247 case SSL_PKEY_RSA_SIGN:
248 /* We have an RSA key. */
249 break;
250
251 case SSL_PKEY_DSA_SIGN:
252 /* We have a DSA key. */
253 break;
254
255 case SSL_PKEY_DH_RSA:
256 case SSL_PKEY_DH_DSA:
257 /* We have a DH key. */
258 break;
259
260 default:
261 /* Can't happen. */
262 SSLerr(SSL_F_SSL_CERT_DUP, SSL_R_LIBRARY_BUG);
263 }
264 }
265 }
266
267 /* ret->extra_certs *should* exist, but currently the own certificate
268 * chain is held inside SSL_CTX */
269
270 ret->references=1;
271
272 return(ret);
273
274err:
275#ifndef NO_RSA
276 if (ret->rsa_tmp != NULL)
277 RSA_free(ret->rsa_tmp);
278#endif
279#ifndef NO_DH
280 if (ret->dh_tmp != NULL)
281 DH_free(ret->dh_tmp);
282#endif
283
284 for (i = 0; i < SSL_PKEY_NUM; i++)
285 {
286 if (ret->pkeys[i].x509 != NULL)
287 X509_free(ret->pkeys[i].x509);
288 if (ret->pkeys[i].privatekey != NULL)
289 EVP_PKEY_free(ret->pkeys[i].privatekey);
290 }
291
292 return NULL;
293 }
294
295
296void ssl_cert_free(CERT *c)
297 {
298 int i;
299
300 if(c == NULL)
301 return;
302
303 i=CRYPTO_add(&c->references,-1,CRYPTO_LOCK_SSL_CERT);
304#ifdef REF_PRINT
305 REF_PRINT("CERT",c);
306#endif
307 if (i > 0) return;
308#ifdef REF_CHECK
309 if (i < 0)
310 {
311 fprintf(stderr,"ssl_cert_free, bad reference count\n");
312 abort(); /* ok */
313 }
314#endif
315
316#ifndef NO_RSA
317 if (c->rsa_tmp) RSA_free(c->rsa_tmp);
318#endif
319#ifndef NO_DH
320 if (c->dh_tmp) DH_free(c->dh_tmp);
321#endif
322
323 for (i=0; i<SSL_PKEY_NUM; i++)
324 {
325 if (c->pkeys[i].x509 != NULL)
326 X509_free(c->pkeys[i].x509);
327 if (c->pkeys[i].privatekey != NULL)
328 EVP_PKEY_free(c->pkeys[i].privatekey);
329#if 0
330 if (c->pkeys[i].publickey != NULL)
331 EVP_PKEY_free(c->pkeys[i].publickey);
332#endif
333 }
334 Free(c);
335 }
336
337int ssl_cert_inst(CERT **o)
338 {
339 /* Create a CERT if there isn't already one
340 * (which cannot really happen, as it is initially created in
341 * SSL_CTX_new; but the earlier code usually allows for that one
342 * being non-existant, so we follow that behaviour, as it might
343 * turn out that there actually is a reason for it -- but I'm
344 * not sure that *all* of the existing code could cope with
345 * s->cert being NULL, otherwise we could do without the
346 * initialization in SSL_CTX_new).
347 */
348
349 if (o == NULL)
350 {
351 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_PASSED_NULL_PARAMETER);
352 return(0);
353 }
354 if (*o == NULL)
355 {
356 if ((*o = ssl_cert_new()) == NULL)
357 {
358 SSLerr(SSL_F_SSL_CERT_INST, ERR_R_MALLOC_FAILURE);
359 return(0);
360 }
361 }
362 return(1);
363 }
364
365
366SESS_CERT *ssl_sess_cert_new(void)
367 {
368 SESS_CERT *ret;
369
370 ret = Malloc(sizeof *ret);
371 if (ret == NULL)
372 {
373 SSLerr(SSL_F_SSL_SESS_CERT_NEW, ERR_R_MALLOC_FAILURE);
374 return NULL;
375 }
376
377 memset(ret, 0 ,sizeof *ret);
378 ret->peer_key = &(ret->peer_pkeys[SSL_PKEY_RSA_ENC]);
379 ret->references = 1;
380
381 return ret;
382 }
383
384void ssl_sess_cert_free(SESS_CERT *sc)
385 {
386 int i;
387
388 if (sc == NULL)
389 return;
390
391 i = CRYPTO_add(&sc->references, -1, CRYPTO_LOCK_SSL_SESS_CERT);
392#ifdef REF_PRINT
393 REF_PRINT("SESS_CERT", sc);
394#endif
395 if (i > 0)
396 return;
397#ifdef REF_CHECK
398 if (i < 0)
399 {
400 fprintf(stderr,"ssl_sess_cert_free, bad reference count\n");
401 abort(); /* ok */
402 }
403#endif
404
405 /* i == 0 */
406 if (sc->cert_chain != NULL)
407 sk_X509_pop_free(sc->cert_chain, X509_free);
408 for (i = 0; i < SSL_PKEY_NUM; i++)
409 {
410 if (sc->peer_pkeys[i].x509 != NULL)
411 X509_free(sc->peer_pkeys[i].x509);
412#if 0 /* We don't have the peer's private key. These lines are just
413 * here as a reminder that we're still using a not-quite-appropriate
414 * data structure. */
415 if (sc->peer_pkeys[i].privatekey != NULL)
416 EVP_PKEY_free(sc->peer_pkeys[i].privatekey);
417#endif
418 }
419
420#ifndef NO_RSA
421 if (sc->peer_rsa_tmp != NULL)
422 RSA_free(sc->peer_rsa_tmp);
423#endif
424#ifndef NO_DH
425 if (sc->peer_dh_tmp != NULL)
426 DH_free(sc->peer_dh_tmp);
427#endif
428
429 Free(sc);
430 }
431
432int ssl_set_peer_cert_type(SESS_CERT *sc,int type)
433 {
434 sc->peer_cert_type = type;
435 return(1);
436 }
437
438int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk)
439 {
440 X509 *x;
441 int i;
442 X509_STORE_CTX ctx;
443
444 if ((sk == NULL) || (sk_X509_num(sk) == 0))
445 return(0);
446
447 x=sk_X509_value(sk,0);
448 X509_STORE_CTX_init(&ctx,s->ctx->cert_store,x,sk);
449 if (SSL_get_verify_depth(s) >= 0)
450 X509_STORE_CTX_set_depth(&ctx, SSL_get_verify_depth(s));
451 X509_STORE_CTX_set_ex_data(&ctx,SSL_get_ex_data_X509_STORE_CTX_idx(),s);
452 /* We need to set the verify purpose. The purpose can be determined by
453 * the context: if its a server it will verify SSL client certificates
454 * or vice versa.
455 */
456
457 if(s->server) i = X509_PURPOSE_SSL_CLIENT;
458 else i = X509_PURPOSE_SSL_SERVER;
459
460 X509_STORE_CTX_purpose_inherit(&ctx, i, s->purpose, s->trust);
461
462 if (s->ctx->app_verify_callback != NULL)
463 i=s->ctx->app_verify_callback(&ctx); /* should pass app_verify_arg */
464 else
465 {
466#ifndef NO_X509_VERIFY
467 i=X509_verify_cert(&ctx);
468#else
469 i=0;
470 ctx.error=X509_V_ERR_APPLICATION_VERIFICATION;
471 SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,SSL_R_NO_VERIFY_CALLBACK);
472#endif
473 }
474
475 s->verify_result=ctx.error;
476 X509_STORE_CTX_cleanup(&ctx);
477
478 return(i);
479 }
480
481static void set_client_CA_list(STACK_OF(X509_NAME) **ca_list,STACK_OF(X509_NAME) *list)
482 {
483 if (*ca_list != NULL)
484 sk_X509_NAME_pop_free(*ca_list,X509_NAME_free);
485
486 *ca_list=list;
487 }
488
489STACK_OF(X509_NAME) *SSL_dup_CA_list(STACK_OF(X509_NAME) *sk)
490 {
491 int i;
492 STACK_OF(X509_NAME) *ret;
493 X509_NAME *name;
494
495 ret=sk_X509_NAME_new_null();
496 for (i=0; i<sk_X509_NAME_num(sk); i++)
497 {
498 name=X509_NAME_dup(sk_X509_NAME_value(sk,i));
499 if ((name == NULL) || !sk_X509_NAME_push(ret,name))
500 {
501 sk_X509_NAME_pop_free(ret,X509_NAME_free);
502 return(NULL);
503 }
504 }
505 return(ret);
506 }
507
508void SSL_set_client_CA_list(SSL *s,STACK_OF(X509_NAME) *list)
509 {
510 set_client_CA_list(&(s->client_CA),list);
511 }
512
513void SSL_CTX_set_client_CA_list(SSL_CTX *ctx,STACK_OF(X509_NAME) *list)
514 {
515 set_client_CA_list(&(ctx->client_CA),list);
516 }
517
518STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(SSL_CTX *ctx)
519 {
520 return(ctx->client_CA);
521 }
522
523STACK_OF(X509_NAME) *SSL_get_client_CA_list(SSL *s)
524 {
525 if (s->type == SSL_ST_CONNECT)
526 { /* we are in the client */
527 if (((s->version>>8) == SSL3_VERSION_MAJOR) &&
528 (s->s3 != NULL))
529 return(s->s3->tmp.ca_names);
530 else
531 return(NULL);
532 }
533 else
534 {
535 if (s->client_CA != NULL)
536 return(s->client_CA);
537 else
538 return(s->ctx->client_CA);
539 }
540 }
541
542static int add_client_CA(STACK_OF(X509_NAME) **sk,X509 *x)
543 {
544 X509_NAME *name;
545
546 if (x == NULL) return(0);
547 if ((*sk == NULL) && ((*sk=sk_X509_NAME_new_null()) == NULL))
548 return(0);
549
550 if ((name=X509_NAME_dup(X509_get_subject_name(x))) == NULL)
551 return(0);
552
553 if (!sk_X509_NAME_push(*sk,name))
554 {
555 X509_NAME_free(name);
556 return(0);
557 }
558 return(1);
559 }
560
561int SSL_add_client_CA(SSL *ssl,X509 *x)
562 {
563 return(add_client_CA(&(ssl->client_CA),x));
564 }
565
566int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x)
567 {
568 return(add_client_CA(&(ctx->client_CA),x));
569 }
570
571static int xname_cmp(X509_NAME **a,X509_NAME **b)
572 {
573 return(X509_NAME_cmp(*a,*b));
574 }
575
576#ifndef NO_STDIO
577/*!
578 * Load CA certs from a file into a ::STACK. Note that it is somewhat misnamed;
579 * it doesn't really have anything to do with clients (except that a common use
580 * for a stack of CAs is to send it to the client). Actually, it doesn't have
581 * much to do with CAs, either, since it will load any old cert.
582 * \param file the file containing one or more certs.
583 * \return a ::STACK containing the certs.
584 */
585STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file)
586 {
587 BIO *in;
588 X509 *x=NULL;
589 X509_NAME *xn=NULL;
590 STACK_OF(X509_NAME) *ret,*sk;
591
592 ret=sk_X509_NAME_new(NULL);
593 sk=sk_X509_NAME_new(xname_cmp);
594
595 in=BIO_new(BIO_s_file_internal());
596
597 if ((ret == NULL) || (sk == NULL) || (in == NULL))
598 {
599 SSLerr(SSL_F_SSL_LOAD_CLIENT_CA_FILE,ERR_R_MALLOC_FAILURE);
600 goto err;
601 }
602
603 if (!BIO_read_filename(in,file))
604 goto err;
605
606 for (;;)
607 {
608 if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)
609 break;
610 if ((xn=X509_get_subject_name(x)) == NULL) goto err;
611 /* check for duplicates */
612 xn=X509_NAME_dup(xn);
613 if (xn == NULL) goto err;
614 if (sk_X509_NAME_find(sk,xn) >= 0)
615 X509_NAME_free(xn);
616 else
617 {
618 sk_X509_NAME_push(sk,xn);
619 sk_X509_NAME_push(ret,xn);
620 }
621 }
622
623 if (0)
624 {
625err:
626 if (ret != NULL) sk_X509_NAME_pop_free(ret,X509_NAME_free);
627 ret=NULL;
628 }
629 if (sk != NULL) sk_X509_NAME_free(sk);
630 if (in != NULL) BIO_free(in);
631 if (x != NULL) X509_free(x);
632 return(ret);
633 }
634#endif
635
636/*!
637 * Add a file of certs to a stack.
638 * \param stack the stack to add to.
639 * \param file the file to add from. All certs in this file that are not
640 * already in the stack will be added.
641 * \return 1 for success, 0 for failure. Note that in the case of failure some
642 * certs may have been added to \c stack.
643 */
644
645int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
646 const char *file)
647 {
648 BIO *in;
649 X509 *x=NULL;
650 X509_NAME *xn=NULL;
651 int ret=1;
652 int (*oldcmp)(X509_NAME **a, X509_NAME **b);
653
654 oldcmp=sk_X509_NAME_set_cmp_func(stack,xname_cmp);
655
656 in=BIO_new(BIO_s_file_internal());
657
658 if (in == NULL)
659 {
660 SSLerr(SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,ERR_R_MALLOC_FAILURE);
661 goto err;
662 }
663
664 if (!BIO_read_filename(in,file))
665 goto err;
666
667 for (;;)
668 {
669 if (PEM_read_bio_X509(in,&x,NULL,NULL) == NULL)
670 break;
671 if ((xn=X509_get_subject_name(x)) == NULL) goto err;
672 xn=X509_NAME_dup(xn);
673 if (xn == NULL) goto err;
674 if (sk_X509_NAME_find(stack,xn) >= 0)
675 X509_NAME_free(xn);
676 else
677 sk_X509_NAME_push(stack,xn);
678 }
679
680 if (0)
681 {
682err:
683 ret=0;
684 }
685 if(in != NULL)
686 BIO_free(in);
687 if(x != NULL)
688 X509_free(x);
689
690 sk_X509_NAME_set_cmp_func(stack,oldcmp);
691
692 return ret;
693 }
694
695/*!
696 * Add a directory of certs to a stack.
697 * \param stack the stack to append to.
698 * \param dir the directory to append from. All files in this directory will be
699 * examined as potential certs. Any that are acceptable to
700 * SSL_add_dir_cert_subjects_to_stack() that are not already in the stack will be
701 * included.
702 * \return 1 for success, 0 for failure. Note that in the case of failure some
703 * certs may have been added to \c stack.
704 */
705
706#ifndef WIN32
707#ifndef VMS /* XXXX This may be fixed in the future */
708#ifndef MAC_OS_pre_X
709
710int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
711 const char *dir)
712 {
713 DIR *d;
714 struct dirent *dstruct;
715 int ret = 0;
716
717 CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
718 d = opendir(dir);
719
720 /* Note that a side effect is that the CAs will be sorted by name */
721 if(!d)
722 {
723 SYSerr(SYS_F_OPENDIR, get_last_sys_error());
724 ERR_add_error_data(3, "opendir('", dir, "')");
725 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
726 goto err;
727 }
728
729 while((dstruct=readdir(d)))
730 {
731 char buf[1024];
732
733 if(strlen(dir)+strlen(dstruct->d_name)+2 > sizeof buf)
734 {
735 SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
736 goto err;
737 }
738
739 sprintf(buf,"%s/%s",dir,dstruct->d_name);
740 if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
741 goto err;
742 }
743 ret = 1;
744
745err:
746 closedir(d);
747 CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
748 return ret;
749 }
750
751#endif
752#endif
753#endif
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c
deleted file mode 100644
index 7436a50ad1..0000000000
--- a/src/lib/libssl/ssl_ciph.c
+++ /dev/null
@@ -1,1069 +0,0 @@
1/* ssl/ssl_ciph.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#include <stdio.h>
60#include <openssl/objects.h>
61#include <openssl/comp.h>
62#include "ssl_locl.h"
63
64#define SSL_ENC_DES_IDX 0
65#define SSL_ENC_3DES_IDX 1
66#define SSL_ENC_RC4_IDX 2
67#define SSL_ENC_RC2_IDX 3
68#define SSL_ENC_IDEA_IDX 4
69#define SSL_ENC_eFZA_IDX 5
70#define SSL_ENC_NULL_IDX 6
71#define SSL_ENC_NUM_IDX 7
72
73static const EVP_CIPHER *ssl_cipher_methods[SSL_ENC_NUM_IDX]={
74 NULL,NULL,NULL,NULL,NULL,NULL,
75 };
76
77static STACK_OF(SSL_COMP) *ssl_comp_methods=NULL;
78
79#define SSL_MD_MD5_IDX 0
80#define SSL_MD_SHA1_IDX 1
81#define SSL_MD_NUM_IDX 2
82static const EVP_MD *ssl_digest_methods[SSL_MD_NUM_IDX]={
83 NULL,NULL,
84 };
85
86#define CIPHER_ADD 1
87#define CIPHER_KILL 2
88#define CIPHER_DEL 3
89#define CIPHER_ORD 4
90#define CIPHER_SPECIAL 5
91
92typedef struct cipher_order_st
93 {
94 SSL_CIPHER *cipher;
95 int active;
96 int dead;
97 struct cipher_order_st *next,*prev;
98 } CIPHER_ORDER;
99
100static const SSL_CIPHER cipher_aliases[]={
101 /* Don't include eNULL unless specifically enabled */
102 {0,SSL_TXT_ALL, 0,SSL_ALL & ~SSL_eNULL, SSL_ALL ,0,0,0,SSL_ALL,SSL_ALL}, /* must be first */
103 {0,SSL_TXT_kRSA,0,SSL_kRSA, 0,0,0,0,SSL_MKEY_MASK,0},
104 {0,SSL_TXT_kDHr,0,SSL_kDHr, 0,0,0,0,SSL_MKEY_MASK,0},
105 {0,SSL_TXT_kDHd,0,SSL_kDHd, 0,0,0,0,SSL_MKEY_MASK,0},
106 {0,SSL_TXT_kEDH,0,SSL_kEDH, 0,0,0,0,SSL_MKEY_MASK,0},
107 {0,SSL_TXT_kFZA,0,SSL_kFZA, 0,0,0,0,SSL_MKEY_MASK,0},
108 {0,SSL_TXT_DH, 0,SSL_DH, 0,0,0,0,SSL_MKEY_MASK,0},
109 {0,SSL_TXT_EDH, 0,SSL_EDH, 0,0,0,0,SSL_MKEY_MASK|SSL_AUTH_MASK,0},
110
111 {0,SSL_TXT_aRSA,0,SSL_aRSA, 0,0,0,0,SSL_AUTH_MASK,0},
112 {0,SSL_TXT_aDSS,0,SSL_aDSS, 0,0,0,0,SSL_AUTH_MASK,0},
113 {0,SSL_TXT_aFZA,0,SSL_aFZA, 0,0,0,0,SSL_AUTH_MASK,0},
114 {0,SSL_TXT_aNULL,0,SSL_aNULL,0,0,0,0,SSL_AUTH_MASK,0},
115 {0,SSL_TXT_aDH, 0,SSL_aDH, 0,0,0,0,SSL_AUTH_MASK,0},
116 {0,SSL_TXT_DSS, 0,SSL_DSS, 0,0,0,0,SSL_AUTH_MASK,0},
117
118 {0,SSL_TXT_DES, 0,SSL_DES, 0,0,0,0,SSL_ENC_MASK,0},
119 {0,SSL_TXT_3DES,0,SSL_3DES, 0,0,0,0,SSL_ENC_MASK,0},
120 {0,SSL_TXT_RC4, 0,SSL_RC4, 0,0,0,0,SSL_ENC_MASK,0},
121 {0,SSL_TXT_RC2, 0,SSL_RC2, 0,0,0,0,SSL_ENC_MASK,0},
122 {0,SSL_TXT_IDEA,0,SSL_IDEA, 0,0,0,0,SSL_ENC_MASK,0},
123 {0,SSL_TXT_eNULL,0,SSL_eNULL,0,0,0,0,SSL_ENC_MASK,0},
124 {0,SSL_TXT_eFZA,0,SSL_eFZA, 0,0,0,0,SSL_ENC_MASK,0},
125
126 {0,SSL_TXT_MD5, 0,SSL_MD5, 0,0,0,0,SSL_MAC_MASK,0},
127 {0,SSL_TXT_SHA1,0,SSL_SHA1, 0,0,0,0,SSL_MAC_MASK,0},
128 {0,SSL_TXT_SHA, 0,SSL_SHA, 0,0,0,0,SSL_MAC_MASK,0},
129
130 {0,SSL_TXT_NULL,0,SSL_NULL, 0,0,0,0,SSL_ENC_MASK,0},
131 {0,SSL_TXT_RSA, 0,SSL_RSA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
132 {0,SSL_TXT_ADH, 0,SSL_ADH, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK,0},
133 {0,SSL_TXT_FZA, 0,SSL_FZA, 0,0,0,0,SSL_AUTH_MASK|SSL_MKEY_MASK|SSL_ENC_MASK,0},
134
135 {0,SSL_TXT_SSLV2, 0,SSL_SSLV2, 0,0,0,0,SSL_SSL_MASK,0},
136 {0,SSL_TXT_SSLV3, 0,SSL_SSLV3, 0,0,0,0,SSL_SSL_MASK,0},
137 {0,SSL_TXT_TLSV1, 0,SSL_TLSV1, 0,0,0,0,SSL_SSL_MASK,0},
138
139 {0,SSL_TXT_EXP ,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
140 {0,SSL_TXT_EXPORT,0, 0,SSL_EXPORT, 0,0,0,0,SSL_EXP_MASK},
141 {0,SSL_TXT_EXP40, 0, 0, SSL_EXP40, 0,0,0,0,SSL_STRONG_MASK},
142 {0,SSL_TXT_EXP56, 0, 0, SSL_EXP56, 0,0,0,0,SSL_STRONG_MASK},
143 {0,SSL_TXT_LOW, 0, 0, SSL_LOW, 0,0,0,0,SSL_STRONG_MASK},
144 {0,SSL_TXT_MEDIUM,0, 0,SSL_MEDIUM, 0,0,0,0,SSL_STRONG_MASK},
145 {0,SSL_TXT_HIGH, 0, 0, SSL_HIGH, 0,0,0,0,SSL_STRONG_MASK},
146 };
147
148static int init_ciphers=1;
149
150static void load_ciphers(void)
151 {
152 init_ciphers=0;
153 ssl_cipher_methods[SSL_ENC_DES_IDX]=
154 EVP_get_cipherbyname(SN_des_cbc);
155 ssl_cipher_methods[SSL_ENC_3DES_IDX]=
156 EVP_get_cipherbyname(SN_des_ede3_cbc);
157 ssl_cipher_methods[SSL_ENC_RC4_IDX]=
158 EVP_get_cipherbyname(SN_rc4);
159 ssl_cipher_methods[SSL_ENC_RC2_IDX]=
160 EVP_get_cipherbyname(SN_rc2_cbc);
161 ssl_cipher_methods[SSL_ENC_IDEA_IDX]=
162 EVP_get_cipherbyname(SN_idea_cbc);
163
164 ssl_digest_methods[SSL_MD_MD5_IDX]=
165 EVP_get_digestbyname(SN_md5);
166 ssl_digest_methods[SSL_MD_SHA1_IDX]=
167 EVP_get_digestbyname(SN_sha1);
168 }
169
170int ssl_cipher_get_evp(SSL_SESSION *s, const EVP_CIPHER **enc,
171 const EVP_MD **md, SSL_COMP **comp)
172 {
173 int i;
174 SSL_CIPHER *c;
175
176 c=s->cipher;
177 if (c == NULL) return(0);
178 if (comp != NULL)
179 {
180 SSL_COMP ctmp;
181
182 if (s->compress_meth == 0)
183 *comp=NULL;
184 else if (ssl_comp_methods == NULL)
185 {
186 /* bad */
187 *comp=NULL;
188 }
189 else
190 {
191
192 ctmp.id=s->compress_meth;
193 i=sk_SSL_COMP_find(ssl_comp_methods,&ctmp);
194 if (i >= 0)
195 *comp=sk_SSL_COMP_value(ssl_comp_methods,i);
196 else
197 *comp=NULL;
198 }
199 }
200
201 if ((enc == NULL) || (md == NULL)) return(0);
202
203 switch (c->algorithms & SSL_ENC_MASK)
204 {
205 case SSL_DES:
206 i=SSL_ENC_DES_IDX;
207 break;
208 case SSL_3DES:
209 i=SSL_ENC_3DES_IDX;
210 break;
211 case SSL_RC4:
212 i=SSL_ENC_RC4_IDX;
213 break;
214 case SSL_RC2:
215 i=SSL_ENC_RC2_IDX;
216 break;
217 case SSL_IDEA:
218 i=SSL_ENC_IDEA_IDX;
219 break;
220 case SSL_eNULL:
221 i=SSL_ENC_NULL_IDX;
222 break;
223 default:
224 i= -1;
225 break;
226 }
227
228 if ((i < 0) || (i > SSL_ENC_NUM_IDX))
229 *enc=NULL;
230 else
231 {
232 if (i == SSL_ENC_NULL_IDX)
233 *enc=EVP_enc_null();
234 else
235 *enc=ssl_cipher_methods[i];
236 }
237
238 switch (c->algorithms & SSL_MAC_MASK)
239 {
240 case SSL_MD5:
241 i=SSL_MD_MD5_IDX;
242 break;
243 case SSL_SHA1:
244 i=SSL_MD_SHA1_IDX;
245 break;
246 default:
247 i= -1;
248 break;
249 }
250 if ((i < 0) || (i > SSL_MD_NUM_IDX))
251 *md=NULL;
252 else
253 *md=ssl_digest_methods[i];
254
255 if ((*enc != NULL) && (*md != NULL))
256 return(1);
257 else
258 return(0);
259 }
260
261#define ITEM_SEP(a) \
262 (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
263
264static void ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr,
265 CIPHER_ORDER **tail)
266 {
267 if (curr == *tail) return;
268 if (curr == *head)
269 *head=curr->next;
270 if (curr->prev != NULL)
271 curr->prev->next=curr->next;
272 if (curr->next != NULL) /* should always be true */
273 curr->next->prev=curr->prev;
274 (*tail)->next=curr;
275 curr->prev= *tail;
276 curr->next=NULL;
277 *tail=curr;
278 }
279
280static unsigned long ssl_cipher_get_disabled(void)
281 {
282 unsigned long mask;
283
284 mask = SSL_kFZA;
285#ifdef NO_RSA
286 mask |= SSL_aRSA|SSL_kRSA;
287#endif
288#ifdef NO_DSA
289 mask |= SSL_aDSS;
290#endif
291#ifdef NO_DH
292 mask |= SSL_kDHr|SSL_kDHd|SSL_kEDH|SSL_aDH;
293#endif
294
295#ifdef SSL_FORBID_ENULL
296 mask |= SSL_eNULL;
297#endif
298
299 mask |= (ssl_cipher_methods[SSL_ENC_DES_IDX ] == NULL) ? SSL_DES :0;
300 mask |= (ssl_cipher_methods[SSL_ENC_3DES_IDX] == NULL) ? SSL_3DES:0;
301 mask |= (ssl_cipher_methods[SSL_ENC_RC4_IDX ] == NULL) ? SSL_RC4 :0;
302 mask |= (ssl_cipher_methods[SSL_ENC_RC2_IDX ] == NULL) ? SSL_RC2 :0;
303 mask |= (ssl_cipher_methods[SSL_ENC_IDEA_IDX] == NULL) ? SSL_IDEA:0;
304 mask |= (ssl_cipher_methods[SSL_ENC_eFZA_IDX] == NULL) ? SSL_eFZA:0;
305
306 mask |= (ssl_digest_methods[SSL_MD_MD5_IDX ] == NULL) ? SSL_MD5 :0;
307 mask |= (ssl_digest_methods[SSL_MD_SHA1_IDX] == NULL) ? SSL_SHA1:0;
308
309 return(mask);
310 }
311
312static void ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method,
313 int num_of_ciphers, unsigned long mask, CIPHER_ORDER *list,
314 CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
315 {
316 int i, list_num;
317 SSL_CIPHER *c;
318
319 /*
320 * We have num_of_ciphers descriptions compiled in, depending on the
321 * method selected (SSLv2 and/or SSLv3, TLSv1 etc).
322 * These will later be sorted in a linked list with at most num
323 * entries.
324 */
325
326 /* Get the initial list of ciphers */
327 list_num = 0; /* actual count of ciphers */
328 for (i = 0; i < num_of_ciphers; i++)
329 {
330 c = ssl_method->get_cipher(i);
331 /* drop those that use any of that is not available */
332 if ((c != NULL) && c->valid && !(c->algorithms & mask))
333 {
334 list[list_num].cipher = c;
335 list[list_num].next = NULL;
336 list[list_num].prev = NULL;
337 list[list_num].active = 0;
338 list_num++;
339 /*
340 if (!sk_push(ca_list,(char *)c)) goto err;
341 */
342 }
343 }
344
345 /*
346 * Prepare linked list from list entries
347 */
348 for (i = 1; i < list_num - 1; i++)
349 {
350 list[i].prev = &(list[i-1]);
351 list[i].next = &(list[i+1]);
352 }
353 if (list_num > 0)
354 {
355 (*head_p) = &(list[0]);
356 (*head_p)->prev = NULL;
357 (*head_p)->next = &(list[1]);
358 (*tail_p) = &(list[list_num - 1]);
359 (*tail_p)->prev = &(list[list_num - 2]);
360 (*tail_p)->next = NULL;
361 }
362 }
363
364static void ssl_cipher_collect_aliases(SSL_CIPHER **ca_list,
365 int num_of_group_aliases, unsigned long mask,
366 CIPHER_ORDER *head)
367 {
368 CIPHER_ORDER *ciph_curr;
369 SSL_CIPHER **ca_curr;
370 int i;
371
372 /*
373 * First, add the real ciphers as already collected
374 */
375 ciph_curr = head;
376 ca_curr = ca_list;
377 while (ciph_curr != NULL)
378 {
379 *ca_curr = ciph_curr->cipher;
380 ca_curr++;
381 ciph_curr = ciph_curr->next;
382 }
383
384 /*
385 * Now we add the available ones from the cipher_aliases[] table.
386 * They represent either an algorithm, that must be fully
387 * supported (not match any bit in mask) or represent a cipher
388 * strength value (will be added in any case because algorithms=0).
389 */
390 for (i = 0; i < num_of_group_aliases; i++)
391 {
392 if ((i == 0) || /* always fetch "ALL" */
393 !(cipher_aliases[i].algorithms & mask))
394 {
395 *ca_curr = (SSL_CIPHER *)(cipher_aliases + i);
396 ca_curr++;
397 }
398 }
399
400 *ca_curr = NULL; /* end of list */
401 }
402
403static void ssl_cipher_apply_rule(unsigned long algorithms, unsigned long mask,
404 unsigned long algo_strength, unsigned long mask_strength,
405 int rule, int strength_bits, CIPHER_ORDER *list,
406 CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
407 {
408 CIPHER_ORDER *head, *tail, *curr, *curr2, *tail2;
409 SSL_CIPHER *cp;
410 unsigned long ma, ma_s;
411
412#ifdef CIPHER_DEBUG
413 printf("Applying rule %d with %08lx %08lx %08lx %08lx (%d)\n",
414 rule, algorithms, mask, algo_strength, mask_strength,
415 strength_bits);
416#endif
417
418 curr = head = *head_p;
419 curr2 = head;
420 tail2 = tail = *tail_p;
421 for (;;)
422 {
423 if ((curr == NULL) || (curr == tail2)) break;
424 curr = curr2;
425 curr2 = curr->next;
426
427 cp = curr->cipher;
428
429 /*
430 * Selection criteria is either the number of strength_bits
431 * or the algorithm used.
432 */
433 if (strength_bits == -1)
434 {
435 ma = mask & cp->algorithms;
436 ma_s = mask_strength & cp->algo_strength;
437
438#ifdef CIPHER_DEBUG
439 printf("\nName: %s:\nAlgo = %08lx Algo_strength = %08lx\nMask = %08lx Mask_strength %08lx\n", cp->name, cp->algorithms, cp->algo_strength, mask, mask_strength);
440 printf("ma = %08lx ma_s %08lx, ma&algo=%08lx, ma_s&algos=%08lx\n", ma, ma_s, ma&algorithms, ma_s&algo_strength);
441#endif
442 /*
443 * Select: if none of the mask bit was met from the
444 * cipher or not all of the bits were met, the
445 * selection does not apply.
446 */
447 if (((ma == 0) && (ma_s == 0)) ||
448 ((ma & algorithms) != ma) ||
449 ((ma_s & algo_strength) != ma_s))
450 continue; /* does not apply */
451 }
452 else if (strength_bits != cp->strength_bits)
453 continue; /* does not apply */
454
455#ifdef CIPHER_DEBUG
456 printf("Action = %d\n", rule);
457#endif
458
459 /* add the cipher if it has not been added yet. */
460 if (rule == CIPHER_ADD)
461 {
462 if (!curr->active)
463 {
464 ll_append_tail(&head, curr, &tail);
465 curr->active = 1;
466 }
467 }
468 /* Move the added cipher to this location */
469 else if (rule == CIPHER_ORD)
470 {
471 if (curr->active)
472 {
473 ll_append_tail(&head, curr, &tail);
474 }
475 }
476 else if (rule == CIPHER_DEL)
477 curr->active = 0;
478 else if (rule == CIPHER_KILL)
479 {
480 if (head == curr)
481 head = curr->next;
482 else
483 curr->prev->next = curr->next;
484 if (tail == curr)
485 tail = curr->prev;
486 curr->active = 0;
487 if (curr->next != NULL)
488 curr->next->prev = curr->prev;
489 if (curr->prev != NULL)
490 curr->prev->next = curr->next;
491 curr->next = NULL;
492 curr->prev = NULL;
493 }
494 }
495
496 *head_p = head;
497 *tail_p = tail;
498 }
499
500static int ssl_cipher_strength_sort(CIPHER_ORDER *list, CIPHER_ORDER **head_p,
501 CIPHER_ORDER **tail_p)
502 {
503 int max_strength_bits, i, *number_uses;
504 CIPHER_ORDER *curr;
505
506 /*
507 * This routine sorts the ciphers with descending strength. The sorting
508 * must keep the pre-sorted sequence, so we apply the normal sorting
509 * routine as '+' movement to the end of the list.
510 */
511 max_strength_bits = 0;
512 curr = *head_p;
513 while (curr != NULL)
514 {
515 if (curr->active &&
516 (curr->cipher->strength_bits > max_strength_bits))
517 max_strength_bits = curr->cipher->strength_bits;
518 curr = curr->next;
519 }
520
521 number_uses = Malloc((max_strength_bits + 1) * sizeof(int));
522 if (!number_uses)
523 {
524 SSLerr(SSL_F_SSL_CIPHER_STRENGTH_SORT,ERR_R_MALLOC_FAILURE);
525 return(0);
526 }
527 memset(number_uses, 0, (max_strength_bits + 1) * sizeof(int));
528
529 /*
530 * Now find the strength_bits values actually used
531 */
532 curr = *head_p;
533 while (curr != NULL)
534 {
535 if (curr->active)
536 number_uses[curr->cipher->strength_bits]++;
537 curr = curr->next;
538 }
539 /*
540 * Go through the list of used strength_bits values in descending
541 * order.
542 */
543 for (i = max_strength_bits; i >= 0; i--)
544 if (number_uses[i] > 0)
545 ssl_cipher_apply_rule(0, 0, 0, 0, CIPHER_ORD, i,
546 list, head_p, tail_p);
547
548 Free(number_uses);
549 return(1);
550 }
551
552static int ssl_cipher_process_rulestr(const char *rule_str,
553 CIPHER_ORDER *list, CIPHER_ORDER **head_p,
554 CIPHER_ORDER **tail_p, SSL_CIPHER **ca_list)
555 {
556 unsigned long algorithms, mask, algo_strength, mask_strength;
557 const char *l, *start, *buf;
558 int j, multi, found, rule, retval, ok, buflen;
559 char ch;
560
561 retval = 1;
562 l = rule_str;
563 for (;;)
564 {
565 ch = *l;
566
567 if (ch == '\0')
568 break; /* done */
569 if (ch == '-')
570 { rule = CIPHER_DEL; l++; }
571 else if (ch == '+')
572 { rule = CIPHER_ORD; l++; }
573 else if (ch == '!')
574 { rule = CIPHER_KILL; l++; }
575 else if (ch == '@')
576 { rule = CIPHER_SPECIAL; l++; }
577 else
578 { rule = CIPHER_ADD; }
579
580 if (ITEM_SEP(ch))
581 {
582 l++;
583 continue;
584 }
585
586 algorithms = mask = algo_strength = mask_strength = 0;
587
588 start=l;
589 for (;;)
590 {
591 ch = *l;
592 buf = l;
593 buflen = 0;
594#ifndef CHARSET_EBCDIC
595 while ( ((ch >= 'A') && (ch <= 'Z')) ||
596 ((ch >= '0') && (ch <= '9')) ||
597 ((ch >= 'a') && (ch <= 'z')) ||
598 (ch == '-'))
599#else
600 while ( isalnum(ch) || (ch == '-'))
601#endif
602 {
603 ch = *(++l);
604 buflen++;
605 }
606
607 if (buflen == 0)
608 {
609 /*
610 * We hit something we cannot deal with,
611 * it is no command or separator nor
612 * alphanumeric, so we call this an error.
613 */
614 SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
615 SSL_R_INVALID_COMMAND);
616 retval = found = 0;
617 l++;
618 break;
619 }
620
621 if (rule == CIPHER_SPECIAL)
622 {
623 found = 0; /* unused -- avoid compiler warning */
624 break; /* special treatment */
625 }
626
627 /* check for multi-part specification */
628 if (ch == '+')
629 {
630 multi=1;
631 l++;
632 }
633 else
634 multi=0;
635
636 /*
637 * Now search for the cipher alias in the ca_list. Be careful
638 * with the strncmp, because the "buflen" limitation
639 * will make the rule "ADH:SOME" and the cipher
640 * "ADH-MY-CIPHER" look like a match for buflen=3.
641 * So additionally check whether the cipher name found
642 * has the correct length. We can save a strlen() call:
643 * just checking for the '\0' at the right place is
644 * sufficient, we have to strncmp() anyway.
645 */
646 j = found = 0;
647 while (ca_list[j])
648 {
649 if ((ca_list[j]->name[buflen] == '\0') &&
650 !strncmp(buf, ca_list[j]->name, buflen))
651 {
652 found = 1;
653 break;
654 }
655 else
656 j++;
657 }
658 if (!found)
659 break; /* ignore this entry */
660
661 algorithms |= ca_list[j]->algorithms;
662 mask |= ca_list[j]->mask;
663 algo_strength |= ca_list[j]->algo_strength;
664 mask_strength |= ca_list[j]->mask_strength;
665
666 if (!multi) break;
667 }
668
669 /*
670 * Ok, we have the rule, now apply it
671 */
672 if (rule == CIPHER_SPECIAL)
673 { /* special command */
674 ok = 0;
675 if ((buflen == 8) &&
676 !strncmp(buf, "STRENGTH", 8))
677 ok = ssl_cipher_strength_sort(list,
678 head_p, tail_p);
679 else
680 SSLerr(SSL_F_SSL_CIPHER_PROCESS_RULESTR,
681 SSL_R_INVALID_COMMAND);
682 if (ok == 0)
683 retval = 0;
684 /*
685 * We do not support any "multi" options
686 * together with "@", so throw away the
687 * rest of the command, if any left, until
688 * end or ':' is found.
689 */
690 while ((*l != '\0') && ITEM_SEP(*l))
691 l++;
692 }
693 else if (found)
694 {
695 ssl_cipher_apply_rule(algorithms, mask,
696 algo_strength, mask_strength, rule, -1,
697 list, head_p, tail_p);
698 }
699 else
700 {
701 while ((*l != '\0') && ITEM_SEP(*l))
702 l++;
703 }
704 if (*l == '\0') break; /* done */
705 }
706
707 return(retval);
708 }
709
710STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method,
711 STACK_OF(SSL_CIPHER) **cipher_list,
712 STACK_OF(SSL_CIPHER) **cipher_list_by_id,
713 const char *rule_str)
714 {
715 int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases;
716 unsigned long disabled_mask;
717 STACK_OF(SSL_CIPHER) *cipherstack;
718 const char *rule_p;
719 CIPHER_ORDER *list = NULL, *head = NULL, *tail = NULL, *curr;
720 SSL_CIPHER **ca_list = NULL;
721
722 /*
723 * Return with error if nothing to do.
724 */
725 if (rule_str == NULL) return(NULL);
726
727 if (init_ciphers) load_ciphers();
728
729 /*
730 * To reduce the work to do we only want to process the compiled
731 * in algorithms, so we first get the mask of disabled ciphers.
732 */
733 disabled_mask = ssl_cipher_get_disabled();
734
735 /*
736 * Now we have to collect the available ciphers from the compiled
737 * in ciphers. We cannot get more than the number compiled in, so
738 * it is used for allocation.
739 */
740 num_of_ciphers = ssl_method->num_ciphers();
741 list = (CIPHER_ORDER *)Malloc(sizeof(CIPHER_ORDER) * num_of_ciphers);
742 if (list == NULL)
743 {
744 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
745 return(NULL); /* Failure */
746 }
747
748 ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers, disabled_mask,
749 list, &head, &tail);
750
751 /*
752 * We also need cipher aliases for selecting based on the rule_str.
753 * There might be two types of entries in the rule_str: 1) names
754 * of ciphers themselves 2) aliases for groups of ciphers.
755 * For 1) we need the available ciphers and for 2) the cipher
756 * groups of cipher_aliases added together in one list (otherwise
757 * we would be happy with just the cipher_aliases table).
758 */
759 num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER);
760 num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
761 ca_list =
762 (SSL_CIPHER **)Malloc(sizeof(SSL_CIPHER *) * num_of_alias_max);
763 if (ca_list == NULL)
764 {
765 Free(list);
766 SSLerr(SSL_F_SSL_CREATE_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
767 return(NULL); /* Failure */
768 }
769 ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, disabled_mask,
770 head);
771
772 /*
773 * If the rule_string begins with DEFAULT, apply the default rule
774 * before using the (possibly available) additional rules.
775 */
776 ok = 1;
777 rule_p = rule_str;
778 if (strncmp(rule_str,"DEFAULT",7) == 0)
779 {
780 ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST,
781 list, &head, &tail, ca_list);
782 rule_p += 7;
783 if (*rule_p == ':')
784 rule_p++;
785 }
786
787 if (ok && (strlen(rule_p) > 0))
788 ok = ssl_cipher_process_rulestr(rule_p, list, &head, &tail,
789 ca_list);
790
791 Free(ca_list); /* Not needed anymore */
792
793 if (!ok)
794 { /* Rule processing failure */
795 Free(list);
796 return(NULL);
797 }
798 /*
799 * Allocate new "cipherstack" for the result, return with error
800 * if we cannot get one.
801 */
802 if ((cipherstack = sk_SSL_CIPHER_new(NULL)) == NULL)
803 {
804 Free(list);
805 return(NULL);
806 }
807
808 /*
809 * The cipher selection for the list is done. The ciphers are added
810 * to the resulting precedence to the STACK_OF(SSL_CIPHER).
811 */
812 for (curr = head; curr != NULL; curr = curr->next)
813 {
814 if (curr->active)
815 {
816 sk_SSL_CIPHER_push(cipherstack, curr->cipher);
817#ifdef CIPHER_DEBUG
818 printf("<%s>\n",curr->cipher->name);
819#endif
820 }
821 }
822 Free(list); /* Not needed any longer */
823
824 /*
825 * The following passage is a little bit odd. If pointer variables
826 * were supplied to hold STACK_OF(SSL_CIPHER) return information,
827 * the old memory pointed to is free()ed. Then, however, the
828 * cipher_list entry will be assigned just a copy of the returned
829 * cipher stack. For cipher_list_by_id a copy of the cipher stack
830 * will be created. See next comment...
831 */
832 if (cipher_list != NULL)
833 {
834 if (*cipher_list != NULL)
835 sk_SSL_CIPHER_free(*cipher_list);
836 *cipher_list = cipherstack;
837 }
838
839 if (cipher_list_by_id != NULL)
840 {
841 if (*cipher_list_by_id != NULL)
842 sk_SSL_CIPHER_free(*cipher_list_by_id);
843 *cipher_list_by_id = sk_SSL_CIPHER_dup(cipherstack);
844 }
845
846 /*
847 * Now it is getting really strange. If something failed during
848 * the previous pointer assignment or if one of the pointers was
849 * not requested, the error condition is met. That might be
850 * discussable. The strange thing is however that in this case
851 * the memory "ret" pointed to is "free()ed" and hence the pointer
852 * cipher_list becomes wild. The memory reserved for
853 * cipher_list_by_id however is not "free()ed" and stays intact.
854 */
855 if ( (cipher_list_by_id == NULL) ||
856 (*cipher_list_by_id == NULL) ||
857 (cipher_list == NULL) ||
858 (*cipher_list == NULL))
859 {
860 sk_SSL_CIPHER_free(cipherstack);
861 return(NULL);
862 }
863
864 sk_SSL_CIPHER_set_cmp_func(*cipher_list_by_id,ssl_cipher_ptr_id_cmp);
865
866 return(cipherstack);
867 }
868
869char *SSL_CIPHER_description(SSL_CIPHER *cipher, char *buf, int len)
870 {
871 int is_export,pkl,kl;
872 char *ver,*exp;
873 char *kx,*au,*enc,*mac;
874 unsigned long alg,alg2,alg_s;
875 static char *format="%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s%s\n";
876
877 alg=cipher->algorithms;
878 alg_s=cipher->algo_strength;
879 alg2=cipher->algorithm2;
880
881 is_export=SSL_C_IS_EXPORT(cipher);
882 pkl=SSL_C_EXPORT_PKEYLENGTH(cipher);
883 kl=SSL_C_EXPORT_KEYLENGTH(cipher);
884 exp=is_export?" export":"";
885
886 if (alg & SSL_SSLV2)
887 ver="SSLv2";
888 else if (alg & SSL_SSLV3)
889 ver="SSLv3";
890 else
891 ver="unknown";
892
893 switch (alg&SSL_MKEY_MASK)
894 {
895 case SSL_kRSA:
896 kx=is_export?(pkl == 512 ? "RSA(512)" : "RSA(1024)"):"RSA";
897 break;
898 case SSL_kDHr:
899 kx="DH/RSA";
900 break;
901 case SSL_kDHd:
902 kx="DH/DSS";
903 break;
904 case SSL_kFZA:
905 kx="Fortezza";
906 break;
907 case SSL_kEDH:
908 kx=is_export?(pkl == 512 ? "DH(512)" : "DH(1024)"):"DH";
909 break;
910 default:
911 kx="unknown";
912 }
913
914 switch (alg&SSL_AUTH_MASK)
915 {
916 case SSL_aRSA:
917 au="RSA";
918 break;
919 case SSL_aDSS:
920 au="DSS";
921 break;
922 case SSL_aDH:
923 au="DH";
924 break;
925 case SSL_aFZA:
926 case SSL_aNULL:
927 au="None";
928 break;
929 default:
930 au="unknown";
931 break;
932 }
933
934 switch (alg&SSL_ENC_MASK)
935 {
936 case SSL_DES:
937 enc=(is_export && kl == 5)?"DES(40)":"DES(56)";
938 break;
939 case SSL_3DES:
940 enc="3DES(168)";
941 break;
942 case SSL_RC4:
943 enc=is_export?(kl == 5 ? "RC4(40)" : "RC4(56)")
944 :((alg2&SSL2_CF_8_BYTE_ENC)?"RC4(64)":"RC4(128)");
945 break;
946 case SSL_RC2:
947 enc=is_export?(kl == 5 ? "RC2(40)" : "RC2(56)"):"RC2(128)";
948 break;
949 case SSL_IDEA:
950 enc="IDEA(128)";
951 break;
952 case SSL_eFZA:
953 enc="Fortezza";
954 break;
955 case SSL_eNULL:
956 enc="None";
957 break;
958 default:
959 enc="unknown";
960 break;
961 }
962
963 switch (alg&SSL_MAC_MASK)
964 {
965 case SSL_MD5:
966 mac="MD5";
967 break;
968 case SSL_SHA1:
969 mac="SHA1";
970 break;
971 default:
972 mac="unknown";
973 break;
974 }
975
976 if (buf == NULL)
977 {
978 buf=Malloc(128);
979 if (buf == NULL) return("Malloc Error");
980 }
981 else if (len < 128)
982 return("Buffer too small");
983
984 sprintf(buf,format,cipher->name,ver,kx,au,enc,mac,exp);
985 return(buf);
986 }
987
988char *SSL_CIPHER_get_version(SSL_CIPHER *c)
989 {
990 int i;
991
992 if (c == NULL) return("(NONE)");
993 i=(int)(c->id>>24L);
994 if (i == 3)
995 return("TLSv1/SSLv3");
996 else if (i == 2)
997 return("SSLv2");
998 else
999 return("unknown");
1000 }
1001
1002/* return the actual cipher being used */
1003const char *SSL_CIPHER_get_name(SSL_CIPHER *c)
1004 {
1005 if (c != NULL)
1006 return(c->name);
1007 return("(NONE)");
1008 }
1009
1010/* number of bits for symmetric cipher */
1011int SSL_CIPHER_get_bits(SSL_CIPHER *c, int *alg_bits)
1012 {
1013 int ret=0;
1014
1015 if (c != NULL)
1016 {
1017 if (alg_bits != NULL) *alg_bits = c->alg_bits;
1018 ret = c->strength_bits;
1019 }
1020 return(ret);
1021 }
1022
1023SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n)
1024 {
1025 SSL_COMP *ctmp;
1026 int i,nn;
1027
1028 if ((n == 0) || (sk == NULL)) return(NULL);
1029 nn=sk_SSL_COMP_num(sk);
1030 for (i=0; i<nn; i++)
1031 {
1032 ctmp=sk_SSL_COMP_value(sk,i);
1033 if (ctmp->id == n)
1034 return(ctmp);
1035 }
1036 return(NULL);
1037 }
1038
1039static int sk_comp_cmp(SSL_COMP **a,SSL_COMP **b)
1040 {
1041 return((*a)->id-(*b)->id);
1042 }
1043
1044STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void)
1045 {
1046 return(ssl_comp_methods);
1047 }
1048
1049int SSL_COMP_add_compression_method(int id, COMP_METHOD *cm)
1050 {
1051 SSL_COMP *comp;
1052 STACK_OF(SSL_COMP) *sk;
1053
1054 comp=(SSL_COMP *)Malloc(sizeof(SSL_COMP));
1055 comp->id=id;
1056 comp->method=cm;
1057 if (ssl_comp_methods == NULL)
1058 sk=ssl_comp_methods=sk_SSL_COMP_new(sk_comp_cmp);
1059 else
1060 sk=ssl_comp_methods;
1061 if ((sk == NULL) || !sk_SSL_COMP_push(sk,comp))
1062 {
1063 SSLerr(SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,ERR_R_MALLOC_FAILURE);
1064 return(0);
1065 }
1066 else
1067 return(1);
1068 }
1069
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c
deleted file mode 100644
index 642c3f93e7..0000000000
--- a/src/lib/libssl/ssl_err.c
+++ /dev/null
@@ -1,430 +0,0 @@
1/* ssl/ssl_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/ssl.h>
64
65/* BEGIN ERROR CODES */
66#ifndef NO_ERR
67static ERR_STRING_DATA SSL_str_functs[]=
68 {
69{ERR_PACK(0,SSL_F_CLIENT_CERTIFICATE,0), "CLIENT_CERTIFICATE"},
70{ERR_PACK(0,SSL_F_CLIENT_HELLO,0), "CLIENT_HELLO"},
71{ERR_PACK(0,SSL_F_CLIENT_MASTER_KEY,0), "CLIENT_MASTER_KEY"},
72{ERR_PACK(0,SSL_F_D2I_SSL_SESSION,0), "d2i_SSL_SESSION"},
73{ERR_PACK(0,SSL_F_DO_SSL3_WRITE,0), "DO_SSL3_WRITE"},
74{ERR_PACK(0,SSL_F_GET_CLIENT_FINISHED,0), "GET_CLIENT_FINISHED"},
75{ERR_PACK(0,SSL_F_GET_CLIENT_HELLO,0), "GET_CLIENT_HELLO"},
76{ERR_PACK(0,SSL_F_GET_CLIENT_MASTER_KEY,0), "GET_CLIENT_MASTER_KEY"},
77{ERR_PACK(0,SSL_F_GET_SERVER_FINISHED,0), "GET_SERVER_FINISHED"},
78{ERR_PACK(0,SSL_F_GET_SERVER_HELLO,0), "GET_SERVER_HELLO"},
79{ERR_PACK(0,SSL_F_GET_SERVER_VERIFY,0), "GET_SERVER_VERIFY"},
80{ERR_PACK(0,SSL_F_I2D_SSL_SESSION,0), "i2d_SSL_SESSION"},
81{ERR_PACK(0,SSL_F_READ_N,0), "READ_N"},
82{ERR_PACK(0,SSL_F_REQUEST_CERTIFICATE,0), "REQUEST_CERTIFICATE"},
83{ERR_PACK(0,SSL_F_SERVER_HELLO,0), "SERVER_HELLO"},
84{ERR_PACK(0,SSL_F_SSL23_ACCEPT,0), "SSL23_ACCEPT"},
85{ERR_PACK(0,SSL_F_SSL23_CLIENT_HELLO,0), "SSL23_CLIENT_HELLO"},
86{ERR_PACK(0,SSL_F_SSL23_CONNECT,0), "SSL23_CONNECT"},
87{ERR_PACK(0,SSL_F_SSL23_GET_CLIENT_HELLO,0), "SSL23_GET_CLIENT_HELLO"},
88{ERR_PACK(0,SSL_F_SSL23_GET_SERVER_HELLO,0), "SSL23_GET_SERVER_HELLO"},
89{ERR_PACK(0,SSL_F_SSL23_READ,0), "SSL23_READ"},
90{ERR_PACK(0,SSL_F_SSL23_WRITE,0), "SSL23_WRITE"},
91{ERR_PACK(0,SSL_F_SSL2_ACCEPT,0), "SSL2_ACCEPT"},
92{ERR_PACK(0,SSL_F_SSL2_CONNECT,0), "SSL2_CONNECT"},
93{ERR_PACK(0,SSL_F_SSL2_ENC_INIT,0), "SSL2_ENC_INIT"},
94{ERR_PACK(0,SSL_F_SSL2_READ,0), "SSL2_READ"},
95{ERR_PACK(0,SSL_F_SSL2_SET_CERTIFICATE,0), "SSL2_SET_CERTIFICATE"},
96{ERR_PACK(0,SSL_F_SSL2_WRITE,0), "SSL2_WRITE"},
97{ERR_PACK(0,SSL_F_SSL3_ACCEPT,0), "SSL3_ACCEPT"},
98{ERR_PACK(0,SSL_F_SSL3_CALLBACK_CTRL,0), "SSL3_CALLBACK_CTRL"},
99{ERR_PACK(0,SSL_F_SSL3_CHANGE_CIPHER_STATE,0), "SSL3_CHANGE_CIPHER_STATE"},
100{ERR_PACK(0,SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,0), "SSL3_CHECK_CERT_AND_ALGORITHM"},
101{ERR_PACK(0,SSL_F_SSL3_CLIENT_HELLO,0), "SSL3_CLIENT_HELLO"},
102{ERR_PACK(0,SSL_F_SSL3_CONNECT,0), "SSL3_CONNECT"},
103{ERR_PACK(0,SSL_F_SSL3_CTRL,0), "SSL3_CTRL"},
104{ERR_PACK(0,SSL_F_SSL3_CTX_CTRL,0), "SSL3_CTX_CTRL"},
105{ERR_PACK(0,SSL_F_SSL3_ENC,0), "SSL3_ENC"},
106{ERR_PACK(0,SSL_F_SSL3_GET_CERTIFICATE_REQUEST,0), "SSL3_GET_CERTIFICATE_REQUEST"},
107{ERR_PACK(0,SSL_F_SSL3_GET_CERT_VERIFY,0), "SSL3_GET_CERT_VERIFY"},
108{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_CERTIFICATE,0), "SSL3_GET_CLIENT_CERTIFICATE"},
109{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_HELLO,0), "SSL3_GET_CLIENT_HELLO"},
110{ERR_PACK(0,SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,0), "SSL3_GET_CLIENT_KEY_EXCHANGE"},
111{ERR_PACK(0,SSL_F_SSL3_GET_FINISHED,0), "SSL3_GET_FINISHED"},
112{ERR_PACK(0,SSL_F_SSL3_GET_KEY_EXCHANGE,0), "SSL3_GET_KEY_EXCHANGE"},
113{ERR_PACK(0,SSL_F_SSL3_GET_MESSAGE,0), "SSL3_GET_MESSAGE"},
114{ERR_PACK(0,SSL_F_SSL3_GET_RECORD,0), "SSL3_GET_RECORD"},
115{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_CERTIFICATE,0), "SSL3_GET_SERVER_CERTIFICATE"},
116{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_DONE,0), "SSL3_GET_SERVER_DONE"},
117{ERR_PACK(0,SSL_F_SSL3_GET_SERVER_HELLO,0), "SSL3_GET_SERVER_HELLO"},
118{ERR_PACK(0,SSL_F_SSL3_OUTPUT_CERT_CHAIN,0), "SSL3_OUTPUT_CERT_CHAIN"},
119{ERR_PACK(0,SSL_F_SSL3_READ_BYTES,0), "SSL3_READ_BYTES"},
120{ERR_PACK(0,SSL_F_SSL3_READ_N,0), "SSL3_READ_N"},
121{ERR_PACK(0,SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,0), "SSL3_SEND_CERTIFICATE_REQUEST"},
122{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_CERTIFICATE,0), "SSL3_SEND_CLIENT_CERTIFICATE"},
123{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,0), "SSL3_SEND_CLIENT_KEY_EXCHANGE"},
124{ERR_PACK(0,SSL_F_SSL3_SEND_CLIENT_VERIFY,0), "SSL3_SEND_CLIENT_VERIFY"},
125{ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_CERTIFICATE,0), "SSL3_SEND_SERVER_CERTIFICATE"},
126{ERR_PACK(0,SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,0), "SSL3_SEND_SERVER_KEY_EXCHANGE"},
127{ERR_PACK(0,SSL_F_SSL3_SETUP_BUFFERS,0), "SSL3_SETUP_BUFFERS"},
128{ERR_PACK(0,SSL_F_SSL3_SETUP_KEY_BLOCK,0), "SSL3_SETUP_KEY_BLOCK"},
129{ERR_PACK(0,SSL_F_SSL3_WRITE_BYTES,0), "SSL3_WRITE_BYTES"},
130{ERR_PACK(0,SSL_F_SSL3_WRITE_PENDING,0), "SSL3_WRITE_PENDING"},
131{ERR_PACK(0,SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,0), "SSL_add_dir_cert_subjects_to_stack"},
132{ERR_PACK(0,SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK,0), "SSL_add_file_cert_subjects_to_stack"},
133{ERR_PACK(0,SSL_F_SSL_BAD_METHOD,0), "SSL_BAD_METHOD"},
134{ERR_PACK(0,SSL_F_SSL_BYTES_TO_CIPHER_LIST,0), "SSL_BYTES_TO_CIPHER_LIST"},
135{ERR_PACK(0,SSL_F_SSL_CERT_DUP,0), "SSL_CERT_DUP"},
136{ERR_PACK(0,SSL_F_SSL_CERT_INST,0), "SSL_CERT_INST"},
137{ERR_PACK(0,SSL_F_SSL_CERT_INSTANTIATE,0), "SSL_CERT_INSTANTIATE"},
138{ERR_PACK(0,SSL_F_SSL_CERT_NEW,0), "SSL_CERT_NEW"},
139{ERR_PACK(0,SSL_F_SSL_CHECK_PRIVATE_KEY,0), "SSL_check_private_key"},
140{ERR_PACK(0,SSL_F_SSL_CIPHER_PROCESS_RULESTR,0), "SSL_CIPHER_PROCESS_RULESTR"},
141{ERR_PACK(0,SSL_F_SSL_CIPHER_STRENGTH_SORT,0), "SSL_CIPHER_STRENGTH_SORT"},
142{ERR_PACK(0,SSL_F_SSL_CLEAR,0), "SSL_clear"},
143{ERR_PACK(0,SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD,0), "SSL_COMP_add_compression_method"},
144{ERR_PACK(0,SSL_F_SSL_CREATE_CIPHER_LIST,0), "SSL_CREATE_CIPHER_LIST"},
145{ERR_PACK(0,SSL_F_SSL_CTRL,0), "SSL_ctrl"},
146{ERR_PACK(0,SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,0), "SSL_CTX_check_private_key"},
147{ERR_PACK(0,SSL_F_SSL_CTX_NEW,0), "SSL_CTX_new"},
148{ERR_PACK(0,SSL_F_SSL_CTX_SET_PURPOSE,0), "SSL_CTX_set_purpose"},
149{ERR_PACK(0,SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,0), "SSL_CTX_set_session_id_context"},
150{ERR_PACK(0,SSL_F_SSL_CTX_SET_SSL_VERSION,0), "SSL_CTX_set_ssl_version"},
151{ERR_PACK(0,SSL_F_SSL_CTX_SET_TRUST,0), "SSL_CTX_set_trust"},
152{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE,0), "SSL_CTX_use_certificate"},
153{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,0), "SSL_CTX_use_certificate_ASN1"},
154{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,0), "SSL_CTX_use_certificate_chain_file"},
155{ERR_PACK(0,SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,0), "SSL_CTX_use_certificate_file"},
156{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY,0), "SSL_CTX_use_PrivateKey"},
157{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,0), "SSL_CTX_use_PrivateKey_ASN1"},
158{ERR_PACK(0,SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,0), "SSL_CTX_use_PrivateKey_file"},
159{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,0), "SSL_CTX_use_RSAPrivateKey"},
160{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,0), "SSL_CTX_use_RSAPrivateKey_ASN1"},
161{ERR_PACK(0,SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,0), "SSL_CTX_use_RSAPrivateKey_file"},
162{ERR_PACK(0,SSL_F_SSL_DO_HANDSHAKE,0), "SSL_do_handshake"},
163{ERR_PACK(0,SSL_F_SSL_GET_NEW_SESSION,0), "SSL_GET_NEW_SESSION"},
164{ERR_PACK(0,SSL_F_SSL_GET_PREV_SESSION,0), "SSL_GET_PREV_SESSION"},
165{ERR_PACK(0,SSL_F_SSL_GET_SERVER_SEND_CERT,0), "SSL_GET_SERVER_SEND_CERT"},
166{ERR_PACK(0,SSL_F_SSL_GET_SIGN_PKEY,0), "SSL_GET_SIGN_PKEY"},
167{ERR_PACK(0,SSL_F_SSL_INIT_WBIO_BUFFER,0), "SSL_INIT_WBIO_BUFFER"},
168{ERR_PACK(0,SSL_F_SSL_LOAD_CLIENT_CA_FILE,0), "SSL_load_client_CA_file"},
169{ERR_PACK(0,SSL_F_SSL_NEW,0), "SSL_new"},
170{ERR_PACK(0,SSL_F_SSL_READ,0), "SSL_read"},
171{ERR_PACK(0,SSL_F_SSL_RSA_PRIVATE_DECRYPT,0), "SSL_RSA_PRIVATE_DECRYPT"},
172{ERR_PACK(0,SSL_F_SSL_RSA_PUBLIC_ENCRYPT,0), "SSL_RSA_PUBLIC_ENCRYPT"},
173{ERR_PACK(0,SSL_F_SSL_SESSION_NEW,0), "SSL_SESSION_new"},
174{ERR_PACK(0,SSL_F_SSL_SESSION_PRINT_FP,0), "SSL_SESSION_print_fp"},
175{ERR_PACK(0,SSL_F_SSL_SESS_CERT_NEW,0), "SSL_SESS_CERT_NEW"},
176{ERR_PACK(0,SSL_F_SSL_SET_CERT,0), "SSL_SET_CERT"},
177{ERR_PACK(0,SSL_F_SSL_SET_FD,0), "SSL_set_fd"},
178{ERR_PACK(0,SSL_F_SSL_SET_PKEY,0), "SSL_SET_PKEY"},
179{ERR_PACK(0,SSL_F_SSL_SET_PURPOSE,0), "SSL_set_purpose"},
180{ERR_PACK(0,SSL_F_SSL_SET_RFD,0), "SSL_set_rfd"},
181{ERR_PACK(0,SSL_F_SSL_SET_SESSION,0), "SSL_set_session"},
182{ERR_PACK(0,SSL_F_SSL_SET_SESSION_ID_CONTEXT,0), "SSL_set_session_id_context"},
183{ERR_PACK(0,SSL_F_SSL_SET_TRUST,0), "SSL_set_trust"},
184{ERR_PACK(0,SSL_F_SSL_SET_WFD,0), "SSL_set_wfd"},
185{ERR_PACK(0,SSL_F_SSL_SHUTDOWN,0), "SSL_shutdown"},
186{ERR_PACK(0,SSL_F_SSL_UNDEFINED_FUNCTION,0), "SSL_UNDEFINED_FUNCTION"},
187{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE,0), "SSL_use_certificate"},
188{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_ASN1,0), "SSL_use_certificate_ASN1"},
189{ERR_PACK(0,SSL_F_SSL_USE_CERTIFICATE_FILE,0), "SSL_use_certificate_file"},
190{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY,0), "SSL_use_PrivateKey"},
191{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_ASN1,0), "SSL_use_PrivateKey_ASN1"},
192{ERR_PACK(0,SSL_F_SSL_USE_PRIVATEKEY_FILE,0), "SSL_use_PrivateKey_file"},
193{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY,0), "SSL_use_RSAPrivateKey"},
194{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,0), "SSL_use_RSAPrivateKey_ASN1"},
195{ERR_PACK(0,SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,0), "SSL_use_RSAPrivateKey_file"},
196{ERR_PACK(0,SSL_F_SSL_VERIFY_CERT_CHAIN,0), "SSL_VERIFY_CERT_CHAIN"},
197{ERR_PACK(0,SSL_F_SSL_WRITE,0), "SSL_write"},
198{ERR_PACK(0,SSL_F_TLS1_CHANGE_CIPHER_STATE,0), "TLS1_CHANGE_CIPHER_STATE"},
199{ERR_PACK(0,SSL_F_TLS1_ENC,0), "TLS1_ENC"},
200{ERR_PACK(0,SSL_F_TLS1_SETUP_KEY_BLOCK,0), "TLS1_SETUP_KEY_BLOCK"},
201{ERR_PACK(0,SSL_F_WRITE_PENDING,0), "WRITE_PENDING"},
202{0,NULL}
203 };
204
205static ERR_STRING_DATA SSL_str_reasons[]=
206 {
207{SSL_R_APP_DATA_IN_HANDSHAKE ,"app data in handshake"},
208{SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT,"attempt to reuse session in different context"},
209{SSL_R_BAD_ALERT_RECORD ,"bad alert record"},
210{SSL_R_BAD_AUTHENTICATION_TYPE ,"bad authentication type"},
211{SSL_R_BAD_CHANGE_CIPHER_SPEC ,"bad change cipher spec"},
212{SSL_R_BAD_CHECKSUM ,"bad checksum"},
213{SSL_R_BAD_DATA_RETURNED_BY_CALLBACK ,"bad data returned by callback"},
214{SSL_R_BAD_DECOMPRESSION ,"bad decompression"},
215{SSL_R_BAD_DH_G_LENGTH ,"bad dh g length"},
216{SSL_R_BAD_DH_PUB_KEY_LENGTH ,"bad dh pub key length"},
217{SSL_R_BAD_DH_P_LENGTH ,"bad dh p length"},
218{SSL_R_BAD_DIGEST_LENGTH ,"bad digest length"},
219{SSL_R_BAD_DSA_SIGNATURE ,"bad dsa signature"},
220{SSL_R_BAD_HELLO_REQUEST ,"bad hello request"},
221{SSL_R_BAD_LENGTH ,"bad length"},
222{SSL_R_BAD_MAC_DECODE ,"bad mac decode"},
223{SSL_R_BAD_MESSAGE_TYPE ,"bad message type"},
224{SSL_R_BAD_PACKET_LENGTH ,"bad packet length"},
225{SSL_R_BAD_PROTOCOL_VERSION_NUMBER ,"bad protocol version number"},
226{SSL_R_BAD_RESPONSE_ARGUMENT ,"bad response argument"},
227{SSL_R_BAD_RSA_DECRYPT ,"bad rsa decrypt"},
228{SSL_R_BAD_RSA_ENCRYPT ,"bad rsa encrypt"},
229{SSL_R_BAD_RSA_E_LENGTH ,"bad rsa e length"},
230{SSL_R_BAD_RSA_MODULUS_LENGTH ,"bad rsa modulus length"},
231{SSL_R_BAD_RSA_SIGNATURE ,"bad rsa signature"},
232{SSL_R_BAD_SIGNATURE ,"bad signature"},
233{SSL_R_BAD_SSL_FILETYPE ,"bad ssl filetype"},
234{SSL_R_BAD_SSL_SESSION_ID_LENGTH ,"bad ssl session id length"},
235{SSL_R_BAD_STATE ,"bad state"},
236{SSL_R_BAD_WRITE_RETRY ,"bad write retry"},
237{SSL_R_BIO_NOT_SET ,"bio not set"},
238{SSL_R_BLOCK_CIPHER_PAD_IS_WRONG ,"block cipher pad is wrong"},
239{SSL_R_BN_LIB ,"bn lib"},
240{SSL_R_CA_DN_LENGTH_MISMATCH ,"ca dn length mismatch"},
241{SSL_R_CA_DN_TOO_LONG ,"ca dn too long"},
242{SSL_R_CCS_RECEIVED_EARLY ,"ccs received early"},
243{SSL_R_CERTIFICATE_VERIFY_FAILED ,"certificate verify failed"},
244{SSL_R_CERT_LENGTH_MISMATCH ,"cert length mismatch"},
245{SSL_R_CHALLENGE_IS_DIFFERENT ,"challenge is different"},
246{SSL_R_CIPHER_CODE_WRONG_LENGTH ,"cipher code wrong length"},
247{SSL_R_CIPHER_OR_HASH_UNAVAILABLE ,"cipher or hash unavailable"},
248{SSL_R_CIPHER_TABLE_SRC_ERROR ,"cipher table src error"},
249{SSL_R_COMPRESSED_LENGTH_TOO_LONG ,"compressed length too long"},
250{SSL_R_COMPRESSION_FAILURE ,"compression failure"},
251{SSL_R_COMPRESSION_LIBRARY_ERROR ,"compression library error"},
252{SSL_R_CONNECTION_ID_IS_DIFFERENT ,"connection id is different"},
253{SSL_R_CONNECTION_TYPE_NOT_SET ,"connection type not set"},
254{SSL_R_DATA_BETWEEN_CCS_AND_FINISHED ,"data between ccs and finished"},
255{SSL_R_DATA_LENGTH_TOO_LONG ,"data length too long"},
256{SSL_R_DECRYPTION_FAILED ,"decryption failed"},
257{SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG ,"dh public value length is wrong"},
258{SSL_R_DIGEST_CHECK_FAILED ,"digest check failed"},
259{SSL_R_ENCRYPTED_LENGTH_TOO_LONG ,"encrypted length too long"},
260{SSL_R_ERROR_GENERATING_TMP_RSA_KEY ,"error generating tmp rsa key"},
261{SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST ,"error in received cipher list"},
262{SSL_R_EXCESSIVE_MESSAGE_SIZE ,"excessive message size"},
263{SSL_R_EXTRA_DATA_IN_MESSAGE ,"extra data in message"},
264{SSL_R_GOT_A_FIN_BEFORE_A_CCS ,"got a fin before a ccs"},
265{SSL_R_HTTPS_PROXY_REQUEST ,"https proxy request"},
266{SSL_R_HTTP_REQUEST ,"http request"},
267{SSL_R_INTERNAL_ERROR ,"internal error"},
268{SSL_R_INVALID_CHALLENGE_LENGTH ,"invalid challenge length"},
269{SSL_R_INVALID_COMMAND ,"invalid command"},
270{SSL_R_INVALID_PURPOSE ,"invalid purpose"},
271{SSL_R_INVALID_TRUST ,"invalid trust"},
272{SSL_R_LENGTH_MISMATCH ,"length mismatch"},
273{SSL_R_LENGTH_TOO_SHORT ,"length too short"},
274{SSL_R_LIBRARY_BUG ,"library bug"},
275{SSL_R_LIBRARY_HAS_NO_CIPHERS ,"library has no ciphers"},
276{SSL_R_MISSING_DH_DSA_CERT ,"missing dh dsa cert"},
277{SSL_R_MISSING_DH_KEY ,"missing dh key"},
278{SSL_R_MISSING_DH_RSA_CERT ,"missing dh rsa cert"},
279{SSL_R_MISSING_DSA_SIGNING_CERT ,"missing dsa signing cert"},
280{SSL_R_MISSING_EXPORT_TMP_DH_KEY ,"missing export tmp dh key"},
281{SSL_R_MISSING_EXPORT_TMP_RSA_KEY ,"missing export tmp rsa key"},
282{SSL_R_MISSING_RSA_CERTIFICATE ,"missing rsa certificate"},
283{SSL_R_MISSING_RSA_ENCRYPTING_CERT ,"missing rsa encrypting cert"},
284{SSL_R_MISSING_RSA_SIGNING_CERT ,"missing rsa signing cert"},
285{SSL_R_MISSING_TMP_DH_KEY ,"missing tmp dh key"},
286{SSL_R_MISSING_TMP_RSA_KEY ,"missing tmp rsa key"},
287{SSL_R_MISSING_TMP_RSA_PKEY ,"missing tmp rsa pkey"},
288{SSL_R_MISSING_VERIFY_MESSAGE ,"missing verify message"},
289{SSL_R_NON_SSLV2_INITIAL_PACKET ,"non sslv2 initial packet"},
290{SSL_R_NO_CERTIFICATES_RETURNED ,"no certificates returned"},
291{SSL_R_NO_CERTIFICATE_ASSIGNED ,"no certificate assigned"},
292{SSL_R_NO_CERTIFICATE_RETURNED ,"no certificate returned"},
293{SSL_R_NO_CERTIFICATE_SET ,"no certificate set"},
294{SSL_R_NO_CERTIFICATE_SPECIFIED ,"no certificate specified"},
295{SSL_R_NO_CIPHERS_AVAILABLE ,"no ciphers available"},
296{SSL_R_NO_CIPHERS_PASSED ,"no ciphers passed"},
297{SSL_R_NO_CIPHERS_SPECIFIED ,"no ciphers specified"},
298{SSL_R_NO_CIPHER_LIST ,"no cipher list"},
299{SSL_R_NO_CIPHER_MATCH ,"no cipher match"},
300{SSL_R_NO_CLIENT_CERT_RECEIVED ,"no client cert received"},
301{SSL_R_NO_COMPRESSION_SPECIFIED ,"no compression specified"},
302{SSL_R_NO_METHOD_SPECIFIED ,"no method specified"},
303{SSL_R_NO_PRIVATEKEY ,"no privatekey"},
304{SSL_R_NO_PRIVATE_KEY_ASSIGNED ,"no private key assigned"},
305{SSL_R_NO_PROTOCOLS_AVAILABLE ,"no protocols available"},
306{SSL_R_NO_PUBLICKEY ,"no publickey"},
307{SSL_R_NO_SHARED_CIPHER ,"no shared cipher"},
308{SSL_R_NO_VERIFY_CALLBACK ,"no verify callback"},
309{SSL_R_NULL_SSL_CTX ,"null ssl ctx"},
310{SSL_R_NULL_SSL_METHOD_PASSED ,"null ssl method passed"},
311{SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED ,"old session cipher not returned"},
312{SSL_R_PACKET_LENGTH_TOO_LONG ,"packet length too long"},
313{SSL_R_PATH_TOO_LONG ,"path too long"},
314{SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE ,"peer did not return a certificate"},
315{SSL_R_PEER_ERROR ,"peer error"},
316{SSL_R_PEER_ERROR_CERTIFICATE ,"peer error certificate"},
317{SSL_R_PEER_ERROR_NO_CERTIFICATE ,"peer error no certificate"},
318{SSL_R_PEER_ERROR_NO_CIPHER ,"peer error no cipher"},
319{SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"peer error unsupported certificate type"},
320{SSL_R_PRE_MAC_LENGTH_TOO_LONG ,"pre mac length too long"},
321{SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS ,"problems mapping cipher functions"},
322{SSL_R_PROTOCOL_IS_SHUTDOWN ,"protocol is shutdown"},
323{SSL_R_PUBLIC_KEY_ENCRYPT_ERROR ,"public key encrypt error"},
324{SSL_R_PUBLIC_KEY_IS_NOT_RSA ,"public key is not rsa"},
325{SSL_R_PUBLIC_KEY_NOT_RSA ,"public key not rsa"},
326{SSL_R_READ_BIO_NOT_SET ,"read bio not set"},
327{SSL_R_READ_WRONG_PACKET_TYPE ,"read wrong packet type"},
328{SSL_R_RECORD_LENGTH_MISMATCH ,"record length mismatch"},
329{SSL_R_RECORD_TOO_LARGE ,"record too large"},
330{SSL_R_REQUIRED_CIPHER_MISSING ,"required cipher missing"},
331{SSL_R_REUSE_CERT_LENGTH_NOT_ZERO ,"reuse cert length not zero"},
332{SSL_R_REUSE_CERT_TYPE_NOT_ZERO ,"reuse cert type not zero"},
333{SSL_R_REUSE_CIPHER_LIST_NOT_ZERO ,"reuse cipher list not zero"},
334{SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED ,"session id context uninitialized"},
335{SSL_R_SHORT_READ ,"short read"},
336{SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE,"signature for non signing certificate"},
337{SSL_R_SSL23_DOING_SESSION_ID_REUSE ,"ssl23 doing session id reuse"},
338{SSL_R_SSL3_SESSION_ID_TOO_SHORT ,"ssl3 session id too short"},
339{SSL_R_SSLV3_ALERT_BAD_CERTIFICATE ,"sslv3 alert bad certificate"},
340{SSL_R_SSLV3_ALERT_BAD_RECORD_MAC ,"sslv3 alert bad record mac"},
341{SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED ,"sslv3 alert certificate expired"},
342{SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED ,"sslv3 alert certificate revoked"},
343{SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN ,"sslv3 alert certificate unknown"},
344{SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE ,"sslv3 alert decompression failure"},
345{SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE ,"sslv3 alert handshake failure"},
346{SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER ,"sslv3 alert illegal parameter"},
347{SSL_R_SSLV3_ALERT_NO_CERTIFICATE ,"sslv3 alert no certificate"},
348{SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE,"sslv3 alert peer error certificate"},
349{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE,"sslv3 alert peer error no certificate"},
350{SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER ,"sslv3 alert peer error no cipher"},
351{SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE,"sslv3 alert peer error unsupported certificate type"},
352{SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE ,"sslv3 alert unexpected message"},
353{SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE,"sslv3 alert unknown remote error type"},
354{SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE,"sslv3 alert unsupported certificate"},
355{SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION,"ssl ctx has no default ssl version"},
356{SSL_R_SSL_HANDSHAKE_FAILURE ,"ssl handshake failure"},
357{SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS ,"ssl library has no ciphers"},
358{SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG ,"ssl session id context too long"},
359{SSL_R_SSL_SESSION_ID_IS_DIFFERENT ,"ssl session id is different"},
360{SSL_R_TLSV1_ALERT_ACCESS_DENIED ,"tlsv1 alert access denied"},
361{SSL_R_TLSV1_ALERT_DECODE_ERROR ,"tlsv1 alert decode error"},
362{SSL_R_TLSV1_ALERT_DECRYPTION_FAILED ,"tlsv1 alert decryption failed"},
363{SSL_R_TLSV1_ALERT_DECRYPT_ERROR ,"tlsv1 alert decrypt error"},
364{SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION ,"tlsv1 alert export restriction"},
365{SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY ,"tlsv1 alert insufficient security"},
366{SSL_R_TLSV1_ALERT_INTERNAL_ERROR ,"tlsv1 alert internal error"},
367{SSL_R_TLSV1_ALERT_NO_RENEGOTIATION ,"tlsv1 alert no renegotiation"},
368{SSL_R_TLSV1_ALERT_PROTOCOL_VERSION ,"tlsv1 alert protocol version"},
369{SSL_R_TLSV1_ALERT_RECORD_OVERFLOW ,"tlsv1 alert record overflow"},
370{SSL_R_TLSV1_ALERT_UNKNOWN_CA ,"tlsv1 alert unknown ca"},
371{SSL_R_TLSV1_ALERT_USER_CANCELLED ,"tlsv1 alert user cancelled"},
372{SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER,"tls client cert req with anon cipher"},
373{SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST,"tls peer did not respond with certificate list"},
374{SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG,"tls rsa encrypted value length is wrong"},
375{SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER ,"tried to use unsupported cipher"},
376{SSL_R_UNABLE_TO_DECODE_DH_CERTS ,"unable to decode dh certs"},
377{SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY ,"unable to extract public key"},
378{SSL_R_UNABLE_TO_FIND_DH_PARAMETERS ,"unable to find dh parameters"},
379{SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS,"unable to find public key parameters"},
380{SSL_R_UNABLE_TO_FIND_SSL_METHOD ,"unable to find ssl method"},
381{SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES ,"unable to load ssl2 md5 routines"},
382{SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES ,"unable to load ssl3 md5 routines"},
383{SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES ,"unable to load ssl3 sha1 routines"},
384{SSL_R_UNEXPECTED_MESSAGE ,"unexpected message"},
385{SSL_R_UNEXPECTED_RECORD ,"unexpected record"},
386{SSL_R_UNINITIALIZED ,"uninitialized"},
387{SSL_R_UNKNOWN_ALERT_TYPE ,"unknown alert type"},
388{SSL_R_UNKNOWN_CERTIFICATE_TYPE ,"unknown certificate type"},
389{SSL_R_UNKNOWN_CIPHER_RETURNED ,"unknown cipher returned"},
390{SSL_R_UNKNOWN_CIPHER_TYPE ,"unknown cipher type"},
391{SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE ,"unknown key exchange type"},
392{SSL_R_UNKNOWN_PKEY_TYPE ,"unknown pkey type"},
393{SSL_R_UNKNOWN_PROTOCOL ,"unknown protocol"},
394{SSL_R_UNKNOWN_REMOTE_ERROR_TYPE ,"unknown remote error type"},
395{SSL_R_UNKNOWN_SSL_VERSION ,"unknown ssl version"},
396{SSL_R_UNKNOWN_STATE ,"unknown state"},
397{SSL_R_UNSUPPORTED_CIPHER ,"unsupported cipher"},
398{SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM ,"unsupported compression algorithm"},
399{SSL_R_UNSUPPORTED_OPTION ,"unsupported option"},
400{SSL_R_UNSUPPORTED_PROTOCOL ,"unsupported protocol"},
401{SSL_R_UNSUPPORTED_SSL_VERSION ,"unsupported ssl version"},
402{SSL_R_WRITE_BIO_NOT_SET ,"write bio not set"},
403{SSL_R_WRONG_CIPHER_RETURNED ,"wrong cipher returned"},
404{SSL_R_WRONG_MESSAGE_TYPE ,"wrong message type"},
405{SSL_R_WRONG_NUMBER_OF_KEY_BITS ,"wrong number of key bits"},
406{SSL_R_WRONG_SIGNATURE_LENGTH ,"wrong signature length"},
407{SSL_R_WRONG_SIGNATURE_SIZE ,"wrong signature size"},
408{SSL_R_WRONG_SSL_VERSION ,"wrong ssl version"},
409{SSL_R_WRONG_VERSION_NUMBER ,"wrong version number"},
410{SSL_R_X509_LIB ,"x509 lib"},
411{SSL_R_X509_VERIFICATION_SETUP_PROBLEMS ,"x509 verification setup problems"},
412{0,NULL}
413 };
414
415#endif
416
417void ERR_load_SSL_strings(void)
418 {
419 static int init=1;
420
421 if (init)
422 {
423 init=0;
424#ifndef NO_ERR
425 ERR_load_strings(ERR_LIB_SSL,SSL_str_functs);
426 ERR_load_strings(ERR_LIB_SSL,SSL_str_reasons);
427#endif
428
429 }
430 }
diff --git a/src/lib/libssl/ssl_err2.c b/src/lib/libssl/ssl_err2.c
deleted file mode 100644
index cc089a612b..0000000000
--- a/src/lib/libssl/ssl_err2.c
+++ /dev/null
@@ -1,70 +0,0 @@
1/* ssl/ssl_err2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#include <stdio.h>
60#include <openssl/err.h>
61#include <openssl/ssl.h>
62
63void SSL_load_error_strings(void)
64 {
65#ifndef NO_ERR
66 ERR_load_crypto_strings();
67 ERR_load_SSL_strings();
68#endif
69 }
70
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
deleted file mode 100644
index c515c41b4e..0000000000
--- a/src/lib/libssl/ssl_lib.c
+++ /dev/null
@@ -1,2061 +0,0 @@
1/*! \file ssl/ssl_lib.c
2 * \brief Version independent SSL functions.
3 */
4/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * All rights reserved.
6 *
7 * This package is an SSL implementation written
8 * by Eric Young (eay@cryptsoft.com).
9 * The implementation was written so as to conform with Netscapes SSL.
10 *
11 * This library is free for commercial and non-commercial use as long as
12 * the following conditions are aheared to. The following conditions
13 * apply to all code found in this distribution, be it the RC4, RSA,
14 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
15 * included with this distribution is covered by the same copyright terms
16 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
17 *
18 * Copyright remains Eric Young's, and as such any Copyright notices in
19 * the code are not to be removed.
20 * If this package is used in a product, Eric Young should be given attribution
21 * as the author of the parts of the library used.
22 * This can be in the form of a textual message at program startup or
23 * in documentation (online or textual) provided with the package.
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 * 1. Redistributions of source code must retain the copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 * 3. All advertising materials mentioning features or use of this software
34 * must display the following acknowledgement:
35 * "This product includes cryptographic software written by
36 * Eric Young (eay@cryptsoft.com)"
37 * The word 'cryptographic' can be left out if the rouines from the library
38 * being used are not cryptographic related :-).
39 * 4. If you include any Windows specific code (or a derivative thereof) from
40 * the apps directory (application code) you must include an acknowledgement:
41 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
42 *
43 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * The licence and distribution terms for any publically available version or
56 * derivative of this code cannot be changed. i.e. this code cannot simply be
57 * copied and put under another distribution licence
58 * [including the GNU Public Licence.]
59 */
60
61#include <stdio.h>
62#include <openssl/objects.h>
63#include <openssl/lhash.h>
64#include <openssl/x509v3.h>
65#include "ssl_locl.h"
66
67const char *SSL_version_str=OPENSSL_VERSION_TEXT;
68
69static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_meth=NULL;
70static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_ctx_meth=NULL;
71static int ssl_meth_num=0;
72static int ssl_ctx_meth_num=0;
73
74OPENSSL_GLOBAL SSL3_ENC_METHOD ssl3_undef_enc_method={
75 /* evil casts, but these functions are only called if there's a library bug */
76 (int (*)(SSL *,int))ssl_undefined_function,
77 (int (*)(SSL *, unsigned char *, int))ssl_undefined_function,
78 ssl_undefined_function,
79 (int (*)(SSL *, unsigned char *, unsigned char *, int))ssl_undefined_function,
80 (int (*)(SSL*, int))ssl_undefined_function,
81 (int (*)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char*, int, unsigned char *))ssl_undefined_function
82 };
83
84int SSL_clear(SSL *s)
85 {
86 int state;
87
88 if (s->method == NULL)
89 {
90 SSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);
91 return(0);
92 }
93
94 s->error=0;
95 s->hit=0;
96 s->shutdown=0;
97
98#if 0 /* Disabled since version 1.10 of this file (early return not
99 * needed because SSL_clear is not called when doing renegotiation) */
100 /* This is set if we are doing dynamic renegotiation so keep
101 * the old cipher. It is sort of a SSL_clear_lite :-) */
102 if (s->new_session) return(1);
103#else
104 if (s->new_session)
105 {
106 SSLerr(SSL_F_SSL_CLEAR,SSL_R_INTERNAL_ERROR);
107 return 0;
108 }
109#endif
110
111 state=s->state; /* Keep to check if we throw away the session-id */
112 s->type=0;
113
114 s->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);
115
116 s->version=s->method->version;
117 s->client_version=s->version;
118 s->rwstate=SSL_NOTHING;
119 s->rstate=SSL_ST_READ_HEADER;
120 s->read_ahead=s->ctx->read_ahead;
121
122 if (s->init_buf != NULL)
123 {
124 BUF_MEM_free(s->init_buf);
125 s->init_buf=NULL;
126 }
127
128 ssl_clear_cipher_ctx(s);
129
130 if (ssl_clear_bad_session(s))
131 {
132 SSL_SESSION_free(s->session);
133 s->session=NULL;
134 }
135
136 s->first_packet=0;
137
138#if 1
139 /* Check to see if we were changed into a different method, if
140 * so, revert back if we are not doing session-id reuse. */
141 if ((s->session == NULL) && (s->method != s->ctx->method))
142 {
143 s->method->ssl_free(s);
144 s->method=s->ctx->method;
145 if (!s->method->ssl_new(s))
146 return(0);
147 }
148 else
149#endif
150 s->method->ssl_clear(s);
151 return(1);
152 }
153
154/** Used to change an SSL_CTXs default SSL method type */
155int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth)
156 {
157 STACK_OF(SSL_CIPHER) *sk;
158
159 ctx->method=meth;
160
161 sk=ssl_create_cipher_list(ctx->method,&(ctx->cipher_list),
162 &(ctx->cipher_list_by_id),SSL_DEFAULT_CIPHER_LIST);
163 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0))
164 {
165 SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION,SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
166 return(0);
167 }
168 return(1);
169 }
170
171SSL *SSL_new(SSL_CTX *ctx)
172 {
173 SSL *s;
174
175 if (ctx == NULL)
176 {
177 SSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);
178 return(NULL);
179 }
180 if (ctx->method == NULL)
181 {
182 SSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
183 return(NULL);
184 }
185
186 s=(SSL *)Malloc(sizeof(SSL));
187 if (s == NULL) goto err;
188 memset(s,0,sizeof(SSL));
189
190 if (ctx->cert != NULL)
191 {
192 /* Earlier library versions used to copy the pointer to
193 * the CERT, not its contents; only when setting new
194 * parameters for the per-SSL copy, ssl_cert_new would be
195 * called (and the direct reference to the per-SSL_CTX
196 * settings would be lost, but those still were indirectly
197 * accessed for various purposes, and for that reason they
198 * used to be known as s->ctx->default_cert).
199 * Now we don't look at the SSL_CTX's CERT after having
200 * duplicated it once. */
201
202 s->cert = ssl_cert_dup(ctx->cert);
203 if (s->cert == NULL)
204 goto err;
205 }
206 else
207 s->cert=NULL; /* Cannot really happen (see SSL_CTX_new) */
208 s->sid_ctx_length=ctx->sid_ctx_length;
209 memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));
210 s->verify_mode=ctx->verify_mode;
211 s->verify_depth=ctx->verify_depth;
212 s->verify_callback=ctx->default_verify_callback;
213 s->purpose = ctx->purpose;
214 s->trust = ctx->trust;
215 CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
216 s->ctx=ctx;
217
218 s->verify_result=X509_V_OK;
219
220 s->method=ctx->method;
221
222 if (!s->method->ssl_new(s))
223 goto err;
224
225 s->quiet_shutdown=ctx->quiet_shutdown;
226 s->references=1;
227 s->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;
228 s->options=ctx->options;
229 s->mode=ctx->mode;
230 SSL_clear(s);
231
232 CRYPTO_new_ex_data(ssl_meth,s,&s->ex_data);
233
234 return(s);
235err:
236 if (s != NULL)
237 {
238 if (s->cert != NULL)
239 ssl_cert_free(s->cert);
240 if (s->ctx != NULL)
241 SSL_CTX_free(s->ctx); /* decrement reference count */
242 Free(s);
243 }
244 SSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);
245 return(NULL);
246 }
247
248int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx,
249 unsigned int sid_ctx_len)
250 {
251 if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)
252 {
253 SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
254 return 0;
255 }
256 ctx->sid_ctx_length=sid_ctx_len;
257 memcpy(ctx->sid_ctx,sid_ctx,sid_ctx_len);
258
259 return 1;
260 }
261
262int SSL_set_session_id_context(SSL *ssl,const unsigned char *sid_ctx,
263 unsigned int sid_ctx_len)
264 {
265 if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH)
266 {
267 SSLerr(SSL_F_SSL_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
268 return 0;
269 }
270 ssl->sid_ctx_length=sid_ctx_len;
271 memcpy(ssl->sid_ctx,sid_ctx,sid_ctx_len);
272
273 return 1;
274 }
275
276int SSL_CTX_set_purpose(SSL_CTX *s, int purpose)
277{
278 if(X509_PURPOSE_get_by_id(purpose) == -1) {
279 SSLerr(SSL_F_SSL_CTX_SET_PURPOSE, SSL_R_INVALID_PURPOSE);
280 return 0;
281 }
282 s->purpose = purpose;
283 return 1;
284}
285
286int SSL_set_purpose(SSL *s, int purpose)
287{
288 if(X509_PURPOSE_get_by_id(purpose) == -1) {
289 SSLerr(SSL_F_SSL_SET_PURPOSE, SSL_R_INVALID_PURPOSE);
290 return 0;
291 }
292 s->purpose = purpose;
293 return 1;
294}
295
296int SSL_CTX_set_trust(SSL_CTX *s, int trust)
297{
298 if(X509_TRUST_get_by_id(trust) == -1) {
299 SSLerr(SSL_F_SSL_CTX_SET_TRUST, SSL_R_INVALID_TRUST);
300 return 0;
301 }
302 s->trust = trust;
303 return 1;
304}
305
306int SSL_set_trust(SSL *s, int trust)
307{
308 if(X509_TRUST_get_by_id(trust) == -1) {
309 SSLerr(SSL_F_SSL_SET_TRUST, SSL_R_INVALID_TRUST);
310 return 0;
311 }
312 s->trust = trust;
313 return 1;
314}
315
316void SSL_free(SSL *s)
317 {
318 int i;
319
320 if(s == NULL)
321 return;
322
323 i=CRYPTO_add(&s->references,-1,CRYPTO_LOCK_SSL);
324#ifdef REF_PRINT
325 REF_PRINT("SSL",s);
326#endif
327 if (i > 0) return;
328#ifdef REF_CHECK
329 if (i < 0)
330 {
331 fprintf(stderr,"SSL_free, bad reference count\n");
332 abort(); /* ok */
333 }
334#endif
335
336 CRYPTO_free_ex_data(ssl_meth,(char *)s,&s->ex_data);
337
338 if (s->bbio != NULL)
339 {
340 /* If the buffering BIO is in place, pop it off */
341 if (s->bbio == s->wbio)
342 {
343 s->wbio=BIO_pop(s->wbio);
344 }
345 BIO_free(s->bbio);
346 s->bbio=NULL;
347 }
348 if (s->rbio != NULL)
349 BIO_free_all(s->rbio);
350 if ((s->wbio != NULL) && (s->wbio != s->rbio))
351 BIO_free_all(s->wbio);
352
353 if (s->init_buf != NULL) BUF_MEM_free(s->init_buf);
354
355 /* add extra stuff */
356 if (s->cipher_list != NULL) sk_SSL_CIPHER_free(s->cipher_list);
357 if (s->cipher_list_by_id != NULL) sk_SSL_CIPHER_free(s->cipher_list_by_id);
358
359 /* Make the next call work :-) */
360 if (s->session != NULL)
361 {
362 ssl_clear_bad_session(s);
363 SSL_SESSION_free(s->session);
364 }
365
366 ssl_clear_cipher_ctx(s);
367
368 if (s->cert != NULL) ssl_cert_free(s->cert);
369 /* Free up if allocated */
370
371 if (s->ctx) SSL_CTX_free(s->ctx);
372
373 if (s->client_CA != NULL)
374 sk_X509_NAME_pop_free(s->client_CA,X509_NAME_free);
375
376 if (s->method != NULL) s->method->ssl_free(s);
377
378 Free(s);
379 }
380
381void SSL_set_bio(SSL *s,BIO *rbio,BIO *wbio)
382 {
383 /* If the output buffering BIO is still in place, remove it
384 */
385 if (s->bbio != NULL)
386 {
387 if (s->wbio == s->bbio)
388 {
389 s->wbio=s->wbio->next_bio;
390 s->bbio->next_bio=NULL;
391 }
392 }
393 if ((s->rbio != NULL) && (s->rbio != rbio))
394 BIO_free_all(s->rbio);
395 if ((s->wbio != NULL) && (s->wbio != wbio) && (s->rbio != s->wbio))
396 BIO_free_all(s->wbio);
397 s->rbio=rbio;
398 s->wbio=wbio;
399 }
400
401BIO *SSL_get_rbio(SSL *s)
402 { return(s->rbio); }
403
404BIO *SSL_get_wbio(SSL *s)
405 { return(s->wbio); }
406
407int SSL_get_fd(SSL *s)
408 {
409 int ret= -1;
410 BIO *b,*r;
411
412 b=SSL_get_rbio(s);
413 r=BIO_find_type(b,BIO_TYPE_DESCRIPTOR);
414 if (r != NULL)
415 BIO_get_fd(r,&ret);
416 return(ret);
417 }
418
419#ifndef NO_SOCK
420int SSL_set_fd(SSL *s,int fd)
421 {
422 int ret=0;
423 BIO *bio=NULL;
424
425 bio=BIO_new(BIO_s_socket());
426
427 if (bio == NULL)
428 {
429 SSLerr(SSL_F_SSL_SET_FD,ERR_R_BUF_LIB);
430 goto err;
431 }
432 BIO_set_fd(bio,fd,BIO_NOCLOSE);
433 SSL_set_bio(s,bio,bio);
434 ret=1;
435err:
436 return(ret);
437 }
438
439int SSL_set_wfd(SSL *s,int fd)
440 {
441 int ret=0;
442 BIO *bio=NULL;
443
444 if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET)
445 || ((int)BIO_get_fd(s->rbio,NULL) != fd))
446 {
447 bio=BIO_new(BIO_s_socket());
448
449 if (bio == NULL)
450 { SSLerr(SSL_F_SSL_SET_WFD,ERR_R_BUF_LIB); goto err; }
451 BIO_set_fd(bio,fd,BIO_NOCLOSE);
452 SSL_set_bio(s,SSL_get_rbio(s),bio);
453 }
454 else
455 SSL_set_bio(s,SSL_get_rbio(s),SSL_get_rbio(s));
456 ret=1;
457err:
458 return(ret);
459 }
460
461int SSL_set_rfd(SSL *s,int fd)
462 {
463 int ret=0;
464 BIO *bio=NULL;
465
466 if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET)
467 || ((int)BIO_get_fd(s->wbio,NULL) != fd))
468 {
469 bio=BIO_new(BIO_s_socket());
470
471 if (bio == NULL)
472 {
473 SSLerr(SSL_F_SSL_SET_RFD,ERR_R_BUF_LIB);
474 goto err;
475 }
476 BIO_set_fd(bio,fd,BIO_NOCLOSE);
477 SSL_set_bio(s,bio,SSL_get_wbio(s));
478 }
479 else
480 SSL_set_bio(s,SSL_get_wbio(s),SSL_get_wbio(s));
481 ret=1;
482err:
483 return(ret);
484 }
485#endif
486
487
488/* return length of latest Finished message we sent, copy to 'buf' */
489size_t SSL_get_finished(SSL *s, void *buf, size_t count)
490 {
491 size_t ret = 0;
492
493 if (s->s3 != NULL)
494 {
495 ret = s->s3->tmp.finish_md_len;
496 if (count > ret)
497 count = ret;
498 memcpy(buf, s->s3->tmp.finish_md, count);
499 }
500 return ret;
501 }
502
503/* return length of latest Finished message we expected, copy to 'buf' */
504size_t SSL_get_peer_finished(SSL *s, void *buf, size_t count)
505 {
506 size_t ret = 0;
507
508 if (s->s3 != NULL)
509 {
510 ret = s->s3->tmp.peer_finish_md_len;
511 if (count > ret)
512 count = ret;
513 memcpy(buf, s->s3->tmp.peer_finish_md, count);
514 }
515 return ret;
516 }
517
518
519int SSL_get_verify_mode(SSL *s)
520 {
521 return(s->verify_mode);
522 }
523
524int SSL_get_verify_depth(SSL *s)
525 {
526 return(s->verify_depth);
527 }
528
529int (*SSL_get_verify_callback(SSL *s))(int,X509_STORE_CTX *)
530 {
531 return(s->verify_callback);
532 }
533
534int SSL_CTX_get_verify_mode(SSL_CTX *ctx)
535 {
536 return(ctx->verify_mode);
537 }
538
539int SSL_CTX_get_verify_depth(SSL_CTX *ctx)
540 {
541 return(ctx->verify_depth);
542 }
543
544int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))(int,X509_STORE_CTX *)
545 {
546 return(ctx->default_verify_callback);
547 }
548
549void SSL_set_verify(SSL *s,int mode,
550 int (*callback)(int ok,X509_STORE_CTX *ctx))
551 {
552 s->verify_mode=mode;
553 if (callback != NULL)
554 s->verify_callback=callback;
555 }
556
557void SSL_set_verify_depth(SSL *s,int depth)
558 {
559 s->verify_depth=depth;
560 }
561
562void SSL_set_read_ahead(SSL *s,int yes)
563 {
564 s->read_ahead=yes;
565 }
566
567int SSL_get_read_ahead(SSL *s)
568 {
569 return(s->read_ahead);
570 }
571
572int SSL_pending(SSL *s)
573 {
574 return(s->method->ssl_pending(s));
575 }
576
577X509 *SSL_get_peer_certificate(SSL *s)
578 {
579 X509 *r;
580
581 if ((s == NULL) || (s->session == NULL))
582 r=NULL;
583 else
584 r=s->session->peer;
585
586 if (r == NULL) return(r);
587
588 CRYPTO_add(&r->references,1,CRYPTO_LOCK_X509);
589
590 return(r);
591 }
592
593STACK_OF(X509) *SSL_get_peer_cert_chain(SSL *s)
594 {
595 STACK_OF(X509) *r;
596
597 if ((s == NULL) || (s->session == NULL) || (s->session->sess_cert == NULL))
598 r=NULL;
599 else
600 r=s->session->sess_cert->cert_chain;
601
602 /* If we are a client, cert_chain includes the peer's own
603 * certificate; if we are a server, it does not. */
604
605 return(r);
606 }
607
608/* Now in theory, since the calling process own 't' it should be safe to
609 * modify. We need to be able to read f without being hassled */
610void SSL_copy_session_id(SSL *t,SSL *f)
611 {
612 CERT *tmp;
613
614 /* Do we need to to SSL locking? */
615 SSL_set_session(t,SSL_get_session(f));
616
617 /* what if we are setup as SSLv2 but want to talk SSLv3 or
618 * vice-versa */
619 if (t->method != f->method)
620 {
621 t->method->ssl_free(t); /* cleanup current */
622 t->method=f->method; /* change method */
623 t->method->ssl_new(t); /* setup new */
624 }
625
626 tmp=t->cert;
627 if (f->cert != NULL)
628 {
629 CRYPTO_add(&f->cert->references,1,CRYPTO_LOCK_SSL_CERT);
630 t->cert=f->cert;
631 }
632 else
633 t->cert=NULL;
634 if (tmp != NULL) ssl_cert_free(tmp);
635 SSL_set_session_id_context(t,f->sid_ctx,f->sid_ctx_length);
636 }
637
638/* Fix this so it checks all the valid key/cert options */
639int SSL_CTX_check_private_key(SSL_CTX *ctx)
640 {
641 if ( (ctx == NULL) ||
642 (ctx->cert == NULL) ||
643 (ctx->cert->key->x509 == NULL))
644 {
645 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
646 return(0);
647 }
648 if (ctx->cert->key->privatekey == NULL)
649 {
650 SSLerr(SSL_F_SSL_CTX_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
651 return(0);
652 }
653 return(X509_check_private_key(ctx->cert->key->x509, ctx->cert->key->privatekey));
654 }
655
656/* Fix this function so that it takes an optional type parameter */
657int SSL_check_private_key(SSL *ssl)
658 {
659 if (ssl == NULL)
660 {
661 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,ERR_R_PASSED_NULL_PARAMETER);
662 return(0);
663 }
664 if (ssl->cert == NULL)
665 {
666 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
667 return 0;
668 }
669 if (ssl->cert->key->x509 == NULL)
670 {
671 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_CERTIFICATE_ASSIGNED);
672 return(0);
673 }
674 if (ssl->cert->key->privatekey == NULL)
675 {
676 SSLerr(SSL_F_SSL_CHECK_PRIVATE_KEY,SSL_R_NO_PRIVATE_KEY_ASSIGNED);
677 return(0);
678 }
679 return(X509_check_private_key(ssl->cert->key->x509,
680 ssl->cert->key->privatekey));
681 }
682
683int SSL_accept(SSL *s)
684 {
685 if (s->handshake_func == 0)
686 /* Not properly initialized yet */
687 SSL_set_accept_state(s);
688
689 return(s->method->ssl_accept(s));
690 }
691
692int SSL_connect(SSL *s)
693 {
694 if (s->handshake_func == 0)
695 /* Not properly initialized yet */
696 SSL_set_connect_state(s);
697
698 return(s->method->ssl_connect(s));
699 }
700
701long SSL_get_default_timeout(SSL *s)
702 {
703 return(s->method->get_timeout());
704 }
705
706int SSL_read(SSL *s,char *buf,int num)
707 {
708 if (s->handshake_func == 0)
709 {
710 SSLerr(SSL_F_SSL_READ, SSL_R_UNINITIALIZED);
711 return -1;
712 }
713
714 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
715 {
716 s->rwstate=SSL_NOTHING;
717 return(0);
718 }
719 return(s->method->ssl_read(s,buf,num));
720 }
721
722int SSL_peek(SSL *s,char *buf,int num)
723 {
724 if (s->shutdown & SSL_RECEIVED_SHUTDOWN)
725 {
726 return(0);
727 }
728 return(s->method->ssl_peek(s,buf,num));
729 }
730
731int SSL_write(SSL *s,const char *buf,int num)
732 {
733 if (s->handshake_func == 0)
734 {
735 SSLerr(SSL_F_SSL_WRITE, SSL_R_UNINITIALIZED);
736 return -1;
737 }
738
739 if (s->shutdown & SSL_SENT_SHUTDOWN)
740 {
741 s->rwstate=SSL_NOTHING;
742 SSLerr(SSL_F_SSL_WRITE,SSL_R_PROTOCOL_IS_SHUTDOWN);
743 return(-1);
744 }
745 return(s->method->ssl_write(s,buf,num));
746 }
747
748int SSL_shutdown(SSL *s)
749 {
750 /* Note that this function behaves differently from what one might
751 * expect. Return values are 0 for no success (yet),
752 * 1 for success; but calling it once is usually not enough,
753 * even if blocking I/O is used (see ssl3_shutdown).
754 */
755
756 if (s->handshake_func == 0)
757 {
758 SSLerr(SSL_F_SSL_SHUTDOWN, SSL_R_UNINITIALIZED);
759 return -1;
760 }
761
762 if ((s != NULL) && !SSL_in_init(s))
763 return(s->method->ssl_shutdown(s));
764 else
765 return(1);
766 }
767
768int SSL_renegotiate(SSL *s)
769 {
770 s->new_session=1;
771 return(s->method->ssl_renegotiate(s));
772 }
773
774long SSL_ctrl(SSL *s,int cmd,long larg,char *parg)
775 {
776 long l;
777
778 switch (cmd)
779 {
780 case SSL_CTRL_GET_READ_AHEAD:
781 return(s->read_ahead);
782 case SSL_CTRL_SET_READ_AHEAD:
783 l=s->read_ahead;
784 s->read_ahead=larg;
785 return(l);
786 case SSL_CTRL_OPTIONS:
787 return(s->options|=larg);
788 case SSL_CTRL_MODE:
789 return(s->mode|=larg);
790 default:
791 return(s->method->ssl_ctrl(s,cmd,larg,parg));
792 }
793 }
794
795long SSL_callback_ctrl(SSL *s, int cmd, void (*fp)())
796 {
797 switch(cmd)
798 {
799 default:
800 return(s->method->ssl_callback_ctrl(s,cmd,fp));
801 }
802 }
803
804struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx)
805 {
806 return ctx->sessions;
807 }
808
809long SSL_CTX_ctrl(SSL_CTX *ctx,int cmd,long larg,char *parg)
810 {
811 long l;
812
813 switch (cmd)
814 {
815 case SSL_CTRL_GET_READ_AHEAD:
816 return(ctx->read_ahead);
817 case SSL_CTRL_SET_READ_AHEAD:
818 l=ctx->read_ahead;
819 ctx->read_ahead=larg;
820 return(l);
821
822 case SSL_CTRL_SET_SESS_CACHE_SIZE:
823 l=ctx->session_cache_size;
824 ctx->session_cache_size=larg;
825 return(l);
826 case SSL_CTRL_GET_SESS_CACHE_SIZE:
827 return(ctx->session_cache_size);
828 case SSL_CTRL_SET_SESS_CACHE_MODE:
829 l=ctx->session_cache_mode;
830 ctx->session_cache_mode=larg;
831 return(l);
832 case SSL_CTRL_GET_SESS_CACHE_MODE:
833 return(ctx->session_cache_mode);
834
835 case SSL_CTRL_SESS_NUMBER:
836 return(ctx->sessions->num_items);
837 case SSL_CTRL_SESS_CONNECT:
838 return(ctx->stats.sess_connect);
839 case SSL_CTRL_SESS_CONNECT_GOOD:
840 return(ctx->stats.sess_connect_good);
841 case SSL_CTRL_SESS_CONNECT_RENEGOTIATE:
842 return(ctx->stats.sess_connect_renegotiate);
843 case SSL_CTRL_SESS_ACCEPT:
844 return(ctx->stats.sess_accept);
845 case SSL_CTRL_SESS_ACCEPT_GOOD:
846 return(ctx->stats.sess_accept_good);
847 case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE:
848 return(ctx->stats.sess_accept_renegotiate);
849 case SSL_CTRL_SESS_HIT:
850 return(ctx->stats.sess_hit);
851 case SSL_CTRL_SESS_CB_HIT:
852 return(ctx->stats.sess_cb_hit);
853 case SSL_CTRL_SESS_MISSES:
854 return(ctx->stats.sess_miss);
855 case SSL_CTRL_SESS_TIMEOUTS:
856 return(ctx->stats.sess_timeout);
857 case SSL_CTRL_SESS_CACHE_FULL:
858 return(ctx->stats.sess_cache_full);
859 case SSL_CTRL_OPTIONS:
860 return(ctx->options|=larg);
861 case SSL_CTRL_MODE:
862 return(ctx->mode|=larg);
863 default:
864 return(ctx->method->ssl_ctx_ctrl(ctx,cmd,larg,parg));
865 }
866 }
867
868long SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)())
869 {
870 switch(cmd)
871 {
872 default:
873 return(ctx->method->ssl_ctx_callback_ctrl(ctx,cmd,fp));
874 }
875 }
876
877int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b)
878 {
879 long l;
880
881 l=a->id-b->id;
882 if (l == 0L)
883 return(0);
884 else
885 return((l > 0)?1:-1);
886 }
887
888int ssl_cipher_ptr_id_cmp(SSL_CIPHER **ap,SSL_CIPHER **bp)
889 {
890 long l;
891
892 l=(*ap)->id-(*bp)->id;
893 if (l == 0L)
894 return(0);
895 else
896 return((l > 0)?1:-1);
897 }
898
899/** return a STACK of the ciphers available for the SSL and in order of
900 * preference */
901STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s)
902 {
903 if ((s != NULL) && (s->cipher_list != NULL))
904 {
905 return(s->cipher_list);
906 }
907 else if ((s->ctx != NULL) &&
908 (s->ctx->cipher_list != NULL))
909 {
910 return(s->ctx->cipher_list);
911 }
912 return(NULL);
913 }
914
915/** return a STACK of the ciphers available for the SSL and in order of
916 * algorithm id */
917STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s)
918 {
919 if ((s != NULL) && (s->cipher_list_by_id != NULL))
920 {
921 return(s->cipher_list_by_id);
922 }
923 else if ((s != NULL) && (s->ctx != NULL) &&
924 (s->ctx->cipher_list_by_id != NULL))
925 {
926 return(s->ctx->cipher_list_by_id);
927 }
928 return(NULL);
929 }
930
931/** The old interface to get the same thing as SSL_get_ciphers() */
932const char *SSL_get_cipher_list(SSL *s,int n)
933 {
934 SSL_CIPHER *c;
935 STACK_OF(SSL_CIPHER) *sk;
936
937 if (s == NULL) return(NULL);
938 sk=SSL_get_ciphers(s);
939 if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= n))
940 return(NULL);
941 c=sk_SSL_CIPHER_value(sk,n);
942 if (c == NULL) return(NULL);
943 return(c->name);
944 }
945
946/** specify the ciphers to be used by default by the SSL_CTX */
947int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
948 {
949 STACK_OF(SSL_CIPHER) *sk;
950
951 sk=ssl_create_cipher_list(ctx->method,&ctx->cipher_list,
952 &ctx->cipher_list_by_id,str);
953/* XXXX */
954 return((sk == NULL)?0:1);
955 }
956
957/** specify the ciphers to be used by the SSL */
958int SSL_set_cipher_list(SSL *s,const char *str)
959 {
960 STACK_OF(SSL_CIPHER) *sk;
961
962 sk=ssl_create_cipher_list(s->ctx->method,&s->cipher_list,
963 &s->cipher_list_by_id,str);
964/* XXXX */
965 return((sk == NULL)?0:1);
966 }
967
968/* works well for SSLv2, not so good for SSLv3 */
969char *SSL_get_shared_ciphers(SSL *s,char *buf,int len)
970 {
971 char *p;
972 const char *cp;
973 STACK_OF(SSL_CIPHER) *sk;
974 SSL_CIPHER *c;
975 int i;
976
977 if ((s->session == NULL) || (s->session->ciphers == NULL) ||
978 (len < 2))
979 return(NULL);
980
981 p=buf;
982 sk=s->session->ciphers;
983 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
984 {
985 /* Decrement for either the ':' or a '\0' */
986 len--;
987 c=sk_SSL_CIPHER_value(sk,i);
988 for (cp=c->name; *cp; )
989 {
990 if (len-- == 0)
991 {
992 *p='\0';
993 return(buf);
994 }
995 else
996 *(p++)= *(cp++);
997 }
998 *(p++)=':';
999 }
1000 p[-1]='\0';
1001 return(buf);
1002 }
1003
1004int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p)
1005 {
1006 int i,j=0;
1007 SSL_CIPHER *c;
1008 unsigned char *q;
1009
1010 if (sk == NULL) return(0);
1011 q=p;
1012
1013 for (i=0; i<sk_SSL_CIPHER_num(sk); i++)
1014 {
1015 c=sk_SSL_CIPHER_value(sk,i);
1016 j=ssl_put_cipher_by_char(s,c,p);
1017 p+=j;
1018 }
1019 return(p-q);
1020 }
1021
1022STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
1023 STACK_OF(SSL_CIPHER) **skp)
1024 {
1025 SSL_CIPHER *c;
1026 STACK_OF(SSL_CIPHER) *sk;
1027 int i,n;
1028
1029 n=ssl_put_cipher_by_char(s,NULL,NULL);
1030 if ((num%n) != 0)
1031 {
1032 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1033 return(NULL);
1034 }
1035 if ((skp == NULL) || (*skp == NULL))
1036 sk=sk_SSL_CIPHER_new(NULL); /* change perhaps later */
1037 else
1038 {
1039 sk= *skp;
1040 sk_SSL_CIPHER_zero(sk);
1041 }
1042
1043 for (i=0; i<num; i+=n)
1044 {
1045 c=ssl_get_cipher_by_char(s,p);
1046 p+=n;
1047 if (c != NULL)
1048 {
1049 if (!sk_SSL_CIPHER_push(sk,c))
1050 {
1051 SSLerr(SSL_F_SSL_BYTES_TO_CIPHER_LIST,ERR_R_MALLOC_FAILURE);
1052 goto err;
1053 }
1054 }
1055 }
1056
1057 if (skp != NULL)
1058 *skp=sk;
1059 return(sk);
1060err:
1061 if ((skp == NULL) || (*skp == NULL))
1062 sk_SSL_CIPHER_free(sk);
1063 return(NULL);
1064 }
1065
1066unsigned long SSL_SESSION_hash(SSL_SESSION *a)
1067 {
1068 unsigned long l;
1069
1070 l=(unsigned long)
1071 ((unsigned int) a->session_id[0] )|
1072 ((unsigned int) a->session_id[1]<< 8L)|
1073 ((unsigned long)a->session_id[2]<<16L)|
1074 ((unsigned long)a->session_id[3]<<24L);
1075 return(l);
1076 }
1077
1078int SSL_SESSION_cmp(SSL_SESSION *a,SSL_SESSION *b)
1079 {
1080 if (a->ssl_version != b->ssl_version)
1081 return(1);
1082 if (a->session_id_length != b->session_id_length)
1083 return(1);
1084 return(memcmp(a->session_id,b->session_id,a->session_id_length));
1085 }
1086
1087SSL_CTX *SSL_CTX_new(SSL_METHOD *meth)
1088 {
1089 SSL_CTX *ret=NULL;
1090
1091 if (meth == NULL)
1092 {
1093 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_NULL_SSL_METHOD_PASSED);
1094 return(NULL);
1095 }
1096
1097 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0)
1098 {
1099 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
1100 goto err;
1101 }
1102 ret=(SSL_CTX *)Malloc(sizeof(SSL_CTX));
1103 if (ret == NULL)
1104 goto err;
1105
1106 memset(ret,0,sizeof(SSL_CTX));
1107
1108 ret->method=meth;
1109
1110 ret->cert_store=NULL;
1111 ret->session_cache_mode=SSL_SESS_CACHE_SERVER;
1112 ret->session_cache_size=SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
1113 ret->session_cache_head=NULL;
1114 ret->session_cache_tail=NULL;
1115
1116 /* We take the system default */
1117 ret->session_timeout=meth->get_timeout();
1118
1119 ret->new_session_cb=NULL;
1120 ret->remove_session_cb=NULL;
1121 ret->get_session_cb=NULL;
1122
1123 memset((char *)&ret->stats,0,sizeof(ret->stats));
1124
1125 ret->references=1;
1126 ret->quiet_shutdown=0;
1127
1128/* ret->cipher=NULL;*/
1129/* ret->s2->challenge=NULL;
1130 ret->master_key=NULL;
1131 ret->key_arg=NULL;
1132 ret->s2->conn_id=NULL; */
1133
1134 ret->info_callback=NULL;
1135
1136 ret->app_verify_callback=NULL;
1137 ret->app_verify_arg=NULL;
1138
1139 ret->read_ahead=0;
1140 ret->verify_mode=SSL_VERIFY_NONE;
1141 ret->verify_depth=-1; /* Don't impose a limit (but x509_lu.c does) */
1142 ret->default_verify_callback=NULL;
1143 if ((ret->cert=ssl_cert_new()) == NULL)
1144 goto err;
1145
1146 ret->default_passwd_callback=NULL;
1147 ret->default_passwd_callback_userdata=NULL;
1148 ret->client_cert_cb=NULL;
1149
1150 ret->sessions=lh_new(SSL_SESSION_hash,SSL_SESSION_cmp);
1151 if (ret->sessions == NULL) goto err;
1152 ret->cert_store=X509_STORE_new();
1153 if (ret->cert_store == NULL) goto err;
1154
1155 ssl_create_cipher_list(ret->method,
1156 &ret->cipher_list,&ret->cipher_list_by_id,
1157 SSL_DEFAULT_CIPHER_LIST);
1158 if (ret->cipher_list == NULL
1159 || sk_SSL_CIPHER_num(ret->cipher_list) <= 0)
1160 {
1161 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_LIBRARY_HAS_NO_CIPHERS);
1162 goto err2;
1163 }
1164
1165 if ((ret->rsa_md5=EVP_get_digestbyname("ssl2-md5")) == NULL)
1166 {
1167 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES);
1168 goto err2;
1169 }
1170 if ((ret->md5=EVP_get_digestbyname("ssl3-md5")) == NULL)
1171 {
1172 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);
1173 goto err2;
1174 }
1175 if ((ret->sha1=EVP_get_digestbyname("ssl3-sha1")) == NULL)
1176 {
1177 SSLerr(SSL_F_SSL_CTX_NEW,SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);
1178 goto err2;
1179 }
1180
1181 if ((ret->client_CA=sk_X509_NAME_new_null()) == NULL)
1182 goto err;
1183
1184 CRYPTO_new_ex_data(ssl_ctx_meth,(char *)ret,&ret->ex_data);
1185
1186 ret->extra_certs=NULL;
1187 ret->comp_methods=SSL_COMP_get_compression_methods();
1188
1189 return(ret);
1190err:
1191 SSLerr(SSL_F_SSL_CTX_NEW,ERR_R_MALLOC_FAILURE);
1192err2:
1193 if (ret != NULL) SSL_CTX_free(ret);
1194 return(NULL);
1195 }
1196
1197static void SSL_COMP_free(SSL_COMP *comp)
1198 { Free(comp); }
1199
1200void SSL_CTX_free(SSL_CTX *a)
1201 {
1202 int i;
1203
1204 if (a == NULL) return;
1205
1206 i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_SSL_CTX);
1207#ifdef REF_PRINT
1208 REF_PRINT("SSL_CTX",a);
1209#endif
1210 if (i > 0) return;
1211#ifdef REF_CHECK
1212 if (i < 0)
1213 {
1214 fprintf(stderr,"SSL_CTX_free, bad reference count\n");
1215 abort(); /* ok */
1216 }
1217#endif
1218 CRYPTO_free_ex_data(ssl_ctx_meth,(char *)a,&a->ex_data);
1219
1220 if (a->sessions != NULL)
1221 {
1222 SSL_CTX_flush_sessions(a,0);
1223 lh_free(a->sessions);
1224 }
1225 if (a->cert_store != NULL)
1226 X509_STORE_free(a->cert_store);
1227 if (a->cipher_list != NULL)
1228 sk_SSL_CIPHER_free(a->cipher_list);
1229 if (a->cipher_list_by_id != NULL)
1230 sk_SSL_CIPHER_free(a->cipher_list_by_id);
1231 if (a->cert != NULL)
1232 ssl_cert_free(a->cert);
1233 if (a->client_CA != NULL)
1234 sk_X509_NAME_pop_free(a->client_CA,X509_NAME_free);
1235 if (a->extra_certs != NULL)
1236 sk_X509_pop_free(a->extra_certs,X509_free);
1237 if (a->comp_methods != NULL)
1238 sk_SSL_COMP_pop_free(a->comp_methods,SSL_COMP_free);
1239 Free(a);
1240 }
1241
1242void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb)
1243 {
1244 ctx->default_passwd_callback=cb;
1245 }
1246
1247void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx,void *u)
1248 {
1249 ctx->default_passwd_callback_userdata=u;
1250 }
1251
1252void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,int (*cb)(),char *arg)
1253 {
1254 /* now
1255 * int (*cb)(X509_STORE_CTX *),
1256 * but should be
1257 * int (*cb)(X509_STORE_CTX *, void *arg)
1258 */
1259 ctx->app_verify_callback=cb;
1260 ctx->app_verify_arg=arg; /* never used */
1261 }
1262
1263void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*cb)(int, X509_STORE_CTX *))
1264 {
1265 ctx->verify_mode=mode;
1266 ctx->default_verify_callback=cb;
1267 /* This needs cleaning up EAY EAY EAY */
1268 X509_STORE_set_verify_cb_func(ctx->cert_store,cb);
1269 }
1270
1271void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth)
1272 {
1273 ctx->verify_depth=depth;
1274 }
1275
1276void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher)
1277 {
1278 CERT_PKEY *cpk;
1279 int rsa_enc,rsa_tmp,rsa_sign,dh_tmp,dh_rsa,dh_dsa,dsa_sign;
1280 int rsa_enc_export,dh_rsa_export,dh_dsa_export;
1281 int rsa_tmp_export,dh_tmp_export,kl;
1282 unsigned long mask,emask;
1283
1284 if (c == NULL) return;
1285
1286 kl=SSL_C_EXPORT_PKEYLENGTH(cipher);
1287
1288#ifndef NO_RSA
1289 rsa_tmp=(c->rsa_tmp != NULL || c->rsa_tmp_cb != NULL);
1290 rsa_tmp_export=(c->rsa_tmp_cb != NULL ||
1291 (rsa_tmp && RSA_size(c->rsa_tmp)*8 <= kl));
1292#else
1293 rsa_tmp=rsa_tmp_export=0;
1294#endif
1295#ifndef NO_DH
1296 dh_tmp=(c->dh_tmp != NULL || c->dh_tmp_cb != NULL);
1297 dh_tmp_export=(c->dh_tmp_cb != NULL ||
1298 (dh_tmp && DH_size(c->dh_tmp)*8 <= kl));
1299#else
1300 dh_tmp=dh_tmp_export=0;
1301#endif
1302
1303 cpk= &(c->pkeys[SSL_PKEY_RSA_ENC]);
1304 rsa_enc= (cpk->x509 != NULL && cpk->privatekey != NULL);
1305 rsa_enc_export=(rsa_enc && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1306 cpk= &(c->pkeys[SSL_PKEY_RSA_SIGN]);
1307 rsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1308 cpk= &(c->pkeys[SSL_PKEY_DSA_SIGN]);
1309 dsa_sign=(cpk->x509 != NULL && cpk->privatekey != NULL);
1310 cpk= &(c->pkeys[SSL_PKEY_DH_RSA]);
1311 dh_rsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1312 dh_rsa_export=(dh_rsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1313 cpk= &(c->pkeys[SSL_PKEY_DH_DSA]);
1314/* FIX THIS EAY EAY EAY */
1315 dh_dsa= (cpk->x509 != NULL && cpk->privatekey != NULL);
1316 dh_dsa_export=(dh_dsa && EVP_PKEY_size(cpk->privatekey)*8 <= kl);
1317
1318 mask=0;
1319 emask=0;
1320
1321#ifdef CIPHER_DEBUG
1322 printf("rt=%d rte=%d dht=%d re=%d ree=%d rs=%d ds=%d dhr=%d dhd=%d\n",
1323 rsa_tmp,rsa_tmp_export,dh_tmp,
1324 rsa_enc,rsa_enc_export,rsa_sign,dsa_sign,dh_rsa,dh_dsa);
1325#endif
1326
1327 if (rsa_enc || (rsa_tmp && rsa_sign))
1328 mask|=SSL_kRSA;
1329 if (rsa_enc_export || (rsa_tmp_export && (rsa_sign || rsa_enc)))
1330 emask|=SSL_kRSA;
1331
1332#if 0
1333 /* The match needs to be both kEDH and aRSA or aDSA, so don't worry */
1334 if ( (dh_tmp || dh_rsa || dh_dsa) &&
1335 (rsa_enc || rsa_sign || dsa_sign))
1336 mask|=SSL_kEDH;
1337 if ((dh_tmp_export || dh_rsa_export || dh_dsa_export) &&
1338 (rsa_enc || rsa_sign || dsa_sign))
1339 emask|=SSL_kEDH;
1340#endif
1341
1342 if (dh_tmp_export)
1343 emask|=SSL_kEDH;
1344
1345 if (dh_tmp)
1346 mask|=SSL_kEDH;
1347
1348 if (dh_rsa) mask|=SSL_kDHr;
1349 if (dh_rsa_export) emask|=SSL_kDHr;
1350
1351 if (dh_dsa) mask|=SSL_kDHd;
1352 if (dh_dsa_export) emask|=SSL_kDHd;
1353
1354 if (rsa_enc || rsa_sign)
1355 {
1356 mask|=SSL_aRSA;
1357 emask|=SSL_aRSA;
1358 }
1359
1360 if (dsa_sign)
1361 {
1362 mask|=SSL_aDSS;
1363 emask|=SSL_aDSS;
1364 }
1365
1366 mask|=SSL_aNULL;
1367 emask|=SSL_aNULL;
1368
1369 c->mask=mask;
1370 c->export_mask=emask;
1371 c->valid=1;
1372 }
1373
1374/* THIS NEEDS CLEANING UP */
1375X509 *ssl_get_server_send_cert(SSL *s)
1376 {
1377 unsigned long alg,mask,kalg;
1378 CERT *c;
1379 int i,is_export;
1380
1381 c=s->cert;
1382 ssl_set_cert_masks(c, s->s3->tmp.new_cipher);
1383 alg=s->s3->tmp.new_cipher->algorithms;
1384 is_export=SSL_C_IS_EXPORT(s->s3->tmp.new_cipher);
1385 mask=is_export?c->export_mask:c->mask;
1386 kalg=alg&(SSL_MKEY_MASK|SSL_AUTH_MASK);
1387
1388 if (kalg & SSL_kDHr)
1389 i=SSL_PKEY_DH_RSA;
1390 else if (kalg & SSL_kDHd)
1391 i=SSL_PKEY_DH_DSA;
1392 else if (kalg & SSL_aDSS)
1393 i=SSL_PKEY_DSA_SIGN;
1394 else if (kalg & SSL_aRSA)
1395 {
1396 if (c->pkeys[SSL_PKEY_RSA_ENC].x509 == NULL)
1397 i=SSL_PKEY_RSA_SIGN;
1398 else
1399 i=SSL_PKEY_RSA_ENC;
1400 }
1401 else /* if (kalg & SSL_aNULL) */
1402 {
1403 SSLerr(SSL_F_SSL_GET_SERVER_SEND_CERT,SSL_R_INTERNAL_ERROR);
1404 return(NULL);
1405 }
1406 if (c->pkeys[i].x509 == NULL) return(NULL);
1407 return(c->pkeys[i].x509);
1408 }
1409
1410EVP_PKEY *ssl_get_sign_pkey(SSL *s,SSL_CIPHER *cipher)
1411 {
1412 unsigned long alg;
1413 CERT *c;
1414
1415 alg=cipher->algorithms;
1416 c=s->cert;
1417
1418 if ((alg & SSL_aDSS) &&
1419 (c->pkeys[SSL_PKEY_DSA_SIGN].privatekey != NULL))
1420 return(c->pkeys[SSL_PKEY_DSA_SIGN].privatekey);
1421 else if (alg & SSL_aRSA)
1422 {
1423 if (c->pkeys[SSL_PKEY_RSA_SIGN].privatekey != NULL)
1424 return(c->pkeys[SSL_PKEY_RSA_SIGN].privatekey);
1425 else if (c->pkeys[SSL_PKEY_RSA_ENC].privatekey != NULL)
1426 return(c->pkeys[SSL_PKEY_RSA_ENC].privatekey);
1427 else
1428 return(NULL);
1429 }
1430 else /* if (alg & SSL_aNULL) */
1431 {
1432 SSLerr(SSL_F_SSL_GET_SIGN_PKEY,SSL_R_INTERNAL_ERROR);
1433 return(NULL);
1434 }
1435 }
1436
1437void ssl_update_cache(SSL *s,int mode)
1438 {
1439 int i;
1440
1441 /* If the session_id_length is 0, we are not supposed to cache it,
1442 * and it would be rather hard to do anyway :-) */
1443 if (s->session->session_id_length == 0) return;
1444
1445 if ((s->ctx->session_cache_mode & mode)
1446 && (!s->hit)
1447 && SSL_CTX_add_session(s->ctx,s->session)
1448 && (s->ctx->new_session_cb != NULL))
1449 {
1450 CRYPTO_add(&s->session->references,1,CRYPTO_LOCK_SSL_SESSION);
1451 if (!s->ctx->new_session_cb(s,s->session))
1452 SSL_SESSION_free(s->session);
1453 }
1454
1455 /* auto flush every 255 connections */
1456 i=s->ctx->session_cache_mode;
1457 if ((!(i & SSL_SESS_CACHE_NO_AUTO_CLEAR)) &&
1458 ((i & mode) == mode))
1459 {
1460 if ( (((mode & SSL_SESS_CACHE_CLIENT)
1461 ?s->ctx->stats.sess_connect_good
1462 :s->ctx->stats.sess_accept_good) & 0xff) == 0xff)
1463 {
1464 SSL_CTX_flush_sessions(s->ctx,time(NULL));
1465 }
1466 }
1467 }
1468
1469SSL_METHOD *SSL_get_ssl_method(SSL *s)
1470 {
1471 return(s->method);
1472 }
1473
1474int SSL_set_ssl_method(SSL *s,SSL_METHOD *meth)
1475 {
1476 int conn= -1;
1477 int ret=1;
1478
1479 if (s->method != meth)
1480 {
1481 if (s->handshake_func != NULL)
1482 conn=(s->handshake_func == s->method->ssl_connect);
1483
1484 if (s->method->version == meth->version)
1485 s->method=meth;
1486 else
1487 {
1488 s->method->ssl_free(s);
1489 s->method=meth;
1490 ret=s->method->ssl_new(s);
1491 }
1492
1493 if (conn == 1)
1494 s->handshake_func=meth->ssl_connect;
1495 else if (conn == 0)
1496 s->handshake_func=meth->ssl_accept;
1497 }
1498 return(ret);
1499 }
1500
1501int SSL_get_error(SSL *s,int i)
1502 {
1503 int reason;
1504 unsigned long l;
1505 BIO *bio;
1506
1507 if (i > 0) return(SSL_ERROR_NONE);
1508
1509 /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake
1510 * etc, where we do encode the error */
1511 if ((l=ERR_peek_error()) != 0)
1512 {
1513 if (ERR_GET_LIB(l) == ERR_LIB_SYS)
1514 return(SSL_ERROR_SYSCALL);
1515 else
1516 return(SSL_ERROR_SSL);
1517 }
1518
1519 if ((i < 0) && SSL_want_read(s))
1520 {
1521 bio=SSL_get_rbio(s);
1522 if (BIO_should_read(bio))
1523 return(SSL_ERROR_WANT_READ);
1524 else if (BIO_should_write(bio))
1525 /* This one doesn't make too much sense ... We never try
1526 * to write to the rbio, and an application program where
1527 * rbio and wbio are separate couldn't even know what it
1528 * should wait for.
1529 * However if we ever set s->rwstate incorrectly
1530 * (so that we have SSL_want_read(s) instead of
1531 * SSL_want_write(s)) and rbio and wbio *are* the same,
1532 * this test works around that bug; so it might be safer
1533 * to keep it. */
1534 return(SSL_ERROR_WANT_WRITE);
1535 else if (BIO_should_io_special(bio))
1536 {
1537 reason=BIO_get_retry_reason(bio);
1538 if (reason == BIO_RR_CONNECT)
1539 return(SSL_ERROR_WANT_CONNECT);
1540 else
1541 return(SSL_ERROR_SYSCALL); /* unknown */
1542 }
1543 }
1544
1545 if ((i < 0) && SSL_want_write(s))
1546 {
1547 bio=SSL_get_wbio(s);
1548 if (BIO_should_write(bio))
1549 return(SSL_ERROR_WANT_WRITE);
1550 else if (BIO_should_read(bio))
1551 /* See above (SSL_want_read(s) with BIO_should_write(bio)) */
1552 return(SSL_ERROR_WANT_READ);
1553 else if (BIO_should_io_special(bio))
1554 {
1555 reason=BIO_get_retry_reason(bio);
1556 if (reason == BIO_RR_CONNECT)
1557 return(SSL_ERROR_WANT_CONNECT);
1558 else
1559 return(SSL_ERROR_SYSCALL);
1560 }
1561 }
1562 if ((i < 0) && SSL_want_x509_lookup(s))
1563 {
1564 return(SSL_ERROR_WANT_X509_LOOKUP);
1565 }
1566
1567 if (i == 0)
1568 {
1569 if (s->version == SSL2_VERSION)
1570 {
1571 /* assume it is the socket being closed */
1572 return(SSL_ERROR_ZERO_RETURN);
1573 }
1574 else
1575 {
1576 if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) &&
1577 (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY))
1578 return(SSL_ERROR_ZERO_RETURN);
1579 }
1580 }
1581 return(SSL_ERROR_SYSCALL);
1582 }
1583
1584int SSL_do_handshake(SSL *s)
1585 {
1586 int ret=1;
1587
1588 if (s->handshake_func == NULL)
1589 {
1590 SSLerr(SSL_F_SSL_DO_HANDSHAKE,SSL_R_CONNECTION_TYPE_NOT_SET);
1591 return(-1);
1592 }
1593
1594 s->method->ssl_renegotiate_check(s);
1595
1596 if (SSL_in_init(s) || SSL_in_before(s))
1597 {
1598 ret=s->handshake_func(s);
1599 }
1600 return(ret);
1601 }
1602
1603/* For the next 2 functions, SSL_clear() sets shutdown and so
1604 * one of these calls will reset it */
1605void SSL_set_accept_state(SSL *s)
1606 {
1607 s->server=1;
1608 s->shutdown=0;
1609 s->state=SSL_ST_ACCEPT|SSL_ST_BEFORE;
1610 s->handshake_func=s->method->ssl_accept;
1611 /* clear the current cipher */
1612 ssl_clear_cipher_ctx(s);
1613 }
1614
1615void SSL_set_connect_state(SSL *s)
1616 {
1617 s->server=0;
1618 s->shutdown=0;
1619 s->state=SSL_ST_CONNECT|SSL_ST_BEFORE;
1620 s->handshake_func=s->method->ssl_connect;
1621 /* clear the current cipher */
1622 ssl_clear_cipher_ctx(s);
1623 }
1624
1625int ssl_undefined_function(SSL *s)
1626 {
1627 SSLerr(SSL_F_SSL_UNDEFINED_FUNCTION,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1628 return(0);
1629 }
1630
1631SSL_METHOD *ssl_bad_method(int ver)
1632 {
1633 SSLerr(SSL_F_SSL_BAD_METHOD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1634 return(NULL);
1635 }
1636
1637const char *SSL_get_version(SSL *s)
1638 {
1639 if (s->version == TLS1_VERSION)
1640 return("TLSv1");
1641 else if (s->version == SSL3_VERSION)
1642 return("SSLv3");
1643 else if (s->version == SSL2_VERSION)
1644 return("SSLv2");
1645 else
1646 return("unknown");
1647 }
1648
1649SSL *SSL_dup(SSL *s)
1650 {
1651 STACK_OF(X509_NAME) *sk;
1652 X509_NAME *xn;
1653 SSL *ret;
1654 int i;
1655
1656 if ((ret=SSL_new(SSL_get_SSL_CTX(s))) == NULL)
1657 return(NULL);
1658
1659 if (s->session != NULL)
1660 {
1661 /* This copies session-id, SSL_METHOD, sid_ctx, and 'cert' */
1662 SSL_copy_session_id(ret,s);
1663 }
1664 else
1665 {
1666 /* No session has been established yet, so we have to expect
1667 * that s->cert or ret->cert will be changed later --
1668 * they should not both point to the same object,
1669 * and thus we can't use SSL_copy_session_id. */
1670
1671 ret->method = s->method;
1672 ret->method->ssl_new(ret);
1673
1674 if (s->cert != NULL)
1675 {
1676 ret->cert = ssl_cert_dup(s->cert);
1677 if (ret->cert == NULL)
1678 goto err;
1679 }
1680
1681 SSL_set_session_id_context(ret,
1682 s->sid_ctx, s->sid_ctx_length);
1683 }
1684
1685 SSL_set_read_ahead(ret,SSL_get_read_ahead(s));
1686 SSL_set_verify(ret,SSL_get_verify_mode(s),
1687 SSL_get_verify_callback(s));
1688 SSL_set_verify_depth(ret,SSL_get_verify_depth(s));
1689
1690 SSL_set_info_callback(ret,SSL_get_info_callback(s));
1691
1692 ret->debug=s->debug;
1693 ret->options=s->options;
1694
1695 /* copy app data, a little dangerous perhaps */
1696 if (!CRYPTO_dup_ex_data(ssl_meth,&ret->ex_data,&s->ex_data))
1697 goto err;
1698
1699 /* setup rbio, and wbio */
1700 if (s->rbio != NULL)
1701 {
1702 if (!BIO_dup_state(s->rbio,(char *)&ret->rbio))
1703 goto err;
1704 }
1705 if (s->wbio != NULL)
1706 {
1707 if (s->wbio != s->rbio)
1708 {
1709 if (!BIO_dup_state(s->wbio,(char *)&ret->wbio))
1710 goto err;
1711 }
1712 else
1713 ret->wbio=ret->rbio;
1714 }
1715
1716 /* dup the cipher_list and cipher_list_by_id stacks */
1717 if (s->cipher_list != NULL)
1718 {
1719 if ((ret->cipher_list=sk_SSL_CIPHER_dup(s->cipher_list)) == NULL)
1720 goto err;
1721 }
1722 if (s->cipher_list_by_id != NULL)
1723 if ((ret->cipher_list_by_id=sk_SSL_CIPHER_dup(s->cipher_list_by_id))
1724 == NULL)
1725 goto err;
1726
1727 /* Dup the client_CA list */
1728 if (s->client_CA != NULL)
1729 {
1730 if ((sk=sk_X509_NAME_dup(s->client_CA)) == NULL) goto err;
1731 ret->client_CA=sk;
1732 for (i=0; i<sk_X509_NAME_num(sk); i++)
1733 {
1734 xn=sk_X509_NAME_value(sk,i);
1735 if (sk_X509_NAME_set(sk,i,X509_NAME_dup(xn)) == NULL)
1736 {
1737 X509_NAME_free(xn);
1738 goto err;
1739 }
1740 }
1741 }
1742
1743 ret->shutdown=s->shutdown;
1744 ret->state=s->state;
1745 ret->handshake_func=s->handshake_func;
1746 ret->server=s->server;
1747
1748 if (0)
1749 {
1750err:
1751 if (ret != NULL) SSL_free(ret);
1752 ret=NULL;
1753 }
1754 return(ret);
1755 }
1756
1757void ssl_clear_cipher_ctx(SSL *s)
1758 {
1759 if (s->enc_read_ctx != NULL)
1760 {
1761 EVP_CIPHER_CTX_cleanup(s->enc_read_ctx);
1762 Free(s->enc_read_ctx);
1763 s->enc_read_ctx=NULL;
1764 }
1765 if (s->enc_write_ctx != NULL)
1766 {
1767 EVP_CIPHER_CTX_cleanup(s->enc_write_ctx);
1768 Free(s->enc_write_ctx);
1769 s->enc_write_ctx=NULL;
1770 }
1771 if (s->expand != NULL)
1772 {
1773 COMP_CTX_free(s->expand);
1774 s->expand=NULL;
1775 }
1776 if (s->compress != NULL)
1777 {
1778 COMP_CTX_free(s->compress);
1779 s->compress=NULL;
1780 }
1781 }
1782
1783/* Fix this function so that it takes an optional type parameter */
1784X509 *SSL_get_certificate(SSL *s)
1785 {
1786 if (s->cert != NULL)
1787 return(s->cert->key->x509);
1788 else
1789 return(NULL);
1790 }
1791
1792/* Fix this function so that it takes an optional type parameter */
1793EVP_PKEY *SSL_get_privatekey(SSL *s)
1794 {
1795 if (s->cert != NULL)
1796 return(s->cert->key->privatekey);
1797 else
1798 return(NULL);
1799 }
1800
1801SSL_CIPHER *SSL_get_current_cipher(SSL *s)
1802 {
1803 if ((s->session != NULL) && (s->session->cipher != NULL))
1804 return(s->session->cipher);
1805 return(NULL);
1806 }
1807
1808int ssl_init_wbio_buffer(SSL *s,int push)
1809 {
1810 BIO *bbio;
1811
1812 if (s->bbio == NULL)
1813 {
1814 bbio=BIO_new(BIO_f_buffer());
1815 if (bbio == NULL) return(0);
1816 s->bbio=bbio;
1817 }
1818 else
1819 {
1820 bbio=s->bbio;
1821 if (s->bbio == s->wbio)
1822 s->wbio=BIO_pop(s->wbio);
1823 }
1824 (void)BIO_reset(bbio);
1825/* if (!BIO_set_write_buffer_size(bbio,16*1024)) */
1826 if (!BIO_set_read_buffer_size(bbio,1))
1827 {
1828 SSLerr(SSL_F_SSL_INIT_WBIO_BUFFER,ERR_R_BUF_LIB);
1829 return(0);
1830 }
1831 if (push)
1832 {
1833 if (s->wbio != bbio)
1834 s->wbio=BIO_push(bbio,s->wbio);
1835 }
1836 else
1837 {
1838 if (s->wbio == bbio)
1839 s->wbio=BIO_pop(bbio);
1840 }
1841 return(1);
1842 }
1843
1844void ssl_free_wbio_buffer(SSL *s)
1845 {
1846 BIO *under;
1847
1848 if (s->bbio == NULL) return;
1849
1850 if (s->bbio == s->wbio)
1851 {
1852 /* remove buffering */
1853 under=BIO_pop(s->wbio);
1854 if (under != NULL)
1855 s->wbio=under;
1856 else
1857 abort(); /* ok */
1858 }
1859 BIO_free(s->bbio);
1860 s->bbio=NULL;
1861 }
1862
1863void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode)
1864 {
1865 ctx->quiet_shutdown=mode;
1866 }
1867
1868int SSL_CTX_get_quiet_shutdown(SSL_CTX *ctx)
1869 {
1870 return(ctx->quiet_shutdown);
1871 }
1872
1873void SSL_set_quiet_shutdown(SSL *s,int mode)
1874 {
1875 s->quiet_shutdown=mode;
1876 }
1877
1878int SSL_get_quiet_shutdown(SSL *s)
1879 {
1880 return(s->quiet_shutdown);
1881 }
1882
1883void SSL_set_shutdown(SSL *s,int mode)
1884 {
1885 s->shutdown=mode;
1886 }
1887
1888int SSL_get_shutdown(SSL *s)
1889 {
1890 return(s->shutdown);
1891 }
1892
1893int SSL_version(SSL *s)
1894 {
1895 return(s->version);
1896 }
1897
1898SSL_CTX *SSL_get_SSL_CTX(SSL *ssl)
1899 {
1900 return(ssl->ctx);
1901 }
1902
1903#ifndef NO_STDIO
1904int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)
1905 {
1906 return(X509_STORE_set_default_paths(ctx->cert_store));
1907 }
1908
1909int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
1910 const char *CApath)
1911 {
1912 return(X509_STORE_load_locations(ctx->cert_store,CAfile,CApath));
1913 }
1914#endif
1915
1916void SSL_set_info_callback(SSL *ssl,void (*cb)())
1917 {
1918 ssl->info_callback=cb;
1919 }
1920
1921void (*SSL_get_info_callback(SSL *ssl))(void)
1922 {
1923 return((void (*)())ssl->info_callback);
1924 }
1925
1926int SSL_state(SSL *ssl)
1927 {
1928 return(ssl->state);
1929 }
1930
1931void SSL_set_verify_result(SSL *ssl,long arg)
1932 {
1933 ssl->verify_result=arg;
1934 }
1935
1936long SSL_get_verify_result(SSL *ssl)
1937 {
1938 return(ssl->verify_result);
1939 }
1940
1941int SSL_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func,
1942 CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func)
1943 {
1944 ssl_meth_num++;
1945 return(CRYPTO_get_ex_new_index(ssl_meth_num-1,
1946 &ssl_meth,argl,argp,new_func,dup_func,free_func));
1947 }
1948
1949int SSL_set_ex_data(SSL *s,int idx,void *arg)
1950 {
1951 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
1952 }
1953
1954void *SSL_get_ex_data(SSL *s,int idx)
1955 {
1956 return(CRYPTO_get_ex_data(&s->ex_data,idx));
1957 }
1958
1959int SSL_CTX_get_ex_new_index(long argl,void *argp,CRYPTO_EX_new *new_func,
1960 CRYPTO_EX_dup *dup_func,CRYPTO_EX_free *free_func)
1961 {
1962 ssl_ctx_meth_num++;
1963 return(CRYPTO_get_ex_new_index(ssl_ctx_meth_num-1,
1964 &ssl_ctx_meth,argl,argp,new_func,dup_func,free_func));
1965 }
1966
1967int SSL_CTX_set_ex_data(SSL_CTX *s,int idx,void *arg)
1968 {
1969 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
1970 }
1971
1972void *SSL_CTX_get_ex_data(SSL_CTX *s,int idx)
1973 {
1974 return(CRYPTO_get_ex_data(&s->ex_data,idx));
1975 }
1976
1977int ssl_ok(SSL *s)
1978 {
1979 return(1);
1980 }
1981
1982X509_STORE *SSL_CTX_get_cert_store(SSL_CTX *ctx)
1983 {
1984 return(ctx->cert_store);
1985 }
1986
1987void SSL_CTX_set_cert_store(SSL_CTX *ctx,X509_STORE *store)
1988 {
1989 if (ctx->cert_store != NULL)
1990 X509_STORE_free(ctx->cert_store);
1991 ctx->cert_store=store;
1992 }
1993
1994int SSL_want(SSL *s)
1995 {
1996 return(s->rwstate);
1997 }
1998
1999/*!
2000 * \brief Set the callback for generating temporary RSA keys.
2001 * \param ctx the SSL context.
2002 * \param cb the callback
2003 */
2004
2005#ifndef NO_RSA
2006void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,RSA *(*cb)(SSL *ssl,
2007 int is_export,
2008 int keylength))
2009 {
2010 SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb);
2011 }
2012
2013void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl,
2014 int is_export,
2015 int keylength))
2016 {
2017 SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,(void (*)())cb);
2018 }
2019#endif
2020
2021#ifdef DOXYGEN
2022/*!
2023 * \brief The RSA temporary key callback function.
2024 * \param ssl the SSL session.
2025 * \param is_export \c TRUE if the temp RSA key is for an export ciphersuite.
2026 * \param keylength if \c is_export is \c TRUE, then \c keylength is the size
2027 * of the required key in bits.
2028 * \return the temporary RSA key.
2029 * \sa SSL_CTX_set_tmp_rsa_callback, SSL_set_tmp_rsa_callback
2030 */
2031
2032RSA *cb(SSL *ssl,int is_export,int keylength)
2033 {}
2034#endif
2035
2036/*!
2037 * \brief Set the callback for generating temporary DH keys.
2038 * \param ctx the SSL context.
2039 * \param dh the callback
2040 */
2041
2042#ifndef NO_DH
2043void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,DH *(*dh)(SSL *ssl,int is_export,
2044 int keylength))
2045 {
2046 SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh);
2047 }
2048
2049void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int is_export,
2050 int keylength))
2051 {
2052 SSL_callback_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,(void (*)())dh);
2053 }
2054#endif
2055
2056#if defined(_WINDLL) && defined(WIN16)
2057#include "../crypto/bio/bss_file.c"
2058#endif
2059
2060IMPLEMENT_STACK_OF(SSL_CIPHER)
2061IMPLEMENT_STACK_OF(SSL_COMP)
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h
deleted file mode 100644
index 9a52bab254..0000000000
--- a/src/lib/libssl/ssl_locl.h
+++ /dev/null
@@ -1,555 +0,0 @@
1/* ssl/ssl_locl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#ifndef HEADER_SSL_LOCL_H
60#define HEADER_SSL_LOCL_H
61#include <stdlib.h>
62#include <time.h>
63#include <string.h>
64#include <errno.h>
65
66#include "openssl/e_os.h"
67
68#include <openssl/buffer.h>
69#include <openssl/comp.h>
70#include <openssl/bio.h>
71#include <openssl/crypto.h>
72#include <openssl/evp.h>
73#include <openssl/stack.h>
74#include <openssl/x509.h>
75#include <openssl/err.h>
76#include <openssl/ssl.h>
77
78#define PKCS1_CHECK
79
80#define c2l(c,l) (l = ((unsigned long)(*((c)++))) , \
81 l|=(((unsigned long)(*((c)++)))<< 8), \
82 l|=(((unsigned long)(*((c)++)))<<16), \
83 l|=(((unsigned long)(*((c)++)))<<24))
84
85/* NOTE - c is not incremented as per c2l */
86#define c2ln(c,l1,l2,n) { \
87 c+=n; \
88 l1=l2=0; \
89 switch (n) { \
90 case 8: l2 =((unsigned long)(*(--(c))))<<24; \
91 case 7: l2|=((unsigned long)(*(--(c))))<<16; \
92 case 6: l2|=((unsigned long)(*(--(c))))<< 8; \
93 case 5: l2|=((unsigned long)(*(--(c)))); \
94 case 4: l1 =((unsigned long)(*(--(c))))<<24; \
95 case 3: l1|=((unsigned long)(*(--(c))))<<16; \
96 case 2: l1|=((unsigned long)(*(--(c))))<< 8; \
97 case 1: l1|=((unsigned long)(*(--(c)))); \
98 } \
99 }
100
101#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
102 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
103 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
104 *((c)++)=(unsigned char)(((l)>>24)&0xff))
105
106#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24, \
107 l|=((unsigned long)(*((c)++)))<<16, \
108 l|=((unsigned long)(*((c)++)))<< 8, \
109 l|=((unsigned long)(*((c)++))))
110
111#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
112 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
113 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
114 *((c)++)=(unsigned char)(((l) )&0xff))
115
116/* NOTE - c is not incremented as per l2c */
117#define l2cn(l1,l2,c,n) { \
118 c+=n; \
119 switch (n) { \
120 case 8: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
121 case 7: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
122 case 6: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
123 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
124 case 4: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
125 case 3: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
126 case 2: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
127 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
128 } \
129 }
130
131#define n2s(c,s) ((s=(((unsigned int)(c[0]))<< 8)| \
132 (((unsigned int)(c[1])) )),c+=2)
133#define s2n(s,c) ((c[0]=(unsigned char)(((s)>> 8)&0xff), \
134 c[1]=(unsigned char)(((s) )&0xff)),c+=2)
135
136#define n2l3(c,l) ((l =(((unsigned long)(c[0]))<<16)| \
137 (((unsigned long)(c[1]))<< 8)| \
138 (((unsigned long)(c[2])) )),c+=3)
139
140#define l2n3(l,c) ((c[0]=(unsigned char)(((l)>>16)&0xff), \
141 c[1]=(unsigned char)(((l)>> 8)&0xff), \
142 c[2]=(unsigned char)(((l) )&0xff)),c+=3)
143
144/* LOCAL STUFF */
145
146#define SSL_DECRYPT 0
147#define SSL_ENCRYPT 1
148
149#define TWO_BYTE_BIT 0x80
150#define SEC_ESC_BIT 0x40
151#define TWO_BYTE_MASK 0x7fff
152#define THREE_BYTE_MASK 0x3fff
153
154#define INC32(a) ((a)=((a)+1)&0xffffffffL)
155#define DEC32(a) ((a)=((a)-1)&0xffffffffL)
156#define MAX_MAC_SIZE 20 /* up from 16 for SSLv3 */
157
158/*
159 * Define the Bitmasks for SSL_CIPHER.algorithms.
160 * This bits are used packed as dense as possible. If new methods/ciphers
161 * etc will be added, the bits a likely to change, so this information
162 * is for internal library use only, even though SSL_CIPHER.algorithms
163 * can be publicly accessed.
164 * Use the according functions for cipher management instead.
165 *
166 * The bit mask handling in the selection and sorting scheme in
167 * ssl_create_cipher_list() has only limited capabilities, reflecting
168 * that the different entities within are mutually exclusive:
169 * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
170 */
171#define SSL_MKEY_MASK 0x0000001FL
172#define SSL_kRSA 0x00000001L /* RSA key exchange */
173#define SSL_kDHr 0x00000002L /* DH cert RSA CA cert */
174#define SSL_kDHd 0x00000004L /* DH cert DSA CA cert */
175#define SSL_kFZA 0x00000008L
176#define SSL_kEDH 0x00000010L /* tmp DH key no DH cert */
177#define SSL_EDH (SSL_kEDH|(SSL_AUTH_MASK^SSL_aNULL))
178
179#define SSL_AUTH_MASK 0x000003e0L
180#define SSL_aRSA 0x00000020L /* Authenticate with RSA */
181#define SSL_aDSS 0x00000040L /* Authenticate with DSS */
182#define SSL_DSS SSL_aDSS
183#define SSL_aFZA 0x00000080L
184#define SSL_aNULL 0x00000100L /* no Authenticate, ADH */
185#define SSL_aDH 0x00000200L /* no Authenticate, ADH */
186
187#define SSL_NULL (SSL_eNULL)
188#define SSL_ADH (SSL_kEDH|SSL_aNULL)
189#define SSL_RSA (SSL_kRSA|SSL_aRSA)
190#define SSL_DH (SSL_kDHr|SSL_kDHd|SSL_kEDH)
191#define SSL_FZA (SSL_aFZA|SSL_kFZA|SSL_eFZA)
192
193#define SSL_ENC_MASK 0x0001Fc00L
194#define SSL_DES 0x00000400L
195#define SSL_3DES 0x00000800L
196#define SSL_RC4 0x00001000L
197#define SSL_RC2 0x00002000L
198#define SSL_IDEA 0x00004000L
199#define SSL_eFZA 0x00008000L
200#define SSL_eNULL 0x00010000L
201
202#define SSL_MAC_MASK 0x00060000L
203#define SSL_MD5 0x00020000L
204#define SSL_SHA1 0x00040000L
205#define SSL_SHA (SSL_SHA1)
206
207#define SSL_SSL_MASK 0x00180000L
208#define SSL_SSLV2 0x00080000L
209#define SSL_SSLV3 0x00100000L
210#define SSL_TLSV1 SSL_SSLV3 /* for now */
211
212/* we have used 001fffff - 11 bits left to go */
213
214/*
215 * Export and cipher strength information. For each cipher we have to decide
216 * whether it is exportable or not. This information is likely to change
217 * over time, since the export control rules are no static technical issue.
218 *
219 * Independent of the export flag the cipher strength is sorted into classes.
220 * SSL_EXP40 was denoting the 40bit US export limit of past times, which now
221 * is at 56bit (SSL_EXP56). If the exportable cipher class is going to change
222 * again (eg. to 64bit) the use of "SSL_EXP*" becomes blurred even more,
223 * since SSL_EXP64 could be similar to SSL_LOW.
224 * For this reason SSL_MICRO and SSL_MINI macros are included to widen the
225 * namespace of SSL_LOW-SSL_HIGH to lower values. As development of speed
226 * and ciphers goes, another extension to SSL_SUPER and/or SSL_ULTRA would
227 * be possible.
228 */
229#define SSL_EXP_MASK 0x00000003L
230#define SSL_NOT_EXP 0x00000001L
231#define SSL_EXPORT 0x00000002L
232
233#define SSL_STRONG_MASK 0x0000007cL
234#define SSL_EXP40 0x00000004L
235#define SSL_MICRO (SSL_EXP40)
236#define SSL_EXP56 0x00000008L
237#define SSL_MINI (SSL_EXP56)
238#define SSL_LOW 0x00000010L
239#define SSL_MEDIUM 0x00000020L
240#define SSL_HIGH 0x00000040L
241
242/* we have used 0000007f - 25 bits left to go */
243
244/*
245 * Macros to check the export status and cipher strength for export ciphers.
246 * Even though the macros for EXPORT and EXPORT40/56 have similar names,
247 * their meaning is different:
248 * *_EXPORT macros check the 'exportable' status.
249 * *_EXPORT40/56 macros are used to check whether a certain cipher strength
250 * is given.
251 * Since the SSL_IS_EXPORT* and SSL_EXPORT* macros depend on the correct
252 * algorithm structure element to be passed (algorithms, algo_strength) and no
253 * typechecking can be done as they are all of type unsigned long, their
254 * direct usage is discouraged.
255 * Use the SSL_C_* macros instead.
256 */
257#define SSL_IS_EXPORT(a) ((a)&SSL_EXPORT)
258#define SSL_IS_EXPORT56(a) ((a)&SSL_EXP56)
259#define SSL_IS_EXPORT40(a) ((a)&SSL_EXP40)
260#define SSL_C_IS_EXPORT(c) SSL_IS_EXPORT((c)->algo_strength)
261#define SSL_C_IS_EXPORT56(c) SSL_IS_EXPORT56((c)->algo_strength)
262#define SSL_C_IS_EXPORT40(c) SSL_IS_EXPORT40((c)->algo_strength)
263
264#define SSL_EXPORT_KEYLENGTH(a,s) (SSL_IS_EXPORT40(s) ? 5 : \
265 ((a)&SSL_ENC_MASK) == SSL_DES ? 8 : 7)
266#define SSL_EXPORT_PKEYLENGTH(a) (SSL_IS_EXPORT40(a) ? 512 : 1024)
267#define SSL_C_EXPORT_KEYLENGTH(c) SSL_EXPORT_KEYLENGTH((c)->algorithms, \
268 (c)->algo_strength)
269#define SSL_C_EXPORT_PKEYLENGTH(c) SSL_EXPORT_PKEYLENGTH((c)->algo_strength)
270
271
272#define SSL_ALL 0xffffffffL
273#define SSL_ALL_CIPHERS (SSL_MKEY_MASK|SSL_AUTH_MASK|SSL_ENC_MASK|\
274 SSL_MAC_MASK)
275#define SSL_ALL_STRENGTHS (SSL_EXP_MASK|SSL_STRONG_MASK)
276
277/* Mostly for SSLv3 */
278#define SSL_PKEY_RSA_ENC 0
279#define SSL_PKEY_RSA_SIGN 1
280#define SSL_PKEY_DSA_SIGN 2
281#define SSL_PKEY_DH_RSA 3
282#define SSL_PKEY_DH_DSA 4
283#define SSL_PKEY_NUM 5
284
285/* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) |
286 * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN)
287 * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
288 * SSL_kEDH <- RSA_ENC | RSA_SIGN | DSA_SIGN
289 * SSL_aRSA <- RSA_ENC | RSA_SIGN
290 * SSL_aDSS <- DSA_SIGN
291 */
292
293/*
294#define CERT_INVALID 0
295#define CERT_PUBLIC_KEY 1
296#define CERT_PRIVATE_KEY 2
297*/
298
299typedef struct cert_pkey_st
300 {
301 X509 *x509;
302 EVP_PKEY *privatekey;
303 } CERT_PKEY;
304
305typedef struct cert_st
306 {
307 /* Current active set */
308 CERT_PKEY *key; /* ALWAYS points to an element of the pkeys array
309 * Probably it would make more sense to store
310 * an index, not a pointer. */
311
312 /* The following masks are for the key and auth
313 * algorithms that are supported by the certs below */
314 int valid;
315 unsigned long mask;
316 unsigned long export_mask;
317#ifndef NO_RSA
318 RSA *rsa_tmp;
319 RSA *(*rsa_tmp_cb)(SSL *ssl,int is_export,int keysize);
320#endif
321#ifndef NO_DH
322 DH *dh_tmp;
323 DH *(*dh_tmp_cb)(SSL *ssl,int is_export,int keysize);
324#endif
325
326 CERT_PKEY pkeys[SSL_PKEY_NUM];
327
328 int references; /* >1 only if SSL_copy_session_id is used */
329 } CERT;
330
331
332typedef struct sess_cert_st
333 {
334 STACK_OF(X509) *cert_chain; /* as received from peer (not for SSL2) */
335
336 /* The 'peer_...' members are used only by clients. */
337 int peer_cert_type;
338
339 CERT_PKEY *peer_key; /* points to an element of peer_pkeys (never NULL!) */
340 CERT_PKEY peer_pkeys[SSL_PKEY_NUM];
341 /* Obviously we don't have the private keys of these,
342 * so maybe we shouldn't even use the CERT_PKEY type here. */
343
344#ifndef NO_RSA
345 RSA *peer_rsa_tmp; /* not used for SSL 2 */
346#endif
347#ifndef NO_DH
348 DH *peer_dh_tmp; /* not used for SSL 2 */
349#endif
350
351 int references; /* actually always 1 at the moment */
352 } SESS_CERT;
353
354
355/*#define MAC_DEBUG */
356
357/*#define ERR_DEBUG */
358/*#define ABORT_DEBUG */
359/*#define PKT_DEBUG 1 */
360/*#define DES_DEBUG */
361/*#define DES_OFB_DEBUG */
362/*#define SSL_DEBUG */
363/*#define RSA_DEBUG */
364/*#define IDEA_DEBUG */
365
366#define FP_ICC (int (*)(const void *,const void *))
367#define ssl_put_cipher_by_char(ssl,ciph,ptr) \
368 ((ssl)->method->put_cipher_by_char((ciph),(ptr)))
369#define ssl_get_cipher_by_char(ssl,ptr) \
370 ((ssl)->method->get_cipher_by_char(ptr))
371
372/* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff
373 * It is a bit of a mess of functions, but hell, think of it as
374 * an opaque structure :-) */
375typedef struct ssl3_enc_method
376 {
377 int (*enc)(SSL *, int);
378 int (*mac)(SSL *, unsigned char *, int);
379 int (*setup_key_block)(SSL *);
380 int (*generate_master_secret)(SSL *, unsigned char *, unsigned char *, int);
381 int (*change_cipher_state)(SSL *, int);
382 int (*final_finish_mac)(SSL *, EVP_MD_CTX *, EVP_MD_CTX *, const char *, int, unsigned char *);
383 int finish_mac_length;
384 int (*cert_verify_mac)(SSL *, EVP_MD_CTX *, unsigned char *);
385 const char *client_finished_label;
386 int client_finished_label_len;
387 const char *server_finished_label;
388 int server_finished_label_len;
389 int (*alert_value)(int);
390 } SSL3_ENC_METHOD;
391
392/* Used for holding the relevant compression methods loaded into SSL_CTX */
393typedef struct ssl3_comp_st
394 {
395 int comp_id; /* The identifier byte for this compression type */
396 char *name; /* Text name used for the compression type */
397 COMP_METHOD *method; /* The method :-) */
398 } SSL3_COMP;
399
400OPENSSL_EXTERN SSL3_ENC_METHOD ssl3_undef_enc_method;
401OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[];
402OPENSSL_EXTERN SSL_CIPHER ssl3_ciphers[];
403
404#ifdef VMS
405#undef SSL_COMP_get_compression_methods
406#define SSL_COMP_get_compression_methods SSL_COMP_get_compress_methods
407#endif
408
409
410SSL_METHOD *ssl_bad_method(int ver);
411SSL_METHOD *sslv2_base_method(void);
412SSL_METHOD *sslv23_base_method(void);
413SSL_METHOD *sslv3_base_method(void);
414
415void ssl_clear_cipher_ctx(SSL *s);
416int ssl_clear_bad_session(SSL *s);
417CERT *ssl_cert_new(void);
418CERT *ssl_cert_dup(CERT *cert);
419int ssl_cert_inst(CERT **o);
420void ssl_cert_free(CERT *c);
421SESS_CERT *ssl_sess_cert_new(void);
422void ssl_sess_cert_free(SESS_CERT *sc);
423int ssl_set_peer_cert_type(SESS_CERT *c, int type);
424int ssl_get_new_session(SSL *s, int session);
425int ssl_get_prev_session(SSL *s, unsigned char *session,int len);
426int ssl_cipher_id_cmp(SSL_CIPHER *a,SSL_CIPHER *b);
427int ssl_cipher_ptr_id_cmp(SSL_CIPHER **ap,SSL_CIPHER **bp);
428STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
429 STACK_OF(SSL_CIPHER) **skp);
430int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p);
431STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
432 STACK_OF(SSL_CIPHER) **pref,
433 STACK_OF(SSL_CIPHER) **sorted,
434 const char *rule_str);
435void ssl_update_cache(SSL *s, int mode);
436int ssl_cipher_get_evp(SSL_SESSION *s,const EVP_CIPHER **enc,const EVP_MD **md,
437 SSL_COMP **comp);
438int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk);
439int ssl_undefined_function(SSL *s);
440X509 *ssl_get_server_send_cert(SSL *);
441EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *);
442int ssl_cert_type(X509 *x,EVP_PKEY *pkey);
443void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher);
444STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
445int ssl_verify_alarm_type(long type);
446
447int ssl2_enc_init(SSL *s, int client);
448void ssl2_generate_key_material(SSL *s);
449void ssl2_enc(SSL *s,int send_data);
450void ssl2_mac(SSL *s,unsigned char *mac,int send_data);
451SSL_CIPHER *ssl2_get_cipher_by_char(const unsigned char *p);
452int ssl2_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
453int ssl2_part_read(SSL *s, unsigned long f, int i);
454int ssl2_do_write(SSL *s);
455int ssl2_set_certificate(SSL *s, int type, int len, unsigned char *data);
456void ssl2_return_error(SSL *s,int reason);
457void ssl2_write_error(SSL *s);
458int ssl2_num_ciphers(void);
459SSL_CIPHER *ssl2_get_cipher(unsigned int u);
460int ssl2_new(SSL *s);
461void ssl2_free(SSL *s);
462int ssl2_accept(SSL *s);
463int ssl2_connect(SSL *s);
464int ssl2_read(SSL *s, void *buf, int len);
465int ssl2_peek(SSL *s, char *buf, int len);
466int ssl2_write(SSL *s, const void *buf, int len);
467int ssl2_shutdown(SSL *s);
468void ssl2_clear(SSL *s);
469long ssl2_ctrl(SSL *s,int cmd, long larg, char *parg);
470long ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg);
471long ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)());
472long ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)());
473int ssl2_pending(SSL *s);
474
475SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
476int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
477void ssl3_init_finished_mac(SSL *s);
478int ssl3_send_server_certificate(SSL *s);
479int ssl3_get_finished(SSL *s,int state_a,int state_b);
480int ssl3_setup_key_block(SSL *s);
481int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b);
482int ssl3_change_cipher_state(SSL *s,int which);
483void ssl3_cleanup_key_block(SSL *s);
484int ssl3_do_write(SSL *s,int type);
485void ssl3_send_alert(SSL *s,int level, int desc);
486int ssl3_generate_master_secret(SSL *s, unsigned char *out,
487 unsigned char *p, int len);
488int ssl3_get_req_cert_type(SSL *s,unsigned char *p);
489long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok);
490int ssl3_send_finished(SSL *s, int a, int b, const char *sender,int slen);
491int ssl3_num_ciphers(void);
492SSL_CIPHER *ssl3_get_cipher(unsigned int u);
493int ssl3_renegotiate(SSL *ssl);
494int ssl3_renegotiate_check(SSL *ssl);
495int ssl3_dispatch_alert(SSL *s);
496int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len);
497int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
498int ssl3_final_finish_mac(SSL *s, EVP_MD_CTX *ctx1, EVP_MD_CTX *ctx2,
499 const char *sender, int slen,unsigned char *p);
500int ssl3_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
501void ssl3_finish_mac(SSL *s, const unsigned char *buf, int len);
502int ssl3_enc(SSL *s, int send_data);
503int ssl3_mac(SSL *ssl, unsigned char *md, int send_data);
504unsigned long ssl3_output_cert_chain(SSL *s, X509 *x);
505SSL_CIPHER *ssl3_choose_cipher(SSL *ssl,STACK_OF(SSL_CIPHER) *have,
506 STACK_OF(SSL_CIPHER) *pref);
507int ssl3_setup_buffers(SSL *s);
508int ssl3_new(SSL *s);
509void ssl3_free(SSL *s);
510int ssl3_accept(SSL *s);
511int ssl3_connect(SSL *s);
512int ssl3_read(SSL *s, void *buf, int len);
513int ssl3_peek(SSL *s,char *buf, int len);
514int ssl3_write(SSL *s, const void *buf, int len);
515int ssl3_shutdown(SSL *s);
516void ssl3_clear(SSL *s);
517long ssl3_ctrl(SSL *s,int cmd, long larg, char *parg);
518long ssl3_ctx_ctrl(SSL_CTX *s,int cmd, long larg, char *parg);
519long ssl3_callback_ctrl(SSL *s,int cmd, void (*fp)());
520long ssl3_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)());
521int ssl3_pending(SSL *s);
522
523int ssl23_accept(SSL *s);
524int ssl23_connect(SSL *s);
525int ssl23_read_bytes(SSL *s, int n);
526int ssl23_write_bytes(SSL *s);
527
528int tls1_new(SSL *s);
529void tls1_free(SSL *s);
530void tls1_clear(SSL *s);
531long tls1_ctrl(SSL *s,int cmd, long larg, char *parg);
532long tls1_callback_ctrl(SSL *s,int cmd, void (*fp)());
533SSL_METHOD *tlsv1_base_method(void );
534
535int ssl_init_wbio_buffer(SSL *s, int push);
536void ssl_free_wbio_buffer(SSL *s);
537
538int tls1_change_cipher_state(SSL *s, int which);
539int tls1_setup_key_block(SSL *s);
540int tls1_enc(SSL *s, int snd);
541int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx,
542 const char *str, int slen, unsigned char *p);
543int tls1_cert_verify_mac(SSL *s, EVP_MD_CTX *in, unsigned char *p);
544int tls1_mac(SSL *ssl, unsigned char *md, int snd);
545int tls1_generate_master_secret(SSL *s, unsigned char *out,
546 unsigned char *p, int len);
547int tls1_alert_code(int code);
548int ssl3_alert_code(int code);
549int ssl_ok(SSL *s);
550
551SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
552STACK_OF(SSL_COMP) *SSL_COMP_get_compression_methods(void);
553
554
555#endif
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c
deleted file mode 100644
index 6ec7a5cdb1..0000000000
--- a/src/lib/libssl/ssl_rsa.c
+++ /dev/null
@@ -1,815 +0,0 @@
1/* ssl/ssl_rsa.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#include <stdio.h>
60#include <openssl/bio.h>
61#include <openssl/objects.h>
62#include <openssl/evp.h>
63#include <openssl/x509.h>
64#include <openssl/pem.h>
65#include "ssl_locl.h"
66
67static int ssl_set_cert(CERT *c, X509 *x509);
68static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey);
69int SSL_use_certificate(SSL *ssl, X509 *x)
70 {
71 if (x == NULL)
72 {
73 SSLerr(SSL_F_SSL_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER);
74 return(0);
75 }
76 if (!ssl_cert_inst(&ssl->cert))
77 {
78 SSLerr(SSL_F_SSL_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE);
79 return(0);
80 }
81 return(ssl_set_cert(ssl->cert,x));
82 }
83
84#ifndef NO_STDIO
85int SSL_use_certificate_file(SSL *ssl, const char *file, int type)
86 {
87 int j;
88 BIO *in;
89 int ret=0;
90 X509 *x=NULL;
91
92 in=BIO_new(BIO_s_file_internal());
93 if (in == NULL)
94 {
95 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB);
96 goto end;
97 }
98
99 if (BIO_read_filename(in,file) <= 0)
100 {
101 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB);
102 goto end;
103 }
104 if (type == SSL_FILETYPE_ASN1)
105 {
106 j=ERR_R_ASN1_LIB;
107 x=d2i_X509_bio(in,NULL);
108 }
109 else if (type == SSL_FILETYPE_PEM)
110 {
111 j=ERR_R_PEM_LIB;
112 x=PEM_read_bio_X509(in,NULL,ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata);
113 }
114 else
115 {
116 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE);
117 goto end;
118 }
119
120 if (x == NULL)
121 {
122 SSLerr(SSL_F_SSL_USE_CERTIFICATE_FILE,j);
123 goto end;
124 }
125
126 ret=SSL_use_certificate(ssl,x);
127end:
128 if (x != NULL) X509_free(x);
129 if (in != NULL) BIO_free(in);
130 return(ret);
131 }
132#endif
133
134int SSL_use_certificate_ASN1(SSL *ssl, unsigned char *d, int len)
135 {
136 X509 *x;
137 int ret;
138
139 x=d2i_X509(NULL,&d,(long)len);
140 if (x == NULL)
141 {
142 SSLerr(SSL_F_SSL_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB);
143 return(0);
144 }
145
146 ret=SSL_use_certificate(ssl,x);
147 X509_free(x);
148 return(ret);
149 }
150
151#ifndef NO_RSA
152int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa)
153 {
154 EVP_PKEY *pkey;
155 int ret;
156
157 if (rsa == NULL)
158 {
159 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
160 return(0);
161 }
162 if (!ssl_cert_inst(&ssl->cert))
163 {
164 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE);
165 return(0);
166 }
167 if ((pkey=EVP_PKEY_new()) == NULL)
168 {
169 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB);
170 return(0);
171 }
172
173 CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA);
174 EVP_PKEY_assign_RSA(pkey,rsa);
175
176 ret=ssl_set_pkey(ssl->cert,pkey);
177 EVP_PKEY_free(pkey);
178 return(ret);
179 }
180#endif
181
182static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey)
183 {
184 int i,ok=0,bad=0;
185
186 i=ssl_cert_type(NULL,pkey);
187 if (i < 0)
188 {
189 SSLerr(SSL_F_SSL_SET_PKEY,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
190 return(0);
191 }
192
193 if (c->pkeys[i].x509 != NULL)
194 {
195 EVP_PKEY *pktmp;
196 pktmp = X509_get_pubkey(c->pkeys[i].x509);
197 EVP_PKEY_copy_parameters(pktmp,pkey);
198 EVP_PKEY_free(pktmp);
199 ERR_clear_error();
200
201#ifndef NO_RSA
202 /* Don't check the public/private key, this is mostly
203 * for smart cards. */
204 if ((pkey->type == EVP_PKEY_RSA) &&
205 (RSA_flags(pkey->pkey.rsa) &
206 RSA_METHOD_FLAG_NO_CHECK))
207 ok=1;
208 else
209#endif
210 if (!X509_check_private_key(c->pkeys[i].x509,pkey))
211 {
212 if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA))
213 {
214 i=(i == SSL_PKEY_DH_RSA)?
215 SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA;
216
217 if (c->pkeys[i].x509 == NULL)
218 ok=1;
219 else
220 {
221 if (!X509_check_private_key(
222 c->pkeys[i].x509,pkey))
223 bad=1;
224 else
225 ok=1;
226 }
227 }
228 else
229 bad=1;
230 }
231 else
232 ok=1;
233 }
234 else
235 ok=1;
236
237 if (bad)
238 {
239 X509_free(c->pkeys[i].x509);
240 c->pkeys[i].x509=NULL;
241 return(0);
242 }
243
244 if (c->pkeys[i].privatekey != NULL)
245 EVP_PKEY_free(c->pkeys[i].privatekey);
246 CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
247 c->pkeys[i].privatekey=pkey;
248 c->key= &(c->pkeys[i]);
249
250 c->valid=0;
251 return(1);
252 }
253
254#ifndef NO_RSA
255#ifndef NO_STDIO
256int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type)
257 {
258 int j,ret=0;
259 BIO *in;
260 RSA *rsa=NULL;
261
262 in=BIO_new(BIO_s_file_internal());
263 if (in == NULL)
264 {
265 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB);
266 goto end;
267 }
268
269 if (BIO_read_filename(in,file) <= 0)
270 {
271 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB);
272 goto end;
273 }
274 if (type == SSL_FILETYPE_ASN1)
275 {
276 j=ERR_R_ASN1_LIB;
277 rsa=d2i_RSAPrivateKey_bio(in,NULL);
278 }
279 else if (type == SSL_FILETYPE_PEM)
280 {
281 j=ERR_R_PEM_LIB;
282 rsa=PEM_read_bio_RSAPrivateKey(in,NULL,
283 ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata);
284 }
285 else
286 {
287 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
288 goto end;
289 }
290 if (rsa == NULL)
291 {
292 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_FILE,j);
293 goto end;
294 }
295 ret=SSL_use_RSAPrivateKey(ssl,rsa);
296 RSA_free(rsa);
297end:
298 if (in != NULL) BIO_free(in);
299 return(ret);
300 }
301#endif
302
303int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len)
304 {
305 int ret;
306 unsigned char *p;
307 RSA *rsa;
308
309 p=d;
310 if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL)
311 {
312 SSLerr(SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
313 return(0);
314 }
315
316 ret=SSL_use_RSAPrivateKey(ssl,rsa);
317 RSA_free(rsa);
318 return(ret);
319 }
320#endif /* !NO_RSA */
321
322int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey)
323 {
324 int ret;
325
326 if (pkey == NULL)
327 {
328 SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
329 return(0);
330 }
331 if (!ssl_cert_inst(&ssl->cert))
332 {
333 SSLerr(SSL_F_SSL_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE);
334 return(0);
335 }
336 ret=ssl_set_pkey(ssl->cert,pkey);
337 return(ret);
338 }
339
340#ifndef NO_STDIO
341int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type)
342 {
343 int j,ret=0;
344 BIO *in;
345 EVP_PKEY *pkey=NULL;
346
347 in=BIO_new(BIO_s_file_internal());
348 if (in == NULL)
349 {
350 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB);
351 goto end;
352 }
353
354 if (BIO_read_filename(in,file) <= 0)
355 {
356 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB);
357 goto end;
358 }
359 if (type == SSL_FILETYPE_PEM)
360 {
361 j=ERR_R_PEM_LIB;
362 pkey=PEM_read_bio_PrivateKey(in,NULL,
363 ssl->ctx->default_passwd_callback,ssl->ctx->default_passwd_callback_userdata);
364 }
365 else
366 {
367 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
368 goto end;
369 }
370 if (pkey == NULL)
371 {
372 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_FILE,j);
373 goto end;
374 }
375 ret=SSL_use_PrivateKey(ssl,pkey);
376 EVP_PKEY_free(pkey);
377end:
378 if (in != NULL) BIO_free(in);
379 return(ret);
380 }
381#endif
382
383int SSL_use_PrivateKey_ASN1(int type, SSL *ssl, unsigned char *d, long len)
384 {
385 int ret;
386 unsigned char *p;
387 EVP_PKEY *pkey;
388
389 p=d;
390 if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL)
391 {
392 SSLerr(SSL_F_SSL_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
393 return(0);
394 }
395
396 ret=SSL_use_PrivateKey(ssl,pkey);
397 EVP_PKEY_free(pkey);
398 return(ret);
399 }
400
401int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x)
402 {
403 if (x == NULL)
404 {
405 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_PASSED_NULL_PARAMETER);
406 return(0);
407 }
408 if (!ssl_cert_inst(&ctx->cert))
409 {
410 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE,ERR_R_MALLOC_FAILURE);
411 return(0);
412 }
413 return(ssl_set_cert(ctx->cert, x));
414 }
415
416static int ssl_set_cert(CERT *c, X509 *x)
417 {
418 EVP_PKEY *pkey;
419 int i,ok=0,bad=0;
420
421 pkey=X509_get_pubkey(x);
422 if (pkey == NULL)
423 {
424 SSLerr(SSL_F_SSL_SET_CERT,SSL_R_X509_LIB);
425 return(0);
426 }
427
428 i=ssl_cert_type(x,pkey);
429 if (i < 0)
430 {
431 SSLerr(SSL_F_SSL_SET_CERT,SSL_R_UNKNOWN_CERTIFICATE_TYPE);
432 EVP_PKEY_free(pkey);
433 return(0);
434 }
435
436 if (c->pkeys[i].privatekey != NULL)
437 {
438 EVP_PKEY_copy_parameters(pkey,c->pkeys[i].privatekey);
439 ERR_clear_error();
440
441#ifndef NO_RSA
442 /* Don't check the public/private key, this is mostly
443 * for smart cards. */
444 if ((c->pkeys[i].privatekey->type == EVP_PKEY_RSA) &&
445 (RSA_flags(c->pkeys[i].privatekey->pkey.rsa) &
446 RSA_METHOD_FLAG_NO_CHECK))
447 ok=1;
448 else
449#endif
450 {
451 if (!X509_check_private_key(x,c->pkeys[i].privatekey))
452 {
453 if ((i == SSL_PKEY_DH_RSA) || (i == SSL_PKEY_DH_DSA))
454 {
455 i=(i == SSL_PKEY_DH_RSA)?
456 SSL_PKEY_DH_DSA:SSL_PKEY_DH_RSA;
457
458 if (c->pkeys[i].privatekey == NULL)
459 ok=1;
460 else
461 {
462 if (!X509_check_private_key(x,
463 c->pkeys[i].privatekey))
464 bad=1;
465 else
466 ok=1;
467 }
468 }
469 else
470 bad=1;
471 }
472 else
473 ok=1;
474 } /* NO_RSA */
475 }
476 else
477 ok=1;
478
479 EVP_PKEY_free(pkey);
480 if (bad)
481 {
482 EVP_PKEY_free(c->pkeys[i].privatekey);
483 c->pkeys[i].privatekey=NULL;
484 }
485
486 if (c->pkeys[i].x509 != NULL)
487 X509_free(c->pkeys[i].x509);
488 CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509);
489 c->pkeys[i].x509=x;
490 c->key= &(c->pkeys[i]);
491
492 c->valid=0;
493 return(1);
494 }
495
496#ifndef NO_STDIO
497int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type)
498 {
499 int j;
500 BIO *in;
501 int ret=0;
502 X509 *x=NULL;
503
504 in=BIO_new(BIO_s_file_internal());
505 if (in == NULL)
506 {
507 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_BUF_LIB);
508 goto end;
509 }
510
511 if (BIO_read_filename(in,file) <= 0)
512 {
513 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,ERR_R_SYS_LIB);
514 goto end;
515 }
516 if (type == SSL_FILETYPE_ASN1)
517 {
518 j=ERR_R_ASN1_LIB;
519 x=d2i_X509_bio(in,NULL);
520 }
521 else if (type == SSL_FILETYPE_PEM)
522 {
523 j=ERR_R_PEM_LIB;
524 x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
525 }
526 else
527 {
528 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,SSL_R_BAD_SSL_FILETYPE);
529 goto end;
530 }
531
532 if (x == NULL)
533 {
534 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_FILE,j);
535 goto end;
536 }
537
538 ret=SSL_CTX_use_certificate(ctx,x);
539end:
540 if (x != NULL) X509_free(x);
541 if (in != NULL) BIO_free(in);
542 return(ret);
543 }
544#endif
545
546int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d)
547 {
548 X509 *x;
549 int ret;
550
551 x=d2i_X509(NULL,&d,(long)len);
552 if (x == NULL)
553 {
554 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1,ERR_R_ASN1_LIB);
555 return(0);
556 }
557
558 ret=SSL_CTX_use_certificate(ctx,x);
559 X509_free(x);
560 return(ret);
561 }
562
563#ifndef NO_RSA
564int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa)
565 {
566 int ret;
567 EVP_PKEY *pkey;
568
569 if (rsa == NULL)
570 {
571 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
572 return(0);
573 }
574 if (!ssl_cert_inst(&ctx->cert))
575 {
576 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_MALLOC_FAILURE);
577 return(0);
578 }
579 if ((pkey=EVP_PKEY_new()) == NULL)
580 {
581 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY,ERR_R_EVP_LIB);
582 return(0);
583 }
584
585 CRYPTO_add(&rsa->references,1,CRYPTO_LOCK_RSA);
586 EVP_PKEY_assign_RSA(pkey,rsa);
587
588 ret=ssl_set_pkey(ctx->cert, pkey);
589 EVP_PKEY_free(pkey);
590 return(ret);
591 }
592
593#ifndef NO_STDIO
594int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type)
595 {
596 int j,ret=0;
597 BIO *in;
598 RSA *rsa=NULL;
599
600 in=BIO_new(BIO_s_file_internal());
601 if (in == NULL)
602 {
603 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_BUF_LIB);
604 goto end;
605 }
606
607 if (BIO_read_filename(in,file) <= 0)
608 {
609 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,ERR_R_SYS_LIB);
610 goto end;
611 }
612 if (type == SSL_FILETYPE_ASN1)
613 {
614 j=ERR_R_ASN1_LIB;
615 rsa=d2i_RSAPrivateKey_bio(in,NULL);
616 }
617 else if (type == SSL_FILETYPE_PEM)
618 {
619 j=ERR_R_PEM_LIB;
620 rsa=PEM_read_bio_RSAPrivateKey(in,NULL,
621 ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
622 }
623 else
624 {
625 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
626 goto end;
627 }
628 if (rsa == NULL)
629 {
630 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE,j);
631 goto end;
632 }
633 ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa);
634 RSA_free(rsa);
635end:
636 if (in != NULL) BIO_free(in);
637 return(ret);
638 }
639#endif
640
641int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len)
642 {
643 int ret;
644 unsigned char *p;
645 RSA *rsa;
646
647 p=d;
648 if ((rsa=d2i_RSAPrivateKey(NULL,&p,(long)len)) == NULL)
649 {
650 SSLerr(SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
651 return(0);
652 }
653
654 ret=SSL_CTX_use_RSAPrivateKey(ctx,rsa);
655 RSA_free(rsa);
656 return(ret);
657 }
658#endif /* !NO_RSA */
659
660int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey)
661 {
662 if (pkey == NULL)
663 {
664 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_PASSED_NULL_PARAMETER);
665 return(0);
666 }
667 if (!ssl_cert_inst(&ctx->cert))
668 {
669 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY,ERR_R_MALLOC_FAILURE);
670 return(0);
671 }
672 return(ssl_set_pkey(ctx->cert,pkey));
673 }
674
675#ifndef NO_STDIO
676int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type)
677 {
678 int j,ret=0;
679 BIO *in;
680 EVP_PKEY *pkey=NULL;
681
682 in=BIO_new(BIO_s_file_internal());
683 if (in == NULL)
684 {
685 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_BUF_LIB);
686 goto end;
687 }
688
689 if (BIO_read_filename(in,file) <= 0)
690 {
691 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,ERR_R_SYS_LIB);
692 goto end;
693 }
694 if (type == SSL_FILETYPE_PEM)
695 {
696 j=ERR_R_PEM_LIB;
697 pkey=PEM_read_bio_PrivateKey(in,NULL,
698 ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
699 }
700 else
701 {
702 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,SSL_R_BAD_SSL_FILETYPE);
703 goto end;
704 }
705 if (pkey == NULL)
706 {
707 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE,j);
708 goto end;
709 }
710 ret=SSL_CTX_use_PrivateKey(ctx,pkey);
711 EVP_PKEY_free(pkey);
712end:
713 if (in != NULL) BIO_free(in);
714 return(ret);
715 }
716#endif
717
718int SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, unsigned char *d,
719 long len)
720 {
721 int ret;
722 unsigned char *p;
723 EVP_PKEY *pkey;
724
725 p=d;
726 if ((pkey=d2i_PrivateKey(type,NULL,&p,(long)len)) == NULL)
727 {
728 SSLerr(SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1,ERR_R_ASN1_LIB);
729 return(0);
730 }
731
732 ret=SSL_CTX_use_PrivateKey(ctx,pkey);
733 EVP_PKEY_free(pkey);
734 return(ret);
735 }
736
737
738#ifndef NO_STDIO
739/* Read a file that contains our certificate in "PEM" format,
740 * possibly followed by a sequence of CA certificates that should be
741 * sent to the peer in the Certificate message.
742 */
743int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file)
744 {
745 BIO *in;
746 int ret=0;
747 X509 *x=NULL;
748
749 in=BIO_new(BIO_s_file_internal());
750 if (in == NULL)
751 {
752 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_BUF_LIB);
753 goto end;
754 }
755
756 if (BIO_read_filename(in,file) <= 0)
757 {
758 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_SYS_LIB);
759 goto end;
760 }
761
762 x=PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata);
763 if (x == NULL)
764 {
765 SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE,ERR_R_PEM_LIB);
766 goto end;
767 }
768
769 ret=SSL_CTX_use_certificate(ctx,x);
770 if (ERR_peek_error() != 0)
771 ret = 0; /* Key/certificate mismatch doesn't imply ret==0 ... */
772 if (ret)
773 {
774 /* If we could set up our certificate, now proceed to
775 * the CA certificates.
776 */
777 X509 *ca;
778 int r;
779 unsigned long err;
780
781 if (ctx->extra_certs != NULL)
782 {
783 sk_X509_pop_free(ctx->extra_certs, X509_free);
784 ctx->extra_certs = NULL;
785 }
786
787 while ((ca = PEM_read_bio_X509(in,NULL,ctx->default_passwd_callback,ctx->default_passwd_callback_userdata))
788 != NULL)
789 {
790 r = SSL_CTX_add_extra_chain_cert(ctx, ca);
791 if (!r)
792 {
793 X509_free(ca);
794 ret = 0;
795 goto end;
796 }
797 /* Note that we must not free r if it was successfully
798 * added to the chain (while we must free the main
799 * certificate, since its reference count is increased
800 * by SSL_CTX_use_certificate). */
801 }
802 /* When the while loop ends, it's usually just EOF. */
803 err = ERR_peek_error();
804 if (ERR_GET_LIB(err) == ERR_LIB_PEM && ERR_GET_REASON(err) == PEM_R_NO_START_LINE)
805 (void) ERR_get_error();
806 else
807 ret = 0; /* some real error */
808 }
809
810end:
811 if (x != NULL) X509_free(x);
812 if (in != NULL) BIO_free(in);
813 return(ret);
814 }
815#endif
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c
deleted file mode 100644
index 9e01f72753..0000000000
--- a/src/lib/libssl/ssl_sess.c
+++ /dev/null
@@ -1,680 +0,0 @@
1/* ssl/ssl_sess.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#include <stdio.h>
60#include <openssl/lhash.h>
61#include <openssl/rand.h>
62#include "ssl_locl.h"
63
64static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s);
65static void SSL_SESSION_list_add(SSL_CTX *ctx,SSL_SESSION *s);
66static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck);
67static int ssl_session_num=0;
68static STACK_OF(CRYPTO_EX_DATA_FUNCS) *ssl_session_meth=NULL;
69
70SSL_SESSION *SSL_get_session(SSL *ssl)
71/* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */
72 {
73 return(ssl->session);
74 }
75
76SSL_SESSION *SSL_get1_session(SSL *ssl)
77/* variant of SSL_get_session: caller really gets something */
78 {
79 SSL_SESSION *sess;
80 /* Need to lock this all up rather than just use CRYPTO_add so that
81 * somebody doesn't free ssl->session between when we check it's
82 * non-null and when we up the reference count. */
83 CRYPTO_r_lock(CRYPTO_LOCK_SSL_SESSION);
84 sess = ssl->session;
85 if(sess)
86 sess->references++;
87 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_SESSION);
88 return(sess);
89 }
90
91int SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
92 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
93 {
94 ssl_session_num++;
95 return(CRYPTO_get_ex_new_index(ssl_session_num-1,
96 &ssl_session_meth,
97 argl,argp,new_func,dup_func,free_func));
98 }
99
100int SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg)
101 {
102 return(CRYPTO_set_ex_data(&s->ex_data,idx,arg));
103 }
104
105void *SSL_SESSION_get_ex_data(SSL_SESSION *s, int idx)
106 {
107 return(CRYPTO_get_ex_data(&s->ex_data,idx));
108 }
109
110SSL_SESSION *SSL_SESSION_new(void)
111 {
112 SSL_SESSION *ss;
113
114 ss=(SSL_SESSION *)Malloc(sizeof(SSL_SESSION));
115 if (ss == NULL)
116 {
117 SSLerr(SSL_F_SSL_SESSION_NEW,ERR_R_MALLOC_FAILURE);
118 return(0);
119 }
120 memset(ss,0,sizeof(SSL_SESSION));
121
122 ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */
123 ss->references=1;
124 ss->timeout=60*5+4; /* 5 minute timeout by default */
125 ss->time=time(NULL);
126 ss->prev=NULL;
127 ss->next=NULL;
128 ss->compress_meth=0;
129 CRYPTO_new_ex_data(ssl_session_meth,ss,&ss->ex_data);
130 return(ss);
131 }
132
133int ssl_get_new_session(SSL *s, int session)
134 {
135 /* This gets used by clients and servers. */
136
137 SSL_SESSION *ss=NULL;
138
139 if ((ss=SSL_SESSION_new()) == NULL) return(0);
140
141 /* If the context has a default timeout, use it */
142 if (s->ctx->session_timeout == 0)
143 ss->timeout=SSL_get_default_timeout(s);
144 else
145 ss->timeout=s->ctx->session_timeout;
146
147 if (s->session != NULL)
148 {
149 SSL_SESSION_free(s->session);
150 s->session=NULL;
151 }
152
153 if (session)
154 {
155 if (s->version == SSL2_VERSION)
156 {
157 ss->ssl_version=SSL2_VERSION;
158 ss->session_id_length=SSL2_SSL_SESSION_ID_LENGTH;
159 }
160 else if (s->version == SSL3_VERSION)
161 {
162 ss->ssl_version=SSL3_VERSION;
163 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
164 }
165 else if (s->version == TLS1_VERSION)
166 {
167 ss->ssl_version=TLS1_VERSION;
168 ss->session_id_length=SSL3_SSL_SESSION_ID_LENGTH;
169 }
170 else
171 {
172 SSLerr(SSL_F_SSL_GET_NEW_SESSION,SSL_R_UNSUPPORTED_SSL_VERSION);
173 SSL_SESSION_free(ss);
174 return(0);
175 }
176
177 for (;;)
178 {
179 SSL_SESSION *r;
180
181 RAND_pseudo_bytes(ss->session_id,ss->session_id_length);
182 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
183 r=(SSL_SESSION *)lh_retrieve(s->ctx->sessions, ss);
184 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
185 if (r == NULL) break;
186 /* else - woops a session_id match */
187 /* XXX We should also check the external cache --
188 * but the probability of a collision is negligible, and
189 * we could not prevent the concurrent creation of sessions
190 * with identical IDs since we currently don't have means
191 * to atomically check whether a session ID already exists
192 * and make a reservation for it if it does not
193 * (this problem applies to the internal cache as well).
194 */
195 }
196 }
197 else
198 {
199 ss->session_id_length=0;
200 }
201
202 memcpy(ss->sid_ctx,s->sid_ctx,s->sid_ctx_length);
203 ss->sid_ctx_length=s->sid_ctx_length;
204 s->session=ss;
205 ss->ssl_version=s->version;
206 ss->verify_result = X509_V_OK;
207
208 return(1);
209 }
210
211int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len)
212 {
213 /* This is used only by servers. */
214
215 SSL_SESSION *ret=NULL,data;
216 int fatal = 0;
217
218 data.ssl_version=s->version;
219 data.session_id_length=len;
220 if (len > SSL_MAX_SSL_SESSION_ID_LENGTH)
221 goto err;
222 memcpy(data.session_id,session_id,len);
223
224 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))
225 {
226 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
227 ret=(SSL_SESSION *)lh_retrieve(s->ctx->sessions,&data);
228 if (ret != NULL)
229 /* don't allow other threads to steal it: */
230 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
231 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
232 }
233
234 if (ret == NULL)
235 {
236 int copy=1;
237
238 s->ctx->stats.sess_miss++;
239 ret=NULL;
240 if (s->ctx->get_session_cb != NULL
241 && (ret=s->ctx->get_session_cb(s,session_id,len,&copy))
242 != NULL)
243 {
244 s->ctx->stats.sess_cb_hit++;
245
246 /* Increment reference count now if the session callback
247 * asks us to do so (note that if the session structures
248 * returned by the callback are shared between threads,
249 * it must handle the reference count itself [i.e. copy == 0],
250 * or things won't be thread-safe). */
251 if (copy)
252 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
253
254 /* The following should not return 1, otherwise,
255 * things are very strange */
256 SSL_CTX_add_session(s->ctx,ret);
257 }
258 if (ret == NULL)
259 goto err;
260 }
261
262 /* Now ret is non-NULL, and we own one of its reference counts. */
263
264 if((s->verify_mode&SSL_VERIFY_PEER)
265 && (!s->sid_ctx_length || ret->sid_ctx_length != s->sid_ctx_length
266 || memcmp(ret->sid_ctx,s->sid_ctx,ret->sid_ctx_length)))
267 {
268 /* We've found the session named by the client, but we don't
269 * want to use it in this context. */
270
271 if (s->sid_ctx_length == 0)
272 {
273 /* application should have used SSL[_CTX]_set_session_id_context
274 * -- we could tolerate this and just pretend we never heard
275 * of this session, but then applications could effectively
276 * disable the session cache by accident without anyone noticing */
277
278 SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);
279 fatal = 1;
280 goto err;
281 }
282 else
283 {
284#if 0 /* The client cannot always know when a session is not appropriate,
285 * so we shouldn't generate an error message. */
286
287 SSLerr(SSL_F_SSL_GET_PREV_SESSION,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
288#endif
289 goto err; /* treat like cache miss */
290 }
291 }
292
293 if (ret->cipher == NULL)
294 {
295 unsigned char buf[5],*p;
296 unsigned long l;
297
298 p=buf;
299 l=ret->cipher_id;
300 l2n(l,p);
301 if ((ret->ssl_version>>8) == SSL3_VERSION_MAJOR)
302 ret->cipher=ssl_get_cipher_by_char(s,&(buf[2]));
303 else
304 ret->cipher=ssl_get_cipher_by_char(s,&(buf[1]));
305 if (ret->cipher == NULL)
306 goto err;
307 }
308
309
310#if 0 /* This is way too late. */
311
312 /* If a thread got the session, then 'swaped', and another got
313 * it and then due to a time-out decided to 'Free' it we could
314 * be in trouble. So I'll increment it now, then double decrement
315 * later - am I speaking rubbish?. */
316 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION);
317#endif
318
319 if ((long)(ret->time+ret->timeout) < (long)time(NULL)) /* timeout */
320 {
321 s->ctx->stats.sess_timeout++;
322 /* remove it from the cache */
323 SSL_CTX_remove_session(s->ctx,ret);
324 goto err;
325 }
326
327 s->ctx->stats.sess_hit++;
328
329 /* ret->time=time(NULL); */ /* rezero timeout? */
330 /* again, just leave the session
331 * if it is the same session, we have just incremented and
332 * then decremented the reference count :-) */
333 if (s->session != NULL)
334 SSL_SESSION_free(s->session);
335 s->session=ret;
336 s->verify_result = s->session->verify_result;
337 return(1);
338
339 err:
340 if (ret != NULL)
341 SSL_SESSION_free(ret);
342 if (fatal)
343 return -1;
344 else
345 return 0;
346 }
347
348int SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
349 {
350 int ret=0;
351 SSL_SESSION *s;
352
353 /* add just 1 reference count for the SSL_CTX's session cache
354 * even though it has two ways of access: each session is in a
355 * doubly linked list and an lhash */
356 CRYPTO_add(&c->references,1,CRYPTO_LOCK_SSL_SESSION);
357 /* if session c is in already in cache, we take back the increment later */
358
359 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
360 s=(SSL_SESSION *)lh_insert(ctx->sessions,c);
361
362 /* s != NULL iff we already had a session with the given PID.
363 * In this case, s == c should hold (then we did not really modify
364 * ctx->sessions), or we're in trouble. */
365 if (s != NULL && s != c)
366 {
367 /* We *are* in trouble ... */
368 SSL_SESSION_list_remove(ctx,s);
369 SSL_SESSION_free(s);
370 /* ... so pretend the other session did not exist in cache
371 * (we cannot handle two SSL_SESSION structures with identical
372 * session ID in the same cache, which could happen e.g. when
373 * two threads concurrently obtain the same session from an external
374 * cache) */
375 s = NULL;
376 }
377
378 /* Put at the head of the queue unless it is already in the cache */
379 if (s == NULL)
380 SSL_SESSION_list_add(ctx,c);
381
382 if (s != NULL)
383 {
384 /* existing cache entry -- decrement previously incremented reference
385 * count because it already takes into account the cache */
386
387 SSL_SESSION_free(s); /* s == c */
388 ret=0;
389 }
390 else
391 {
392 /* new cache entry -- remove old ones if cache has become too large */
393
394 ret=1;
395
396 if (SSL_CTX_sess_get_cache_size(ctx) > 0)
397 {
398 while (SSL_CTX_sess_number(ctx) >
399 SSL_CTX_sess_get_cache_size(ctx))
400 {
401 if (!remove_session_lock(ctx,
402 ctx->session_cache_tail, 0))
403 break;
404 else
405 ctx->stats.sess_cache_full++;
406 }
407 }
408 }
409 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
410 return(ret);
411 }
412
413int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
414{
415 return remove_session_lock(ctx, c, 1);
416}
417
418static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
419 {
420 SSL_SESSION *r;
421 int ret=0;
422
423 if ((c != NULL) && (c->session_id_length != 0))
424 {
425 if(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
426 r=(SSL_SESSION *)lh_delete(ctx->sessions,c);
427 if (r != NULL)
428 {
429 ret=1;
430 SSL_SESSION_list_remove(ctx,c);
431 }
432
433 if(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
434
435 if (ret)
436 {
437 r->not_resumable=1;
438 if (ctx->remove_session_cb != NULL)
439 ctx->remove_session_cb(ctx,r);
440 SSL_SESSION_free(r);
441 }
442 }
443 else
444 ret=0;
445 return(ret);
446 }
447
448void SSL_SESSION_free(SSL_SESSION *ss)
449 {
450 int i;
451
452 if(ss == NULL)
453 return;
454
455 i=CRYPTO_add(&ss->references,-1,CRYPTO_LOCK_SSL_SESSION);
456#ifdef REF_PRINT
457 REF_PRINT("SSL_SESSION",ss);
458#endif
459 if (i > 0) return;
460#ifdef REF_CHECK
461 if (i < 0)
462 {
463 fprintf(stderr,"SSL_SESSION_free, bad reference count\n");
464 abort(); /* ok */
465 }
466#endif
467
468 CRYPTO_free_ex_data(ssl_session_meth,ss,&ss->ex_data);
469
470 memset(ss->key_arg,0,SSL_MAX_KEY_ARG_LENGTH);
471 memset(ss->master_key,0,SSL_MAX_MASTER_KEY_LENGTH);
472 memset(ss->session_id,0,SSL_MAX_SSL_SESSION_ID_LENGTH);
473 if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert);
474 if (ss->peer != NULL) X509_free(ss->peer);
475 if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers);
476 memset(ss,0,sizeof(*ss));
477 Free(ss);
478 }
479
480int SSL_set_session(SSL *s, SSL_SESSION *session)
481 {
482 int ret=0;
483 SSL_METHOD *meth;
484
485 if (session != NULL)
486 {
487 meth=s->ctx->method->get_ssl_method(session->ssl_version);
488 if (meth == NULL)
489 meth=s->method->get_ssl_method(session->ssl_version);
490 if (meth == NULL)
491 {
492 SSLerr(SSL_F_SSL_SET_SESSION,SSL_R_UNABLE_TO_FIND_SSL_METHOD);
493 return(0);
494 }
495
496 if (meth != s->method)
497 {
498 if (!SSL_set_ssl_method(s,meth))
499 return(0);
500 if (s->ctx->session_timeout == 0)
501 session->timeout=SSL_get_default_timeout(s);
502 else
503 session->timeout=s->ctx->session_timeout;
504 }
505
506 /* CRYPTO_w_lock(CRYPTO_LOCK_SSL);*/
507 CRYPTO_add(&session->references,1,CRYPTO_LOCK_SSL_SESSION);
508 if (s->session != NULL)
509 SSL_SESSION_free(s->session);
510 s->session=session;
511 /* CRYPTO_w_unlock(CRYPTO_LOCK_SSL);*/
512 ret=1;
513 }
514 else
515 {
516 if (s->session != NULL)
517 {
518 SSL_SESSION_free(s->session);
519 s->session=NULL;
520 }
521
522 meth=s->ctx->method;
523 if (meth != s->method)
524 {
525 if (!SSL_set_ssl_method(s,meth))
526 return(0);
527 }
528 ret=1;
529 }
530 return(ret);
531 }
532
533long SSL_SESSION_set_timeout(SSL_SESSION *s, long t)
534 {
535 if (s == NULL) return(0);
536 s->timeout=t;
537 return(1);
538 }
539
540long SSL_SESSION_get_timeout(SSL_SESSION *s)
541 {
542 if (s == NULL) return(0);
543 return(s->timeout);
544 }
545
546long SSL_SESSION_get_time(SSL_SESSION *s)
547 {
548 if (s == NULL) return(0);
549 return(s->time);
550 }
551
552long SSL_SESSION_set_time(SSL_SESSION *s, long t)
553 {
554 if (s == NULL) return(0);
555 s->time=t;
556 return(t);
557 }
558
559long SSL_CTX_set_timeout(SSL_CTX *s, long t)
560 {
561 long l;
562 if (s == NULL) return(0);
563 l=s->session_timeout;
564 s->session_timeout=t;
565 return(l);
566 }
567
568long SSL_CTX_get_timeout(SSL_CTX *s)
569 {
570 if (s == NULL) return(0);
571 return(s->session_timeout);
572 }
573
574typedef struct timeout_param_st
575 {
576 SSL_CTX *ctx;
577 long time;
578 LHASH *cache;
579 } TIMEOUT_PARAM;
580
581static void timeout(SSL_SESSION *s, TIMEOUT_PARAM *p)
582 {
583 if ((p->time == 0) || (p->time > (s->time+s->timeout))) /* timeout */
584 {
585 /* The reason we don't call SSL_CTX_remove_session() is to
586 * save on locking overhead */
587 lh_delete(p->cache,s);
588 SSL_SESSION_list_remove(p->ctx,s);
589 s->not_resumable=1;
590 if (p->ctx->remove_session_cb != NULL)
591 p->ctx->remove_session_cb(p->ctx,s);
592 SSL_SESSION_free(s);
593 }
594 }
595
596void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
597 {
598 unsigned long i;
599 TIMEOUT_PARAM tp;
600
601 tp.ctx=s;
602 tp.cache=s->sessions;
603 if (tp.cache == NULL) return;
604 tp.time=t;
605 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
606 i=tp.cache->down_load;
607 tp.cache->down_load=0;
608 lh_doall_arg(tp.cache,(void (*)())timeout,&tp);
609 tp.cache->down_load=i;
610 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
611 }
612
613int ssl_clear_bad_session(SSL *s)
614 {
615 if ( (s->session != NULL) &&
616 !(s->shutdown & SSL_SENT_SHUTDOWN) &&
617 !(SSL_in_init(s) || SSL_in_before(s)))
618 {
619 SSL_CTX_remove_session(s->ctx,s->session);
620 return(1);
621 }
622 else
623 return(0);
624 }
625
626/* locked by SSL_CTX in the calling function */
627static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s)
628 {
629 if ((s->next == NULL) || (s->prev == NULL)) return;
630
631 if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail))
632 { /* last element in list */
633 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
634 { /* only one element in list */
635 ctx->session_cache_head=NULL;
636 ctx->session_cache_tail=NULL;
637 }
638 else
639 {
640 ctx->session_cache_tail=s->prev;
641 s->prev->next=(SSL_SESSION *)&(ctx->session_cache_tail);
642 }
643 }
644 else
645 {
646 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head))
647 { /* first element in list */
648 ctx->session_cache_head=s->next;
649 s->next->prev=(SSL_SESSION *)&(ctx->session_cache_head);
650 }
651 else
652 { /* middle of list */
653 s->next->prev=s->prev;
654 s->prev->next=s->next;
655 }
656 }
657 s->prev=s->next=NULL;
658 }
659
660static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s)
661 {
662 if ((s->next != NULL) && (s->prev != NULL))
663 SSL_SESSION_list_remove(ctx,s);
664
665 if (ctx->session_cache_head == NULL)
666 {
667 ctx->session_cache_head=s;
668 ctx->session_cache_tail=s;
669 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
670 s->next=(SSL_SESSION *)&(ctx->session_cache_tail);
671 }
672 else
673 {
674 s->next=ctx->session_cache_head;
675 s->next->prev=s;
676 s->prev=(SSL_SESSION *)&(ctx->session_cache_head);
677 ctx->session_cache_head=s;
678 }
679 }
680
diff --git a/src/lib/libssl/ssl_stat.c b/src/lib/libssl/ssl_stat.c
deleted file mode 100644
index 8e12461f3b..0000000000
--- a/src/lib/libssl/ssl_stat.c
+++ /dev/null
@@ -1,454 +0,0 @@
1/* ssl/ssl_stat.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#include <stdio.h>
60#include "ssl_locl.h"
61
62char *SSL_state_string_long(SSL *s)
63 {
64 char *str;
65
66 switch (s->state)
67 {
68case SSL_ST_BEFORE: str="before SSL initialization"; break;
69case SSL_ST_ACCEPT: str="before accept initialization"; break;
70case SSL_ST_CONNECT: str="before connect initialization"; break;
71case SSL_ST_OK: str="SSL negotiation finished successfully"; break;
72case SSL_ST_RENEGOTIATE: str="SSL renegotiate ciphers"; break;
73case SSL_ST_BEFORE|SSL_ST_CONNECT: str="before/connect initialization"; break;
74case SSL_ST_OK|SSL_ST_CONNECT: str="ok/connect SSL initialization"; break;
75case SSL_ST_BEFORE|SSL_ST_ACCEPT: str="before/accept initialization"; break;
76case SSL_ST_OK|SSL_ST_ACCEPT: str="ok/accept SSL initialization"; break;
77#ifndef NO_SSL2
78case SSL2_ST_CLIENT_START_ENCRYPTION: str="SSLv2 client start encryption"; break;
79case SSL2_ST_SERVER_START_ENCRYPTION: str="SSLv2 server start encryption"; break;
80case SSL2_ST_SEND_CLIENT_HELLO_A: str="SSLv2 write client hello A"; break;
81case SSL2_ST_SEND_CLIENT_HELLO_B: str="SSLv2 write client hello B"; break;
82case SSL2_ST_GET_SERVER_HELLO_A: str="SSLv2 read server hello A"; break;
83case SSL2_ST_GET_SERVER_HELLO_B: str="SSLv2 read server hello B"; break;
84case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="SSLv2 write client master key A"; break;
85case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="SSLv2 write client master key B"; break;
86case SSL2_ST_SEND_CLIENT_FINISHED_A: str="SSLv2 write client finished A"; break;
87case SSL2_ST_SEND_CLIENT_FINISHED_B: str="SSLv2 write client finished B"; break;
88case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="SSLv2 write client certificate A"; break;
89case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="SSLv2 write client certificate B"; break;
90case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="SSLv2 write client certificate C"; break;
91case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="SSLv2 write client certificate D"; break;
92case SSL2_ST_GET_SERVER_VERIFY_A: str="SSLv2 read server verify A"; break;
93case SSL2_ST_GET_SERVER_VERIFY_B: str="SSLv2 read server verify B"; break;
94case SSL2_ST_GET_SERVER_FINISHED_A: str="SSLv2 read server finished A"; break;
95case SSL2_ST_GET_SERVER_FINISHED_B: str="SSLv2 read server finished B"; break;
96case SSL2_ST_GET_CLIENT_HELLO_A: str="SSLv2 read client hello A"; break;
97case SSL2_ST_GET_CLIENT_HELLO_B: str="SSLv2 read client hello B"; break;
98case SSL2_ST_GET_CLIENT_HELLO_C: str="SSLv2 read client hello C"; break;
99case SSL2_ST_SEND_SERVER_HELLO_A: str="SSLv2 write server hello A"; break;
100case SSL2_ST_SEND_SERVER_HELLO_B: str="SSLv2 write server hello B"; break;
101case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="SSLv2 read client master key A"; break;
102case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="SSLv2 read client master key B"; break;
103case SSL2_ST_SEND_SERVER_VERIFY_A: str="SSLv2 write server verify A"; break;
104case SSL2_ST_SEND_SERVER_VERIFY_B: str="SSLv2 write server verify B"; break;
105case SSL2_ST_SEND_SERVER_VERIFY_C: str="SSLv2 write server verify C"; break;
106case SSL2_ST_GET_CLIENT_FINISHED_A: str="SSLv2 read client finished A"; break;
107case SSL2_ST_GET_CLIENT_FINISHED_B: str="SSLv2 read client finished B"; break;
108case SSL2_ST_SEND_SERVER_FINISHED_A: str="SSLv2 write server finished A"; break;
109case SSL2_ST_SEND_SERVER_FINISHED_B: str="SSLv2 write server finished B"; break;
110case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="SSLv2 write request certificate A"; break;
111case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="SSLv2 write request certificate B"; break;
112case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="SSLv2 write request certificate C"; break;
113case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="SSLv2 write request certificate D"; break;
114case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="SSLv2 X509 read server certificate"; break;
115case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="SSLv2 X509 read client certificate"; break;
116#endif
117
118#ifndef NO_SSL3
119/* SSLv3 additions */
120case SSL3_ST_CW_CLNT_HELLO_A: str="SSLv3 write client hello A"; break;
121case SSL3_ST_CW_CLNT_HELLO_B: str="SSLv3 write client hello B"; break;
122case SSL3_ST_CR_SRVR_HELLO_A: str="SSLv3 read server hello A"; break;
123case SSL3_ST_CR_SRVR_HELLO_B: str="SSLv3 read server hello B"; break;
124case SSL3_ST_CR_CERT_A: str="SSLv3 read server certificate A"; break;
125case SSL3_ST_CR_CERT_B: str="SSLv3 read server certificate B"; break;
126case SSL3_ST_CR_KEY_EXCH_A: str="SSLv3 read server key exchange A"; break;
127case SSL3_ST_CR_KEY_EXCH_B: str="SSLv3 read server key exchange B"; break;
128case SSL3_ST_CR_CERT_REQ_A: str="SSLv3 read server certificate request A"; break;
129case SSL3_ST_CR_CERT_REQ_B: str="SSLv3 read server certificate request B"; break;
130case SSL3_ST_CR_SRVR_DONE_A: str="SSLv3 read server done A"; break;
131case SSL3_ST_CR_SRVR_DONE_B: str="SSLv3 read server done B"; break;
132case SSL3_ST_CW_CERT_A: str="SSLv3 write client certificate A"; break;
133case SSL3_ST_CW_CERT_B: str="SSLv3 write client certificate B"; break;
134case SSL3_ST_CW_CERT_C: str="SSLv3 write client certificate C"; break;
135case SSL3_ST_CW_CERT_D: str="SSLv3 write client certificate D"; break;
136case SSL3_ST_CW_KEY_EXCH_A: str="SSLv3 write client key exchange A"; break;
137case SSL3_ST_CW_KEY_EXCH_B: str="SSLv3 write client key exchange B"; break;
138case SSL3_ST_CW_CERT_VRFY_A: str="SSLv3 write certificate verify A"; break;
139case SSL3_ST_CW_CERT_VRFY_B: str="SSLv3 write certificate verify A"; break;
140
141case SSL3_ST_CW_CHANGE_A:
142case SSL3_ST_SW_CHANGE_A: str="SSLv3 write change cipher spec A"; break;
143case SSL3_ST_CW_CHANGE_B:
144case SSL3_ST_SW_CHANGE_B: str="SSLv3 write change cipher spec B"; break;
145case SSL3_ST_CW_FINISHED_A:
146case SSL3_ST_SW_FINISHED_A: str="SSLv3 write finished A"; break;
147case SSL3_ST_CW_FINISHED_B:
148case SSL3_ST_SW_FINISHED_B: str="SSLv3 write finished A"; break;
149case SSL3_ST_CR_CHANGE_A:
150case SSL3_ST_SR_CHANGE_A: str="SSLv3 read change cipher spec A"; break;
151case SSL3_ST_CR_CHANGE_B:
152case SSL3_ST_SR_CHANGE_B: str="SSLv3 read change cipher spec B"; break;
153case SSL3_ST_CR_FINISHED_A:
154case SSL3_ST_SR_FINISHED_A: str="SSLv3 read finished A"; break;
155case SSL3_ST_CR_FINISHED_B:
156case SSL3_ST_SR_FINISHED_B: str="SSLv3 read finished B"; break;
157
158case SSL3_ST_CW_FLUSH:
159case SSL3_ST_SW_FLUSH: str="SSLv3 flush data"; break;
160
161case SSL3_ST_SR_CLNT_HELLO_A: str="SSLv3 read client hello A"; break;
162case SSL3_ST_SR_CLNT_HELLO_B: str="SSLv3 read client hello B"; break;
163case SSL3_ST_SR_CLNT_HELLO_C: str="SSLv3 read client hello C"; break;
164case SSL3_ST_SW_HELLO_REQ_A: str="SSLv3 write hello request A"; break;
165case SSL3_ST_SW_HELLO_REQ_B: str="SSLv3 write hello request B"; break;
166case SSL3_ST_SW_HELLO_REQ_C: str="SSLv3 write hello request C"; break;
167case SSL3_ST_SW_SRVR_HELLO_A: str="SSLv3 write server hello A"; break;
168case SSL3_ST_SW_SRVR_HELLO_B: str="SSLv3 write server hello B"; break;
169case SSL3_ST_SW_CERT_A: str="SSLv3 write certificate A"; break;
170case SSL3_ST_SW_CERT_B: str="SSLv3 write certificate B"; break;
171case SSL3_ST_SW_KEY_EXCH_A: str="SSLv3 write key exchange A"; break;
172case SSL3_ST_SW_KEY_EXCH_B: str="SSLv3 write key exchange B"; break;
173case SSL3_ST_SW_CERT_REQ_A: str="SSLv3 write certificate request A"; break;
174case SSL3_ST_SW_CERT_REQ_B: str="SSLv3 write certificate request B"; break;
175case SSL3_ST_SW_SRVR_DONE_A: str="SSLv3 write server done A"; break;
176case SSL3_ST_SW_SRVR_DONE_B: str="SSLv3 write server done B"; break;
177case SSL3_ST_SR_CERT_A: str="SSLv3 read client certificate A"; break;
178case SSL3_ST_SR_CERT_B: str="SSLv3 read client certificate B"; break;
179case SSL3_ST_SR_KEY_EXCH_A: str="SSLv3 read client key exchange A"; break;
180case SSL3_ST_SR_KEY_EXCH_B: str="SSLv3 read client key exchange B"; break;
181case SSL3_ST_SR_CERT_VRFY_A: str="SSLv3 read certificate verify A"; break;
182case SSL3_ST_SR_CERT_VRFY_B: str="SSLv3 read certificate verify B"; break;
183#endif
184
185#if !defined(NO_SSL2) && !defined(NO_SSL3)
186/* SSLv2/v3 compatibility states */
187/* client */
188case SSL23_ST_CW_CLNT_HELLO_A: str="SSLv2/v3 write client hello A"; break;
189case SSL23_ST_CW_CLNT_HELLO_B: str="SSLv2/v3 write client hello B"; break;
190case SSL23_ST_CR_SRVR_HELLO_A: str="SSLv2/v3 read server hello A"; break;
191case SSL23_ST_CR_SRVR_HELLO_B: str="SSLv2/v3 read server hello B"; break;
192/* server */
193case SSL23_ST_SR_CLNT_HELLO_A: str="SSLv2/v3 read client hello A"; break;
194case SSL23_ST_SR_CLNT_HELLO_B: str="SSLv2/v3 read client hello B"; break;
195#endif
196
197default: str="unknown state"; break;
198 }
199 return(str);
200 }
201
202char *SSL_rstate_string_long(SSL *s)
203 {
204 char *str;
205
206 switch (s->rstate)
207 {
208 case SSL_ST_READ_HEADER: str="read header"; break;
209 case SSL_ST_READ_BODY: str="read body"; break;
210 case SSL_ST_READ_DONE: str="read done"; break;
211 default: str="unknown"; break;
212 }
213 return(str);
214 }
215
216char *SSL_state_string(SSL *s)
217 {
218 char *str;
219
220 switch (s->state)
221 {
222case SSL_ST_BEFORE: str="PINIT "; break;
223case SSL_ST_ACCEPT: str="AINIT "; break;
224case SSL_ST_CONNECT: str="CINIT "; break;
225case SSL_ST_OK: str="SSLOK "; break;
226#ifndef NO_SSL2
227case SSL2_ST_CLIENT_START_ENCRYPTION: str="2CSENC"; break;
228case SSL2_ST_SERVER_START_ENCRYPTION: str="2SSENC"; break;
229case SSL2_ST_SEND_CLIENT_HELLO_A: str="2SCH_A"; break;
230case SSL2_ST_SEND_CLIENT_HELLO_B: str="2SCH_B"; break;
231case SSL2_ST_GET_SERVER_HELLO_A: str="2GSH_A"; break;
232case SSL2_ST_GET_SERVER_HELLO_B: str="2GSH_B"; break;
233case SSL2_ST_SEND_CLIENT_MASTER_KEY_A: str="2SCMKA"; break;
234case SSL2_ST_SEND_CLIENT_MASTER_KEY_B: str="2SCMKB"; break;
235case SSL2_ST_SEND_CLIENT_FINISHED_A: str="2SCF_A"; break;
236case SSL2_ST_SEND_CLIENT_FINISHED_B: str="2SCF_B"; break;
237case SSL2_ST_SEND_CLIENT_CERTIFICATE_A: str="2SCC_A"; break;
238case SSL2_ST_SEND_CLIENT_CERTIFICATE_B: str="2SCC_B"; break;
239case SSL2_ST_SEND_CLIENT_CERTIFICATE_C: str="2SCC_C"; break;
240case SSL2_ST_SEND_CLIENT_CERTIFICATE_D: str="2SCC_D"; break;
241case SSL2_ST_GET_SERVER_VERIFY_A: str="2GSV_A"; break;
242case SSL2_ST_GET_SERVER_VERIFY_B: str="2GSV_B"; break;
243case SSL2_ST_GET_SERVER_FINISHED_A: str="2GSF_A"; break;
244case SSL2_ST_GET_SERVER_FINISHED_B: str="2GSF_B"; break;
245case SSL2_ST_GET_CLIENT_HELLO_A: str="2GCH_A"; break;
246case SSL2_ST_GET_CLIENT_HELLO_B: str="2GCH_B"; break;
247case SSL2_ST_GET_CLIENT_HELLO_C: str="2GCH_C"; break;
248case SSL2_ST_SEND_SERVER_HELLO_A: str="2SSH_A"; break;
249case SSL2_ST_SEND_SERVER_HELLO_B: str="2SSH_B"; break;
250case SSL2_ST_GET_CLIENT_MASTER_KEY_A: str="2GCMKA"; break;
251case SSL2_ST_GET_CLIENT_MASTER_KEY_B: str="2GCMKA"; break;
252case SSL2_ST_SEND_SERVER_VERIFY_A: str="2SSV_A"; break;
253case SSL2_ST_SEND_SERVER_VERIFY_B: str="2SSV_B"; break;
254case SSL2_ST_SEND_SERVER_VERIFY_C: str="2SSV_C"; break;
255case SSL2_ST_GET_CLIENT_FINISHED_A: str="2GCF_A"; break;
256case SSL2_ST_GET_CLIENT_FINISHED_B: str="2GCF_B"; break;
257case SSL2_ST_SEND_SERVER_FINISHED_A: str="2SSF_A"; break;
258case SSL2_ST_SEND_SERVER_FINISHED_B: str="2SSF_B"; break;
259case SSL2_ST_SEND_REQUEST_CERTIFICATE_A: str="2SRC_A"; break;
260case SSL2_ST_SEND_REQUEST_CERTIFICATE_B: str="2SRC_B"; break;
261case SSL2_ST_SEND_REQUEST_CERTIFICATE_C: str="2SRC_C"; break;
262case SSL2_ST_SEND_REQUEST_CERTIFICATE_D: str="2SRC_D"; break;
263case SSL2_ST_X509_GET_SERVER_CERTIFICATE: str="2X9GSC"; break;
264case SSL2_ST_X509_GET_CLIENT_CERTIFICATE: str="2X9GCC"; break;
265#endif
266
267#ifndef NO_SSL3
268/* SSLv3 additions */
269case SSL3_ST_SW_FLUSH:
270case SSL3_ST_CW_FLUSH: str="3FLUSH"; break;
271case SSL3_ST_CW_CLNT_HELLO_A: str="3WCH_A"; break;
272case SSL3_ST_CW_CLNT_HELLO_B: str="3WCH_B"; break;
273case SSL3_ST_CR_SRVR_HELLO_A: str="3RSH_A"; break;
274case SSL3_ST_CR_SRVR_HELLO_B: str="3RSH_B"; break;
275case SSL3_ST_CR_CERT_A: str="3RSC_A"; break;
276case SSL3_ST_CR_CERT_B: str="3RSC_B"; break;
277case SSL3_ST_CR_KEY_EXCH_A: str="3RSKEA"; break;
278case SSL3_ST_CR_KEY_EXCH_B: str="3RSKEB"; break;
279case SSL3_ST_CR_CERT_REQ_A: str="3RCR_A"; break;
280case SSL3_ST_CR_CERT_REQ_B: str="3RCR_B"; break;
281case SSL3_ST_CR_SRVR_DONE_A: str="3RSD_A"; break;
282case SSL3_ST_CR_SRVR_DONE_B: str="3RSD_B"; break;
283case SSL3_ST_CW_CERT_A: str="3WCC_A"; break;
284case SSL3_ST_CW_CERT_B: str="3WCC_B"; break;
285case SSL3_ST_CW_CERT_C: str="3WCC_C"; break;
286case SSL3_ST_CW_CERT_D: str="3WCC_D"; break;
287case SSL3_ST_CW_KEY_EXCH_A: str="3WCKEA"; break;
288case SSL3_ST_CW_KEY_EXCH_B: str="3WCKEB"; break;
289case SSL3_ST_CW_CERT_VRFY_A: str="3WCV_A"; break;
290case SSL3_ST_CW_CERT_VRFY_B: str="3WCV_B"; break;
291
292case SSL3_ST_SW_CHANGE_A:
293case SSL3_ST_CW_CHANGE_A: str="3WCCSA"; break;
294case SSL3_ST_SW_CHANGE_B:
295case SSL3_ST_CW_CHANGE_B: str="3WCCSB"; break;
296case SSL3_ST_SW_FINISHED_A:
297case SSL3_ST_CW_FINISHED_A: str="3WFINA"; break;
298case SSL3_ST_SW_FINISHED_B:
299case SSL3_ST_CW_FINISHED_B: str="3WFINB"; break;
300case SSL3_ST_SR_CHANGE_A:
301case SSL3_ST_CR_CHANGE_A: str="3RCCSA"; break;
302case SSL3_ST_SR_CHANGE_B:
303case SSL3_ST_CR_CHANGE_B: str="3RCCSB"; break;
304case SSL3_ST_SR_FINISHED_A:
305case SSL3_ST_CR_FINISHED_A: str="3RFINA"; break;
306case SSL3_ST_SR_FINISHED_B:
307case SSL3_ST_CR_FINISHED_B: str="3RFINB"; break;
308
309case SSL3_ST_SW_HELLO_REQ_A: str="3WHR_A"; break;
310case SSL3_ST_SW_HELLO_REQ_B: str="3WHR_B"; break;
311case SSL3_ST_SW_HELLO_REQ_C: str="3WHR_C"; break;
312case SSL3_ST_SR_CLNT_HELLO_A: str="3RCH_A"; break;
313case SSL3_ST_SR_CLNT_HELLO_B: str="3RCH_B"; break;
314case SSL3_ST_SR_CLNT_HELLO_C: str="3RCH_C"; break;
315case SSL3_ST_SW_SRVR_HELLO_A: str="3WSH_A"; break;
316case SSL3_ST_SW_SRVR_HELLO_B: str="3WSH_B"; break;
317case SSL3_ST_SW_CERT_A: str="3WSC_A"; break;
318case SSL3_ST_SW_CERT_B: str="3WSC_B"; break;
319case SSL3_ST_SW_KEY_EXCH_A: str="3WSKEA"; break;
320case SSL3_ST_SW_KEY_EXCH_B: str="3WSKEB"; break;
321case SSL3_ST_SW_CERT_REQ_A: str="3WCR_A"; break;
322case SSL3_ST_SW_CERT_REQ_B: str="3WCR_B"; break;
323case SSL3_ST_SW_SRVR_DONE_A: str="3WSD_A"; break;
324case SSL3_ST_SW_SRVR_DONE_B: str="3WSD_B"; break;
325case SSL3_ST_SR_CERT_A: str="3RCC_A"; break;
326case SSL3_ST_SR_CERT_B: str="3RCC_B"; break;
327case SSL3_ST_SR_KEY_EXCH_A: str="3RCKEA"; break;
328case SSL3_ST_SR_KEY_EXCH_B: str="3RCKEB"; break;
329case SSL3_ST_SR_CERT_VRFY_A: str="3RCV_A"; break;
330case SSL3_ST_SR_CERT_VRFY_B: str="3RCV_B"; break;
331#endif
332
333#if !defined(NO_SSL2) && !defined(NO_SSL3)
334/* SSLv2/v3 compatibility states */
335/* client */
336case SSL23_ST_CW_CLNT_HELLO_A: str="23WCHA"; break;
337case SSL23_ST_CW_CLNT_HELLO_B: str="23WCHB"; break;
338case SSL23_ST_CR_SRVR_HELLO_A: str="23RSHA"; break;
339case SSL23_ST_CR_SRVR_HELLO_B: str="23RSHA"; break;
340/* server */
341case SSL23_ST_SR_CLNT_HELLO_A: str="23RCHA"; break;
342case SSL23_ST_SR_CLNT_HELLO_B: str="23RCHB"; break;
343#endif
344
345default: str="UNKWN "; break;
346 }
347 return(str);
348 }
349
350char *SSL_alert_type_string_long(int value)
351 {
352 value>>=8;
353 if (value == SSL3_AL_WARNING)
354 return("warning");
355 else if (value == SSL3_AL_FATAL)
356 return("fatal");
357 else
358 return("unknown");
359 }
360
361char *SSL_alert_type_string(int value)
362 {
363 value>>=8;
364 if (value == SSL3_AL_WARNING)
365 return("W");
366 else if (value == SSL3_AL_FATAL)
367 return("F");
368 else
369 return("U");
370 }
371
372char *SSL_alert_desc_string(int value)
373 {
374 char *str;
375
376 switch (value & 0xff)
377 {
378 case SSL3_AD_CLOSE_NOTIFY: str="CN"; break;
379 case SSL3_AD_UNEXPECTED_MESSAGE: str="UM"; break;
380 case SSL3_AD_BAD_RECORD_MAC: str="BM"; break;
381 case SSL3_AD_DECOMPRESSION_FAILURE: str="DF"; break;
382 case SSL3_AD_HANDSHAKE_FAILURE: str="HF"; break;
383 case SSL3_AD_NO_CERTIFICATE: str="NC"; break;
384 case SSL3_AD_BAD_CERTIFICATE: str="BC"; break;
385 case SSL3_AD_UNSUPPORTED_CERTIFICATE: str="UC"; break;
386 case SSL3_AD_CERTIFICATE_REVOKED: str="CR"; break;
387 case SSL3_AD_CERTIFICATE_EXPIRED: str="CE"; break;
388 case SSL3_AD_CERTIFICATE_UNKNOWN: str="CU"; break;
389 case SSL3_AD_ILLEGAL_PARAMETER: str="IP"; break;
390 default: str="UK"; break;
391 }
392 return(str);
393 }
394
395char *SSL_alert_desc_string_long(int value)
396 {
397 char *str;
398
399 switch (value & 0xff)
400 {
401 case SSL3_AD_CLOSE_NOTIFY:
402 str="close notify";
403 break;
404 case SSL3_AD_UNEXPECTED_MESSAGE:
405 str="unexpected_message";
406 break;
407 case SSL3_AD_BAD_RECORD_MAC:
408 str="bad record mac";
409 break;
410 case SSL3_AD_DECOMPRESSION_FAILURE:
411 str="decompression failure";
412 break;
413 case SSL3_AD_HANDSHAKE_FAILURE:
414 str="handshake failure";
415 break;
416 case SSL3_AD_NO_CERTIFICATE:
417 str="no certificate";
418 break;
419 case SSL3_AD_BAD_CERTIFICATE:
420 str="bad certificate";
421 break;
422 case SSL3_AD_UNSUPPORTED_CERTIFICATE:
423 str="unsupported certificate";
424 break;
425 case SSL3_AD_CERTIFICATE_REVOKED:
426 str="certificate revoked";
427 break;
428 case SSL3_AD_CERTIFICATE_EXPIRED:
429 str="certificate expired";
430 break;
431 case SSL3_AD_CERTIFICATE_UNKNOWN:
432 str="certificate unknown";
433 break;
434 case SSL3_AD_ILLEGAL_PARAMETER:
435 str="illegal parameter";
436 break;
437 default: str="unknown"; break;
438 }
439 return(str);
440 }
441
442char *SSL_rstate_string(SSL *s)
443 {
444 char *str;
445
446 switch (s->rstate)
447 {
448 case SSL_ST_READ_HEADER:str="RH"; break;
449 case SSL_ST_READ_BODY: str="RB"; break;
450 case SSL_ST_READ_DONE: str="RD"; break;
451 default: str="unknown"; break;
452 }
453 return(str);
454 }
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c
deleted file mode 100644
index c07d957576..0000000000
--- a/src/lib/libssl/ssl_txt.c
+++ /dev/null
@@ -1,176 +0,0 @@
1/* ssl/ssl_txt.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59#include <stdio.h>
60#include <openssl/buffer.h>
61#include "ssl_locl.h"
62
63#ifndef NO_FP_API
64int SSL_SESSION_print_fp(FILE *fp, SSL_SESSION *x)
65 {
66 BIO *b;
67 int ret;
68
69 if ((b=BIO_new(BIO_s_file_internal())) == NULL)
70 {
71 SSLerr(SSL_F_SSL_SESSION_PRINT_FP,ERR_R_BUF_LIB);
72 return(0);
73 }
74 BIO_set_fp(b,fp,BIO_NOCLOSE);
75 ret=SSL_SESSION_print(b,x);
76 BIO_free(b);
77 return(ret);
78 }
79#endif
80
81int SSL_SESSION_print(BIO *bp, SSL_SESSION *x)
82 {
83 unsigned int i;
84 char str[128],*s;
85
86 if (x == NULL) goto err;
87 if (BIO_puts(bp,"SSL-Session:\n") <= 0) goto err;
88 if (x->ssl_version == SSL2_VERSION)
89 s="SSLv2";
90 else if (x->ssl_version == SSL3_VERSION)
91 s="SSLv3";
92 else if (x->ssl_version == TLS1_VERSION)
93 s="TLSv1";
94 else
95 s="unknown";
96 sprintf(str," Protocol : %s\n",s);
97 if (BIO_puts(bp,str) <= 0) goto err;
98
99 if (x->cipher == NULL)
100 {
101 if (((x->cipher_id) & 0xff000000) == 0x02000000)
102 sprintf(str," Cipher : %06lX\n",x->cipher_id&0xffffff);
103 else
104 sprintf(str," Cipher : %04lX\n",x->cipher_id&0xffff);
105 }
106 else
107 sprintf(str," Cipher : %s\n",(x->cipher == NULL)?"unknown":x->cipher->name);
108 if (BIO_puts(bp,str) <= 0) goto err;
109 if (BIO_puts(bp," Session-ID: ") <= 0) goto err;
110 for (i=0; i<x->session_id_length; i++)
111 {
112 sprintf(str,"%02X",x->session_id[i]);
113 if (BIO_puts(bp,str) <= 0) goto err;
114 }
115 if (BIO_puts(bp,"\n Session-ID-ctx: ") <= 0) goto err;
116 for (i=0; i<x->sid_ctx_length; i++)
117 {
118 sprintf(str,"%02X",x->sid_ctx[i]);
119 if (BIO_puts(bp,str) <= 0) goto err;
120 }
121 if (BIO_puts(bp,"\n Master-Key: ") <= 0) goto err;
122 for (i=0; i<(unsigned int)x->master_key_length; i++)
123 {
124 sprintf(str,"%02X",x->master_key[i]);
125 if (BIO_puts(bp,str) <= 0) goto err;
126 }
127 if (BIO_puts(bp,"\n Key-Arg : ") <= 0) goto err;
128 if (x->key_arg_length == 0)
129 {
130 if (BIO_puts(bp,"None") <= 0) goto err;
131 }
132 else
133 for (i=0; i<x->key_arg_length; i++)
134 {
135 sprintf(str,"%02X",x->key_arg[i]);
136 if (BIO_puts(bp,str) <= 0) goto err;
137 }
138 if (x->compress_meth != 0)
139 {
140 SSL_COMP *comp;
141
142 ssl_cipher_get_evp(x,NULL,NULL,&comp);
143 if (comp == NULL)
144 {
145 sprintf(str,"\n Compression: %d",x->compress_meth);
146 if (BIO_puts(bp,str) <= 0) goto err;
147 }
148 else
149 {
150 sprintf(str,"\n Compression: %d (%s)",
151 comp->id,comp->method->name);
152 if (BIO_puts(bp,str) <= 0) goto err;
153 }
154 }
155 if (x->time != 0L)
156 {
157 sprintf(str,"\n Start Time: %ld",x->time);
158 if (BIO_puts(bp,str) <= 0) goto err;
159 }
160 if (x->timeout != 0L)
161 {
162 sprintf(str,"\n Timeout : %ld (sec)",x->timeout);
163 if (BIO_puts(bp,str) <= 0) goto err;
164 }
165 if (BIO_puts(bp,"\n") <= 0) goto err;
166
167 if (BIO_puts(bp, " Verify return code: ") <= 0) goto err;
168 sprintf(str, "%ld (%s)\n", x->verify_result,
169 X509_verify_cert_error_string(x->verify_result));
170 if (BIO_puts(bp,str) <= 0) goto err;
171
172 return(1);
173err:
174 return(0);
175 }
176