Skip to content

Latest commit

 

History

History
434 lines (374 loc) · 11.4 KB

openconnect-internal.h

File metadata and controls

434 lines (374 loc) · 11.4 KB
 
1
2
3
/*
* OpenConnect (SSL + DTLS) VPN client
*
May 13, 2012
May 13, 2012
4
* Copyright © 2008-2012 Intel Corporation.
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
* Copyright © 2008 Nick Andrew <nick@nick-andrew.net>
*
* Author: David Woodhouse <dwmw2@infradead.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1, as published by the Free Software Foundation.
*
* This program 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:
*
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef __OPENCONNECT_INTERNAL_H__
#define __OPENCONNECT_INTERNAL_H__
#include "openconnect.h"
Jun 11, 2012
Jun 11, 2012
31
#if defined (OPENCONNECT_OPENSSL) || defined(DTLS_OPENSSL)
32
#include <openssl/ssl.h>
Jun 11, 2012
Jun 11, 2012
33
#include <openssl/err.h>
Jun 15, 2012
Jun 15, 2012
34
35
36
37
38
/* Ick */
#if OPENSSL_VERSION_NUMBER >= 0x00909000L
#define method_const const
#else
#define method_const
Jun 11, 2012
Jun 11, 2012
39
#endif
Jun 15, 2012
Jun 15, 2012
40
41
#endif /* OPENSSL */
Jun 11, 2012
Jun 11, 2012
42
#if defined (OPENCONNECT_GNUTLS)
May 29, 2012
May 29, 2012
43
#include <gnutls/gnutls.h>
Jun 14, 2012
Jun 14, 2012
44
#include <gnutls/abstract.h>
May 29, 2012
May 29, 2012
45
#include <gnutls/x509.h>
Jun 13, 2012
Jun 13, 2012
46
47
48
49
#ifdef HAVE_TROUSERS
#include <trousers/tss.h>
#include <trousers/trousers.h>
#endif
May 29, 2012
May 29, 2012
50
51
#endif
52
53
54
55
56
57
58
#include <zlib.h>
#include <stdint.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
May 29, 2012
May 29, 2012
59
Sep 22, 2011
Sep 22, 2011
60
#ifdef LIBPROXY_HDR
61
62
#include LIBPROXY_HDR
#endif
May 29, 2012
May 29, 2012
63
Oct 15, 2012
Oct 15, 2012
64
65
66
67
#ifdef LIBSTOKEN_HDR
#include LIBSTOKEN_HDR
#endif
Sep 22, 2011
Sep 22, 2011
68
#ifdef ENABLE_NLS
Nov 3, 2011
Nov 3, 2011
69
#include <locale.h>
Sep 22, 2011
Sep 22, 2011
70
#include <libintl.h>
Sep 22, 2011
Sep 22, 2011
71
#define _(s) dgettext("openconnect", s)
Sep 22, 2011
Sep 22, 2011
72
73
74
#else
#define _(s) s
#endif
Sep 22, 2011
Sep 22, 2011
75
#define N_(s) s
Oct 28, 2012
Oct 28, 2012
77
78
#include <libxml/tree.h>
May 29, 2012
May 29, 2012
79
#define SHA1_SIZE 20
May 29, 2012
May 29, 2012
80
#define MD5_SIZE 16
May 29, 2012
May 29, 2012
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
/****************************************************************************/
struct pkt {
int len;
struct pkt *next;
unsigned char hdr[8];
unsigned char data[];
};
struct vpn_option {
char *option;
char *value;
struct vpn_option *next;
};
#define KA_NONE 0
#define KA_DPD 1
#define KA_DPD_DEAD 2
#define KA_KEEPALIVE 3
#define KA_REKEY 4
struct keepalive_info {
int dpd;
int keepalive;
int rekey;
time_t last_rekey;
time_t last_tx;
time_t last_rx;
time_t last_dpd;
};
struct split_include {
char *route;
struct split_include *next;
};
Jun 10, 2012
Jun 10, 2012
118
119
120
121
122
123
struct pin_cache {
struct pin_cache *next;
char *token;
char *pin;
};
124
125
126
127
128
129
130
131
#define RECONNECT_INTERVAL_MIN 10
#define RECONNECT_INTERVAL_MAX 100
#define CERT_TYPE_UNKNOWN 0
#define CERT_TYPE_PEM 1
#define CERT_TYPE_PKCS12 2
#define CERT_TYPE_TPM 3
Oct 28, 2012
Oct 28, 2012
132
133
134
135
#define REDIR_TYPE_NONE 0
#define REDIR_TYPE_NEWHOST 1
#define REDIR_TYPE_LOCAL 2
136
137
struct openconnect_info {
char *redirect_url;
Oct 28, 2012
Oct 28, 2012
138
int redirect_type;
Jul 12, 2012
Jul 12, 2012
140
const char *csd_xmltag;
Oct 28, 2012
Oct 28, 2012
141
const char *platname;
142
143
144
145
146
147
148
149
char *csd_token;
char *csd_ticket;
char *csd_stuburl;
char *csd_starturl;
char *csd_waiturl;
char *csd_preurl;
char *csd_scriptname;
Oct 28, 2012
Oct 28, 2012
150
xmlNode *opaque_srvdata;
Sep 22, 2011
Sep 22, 2011
152
#ifdef LIBPROXY_HDR
153
154
155
156
157
158
159
160
161
162
pxProxyFactory *proxy_factory;
#endif
char *proxy_type;
char *proxy;
int proxy_port;
const char *localname;
char *hostname;
int port;
char *urlpath;
Sep 29, 2011
Sep 29, 2011
163
int cert_expire_warning;
164
165
166
167
168
169
170
const char *cert;
const char *sslkey;
int cert_type;
char *cert_password;
const char *cafile;
const char *servercert;
const char *xmlconfig;
May 29, 2012
May 29, 2012
171
char xmlsha1[(SHA1_SIZE * 2) + 1];
172
173
174
175
176
177
178
179
180
181
char *username;
char *password;
char *authgroup;
int nopasswd;
char *dtls_ciphers;
uid_t uid_csd;
char *csd_wrapper;
int uid_csd_given;
int no_http_keepalive;
Oct 15, 2012
Oct 15, 2012
182
183
184
185
186
187
188
189
190
#ifdef LIBSTOKEN_HDR
struct stoken_ctx *stoken_ctx;
#endif
int use_stoken;
int stoken_bypassed;
int stoken_tries;
time_t stoken_time;
char *stoken_pin;
May 29, 2012
May 29, 2012
191
OPENCONNECT_X509 *peer_cert;
May 17, 2012
May 17, 2012
192
Mar 17, 2011
Mar 17, 2011
193
char *cookie; /* Pointer to within cookies list */
194
195
196
197
struct vpn_option *cookies;
struct vpn_option *cstp_options;
struct vpn_option *dtls_options;
May 29, 2012
May 29, 2012
198
199
#if defined(OPENCONNECT_OPENSSL)
X509 *cert_x509;
200
201
SSL_CTX *https_ctx;
SSL *https_ssl;
May 29, 2012
May 29, 2012
202
203
204
#elif defined(OPENCONNECT_GNUTLS)
gnutls_session_t https_sess;
gnutls_certificate_credentials_t https_cred;
Jun 10, 2012
Jun 10, 2012
205
struct pin_cache *pin_cache;
Jun 13, 2012
Jun 13, 2012
206
207
208
209
210
#ifdef HAVE_TROUSERS
TSS_HCONTEXT tpm_context;
TSS_HKEY srk;
TSS_HPOLICY srk_policy;
TSS_HKEY tpm_key;
Jun 13, 2012
Jun 13, 2012
211
TSS_HPOLICY tpm_key_policy;
Jun 13, 2012
Jun 13, 2012
212
#endif
Jun 14, 2012
Jun 14, 2012
213
214
215
#ifndef HAVE_GNUTLS_CERTIFICATE_SET_KEY
#ifdef HAVE_P11KIT
gnutls_pkcs11_privkey_t my_p11key;
May 29, 2012
May 29, 2012
216
#endif
Jun 14, 2012
Jun 14, 2012
217
218
219
220
221
gnutls_privkey_t my_pkey;
gnutls_x509_crt_t *my_certs;
unsigned int nr_my_certs;
#endif
#endif /* OPENCONNECT_GNUTLS */
222
223
224
225
struct keepalive_info ssl_times;
int owe_ssl_dpd_response;
struct pkt *deflate_pkt;
struct pkt *current_ssl_pkt;
Dec 12, 2011
Dec 12, 2011
226
struct pkt *pending_deflated_pkt;
227
228
229
230
231
232
233
234
235
236
237
z_stream inflate_strm;
uint32_t inflate_adler32;
z_stream deflate_strm;
uint32_t deflate_adler32;
int disable_ipv6;
int reconnect_timeout;
int reconnect_interval;
int dtls_attempt_period;
time_t new_dtls_started;
Jun 11, 2012
Jun 11, 2012
238
#if defined(DTLS_OPENSSL)
239
240
241
242
SSL_CTX *dtls_ctx;
SSL *dtls_ssl;
SSL *new_dtls_ssl;
SSL_SESSION *dtls_session;
Jun 11, 2012
Jun 11, 2012
243
#elif defined(DTLS_GNUTLS)
Jun 7, 2012
Jun 7, 2012
244
245
246
247
248
249
250
/* Call these *_ssl rather than *_sess because they're just
pointers, and generic code (in mainloop.c for example)
wants to check if they're NULL or not. No point in being
differently named to the OpenSSL variant, and forcing us to
have ifdefs or accessor macros for them. */
gnutls_session_t dtls_ssl;
gnutls_session_t new_dtls_ssl;
May 29, 2012
May 29, 2012
251
#endif
252
253
254
255
256
struct keepalive_info dtls_times;
unsigned char dtls_session_id[32];
unsigned char dtls_secret[48];
char *dtls_cipher;
Apr 16, 2012
Apr 16, 2012
257
const char *vpnc_script;
258
259
260
int script_tun;
char *ifname;
Jun 30, 2012
Jun 30, 2012
261
262
int actual_mtu;
int reqmtu, basemtu;
263
264
265
266
267
268
269
270
271
const char *banner;
const char *vpn_addr;
const char *vpn_netmask;
const char *vpn_addr6;
const char *vpn_netmask6;
const char *vpn_dns[3];
const char *vpn_nbns[3];
const char *vpn_domain;
const char *vpn_proxy_pac;
Jun 8, 2012
Jun 8, 2012
272
struct split_include *split_dns;
273
274
275
276
277
278
279
280
281
282
struct split_include *split_includes;
struct split_include *split_excludes;
int select_nfds;
fd_set select_rfds;
fd_set select_wfds;
fd_set select_efds;
#ifdef __sun__
int ip_fd;
Dec 12, 2011
Dec 12, 2011
283
int ip6_fd;
284
285
286
287
288
#endif
int tun_fd;
int ssl_fd;
int dtls_fd;
int new_dtls_fd;
May 12, 2012
May 12, 2012
289
int cancel_fd;
290
291
292
293
294
295
296
297
298
299
struct pkt *incoming_queue;
struct pkt *outgoing_queue;
int outgoing_qlen;
int max_qlen;
socklen_t peer_addrlen;
struct sockaddr *peer_addr;
struct sockaddr *dtls_addr;
Jun 25, 2012
Jun 25, 2012
300
301
int dtls_local_port;
302
303
304
int deflate;
char *useragent;
Sep 15, 2011
Sep 15, 2011
305
const char *quit_reason;
Jun 27, 2011
Jun 27, 2011
307
308
309
310
311
void *cbdata;
openconnect_validate_peer_cert_vfn validate_peer_cert;
openconnect_write_new_config_vfn write_new_config;
openconnect_process_auth_form_vfn process_auth_form;
openconnect_progress_vfn progress;
Jun 11, 2012
Jun 11, 2012
314
315
#if (defined (DTLS_OPENSSL) && defined (SSL_OP_CISCO_ANYCONNECT)) || \
(defined (DTLS_GNUTLS) && defined (HAVE_GNUTLS_SESSION_SET_PREMASTER))
Jun 7, 2012
Jun 7, 2012
316
317
318
#define HAVE_DTLS 1
#endif
319
320
321
322
323
324
325
326
327
328
/* Packet types */
#define AC_PKT_DATA 0 /* Uncompressed data */
#define AC_PKT_DPD_OUT 3 /* Dead Peer Detection */
#define AC_PKT_DPD_RESP 4 /* DPD response */
#define AC_PKT_DISCONN 5 /* Client disconnection notice */
#define AC_PKT_KEEPALIVE 7 /* Keepalive */
#define AC_PKT_COMPRESSED 8 /* Compressed data */
#define AC_PKT_TERM_SERVER 9 /* Server kick */
Jun 27, 2011
Jun 27, 2011
329
330
#define vpn_progress(vpninfo, ...) (vpninfo)->progress ((vpninfo)->cbdata, __VA_ARGS__)
Apr 18, 2012
Apr 18, 2012
331
332
/****************************************************************************/
/* Oh Solaris how we hate thee! */
Apr 19, 2012
Apr 19, 2012
333
334
335
336
#ifdef __sun__
#define time(x) openconnect__time(x)
time_t openconnect__time(time_t *t);
#endif
Apr 18, 2012
Apr 18, 2012
337
338
339
340
#ifndef HAVE_ASPRINTF
#define asprintf openconnect__asprintf
int openconnect__asprintf(char **strp, const char *fmt, ...);
#endif
May 3, 2012
May 3, 2012
341
342
343
344
#ifndef HAVE_GETLINE
#define getline openconnect__getline
ssize_t openconnect__getline(char **lineptr, size_t *n, FILE *stream);
#endif
Oct 13, 2012
Oct 13, 2012
345
346
347
348
#ifndef HAVE_STRCASESTR
#define strcasestr openconnect__strcasestr
char *openconnect__strcasestr(const char *haystack, const char *needle);
#endif
Apr 18, 2012
Apr 18, 2012
349
350
351
352
353
354
355
/****************************************************************************/
/* tun.c */
int setup_tun(struct openconnect_info *vpninfo);
int tun_mainloop(struct openconnect_info *vpninfo, int *timeout);
void shutdown_tun(struct openconnect_info *vpninfo);
Apr 10, 2012
Apr 10, 2012
356
int script_config_tun (struct openconnect_info *vpninfo, const char *reason);
357
358
359
360
361
362
363
364
365
366
367
/* dtls.c */
unsigned char unhex(const char *data);
int setup_dtls(struct openconnect_info *vpninfo);
int dtls_mainloop(struct openconnect_info *vpninfo, int *timeout);
int dtls_try_handshake(struct openconnect_info *vpninfo);
int connect_dtls_socket(struct openconnect_info *vpninfo);
/* cstp.c */
int make_cstp_connection(struct openconnect_info *vpninfo);
int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout);
Sep 15, 2011
Sep 15, 2011
368
int cstp_bye(struct openconnect_info *vpninfo, const char *reason);
369
370
371
int cstp_reconnect(struct openconnect_info *vpninfo);
/* ssl.c */
May 29, 2012
May 29, 2012
372
int connect_https_socket(struct openconnect_info *vpninfo);
Jun 13, 2012
Jun 13, 2012
373
int request_passphrase(struct openconnect_info *vpninfo, const char *label,
Jun 4, 2012
Jun 4, 2012
374
char **response, const char *fmt, ...);
375
int __attribute__ ((format (printf, 2, 3)))
May 12, 2012
May 12, 2012
376
openconnect_SSL_printf(struct openconnect_info *vpninfo, const char *fmt, ...);
Jun 14, 2012
Jun 14, 2012
377
378
int openconnect_print_err_cb(const char *str, size_t len, void *ptr);
#define openconnect_report_ssl_errors(v) ERR_print_errors_cb(openconnect_print_err_cb, (v))
Jun 17, 2012
Jun 17, 2012
379
380
381
382
383
384
385
#ifdef FAKE_ANDROID_KEYSTORE
#define ANDROID_KEYSTORE
#endif
#ifdef ANDROID_KEYSTORE
char *keystore_strerror(int err);
int keystore_fetch(const char *key, unsigned char **result);
#endif
Jun 4, 2012
Jun 4, 2012
386
387
/* ${SSL_LIBRARY}.c */
May 12, 2012
May 12, 2012
388
int openconnect_SSL_gets(struct openconnect_info *vpninfo, char *buf, size_t len);
May 12, 2012
May 12, 2012
389
int openconnect_SSL_write(struct openconnect_info *vpninfo, char *buf, size_t len);
May 12, 2012
May 12, 2012
390
int openconnect_SSL_read(struct openconnect_info *vpninfo, char *buf, size_t len);
391
int openconnect_open_https(struct openconnect_info *vpninfo);
Jun 9, 2012
Jun 9, 2012
392
void openconnect_close_https(struct openconnect_info *vpninfo, int final);
May 29, 2012
May 29, 2012
393
int get_cert_md5_fingerprint(struct openconnect_info *vpninfo, OPENCONNECT_X509 *cert,
May 29, 2012
May 29, 2012
395
int openconnect_sha1(unsigned char *result, void *data, int len);
May 29, 2012
May 29, 2012
396
int openconnect_random(void *bytes, int len);
May 29, 2012
May 29, 2012
397
398
int openconnect_local_cert_md5(struct openconnect_info *vpninfo,
char *buf);
May 29, 2012
May 29, 2012
399
400
401
402
403
404
405
/* mainloop.c */
int vpn_add_pollfd(struct openconnect_info *vpninfo, int fd, short events);
int vpn_mainloop(struct openconnect_info *vpninfo);
int queue_new_packet(struct pkt **q, void *buf, int len);
void queue_packet(struct pkt **q, struct pkt *new);
int keepalive_action(struct keepalive_info *ka, int *timeout);
Aug 3, 2012
Aug 3, 2012
406
int ka_stalled_action(struct keepalive_info *ka, int *timeout);
407
408
409
410
411
412
413
extern int killed;
/* xml.c */
int config_lookup_host(struct openconnect_info *vpninfo, const char *host);
/* auth.c */
Oct 28, 2012
Oct 28, 2012
414
415
416
int parse_xml_response(struct openconnect_info *vpninfo, char *response, struct oc_auth_form **form);
int handle_auth_form(struct openconnect_info *vpninfo, struct oc_auth_form *form,
char *request_body, int req_len, const char **method,
Oct 28, 2012
Oct 28, 2012
417
const char **request_body_type, int xmlpost);
Oct 28, 2012
Oct 28, 2012
418
void free_auth_form(struct oc_auth_form *form);
Oct 28, 2012
Oct 28, 2012
419
int xmlpost_initial_req(struct openconnect_info *vpninfo, char *request_body, int req_len);
Oct 15, 2012
Oct 15, 2012
420
int prepare_stoken(struct openconnect_info *vpninfo);
Sep 15, 2011
Sep 15, 2011
423
char *openconnect_create_useragent(const char *base);
424
int process_proxy(struct openconnect_info *vpninfo, int ssl_sock);
Mar 9, 2011
Mar 9, 2011
425
426
int internal_parse_url(char *url, char **res_proto, char **res_host,
int *res_port, char **res_path, int default_port);
427
428
429
430
431
/* ssl_ui.c */
int set_openssl_ui(void);
/* version.c */
May 12, 2012
May 12, 2012
432
extern const char *openconnect_version_str;
433
434
#endif /* __OPENCONNECT_INTERNAL_H__ */