2 * OpenConnect (SSL + DTLS) VPN client
4 * Copyright © 2008-2011 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_INTERNAL_H__
27 #define __OPENCONNECT_INTERNAL_H__
29 #include "openconnect.h"
31 #include <openssl/ssl.h>
34 #include <sys/socket.h>
35 #include <sys/select.h>
37 #include <sys/types.h>
45 #define _(s) dgettext("openconnect", s)
51 /****************************************************************************/
63 struct vpn_option *next;
69 #define KA_KEEPALIVE 3
72 struct keepalive_info {
82 struct split_include {
84 struct split_include *next;
87 #define RECONNECT_INTERVAL_MIN 10
88 #define RECONNECT_INTERVAL_MAX 100
90 #define CERT_TYPE_UNKNOWN 0
91 #define CERT_TYPE_PEM 1
92 #define CERT_TYPE_PKCS12 2
93 #define CERT_TYPE_TPM 3
95 struct openconnect_info {
105 char *csd_scriptname;
108 pxProxyFactory *proxy_factory;
114 const char *localname;
118 int cert_expire_warning;
125 const char *servercert;
126 const char *xmlconfig;
127 char xmlsha1[(SHA_DIGEST_LENGTH * 2) + 1];
136 int no_http_keepalive;
138 char *cookie; /* Pointer to within cookies list */
139 struct vpn_option *cookies;
140 struct vpn_option *cstp_options;
141 struct vpn_option *dtls_options;
145 struct keepalive_info ssl_times;
146 int owe_ssl_dpd_response;
147 struct pkt *deflate_pkt;
148 struct pkt *current_ssl_pkt;
149 struct pkt *pending_deflated_pkt;
151 z_stream inflate_strm;
152 uint32_t inflate_adler32;
153 z_stream deflate_strm;
154 uint32_t deflate_adler32;
157 int reconnect_timeout;
158 int reconnect_interval;
159 int dtls_attempt_period;
160 time_t new_dtls_started;
164 SSL_SESSION *dtls_session;
165 struct keepalive_info dtls_times;
166 unsigned char dtls_session_id[32];
167 unsigned char dtls_secret[48];
170 const char *vpnc_script;
176 const char *vpn_addr;
177 const char *vpn_netmask;
178 const char *vpn_addr6;
179 const char *vpn_netmask6;
180 const char *vpn_dns[3];
181 const char *vpn_nbns[3];
182 const char *vpn_domain;
183 const char *vpn_proxy_pac;
184 struct split_include *split_includes;
185 struct split_include *split_excludes;
201 struct pkt *incoming_queue;
202 struct pkt *outgoing_queue;
206 socklen_t peer_addrlen;
207 struct sockaddr *peer_addr;
208 struct sockaddr *dtls_addr;
213 const char *quit_reason;
216 openconnect_validate_peer_cert_vfn validate_peer_cert;
217 openconnect_write_new_config_vfn write_new_config;
218 openconnect_process_auth_form_vfn process_auth_form;
219 openconnect_progress_vfn progress;
224 #define AC_PKT_DATA 0 /* Uncompressed data */
225 #define AC_PKT_DPD_OUT 3 /* Dead Peer Detection */
226 #define AC_PKT_DPD_RESP 4 /* DPD response */
227 #define AC_PKT_DISCONN 5 /* Client disconnection notice */
228 #define AC_PKT_KEEPALIVE 7 /* Keepalive */
229 #define AC_PKT_COMPRESSED 8 /* Compressed data */
230 #define AC_PKT_TERM_SERVER 9 /* Server kick */
233 #if OPENSSL_VERSION_NUMBER >= 0x00909000L
234 #define method_const const
239 #define vpn_progress(vpninfo, ...) (vpninfo)->progress ((vpninfo)->cbdata, __VA_ARGS__)
241 /****************************************************************************/
242 /* Oh Solaris how we hate thee! */
244 #define time(x) openconnect__time(x)
245 time_t openconnect__time(time_t *t);
247 #ifndef HAVE_ASPRINTF
248 #define asprintf openconnect__asprintf
249 int openconnect__asprintf(char **strp, const char *fmt, ...);
252 #define getline openconnect__getline
253 ssize_t openconnect__getline(char **lineptr, size_t *n, FILE *stream);
256 /****************************************************************************/
259 int setup_tun(struct openconnect_info *vpninfo);
260 int tun_mainloop(struct openconnect_info *vpninfo, int *timeout);
261 void shutdown_tun(struct openconnect_info *vpninfo);
262 int script_config_tun (struct openconnect_info *vpninfo, const char *reason);
265 unsigned char unhex(const char *data);
266 int setup_dtls(struct openconnect_info *vpninfo);
267 int dtls_mainloop(struct openconnect_info *vpninfo, int *timeout);
268 int dtls_try_handshake(struct openconnect_info *vpninfo);
269 int connect_dtls_socket(struct openconnect_info *vpninfo);
272 int make_cstp_connection(struct openconnect_info *vpninfo);
273 int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout);
274 int cstp_bye(struct openconnect_info *vpninfo, const char *reason);
275 int cstp_reconnect(struct openconnect_info *vpninfo);
278 int __attribute__ ((format (printf, 2, 3)))
279 openconnect_SSL_printf(SSL *ssl, const char *fmt, ...);
280 int openconnect_SSL_gets(SSL *ssl, char *buf, size_t len);
281 int openconnect_open_https(struct openconnect_info *vpninfo);
282 void openconnect_close_https(struct openconnect_info *vpninfo);
283 int get_cert_md5_fingerprint(struct openconnect_info *vpninfo, X509 *cert,
285 void report_ssl_errors(struct openconnect_info *vpninfo);
288 int vpn_add_pollfd(struct openconnect_info *vpninfo, int fd, short events);
289 int vpn_mainloop(struct openconnect_info *vpninfo);
290 int queue_new_packet(struct pkt **q, void *buf, int len);
291 void queue_packet(struct pkt **q, struct pkt *new);
292 int keepalive_action(struct keepalive_info *ka, int *timeout);
293 int ka_stalled_dpd_time(struct keepalive_info *ka, int *timeout);
298 int config_lookup_host(struct openconnect_info *vpninfo, const char *host);
301 int parse_xml_response(struct openconnect_info *vpninfo, char *response,
302 char *request_body, int req_len, const char **method,
303 const char **request_body_type);
306 char *openconnect_create_useragent(const char *base);
307 int process_proxy(struct openconnect_info *vpninfo, int ssl_sock);
308 int internal_parse_url(char *url, char **res_proto, char **res_host,
309 int *res_port, char **res_path, int default_port);
312 int set_openssl_ui(void);
315 int generate_securid_tokencodes(struct openconnect_info *vpninfo);
316 int add_securid_pin(char *token, char *pin);
319 extern char openconnect_version[];
321 #endif /* __OPENCONNECT_INTERNAL_H__ */