Ignore HSTS for partitioned, cross-origin subresource requests
[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(WIN) || USE(APPLE_INTERNAL_SDK)
34
35 #include <CFNetwork/CFHTTPCookiesPriv.h>
36 #include <CFNetwork/CFProxySupportPriv.h>
37 #include <CFNetwork/CFURLCachePriv.h>
38 #include <CFNetwork/CFURLConnectionPriv.h>
39 #include <CFNetwork/CFURLCredentialStorage.h>
40 #include <CFNetwork/CFURLProtocolPriv.h>
41 #include <CFNetwork/CFURLRequestPriv.h>
42 #include <CFNetwork/CFURLResponsePriv.h>
43 #include <CFNetwork/CFURLStorageSession.h>
44
45 // FIXME: Remove the defined(__OBJC__)-guard once we fix <rdar://problem/19033610>.
46 #if defined(__OBJC__) && PLATFORM(COCOA)
47 #import <CFNetwork/CFNSURLConnection.h>
48 #endif
49
50 #else // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
51
52 typedef CF_ENUM(int64_t, _TimingDataOptions)
53 {
54     _TimingDataOptionsEnableW3CNavigationTiming = (1 << 0)
55 };
56
57 enum CFURLCacheStoragePolicy {
58     kCFURLCacheStorageAllowed = 0,
59     kCFURLCacheStorageAllowedInMemoryOnly = 1,
60     kCFURLCacheStorageNotAllowed = 2
61 };
62 typedef enum CFURLCacheStoragePolicy CFURLCacheStoragePolicy;
63
64 typedef const struct _CFCachedURLResponse* CFCachedURLResponseRef;
65 typedef const struct _CFURLCache* CFURLCacheRef;
66 typedef const struct _CFURLCredential* CFURLCredentialRef;
67 typedef const struct _CFURLRequest* CFURLRequestRef;
68 typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
69 typedef const struct __CFData* CFDataRef;
70 typedef const struct OpaqueCFHTTPCookie* CFHTTPCookieRef;
71 typedef struct _CFURLConnection* CFURLConnectionRef;
72 typedef struct _CFURLCredentialStorage* CFURLCredentialStorageRef;
73 typedef struct _CFURLProtectionSpace* CFURLProtectionSpaceRef;
74 typedef struct _CFURLRequest* CFMutableURLRequestRef;
75 typedef struct _CFURLResponse* CFURLResponseRef;
76 typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
77 typedef CFIndex CFURLRequestPriority;
78 typedef int CFHTTPCookieStorageAcceptPolicy;
79
80 #ifdef __BLOCKS__
81 typedef void (^CFCachedURLResponseCallBackBlock)(CFCachedURLResponseRef);
82 #endif
83
84 #if defined(__OBJC__)
85
86 @interface NSURLCache ()
87 -(instancetype)_initWithMemoryCapacity:(NSUInteger)memoryCapacity diskCapacity:(NSUInteger)diskCapacity relativePath:(NSString *)path;
88 - (CFURLCacheRef)_CFURLCache;
89 @end
90
91 @interface NSURLRequest ()
92 + (NSArray *)allowsSpecificHTTPSCertificateForHost:(NSString *)host;
93 + (void)setAllowsSpecificHTTPSCertificate:(NSArray *)allow forHost:(NSString *)host;
94 + (void)setDefaultTimeoutInterval:(NSTimeInterval)seconds;
95 - (NSArray *)contentDispositionEncodingFallbackArray;
96 - (CFURLRequestRef)_CFURLRequest;
97 - (id)_initWithCFURLRequest:(CFURLRequestRef)request;
98 - (id)_propertyForKey:(NSString *)key;
99 - (void)_setProperty:(id)value forKey:(NSString *)key;
100 @end
101
102 #if HAVE(CFNETWORK_IGNORE_HSTS)
103 @interface NSURLRequest ()
104 - (BOOL)_schemeWasUpgradedDueToDynamicHSTS;
105 - (BOOL)_preventHSTSStorage;
106 - (BOOL)_ignoreHSTS;
107 @end
108 #endif
109
110 @interface NSMutableURLRequest ()
111 - (void)setContentDispositionEncodingFallbackArray:(NSArray *)theEncodingFallbackArray;
112 - (void)setBoundInterfaceIdentifier:(NSString *)identifier;
113 @end
114
115 #if HAVE(CFNETWORK_IGNORE_HSTS)
116 @interface NSMutableURLRequest ()
117 - (void)_setPreventHSTSStorage:(BOOL)preventHSTSStorage;
118 - (void)_setIgnoreHSTS:(BOOL)ignoreHSTS;
119 @end
120 #endif
121
122 @interface NSURLResponse ()
123 + (NSURLResponse *)_responseWithCFURLResponse:(CFURLResponseRef)response;
124 - (CFURLResponseRef)_CFURLResponse;
125 - (NSDate *)_lastModifiedDate;
126 @end
127
128 @interface NSURLSessionTask (TimingData)
129 - (NSDictionary *)_timingData;
130 @end
131
132 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
133 @interface NSURLSessionTask (ResourceHints)
134 @property (nonatomic, assign) BOOL _preconnect;
135 @end
136 #endif
137
138 @interface NSHTTPCookie ()
139 - (CFHTTPCookieRef)_CFHTTPCookie;
140 + (CFArrayRef __nullable)_ns2cfCookies:(NSArray * __nullable)nsCookies CF_RETURNS_RETAINED;
141 - (CFHTTPCookieRef __nullable)_GetInternalCFHTTPCookie;
142 @end
143
144 @interface NSURLSessionConfiguration ()
145 @property (assign) _TimingDataOptions _timingDataOptions;
146 @property (copy) NSData *_sourceApplicationAuditTokenData;
147 @property (nullable, copy) NSString *_sourceApplicationBundleIdentifier;
148 @property (nullable, copy) NSString *_sourceApplicationSecondaryIdentifier;
149 @property BOOL _shouldSkipPreferredClientCertificateLookup NS_AVAILABLE(10_10, 8_0);
150 #if PLATFORM(IOS)
151 @property (nullable, copy) NSString *_CTDataConnectionServiceType;
152 #endif
153 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
154 @property (nullable, copy) NSSet *_suppressedAutoAddedHTTPHeaders;
155 #endif
156 @end
157
158 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000)
159 @interface NSURLSessionTaskTransactionMetrics ()
160 @property (copy, readonly) NSString* _remoteAddressAndPort;
161 @property (copy, readonly) NSUUID* _connectionIdentifier;
162 @property (assign, readonly) NSInteger _requestHeaderBytesSent;
163 @property (assign, readonly) NSInteger _responseHeaderBytesReceived;
164 @property (assign, readonly) int64_t _responseBodyBytesReceived;
165 @property (assign, readonly) int64_t _responseBodyBytesDecoded;
166 @end
167 #endif
168
169 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || PLATFORM(IOS)
170 @interface NSHTTPCookie ()
171 @property (nullable, readonly, copy) NSString *_storagePartition;
172 @end
173
174 @interface NSHTTPCookieStorage ()
175 - (void)_getCookiesForURL:(NSURL *)url mainDocumentURL:(NSURL *)mainDocumentURL partition:(NSString *)partition completionHandler:(void (^)(NSArray *))completionHandler;
176 @end
177
178 @interface NSURLSessionTask ()
179 @property (readwrite, copy) NSString *_pathToDownloadTaskFile;
180 @property (copy) NSString *_storagePartitionIdentifier;
181 @end
182 #endif
183
184 #endif // defined(__OBJC__)
185
186 #endif // !PLATFORM(WIN) && !USE(APPLE_INTERNAL_SDK)
187
188 WTF_EXTERN_C_BEGIN
189
190 #if !PLATFORM(WIN)
191
192 CFURLStorageSessionRef _CFURLStorageSessionCreate(CFAllocatorRef, CFStringRef, CFDictionaryRef);
193 CFURLCacheRef _CFURLStorageSessionCopyCache(CFAllocatorRef, CFURLStorageSessionRef);
194
195 void CFURLRequestSetShouldStartSynchronously(CFURLRequestRef, Boolean);
196
197 CFURLCacheRef CFURLCacheCopySharedURLCache();
198 void CFURLCacheSetMemoryCapacity(CFURLCacheRef, CFIndex memoryCapacity);
199 CFIndex CFURLCacheMemoryCapacity(CFURLCacheRef);
200 void CFURLCacheSetDiskCapacity(CFURLCacheRef, CFIndex);
201 CFCachedURLResponseRef CFURLCacheCopyResponseForRequest(CFURLCacheRef, CFURLRequestRef);
202
203 #if PLATFORM(COCOA)
204 Boolean _CFNetworkIsKnownHSTSHostWithSession(CFURLRef, CFURLStorageSessionRef);
205 void _CFNetworkResetHSTSHostsWithSession(CFURLStorageSessionRef);
206 #endif
207
208 void CFHTTPCookieStorageDeleteAllCookies(CFHTTPCookieStorageRef);
209 void _CFHTTPCookieStorageFlushCookieStores();
210
211 #if PLATFORM(COCOA)
212 CFDataRef _CFCachedURLResponseGetMemMappedData(CFCachedURLResponseRef);
213 #endif
214
215 #if PLATFORM(COCOA) && defined(__BLOCKS__)
216 void _CFCachedURLResponseSetBecameFileBackedCallBackBlock(CFCachedURLResponseRef, CFCachedURLResponseCallBackBlock, dispatch_queue_t);
217 #endif
218
219 extern CFStringRef const kCFHTTPCookieLocalFileDomain;
220 extern const CFStringRef kCFHTTPVersion1_1;
221 extern const CFStringRef kCFURLRequestAllowAllPOSTCaching;
222 extern const CFStringRef _kCFURLCachePartitionKey;
223 extern const CFStringRef _kCFURLConnectionPropertyShouldSniff;
224 extern const CFStringRef _kCFURLStorageSessionIsPrivate;
225
226 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101302
227 extern const CFStringRef kCFURLRequestContentDecoderSkipURLCheck;
228 #endif
229
230 CFHTTPCookieStorageRef _CFHTTPCookieStorageGetDefault(CFAllocatorRef);
231 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromFile(CFAllocatorRef, CFURLRef, CFHTTPCookieStorageRef);
232 void CFHTTPCookieStorageScheduleWithRunLoop(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef);
233 void CFHTTPCookieStorageSetCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
234 void CFHTTPCookieStorageSetCookieAcceptPolicy(CFHTTPCookieStorageRef, CFHTTPCookieStorageAcceptPolicy);
235 CFHTTPCookieStorageAcceptPolicy CFHTTPCookieStorageGetCookieAcceptPolicy(CFHTTPCookieStorageRef);
236
237 typedef void (*CFHTTPCookieStorageChangedProcPtr)(CFHTTPCookieStorageRef, void*);
238 void CFHTTPCookieStorageAddObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
239 void CFHTTPCookieStorageRemoveObserver(CFHTTPCookieStorageRef, CFRunLoopRef, CFStringRef, CFHTTPCookieStorageChangedProcPtr, void*);
240
241 void _CFNetworkSetOverrideSystemProxySettings(CFDictionaryRef);
242 CFURLCredentialStorageRef CFURLCredentialStorageCreate(CFAllocatorRef);
243 CFURLCredentialRef CFURLCredentialStorageCopyDefaultCredentialForProtectionSpace(CFURLCredentialStorageRef, CFURLProtectionSpaceRef);
244 CFURLRequestPriority CFURLRequestGetRequestPriority(CFURLRequestRef);
245 void _CFURLRequestSetProtocolProperty(CFURLRequestRef, CFStringRef, CFTypeRef);
246 void CFURLRequestSetRequestPriority(CFURLRequestRef, CFURLRequestPriority);
247 void CFURLRequestSetShouldPipelineHTTP(CFURLRequestRef, Boolean, Boolean);
248 void _CFURLRequestSetStorageSession(CFMutableURLRequestRef, CFURLStorageSessionRef);
249 CFStringRef CFURLResponseCopySuggestedFilename(CFURLResponseRef);
250 CFHTTPMessageRef CFURLResponseGetHTTPResponse(CFURLResponseRef);
251 CFStringRef CFURLResponseGetMIMEType(CFURLResponseRef);
252 CFDictionaryRef _CFURLResponseGetSSLCertificateContext(CFURLResponseRef);
253 CFURLRef CFURLResponseGetURL(CFURLResponseRef);
254 void CFURLResponseSetMIMEType(CFURLResponseRef, CFStringRef);
255 CFHTTPCookieStorageRef _CFURLStorageSessionCopyCookieStorage(CFAllocatorRef, CFURLStorageSessionRef);
256 CFArrayRef _CFHTTPCookieStorageCopyCookiesForURLWithMainDocumentURL(CFHTTPCookieStorageRef inCookieStorage, CFURLRef inURL, CFURLRef inMainDocumentURL, Boolean sendSecureCookies);
257 CFStringRef CFURLResponseGetTextEncodingName(CFURLResponseRef);
258 SInt64 CFURLResponseGetExpectedContentLength(CFURLResponseRef);
259 CFTypeID CFURLResponseGetTypeID();
260 Boolean CFURLRequestShouldHandleHTTPCookies(CFURLRequestRef);
261 CFURLRef CFURLRequestGetURL(CFURLRequestRef);
262 CFURLResponseRef CFURLResponseCreate(CFAllocatorRef, CFURLRef, CFStringRef mimeType, SInt64 expectedContentLength, CFStringRef textEncodingName, CFURLCacheStoragePolicy);
263 void CFURLResponseSetExpectedContentLength(CFURLResponseRef, SInt64 length);
264 CFURLResponseRef CFURLResponseCreateWithHTTPResponse(CFAllocatorRef, CFURLRef, CFHTTPMessageRef, CFURLCacheStoragePolicy);
265 CFArrayRef CFHTTPCookieStorageCopyCookies(CFHTTPCookieStorageRef);
266 void CFHTTPCookieStorageSetCookies(CFHTTPCookieStorageRef, CFArrayRef cookies, CFURLRef, CFURLRef mainDocumentURL);
267 void CFHTTPCookieStorageDeleteCookie(CFHTTPCookieStorageRef, CFHTTPCookieRef);
268 CFMutableURLRequestRef CFURLRequestCreateMutableCopy(CFAllocatorRef, CFURLRequestRef);
269 CFStringRef _CFURLCacheCopyCacheDirectory(CFURLCacheRef);
270 Boolean _CFHostIsDomainTopLevel(CFStringRef domain);
271 void _CFURLRequestCreateArchiveList(CFAllocatorRef, CFURLRequestRef, CFIndex* version, CFTypeRef** objects, CFIndex* objectCount, CFDictionaryRef* protocolProperties);
272 CFMutableURLRequestRef _CFURLRequestCreateFromArchiveList(CFAllocatorRef, CFIndex version, CFTypeRef* objects, CFIndex objectCount, CFDictionaryRef protocolProperties);
273
274 #endif // !PLATFORM(WIN)
275
276 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxy;
277 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxyHost;
278 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTProxyPort;
279 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTAdditionalHeaders;
280 CFN_EXPORT const CFStringRef kCFStreamPropertyCONNECTResponse;
281
282 CFN_EXPORT void _CFHTTPMessageSetResponseURL(CFHTTPMessageRef, CFURLRef);
283 CFN_EXPORT void _CFHTTPMessageSetResponseProxyURL(CFHTTPMessageRef, CFURLRef);
284
285 WTF_EXTERN_C_END
286
287 #if defined(__OBJC__) && !USE(APPLE_INTERNAL_SDK)
288
289 enum : NSUInteger {
290     NSHTTPCookieAcceptPolicyExclusivelyFromMainDocumentDomain = 3,
291 };
292
293 @interface NSCachedURLResponse ()
294 -(id)_initWithCFCachedURLResponse:(CFCachedURLResponseRef)cachedResponse;
295 -(CFCachedURLResponseRef)_CFCachedURLResponse;
296 @end
297
298 #endif
299
300 WTF_EXTERN_C_BEGIN
301
302 CFDataRef _CFNetworkCopyATSContext(void);
303 Boolean _CFNetworkSetATSContext(CFDataRef);
304
305 #if PLATFORM(COCOA)
306 void _CFNetworkResetHSTSHostsSinceDate(CFURLStorageSessionRef, CFDateRef);
307 #endif
308
309 CFDataRef CFHTTPCookieStorageCreateIdentifyingData(CFAllocatorRef inAllocator, CFHTTPCookieStorageRef inStorage);
310 CFHTTPCookieStorageRef CFHTTPCookieStorageCreateFromIdentifyingData(CFAllocatorRef inAllocator, CFDataRef inData);
311 CFArrayRef _CFHTTPParsedCookiesWithResponseHeaderFields(CFAllocatorRef inAllocator, CFDictionaryRef headerFields, CFURLRef inURL);
312
313 WTF_EXTERN_C_END
314
315 #if defined(__OBJC__)
316
317 @interface NSHTTPCookie ()
318 #if PLATFORM(MAC)
319 + (NSArray *)_parsedCookiesWithResponseHeaderFields:(NSDictionary *)headerFields forURL:(NSURL *)aURL;
320 #endif
321 + (NSArray *)_cf2nsCookies:(CFArrayRef)cfCookies;
322 @end
323
324 #if !USE(APPLE_INTERNAL_SDK)
325 @interface NSHTTPCookieStorage ()
326 - (void)removeCookiesSinceDate:(NSDate *)date;
327 - (id)_initWithCFHTTPCookieStorage:(CFHTTPCookieStorageRef)cfStorage;
328 - (CFHTTPCookieStorageRef)_cookieStorage;
329 - (void)_saveCookies;
330 @end
331 #endif
332
333 // FIXME: Move +_setSharedHTTPCookieStorage: into the above section under !USE(APPLE_INTERNAL_SDK) when possible (soon).
334 @interface NSHTTPCookieStorage ()
335 + (void)_setSharedHTTPCookieStorage:(NSHTTPCookieStorage *)storage;
336 @end
337
338 @interface NSURLResponse ()
339 - (void)_setMIMEType:(NSString *)type;
340 @end
341
342 #endif // defined(__OBJC__)