594295d5e065ea09233f9fb97a5f902fad2d2d06
[openssl.git] / ssl / ssl.h
1 /* ssl/ssl.h */
2 /* Copyright (C) 1995-1997 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
63 extern "C" {
64 #endif
65
66 /* SSLeay version number for ASN.1 encoding of the session information */
67 /* Version 0 - initial version
68  * Version 1 - added the optional peer certificate
69  */
70 #define SSL_SESSION_ASN1_VERSION 0x0001
71
72 /* text strings for the ciphers */
73 #define SSL_TXT_NULL_WITH_MD5           SSL2_TXT_NULL_WITH_MD5                  
74 #define SSL_TXT_RC4_128_WITH_MD5        SSL2_TXT_RC4_128_WITH_MD5               
75 #define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5    
76 #define SSL_TXT_RC2_128_CBC_WITH_MD5    SSL2_TXT_RC2_128_CBC_WITH_MD5           
77 #define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5    
78 #define SSL_TXT_IDEA_128_CBC_WITH_MD5   SSL2_TXT_IDEA_128_CBC_WITH_MD5          
79 #define SSL_TXT_DES_64_CBC_WITH_MD5     SSL2_TXT_DES_64_CBC_WITH_MD5            
80 #define SSL_TXT_DES_64_CBC_WITH_SHA     SSL2_TXT_DES_64_CBC_WITH_SHA            
81 #define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5    
82 #define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA    
83
84 #define SSL_MAX_SSL_SESSION_ID_LENGTH           32
85
86 #define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES     (512/8)
87 #define SSL_MAX_KEY_ARG_LENGTH                  8
88 #define SSL_MAX_MASTER_KEY_LENGTH               48
89
90 /* These are used to specify which ciphers to use and not to use */
91 #define SSL_TXT_LOW             "LOW"
92 #define SSL_TXT_MEDIUM          "MEDIUM"
93 #define SSL_TXT_HIGH            "HIGH"
94 #define SSL_TXT_kFZA            "kFZA"
95 #define SSL_TXT_aFZA            "aFZA"
96 #define SSL_TXT_eFZA            "eFZA"
97 #define SSL_TXT_FZA             "FZA"
98
99 #define SSL_TXT_aNULL           "aNULL"
100 #define SSL_TXT_eNULL           "eNULL"
101 #define SSL_TXT_NULL            "NULL"
102
103 #define SSL_TXT_kRSA            "kRSA"
104 #define SSL_TXT_kDHr            "kDHr"
105 #define SSL_TXT_kDHd            "kDHd"
106 #define SSL_TXT_kEDH            "kEDH"
107 #define SSL_TXT_aRSA            "aRSA"
108 #define SSL_TXT_aDSS            "aDSS"
109 #define SSL_TXT_aDH             "aDH"
110 #define SSL_TXT_DSS             "DSS"
111 #define SSL_TXT_DH              "DH"
112 #define SSL_TXT_EDH             "EDH"
113 #define SSL_TXT_ADH             "ADH"
114 #define SSL_TXT_RSA             "RSA"
115 #define SSL_TXT_DES             "DES"
116 #define SSL_TXT_3DES            "3DES"
117 #define SSL_TXT_RC4             "RC4"
118 #define SSL_TXT_RC2             "RC2"
119 #define SSL_TXT_IDEA            "IDEA"
120 #define SSL_TXT_MD5             "MD5"
121 #define SSL_TXT_SHA0            "SHA0"
122 #define SSL_TXT_SHA1            "SHA1"
123 #define SSL_TXT_SHA             "SHA"
124 #define SSL_TXT_EXP             "EXP"
125 #define SSL_TXT_EXPORT          "EXPORT"
126 #define SSL_TXT_SSLV2           "SSLv2"
127 #define SSL_TXT_SSLV3           "SSLv3"
128 #define SSL_TXT_ALL             "ALL"
129
130 /* 'DEFAULT' at the start of the cipher list insert the following string
131  * in addition to this being the default cipher string */
132 #ifndef NO_RSA
133 #define SSL_DEFAULT_CIPHER_LIST "!ADH:RC4+RSA:HIGH:MEDIUM:LOW:EXP:+SSLv2:+EXP"
134 #else
135 #define SSL_ALLOW_ADH
136 #define SSL_DEFAULT_CIPHER_LIST "HIGH:MEDIUM:LOW:ADH+3DES:ADH+RC4:ADH+DES:+EXP"
137 #endif
138
139 #define SSL_SENT_SHUTDOWN       1
140 #define SSL_RECEIVED_SHUTDOWN   2
141 #define SSL_CTX_set_quiet_shutdown(ctx,y) ((ctx)->quiet_shutdown=(y));
142 #define SSL_CTX_get_quiet_shutdown(ctx) ((ctx)->quiet_shutdown);
143 #define SSL_set_quiet_shutdown(s,y)     ((s)->quiet_shutdown=(y));
144 #define SSL_get_quiet_shutdown(s)       ((s)->quiet_shutdown);
145 #define SSL_set_shutdown(s,mode)        ((s)->shutdown=(mode))
146 #define SSL_get_shutdown(s)             ((s)->shutdown)
147 #define SSL_version(s)                  ((s)->version)
148
149 #include "buffer.h"
150 #include "bio.h"
151 #include "x509.h"
152
153 #define SSL_FILETYPE_ASN1       X509_FILETYPE_ASN1
154 #define SSL_FILETYPE_PEM        X509_FILETYPE_PEM
155
156 typedef struct ssl_st *ssl_crock_st;
157
158 /* used to hold info on the particular ciphers used */
159 typedef struct ssl_cipher_st
160         {
161         int valid;
162         char *name;                     /* text name */
163         unsigned long id;               /* id, 4 bytes, first is version */
164         unsigned long algorithms;       /* what ciphers are used */
165         unsigned long algorithm2;       /* Extra flags */
166         unsigned long mask;             /* used for matching */
167         } SSL_CIPHER;
168
169 /* Used to hold functions for SSLv2 or SSLv3 functions */
170 typedef struct ssl_method_st
171         {
172         int version;
173         int (*ssl_new)();
174         void (*ssl_clear)();
175         void (*ssl_free)();
176         int (*ssl_accept)();
177         int (*ssl_connect)();
178         int (*ssl_read)();
179         int (*ssl_peek)();
180         int (*ssl_write)();
181         int (*ssl_shutdown)();
182         int (*ssl_renegotiate)();
183         long (*ssl_ctrl)();
184         long (*ssl_ctx_ctrl)();
185         SSL_CIPHER *(*get_cipher_by_char)();
186         int (*put_cipher_by_char)();
187         int (*ssl_pending)();
188         int (*num_ciphers)();
189         SSL_CIPHER *(*get_cipher)();
190         struct ssl_method_st *(*get_ssl_method)();
191         long (*get_timeout)();
192         } SSL_METHOD;
193
194 typedef struct ssl_compression_st
195         {
196         char *stuff;
197         } SSL_COMPRESSION;
198
199 /* Lets make this into an ASN.1 type structure as follows
200  * SSL_SESSION_ID ::= SEQUENCE {
201  *      version                 INTEGER,        -- structure version number
202  *      SSLversion              INTEGER,        -- SSL version number
203  *      Cipher                  OCTET_STRING,   -- the 3 byte cipher ID
204  *      Session_ID              OCTET_STRING,   -- the Session ID
205  *      Master_key              OCTET_STRING,   -- the master key
206  *      Key_Arg [ 0 ] IMPLICIT  OCTET_STRING,   -- the optional Key argument
207  *      Time [ 1 ] EXPLICIT     INTEGER,        -- optional Start Time
208  *      Timeout [ 2 ] EXPLICIT  INTEGER,        -- optional Timeout ins seconds
209  *      Peer [ 3 ] EXPLICIT     X509,           -- optional Peer Certificate
210  *      }
211  * Look in ssl/ssl_asn1.c for more details
212  * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
213  */
214 typedef struct ssl_session_st
215         {
216         int ssl_version;        /* what ssl version session info is
217                                  * being kept in here? */
218
219         /* only really used in SSLv2 */
220         unsigned int key_arg_length;
221         unsigned char key_arg[SSL_MAX_KEY_ARG_LENGTH];
222         int master_key_length;
223         unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
224         /* session_id - valid? */
225         unsigned int session_id_length;
226         unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
227
228         int not_resumable;
229
230         /* The cert is the certificate used to establish this connection */
231         struct cert_st /* CERT */ *cert;
232
233         /* This is the cert for the other end.  On servers, it will be
234          * the same as cert->x509 */
235         X509 *peer;
236
237         int references;
238         long timeout;
239         long time;
240
241         SSL_COMPRESSION *read_compression;
242         SSL_COMPRESSION *write_compression;
243
244         SSL_CIPHER *cipher;
245         unsigned long cipher_id;        /* when ASN.1 loaded, this
246                                          * needs to be used to load
247                                          * the 'cipher' structure */
248
249         STACK /* SSL_CIPHER */ *ciphers; /* shared ciphers? */
250
251         char *app_data; /* application specific data */
252         } SSL_SESSION;
253
254 #define SSL_OP_MICROSOFT_SESS_ID_BUG                    0x00000001L
255 #define SSL_OP_NETSCAPE_CHALLENGE_BUG                   0x00000002L
256 #define SSL_OP_NETSCAPE_CA_DN_BUG                       0x00000004L
257 #define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG         0x00000008L
258 #define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG              0x00000010L
259 #define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER               0x00000020L
260 #define SSL_OP_MSIE_SSLV2_RSA_PADDING                   0x00000040L
261 #define SSL_OP_SSLEAY_080_CLIENT_DH_BUG                 0x00000080L
262
263 /* If set, only use tmp_dh parameters once */
264 #define SSL_OP_SINGLE_DH_USE                            0x00100000L
265 /* Set to also use the tmp_rsa key when doing RSA operations. */
266 #define SSL_OP_EPHEMERAL_RSA                            0x00200000L
267
268 #define SSL_OP_NON_EXPORT_FIRST                         0x40000000L
269 #define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG          0x80000000L
270 #define SSL_OP_ALL                                      0x000FFFFFL
271
272 #define SSL_CTX_set_options(ctx,op)     ((ctx)->options|=(op))
273
274 /* Normally you will only use these if your application wants to use
275  * the certificate store in other places, perhaps PKCS7 */
276 #define SSL_CTX_get_cert_store(ctx)     ((ctx)->cert_store)
277 #define SSL_CTX_set_cert_store(ctx,cs) \
278                 (X509_STORE_free((ctx)->cert_store),(ctx)->cert_store=(cs))
279
280
281 typedef struct ssl_ctx_st
282         {
283         SSL_METHOD *method;
284         unsigned long options;
285
286         STACK /* SSL_CIPHER */ *cipher_list;
287         /* same as above but sorted for lookup */
288         STACK /* SSL_CIPHER */ *cipher_list_by_id;
289
290         struct x509_store_st /* X509_STORE */ *cert_store;
291         struct lhash_st /* LHASH */ *sessions;  /* a set of SSL_SESSION's */
292
293         /* This can have one of 2 values, ored together,
294          * SSL_SESS_CACHE_CLIENT,
295          * SSL_SESS_CACHE_SERVER,
296          * Default is SSL_SESSION_CACHE_SERVER, which means only
297          * SSL_accept which cache SSL_SESSIONS. */
298         int session_cache_mode;
299
300         /* If timeout is not 0, it is the default timeout value set
301          * when SSL_new() is called.  This has been put in to make
302          * life easier to set things up */
303         long session_timeout;
304
305         /* If this callback is not null, it will be called each
306          * time a session id is added to the cache.  If this function
307          * returns 1, it means that the callback will do a
308          * SSL_SESSION_free() when it has finished using it.  Otherwise,
309          * on 0, it means the callback has finished with it.
310          * If remove_session_cb is not null, it will be called when
311          * a session-id is removed from the cache.  Again, a return
312          * of 0 mens that SSLeay should not SSL_SESSION_free() since
313          * the application is doing something with it. */
314 #ifndef NOPROTO
315         int (*new_session_cb)(struct ssl_st *ssl,SSL_SESSION *sess);
316         void (*remove_session_cb)(struct ssl_ctx_st *ctx,SSL_SESSION *sess);
317         SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
318                 unsigned char *data,int len,int *copy);
319 #else
320         int (*new_session_cb)();
321         void (*remove_session_cb)();
322         SSL_SESSION *(*get_session_cb)();
323 #endif
324
325         int sess_connect;       /* SSL new (expensive) connection - started */
326         int sess_connect_good;  /* SSL new (expensive) connection - finished */
327         int sess_accept;        /* SSL new (expensive) accept - started */
328         int sess_accept_good;   /* SSL new (expensive) accept - finished */
329         int sess_miss;          /* session lookup misses  */
330         int sess_timeout;       /* session reuse attempt on timeouted session */
331         int sess_hit;           /* session reuse actually done */
332         int sess_cb_hit;        /* session-id that was not in the cache was
333                                  * passed back via the callback.  This
334                                  * indicates that the application is supplying
335                                  * session-id's from other processes -
336                                  * spooky :-) */
337
338         int references;
339
340         void (*info_callback)();
341
342         /* if defined, these override the X509_verify_cert() calls */
343         int (*app_verify_callback)();
344         char *app_verify_arg;
345
346         /* default values to use in SSL structures */
347         struct cert_st /* CERT */ *default_cert;
348         int default_read_ahead;
349         int default_verify_mode;
350         int (*default_verify_callback)();
351
352         /* Default password callback. */
353         int (*default_passwd_callback)();
354
355         /* get client cert callback */
356         int (*client_cert_cb)(/* SSL *ssl, X509 **x509, EVP_PKEY **pkey */);
357
358         /* what we put in client requests */
359         STACK *client_CA;
360
361         int quiet_shutdown;
362
363         char *app_data;
364         } SSL_CTX;
365
366 #define SSL_SESS_CACHE_OFF      0x00
367 #define SSL_SESS_CACHE_CLIENT   0x01
368 #define SSL_SESS_CACHE_SERVER   0x02
369 #define SSL_SESS_CACHE_BOTH     (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
370 #define SSL_SESS_CACHE_NO_AUTO_CLEAR    0x80
371
372 #define SSL_session_reused(s)   ((s)->hit)
373
374 #define SSL_CTX_sessions(ctx)           ((ctx)->sessions)
375 /* You will need to include lhash.h to access the following #define */
376 #define SSL_CTX_sess_number(ctx)        ((ctx)->sessions->num_items)
377 #define SSL_CTX_sess_connect(ctx)       ((ctx)->sess_connect)
378 #define SSL_CTX_sess_connect_good(ctx)  ((ctx)->sess_connect_good)
379 #define SSL_CTX_sess_accept(ctx)        ((ctx)->sess_accept)
380 #define SSL_CTX_sess_accept_good(ctx)   ((ctx)->sess_accept_good)
381 #define SSL_CTX_sess_hits(ctx)          ((ctx)->sess_hit)
382 #define SSL_CTX_sess_cb_hits(ctx)       ((ctx)->sess_cb_hit)
383 #define SSL_CTX_sess_misses(ctx)        ((ctx)->sess_miss)
384 #define SSL_CTX_sess_timeouts(ctx)      ((ctx)->sess_timeout)
385
386 #define SSL_CTX_sess_set_new_cb(ctx,cb) ((ctx)->new_session_cb=(cb))
387 #define SSL_CTX_sess_get_new_cb(ctx)    ((ctx)->new_session_cb)
388 #define SSL_CTX_sess_set_remove_cb(ctx,cb)      ((ctx)->remove_session_cb=(cb))
389 #define SSL_CTX_sess_get_remove_cb(ctx) ((ctx)->remove_session_cb)
390 #define SSL_CTX_sess_set_get_cb(ctx,cb) ((ctx)->get_session_cb=(cb))
391 #define SSL_CTX_sess_get_get_cb(ctx)    ((ctx)->get_session_cb)
392 #define SSL_CTX_set_session_cache_mode(ctx,m)   ((ctx)->session_cache_mode=(m))
393 #define SSL_CTX_get_session_cache_mode(ctx)     ((ctx)->session_cache_mode)
394 #define SSL_CTX_set_timeout(ctx,t)      ((ctx)->session_timeout=(t))
395 #define SSL_CTX_get_timeout(ctx)        ((ctx)->session_timeout)
396
397 #define SSL_CTX_set_info_callback(ctx,cb)       ((ctx)->info_callback=(cb))
398 #define SSL_CTX_get_info_callback(ctx)          ((ctx)->info_callback)
399 #define SSL_CTX_set_default_read_ahead(ctx,m) (((ctx)->default_read_ahead)=(m))
400
401 #define SSL_CTX_set_client_cert_cb(ctx,cb)      ((ctx)->client_cert_cb=(cb))
402 #define SSL_CTX_get_client_cert_cb(ctx)         ((ctx)->client_cert_cb)
403
404 #define SSL_NOTHING     1
405 #define SSL_WRITING     2
406 #define SSL_READING     3
407 #define SSL_X509_LOOKUP 4
408
409 /* These will only be used when doing non-blocking IO */
410 #define SSL_want(s)             ((s)->rwstate)
411 #define SSL_want_nothing(s)     ((s)->rwstate == SSL_NOTHING)
412 #define SSL_want_read(s)        ((s)->rwstate == SSL_READING)
413 #define SSL_want_write(s)       ((s)->rwstate == SSL_WRITING)
414 #define SSL_want_x509_lookup(s) ((s)->rwstate == SSL_X509_LOOKUP)
415
416 typedef struct ssl_st
417         {
418         /* procol version
419          * 2 for SSLv2
420          * 3 for SSLv3
421          * -3 for SSLv3 but accept SSLv2 */
422         int version;
423         int type; /* SSL_ST_CONNECT or SSL_ST_ACCEPT */
424
425         SSL_METHOD *method; /* SSLv3 */
426
427         /* There are 2 BIO's even though they are normally both the
428          * same.  This is so data can be read and written to different
429          * handlers */
430
431 #ifdef HEADER_BIO_H
432         BIO *rbio; /* used by SSL_read */
433         BIO *wbio; /* used by SSL_write */
434         BIO *bbio; /* used during session-id reuse to concatinate
435                     * messages */
436 #else
437         char *rbio; /* used by SSL_read */
438         char *wbio; /* used by SSL_write */
439         char *bbio;
440 #endif
441         /* This holds a variable that indicates what we were doing
442          * when a 0 or -1 is returned.  This is needed for
443          * non-blocking IO so we know what request needs re-doing when
444          * in SSL_accept or SSL_connect */
445         int rwstate;
446
447         /* true when we are actually in SSL_accept() or SSL_connect() */
448         int in_handshake;
449         int (*handshake_func)();
450
451 /*      int server;*/   /* are we the server side? */
452
453         int new_session;/* 1 if we are to use a new session */
454         int quiet_shutdown;/* don't send shutdown packets */
455         int shutdown;   /* we have shut things down, 0x01 sent, 0x02
456                          * for received */
457         int state;      /* where we are */
458         int rstate;     /* where we are when reading */
459
460         BUF_MEM *init_buf;      /* buffer used during init */
461         int init_num;           /* amount read/written */
462         int init_off;           /* amount read/written */
463
464         /* used internally to point at a raw packet */
465         unsigned char *packet;
466         unsigned int packet_length;
467
468         struct ssl2_ctx_st *s2; /* SSLv2 variables */
469         struct ssl3_ctx_st *s3; /* SSLv3 variables */
470
471         int read_ahead;         /* Read as many input bytes as possible */
472         int hit;                /* reusing a previous session */
473
474         /* crypto */
475         STACK /* SSL_CIPHER */ *cipher_list;
476         STACK /* SSL_CIPHER */ *cipher_list_by_id;
477
478         /* These are the ones being used, the ones is SSL_SESSION are
479          * the ones to be 'copied' into these ones */
480
481         EVP_CIPHER_CTX *enc_read_ctx;           /* cryptographic state */
482         EVP_MD *read_hash;                      /* used for mac generation */
483         SSL_COMPRESSION *read_compression;      /* compression */
484
485         EVP_CIPHER_CTX *enc_write_ctx;          /* cryptographic state */
486         EVP_MD *write_hash;                     /* used for mac generation */
487         SSL_COMPRESSION *write_compression;     /* compression */
488
489         /* session info */
490
491         /* client cert? */
492         /* This is used to hold the server certificate used */
493         struct cert_st /* CERT */ *cert;
494
495         /* This can also be in the session once a session is established */
496         SSL_SESSION *session;
497
498         /* Used in SSL2 and SSL3 */
499         int verify_mode;        /* 0 don't care about verify failure.
500                                  * 1 fail if verify fails */
501         int (*verify_callback)(); /* fail if callback returns 0 */
502         void (*info_callback)(); /* optional informational callback */
503
504         int error;              /* error bytes to be written */
505         int error_code;         /* actual code */
506
507         SSL_CTX *ctx;
508         /* set this flag to 1 and a sleep(1) is put into all SSL_read()
509          * and SSL_write() calls, good for nbio debuging :-) */
510         int debug;      
511
512         /* extra application data */
513         int verify_result;
514         char *app_data;
515
516         /* for server side, keep the list of CA_dn we can use */
517         STACK /* X509_NAME */ *client_CA;
518
519         int first_packet;
520         } SSL;
521
522 #include "ssl2.h"
523 #include "ssl3.h"
524 #include "ssl23.h"
525
526 /* application stuff */
527 #define SSL_set_verify_result(s,arg)    ((s)->verify_result=(long)arg)
528 #define SSL_get_verify_result(s)        ((s)->verify_result)
529 #define SSL_set_app_data(s,arg)         ((s)->app_data=(char *)arg)
530 #define SSL_get_app_data(s)             ((s)->app_data)
531
532 #define SSL_SESSION_set_app_data(s,arg)         ((s)->app_data=(char *)arg)
533 #define SSL_SESSION_get_app_data(s)             ((s)->app_data)
534
535 #define SSL_CTX_set_app_data(ctx,arg)   ((ctx)->app_data=(char *)arg)
536 #define SSL_CTX_get_app_data(ctx)       ((ctx)->app_data)
537
538 /* The following are the possible values for ssl->state are are
539  * used to indicate where we are upto in the SSL connection establishment.
540  * The macros that follow are about the only things you should need to use
541  * and even then, only when using non-blocking IO.
542  * It can also be useful to work out where you were when the connection
543  * failed */
544
545 #define SSL_state(a)                    ((a)->state)
546 #define SSL_ST_CONNECT                  0x1000
547 #define SSL_ST_ACCEPT                   0x2000
548 #define SSL_ST_MASK                     0x0FFF
549 #define SSL_ST_INIT                     (SSL_ST_CONNECT|SSL_ST_ACCEPT)
550 #define SSL_ST_BEFORE                   0x4000
551 #define SSL_ST_OK                       0x03
552 #define SSL_ST_RENEGOTIATE              (0x04|SSL_ST_INIT)
553
554 /* SSL info callback functions */
555 #define SSL_set_info_callback(ssl,cb)   ((ssl)->info_callback=(cb))
556 #define SSL_get_info_callback(ssl)      ((ssl)->info_callback)
557
558 #define SSL_CB_LOOP                     0x01
559 #define SSL_CB_EXIT                     0x02
560 #define SSL_CB_READ                     0x04
561 #define SSL_CB_WRITE                    0x08
562 #define SSL_CB_ALERT                    0x4000 /* used in callback */
563 #define SSL_CB_READ_ALERT               (SSL_CB_ALERT|SSL_CB_READ)
564 #define SSL_CB_WRITE_ALERT              (SSL_CB_ALERT|SSL_CB_WRITE)
565 #define SSL_CB_ACCEPT_LOOP              (SSL_ST_ACCEPT|SSL_CB_LOOP)
566 #define SSL_CB_ACCEPT_EXIT              (SSL_ST_ACCEPT|SSL_CB_EXIT)
567 #define SSL_CB_CONNECT_LOOP             (SSL_ST_CONNECT|SSL_CB_LOOP)
568 #define SSL_CB_CONNECT_EXIT             (SSL_ST_CONNECT|SSL_CB_EXIT)
569 #define SSL_CB_HANDSHAKE_START          0x10
570 #define SSL_CB_HANDSHAKE_DONE           0x20
571
572 /* Is the SSL_connection established? */
573 #define SSL_is_init_finished(a)         ((a)->state == SSL_ST_OK)
574 #define SSL_in_init(a)                  ((a)->state&SSL_ST_INIT)
575 #define SSL_in_before(a)                ((a)->state&SSL_ST_BEFORE)
576 #define SSL_in_connect_init(a)          ((a)->state&SSL_ST_CONNECT)
577 #define SSL_in_accept_init(a)           ((a)->state&SSL_ST_ACCEPT)
578
579 /* The following 2 states are kept in ssl->rstate when reads fail,
580  * you should not need these */
581 #define SSL_ST_READ_HEADER                      0xF0
582 #define SSL_ST_READ_BODY                        0xF1
583 #define SSL_ST_READ_DONE                        0xF2
584
585 /* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options
586  * are 'ored' with SSL_VERIFY_PEER if they are desired */
587 #define SSL_VERIFY_NONE                 0x00
588 #define SSL_VERIFY_PEER                 0x01
589 #define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
590 #define SSL_VERIFY_CLIENT_ONCE          0x04
591
592 #define SSL_RWERR_BAD_WRITE_RETRY       (-2)
593 #define SSL_RWERR_BAD_MAC_DECODE        (-3)
594 #define SSL_RWERR_INTERNAL_ERROR        (-4) /* should not get this one */
595 #define SSL_RWERR_WRONG_RECORD_TYPE     (-5) /* used internally */
596
597 #define SSL_CTX_set_default_verify_paths(ctx) \
598                 X509_STORE_set_default_paths((ctx)->cert_store)
599 #define SSL_CTX_load_verify_locations(ctx,CAfile,CApath) \
600                 X509_STORE_load_locations((ctx)->cert_store,\
601                 (CAfile),(CApath))
602
603 #define SSL_get_session(s)      ((s)->session)
604 #define SSL_get_SSL_CTX(s)      ((s)->ctx)
605
606 /* this is for backward compatablility */
607 #if 0 /* NEW_SSLEAY */
608 #define SSL_CTX_set_default_verify(a,b,c) SSL_CTX_set_verify(a,b,c)
609 #define SSL_set_pref_cipher(c,n)        SSL_set_cipher_list(c,n)
610 #define SSL_add_session(a,b)            SSL_CTX_add_session((a),(b))
611 #define SSL_remove_session(a,b)         SSL_CTX_remove_session((a),(b))
612 #define SSL_flush_sessions(a,b)         SSL_CTX_flush_sessions((a),(b))
613 #endif
614 /* More backward compatablity */
615 #define SSL_get_cipher(s) \
616                 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
617 #define SSL_get_cipher_bits(s,np) \
618                 SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
619 #define SSL_get_cipher_version(s) \
620                 SSL_CIPHER_get_version(SSL_get_current_cipher(s))
621 #define SSL_get_cipher_name(s) \
622                 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
623
624 /* VMS linker has a 31 char name limit */
625 #define SSL_CTX_set_cert_verify_callback(a,b,c) \
626                 SSL_CTX_set_cert_verify_cb((a),(b),(c))
627
628 #if 1 /*SSLEAY_MACROS*/
629 #define d2i_SSL_SESSION_bio(bp,s_id) (SSL_SESSION *)ASN1_d2i_bio( \
630         (char *(*)())SSL_SESSION_new,(char *(*)())d2i_SSL_SESSION, \
631         (bp),(unsigned char **)(s_id))
632 #define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio(i2d_SSL_SESSION, \
633         bp,(unsigned char *)s_id)
634 #define PEM_read_SSL_SESSION(fp,x,cb) (SSL_SESSION *)PEM_ASN1_read( \
635         (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,fp,(char **)x,cb)
636 #define PEM_read_bio_SSL_SESSION(bp,x,cb) (SSL_SESSION *)PEM_ASN1_read_bio( \
637         (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb)
638 #define PEM_write_SSL_SESSION(fp,x) \
639         PEM_ASN1_write((int (*)())i2d_SSL_SESSION, \
640                 PEM_STRING_SSL_SESSION,fp, (char *)x, NULL,NULL,0,NULL)
641 #define PEM_write_bio_SSL_SESSION(bp,x) \
642         PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
643                 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL)
644 #endif
645
646 #define SSL_ERROR_NONE                  0
647 #define SSL_ERROR_SSL                   1
648 #define SSL_ERROR_WANT_READ             2
649 #define SSL_ERROR_WANT_WRITE            3
650 #define SSL_ERROR_WANT_X509_LOOKUP      4
651 #define SSL_ERROR_SYSCALL               5 /* look at errno */
652 #define SSL_ERROR_ZERO_RETURN           6
653 #define SSL_ERROR_WANT_CONNECT          7
654
655 #define SSL_CTRL_NEED_TMP_RSA           1
656 #define SSL_CTRL_SET_TMP_RSA            2
657 #define SSL_CTRL_SET_TMP_DH             3
658 #define SSL_CTRL_SET_TMP_RSA_CB         4
659 #define SSL_CTRL_SET_TMP_DH_CB          5
660
661 #define SSL_CTX_need_tmp_RSA(ctx) \
662         SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)
663 #define SSL_CTX_set_tmp_rsa(ctx,rsa) \
664         SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
665 #define SSL_CTX_set_tmp_dh(ctx,dh) \
666         SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
667
668 /* For the next 2, the callbacks are 
669  * RSA *tmp_rsa_cb(int export)
670  * DH *tmp_dh_cb(int export)
671  */
672 #define SSL_CTX_set_tmp_rsa_callback(ctx,cb) \
673         SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA_CB,0,(char *)cb)
674 #define SSL_CTX_set_tmp_dh_callback(ctx,dh) \
675         SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,0,(char *)cb)
676
677 #ifndef NOPROTO
678
679 #ifdef HEADER_BIO_H
680 BIO_METHOD *BIO_f_ssl(void);
681 BIO *BIO_new_ssl(SSL_CTX *ctx,int client);
682 int BIO_ssl_copy_session_id(BIO *to,BIO *from);
683 void BIO_ssl_shutdown(BIO *ssl_bio);
684
685 #endif
686
687 int     SSL_CTX_set_cipher_list(SSL_CTX *,char *str);
688 SSL_CTX *SSL_CTX_new(SSL_METHOD *meth);
689 void    SSL_CTX_free(SSL_CTX *);
690 void    SSL_clear(SSL *s);
691 void    SSL_CTX_flush_sessions(SSL_CTX *ctx,long tm);
692
693 SSL_CIPHER *SSL_get_current_cipher(SSL *s);
694 int     SSL_CIPHER_get_bits(SSL_CIPHER *c,int *alg_bits);
695 char *  SSL_CIPHER_get_version(SSL_CIPHER *c);
696 char *  SSL_CIPHER_get_name(SSL_CIPHER *c);
697
698 int     SSL_get_fd(SSL *s);
699 char  * SSL_get_cipher_list(SSL *s,int n);
700 char *  SSL_get_shared_ciphers(SSL *s, char *buf, int len);
701 int     SSL_get_read_ahead(SSL * s);
702 int     SSL_pending(SSL *s);
703 #ifndef NO_SOCK
704 int     SSL_set_fd(SSL *s, int fd);
705 int     SSL_set_rfd(SSL *s, int fd);
706 int     SSL_set_wfd(SSL *s, int fd);
707 #endif
708 #ifdef HEADER_BIO_H
709 void    SSL_set_bio(SSL *s, BIO *rbio,BIO *wbio);
710 BIO *   SSL_get_rbio(SSL *s);
711 BIO *   SSL_get_wbio(SSL *s);
712 #endif
713 int     SSL_set_cipher_list(SSL *s, char *str);
714 void    SSL_set_read_ahead(SSL *s, int yes);
715 int     SSL_get_verify_mode(SSL *s);
716 int     (*SSL_get_verify_callback(SSL *s))();
717 void    SSL_set_verify(SSL *s, int mode, int (*callback) ());
718 int     SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
719 int     SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len);
720 int     SSL_use_RSAPrivateKey_file(SSL *ssl, char *file, int type);
721 int     SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
722 int     SSL_use_PrivateKey_ASN1(int pk,SSL *ssl, unsigned char *d, long len);
723 int     SSL_use_PrivateKey_file(SSL *ssl, char *file, int type);
724 int     SSL_use_certificate(SSL *ssl, X509 *x);
725 int     SSL_use_certificate_ASN1(SSL *ssl, int len, unsigned char *d);
726 int     SSL_use_certificate_file(SSL *ssl, char *file, int type);
727 void    ERR_load_SSL_strings(void );
728 void    SSL_load_error_strings(void );
729 char *  SSL_state_string(SSL *s);
730 char *  SSL_rstate_string(SSL *s);
731 char *  SSL_state_string_long(SSL *s);
732 char *  SSL_rstate_string_long(SSL *s);
733 long    SSL_get_time(SSL_SESSION *s);
734 long    SSL_set_time(SSL_SESSION *s, long t);
735 long    SSL_get_timeout(SSL_SESSION *s);
736 long    SSL_set_timeout(SSL_SESSION *s, long t);
737 void    SSL_copy_session_id(SSL *to,SSL *from);
738
739 SSL_SESSION *SSL_SESSION_new(void);
740 #ifndef WIN16
741 int     SSL_SESSION_print_fp(FILE *fp,SSL_SESSION *ses);
742 #endif
743 #ifdef HEADER_BIO_H
744 int     SSL_SESSION_print(BIO *fp,SSL_SESSION *ses);
745 #endif
746 void    SSL_SESSION_free(SSL_SESSION *ses);
747 int     i2d_SSL_SESSION(SSL_SESSION *in,unsigned char **pp);
748 int     SSL_set_session(SSL *to, SSL_SESSION *session);
749 int     SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
750 int     SSL_CTX_remove_session(SSL_CTX *,SSL_SESSION *c);
751 SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a,unsigned char **pp,long length);
752
753 #ifdef HEADER_X509_H
754 X509 *  SSL_get_peer_certificate(SSL *s);
755 #endif
756
757 STACK * SSL_get_peer_cert_chain(SSL *s);
758
759 int SSL_CTX_get_verify_mode(SSL_CTX *ctx);
760 int (*SSL_CTX_get_verify_callback(SSL_CTX *ctx))();
761 void SSL_CTX_set_verify(SSL_CTX *ctx,int mode,int (*callback)());
762 void SSL_CTX_set_cert_verify_cb(SSL_CTX *ctx, int (*cb)(),char *arg);
763 int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
764 int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, unsigned char *d, long len);
765 int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, char *file, int type);
766 int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
767 int SSL_CTX_use_PrivateKey_ASN1(int pk,SSL_CTX *ctx,
768         unsigned char *d, long len);
769 int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, char *file, int type);
770 int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
771 int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, unsigned char *d);
772 int SSL_CTX_use_certificate_file(SSL_CTX *ctx, char *file, int type);
773
774 void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx,int (*cb)());
775
776 int SSL_CTX_check_private_key(SSL_CTX *ctx);
777 int SSL_check_private_key(SSL *ctx);
778
779 SSL *   SSL_new(SSL_CTX *ctx);
780 void    SSL_clear(SSL *s);
781 void    SSL_free(SSL *ssl);
782 int     SSL_accept(SSL *ssl);
783 int     SSL_connect(SSL *ssl);
784 int     SSL_read(SSL *ssl,char *buf,int num);
785 int     SSL_peek(SSL *ssl,char *buf,int num);
786 int     SSL_write(SSL *ssl,char *buf,int num);
787 long    SSL_ctrl(SSL *ssl,int cmd, long larg, char *parg);
788 long    SSL_CTX_ctrl(SSL_CTX *ctx,int cmd, long larg, char *parg);
789
790 int     SSL_get_error(SSL *s,int ret_code);
791 char *  SSL_get_version(SSL *s);
792
793 /* This sets the 'default' SSL version that SSL_new() will create */
794 int SSL_CTX_set_ssl_version(SSL_CTX *ctx,SSL_METHOD *meth);
795
796 SSL_METHOD *SSLv2_method(void);         /* sslv2 */
797 SSL_METHOD *SSLv2_server_method(void);  /* sslv2 */
798 SSL_METHOD *SSLv2_client_method(void);  /* sslv2 */
799
800 SSL_METHOD *SSLv3_method(void);         /* sslv3 */
801 SSL_METHOD *SSLv3_server_method(void);  /* sslv3 */
802 SSL_METHOD *SSLv3_client_method(void);  /* sslv3 */
803
804 SSL_METHOD *SSLv23_method(void);        /* sslv3 but can rollback to v2 */
805 SSL_METHOD *SSLv23_server_method(void); /* sslv3 but can rollback to v2 */
806 SSL_METHOD *SSLv23_client_method(void); /* sslv3 but can rollback to v2 */
807
808 STACK *SSL_get_ciphers(SSL *s);
809
810 int SSL_do_handshake(SSL *s);
811 int SSL_renegotiate(SSL *s);
812 int SSL_shutdown(SSL *s);
813
814 SSL_METHOD *SSL_get_ssl_method(SSL *s);
815 int SSL_set_ssl_method(SSL *s,SSL_METHOD *method);
816 char *SSL_alert_type_string_long(int value);
817 char *SSL_alert_type_string(int value);
818 char *SSL_alert_desc_string_long(int value);
819 char *SSL_alert_desc_string(int value);
820
821 STACK *SSL_load_client_CA_file(char *file);
822 void SSL_set_client_CA_list(SSL *s, STACK *list);
823 void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK *list);
824 STACK *SSL_get_client_CA_list(SSL *s);
825 STACK *SSL_CTX_get_client_CA_list(SSL_CTX *s);
826 int SSL_add_client_CA(SSL *ssl,X509 *x);
827 int SSL_CTX_add_client_CA(SSL_CTX *ctx,X509 *x);
828
829 void SSL_set_connect_state(SSL *s);
830 void SSL_set_accept_state(SSL *s);
831
832 long SSL_get_default_timeout(SSL *s);
833
834 void SSLeay_add_ssl_algorithms(void );
835
836 char *SSL_CIPHER_description(SSL_CIPHER *,char *buf,int size);
837 STACK *SSL_dup_CA_list(STACK *sk);
838
839 SSL *SSL_dup(SSL *ssl);
840
841 X509 *SSL_get_certificate(SSL *ssl);
842 /* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(SSL *ssl);
843
844 #else
845
846 BIO_METHOD *BIO_f_ssl();
847 BIO *BIO_new_ssl();
848 int BIO_ssl_copy_session_id();
849 void BIO_ssl_shutdown();
850
851 int     SSL_CTX_set_cipher_list();
852 SSL_CTX *SSL_CTX_new();
853 void    SSL_CTX_free();
854 void    SSL_clear();
855 void    SSL_CTX_flush_sessions();
856
857 SSL_CIPHER *SSL_get_current_cipher();
858 int     SSL_CIPHER_get_bits();
859 char *  SSL_CIPHER_get_version();
860 char *  SSL_CIPHER_get_name();
861
862 int     SSL_get_fd();
863 char  * SSL_get_cipher_list();
864 char *  SSL_get_shared_ciphers();
865 int     SSL_get_read_ahead();
866 int     SSL_pending();
867 #ifndef NO_SOCK
868 int     SSL_set_fd();
869 int     SSL_set_rfd();
870 int     SSL_set_wfd();
871 #endif
872 #ifdef HEADER_BIO_H
873 void    SSL_set_bio();
874 BIO *   SSL_get_rbio();
875 BIO *   SSL_get_wbio();
876 #endif
877 int     SSL_set_cipher_list();
878 void    SSL_set_read_ahead();
879 int     SSL_get_verify_mode();
880
881 void    SSL_set_verify();
882 int     SSL_use_RSAPrivateKey();
883 int     SSL_use_RSAPrivateKey_ASN1();
884 int     SSL_use_RSAPrivateKey_file();
885 int     SSL_use_PrivateKey();
886 int     SSL_use_PrivateKey_ASN1();
887 int     SSL_use_PrivateKey_file();
888 int     SSL_use_certificate();
889 int     SSL_use_certificate_ASN1();
890 int     SSL_use_certificate_file();
891 void    ERR_load_SSL_strings();
892 void    SSL_load_error_strings();
893 char *  SSL_state_string();
894 char *  SSL_rstate_string();
895 char *  SSL_state_string_long();
896 char *  SSL_rstate_string_long();
897 long    SSL_get_time();
898 long    SSL_set_time();
899 long    SSL_get_timeout();
900 long    SSL_set_timeout();
901 void    SSL_copy_session_id();
902
903 SSL_SESSION *SSL_SESSION_new();
904 #ifndef WIN16
905 int     SSL_SESSION_print_fp();
906 #endif
907 #ifdef HEADER_BIO_H
908 int     SSL_SESSION_print();
909 #endif
910 void    SSL_SESSION_free();
911 int     i2d_SSL_SESSION();
912 int     SSL_set_session();
913 int     SSL_CTX_add_session();
914 int     SSL_CTX_remove_session();
915 SSL_SESSION *d2i_SSL_SESSION();
916
917 #ifdef HEADER_X509_H
918 X509 *  SSL_get_peer_certificate();
919 #endif
920
921 STACK * SSL_get_peer_cert_chain();
922
923 int SSL_CTX_get_verify_mode();
924 int (*SSL_CTX_get_verify_callback())();
925 void SSL_CTX_set_verify();
926 void SSL_CTX_set_cert_verify_cb();
927 int SSL_CTX_use_RSAPrivateKey();
928 int SSL_CTX_use_RSAPrivateKey_ASN1();
929 int SSL_CTX_use_RSAPrivateKey_file();
930 int SSL_CTX_use_PrivateKey();
931 int SSL_CTX_use_PrivateKey_ASN1();
932 int SSL_CTX_use_PrivateKey_file();
933 int SSL_CTX_use_certificate();
934 int SSL_CTX_use_certificate_ASN1();
935 int SSL_CTX_use_certificate_file();
936
937 void SSL_CTX_set_default_passwd_cb();
938
939 int SSL_CTX_check_private_key();
940 int SSL_check_private_key();
941
942 SSL *   SSL_new();
943 void    SSL_clear();
944 void    SSL_free();
945 int     SSL_accept();
946 int     SSL_connect();
947 int     SSL_read();
948 int     SSL_peek();
949 int     SSL_write();
950 long    SSL_ctrl();
951 long    SSL_CTX_ctrl();
952
953 int     SSL_get_error();
954 char *  SSL_get_version();
955
956 int SSL_CTX_set_ssl_version();
957
958 SSL_METHOD *SSLv2_method();
959 SSL_METHOD *SSLv2_server_method();
960 SSL_METHOD *SSLv2_client_method();
961
962 SSL_METHOD *SSLv3_method();
963 SSL_METHOD *SSLv3_server_method();
964 SSL_METHOD *SSLv3_client_method();
965
966 SSL_METHOD *SSLv23_method();
967 SSL_METHOD *SSLv23_server_method();
968 SSL_METHOD *SSLv23_client_method();
969
970 STACK *SSL_get_ciphers();
971
972 int SSL_do_handshake();
973 int SSL_renegotiate();
974 int SSL_shutdown();
975
976 SSL_METHOD *SSL_get_ssl_method();
977 int SSL_set_ssl_method();
978 char *SSL_alert_type_string_long();
979 char *SSL_alert_type_string();
980 char *SSL_alert_desc_string_long();
981 char *SSL_alert_desc_string();
982
983 STACK *SSL_load_client_CA_file();
984 void SSL_set_client_CA_list();
985 void SSL_CTX_set_client_CA_list();
986 STACK *SSL_get_client_CA_list();
987 STACK *SSL_CTX_get_client_CA_list();
988 int SSL_add_client_CA();
989 int SSL_CTX_add_client_CA();
990
991 void SSL_set_connect_state();
992 void SSL_set_accept_state();
993
994 long SSL_get_default_timeout();
995
996 void SSLeay_add_ssl_algorithms();
997
998 char *SSL_CIPHER_description();
999 STACK *SSL_dup_CA_list();
1000
1001 SSL *SSL_dup();
1002
1003 X509 *SSL_get_certificate();
1004 /* EVP * */ struct evp_pkey_st *SSL_get_privatekey();
1005
1006 #ifdef this_is_for_mk1mf_pl
1007 EVP *SSL_get_privatekey();
1008 #endif
1009
1010 #endif
1011
1012 /* BEGIN ERROR CODES */
1013 /* Error codes for the SSL functions. */
1014
1015 /* Function codes. */
1016 #define SSL_F_CLIENT_CERTIFICATE                         100
1017 #define SSL_F_CLIENT_HELLO                               101
1018 #define SSL_F_CLIENT_MASTER_KEY                          102
1019 #define SSL_F_D2I_SSL_SESSION                            103
1020 #define SSL_F_DO_SSL3_WRITE                              104
1021 #define SSL_F_GET_CLIENT_FINISHED                        105
1022 #define SSL_F_GET_CLIENT_HELLO                           106
1023 #define SSL_F_GET_CLIENT_MASTER_KEY                      107
1024 #define SSL_F_GET_SERVER_FINISHED                        108
1025 #define SSL_F_GET_SERVER_HELLO                           109
1026 #define SSL_F_GET_SERVER_VERIFY                          110
1027 #define SSL_F_I2D_SSL_SESSION                            111
1028 #define SSL_F_READ_N                                     112
1029 #define SSL_F_REQUEST_CERTIFICATE                        113
1030 #define SSL_F_SERVER_HELLO                               114
1031 #define SSL_F_SSL23_ACCEPT                               115
1032 #define SSL_F_SSL23_CLIENT_HELLO                         116
1033 #define SSL_F_SSL23_CONNECT                              117
1034 #define SSL_F_SSL23_GET_CLIENT_HELLO                     118
1035 #define SSL_F_SSL23_GET_SERVER_HELLO                     119
1036 #define SSL_F_SSL23_READ                                 120
1037 #define SSL_F_SSL23_WRITE                                121
1038 #define SSL_F_SSL2_ACCEPT                                122
1039 #define SSL_F_SSL2_CONNECT                               123
1040 #define SSL_F_SSL2_ENC_INIT                              124
1041 #define SSL_F_SSL2_READ                                  125
1042 #define SSL_F_SSL2_SET_CERTIFICATE                       126
1043 #define SSL_F_SSL2_WRITE                                 127
1044 #define SSL_F_SSL3_ACCEPT                                128
1045 #define SSL_F_SSL3_CHANGE_CIPHER_STATE                   129
1046 #define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM              130
1047 #define SSL_F_SSL3_CLIENT_HELLO                          131
1048 #define SSL_F_SSL3_CONNECT                               132
1049 #define SSL_F_SSL3_CTX_CTRL                              133
1050 #define SSL_F_SSL3_ENC                                   134
1051 #define SSL_F_SSL3_GET_CERTIFICATE_REQUEST               135
1052 #define SSL_F_SSL3_GET_CERT_VERIFY                       136
1053 #define SSL_F_SSL3_GET_CLIENT_CERTIFICATE                137
1054 #define SSL_F_SSL3_GET_CLIENT_HELLO                      138
1055 #define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE               139
1056 #define SSL_F_SSL3_GET_FINISHED                          140
1057 #define SSL_F_SSL3_GET_KEY_EXCHANGE                      141
1058 #define SSL_F_SSL3_GET_MESSAGE                           142
1059 #define SSL_F_SSL3_GET_RECORD                            143
1060 #define SSL_F_SSL3_GET_SERVER_CERTIFICATE                144
1061 #define SSL_F_SSL3_GET_SERVER_DONE                       145
1062 #define SSL_F_SSL3_GET_SERVER_HELLO                      146
1063 #define SSL_F_SSL3_OUTPUT_CERT_CHAIN                     147
1064 #define SSL_F_SSL3_READ_BYTES                            148
1065 #define SSL_F_SSL3_READ_N                                149
1066 #define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST              150
1067 #define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE               151
1068 #define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE              152
1069 #define SSL_F_SSL3_SEND_CLIENT_VERIFY                    153
1070 #define SSL_F_SSL3_SEND_SERVER_CERTIFICATE               154
1071 #define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE              155
1072 #define SSL_F_SSL3_SETUP_BUFFERS                         156
1073 #define SSL_F_SSL3_SETUP_KEY_BLOCK                       157
1074 #define SSL_F_SSL3_WRITE_BYTES                           158
1075 #define SSL_F_SSL3_WRITE_PENDING                         159
1076 #define SSL_F_SSL_BAD_METHOD                             160
1077 #define SSL_F_SSL_BYTES_TO_CIPHER_LIST                   161
1078 #define SSL_F_SSL_CERT_NEW                               162
1079 #define SSL_F_SSL_CHECK_PRIVATE_KEY                      163
1080 #define SSL_F_SSL_CREATE_CIPHER_LIST                     164
1081 #define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY                  165
1082 #define SSL_F_SSL_CTX_NEW                                166
1083 #define SSL_F_SSL_CTX_SET_SSL_VERSION                    167
1084 #define SSL_F_SSL_CTX_USE_CERTIFICATE                    168
1085 #define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1               169
1086 #define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE               170
1087 #define SSL_F_SSL_CTX_USE_PRIVATEKEY                     171
1088 #define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1                172
1089 #define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE                173
1090 #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY                  174
1091 #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1             175
1092 #define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE             176
1093 #define SSL_F_SSL_DO_HANDSHAKE                           177
1094 #define SSL_F_SSL_GET_NEW_SESSION                        178
1095 #define SSL_F_SSL_GET_SERVER_SEND_CERT                   179
1096 #define SSL_F_SSL_GET_SIGN_PKEY                          180
1097 #define SSL_F_SSL_LOAD_CLIENT_CA_FILE                    181
1098 #define SSL_F_SSL_NEW                                    182
1099 #define SSL_F_SSL_RSA_PRIVATE_DECRYPT                    183
1100 #define SSL_F_SSL_RSA_PUBLIC_ENCRYPT                     184
1101 #define SSL_F_SSL_SESSION_NEW                            185
1102 #define SSL_F_SSL_SESSION_PRINT_FP                       186
1103 #define SSL_F_SSL_SET_FD                                 187
1104 #define SSL_F_SSL_SET_PKEY                               188
1105 #define SSL_F_SSL_SET_RFD                                189
1106 #define SSL_F_SSL_SET_SESSION                            190
1107 #define SSL_F_SSL_SET_WFD                                191
1108 #define SSL_F_SSL_UNDEFINED_FUNCTION                     192
1109 #define SSL_F_SSL_USE_CERTIFICATE                        193
1110 #define SSL_F_SSL_USE_CERTIFICATE_ASN1                   194
1111 #define SSL_F_SSL_USE_CERTIFICATE_FILE                   195
1112 #define SSL_F_SSL_USE_PRIVATEKEY                         196
1113 #define SSL_F_SSL_USE_PRIVATEKEY_ASN1                    197
1114 #define SSL_F_SSL_USE_PRIVATEKEY_FILE                    198
1115 #define SSL_F_SSL_USE_RSAPRIVATEKEY                      199
1116 #define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1                 200
1117 #define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE                 201
1118 #define SSL_F_SSL_WRITE                                  202
1119 #define SSL_F_WRITE_PENDING                              203
1120
1121 /* Reason codes. */
1122 #define SSL_R_APP_DATA_IN_HANDSHAKE                      100
1123 #define SSL_R_BAD_ALERT_RECORD                           101
1124 #define SSL_R_BAD_AUTHENTICATION_TYPE                    102
1125 #define SSL_R_BAD_CHANGE_CIPHER_SPEC                     103
1126 #define SSL_R_BAD_CHECKSUM                               104
1127 #define SSL_R_BAD_CLIENT_REQUEST                         105
1128 #define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK              106
1129 #define SSL_R_BAD_DECOMPRESSION                          107
1130 #define SSL_R_BAD_DH_G_LENGTH                            108
1131 #define SSL_R_BAD_DH_PUB_KEY_LENGTH                      109
1132 #define SSL_R_BAD_DH_P_LENGTH                            110
1133 #define SSL_R_BAD_DIGEST_LENGTH                          111
1134 #define SSL_R_BAD_DSA_SIGNATURE                          112
1135 #define SSL_R_BAD_MAC_DECODE                             113
1136 #define SSL_R_BAD_MESSAGE_TYPE                           114
1137 #define SSL_R_BAD_PACKET_LENGTH                          115
1138 #define SSL_R_BAD_RESPONSE_ARGUMENT                      116
1139 #define SSL_R_BAD_RSA_DECRYPT                            117
1140 #define SSL_R_BAD_RSA_ENCRYPT                            118
1141 #define SSL_R_BAD_RSA_E_LENGTH                           119
1142 #define SSL_R_BAD_RSA_MODULUS_LENGTH                     120
1143 #define SSL_R_BAD_RSA_SIGNATURE                          121
1144 #define SSL_R_BAD_SIGNATURE                              122
1145 #define SSL_R_BAD_SSL_FILETYPE                           123
1146 #define SSL_R_BAD_SSL_SESSION_ID_LENGTH                  124
1147 #define SSL_R_BAD_STATE                                  125
1148 #define SSL_R_BAD_WRITE_RETRY                            126
1149 #define SSL_R_BIO_NOT_SET                                127
1150 #define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG                  128
1151 #define SSL_R_BN_LIB                                     129
1152 #define SSL_R_CA_DN_LENGTH_MISMATCH                      130
1153 #define SSL_R_CA_DN_TOO_LONG                             131
1154 #define SSL_R_CCS_RECEIVED_EARLY                         132
1155 #define SSL_R_CERTIFICATE_VERIFY_FAILED                  133
1156 #define SSL_R_CERT_LENGTH_MISMATCH                       134
1157 #define SSL_R_CHALLENGE_IS_DIFFERENT                     135
1158 #define SSL_R_CIPHER_CODE_WRONG_LENGTH                   136
1159 #define SSL_R_CIPHER_OR_HASH_UNAVAILABLE                 137
1160 #define SSL_R_CIPHER_TABLE_SRC_ERROR                     138
1161 #define SSL_R_COMPRESSED_LENGTH_TOO_LONG                 139
1162 #define SSL_R_COMPRESSION_FAILURE                        140
1163 #define SSL_R_CONNECTION_ID_IS_DIFFERENT                 141
1164 #define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED              142
1165 #define SSL_R_DATA_LENGTH_TOO_LONG                       143
1166 #define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG            144
1167 #define SSL_R_DIGEST_CHECK_FAILED                        145
1168 #define SSL_R_ENCRYPTED_LENGTH_TOO_LONG                  146
1169 #define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST              147
1170 #define SSL_R_EXCESSIVE_MESSAGE_SIZE                     148
1171 #define SSL_R_EXTRA_DATA_IN_MESSAGE                      149
1172 #define SSL_R_GOT_A_FIN_BEFORE_A_CCS                     150
1173 #define SSL_R_INTERNAL_ERROR                             151
1174 #define SSL_R_INVALID_CHALLENGE_LENGTH                   152
1175 #define SSL_R_LENGTH_MISMATCH                            153
1176 #define SSL_R_LENGTH_TOO_SHORT                           154
1177 #define SSL_R_LIBRARY_HAS_NO_CIPHERS                     155
1178 #define SSL_R_MISSING_DH_DSA_CERT                        156
1179 #define SSL_R_MISSING_DH_KEY                             157
1180 #define SSL_R_MISSING_DH_RSA_CERT                        158
1181 #define SSL_R_MISSING_DSA_SIGNING_CERT                   159
1182 #define SSL_R_MISSING_EXPORT_TMP_DH_KEY                  160
1183 #define SSL_R_MISSING_EXPORT_TMP_RSA_KEY                 161
1184 #define SSL_R_MISSING_RSA_CERTIFICATE                    162
1185 #define SSL_R_MISSING_RSA_ENCRYPTING_CERT                163
1186 #define SSL_R_MISSING_RSA_SIGNING_CERT                   164
1187 #define SSL_R_MISSING_TMP_DH_KEY                         165
1188 #define SSL_R_MISSING_TMP_RSA_KEY                        166
1189 #define SSL_R_MISSING_TMP_RSA_PKEY                       167
1190 #define SSL_R_MISSING_VERIFY_MESSAGE                     168
1191 #define SSL_R_NON_SSLV2_INITIAL_PACKET                   169
1192 #define SSL_R_NO_CERTIFICATES_PASSED                     170
1193 #define SSL_R_NO_CERTIFICATE_ASSIGNED                    171
1194 #define SSL_R_NO_CERTIFICATE_RETURNED                    172
1195 #define SSL_R_NO_CERTIFICATE_SET                         173
1196 #define SSL_R_NO_CERTIFICATE_SPECIFIED                   174
1197 #define SSL_R_NO_CIPHERS_AVAILABLE                       175
1198 #define SSL_R_NO_CIPHERS_PASSED                          176
1199 #define SSL_R_NO_CIPHERS_SPECIFIED                       177
1200 #define SSL_R_NO_CIPHER_LIST                             178
1201 #define SSL_R_NO_CIPHER_MATCH                            179
1202 #define SSL_R_NO_CLIENT_CERT_RECEIVED                    180
1203 #define SSL_R_NO_COMPRESSION_SPECIFIED                   181
1204 #define SSL_R_NO_PRIVATEKEY                              182
1205 #define SSL_R_NO_PRIVATE_KEY_ASSIGNED                    183
1206 #define SSL_R_NO_PUBLICKEY                               184
1207 #define SSL_R_NO_SHARED_CIPHER                           185
1208 #define SSL_R_NULL_SSL_CTX                               186
1209 #define SSL_R_NULL_SSL_METHOD_PASSED                     187
1210 #define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED            188
1211 #define SSL_R_PACKET_LENGTH_TOO_LONG                     189
1212 #define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE          190
1213 #define SSL_R_PEER_ERROR                                 191
1214 #define SSL_R_PEER_ERROR_CERTIFICATE                     192
1215 #define SSL_R_PEER_ERROR_NO_CERTIFICATE                  193
1216 #define SSL_R_PEER_ERROR_NO_CIPHER                       194
1217 #define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE    195
1218 #define SSL_R_PRE_MAC_LENGTH_TOO_LONG                    196
1219 #define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS          197
1220 #define SSL_R_PROTOCOL_IS_SHUTDOWN                       198
1221 #define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR                   199
1222 #define SSL_R_PUBLIC_KEY_IS_NOT_RSA                      200
1223 #define SSL_R_PUBLIC_KEY_NOT_RSA                         201
1224 #define SSL_R_READ_BIO_NOT_SET                           202
1225 #define SSL_R_READ_WRONG_PACKET_TYPE                     203
1226 #define SSL_R_RECORD_LENGTH_MISMATCH                     204
1227 #define SSL_R_RECORD_TOO_LARGE                           205
1228 #define SSL_R_REQUIRED_CIPHER_MISSING                    206
1229 #define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO                 207
1230 #define SSL_R_REUSE_CERT_TYPE_NOT_ZERO                   208
1231 #define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO                 209
1232 #define SSL_R_SHORT_READ                                 210
1233 #define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE      211
1234 #define SSL_R_SSL3_SESSION_ID_TOO_SHORT                  212
1235 #define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE                1042
1236 #define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC                 1020
1237 #define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED            1045
1238 #define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED            1044
1239 #define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN            1046
1240 #define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE          1030
1241 #define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE              1040
1242 #define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER              1047
1243 #define SSL_R_SSLV3_ALERT_NO_CERTIFICATE                 1041
1244 #define SSL_R_SSLV3_ALERT_PEER_ERROR_CERTIFICATE         213
1245 #define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CERTIFICATE      214
1246 #define SSL_R_SSLV3_ALERT_PEER_ERROR_NO_CIPHER           215
1247 #define SSL_R_SSLV3_ALERT_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 216
1248 #define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE             1010
1249 #define SSL_R_SSLV3_ALERT_UNKNOWN_REMOTE_ERROR_TYPE      217
1250 #define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE        1043
1251 #define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION         218
1252 #define SSL_R_SSL_HANDSHAKE_FAILURE                      219
1253 #define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS                 220
1254 #define SSL_R_SSL_SESSION_ID_IS_DIFFERENT                221
1255 #define SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER            222
1256 #define SSL_R_UNABLE_TO_DECODE_DH_CERTS                  223
1257 #define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY               224
1258 #define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS               225
1259 #define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS       226
1260 #define SSL_R_UNABLE_TO_FIND_SSL_METHOD                  227
1261 #define SSL_R_UNEXPECTED_MESSAGE                         228
1262 #define SSL_R_UNEXPECTED_RECORD                          229
1263 #define SSL_R_UNKNOWN_ALERT_TYPE                         230
1264 #define SSL_R_UNKNOWN_CERTIFICATE_TYPE                   231
1265 #define SSL_R_UNKNOWN_CIPHER_RETURNED                    232
1266 #define SSL_R_UNKNOWN_CIPHER_TYPE                        233
1267 #define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE                  234
1268 #define SSL_R_UNKNOWN_PKEY_TYPE                          235
1269 #define SSL_R_UNKNOWN_PROTOCOL                           236
1270 #define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE                  237
1271 #define SSL_R_UNKNOWN_SSL_VERSION                        238
1272 #define SSL_R_UNKNOWN_STATE                              239
1273 #define SSL_R_UNSUPPORTED_CIPHER                         240
1274 #define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM          241
1275 #define SSL_R_UNSUPPORTED_SSL_VERSION                    242
1276 #define SSL_R_WRITE_BIO_NOT_SET                          243
1277 #define SSL_R_WRONG_CIPHER_RETURNED                      244
1278 #define SSL_R_WRONG_MESSAGE_TYPE                         245
1279 #define SSL_R_WRONG_NUMBER_OF_KEY_BITS                   246
1280 #define SSL_R_WRONG_SIGNATURE_LENGTH                     247
1281 #define SSL_R_WRONG_SIGNATURE_SIZE                       248
1282 #define SSL_R_WRONG_SSL_VERSION                          249
1283 #define SSL_R_WRONG_VERSION_NUMBER                       250
1284 #define SSL_R_X509_LIB                                   251
1285  
1286 #ifdef  __cplusplus
1287 }
1288 #endif
1289 #endif
1290