1.

/* NSObject.h

Copyright (c) 1994-2018, Apple Inc. All rights reserved.

*/

#if __has_feature(objc_arc)

// After using a CFBridgingRetain on an NSObject, the caller must take responsibility for calling CFRelease at an appropriate time.

NS_INLINE CF_RETURNS_RETAINED CFTypeRef _Nullable CFBridgingRetain(id _Nullable X) {

return (__bridge_retained CFTypeRef)X;

}

NS_INLINE id _Nullable CFBridgingRelease(CFTypeRef CF_CONSUMED _Nullable X) {

return (__bridge_transfer id)X;

}

https://www.jianshu.com/p/5c98ac2dab58

2.

SecIdentityRef

https://github.com/xd520/TianjintouNew/blob/79bbeb3915a469d88becce954682d3709c2aedb2/Https.m

https://cloud.tencent.com/developer/ask/109329

3.

https://github.com/search?l=Objective-C&p=2&q=publicKeyIdentifier&type=Code

4.

- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
forDomain:(NSString *)domain
{
if (domain && self.allowInvalidCertificates && self.validatesDomainName && (self.SSLPinningMode == AFSSLPinningModeNone || [self.pinnedCertificates count] == )) {
// https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/OverridingSSLChainValidationCorrectly.html
// According to the docs, you should only trust your provided certs for evaluation.
// Pinned certificates are added to the trust. Without pinned certificates,
// there is nothing to evaluate against.
//
// From Apple Docs:
// "Do not implicitly trust self-signed certificates as anchors (kSecTrustOptionImplicitAnchors).
// Instead, add your own (self-signed) CA certificate to the list of trusted anchors."
NSLog(@"In order to validate a domain name for self signed certificates, you MUST use pinning.");
return NO;
} NSMutableArray *policies = [NSMutableArray array];
if (self.validatesDomainName) {
//如果要验证域名,就通过域名来生成Policy
[policies addObject:(__bridge_transfer id)SecPolicyCreateSSL(true, (__bridge CFStringRef)domain)];
} else {
//不验证域名,就默认基于X.509
[policies addObject:(__bridge_transfer id)SecPolicyCreateBasicX509()];
} //设置policies
SecTrustSetPolicies(serverTrust, (__bridge CFArrayRef)policies); if (self.SSLPinningMode == AFSSLPinningModeNone) {
//不校验证书,只要允许过期无效证书或者serverTrust验证通过,即可信任
return self.allowInvalidCertificates || AFServerTrustIsValid(serverTrust);
} else if (!AFServerTrustIsValid(serverTrust) && !self.allowInvalidCertificates) {
//否则,就不可信任
return NO;
} //到了这里就说明:
//1.通过了证书的验证
//2.allowInvalidCertificates = YES switch (self.SSLPinningMode) {
case AFSSLPinningModeNone:
default:
return NO;
case AFSSLPinningModeCertificate: {
//验证全部证书
NSMutableArray *pinnedCertificates = [NSMutableArray array];
for (NSData *certificateData in self.pinnedCertificates) {
[pinnedCertificates addObject:(__bridge_transfer id)SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificateData)];
}
SecTrustSetAnchorCertificates(serverTrust, (__bridge CFArrayRef)pinnedCertificates); //验证证书是否可信任
if (!AFServerTrustIsValid(serverTrust)) {
return NO;
} // obtain the chain after being validated, which *should* contain the pinned certificate in the last position (if it's the Root CA)
NSArray *serverCertificates = AFCertificateTrustChainForServerTrust(serverTrust); //整个证书链都跟本地的证书匹配才通过验证
for (NSData *trustChainCertificate in [serverCertificates reverseObjectEnumerator]) {
if ([self.pinnedCertificates containsObject:trustChainCertificate]) {
return YES;
}
} return NO;
}
case AFSSLPinningModePublicKey: {
NSUInteger trustedPublicKeyCount = ;
NSArray *publicKeys = AFPublicKeyTrustChainForServerTrust(serverTrust); //只要有公钥相匹配就通过
for (id trustChainPublicKey in publicKeys) {
for (id pinnedPublicKey in self.pinnedPublicKeys) {
if (AFSecKeyIsEqualToKey((__bridge SecKeyRef)trustChainPublicKey, (__bridge SecKeyRef)pinnedPublicKey)) {
trustedPublicKeyCount += ;
}
}
}
return trustedPublicKeyCount > ;
}
} return NO;
}

https://www.jianshu.com/p/f522d041cd91

NSMutableArray *policies = [NSMutableArray array];

// BasicX509 不验证域名是否相同
SecPolicyRef policy = SecPolicyCreateBasicX509();
[policies addObject:(__bridge_transfer id)policy];
SecTrustSetPolicies(trust, (__bridge CFArrayRef)policies);

https://www.cnblogs.com/oc-bowen/p/5896041.html

5.

    NSArray *serverCertificates = @[@"a",@"b",@"c",@"d",@"e",@"f"];

    for (NSString *trustChainCertificate in serverCertificates) {
NSLog(@"str:%@",trustChainCertificate);
}
NSLog(@"---------------");
NSSet *set = [[NSSet alloc] initWithArray:serverCertificates]; for (NSString *trustChainCertificate in [set objectEnumerator]) {
NSLog(@"str:%@",trustChainCertificate);
}

