Skip to content

Commit 4882119

Browse files
authored
Merge pull request #2448 from millenomi/urlprotectionspace
Parity: URLProtectionSpace
2 parents 51c6f47 + 48e4ffc commit 4882119

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

Foundation/URLProtectionSpace.swift

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,22 @@ public let NSURLAuthenticationMethodNegotiate: String = "NSURLAuthenticationMeth
9696
@const NSURLAuthenticationMethodClientCertificate
9797
@abstract SSL Client certificate. Applies to any protocol.
9898
*/
99+
@available(*, deprecated, message: "swift-corelibs-foundation does not currently support certificate authentication.")
99100
public let NSURLAuthenticationMethodClientCertificate: String = "NSURLAuthenticationMethodClientCertificate"
100101

101102
/*!
102103
@const NSURLAuthenticationMethodServerTrust
103104
@abstract SecTrustRef validation required. Applies to any protocol.
104105
*/
106+
@available(*, deprecated, message: "swift-corelibs-foundation does not support methods of authentication that rely on the Darwin Security framework.")
105107
public let NSURLAuthenticationMethodServerTrust: String = "NSURLAuthenticationMethodServerTrust"
106108

107109

108110
/*!
109111
@class URLProtectionSpace
110112
@discussion This class represents a protection space requiring authentication.
111113
*/
112-
open class URLProtectionSpace : NSObject, NSSecureCoding, NSCopying {
114+
open class URLProtectionSpace : NSObject, NSCopying {
113115

114116
private let _host: String
115117
private let _isProxy: Bool
@@ -123,17 +125,10 @@ open class URLProtectionSpace : NSObject, NSSecureCoding, NSCopying {
123125
return copy(with: nil)
124126
}
125127

126-
open func copy(with zone: NSZone? = nil) -> Any { NSUnimplemented() }
127-
public static var supportsSecureCoding: Bool { return true }
128-
129-
open func encode(with aCoder: NSCoder) {
130-
NSUnimplemented()
131-
}
132-
public required init?(coder aDecoder: NSCoder) {
133-
NSUnimplemented()
128+
open func copy(with zone: NSZone? = nil) -> Any {
129+
return self // These instances are immutable.
134130
}
135131

136-
137132
/*!
138133
@method initWithHost:port:protocol:realm:authenticationMethod:
139134
@abstract Initialize a protection space representing an origin server, or a realm on one
@@ -199,7 +194,34 @@ open class URLProtectionSpace : NSObject, NSSecureCoding, NSCopying {
199194
@abstract Determine if the password for this protection space can be sent securely
200195
@result YES if a secure authentication method or protocol will be used, NO otherwise
201196
*/
202-
open var receivesCredentialSecurely: Bool { NSUnimplemented() }
197+
open var receivesCredentialSecurely: Bool {
198+
switch self.protocol {
199+
// The documentation is ambiguous whether a protection space needs to use the NSURLProtectionSpace… constants, or URL schemes.
200+
// Allow both.
201+
case NSURLProtectionSpaceHTTPS: fallthrough
202+
case "https": fallthrough
203+
case "ftps":
204+
return true
205+
206+
default:
207+
switch authenticationMethod {
208+
case NSURLAuthenticationMethodDefault: fallthrough
209+
case NSURLAuthenticationMethodHTTPBasic: fallthrough
210+
case NSURLAuthenticationMethodHTTPDigest: fallthrough
211+
case NSURLAuthenticationMethodHTMLForm:
212+
return false
213+
214+
case NSURLAuthenticationMethodNTLM: fallthrough
215+
case NSURLAuthenticationMethodNegotiate: fallthrough
216+
case NSURLAuthenticationMethodClientCertificate: fallthrough
217+
case NSURLAuthenticationMethodServerTrust:
218+
return true
219+
220+
default:
221+
return false
222+
}
223+
}
224+
}
203225

204226
/*!
205227
@method host
@@ -333,18 +355,14 @@ extension URLProtectionSpace {
333355
@abstract Returns an array of acceptable certificate issuing authorities for client certification authentication. Issuers are identified by their distinguished name and returned as a DER encoded data.
334356
@result An array of NSData objects. (Nil if the authenticationMethod is not NSURLAuthenticationMethodClientCertificate)
335357
*/
336-
public var distinguishedNames: [Data]? { NSUnimplemented() }
337-
}
338-
339-
// TODO: Currently no implementation of Security.framework
340-
/*
341-
extension URLProtectionSpace {
358+
@available(*, deprecated, message: "swift-corelibs-foundation does not currently support certificate authentication.")
359+
public var distinguishedNames: [Data]? { return nil }
342360

343361
/*!
344362
@method serverTrust
345363
@abstract Returns a SecTrustRef which represents the state of the servers SSL transaction state
346364
@result A SecTrustRef from Security.framework. (Nil if the authenticationMethod is not NSURLAuthenticationMethodServerTrust)
347365
*/
348-
public var serverTrust: SecTrust? { NSUnimplemented() }
366+
@available(*, unavailable, message: "swift-corelibs-foundation does not support methods of authentication that rely on the Darwin Security framework.")
367+
public var serverTrust: Any? { NSUnsupported() }
349368
}
350-
*/

0 commit comments

Comments
 (0)