forked from Alamofire/Alamofire
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/opening_up_request
# Conflicts: # Source/Request.swift
- Loading branch information
Showing
39 changed files
with
2,959 additions
and
272 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,10 @@ | |
|
||
[![Build Status](https://travis-ci.org/Alamofire/Alamofire.svg)](https://travis-ci.org/Alamofire/Alamofire) | ||
[![Cocoapods Compatible](https://img.shields.io/cocoapods/v/Alamofire.svg)](https://img.shields.io/cocoapods/v/Alamofire.svg) | ||
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) | ||
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) | ||
[![License](https://img.shields.io/cocoapods/l/Alamofire.svg?style=flat&color=gray)](http://cocoadocs.org/docsets/Alamofire) | ||
[![Platform](https://img.shields.io/cocoapods/p/Alamofire.svg?style=flat)](http://cocoadocs.org/docsets/Alamofire) | ||
[![Twitter](https://img.shields.io/badge/[email protected]?style=flat)](http://twitter.com/AlamofireSF) | ||
|
||
Alamofire is an HTTP networking library written in Swift. | ||
|
||
|
@@ -293,7 +296,7 @@ Adding a custom HTTP header to a `Request` is supported directly in the global ` | |
```swift | ||
let headers = [ | ||
"Authorization", "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", | ||
"Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==", | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
] | ||
|
||
|
@@ -882,6 +885,59 @@ enum Router: URLRequestConvertible { | |
Alamofire.request(Router.ReadUser("mattt")) // GET /users/mattt | ||
``` | ||
|
||
### Security | ||
|
||
Using a secure HTTPS connection when communicating with servers and web services is an important step in securing sensitive data. By default, Alamofire will evaluate the certificate chain provided by the server using Apple's built in validation provided by the Security framework. While this guarantees the certificate chain is valid, it does not prevent man-in-the-middle (MITM) attacks or other potential vulnerabilities. In order to mitigate MITM attacks, applications dealing with sensitive customer data or financial information should use certificate or public key pinning provided by the `ServerTrustPolicy`. | ||
|
||
#### ServerTrustPolicy | ||
|
||
The `ServerTrustPolicy` enumeration evaluates the server trust generally provided by an `NSURLAuthenticationChallenge` when connecting to a server over a secure HTTPS connection. | ||
|
||
```swift | ||
let serverTrustPolicy = ServerTrustPolicy.PinCertificates( | ||
certificates: ServerTrustPolicy.certificatesInBundle(), | ||
validateCertificateChain: true, | ||
validateHost: true | ||
) | ||
``` | ||
|
||
There are many different cases of server trust evaluation giving you complete control over the validation process: | ||
|
||
* `PerformDefaultEvaluation`: Uses the default server trust evaluation while allowing you to control whether to validate the host provided by the challenge. | ||
* `PinCertificates`: Uses the pinned certificates to validate the server trust. The server trust is considered valid if one of the pinned certificates match one of the server certificates. | ||
* `PinPublicKeys`: Uses the pinned public keys to validate the server trust. The server trust is considered valid if one of the pinned public keys match one of the server certificate public keys. | ||
* `DisableEvaluation`: Disables all evaluation which in turn will always consider any server trust as valid. | ||
* `CustomEvaluation`: Uses the associated closure to evaluate the validity of the server trust thus giving you complete control over the validation process. Use with caution. | ||
|
||
#### Server Trust Policy Manager | ||
|
||
The `ServerTrustPolicyManager` is responsible for storing an internal mapping of server trust policies to a particular host. This allows Alamofire to evaluate each host against a different server trust policy. | ||
|
||
```swift | ||
let serverTrustPolicies: [String: ServerTrustPolicy] = [ | ||
"test.example.com": .PinCertificates( | ||
certificates: ServerTrustPolicy.certificatesInBundle(), | ||
validateCertificateChain: true, | ||
validateHost: true | ||
), | ||
"insecure.expired-apis.com": .DisableEvaluation | ||
] | ||
|
||
let manager = Manager( | ||
configuration: NSURLSessionConfiguration.defaultSessionConfiguration(), | ||
serverTrustPolicyManager: ServerTrustPolicyManager(policies: serverTrustPolicies) | ||
) | ||
``` | ||
|
||
These server trust policies will result in the following behavior: | ||
|
||
* `test.example.com` will always use certificate pinning with certificate chain and host validation enabled thus requiring the following criteria to be met to allow the TLS handshake to succeed: | ||
* Certificate chain MUST be valid. | ||
* Certificate chain MUST include one of the pinned certificates. | ||
* Challenge host MUST match the host in the certificate chain's leaf certificate. | ||
* `insecure.expired-apis.com` will never evaluate the certificate chain and will always allow the TLS handshake to succeed. | ||
* All other hosts will use the default evaluation provided by Apple. | ||
|
||
* * * | ||
|
||
## FAQ | ||
|
@@ -899,8 +955,6 @@ AFNetworking remains the premiere networking library available for OS X and iOS, | |
Use AFNetworking for any of the following: | ||
|
||
- UIKit extensions, such as asynchronously loading images to `UIImageView` | ||
- TLS verification, using `AFSecurityManager` | ||
- Situations requiring `NSOperation` or `NSURLConnection`, using `AFURLConnectionOperation` | ||
- Network reachability monitoring, using `AFNetworkReachabilityManager` | ||
|
||
### What's the origin of the name Alamofire? | ||
|
@@ -911,7 +965,11 @@ Alamofire is named after the [Alamo Fire flower](https://aggie-horticulture.tamu | |
|
||
## Credits | ||
|
||
Alamofire is owned and maintained by the [Alamofire Software Foundation](http://alamofire.org). | ||
Alamofire is owned and maintained by the [Alamofire Software Foundation](http://alamofire.org). You can follow them on Twitter at [@AlamofireSF](https://twitter.com/AlamofireSF) for project updates and releases. | ||
|
||
### Security Disclosure | ||
|
||
If you believe you have identified a security vulnerability with Alamofire, you should report it as soon as possible via email to [email protected]. Please do not post it to a public issue tracker. | ||
|
||
## License | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.