@@ -57,6 +57,9 @@ internal final class _EasyHandle {
57
57
fileprivate var pauseState : _PauseState = [ ]
58
58
internal var fileLength : Int64 = 0
59
59
internal var timeoutTimer : _TimeoutSource !
60
+ #if os(Android)
61
+ static fileprivate var _CAInfoFile : UnsafeMutablePointer < Int8 > ?
62
+ #endif
60
63
61
64
init ( delegate: _EasyHandleDelegate ) {
62
65
self . delegate = delegate
@@ -168,6 +171,20 @@ extension _EasyHandle {
168
171
let protocols = ( CFURLSessionProtocolHTTP | CFURLSessionProtocolHTTPS)
169
172
try ! CFURLSession_easy_setopt_long ( rawHandle, CFURLSessionOptionPROTOCOLS, protocols) . asError ( )
170
173
try ! CFURLSession_easy_setopt_long ( rawHandle, CFURLSessionOptionREDIR_PROTOCOLS, protocols) . asError ( )
174
+ #if os(Android)
175
+ // See https://curl.haxx.se/docs/sslcerts.html
176
+ // For SSL to work you need "cacert.pem" to be accessable
177
+ // at the path pointed to by the URLSessionCAInfo env var.
178
+ // Downloadable here: https://curl.haxx.se/ca/cacert.pem
179
+ if let caInfo = _EasyHandle. _CAInfoFile {
180
+ if String ( cString: caInfo) == " UNSAFE_SSL_NOVERIFY " {
181
+ try ! CFURLSession_easy_setopt_int ( rawHandle, CFURLSessionOptionSSL_VERIFYPEER, 0 ) . asError ( )
182
+ }
183
+ else {
184
+ try ! CFURLSession_easy_setopt_ptr ( rawHandle, CFURLSessionOptionCAINFO, caInfo) . asError ( )
185
+ }
186
+ }
187
+ #endif
171
188
//TODO: Added in libcurl 7.45.0
172
189
//TODO: Set default protocol for schemeless URLs
173
190
//CURLOPT_DEFAULT_PROTOCOL available only in libcurl 7.45.0
@@ -268,7 +285,7 @@ fileprivate func printLibcurlDebug(handle: CFURLSessionEasyHandle, type: CInt, d
268
285
269
286
fileprivate func printLibcurlDebug( type: CFURLSessionInfo , data: String , task: URLSessionTask ) {
270
287
// libcurl sends is data with trailing CRLF which inserts lots of newlines into our output.
271
- print ( " [ \( task. taskIdentifier) ] \( type. debugHeader) \( data. mapControlToPictures) " )
288
+ NSLog ( " [ \( task. taskIdentifier) ] \( type. debugHeader) \( data. mapControlToPictures) " )
272
289
}
273
290
274
291
fileprivate extension String {
@@ -615,6 +632,19 @@ extension _EasyHandle._CurlStringList {
615
632
}
616
633
}
617
634
635
+ #if os(Android)
636
+ extension URLSession {
637
+
638
+ public static func setCAInfoFile( _ _CAInfoFile: String ) {
639
+ free ( _EasyHandle. _CAInfoFile)
640
+ _CAInfoFile. withCString {
641
+ _EasyHandle. _CAInfoFile = strdup ( $0)
642
+ }
643
+ }
644
+
645
+ }
646
+ #endif
647
+
618
648
extension CFURLSessionEasyCode : Equatable {
619
649
public static func == ( lhs: CFURLSessionEasyCode , rhs: CFURLSessionEasyCode ) -> Bool {
620
650
return lhs. value == rhs. value
0 commit comments