2 * OpenConnect (SSL + DTLS) VPN client
4 * Copyright © 2008-2010 Intel Corporation.
5 * Copyright © 2008 Nick Andrew <nick@nick-andrew.net>
7 * Author: David Woodhouse <dwmw2@infradead.org>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * version 2.1, as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to:
21 * Free Software Foundation, Inc.
22 * 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301 USA
26 #ifndef __OPENCONNECT_ANYCONNECT_H
27 #define __OPENCONNECT_ANYCONNECT_H
29 #include <openssl/ssl.h>
32 #include <sys/socket.h>
33 #include <sys/select.h>
35 #include <sys/types.h>
37 #ifdef OPENCONNECT_LIBPROXY
38 #include <libproxy/proxy.h>
42 /****************************************************************************/
44 /* Authentication form processing */
46 #define OC_FORM_OPT_TEXT 1
47 #define OC_FORM_OPT_PASSWORD 2
48 #define OC_FORM_OPT_SELECT 3
49 #define OC_FORM_OPT_HIDDEN 4
51 /* char * fields are static (owned by XML parser) and don't need to be
52 freed by the form handling code -- except for value, which for TEXT
53 and PASSWORD options is allocated by process_form() when
54 interacting with the user and must be freed. */
56 struct oc_form_opt *next;
63 /* All fields are static, owned by the XML parser */
72 struct oc_form_opt_select {
73 struct oc_form_opt form;
75 struct oc_choice choices[0];
78 /* All char * fields are static, owned by the XML parser */
86 struct oc_form_opt *opts;
89 /****************************************************************************/
101 struct vpn_option *next;
106 #define KA_DPD_DEAD 2
107 #define KA_KEEPALIVE 3
110 struct keepalive_info {
120 struct split_include {
122 struct split_include *next;
125 #define RECONNECT_INTERVAL_MIN 10
126 #define RECONNECT_INTERVAL_MAX 100
128 #define CERT_TYPE_UNKNOWN 0
129 #define CERT_TYPE_PEM 1
130 #define CERT_TYPE_PKCS12 2
131 #define CERT_TYPE_TPM 3
133 struct openconnect_info {
143 char *csd_scriptname;
147 char sid_tokencode[9];
148 char sid_nexttokencode[9];
150 #ifdef OPENCONNECT_LIBPROXY
151 pxProxyFactory *proxy_factory;
157 const char *localname;
166 const char *servercert;
167 const char *xmlconfig;
168 char xmlsha1[(SHA_DIGEST_LENGTH * 2) + 1];
176 int no_http_keepalive;
179 struct vpn_option *cookies;
180 struct vpn_option *cstp_options;
181 struct vpn_option *dtls_options;
185 struct keepalive_info ssl_times;
186 int owe_ssl_dpd_response;
187 struct pkt *deflate_pkt;
188 struct pkt *current_ssl_pkt;
190 z_stream inflate_strm;
191 uint32_t inflate_adler32;
192 z_stream deflate_strm;
193 uint32_t deflate_adler32;
196 int reconnect_timeout;
197 int reconnect_interval;
198 int dtls_attempt_period;
199 time_t new_dtls_started;
203 SSL_SESSION *dtls_session;
204 struct keepalive_info dtls_times;
205 unsigned char dtls_session_id[32];
206 unsigned char dtls_secret[48];
215 const char *vpn_addr;
216 const char *vpn_netmask;
217 const char *vpn_addr6;
218 const char *vpn_netmask6;
219 const char *vpn_dns[3];
220 const char *vpn_nbns[3];
221 const char *vpn_domain;
222 const char *vpn_proxy_pac;
223 struct split_include *split_includes;
224 struct split_include *split_excludes;
240 struct pkt *incoming_queue;
241 struct pkt *outgoing_queue;
245 socklen_t peer_addrlen;
246 struct sockaddr *peer_addr;
247 struct sockaddr *dtls_addr;
254 int (*validate_peer_cert) (struct openconnect_info *vpninfo, X509 *cert);
255 int (*write_new_config) (struct openconnect_info *vpninfo, char *buf, int buflen);
256 int (*process_auth_form) (struct openconnect_info *vpninfo, struct oc_auth_form *form);
258 void __attribute__ ((format(printf, 3, 4)))
259 (*progress) (struct openconnect_info *vpninfo, int level, const char *fmt, ...);
269 #define AC_PKT_DATA 0 /* Uncompressed data */
270 #define AC_PKT_DPD_OUT 3 /* Dead Peer Detection */
271 #define AC_PKT_DPD_RESP 4 /* DPD response */
272 #define AC_PKT_DISCONN 5 /* Client disconnection notice */
273 #define AC_PKT_KEEPALIVE 7 /* Keepalive */
274 #define AC_PKT_COMPRESSED 8 /* Compressed data */
275 #define AC_PKT_TERM_SERVER 9 /* Server kick */
278 #if OPENSSL_VERSION_NUMBER >= 0x10000000L
279 #define method_const const
284 /****************************************************************************/
287 int setup_tun(struct openconnect_info *vpninfo);
288 int tun_mainloop(struct openconnect_info *vpninfo, int *timeout);
289 void shutdown_tun(struct openconnect_info *vpninfo);
292 unsigned char unhex(const char *data);
293 int setup_dtls(struct openconnect_info *vpninfo);
294 int dtls_mainloop(struct openconnect_info *vpninfo, int *timeout);
295 int dtls_try_handshake(struct openconnect_info *vpninfo);
296 int connect_dtls_socket(struct openconnect_info *vpninfo);
299 int make_cstp_connection(struct openconnect_info *vpninfo);
300 int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout);
301 int cstp_bye(struct openconnect_info *vpninfo, char *reason);
304 void openconnect_init_openssl(void);
305 int __attribute__ ((format (printf, 2, 3)))
306 openconnect_SSL_printf(SSL *ssl, const char *fmt, ...);
307 int openconnect_SSL_gets(SSL *ssl, char *buf, size_t len);
308 int openconnect_open_https(struct openconnect_info *vpninfo);
309 void openconnect_close_https(struct openconnect_info *vpninfo);
310 int get_cert_md5_fingerprint(struct openconnect_info *vpninfo, X509 *cert,
312 int get_cert_sha1_fingerprint(struct openconnect_info *vpninfo, X509 *cert,
314 void report_ssl_errors(struct openconnect_info *vpninfo);
315 int passphrase_from_fsid(struct openconnect_info *vpninfo);
318 int vpn_add_pollfd(struct openconnect_info *vpninfo, int fd, short events);
319 int vpn_mainloop(struct openconnect_info *vpninfo);
320 int queue_new_packet(struct pkt **q, void *buf, int len);
321 void queue_packet(struct pkt **q, struct pkt *new);
322 int keepalive_action(struct keepalive_info *ka, int *timeout);
323 int ka_stalled_dpd_time(struct keepalive_info *ka, int *timeout);
328 int config_lookup_host(struct openconnect_info *vpninfo, const char *host);
331 int parse_xml_response(struct openconnect_info *vpninfo, char *response,
332 char *request_body, int req_len, char **method,
333 char **request_body_type);
336 int openconnect_obtain_cookie(struct openconnect_info *vpninfo);
337 char *openconnect_create_useragent(char *base);
338 int process_proxy(struct openconnect_info *vpninfo, int ssl_sock);
339 int parse_url(char *url, char **res_proto, char **res_host, int *res_port,
340 char **res_path, int default_port);
341 int set_http_proxy(struct openconnect_info *vpninfo, char *proxy);
344 int set_openssl_ui(void);
347 int generate_securid_tokencodes(struct openconnect_info *vpninfo);
348 int add_securid_pin(char *token, char *pin);
351 extern char openconnect_version[];
353 #endif /* __OPENCONNECT_ANYCONNECT_H */