2 * Private HTTP definitions for CUPS.
4 * Copyright 2007-2018 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
11 #ifndef _CUPS_HTTP_PRIVATE_H_
12 # define _CUPS_HTTP_PRIVATE_H_
15 * Include necessary headers...
19 # include <cups/language.h>
24 # include <sys/select.h>
29 # define _WINSOCK_DEPRECATED_NO_WARNINGS 1
31 # include <winsock2.h>
32 # define CUPS_SOCAST (const char *)
36 # include <sys/socket.h>
41 # ifdef HAVE_GSS_GSSAPI_H
42 # include <GSS/gssapi.h>
43 # elif defined(HAVE_GSSAPI_GSSAPI_H)
44 # include <gssapi/gssapi.h>
45 # elif defined(HAVE_GSSAPI_H)
47 # endif /* HAVE_GSS_GSSAPI_H */
48 # ifndef HAVE_GSS_C_NT_HOSTBASED_SERVICE
49 # define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name
50 # endif /* !HAVE_GSS_C_NT_HOSTBASED_SERVICE */
51 # endif /* HAVE_GSSAPI */
53 # ifdef HAVE_AUTHORIZATION_H
54 # include <Security/Authorization.h>
55 # endif /* HAVE_AUTHORIZATION_H */
57 # if defined(__APPLE__) && !defined(_SOCKLEN_T)
59 * macOS 10.2.x does not define socklen_t, and in fact uses an int instead of
60 * unsigned type for length values...
63 typedef int socklen_t
;
64 # endif /* __APPLE__ && !_SOCKLEN_T */
66 # include <cups/http.h>
67 # include "ipp-private.h"
70 # include <gnutls/gnutls.h>
71 # include <gnutls/x509.h>
72 # elif defined(HAVE_CDSASSL)
73 # include <CoreFoundation/CoreFoundation.h>
74 # include <Security/Security.h>
75 # include <Security/SecureTransport.h>
76 # ifdef HAVE_SECITEM_H
77 # include <Security/SecItem.h>
78 # endif /* HAVE_SECITEM_H */
79 # ifdef HAVE_SECCERTIFICATE_H
80 # include <Security/SecCertificate.h>
81 # include <Security/SecIdentity.h>
82 # endif /* HAVE_SECCERTIFICATE_H */
83 # elif defined(HAVE_SSPISSL)
84 # include <wincrypt.h>
85 # include <wintrust.h>
86 # include <schannel.h>
87 # define SECURITY_WIN32
88 # include <security.h>
90 # endif /* HAVE_GNUTLS */
95 # ifdef HAVE_GETIFADDRS
98 # include <sys/ioctl.h>
99 # ifdef HAVE_SYS_SOCKIO_H
100 # include <sys/sockio.h>
101 # endif /* HAVE_SYS_SOCKIO_H */
102 # endif /* HAVE_GETIFADDRS */
103 # endif /* !_WIN32 */
107 # endif /* HAVE_LIBZ */
116 # endif /* __cplusplus */
123 # define _HTTP_MAX_SBUFFER 65536 /* Size of (de)compression buffer */
124 # define _HTTP_RESOLVE_DEFAULT 0 /* Just resolve with default options */
125 # define _HTTP_RESOLVE_STDERR 1 /* Log resolve progress to stderr */
126 # define _HTTP_RESOLVE_FQDN 2 /* Resolve to a FQDN */
127 # define _HTTP_RESOLVE_FAXOUT 4 /* Resolve FaxOut service? */
129 # define _HTTP_TLS_NONE 0 /* No TLS options */
130 # define _HTTP_TLS_ALLOW_RC4 1 /* Allow RC4 cipher suites */
131 # define _HTTP_TLS_ALLOW_DH 2 /* Allow DH/DHE key negotiation */
132 # define _HTTP_TLS_DENY_CBC 4 /* Deny CBC cipher suites */
133 # define _HTTP_TLS_SET_DEFAULT 128 /* Setting the default TLS options */
135 # define _HTTP_TLS_SSL3 0 /* Min/max version is SSL/3.0 */
136 # define _HTTP_TLS_1_0 1 /* Min/max version is TLS/1.0 */
137 # define _HTTP_TLS_1_1 2 /* Min/max version is TLS/1.1 */
138 # define _HTTP_TLS_1_2 3 /* Min/max version is TLS/1.2 */
139 # define _HTTP_TLS_1_3 4 /* Min/max version is TLS/1.3 */
140 # define _HTTP_TLS_MAX 5 /* Highest known TLS version */
144 * Types and functions for SSL support...
149 * The GNU TLS library is more of a "bare metal" SSL/TLS library...
152 typedef gnutls_session_t http_tls_t
;
153 typedef gnutls_certificate_credentials_t
*http_tls_credentials_t
;
155 # elif defined(HAVE_CDSASSL)
157 * Darwin's Security framework provides its own SSL/TLS context structure
158 * for its IO and protocol management...
161 # if !defined(HAVE_SECBASEPRIV_H) && defined(HAVE_CSSMERRORSTRING) /* Declare prototype for function in that header... */
162 extern const char *cssmErrorString(int error
);
163 # endif /* !HAVE_SECBASEPRIV_H && HAVE_CSSMERRORSTRING */
164 # if !defined(HAVE_SECIDENTITYSEARCHPRIV_H) && defined(HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY) /* Declare prototype for function in that header... */
165 extern OSStatus
SecIdentitySearchCreateWithPolicy(SecPolicyRef policy
,
166 CFStringRef idString
, CSSM_KEYUSE keyUsage
,
167 CFTypeRef keychainOrArray
,
168 Boolean returnOnlyValidIdentities
,
169 SecIdentitySearchRef
* searchRef
);
170 # endif /* !HAVE_SECIDENTITYSEARCHPRIV_H && HAVE_SECIDENTITYSEARCHCREATEWITHPOLICY */
171 # if !defined(HAVE_SECPOLICYPRIV_H) && defined(HAVE_SECPOLICYSETVALUE) /* Declare prototype for function in that header... */
172 extern OSStatus
SecPolicySetValue(SecPolicyRef policyRef
,
173 const CSSM_DATA
*value
);
174 # endif /* !HAVE_SECPOLICYPRIV_H && HAVE_SECPOLICYSETVALUE */
176 typedef SSLContextRef http_tls_t
;
177 typedef CFArrayRef http_tls_credentials_t
;
179 # elif defined(HAVE_SSPISSL)
181 * Windows' SSPI library gets a CUPS wrapper...
184 typedef struct _http_sspi_s
/**** SSPI/SSL data structure ****/
186 CredHandle creds
; /* Credentials */
187 CtxtHandle context
; /* SSL context */
188 BOOL contextInitialized
; /* Is context init'd? */
189 SecPkgContext_StreamSizes streamSizes
;/* SSL data stream sizes */
190 BYTE
*decryptBuffer
; /* Data pre-decryption*/
191 size_t decryptBufferLength
; /* Length of decrypt buffer */
192 size_t decryptBufferUsed
; /* Bytes used in buffer */
193 BYTE
*readBuffer
; /* Data post-decryption */
194 int readBufferLength
; /* Length of read buffer */
195 int readBufferUsed
; /* Bytes used in buffer */
196 BYTE
*writeBuffer
; /* Data pre-encryption */
197 int writeBufferLength
; /* Length of write buffer */
198 PCCERT_CONTEXT localCert
, /* Local certificate */
199 remoteCert
; /* Remote (peer's) certificate */
200 char error
[256]; /* Most recent error message */
202 typedef _http_sspi_t
*http_tls_t
;
203 typedef PCCERT_CONTEXT http_tls_credentials_t
;
207 * Otherwise define stub types since we have no SSL support...
210 typedef void *http_tls_t
;
211 typedef void *http_tls_credentials_t
;
212 # endif /* HAVE_GNUTLS */
214 typedef enum _http_coding_e
/**** HTTP content coding enumeration ****/
216 _HTTP_CODING_IDENTITY
, /* No content coding */
217 _HTTP_CODING_GZIP
, /* LZ77+gzip decompression */
218 _HTTP_CODING_DEFLATE
, /* LZ77+zlib compression */
219 _HTTP_CODING_GUNZIP
, /* LZ77+gzip decompression */
220 _HTTP_CODING_INFLATE
/* LZ77+zlib decompression */
223 typedef enum _http_mode_e
/**** HTTP mode enumeration ****/
225 _HTTP_MODE_CLIENT
, /* Client connected to server */
226 _HTTP_MODE_SERVER
/* Server connected (accepted) from client */
229 # ifndef _HTTP_NO_PRIVATE
230 struct _http_s
/**** HTTP connection structure ****/
232 int fd
; /* File descriptor for this socket */
233 int blocking
; /* To block or not to block */
234 int error
; /* Last error on read */
235 time_t activity
; /* Time since last read/write */
236 http_state_t state
; /* State of client */
237 http_status_t status
; /* Status of last request */
238 http_version_t version
; /* Protocol version */
239 http_keepalive_t keep_alive
; /* Keep-alive supported? */
240 struct sockaddr_in _hostaddr
; /* Address of connected host (deprecated) */
241 char hostname
[HTTP_MAX_HOST
],
242 /* Name of connected host */
243 _fields
[HTTP_FIELD_ACCEPT_ENCODING
][HTTP_MAX_VALUE
];
244 /* Field values up to Accept-Encoding (deprecated) */
245 char *data
; /* Pointer to data buffer */
246 http_encoding_t data_encoding
; /* Chunked or not */
247 int _data_remaining
;/* Number of bytes left (deprecated) */
248 int used
; /* Number of bytes used in buffer */
249 char buffer
[HTTP_MAX_BUFFER
];
250 /* Buffer for incoming data */
251 int _auth_type
; /* Authentication in use (deprecated) */
252 unsigned char _md5_state
[88]; /* MD5 state (deprecated) */
253 char nonce
[HTTP_MAX_VALUE
];
255 unsigned nonce_count
; /* Nonce count */
256 http_tls_t tls
; /* TLS state information */
257 http_encryption_t encryption
; /* Encryption requirements */
259 /**** New in CUPS 1.1.19 ****/
260 fd_set
*input_set
; /* select() set for httpWait() (deprecated) */
261 http_status_t expect
; /* Expect: header */
262 char *cookie
; /* Cookie value(s) */
264 /**** New in CUPS 1.1.20 ****/
265 char _authstring
[HTTP_MAX_VALUE
],
266 /* Current Authorization value (deprecated) */
267 userpass
[HTTP_MAX_VALUE
];
268 /* Username:password string */
269 int digest_tries
; /* Number of tries for digest auth */
271 /**** New in CUPS 1.2 ****/
272 off_t data_remaining
; /* Number of bytes left */
273 http_addr_t
*hostaddr
; /* Current host address and port */
274 http_addrlist_t
*addrlist
; /* List of valid addresses */
275 char wbuffer
[HTTP_MAX_BUFFER
];
276 /* Buffer for outgoing data */
277 int wused
; /* Write buffer bytes used */
279 /**** New in CUPS 1.3 ****/
280 char *authstring
; /* Current Authorization field */
282 gss_OID gssmech
; /* Authentication mechanism */
283 gss_ctx_id_t gssctx
; /* Authentication context */
284 gss_name_t gssname
; /* Authentication server name */
285 # endif /* HAVE_GSSAPI */
286 # ifdef HAVE_AUTHORIZATION_H
287 AuthorizationRef auth_ref
; /* Authorization ref */
288 # endif /* HAVE_AUTHORIZATION_H */
290 /**** New in CUPS 1.5 ****/
291 http_tls_credentials_t tls_credentials
;
292 /* TLS credentials */
293 http_timeout_cb_t timeout_cb
; /* Timeout callback */
294 void *timeout_data
; /* User data pointer */
295 double timeout_value
; /* Timeout in seconds */
296 int wait_value
; /* httpWait value for timeout */
298 char gsshost
[256]; /* Hostname for Kerberos */
299 # endif /* HAVE_GSSAPI */
301 /**** New in CUPS 1.7 ****/
302 int tls_upgrade
; /* Non-zero if we are doing an upgrade */
303 _http_mode_t mode
; /* _HTTP_MODE_CLIENT or _HTTP_MODE_SERVER */
305 _http_coding_t coding
; /* _HTTP_CODING_xxx */
306 z_stream stream
; /* (De)compression stream */
307 Bytef
*sbuffer
; /* (De)compression buffer */
308 # endif /* HAVE_LIBZ */
310 /**** New in CUPS 2.2.9 ****/
311 char algorithm
[65], /* Algorithm from WWW-Authenticate */
312 nextnonce
[HTTP_MAX_VALUE
],
313 /* Next nonce value from Authentication-Info */
314 opaque
[HTTP_MAX_VALUE
],
315 /* Opaque value from WWW-Authenticate */
316 realm
[HTTP_MAX_VALUE
];
317 /* Realm from WWW-Authenticate */
319 /**** New in CUPS 2.3 ****/
320 char *fields
[HTTP_FIELD_MAX
],
321 /* Allocated field values */
322 *default_fields
[HTTP_FIELD_MAX
];
323 /* Default field values, if any */
325 # endif /* !_HTTP_NO_PRIVATE */
329 * Some OS's don't have hstrerror(), most notably Solaris...
332 # ifndef HAVE_HSTRERROR
333 extern const char *_cups_hstrerror(int error
);
334 # define hstrerror _cups_hstrerror
335 # endif /* !HAVE_HSTRERROR */
339 * Some OS's don't have getifaddrs() and freeifaddrs()...
342 # if !defined(_WIN32) && !defined(HAVE_GETIFADDRS)
345 # endif /* ifa_dstaddr */
347 # define ifr_netmask ifr_addr
348 # endif /* !ifr_netmask */
350 struct ifaddrs
/**** Interface Structure ****/
352 struct ifaddrs
*ifa_next
; /* Next interface in list */
353 char *ifa_name
; /* Name of interface */
354 unsigned int ifa_flags
; /* Flags (up, point-to-point, etc.) */
355 struct sockaddr
*ifa_addr
, /* Network address */
356 *ifa_netmask
; /* Address mask */
359 struct sockaddr
*ifu_broadaddr
; /* Broadcast address of this interface. */
360 struct sockaddr
*ifu_dstaddr
; /* Point-to-point destination address. */
363 void *ifa_data
; /* Interface statistics */
366 # ifndef ifa_broadaddr
367 # define ifa_broadaddr ifa_ifu.ifu_broadaddr
368 # endif /* !ifa_broadaddr */
370 # define ifa_dstaddr ifa_ifu.ifu_dstaddr
371 # endif /* !ifa_dstaddr */
373 extern int _cups_getifaddrs(struct ifaddrs
**addrs
) _CUPS_PRIVATE
;
374 # define getifaddrs _cups_getifaddrs
375 extern void _cups_freeifaddrs(struct ifaddrs
*addrs
) _CUPS_PRIVATE
;
376 # define freeifaddrs _cups_freeifaddrs
377 # endif /* !_WIN32 && !HAVE_GETIFADDRS */
384 extern void _httpAddrSetPort(http_addr_t
*addr
, int port
) _CUPS_PRIVATE
;
385 extern http_tls_credentials_t
386 _httpCreateCredentials(cups_array_t
*credentials
) _CUPS_PRIVATE
;
387 extern char *_httpDecodeURI(char *dst
, const char *src
,
388 size_t dstsize
) _CUPS_PRIVATE
;
389 extern void _httpDisconnect(http_t
*http
) _CUPS_PRIVATE
;
390 extern char *_httpEncodeURI(char *dst
, const char *src
,
391 size_t dstsize
) _CUPS_PRIVATE
;
392 extern void _httpFreeCredentials(http_tls_credentials_t credentials
) _CUPS_PRIVATE
;
393 extern const char *_httpResolveURI(const char *uri
, char *resolved_uri
,
394 size_t resolved_size
, int options
,
395 int (*cb
)(void *context
),
396 void *context
) _CUPS_PRIVATE
;
397 extern int _httpSetDigestAuthString(http_t
*http
, const char *nonce
, const char *method
, const char *resource
) _CUPS_PRIVATE
;
398 extern const char *_httpStatus(cups_lang_t
*lang
, http_status_t status
) _CUPS_PRIVATE
;
399 extern void _httpTLSInitialize(void) _CUPS_PRIVATE
;
400 extern size_t _httpTLSPending(http_t
*http
) _CUPS_PRIVATE
;
401 extern int _httpTLSRead(http_t
*http
, char *buf
, int len
) _CUPS_PRIVATE
;
402 extern int _httpTLSSetCredentials(http_t
*http
) _CUPS_PRIVATE
;
403 extern void _httpTLSSetOptions(int options
, int min_version
, int max_version
) _CUPS_PRIVATE
;
404 extern int _httpTLSStart(http_t
*http
) _CUPS_PRIVATE
;
405 extern void _httpTLSStop(http_t
*http
) _CUPS_PRIVATE
;
406 extern int _httpTLSWrite(http_t
*http
, const char *buf
, int len
) _CUPS_PRIVATE
;
407 extern int _httpUpdate(http_t
*http
, http_status_t
*status
) _CUPS_PRIVATE
;
408 extern int _httpWait(http_t
*http
, int msec
, int usessl
) _CUPS_PRIVATE
;
417 # endif /* __cplusplus */
419 #endif /* !_CUPS_HTTP_PRIVATE_H_ */