]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/http-private.h
Move the deck chairs a bit so that the TLS stuff is separated from the HTTP
[thirdparty/cups.git] / cups / http-private.h
1 /*
2 * "$Id$"
3 *
4 * Private HTTP definitions for CUPS.
5 *
6 * Copyright 2007-2014 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 *
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 */
17
18 #ifndef _CUPS_HTTP_PRIVATE_H_
19 # define _CUPS_HTTP_PRIVATE_H_
20
21 /*
22 * Include necessary headers...
23 */
24
25 # include "config.h"
26 # include <cups/language.h>
27 # include <stddef.h>
28 # include <stdlib.h>
29
30 # ifdef __sun
31 # include <sys/select.h>
32 # endif /* __sun */
33
34 # include <limits.h>
35 # ifdef WIN32
36 # include <io.h>
37 # include <winsock2.h>
38 # define CUPS_SOCAST (const char *)
39 # else
40 # include <unistd.h>
41 # include <fcntl.h>
42 # include <sys/socket.h>
43 # define CUPS_SOCAST
44 # endif /* WIN32 */
45
46 # ifdef HAVE_GSSAPI
47 # ifdef HAVE_GSS_GSSAPI_H
48 # include <GSS/gssapi.h>
49 # elif defined(HAVE_GSSAPI_GSSAPI_H)
50 # include <gssapi/gssapi.h>
51 # elif defined(HAVE_GSSAPI_H)
52 # include <gssapi.h>
53 # endif /* HAVE_GSS_GSSAPI_H */
54 # ifndef HAVE_GSS_C_NT_HOSTBASED_SERVICE
55 # define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name
56 # endif /* !HAVE_GSS_C_NT_HOSTBASED_SERVICE */
57 # endif /* HAVE_GSSAPI */
58
59 # ifdef HAVE_AUTHORIZATION_H
60 # include <Security/Authorization.h>
61 # endif /* HAVE_AUTHORIZATION_H */
62
63 # if defined(__APPLE__) && !defined(_SOCKLEN_T)
64 /*
65 * MacOS X 10.2.x does not define socklen_t, and in fact uses an int instead of
66 * unsigned type for length values...
67 */
68
69 typedef int socklen_t;
70 # endif /* __APPLE__ && !_SOCKLEN_T */
71
72 # include <cups/http.h>
73 # include "md5-private.h"
74 # include "ipp-private.h"
75
76 # ifdef HAVE_GNUTLS
77 # include <gnutls/gnutls.h>
78 # include <gnutls/x509.h>
79 # include <gcrypt.h>
80 # elif defined(HAVE_CDSASSL)
81 # include <CoreFoundation/CoreFoundation.h>
82 # include <Security/Security.h>
83 # include <Security/SecureTransport.h>
84 # ifdef HAVE_SECURETRANSPORTPRIV_H
85 # include <Security/SecureTransportPriv.h>
86 # endif /* HAVE_SECURETRANSPORTPRIV_H */
87 # ifdef HAVE_SECITEM_H
88 # include <Security/SecItem.h>
89 # endif /* HAVE_SECITEM_H */
90 # ifdef HAVE_SECBASEPRIV_H
91 # include <Security/SecBasePriv.h>
92 # endif /* HAVE_SECBASEPRIV_H */
93 # ifdef HAVE_SECCERTIFICATE_H
94 # include <Security/SecCertificate.h>
95 # include <Security/SecIdentity.h>
96 # endif /* HAVE_SECCERTIFICATE_H */
97 # ifdef HAVE_SECCERTIFICATEPRIV_H
98 # include <Security/SecCertificatePriv.h>
99 # else
100 # ifdef __cplusplus
101 extern "C" {
102 # endif /* __cplusplus */
103 extern SecCertificateRef SecCertificateCreateWithBytes(CFAllocatorRef allocator, const UInt8 *bytes, CFIndex length);
104 extern bool SecCertificateIsValid(SecCertificateRef certificate, CFAbsoluteTime verifyTime);
105 extern CFAbsoluteTime SecCertificateNotValidAfter(SecCertificateRef certificate);
106 # ifdef __cplusplus
107 }
108 # endif /* __cplusplus */
109 # endif /* HAVE_SECCERTIFICATEPRIV_H */
110 # ifdef HAVE_SECITEMPRIV_H
111 # include <Security/SecItemPriv.h>
112 # endif /* HAVE_SECITEMPRIV_H */
113 # ifdef HAVE_SECIDENTITYSEARCHPRIV_H
114 # include <Security/SecIdentitySearchPriv.h>
115 # endif /* HAVE_SECIDENTITYSEARCHPRIV_H */
116 # ifdef HAVE_SECPOLICYPRIV_H
117 # include <Security/SecPolicyPriv.h>
118 # endif /* HAVE_SECPOLICYPRIV_H */
119 # elif defined(HAVE_SSPISSL)
120 # include "sspi-private.h"
121 # endif /* HAVE_GNUTLS */
122
123 # ifndef WIN32
124 # include <net/if.h>
125 # ifdef HAVE_GETIFADDRS
126 # include <ifaddrs.h>
127 # else
128 # include <sys/ioctl.h>
129 # ifdef HAVE_SYS_SOCKIO_H
130 # include <sys/sockio.h>
131 # endif /* HAVE_SYS_SOCKIO_H */
132 # endif /* HAVE_GETIFADDRS */
133 # endif /* !WIN32 */
134
135 # ifdef HAVE_LIBZ
136 # include <zlib.h>
137 # endif /* HAVE_LIBZ */
138
139
140 /*
141 * C++ magic...
142 */
143
144 # ifdef __cplusplus
145 extern "C" {
146 # endif /* __cplusplus */
147
148
149 /*
150 * Constants...
151 */
152
153
154 #define _HTTP_RESOLVE_DEFAULT 0 /* Just resolve with default options */
155 #define _HTTP_RESOLVE_STDERR 1 /* Log resolve progress to stderr */
156 #define _HTTP_RESOLVE_FQDN 2 /* Resolve to a FQDN */
157 #define _HTTP_RESOLVE_FAXOUT 4 /* Resolve FaxOut service? */
158
159
160 /*
161 * Types and functions for SSL support...
162 */
163
164 # ifdef HAVE_GNUTLS
165 /*
166 * The GNU TLS library is more of a "bare metal" SSL/TLS library...
167 */
168
169 typedef gnutls_session_t http_tls_t;
170 typedef void *http_tls_credentials_t;
171
172 # elif defined(HAVE_CDSASSL)
173 /*
174 * Darwin's Security framework provides its own SSL/TLS context structure
175 * for its IO and protocol management...
176 */
177
178 # if !defined(HAVE_SECBASEPRIV_H) && defined(HAVE_CSSMERRORSTRING) /* Declare prototype for function in that header... */
179 extern const char *cssmErrorString(int error);
180 # endif /* !HAVE_SECBASEPRIV_H && HAVE_CSSMERRORSTRING */
181 # ifndef HAVE_SECITEMPRIV_H /* Declare constants from that header... */
182 extern const CFTypeRef kSecClassCertificate;
183 extern const CFTypeRef kSecClassIdentity;
184 # endif /* !HAVE_SECITEMPRIV_H */
185 # if !defined(HAVE_SECIDENTITYSEARCHPRIV_H) && defined(HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY) /* Declare prototype for function in that header... */
186 extern OSStatus SecIdentitySearchCreateWithPolicy(SecPolicyRef policy,
187 CFStringRef idString, CSSM_KEYUSE keyUsage,
188 CFTypeRef keychainOrArray,
189 Boolean returnOnlyValidIdentities,
190 SecIdentitySearchRef* searchRef);
191 # endif /* !HAVE_SECIDENTITYSEARCHPRIV_H && HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY */
192 # if !defined(HAVE_SECPOLICYPRIV_H) && defined(HAVE_SECPOLICYSETVALUE) /* Declare prototype for function in that header... */
193 extern OSStatus SecPolicySetValue(SecPolicyRef policyRef,
194 const CSSM_DATA *value);
195 # endif /* !HAVE_SECPOLICYPRIV_H && HAVE_SECPOLICYSETVALUE */
196
197 typedef SSLContextRef http_tls_t;
198 typedef CFArrayRef http_tls_credentials_t;
199
200 # elif defined(HAVE_SSPISSL)
201 /*
202 * Windows' SSPI library gets a CUPS wrapper...
203 */
204
205 typedef _sspi_struct_t * http_tls_t;
206 typedef void *http_tls_credentials_t;
207
208 # else
209 /*
210 * Otherwise define stub types since we have no SSL support...
211 */
212
213 typedef void *http_tls_t;
214 typedef void *http_tls_credentials_t;
215 # endif /* HAVE_GNUTLS */
216
217 typedef enum _http_coding_e /**** HTTP content coding enumeration ****/
218 {
219 _HTTP_CODING_IDENTITY, /* No content coding */
220 _HTTP_CODING_GZIP, /* LZ77+gzip decompression */
221 _HTTP_CODING_DEFLATE, /* LZ77+zlib compression */
222 _HTTP_CODING_GUNZIP, /* LZ77+gzip decompression */
223 _HTTP_CODING_INFLATE /* LZ77+zlib decompression */
224 } _http_coding_t;
225
226 typedef enum _http_mode_e /**** HTTP mode enumeration ****/
227 {
228 _HTTP_MODE_CLIENT, /* Client connected to server */
229 _HTTP_MODE_SERVER /* Server connected (accepted) from client */
230 } _http_mode_t;
231
232 # ifndef _HTTP_NO_PRIVATE
233 struct _http_s /**** HTTP connection structure ****/
234 {
235 int fd; /* File descriptor for this socket */
236 int blocking; /* To block or not to block */
237 int error; /* Last error on read */
238 time_t activity; /* Time since last read/write */
239 http_state_t state; /* State of client */
240 http_status_t status; /* Status of last request */
241 http_version_t version; /* Protocol version */
242 http_keepalive_t keep_alive; /* Keep-alive supported? */
243 struct sockaddr_in _hostaddr; /* Address of connected host (deprecated) */
244 char hostname[HTTP_MAX_HOST],
245 /* Name of connected host */
246 fields[HTTP_FIELD_ACCEPT_ENCODING][HTTP_MAX_VALUE];
247 /* Field values up to Accept-Encoding */
248 char *data; /* Pointer to data buffer */
249 http_encoding_t data_encoding; /* Chunked or not */
250 int _data_remaining;/* Number of bytes left (deprecated) */
251 int used; /* Number of bytes used in buffer */
252 char buffer[HTTP_MAX_BUFFER];
253 /* Buffer for incoming data */
254 int _auth_type; /* Authentication in use (deprecated) */
255 _cups_md5_state_t md5_state; /* MD5 state */
256 char nonce[HTTP_MAX_VALUE];
257 /* Nonce value */
258 int nonce_count; /* Nonce count */
259 http_tls_t tls; /* TLS state information */
260 http_encryption_t encryption; /* Encryption requirements */
261
262 /**** New in CUPS 1.1.19 ****/
263 fd_set *input_set; /* select() set for httpWait() (deprecated) */
264 http_status_t expect; /* Expect: header */
265 char *cookie; /* Cookie value(s) */
266
267 /**** New in CUPS 1.1.20 ****/
268 char _authstring[HTTP_MAX_VALUE],
269 /* Current Authorization value (deprecated) */
270 userpass[HTTP_MAX_VALUE];
271 /* Username:password string */
272 int digest_tries; /* Number of tries for digest auth */
273
274 /**** New in CUPS 1.2 ****/
275 off_t data_remaining; /* Number of bytes left */
276 http_addr_t *hostaddr; /* Current host address and port */
277 http_addrlist_t *addrlist; /* List of valid addresses */
278 char wbuffer[HTTP_MAX_BUFFER];
279 /* Buffer for outgoing data */
280 int wused; /* Write buffer bytes used */
281
282 /**** New in CUPS 1.3 ****/
283 char *field_authorization;
284 /* Authorization field */
285 char *authstring; /* Current Authorization field */
286 # ifdef HAVE_GSSAPI
287 gss_OID gssmech; /* Authentication mechanism */
288 gss_ctx_id_t gssctx; /* Authentication context */
289 gss_name_t gssname; /* Authentication server name */
290 # endif /* HAVE_GSSAPI */
291 # ifdef HAVE_AUTHORIZATION_H
292 AuthorizationRef auth_ref; /* Authorization ref */
293 # endif /* HAVE_AUTHORIZATION_H */
294
295 /**** New in CUPS 1.5 ****/
296 http_tls_credentials_t tls_credentials;
297 /* TLS credentials */
298 http_timeout_cb_t timeout_cb; /* Timeout callback */
299 void *timeout_data; /* User data pointer */
300 double timeout_value; /* Timeout in seconds */
301 int wait_value; /* httpWait value for timeout */
302 # ifdef HAVE_GSSAPI
303 char gsshost[256]; /* Hostname for Kerberos */
304 # endif /* HAVE_GSSAPI */
305
306 /**** New in CUPS 1.7 ****/
307 int tls_upgrade; /* Non-zero if we are doing an upgrade */
308 _http_mode_t mode; /* _HTTP_MODE_CLIENT or _HTTP_MODE_SERVER */
309 char *accept_encoding,
310 /* Accept-Encoding field */
311 *allow, /* Allow field */
312 *server, /* Server field */
313 *default_accept_encoding,
314 *default_server,
315 *default_user_agent;
316 /* Default field values */
317 # ifdef HAVE_LIBZ
318 _http_coding_t coding; /* _HTTP_CODING_xxx */
319 z_stream stream; /* (De)compression stream */
320 Bytef *dbuffer; /* Decompression buffer */
321 # endif /* HAVE_LIBZ */
322 };
323 # endif /* !_HTTP_NO_PRIVATE */
324
325
326 /*
327 * Some OS's don't have hstrerror(), most notably Solaris...
328 */
329
330 # ifndef HAVE_HSTRERROR
331 extern const char *_cups_hstrerror(int error);
332 # define hstrerror _cups_hstrerror
333 # endif /* !HAVE_HSTRERROR */
334
335
336 /*
337 * Some OS's don't have getifaddrs() and freeifaddrs()...
338 */
339
340 # if !defined(WIN32) && !defined(HAVE_GETIFADDRS)
341 # ifdef ifa_dstaddr
342 # undef ifa_dstaddr
343 # endif /* ifa_dstaddr */
344 # ifndef ifr_netmask
345 # define ifr_netmask ifr_addr
346 # endif /* !ifr_netmask */
347
348 struct ifaddrs /**** Interface Structure ****/
349 {
350 struct ifaddrs *ifa_next; /* Next interface in list */
351 char *ifa_name; /* Name of interface */
352 unsigned int ifa_flags; /* Flags (up, point-to-point, etc.) */
353 struct sockaddr *ifa_addr, /* Network address */
354 *ifa_netmask; /* Address mask */
355 union
356 {
357 struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */
358 struct sockaddr *ifu_dstaddr; /* Point-to-point destination address. */
359 } ifa_ifu;
360
361 void *ifa_data; /* Interface statistics */
362 };
363
364 # ifndef ifa_broadaddr
365 # define ifa_broadaddr ifa_ifu.ifu_broadaddr
366 # endif /* !ifa_broadaddr */
367 # ifndef ifa_dstaddr
368 # define ifa_dstaddr ifa_ifu.ifu_dstaddr
369 # endif /* !ifa_dstaddr */
370
371 extern int _cups_getifaddrs(struct ifaddrs **addrs);
372 # define getifaddrs _cups_getifaddrs
373 extern void _cups_freeifaddrs(struct ifaddrs *addrs);
374 # define freeifaddrs _cups_freeifaddrs
375 # endif /* !WIN32 && !HAVE_GETIFADDRS */
376
377
378 /*
379 * Prototypes...
380 */
381
382 extern void _httpAddrSetPort(http_addr_t *addr, int port);
383 extern http_tls_credentials_t
384 _httpCreateCredentials(cups_array_t *credentials);
385 extern char *_httpDecodeURI(char *dst, const char *src,
386 size_t dstsize);
387 extern void _httpDisconnect(http_t *http);
388 extern char *_httpEncodeURI(char *dst, const char *src,
389 size_t dstsize);
390 extern void _httpFreeCredentials(http_tls_credentials_t credentials);
391 extern const char *_httpResolveURI(const char *uri, char *resolved_uri,
392 size_t resolved_size, int options,
393 int (*cb)(void *context),
394 void *context);
395 extern const char *_httpStatus(cups_lang_t *lang, http_status_t status);
396 extern void _httpTLSInitialize(void);
397 extern size_t _httpTLSPending(http_t *http);
398 extern int _httpTLSRead(http_t *http, char *buf, int len);
399 extern int _httpTLSSetCredentials(http_t *http);
400 extern int _httpTLSStart(http_t *http);
401 extern void _httpTLSStop(http_t *http);
402 extern int _httpTLSWrite(http_t *http, const char *buf, int len);
403 extern int _httpUpdate(http_t *http, http_status_t *status);
404 extern int _httpWait(http_t *http, int msec, int usessl);
405
406
407 /*
408 * C++ magic...
409 */
410
411 # ifdef __cplusplus
412 }
413 # endif /* __cplusplus */
414
415 #endif /* !_CUPS_HTTP_PRIVATE_H_ */
416
417 /*
418 * End of "$Id$".
419 */