Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
white49
Alamofire
提交
8094b368
A
Alamofire
项目概览
white49
/
Alamofire
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
Alamofire
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8094b368
编写于
7月 19, 2015
作者:
C
Christian Noon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added public docstrings for all public APIs in the ServerTrustPolicy.
上级
eed31ab5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
67 addition
and
6 deletion
+67
-6
Source/ServerTrustPolicy.swift
Source/ServerTrustPolicy.swift
+67
-6
未找到文件。
Source/ServerTrustPolicy.swift
浏览文件 @
8094b368
...
...
@@ -22,11 +22,22 @@
import
Foundation
//
TODO: DocStrings
//
/ Responsible for managing the mapping of `ServerTrustPolicy` objects to a given host.
public
class
ServerTrustPolicyManager
{
let
policies
:
[
String
:
ServerTrustPolicy
]
// TODO: DocStrings
/**
Initializes the `ServerTrustPolicyManager` instance with the given policies.
Since different servers and web services can have different leaf certificates, intermediate and even root
certficates, it is important to have the flexibility to specify evaluation policies on a per host basis. This
allows for scenarios such as using default evaluation for host1, certificate pinning for host2, public key
pinning for host3 and disabling evaluation for host4.
:param: policies A dictionary of all policies mapped to a particular host.
:returns: The new `ServerTrustPolicyManager` instance.
*/
public
init
(
policies
:
[
String
:
ServerTrustPolicy
])
{
self
.
policies
=
policies
}
...
...
@@ -55,7 +66,38 @@ extension NSURLSession {
// MARK: - ServerTrustPolicy
// TODO: DocStrings
/**
The `ServerTrustPolicy` evaluates the server trust generally provided by an `NSURLAuthenticationChallenge` when
connecting to a server over a secure HTTPS connection. The policy configuration then evaluates the server trust
with a given set of criteria to determine whether the server trust is valid and the connection should be made.
Using pinned certificates or public keys for evaluation helps prevent man-in-the-middle (MITM) attacks and other
vulnerabilities. Applications dealing with sensitive customer data or financial information are strongly encouraged
to route all communication over an HTTPS connection with pinning enabled.
- PerformDefaultEvaluation: Uses the default server trust evaluation while allowing you to control whether to
validate the host provided by the challenge. Applications are encouraged to always
validate the host in production environments to guarantee the validity of the server's
certificate chain.
- 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.
By validating both the certificate chain and host, certificate pinning provides a very
secure form of server trust validation mitigating most, if not all, MITM attacks.
Applications are encouraged to always validate the host and require a valid certificate
chain in production environments.
- 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.
By validating both the certificate chain and host, public key pinning provides a very
secure form of server trust validation mitigating most, if not all, MITM attacks.
Applications are encouraged to always validate the host and require a valid certificate
chain in production environments.
- 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.
*/
public
enum
ServerTrustPolicy
{
case
PerformDefaultEvaluation
(
validateHost
:
Bool
)
case
PinCertificates
(
certificates
:
[
SecCertificate
],
validateCertificateChain
:
Bool
,
validateHost
:
Bool
)
...
...
@@ -65,7 +107,13 @@ public enum ServerTrustPolicy {
// MARK: - Bundle Location
// TODO: DocStrings
/**
Returns all certificates within the given bundle with a `.cer` file extension.
:param: bundle The bundle to search for all `.cer` files.
:returns: All certificates within the given bundle.
*/
public
func
certificatesInBundle
(
bundle
:
NSBundle
=
NSBundle
.
mainBundle
())
->
[
SecCertificate
]
{
var
certificates
:
[
SecCertificate
]
=
[]
...
...
@@ -81,7 +129,13 @@ public enum ServerTrustPolicy {
return
certificates
}
// TODO: DocStrings
/**
Returns all public keys within the given bundle with a `.cer` file extension.
:param: bundle The bundle to search for all `*.cer` files.
:returns: All public keys within the given bundle.
*/
public
func
publicKeysInBundle
(
bundle
:
NSBundle
=
NSBundle
.
mainBundle
())
->
[
SecKey
]
{
var
publicKeys
:
[
SecKey
]
=
[]
...
...
@@ -96,7 +150,14 @@ public enum ServerTrustPolicy {
// MARK: - Evaluation
// TODO: DocStrings
/**
Evaluates whether the server trust is valid for the given host.
:param: serverTrust The server trust to evaluate.
:param: host The host of the challenge protection space.
:returns: Whether the server trust is valid.
*/
public
func
evaluateServerTrust
(
serverTrust
:
SecTrust
,
isValidForHost
host
:
String
)
->
Bool
{
var
serverTrustIsValid
=
false
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录