Skip to content

Latest commit

 

History

History
266 lines (232 loc) · 10.2 KB

openconnect.h

File metadata and controls

266 lines (232 loc) · 10.2 KB
 
Sep 22, 2008
Sep 22, 2008
1
/*
Nov 20, 2008
Nov 20, 2008
2
* OpenConnect (SSL + DTLS) VPN client
Sep 22, 2008
Sep 22, 2008
3
*
May 13, 2012
May 13, 2012
4
* Copyright © 2008-2012 Intel Corporation.
Apr 9, 2009
Apr 9, 2009
5
* Copyright © 2008 Nick Andrew <nick@nick-andrew.net>
Sep 22, 2008
Sep 22, 2008
6
*
Nov 20, 2008
Nov 20, 2008
7
8
9
* Author: David Woodhouse <dwmw2@infradead.org>
*
* This program is free software; you can redistribute it and/or
Oct 4, 2008
Oct 4, 2008
10
* modify it under the terms of the GNU Lesser General Public License
Nov 20, 2008
Nov 20, 2008
11
* version 2.1, as published by the Free Software Foundation.
Sep 22, 2008
Sep 22, 2008
12
*
Nov 20, 2008
Nov 20, 2008
13
* This program is distributed in the hope that it will be useful, but
Oct 4, 2008
Oct 4, 2008
14
15
16
17
18
19
20
21
22
23
* 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:
*
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
Sep 22, 2008
Sep 22, 2008
24
25
*/
Mar 9, 2011
Mar 9, 2011
26
27
#ifndef __OPENCONNECT_H__
#define __OPENCONNECT_H__
Oct 5, 2008
Oct 5, 2008
28
Sep 22, 2008
Sep 22, 2008
29
#include <stdint.h>
Oct 15, 2008
Oct 15, 2008
30
31
#include <sys/types.h>
#include <unistd.h>
Jan 2, 2010
Jan 2, 2010
32
Jun 8, 2012
Jun 8, 2012
33
#define OPENCONNECT_API_VERSION_MAJOR 2
Oct 15, 2012
Oct 15, 2012
34
#define OPENCONNECT_API_VERSION_MINOR 1
Mar 17, 2011
Mar 17, 2011
35
36
/*
Oct 15, 2012
Oct 15, 2012
37
* API version 2.1:
Nov 5, 2012
Nov 5, 2012
38
* - Add openconnect_set_reported_os()
Oct 15, 2012
Oct 15, 2012
39
40
* - Add openconnect_set_stoken_mode(), openconnect_has_stoken_support()
*
Jun 8, 2012
Jun 8, 2012
41
42
* API version 2.0:
* - OPENCONNECT_X509 is now an opaque type.
Jun 11, 2012
Jun 11, 2012
43
* - Add openconnect_has_pkcs11_support(), openconnect_has_tss_blob_support()
Jun 8, 2012
Jun 8, 2012
44
* - Rename openconnect_init_openssl() -> openconnect_init_ssl()
Jun 8, 2012
Jun 8, 2012
45
46
* - Rename openconnect_vpninfo_new_with_cbdata() -> openconnect_vpninfo_new()
* and kill the old openconnect_vpninfo_new() and its callback types.
Jun 8, 2012
Jun 8, 2012
47
*
May 31, 2012
May 31, 2012
48
49
50
* API version 1.5:
* - Add openconnect_get_cert_details(), openconnect_get_cert_DER().
*
May 12, 2012
May 12, 2012
51
52
53
* API version 1.4:
* - Add openconnect_set_cancel_fd()
*
Sep 30, 2011
Sep 30, 2011
54
55
56
* API version 1.3:
* - Add openconnect_set_cert_expiry_warning() to change from default 60 days
*
Jun 27, 2011
Jun 27, 2011
57
58
59
* API version 1.2:
* - Add openconnect_vpninfo_new_with_cbdata()
*
Mar 17, 2011
Mar 17, 2011
60
61
62
63
64
65
* API version 1.1:
* - Add openconnect_vpninfo_free()
*
* API version 1.0:
* - Initial version
*/
Sep 22, 2008
Sep 22, 2008
66
May 13, 2012
May 13, 2012
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Before API version 1.4 (OpenConnect 3.19) this macro didn't exist.
* Somewhat ironic, that the API version check itself needs to be
* conditionally used depending on the API version. A very simple way
* for users to handle this with an approximately correct answer is
* #include <openconnect.h>
* #ifndef OPENCONNECT_CHECK_VER
* #define OPENCONNECT_CHECK_VER(x,y) 0
* #endif
*/
#define OPENCONNECT_CHECK_VER(maj,min) \
(OPENCONNECT_API_VERSION_MAJOR > (maj) || \
(OPENCONNECT_API_VERSION_MAJOR == (maj) && \
OPENCONNECT_API_VERSION_MINOR >= (min)))
Apr 22, 2009
Apr 22, 2009
81
82
83
84
85
86
87
88
/****************************************************************************/
/* Authentication form processing */
#define OC_FORM_OPT_TEXT 1
#define OC_FORM_OPT_PASSWORD 2
#define OC_FORM_OPT_SELECT 3
#define OC_FORM_OPT_HIDDEN 4
Oct 15, 2012
Oct 15, 2012
89
#define OC_FORM_OPT_STOKEN 5
Apr 22, 2009
Apr 22, 2009
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
/* char * fields are static (owned by XML parser) and don't need to be
freed by the form handling code -- except for value, which for TEXT
and PASSWORD options is allocated by process_form() when
interacting with the user and must be freed. */
struct oc_form_opt {
struct oc_form_opt *next;
int type;
char *name;
char *label;
char *value;
};
/* All fields are static, owned by the XML parser */
struct oc_choice {
char *name;
char *label;
char *auth_type;
char *override_name;
char *override_label;
};
struct oc_form_opt_select {
struct oc_form_opt form;
int nr_choices;
struct oc_choice choices[0];
};
/* All char * fields are static, owned by the XML parser */
struct oc_auth_form {
char *banner;
char *message;
char *error;
char *auth_id;
char *method;
char *action;
struct oc_form_opt *opts;
};
/****************************************************************************/
Oct 5, 2008
Oct 5, 2008
131
132
133
134
135
#define PRG_ERR 0
#define PRG_INFO 1
#define PRG_DEBUG 2
#define PRG_TRACE 3
Mar 9, 2011
Mar 9, 2011
136
struct openconnect_info;
May 29, 2012
May 29, 2012
137
Jun 8, 2012
Jun 8, 2012
138
#define OPENCONNECT_X509 void
Mar 17, 2011
Mar 17, 2011
139
Jun 14, 2012
Jun 14, 2012
140
141
/* Unless otherwise specified, all functions which set strings will take
ownership of those strings and the library will free them later in
Jun 14, 2012
Jun 14, 2012
142
143
144
145
146
openconnect_vpninfo_free() */
/* The buffer 'buf' must be at least 41 bytes. It will receive a hex string
with trailing NUL, representing the SHA1 fingerprint of the certificate. */
Mar 9, 2011
Mar 9, 2011
147
int openconnect_get_cert_sha1(struct openconnect_info *vpninfo,
May 29, 2012
May 29, 2012
148
OPENCONNECT_X509 *cert, char *buf);
May 29, 2012
May 29, 2012
149
char *openconnect_get_cert_details(struct openconnect_info *vpninfo,
May 29, 2012
May 29, 2012
150
OPENCONNECT_X509 *cert);
May 29, 2012
May 29, 2012
151
152
153
/* Returns the length of the created DER output, in a newly-allocated buffer
that will need to be freed by the caller. */
int openconnect_get_cert_DER(struct openconnect_info *vpninfo,
May 29, 2012
May 29, 2012
154
OPENCONNECT_X509 *cert, unsigned char **buf);
Mar 9, 2011
Mar 9, 2011
155
int openconnect_set_http_proxy(struct openconnect_info *vpninfo, char *proxy);
Nov 16, 2010
Nov 16, 2010
156
int openconnect_passphrase_from_fsid(struct openconnect_info *vpninfo);
Oct 5, 2008
Oct 5, 2008
157
int openconnect_obtain_cookie(struct openconnect_info *vpninfo);
Jun 8, 2012
Jun 8, 2012
158
void openconnect_init_ssl(void);
Oct 5, 2008
Oct 5, 2008
159
Mar 9, 2011
Mar 9, 2011
160
161
162
163
164
char *openconnect_get_vpn_name (struct openconnect_info *);
char *openconnect_get_hostname (struct openconnect_info *);
void openconnect_set_hostname (struct openconnect_info *, char *);
char *openconnect_get_urlpath (struct openconnect_info *);
void openconnect_set_urlpath (struct openconnect_info *, char *);
Mar 17, 2011
Mar 17, 2011
165
Oct 15, 2012
Oct 15, 2012
166
167
168
169
170
/* This function does *not* take ownership of the string; it is parsed
and then discarded. */
int openconnect_set_stoken_mode (struct openconnect_info *,
int use_stoken, const char *token_str);
Mar 17, 2011
Mar 17, 2011
171
/* This function does *not* take ownership of the string; it's copied
Jun 14, 2012
Jun 14, 2012
172
173
174
into a static buffer in the vpninfo. The size must be 41 bytes,
since that's the size of a 20-byte SHA1 represented as hex with
a trailing NUL. */
Jun 1, 2012
Jun 1, 2012
175
void openconnect_set_xmlsha1 (struct openconnect_info *, const char *, int size);
Mar 17, 2011
Mar 17, 2011
176
Mar 9, 2011
Mar 9, 2011
177
178
void openconnect_set_cafile (struct openconnect_info *, char *);
void openconnect_setup_csd (struct openconnect_info *, uid_t, int silent, char *wrapper);
Oct 28, 2012
Oct 28, 2012
179
int openconnect_set_reported_os (struct openconnect_info *, const char *os);
Mar 9, 2011
Mar 9, 2011
180
void openconnect_set_client_cert (struct openconnect_info *, char *cert, char *sslkey);
May 17, 2012
May 17, 2012
181
182
183
184
185
/* This is *not* yours and must not be destroyed with X509_free(). It
* will be valid when a cookie has been obtained successfully, and will
* be valid until the connection is destroyed or another attempt it made
* to use it. */
May 29, 2012
May 29, 2012
186
OPENCONNECT_X509 *openconnect_get_peer_cert (struct openconnect_info *);
May 17, 2012
May 17, 2012
187
Mar 9, 2011
Mar 9, 2011
188
189
190
191
192
193
int openconnect_get_port (struct openconnect_info *);
char *openconnect_get_cookie (struct openconnect_info *);
void openconnect_clear_cookie (struct openconnect_info *);
void openconnect_reset_ssl (struct openconnect_info *vpninfo);
int openconnect_parse_url (struct openconnect_info *vpninfo, char *url);
Sep 30, 2011
Sep 30, 2011
194
195
void openconnect_set_cert_expiry_warning (struct openconnect_info *vpninfo,
int seconds);
May 12, 2012
May 12, 2012
196
197
198
199
200
201
202
203
204
205
206
207
/* If this is set, then openconnect_obtain_cookie() will abort and return
failure if the file descriptor is readable. Typically a user may create
a pair of pipes with the pipe(2) system call, hand the readable one to
this function, and then write a byte to the other end if it ever wants
to cancel the connection. This way, a multi-threaded UI (which will be
running openconnect_obtain_cookie() in a separate thread since it blocks)
has the ability to cancel that call, reap its thread and free the
vpninfo structure (or retry). An 'fd' argument of -1 will render the
cancellation mechanism inactive. */
void openconnect_set_cancel_fd (struct openconnect_info *vpninfo, int fd);
Mar 9, 2011
Mar 9, 2011
208
const char *openconnect_get_version(void);
Mar 9, 2011
Mar 9, 2011
209
Jun 27, 2011
Jun 27, 2011
210
/* The first (privdata) argument to each of these functions is either
Jan 11, 2012
Jan 11, 2012
211
212
213
214
215
216
217
218
219
220
221
the privdata argument provided to openconnect_vpninfo_new_with_cbdata(),
or if that argument was NULL then it'll be the vpninfo itself. */
/* When the server's certificate fails validation via the normal means,
this function is called with the offending certificate along with
a textual reason for the failure (which may not be translated, if
it comes directly from OpenSSL, but will be if it is rejected for
"certificate does not match hostname", because that check is done
in OpenConnect and *is* translated). The function shall return zero
if the certificate is (or has in the past been) explicitly accepted
by the user, and non-zero to abort the connection. */
Jun 27, 2011
Jun 27, 2011
222
typedef int (*openconnect_validate_peer_cert_vfn) (void *privdata,
May 29, 2012
May 29, 2012
223
224
OPENCONNECT_X509 *cert,
const char *reason);
Jan 11, 2012
Jan 11, 2012
225
226
227
228
229
230
231
/* On a successful connection, the server may provide us with a new XML
configuration file. This contains the list of servers that can be
chosen by the user to connect to, amongst other stuff that we mostly
ignore. By "new", we mean that the SHA1 indicated by the server does
not match the SHA1 set with the openconnect_set_xmlsha1() above. If
they don't match, or openconnect_set_xmlsha1() has not been called,
then the new XML is downloaded and this function is invoked. */
Jun 27, 2011
Jun 27, 2011
232
233
typedef int (*openconnect_write_new_config_vfn) (void *privdata, char *buf,
int buflen);
May 29, 2012
May 29, 2012
234
235
236
237
238
239
/* Handle an authentication form, requesting input from the user.
* Return value:
* < 0, on error
* = 0, when form was parsed and POST required
* = 1, when response was cancelled by user
*/
Jun 27, 2011
Jun 27, 2011
240
241
typedef int (*openconnect_process_auth_form_vfn) (void *privdata,
struct oc_auth_form *form);
Jan 11, 2012
Jan 11, 2012
242
/* Logging output which the user *may* want to see. */
Jun 27, 2011
Jun 27, 2011
243
244
245
typedef void __attribute__ ((format(printf, 3, 4)))
(*openconnect_progress_vfn) (void *privdata, int level,
const char *fmt, ...);
Jun 8, 2012
Jun 8, 2012
246
struct openconnect_info *openconnect_vpninfo_new (char *useragent,
Jan 11, 2012
Jan 11, 2012
247
248
249
250
251
252
openconnect_validate_peer_cert_vfn,
openconnect_write_new_config_vfn,
openconnect_process_auth_form_vfn,
openconnect_progress_vfn,
void *privdata);
void openconnect_vpninfo_free (struct openconnect_info *vpninfo);
Jun 27, 2011
Jun 27, 2011
253
Jun 11, 2012
Jun 11, 2012
254
255
256
257
/* SSL certificate capabilities. openconnect_has_pkcs11_support() means that we
can accept PKCS#11 URLs in place of filenames, for the certificate and key. */
int openconnect_has_pkcs11_support(void);
Jun 11, 2012
Jun 11, 2012
258
259
260
261
262
/* The OpenSSL TPM ENGINE stores keys in a PEM file labelled with the string
-----BEGIN TSS KEY BLOB-----. GnuTLS may learn to support this format too,
in the near future. */
int openconnect_has_tss_blob_support(void);
Oct 15, 2012
Oct 15, 2012
263
264
265
/* Software token capabilities. */
int openconnect_has_stoken_support(void);
Mar 9, 2011
Mar 9, 2011
266
#endif /* __OPENCONNECT_H__ */