9ef1caa61acacf9ef2df386126ce99b2891850b9
[WebKit-https.git] / Source / WebCore / PAL / pal / spi / cf / CFNetworkSPI.h
1 /*
2  * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma clang system_header
27
28 #pragma once
29
30 #include <CFNetwork/CFNetwork.h>
31 #include <pal/spi/cf/CFNetworkConnectionCacheSPI.h>
32
33 #if ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101302 && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110200) || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 40200) || (PLATFORM(TVOS) && __TV_OS_VERSION_MIN_REQUIRED >= 110200))
34 #define USE_CFNETWORK_IGNORE_HSTS 1
35 #endif
36
37
38 #if PLATFORM(WIN) || USE(APPLE_INTERNAL_SDK)
39
40 #include <CFNetwork/CFHTTPCookiesPriv.h>
41 #include <CFNetwork/CFProxySupportPriv.h>
42 #include <CFNetwork/CFURLCachePriv.h>
43 #include <CFNetwork/CFURLConnectionPriv.h>
44 #include <CFNetwork/CFURLCredentialStorage.h>
45 #include <CFNetwork/CFURLProtocolPriv.h>
46 #include <CFNetwork/CFURLRequestPriv.h>
47 #include <CFNetwork/CFURLResponsePriv.h>
48 #include <CFNetwork/CFURLStorageSession.h>
49
50 // FIXME: Remove the defined(__OBJC__)-guard once we fix <rdar://problem/19033610>.
51 #if defined(__OBJC__) && PLATFORM(COCOA)
52 #import <CFNetwork/CFNSURLConnection.h>
53 #endif
54
55 #else // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
56
57 typedef CF_ENUM(int64_t, _TimingDataOptions)
58 {
59     _TimingDataOptionsEnableW3CNavigationTiming = (1 << 0)
60 };
61
62 enum CFURLCacheStoragePolicy {
63     kCFURLCacheStorageAllowed = 0,
64     kCFURLCacheStorageAllowedInMemoryOnly = 1,
65     kCFURLCacheStorageNotAllowed = 2
66 };
67 typedef enum CFURLCacheStoragePolicy CFURLCacheStoragePolicy;
68
69 typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
70 typedef const struct _CFURLCache* CFURLCacheRef;
71 typedef const struct _CFURLCredential* CFURLCredentialRef;
72 typedef const struct _CFURLRequest* CFURLRequestRef;
73 typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
74 typedef const struct __CFData* CFDataRef;
75 typedef const struct OpaqueCFHTTPCookie* CFHTTPCookieRef;
76 typedef struct _CFURLConnection* CFURLConnectionRef;
77 typedef struct _CFURLCredentialStorage* CFURLCredentialStorageRef;
78 typedef struct _CFURLProtectionSpace* CFURLProtectionSpaceRef;
79 typedef struct _CFURLRequest* CFMutableURLRequestRef;
80 typedef struct _CFURLResponse* CFURLResponseRef;
81 typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
82 typedef CFIndex CFURLRequestPriority;
83 typedef int CFHTTPCookieStorageAcceptPolicy;
84
85 #ifdef __BLOCKS__
86 typedef void (^CFCachedURLResponseCallBackBlock)(CFCachedURLResponseRef);
87 #endif
88
89 #if defined(__OBJC__)
90
91 @interface NSURLCache ()
92 -(instancetype)_initWithMemoryCapacity:(NSUInteger)memoryCapacity diskCapacity:(NSUInteger)diskCapacity relativePath:(NSString *)path;
93 - (CFURLCacheRef)_CFURLCache;
94 @end
95
96 @interface NSURLRequest ()
97 + (NSArray *)allowsSpecificHTTPSCertificateForHost:(NSString *)host;
98 + (void)setAllowsSpecificHTTPSCertificate:(NSArray *)allow forHost:(NSString *)host;
99 + (void)setDefaultTimeoutInterval:(NSTimeInterval)seconds;
100 - (NSArray *)contentDispositionEncodingFallbackArray;
101 - (CFURLRequestRef)_CFURLRequest;
102 - (id)_initWithCFURLRequest:(CFURLRequestRef)request;
103 - (id)_propertyForKey:(NSString *)key;
104 - (void)_setProperty:(id)value forKey:(NSString *)key;
105 #if USE(CFNETWORK_IGNORE_HSTS)
106 - (BOOL)_schemeWasUpgradedDueToDynamicHSTS;
107 - (BOOL)_preventHSTSStorage;
108 - (BOOL)_ignoreHSTS;
109 #endif
110 @end
111
112 @interface NSMutableURLRequest ()
113 - (void)setContentDispositionEncodingFallbackArray:(NSArray *)theEncodingFallbackArray;
114 - (void)setBoundInterfaceIdentifier:(NSString *)identifier;
115 #if USE(CFNETWORK_IGNORE_HSTS)
116 - (void)_setPreventHSTSStorage:(BOOL)preventHSTSStorage;
117 - (void)_setIgnoreHSTS:(BOOL)ignoreHSTS;
118 #endif
119 @end
120
121 @interface NSURLResponse ()
122 + (NSURLResponse *)_responseWithCFURLResponse:(CFURLResponseRef)response;
123 - (CFURLResponseRef)_CFURLResponse;
124 - (NSDate *)_lastModifiedDate;
125 @end
126
127 @interface NSURLSessionTask (TimingData)
128 - (NSDictionary *)_timingData;
129 @end
130
131 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
132 @interface NSURLSessionTask (ResourceHints)
133 @property (nonatomic, assign) BOOL _preconnect;
134 @end
135 #endif
136
137 @interface NSHTTPCookie ()
138 - (CFHTTPCookieRef)_CFHTTPCookie;
139 + (CFArrayRef __nullable)_ns2cfCookies:(NSArray * __nullable)nsCookies CF_RETURNS_RETAINED;
140 - (CFHTTPCookieRef __nullable)_GetInternalCFHTTPCookie;
141 @end
142
143 @interface NSURLSessionConfiguration ()
144 @property (assign) _TimingDataOptions _timingDataOptions;
145 @property (copy) NSData *_sourceApplicationAuditTokenData;
146 @property (nullable, copy) NSString *_sourceApplicationBundleIdentifier;
147 @property (nullable, copy) NSString *_sourceApplicationSecondaryIdentifier;
148 @property BOOL _shouldSkipPreferredClientCertificateLookup NS_AVAILABLE(10_10, 8_0);
149 #if PLATFORM(IOS)
150 @property (nullable, copy) NSString *_CTDataConnectionServiceType;
151 #endif
152 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
153 @property (nullable, copy) NSSet *_suppressedAutoAddedHTTPHeaders;
154 #endif
155 @end
156
157 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
158 @interface NSURLSessionTaskTransactionMetrics ()
159 @property (copy, readonly) NSString* _remoteAddressAndPort;
160 @property (copy, readonly) NSUUID* _connectionIdentifier;
161 @property (assign, readonly) NSInteger _requestHeaderBytesSent;
162 @property (assign, readonly) NSInteger _responseHeaderBytesReceived;
163 @property (assign, readonly) int64_t _responseBodyBytesReceived;
164 @property (assign, readonly) int64_t _responseBodyBytesDecoded;
165 @end
166 #endif
167
168 @interface NSHTTPCookie ()
169 @property (nullable, readonly, copy) NSString *_storagePartition;
170 @end
171
172 @interface NSHTTPCookieStorage ()
173 - (void)_getCookiesForURL:(NSURL *)url mainDocumentURL:(NSURL *)mainDocumentURL partition:(NSString *)partition completionHandler:(void (^)(NSArray *))completionHandler;
174 - (id)_initWithIdentifier:(NSString *)identifier private:(bool)isPrivate;
175 @end
176
177 @interface NSURLSessionTask ()
178 @property (readwrite, copy) NSString *_pathToDownloadTaskFile;
179 @property (copy) NSString *_storagePartitionIdentifier;
180 @end
181
182 #endif // defined(__OBJC__)
183
184 #endif // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
185
186 WTF_EXTERN_C_BEGIN
187
188 #if !PLATFORM(WIN)
189
190 CFURLStorageSessionRef _CFURLStorageSessionCreate(CFAllocatorRef, CFStringRef, CFDictionaryRef);
191 CFURLCacheRef _CFURLStorageSessionCopyCache(CFAllocatorRef, CFURLStorageSessionRef);
192
193 void CFURLRequestSetShouldStartSynchronously(CFURLRequestRef, Boolean);
194
195 CFURLCacheRef CFURLCacheCopySharedURLCache();
196 void CFURLCacheSetMemoryCapacity(CFURLCacheRef, CFIndex memoryCapacity);
197 CFIndex CFURLCacheMemoryCapacity(CFURLCacheRef);
198 void CFURLCacheSetDiskCapacity(CFURLCacheRef, CFIndex);
199 CFCachedURLResponseRef CFURLCacheCopyResponseForRequest(CFURLCacheRef, CFURLRequestRef);
200
201 #if PLATFORM(COCOA)
202 Boolean _CFNetworkIsKnownHSTSHostWithSession(CFURLRef, CFURLStorageSessionRef);
203 void _CFNetworkResetHSTSHostsWithSession(CFURLStorageSessionRef);
204 #endif
205
206 void CFHTTPCookieStorageDeleteAllCookies(CFHTTPCookieStorageRef);
207 void _CFHTTPCookieStorageFlushCookieStores();
208
209 #if PLATFORM(COCOA)
210 CFDataRef _CFCachedURLResponseGetMemMappedData(CFCachedURLResponseRef);
211 #endif
212
213 #if PLATFORM(COCOA) && defined(__BLOCKS__)
214 void _CFCachedURLResponseSetBecameFileBackedCallBackBlock(CFCachedURLResponseRef, CFCachedURLResponseCallBackBlock, dispatch_queue_t);
215 #endif
216
217 extern CFStringRef const kCFHTTPCookieLocalFileDomain;
218 extern const CFStringRef kCFHTTPVersion1_1;
219 extern const CFStringRef kCFURLRequestAllowAllPOSTCaching;
220 extern const CFStringRef _kCFURLCachePartitionKey;
221 extern const CFStringRef _kCFURLConnectionPropertyShouldSniff;
222 extern const CFStringRef _kCFURLStorageSessionIsPrivate;
223
224 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101302
225 extern const CFStringRef kCFURLRequestContentDecoderSkipURLCheck;
226 #endif
227
228 CFHTTPCookieStorageRef _CFHTTPCookieStorageGetDefault(CFAllocatorRef);
229 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromFile(CFAllocatorRef, CFURLRef, CFHTTPCookieStorageRef);
230 void CFHTTPCookieStorageScheduleWithRunLoop(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef);
231 void CFHTTPCookieStorageSetCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
232 void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
233 CFHTTPCookieStorageAcceptPolicy CFHTTPCookieStorageGetCookieAcceptPolicy(CFHTTPCookieStorageRef);
234
235 typedef void (*CFHTTPCookieStorageChangedProcPtr)(CFHTTPCookieStorageRef, void*);
236 void CFHTTPCookieStorageAddObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
237 void CFHTTPCookieStorageRemoveObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
238
239 void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
240 CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
241 CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);
242 CFURLRequestPriority CFURLRequestGetRequestPriority(CFURLRequestRef);
243 void _CFURLRequestSetProtocolProperty(CFURLRequestRef, CFStringRef, CFTypeRef);
244 void CFURLRequestSetRequestPriority(CFURLRequestRef, CFURLRequestPriority);
245 void CFURLRequestSetShouldPipelineHTTP(CFURLRequestRef, Boolean, Boolean);
246 void _CFURLRequestSetStorageSession(CFMutableURLRequestRef, CFURLStorageSessionRef);
247 CFStringRef CFURLResponseCopySuggestedFilename(CFURLResponseRef);
248 CFHTTPMessageRef CFURLResponseGetHTTPResponse(CFURLResponseRef);
249 CFStringRef CFURLResponseGetMIMEType(CFURLResponseRef);
250 CFDictionaryRef _CFURLResponseGetSSLCertificateContext(CFURLResponseRef);
251 CFURLRef CFURLResponseGetURL(CFURLResponseRef);
252 void CFURLResponseSetMIMEType(CFURLResponseRef, CFStringRef);
253 CFHTTPCookieStorageRef _CFURLStorageSessionCopyCookieStorage(CFAllocatorRef, CFURLStorageSessionRef);
254 CFArrayRef _CFHTTPCookieStorageCopyCookiesForURLWithMainDocumentURL(CFHTTPCookieStorageRef inCookieStorage, CFURLRef inURL, CFURLRef inMainDocumentURL, Boolean sendSecureCookies);
255 CFStringRef CFURLResponseGetTextEncodingName(CFURLResponseRef);
256 SInt64 CFURLResponseGetExpectedContentLength(CFURLResponseRef);
257 CFTypeID CFURLResponseGetTypeID();
258 Boolean CFURLRequestShouldHandleHTTPCookies(CFURLRequestRef);
259 CFURLRef CFURLRequestGetURL(CFURLRequestRef);
260 CFURLResponseRef CFURLResponseCreate(CFAllocatorRef, CFURLRef, CFStringRef mimeType, SInt64 expectedContentLength, CFStringRef textEncodingName, CFURLCacheStoragePolicy);
261 void CFURLResponseSetExpectedContentLength(CFURLResponseRef, SInt64 length);
262 CFURLResponseRef CFURLResponseCreateWithHTTPResponse(CFAllocatorRef, CFURLRef, CFHTTPMessageRef, CFURLCacheStoragePolicy);
263 CFArrayRef CFHTTPCookieStorageCopyCookies(CFHTTPCookieStorageRef);
264 void CFHTTPCookieStorageSetCookies(CFHTTPCookieStorageRef, CFArrayRef cookies, CFURLRef, CFURLRef mainDocumentURL);
265 void CFHTTPCookieStorageDeleteCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
266 CFMutableURLRequestRef CFURLRequestCreateMutableCopy(CFAllocatorRef, CFURLRequestRef);
267 CFStringRef _CFURLCacheCopyCacheDirectory(CFURLCacheRef);
268 Boolean _CFHostIsDomainTopLevel(CFStringRef domain);
269 void _CFURLRequestCreateArchiveList(CFAllocatorRef, CFURLRequestRef, CFIndex* version, CFTypeRef** objects, CFIndex* objectCount, CFDictionaryRef* protocolProperties);
270 CFMutableURLRequestRef _CFURLRequestCreateFromArchiveList(CFAllocatorRef, CFIndex version, CFTypeRef* objects, CFIndex objectCount, CFDictionaryRef protocolProperties);
271
272 #endif // !PLATFORM(WIN)
273
274 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxy;
275 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxyHost;
276 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxyPort;
277 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTAdditionalHeaders;
278 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTResponse;
279
280 CFN_EXPORT void _CFHTTPMessageSetResponseURL(CFHTTPMessageRef, CFURLRef);
281 CFN_EXPORT void _CFHTTPMessageSetResponseProxyURL(CFHTTPMessageRef, CFURLRef);
282
283 WTF_EXTERN_C_END
284
285 #if defined(__OBJC__) && !USE(APPLE_INTERNAL_SDK)
286
287 enum : NSUInteger {
288     NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain = 3,
289 };
290
291 @interface NSCachedURLResponse ()
292 -(id)_initWithCFCachedURLResponse:(CFCachedURLResponseRef)cachedResponse;
293 -(CFCachedURLResponseRef)_CFCachedURLResponse;
294 @end
295
296 #endif
297
298 WTF_EXTERN_C_BEGIN
299
300 CFDataRef _CFNetworkCopyATSContext(void);
301 Boolean _CFNetworkSetATSContext(CFDataRef);
302
303 #if PLATFORM(COCOA)
304 void _CFNetworkResetHSTSHostsSinceDate(CFURLStorageSessionRef, CFDateRef);
305 #endif
306
307 CFDataRef CFHTTPCookieStorageCreateIdentifyingData(CFAllocatorRef inAllocator, CFHTTPCookieStorageRef inStorage);
308 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromIdentifyingData(CFAllocatorRef inAllocator, CFDataRef inData);
309 CFArrayRef _CFHTTPParsedCookiesWithResponseHeaderFields(CFAllocatorRef inAllocator, CFDictionaryRef headerFields, CFURLRef inURL);
310
311 WTF_EXTERN_C_END
312
313 #if defined(__OBJC__)
314
315 @interface NSHTTPCookie ()
316 #if PLATFORM(MAC)
317 + (NSArray *)_parsedCookiesWithResponseHeaderFields:(NSDictionary *)headerFields forURL:(NSURL *)aURL;
318 #endif
319 + (NSArray *)_cf2nsCookies:(CFArrayRef)cfCookies;
320 @end
321
322 #if !USE(APPLE_INTERNAL_SDK)
323 @interface NSHTTPCookieStorage ()
324 - (void)removeCookiesSinceDate:(NSDate *)date;
325 - (id)_initWithCFHTTPCookieStorage:(CFHTTPCookieStorageRef)cfStorage;
326 - (CFHTTPCookieStorageRef)_cookieStorage;
327 - (void)_saveCookies;
328 @end
329 #endif
330
331 // FIXME: Move +_setSharedHTTPCookieStorage: into the above section under !USE(APPLE_INTERNAL_SDK) when possible (soon).
332 @interface NSHTTPCookieStorage ()
333 + (void)_setSharedHTTPCookieStorage:(NSHTTPCookieStorage *)storage;
334 @end
335
336 @interface NSURLResponse ()
337 - (void)_setMIMEType:(NSString *)type;
338 @end
339
340 #endif // defined(__OBJC__)