Skip to content

Commit b521aae

Browse files
committed
For HTTPS on Android III
1 parent ef5b7be commit b521aae

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

Foundation/URLSession/http/EasyHandle.swift

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ internal final class _EasyHandle {
5656
fileprivate var headerList: _CurlStringList?
5757
fileprivate var pauseState: _PauseState = []
5858
internal var timeoutTimer: _TimeoutSource!
59-
#if os(Android)
60-
static fileprivate var _CAInfoFile: UnsafeMutablePointer<Int8>?
61-
#endif
6259

6360
init(delegate: _EasyHandleDelegate) {
6461
self.delegate = delegate
@@ -170,20 +167,20 @@ extension _EasyHandle {
170167
let protocols = (CFURLSessionProtocolHTTP | CFURLSessionProtocolHTTPS)
171168
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionPROTOCOLS, protocols).asError()
172169
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionREDIR_PROTOCOLS, protocols).asError()
173-
#if os(Android)
174-
// See https://curl.haxx.se/docs/sslcerts.html
175-
// For SSL to work you need "cacert.pem" to be accessable
176-
// at the path pointed to by the URLSessionCAInfo env var.
177-
// Downloadable here: https://curl.haxx.se/ca/cacert.pem
178-
if let caInfo = _EasyHandle._CAInfoFile {
179-
if String(cString: caInfo) == "UNSAFE_SSL_NOVERIFY" {
180-
try! CFURLSession_easy_setopt_int(rawHandle, CFURLSessionOptionSSL_VERIFYPEER, 0).asError()
181-
}
182-
else {
183-
try! CFURLSession_easy_setopt_ptr(rawHandle, CFURLSessionOptionCAINFO, caInfo).asError()
184-
}
170+
#if os(Android)
171+
// See https://curl.haxx.se/docs/sslcerts.html
172+
// For SSL on Android you need a "cacert.pem" to be
173+
// accessible at the path pointed to by this env var.
174+
// Downloadable here: https://curl.haxx.se/ca/cacert.pem
175+
if let caInfo = getenv("URLSessionCertificateAuthorityInfoFile") {
176+
if String(cString: caInfo) == "INSECURE_SSL_NO_VERIFY" {
177+
try! CFURLSession_easy_setopt_long(rawHandle, CFURLSessionOptionSSL_VERIFYPEER, 0).asError()
178+
}
179+
else {
180+
try! CFURLSession_easy_setopt_ptr(rawHandle, CFURLSessionOptionCAINFO, caInfo).asError()
185181
}
186-
#endif
182+
}
183+
#endif
187184
//TODO: Added in libcurl 7.45.0
188185
//TODO: Set default protocol for schemeless URLs
189186
//CURLOPT_DEFAULT_PROTOCOL available only in libcurl 7.45.0
@@ -630,19 +627,6 @@ extension _EasyHandle._CurlStringList {
630627
}
631628
}
632629

633-
#if os(Android)
634-
extension URLSession {
635-
636-
public static func setCAInfoFile(_ _CAInfoFile: String) {
637-
free(_EasyHandle._CAInfoFile)
638-
_CAInfoFile.withCString {
639-
_EasyHandle._CAInfoFile = strdup($0)
640-
}
641-
}
642-
643-
}
644-
#endif
645-
646630
extension CFURLSessionEasyCode : Equatable {
647631
public static func ==(lhs: CFURLSessionEasyCode, rhs: CFURLSessionEasyCode) -> Bool {
648632
return lhs.value == rhs.value

0 commit comments

Comments
 (0)