Merge pull request #302 from chris5560/master
[project/luci.git] / libs / luci-lib-nixio / src / axtls-compat.h
1 /*
2  * Copyright (c) 2007, Cameron Rich
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice,
10  *   this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  *   this list of conditions and the following disclaimer in the documentation
13  *   and/or other materials provided with the distribution.
14  * * Neither the name of the axTLS project nor the names of its contributors
15  *   may be used to endorse or promote products derived from this software
16  *   without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 /*
32  * Enable a subset of openssl compatible functions. We don't aim to be 100%
33  * compatible - just to be able to do basic ports etc.
34  *
35  * Only really tested on mini_httpd, so I'm not too sure how extensive this
36  * port is.
37  */
38
39 #include "nixio.h"
40 #include "config.h"
41
42 #define WITH_AXTLS                                              1
43 #define WITHOUT_OPENSSL                                 1
44 #define SSL_OP_NO_SSLv3                                 0x02000000L
45 #define SSL_OP_NO_SSLv2                                 0x01000000L
46 #define SSL_FILETYPE_PEM                                1
47 #define SSL_FILETYPE_ASN1                               2
48 #define SSL_VERIFY_NONE                                 0x00
49 #define SSL_VERIFY_PEER                                 0x01
50 #define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
51 #define SSL_VERIFY_CLIENT_ONCE                  0x03
52 #define MD5_DIGEST_LENGTH                               16
53 #define SHA_DIGEST_LENGTH                               20
54
55 #include <stdlib.h>
56 #include <string.h>
57 #include <stdarg.h>
58 #include "ssl.h"
59
60 typedef SHA1_CTX SHA_CTX;
61
62 void *SSLv23_server_method(void);
63 void *SSLv3_server_method(void);
64 void *TLSv1_server_method(void);
65 void *SSLv23_client_method(void);
66 void *SSLv3_client_method(void);
67 void *TLSv1_client_method(void);
68 void *SSLv23_method(void);
69 void *TLSv1_method(void);
70
71
72 typedef void * (*ssl_func_type_t)(void);
73 typedef void * (*bio_func_type_t)(void);
74
75 SSL_CTX * SSL_CTX_new(void *meth);
76 void SSL_CTX_free(SSL_CTX * ssl_ctx);
77 SSL * SSL_new(SSL_CTX *ssl_ctx);
78 int SSL_set_fd(SSL *s, int fd);
79 int SSL_accept(SSL *ssl);
80 int SSL_connect(SSL *ssl);
81 void SSL_free(SSL *ssl);
82 int SSL_read(SSL *ssl, void *buf, int num);
83 int SSL_write(SSL *ssl, const void *buf, int num);
84 int SSL_CTX_use_certificate_file(SSL_CTX *ssl_ctx, const char *file, int type);
85 int SSL_CTX_use_PrivateKey_file(SSL_CTX *ssl_ctx, const char *file, int type);
86 int SSL_CTX_use_certificate_ASN1(SSL_CTX *ssl_ctx, int len, const uint8_t *d);
87 int SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx,
88                                             unsigned int sid_ctx_len);
89 int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
90 int SSL_CTX_use_certificate_chain_file(SSL_CTX *ssl_ctx, const char *file);
91 int SSL_shutdown(SSL *ssl);
92
93 /*** get/set session ***/
94 SSL_SESSION *SSL_get1_session(SSL *ssl);
95 int SSL_set_session(SSL *ssl, SSL_SESSION *session);
96 void SSL_SESSION_free(SSL_SESSION *session);
97 /*** end get/set session ***/
98
99 long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg);
100 void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
101                                  int (*verify_callback)(int, void *));
102
103 void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
104
105 int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
106                                            const char *CApath);
107
108 void *SSL_load_client_CA_file(const char *file);
109
110 void SSL_CTX_set_client_CA_list(SSL_CTX *ssl_ctx, void *file);
111
112 void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, void *cb);
113
114 void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
115
116 int SSL_peek(SSL *ssl, void *buf, int num);
117
118 void SSL_set_bio(SSL *ssl, void *rbio, void *wbio);
119
120 long SSL_get_verify_result(const SSL *ssl);
121
122 int SSL_state(SSL *ssl);
123
124 /** end of could do better list */
125
126 void *SSL_get_peer_certificate(const SSL *ssl);
127
128 int SSL_clear(SSL *ssl);
129
130
131 int SSL_CTX_check_private_key(const SSL_CTX *ctx);
132
133 int SSL_CTX_set_cipher_list(SSL_CTX *s, const char *str);
134
135 int SSL_get_error(const SSL *ssl, int ret);
136
137 void SSL_CTX_set_options(SSL_CTX *ssl_ctx, int option);
138 int SSL_library_init(void );
139 void SSL_load_error_strings(void );
140 void ERR_print_errors_fp(FILE *fp);
141
142 long SSL_CTX_get_timeout(const SSL_CTX *ssl_ctx);
143 long SSL_CTX_set_timeout(SSL_CTX *ssl_ctx, long t);
144 void BIO_printf(FILE *f, const char *format, ...);
145
146 void* BIO_s_null(void);
147 FILE *BIO_new(bio_func_type_t func);
148
149 FILE *BIO_new_fp(FILE *stream, int close_flag);
150 int BIO_free(FILE *a);