Skip to content

Commit d0b0f3c

Browse files
authored
Merge pull request #1264 from johnno1962e/HTTPS4Android
2 parents 2ffda6c + 739f4d3 commit d0b0f3c

File tree

7 files changed

+13
-201
lines changed

7 files changed

+13
-201
lines changed

Foundation/URLSession/http/EasyHandle.swift

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ internal final class _EasyHandle {
5757
fileprivate var pauseState: _PauseState = []
5858
internal var timeoutTimer: _TimeoutSource!
5959
internal lazy var errorBuffer = [UInt8](repeating: 0, count: Int(CFURLSessionEasyErrorSize))
60-
#if os(Android)
61-
static fileprivate var _CAInfoFile: UnsafeMutablePointer<Int8>?
62-
#endif
6360

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

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-
648632
extension CFURLSessionEasyCode : Equatable {
649633
public static func ==(lhs: CFURLSessionEasyCode, rhs: CFURLSessionEasyCode) -> Bool {
650634
return lhs.value == rhs.value

android/README.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

android/builder.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

android/install.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

android/package.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

android/prepare.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

android/updater.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)