NIXIO: TLS-Support, bugfixes
[project/luci.git] / libs / nixio / src / openssl-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 "config.h"
40
41 #define WITH_AXTLS                                              1
42 #define WITHOUT_OPENSSL                                 1
43 #define SSL_OP_NO_SSLv3                                 0x02000000L
44 #define SSL_OP_NO_SSLv2                                 0x01000000L
45 #define SSL_FILETYPE_PEM                                1
46 #define SSL_VERIFY_NONE                                 0x00
47 #define SSL_VERIFY_PEER                                 0x01
48 #define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
49 #define SSL_VERIFY_CLIENT_ONCE                  0x03
50
51 #include <stdlib.h>
52 #include <string.h>
53 #include <stdarg.h>
54 #include "ssl.h"
55
56 void *SSLv23_server_method(void);
57 void *SSLv3_server_method(void);
58 void *TLSv1_server_method(void);
59 void *SSLv23_client_method(void);
60 void *SSLv3_client_method(void);
61 void *TLSv1_client_method(void);
62 void *SSLv23_method(void);
63 void *TLSv1_method(void);
64
65
66 typedef void * (*ssl_func_type_t)(void);
67 typedef void * (*bio_func_type_t)(void);
68
69 SSL_CTX * SSL_CTX_new(void *meth);
70 void SSL_CTX_free(SSL_CTX * ssl_ctx);
71 SSL * SSL_new(SSL_CTX *ssl_ctx);
72 int SSL_set_fd(SSL *s, int fd);
73 int SSL_accept(SSL *ssl);
74 int SSL_connect(SSL *ssl);
75 void SSL_free(SSL *ssl);
76 int SSL_read(SSL *ssl, void *buf, int num);
77 int SSL_write(SSL *ssl, const void *buf, int num);
78 int SSL_CTX_use_certificate_file(SSL_CTX *ssl_ctx, const char *file, int type);
79 int SSL_CTX_use_PrivateKey_file(SSL_CTX *ssl_ctx, const char *file, int type);
80 int SSL_CTX_use_certificate_ASN1(SSL_CTX *ssl_ctx, int len, const uint8_t *d);
81 int SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx,
82                                             unsigned int sid_ctx_len);
83 int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
84 int SSL_CTX_use_certificate_chain_file(SSL_CTX *ssl_ctx, const char *file);
85 int SSL_shutdown(SSL *ssl);
86
87 /*** get/set session ***/
88 SSL_SESSION *SSL_get1_session(SSL *ssl);
89 int SSL_set_session(SSL *ssl, SSL_SESSION *session);
90 void SSL_SESSION_free(SSL_SESSION *session);
91 /*** end get/set session ***/
92
93 long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg);
94 void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
95                                  int (*verify_callback)(int, void *));
96
97 void SSL_CTX_set_verify_depth(SSL_CTX *ctx,int depth);
98
99 int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
100                                            const char *CApath);
101
102 void *SSL_load_client_CA_file(const char *file);
103
104 void SSL_CTX_set_client_CA_list(SSL_CTX *ssl_ctx, void *file);
105
106 void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, void *cb);
107
108 void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
109
110 int SSL_peek(SSL *ssl, void *buf, int num);
111
112 void SSL_set_bio(SSL *ssl, void *rbio, void *wbio);
113
114 long SSL_get_verify_result(const SSL *ssl);
115
116 int SSL_state(SSL *ssl);
117
118 /** end of could do better list */
119
120 void *SSL_get_peer_certificate(const SSL *ssl);
121
122 int SSL_clear(SSL *ssl);
123
124
125 int SSL_CTX_check_private_key(const SSL_CTX *ctx);
126
127 int SSL_CTX_set_cipher_list(SSL_CTX *s, const char *str);
128
129 int SSL_get_error(const SSL *ssl, int ret);
130
131 void SSL_CTX_set_options(SSL_CTX *ssl_ctx, int option);
132 int SSL_library_init(void );
133 void SSL_load_error_strings(void );
134 void ERR_print_errors_fp(FILE *fp);
135
136 long SSL_CTX_get_timeout(const SSL_CTX *ssl_ctx);
137 long SSL_CTX_set_timeout(SSL_CTX *ssl_ctx, long t);
138 void BIO_printf(FILE *f, const char *format, ...);
139
140 void* BIO_s_null(void);
141 FILE *BIO_new(bio_func_type_t func);
142
143 FILE *BIO_new_fp(FILE *stream, int close_flag);
144 int BIO_free(FILE *a);