-
Notifications
You must be signed in to change notification settings - Fork 554
SSL support #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stable
Are you sure you want to change the base?
SSL support #427
Changes from 1 commit
8265d2c
c3923e3
2f394db
ff4257a
756716d
c5caed9
5d64270
d128cbf
88c4578
bfce850
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // | ||
| // HttpRouter.swift | ||
| // Swifter | ||
| // | ||
| // Copyright (c) 2014-2016 Damian Kołakowski. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| #if !os(Linux) | ||
| private func ensureNoErr(_ status: OSStatus) throws { | ||
| guard status == noErr else { | ||
| throw Errno.sslError(from: status) | ||
| } | ||
| } | ||
|
|
||
| public enum TLS { | ||
| public static func loadP12Certificate(_ _data: Data, _ password: String) throws -> CFArray { | ||
| let data = _data as NSData | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most of Core Foundation types are toll-free bridged to their Cocoa Foundation counterparts and can be used interchangeably. But I agree, it's better to use actually expected type names here. Will fix that. /cc https://developer.apple.com/documentation/corefoundation/cfdata-rv9 |
||
| let options = [kSecImportExportPassphrase: password] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the way Apple does it in the page you referenced they make a cast to let options = [ kSecImportExportPassphrase as String: password ]Do we know what difference could generate?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to same discussion of |
||
| var items: CFArray! | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we please make this |
||
| try ensureNoErr(SecPKCS12Import(data, options as NSDictionary, &items)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
try ensureNoErr(withUnsafeMutablePointer(to: &items) { SecPKCS12Import(data, options as CFDictionary, $0) })
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fully sure what |
||
| let dictionary = (items! as [AnyObject])[0] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The guard let dictionary = (items as? [[String: Any]]).first else { throw SomeError } |
||
| let secIdentity = dictionary[kSecImportItemIdentity] as! SecIdentity | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here we can please avoid the force-unwrapping even when Apple does in his examples?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this cannot quite be avoided, because when trying to make it optional compiler produces |
||
| let chain = dictionary[kSecImportItemCertChain] as! [SecCertificate] | ||
| let certs = [secIdentity] + chain.dropFirst().map { $0 as Any } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason we are dropping the first
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from
so |
||
| return certs as CFArray | ||
| } | ||
| } | ||
| #endif | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SecCopyErrorMessageStringis only available for iOS 11.3+ and we're supporting iOS 8+, not sure which is the counterpart here.There was a problem hiding this comment.
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.