Make certificate expiry warning time variable (still default 60 days)
[platform/upstream/openconnect.git] / openconnect-internal.h
1 /*
2  * OpenConnect (SSL + DTLS) VPN client
3  *
4  * Copyright © 2008-2011 Intel Corporation.
5  * Copyright © 2008 Nick Andrew <nick@nick-andrew.net>
6  *
7  * Author: David Woodhouse <dwmw2@infradead.org>
8  *
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.
12  *
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.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to:
20  *
21  *   Free Software Foundation, Inc.
22  *   51 Franklin Street, Fifth Floor,
23  *   Boston, MA 02110-1301 USA
24  */
25
26 #ifndef __OPENCONNECT_INTERNAL_H__
27 #define __OPENCONNECT_INTERNAL_H__
28
29 #include "openconnect.h"
30
31 #include <openssl/ssl.h>
32 #include <zlib.h>
33 #include <stdint.h>
34 #include <sys/socket.h>
35 #include <sys/select.h>
36 #include <sys/time.h>
37 #include <sys/types.h>
38 #include <unistd.h>
39 #ifdef LIBPROXY_HDR
40 #include LIBPROXY_HDR
41 #endif
42 #ifdef ENABLE_NLS
43 #include <libintl.h>
44 #define _(s) dgettext("openconnect", s)
45 #else
46 #define _(s) s
47 #endif
48 #define N_(s) s
49
50 /****************************************************************************/
51
52 struct pkt {
53         int len;
54         struct pkt *next;
55         unsigned char hdr[8];
56         unsigned char data[];
57 };
58
59 struct vpn_option {
60         char *option;
61         char *value;
62         struct vpn_option *next;
63 };
64
65 #define KA_NONE         0
66 #define KA_DPD          1
67 #define KA_DPD_DEAD     2
68 #define KA_KEEPALIVE    3
69 #define KA_REKEY        4
70
71 struct keepalive_info {
72         int dpd;
73         int keepalive;
74         int rekey;
75         time_t last_rekey;
76         time_t last_tx;
77         time_t last_rx;
78         time_t last_dpd;
79 };
80
81 struct split_include {
82         char *route;
83         struct split_include *next;
84 };
85
86 #define RECONNECT_INTERVAL_MIN  10
87 #define RECONNECT_INTERVAL_MAX  100
88
89 #define CERT_TYPE_UNKNOWN       0
90 #define CERT_TYPE_PEM           1
91 #define CERT_TYPE_PKCS12        2
92 #define CERT_TYPE_TPM           3
93
94 struct openconnect_info {
95         char *redirect_url;
96
97         char *csd_token;
98         char *csd_ticket;
99         char *csd_stuburl;
100         char *csd_starturl;
101         char *csd_waiturl;
102         char *csd_preurl;
103
104         char *csd_scriptname;
105
106 #ifdef LIBPROXY_HDR
107         pxProxyFactory *proxy_factory;
108 #endif
109         char *proxy_type;
110         char *proxy;
111         int proxy_port;
112
113         const char *localname;
114         char *hostname;
115         int port;
116         char *urlpath;
117         int cert_expire_warning;
118         const char *cert;
119         const char *sslkey;
120         X509 *cert_x509;
121         int cert_type;
122         char *cert_password;
123         const char *cafile;
124         const char *servercert;
125         const char *xmlconfig;
126         char xmlsha1[(SHA_DIGEST_LENGTH * 2) + 1];
127         char *username;
128         char *password;
129         char *authgroup;
130         int nopasswd;
131         char *dtls_ciphers;
132         uid_t uid_csd;
133         char *csd_wrapper;
134         int uid_csd_given;
135         int no_http_keepalive;
136
137         char *cookie; /* Pointer to within cookies list */
138         struct vpn_option *cookies;
139         struct vpn_option *cstp_options;
140         struct vpn_option *dtls_options;
141
142         SSL_CTX *https_ctx;
143         SSL *https_ssl;
144         struct keepalive_info ssl_times;
145         int owe_ssl_dpd_response;
146         struct pkt *deflate_pkt;
147         struct pkt *current_ssl_pkt;
148
149         z_stream inflate_strm;
150         uint32_t inflate_adler32;
151         z_stream deflate_strm;
152         uint32_t deflate_adler32;
153
154         int disable_ipv6;
155         int reconnect_timeout;
156         int reconnect_interval;
157         int dtls_attempt_period;
158         time_t new_dtls_started;
159         SSL_CTX *dtls_ctx;
160         SSL *dtls_ssl;
161         SSL *new_dtls_ssl;
162         SSL_SESSION *dtls_session;
163         struct keepalive_info dtls_times;
164         unsigned char dtls_session_id[32];
165         unsigned char dtls_secret[48];
166
167         char *dtls_cipher;
168         char *vpnc_script;
169         int script_tun;
170         char *ifname;
171
172         int mtu;
173         const char *banner;
174         const char *vpn_addr;
175         const char *vpn_netmask;
176         const char *vpn_addr6;
177         const char *vpn_netmask6;
178         const char *vpn_dns[3];
179         const char *vpn_nbns[3];
180         const char *vpn_domain;
181         const char *vpn_proxy_pac;
182         struct split_include *split_includes;
183         struct split_include *split_excludes;
184
185         int select_nfds;
186         fd_set select_rfds;
187         fd_set select_wfds;
188         fd_set select_efds;
189
190 #ifdef __sun__
191         int ip_fd;
192         int tun_muxid;
193 #endif
194         int tun_fd;
195         int ssl_fd;
196         int dtls_fd;
197         int new_dtls_fd;
198
199         struct pkt *incoming_queue;
200         struct pkt *outgoing_queue;
201         int outgoing_qlen;
202         int max_qlen;
203
204         socklen_t peer_addrlen;
205         struct sockaddr *peer_addr;
206         struct sockaddr *dtls_addr;
207
208         int deflate;
209         char *useragent;
210
211         const char *quit_reason;
212
213         void *cbdata;
214         openconnect_validate_peer_cert_vfn validate_peer_cert;
215         openconnect_write_new_config_vfn write_new_config;
216         openconnect_process_auth_form_vfn process_auth_form;
217         openconnect_progress_vfn progress;
218 };
219
220 /* Packet types */
221
222 #define AC_PKT_DATA             0       /* Uncompressed data */
223 #define AC_PKT_DPD_OUT          3       /* Dead Peer Detection */
224 #define AC_PKT_DPD_RESP         4       /* DPD response */
225 #define AC_PKT_DISCONN          5       /* Client disconnection notice */
226 #define AC_PKT_KEEPALIVE        7       /* Keepalive */
227 #define AC_PKT_COMPRESSED       8       /* Compressed data */
228 #define AC_PKT_TERM_SERVER      9       /* Server kick */
229
230 /* Ick */
231 #if OPENSSL_VERSION_NUMBER >= 0x00909000L
232 #define method_const const
233 #else
234 #define method_const
235 #endif
236
237 #define vpn_progress(vpninfo, ...) (vpninfo)->progress ((vpninfo)->cbdata, __VA_ARGS__)
238
239 /****************************************************************************/
240
241 /* tun.c */
242 int setup_tun(struct openconnect_info *vpninfo);
243 int tun_mainloop(struct openconnect_info *vpninfo, int *timeout);
244 void shutdown_tun(struct openconnect_info *vpninfo);
245 void script_reconnect (struct openconnect_info *vpninfo);
246
247 /* dtls.c */
248 unsigned char unhex(const char *data);
249 int setup_dtls(struct openconnect_info *vpninfo);
250 int dtls_mainloop(struct openconnect_info *vpninfo, int *timeout);
251 int dtls_try_handshake(struct openconnect_info *vpninfo);
252 int connect_dtls_socket(struct openconnect_info *vpninfo);
253
254 /* cstp.c */
255 int make_cstp_connection(struct openconnect_info *vpninfo);
256 int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout);
257 int cstp_bye(struct openconnect_info *vpninfo, const char *reason);
258 int cstp_reconnect(struct openconnect_info *vpninfo);
259
260 /* ssl.c */
261 int  __attribute__ ((format (printf, 2, 3)))
262                 openconnect_SSL_printf(SSL *ssl, const char *fmt, ...);
263 int openconnect_SSL_gets(SSL *ssl, char *buf, size_t len);
264 int openconnect_open_https(struct openconnect_info *vpninfo);
265 void openconnect_close_https(struct openconnect_info *vpninfo);
266 int get_cert_md5_fingerprint(struct openconnect_info *vpninfo, X509 *cert,
267                              char *buf);
268 void report_ssl_errors(struct openconnect_info *vpninfo);
269
270 /* mainloop.c */
271 int vpn_add_pollfd(struct openconnect_info *vpninfo, int fd, short events);
272 int vpn_mainloop(struct openconnect_info *vpninfo);
273 int queue_new_packet(struct pkt **q, void *buf, int len);
274 void queue_packet(struct pkt **q, struct pkt *new);
275 int keepalive_action(struct keepalive_info *ka, int *timeout);
276 int ka_stalled_dpd_time(struct keepalive_info *ka, int *timeout);
277
278 extern int killed;
279
280 /* xml.c */
281 int config_lookup_host(struct openconnect_info *vpninfo, const char *host);
282
283 /* auth.c */
284 int parse_xml_response(struct openconnect_info *vpninfo, char *response,
285                        char *request_body, int req_len, const char **method,
286                        const char **request_body_type);
287
288 /* http.c */
289 char *openconnect_create_useragent(const char *base);
290 int process_proxy(struct openconnect_info *vpninfo, int ssl_sock);
291 int internal_parse_url(char *url, char **res_proto, char **res_host,
292                        int *res_port, char **res_path, int default_port);
293
294 /* ssl_ui.c */
295 int set_openssl_ui(void);
296
297 /* securid.c */
298 int generate_securid_tokencodes(struct openconnect_info *vpninfo);
299 int add_securid_pin(char *token, char *pin);
300
301 /* version.c */
302 extern char openconnect_version[];
303
304 #endif /* __OPENCONNECT_INTERNAL_H__ */