forked from SWI-Prolog/packages-ssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssllib.h
173 lines (147 loc) · 6.01 KB
/
ssllib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* $Id$
Part of SWI-Prolog
Author: Jan van der Steen and Jan Wielemaker
E-mail: [email protected] and [email protected]
WWW: http://www.swi-prolog.org
Copyright (C): 1985-2002, SWI-Prolog Foundation
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SSLLIBH__
#define SSLLIBH__
#include "../clib/nonblockio.h"
#define SSL_CONFIG_MAGIC 0x539dbe3a
typedef int BOOL;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
typedef enum
{ PL_SSL_NONE
, PL_SSL_SERVER
, PL_SSL_CLIENT
} PL_SSL_ROLE;
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
typedef struct pl_ssl {
long magic;
/*
* Are we server or client
*/
PL_SSL_ROLE pl_ssl_role;
int sock; /* the listening/connected socket */
int closeparent;
/*
* Context, Certificate, SSL info
*/
SSL * pl_ssl_ssl;
SSL_CTX * pl_ssl_ctx;
int pl_ssl_idx;
X509 * pl_ssl_peer_cert;
/*
* In case of the server the hosts we're accepting (NULL for any),
* in case of the client the host we're connecting to.
* We also store the socket file descriptor.
*/
char * pl_ssl_host;
int pl_ssl_port;
/*
* Various parameters affecting the SSL layer
*/
char * pl_ssl_cacert;
char * pl_ssl_certf;
char * pl_ssl_keyf;
char * pl_ssl_password;
BOOL pl_ssl_cert_required;
BOOL pl_ssl_peer_cert_required;
BOOL pl_ssl_reuseaddr;
/*
* Application defined handlers
*/
BOOL (*pl_ssl_cb_cert_verify)( struct pl_ssl *config
, X509*
, X509_STORE_CTX*
, const char *error
) ;
void * pl_ssl_cb_cert_verify_data;
char * (*pl_ssl_cb_pem_passwd) ( struct pl_ssl *
, char *
, int
) ;
void * pl_ssl_cb_pem_passwd_data;
} PL_SSL;
typedef struct ssl_instance {
PL_SSL *config;
SSL *ssl;
nbio_sock_t sock;
IOSTREAM *sread;
IOSTREAM *swrite;
int close_needed;
} PL_SSL_INSTANCE;
/*
* The PL-SSL API
*/
int ssl_lib_init (void);
int ssl_lib_exit (void);
PL_SSL * ssl_init (PL_SSL_ROLE role);
int ssl_socket (PL_SSL *config);
PL_SSL_INSTANCE *ssl_ssl_bio (PL_SSL *config, IOSTREAM* sread, IOSTREAM* swrite);
PL_SSL_INSTANCE *ssl_ssl (PL_SSL *config, int sock);
void ssl_exit (PL_SSL *config);
int ssl_close (PL_SSL_INSTANCE *instance);
int ssl_accept (PL_SSL *config, void *addr, socklen_t *addrlen);
int ssl_connect (PL_SSL *config);
int ssl_read ( PL_SSL_INSTANCE *instance
, char *buf, int size
) ;
int ssl_write ( PL_SSL_INSTANCE *instance
, const char *buf, int size
) ;
int ssl_thread_setup (void);
char * ssl_set_host (PL_SSL *config, const char *host);
int ssl_set_port (PL_SSL *config, int port);
char * ssl_set_cacert (PL_SSL *config, const char *cacert);
char * ssl_set_certf (PL_SSL *config, const char *certf);
char * ssl_set_keyf (PL_SSL *config, const char *keyf);
char * ssl_set_password (PL_SSL *config, const char *password);
BOOL ssl_set_reuseaddr(PL_SSL *config, BOOL reuse);
BOOL ssl_set_cert (PL_SSL *config, BOOL required);
BOOL ssl_set_peer_cert(PL_SSL *config, BOOL required);
BOOL ssl_set_close_parent(PL_SSL *config, int closeparent);
BOOL ssl_set_cb_cert_verify
( PL_SSL *config
, BOOL (*callback)( PL_SSL *
, X509*
, X509_STORE_CTX*
, const char *
)
, void *
) ;
BOOL ssl_set_cb_pem_passwd
( PL_SSL *config
, char * (*callback)( PL_SSL *
, char *
, int
)
, void *
) ;
void ssl_msg (char *fmt, ...);
void ssl_err (char *fmt, ...);
int ssl_set_debug (int level);
void ssl_deb (int level, char *fmt, ...);
extern BIO_METHOD bio_read_functions;
extern BIO_METHOD bio_write_functions;
#endif