当枚举一个NSArray的时候:

  • 使用 for (id object in array) 如果是顺序枚举

  • 使用 for (id object in [array reverseObjectEnumerator]) 如果是倒序枚举

  • 使用 for (NSInteger i = 0; i < count; i++) 如果你需要知道它的索引值,或者需要改变数组

  • 尝试 [array enumerateObjectsWithOptions:usingBlock:] 如果你的代码受益于并行执行

当枚举一个NSSet的时候:

  • 使用  for (id object in set) 大多数时候

  • 使用 for (id object in [set copy]) 如果你需要修改集合(但是会很慢)

  • 尝试 [array enumerateObjectsWithOptions:usingBlock:] 如果你的代码受益于并行执行

当枚举一个NSDictionary的时候:

  • 使用  for (id object in set) 大多数时候

  • 使用 for (id object in [set copy]) 如果你需要修改词典

  • 尝试 [array enumerateObjectsWithOptions:usingBlock:] 如果你的代码受益于并行执行

https://www.cnblogs.com/mafeng/p/5222295.html

第28月第4天 __bridge_transfer的更多相关文章

  1. 第28月第24天 requestSerializer

    1. requestSerializer关于 requestSerializer它就是AFNetworking参数编码的序列化器,它一共有三种编码格式: AFHTTPRequestSerializer ...

  2. 第28月第23天 lineFragmentPadding

    1.lineFragmentPadding https://blog.csdn.net/lwb102063/article/details/78748186

  3. 第28月第22天 iOS动态库

    1. NIMSDK 在 5.1.0 版本之后已改为动态库,集成方式有所改变,若需要集成高于此版本的 SDK,只需要做以下步骤: 将下载的 SDK 拖动到 Targets -> General - ...

  4. 第28月第21天 记事本Unicode 游戏编程中的人工智能技术

    1. Windows平台,有一个最简单的转化方法,就是使用内置的记事本小程序notepad.exe.打开文件后,点击文件菜单中的另存为命令,会跳出一个对话框,在最底部有一个编码的下拉条. 里面有四个选 ...

  5. 第28月第11天 vim -b

    1. 首先以二进制方式编辑这个文件:        vim -b datafile现在用 xxd 把这个文件转换成十六进制:        :%!xxd文本看起来像这样:        0000000 ...

  6. 第28月第10天 iOS动态库

    1. https://www.cnblogs.com/wfwenchao/p/5577789.html https://github.com/wangzz/Demo http://www.kimbs. ...

  7. 第28月第5天 uibutton交换方法

    1. //交换系统的方法 @implementation UIControl (MYButton) + (void)load { Method a = class_getInstanceMethod( ...

  8. 第28月第3天 c语言读写文件

    1. int ConfigIniFile::OpenFile( const char* szFileName ) { FILE *fp; size_t nLen; int nRet; CloseFil ...

  9. 剑指Offer——毕业生求职网站汇总(干货)

    剑指Offer--毕业生求职网站汇总(干货) 致2017即将毕业的你~ 精品网站 牛客网:https://www.nowcoder.com 赛码网:http://www.acmcoder.com/ 招 ...

随机推荐

  1. SRM 600 div 2 T 2

    题意:给你50个数,问你最少去掉多少数能使得剩下的数不可能具备子集S,OR起来为goal 如果一个数不是goal的子状态,那么我们没必要删除他,所以我们只关心goal的子状态的数 1:如果所有的数OR ...

  2. Spring boot学习笔记之@SpringBootApplication注解

    @SpringBootApplication(exclude = SessionAutoConfiguration.class) public class BootReactApplication { ...

  3. 利用twilio进行手机短信验证

    首先要注册 twilio 账号但是由于twilio人机验证用的是Goole所有注册需要FQ 完成后去免费获取15元使用 然后 pip install twilio 注册完成后会在个人首页显示你的免费金 ...

  4. django(七)之数据库表的单表-增删改查QuerySet,双下划线

    https://www.cnblogs.com/haiyan123/p/7738435.html https://www.cnblogs.com/yuanchenqi/articles/6083427 ...

  5. django跨域请求问题

    一 同源策略 同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响.可以说Web是构建在同源策略基础之 ...

  6. opencv mat裁剪

    主要记录的就是对Mat裁剪后,新Mat指向的内存和原来的Mat共用. OpenCV入门教程(3)-Mat类之选取图像局部区域

  7. node(基础)_node.js中的http服务以及模板引擎的渲染

    一.前言 本节的内容主要涉及: 1.node.js中http服务 2.node.js中fs服务 3.node.js中模板引擎的渲染 4.利用上面几点模拟apache服务器 二.知识 1.node.js ...

  8. javaMail简介(一)

    一:开发javaMail用到的协议 SMTP(simple Message Transfer Protocal):简单消息传输协议.发送邮件时使用的协议,描述了数据该如何表示,默认端口为:25 POP ...

  9. 【优秀的艺术文字和图标设计软件】Art Text 3.2.3 for Mac

      [简介] Art Text 3.2.3 版本,这是一款Mac上简单易用的艺术文字和图标设计软件,今这款软件内置了大量的背景纹理和特效,能够让我们非常快速的制作出漂亮的图标,相比专业的PS,Art ...

  10. python自动化开发-[第九天]-异常处理、进程

    今日概要: 1.异常处理使用 2.进程 3.paramiko模块使用 一.异常处理 1.常见的错误异常 #错误异常一 print(a) #NameError #错误异常二 int('sdadsds') ...