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. [luogu4556][Vani有约会]

    题目链接 吐槽 这道题调了7个小时也是够了.最后只好比着题解做了一遍2333 思路 首先考虑n=2000的情况.因为这是在一条路径上,所以可以考虑差分.用a[i][j]表示第i个点中j这种粮食出现的次 ...

  2. [hdu6183][Color it]

    题目链接 题目大意 有一个矩阵,总共有4种操作 0:清空这个矩阵 1 x y c:将\((x,y)(1 \leq x ,y\leq 10^6)\)这个点加上一种颜色c\((0\leq c \leq 5 ...

  3. Java Scanner篇

    Scanner 翻译解释为扫描器 Java中用于控制台的的数据输入 包:import java.util.Scanner 使用方法:Scanner reader=new Scanner(System. ...

  4. linux 日常中会用到的命令(持续更新)

    1. grep 比如,我要查看www目录下所有包含   “聊天室”  的文件 grep -rn "聊天室" * 比如我要把  www  目录下所有文件中的    聊天室   替换为 ...

  5. eclipse+pyDev

    感觉python脚本语言在linux下挺有用的,想入门学习一下 新手入门个人习惯找个好点的IDE帮助完成工作,试了好多,如pycharm,sublime text自己打造 后来发现全扯淡,一点不符合自 ...

  6. ElasticSearch6.5.0【Java客户端之TransportClient】

    说明 TransportClient:网上流传最多的客户端,目前最新版本 Java REST Client:官方推荐的客户端, 官方:我们要在Elasticsearch 7.0的版本中不赞成使用Tra ...

  7. 怎样删除windows server back 备份副本文件

    我用的服务器是windows server 2012 下面说明 第一步:打开windows powershell 第二步:输入命令   DISKSHADOW 第二步:输入 delete shadows ...

  8. (点到线段的最短距离)51nod1298 圆与三角形

    1298 圆与三角形 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三角形是否相交.相交输出"Yes",否则输出"No".(三角形的面积大于0).   收起 ...

  9. 2019你该掌握的开源日志管理平台ELK STACK

    转载于https://www.vtlab.io/?p=217   在企业级开源日志管理平台ELK VS GRAYLOG一文中,我简单阐述了日志管理平台对技术人员的重要性,并把ELK Stack和Gra ...

  10. qml: 模块定义与使用

    1. 模块的定义qmldir Module   MyModule MyTest  1.0  MyTest.qml MyTest  1.3  MyTest.qml 2. 导入: 使用qrc: RESOU ...