Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Form custom SSL error message if API not available
  • Loading branch information
viktorasl committed Nov 5, 2019
commit bfce850f289ff87904b887c9e31c5dc1a1ab31c5
15 changes: 13 additions & 2 deletions XCode/Sources/Errno.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@ public class Errno {

#if !os(Linux)
public class func sslError(from status: OSStatus) -> Error {
guard let msg = SecCopyErrorMessageString(status, nil) else {
guard let msg = getMessage(from: status) else {
return SocketError.tlsSessionFailed("<\(status): message is not provided>")
}
return SocketError.tlsSessionFailed(msg as NSString as String)
return SocketError.tlsSessionFailed(msg)
}

private class func getMessage(from status: OSStatus) -> String? {
if #available(iOS 11.3, tvOS 11.3, *) {
guard let msg = SecCopyErrorMessageString(status, nil) else {
return nil
}
return msg as String
} else {
return "SSL error (\(status))"
}
}
#endif
Comment on lines +17 to +35
Copy link
Copy Markdown
Member

@Vkt0r Vkt0r Nov 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SecCopyErrorMessageString is only available for iOS 11.3+ and we're supporting iOS 8+, not sure which is the counterpart here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Very weird that Xcode didn't notify me.
Could not find any counterpart so formed custom message.

}
2 changes: 2 additions & 0 deletions XCode/Sources/TlsSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public enum TLS {
throw SocketError.tlsSessionFailed("Could not retrieve p12 data from given certificate")
}
// must be force casted, will be fixed in swift 5 https://bugs.swift.org/browse/SR-7015
// swiftlint:disable force_cast
let secIdentity = dictionary[kSecImportItemIdentity as String] as! SecIdentity
// swiftlint:enable force_cast
let chainWithoutIdentity = chain.dropFirst()
let certs = [secIdentity] + chainWithoutIdentity.map { $0 as Any }
return certs as CFArray
Expand Down