ChenYilong / ChenYilong/iOS11AdaptationTips

ios11Beta https TLS1.0 是否可以继续使用

Open
#17 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
477
Forks
47
PR merge metrics
No merged PRs in 30d

Description

## Summary

在iOS10 之前我们HTTPS 双向认证,服务端是使用TLS1.0
iOS11 beta测试时,验证是不通过的,服务端是使用TLS1.2可以正常使用。
## How would you classify this issue?

Choose a problem area with iOS SDK:
Foundation.

## Base Information for this issue

在iOS10之前我们一直用双向认证,服务端是使用TLS1.0
iOS11 beta测试时,验证是不通过的,我们自己搭建了一个测试环境TLS1.0换成TLS1.2就可以通过。
因为公司一些原因,服务端暂时无法升级到TLS1.2,所以我们想iOS将客户端 App Transport Security 使用TLS1.0 但修改plist文件后并没有成功。

想问下 iOS11是否已经完全禁用TLS1.0,如果没有禁用,客户端如何 降至TLS1.0 使用。

https://developer.apple.com/download/
iOS_11_beta_10_Release_Notes
Security
Resolved Issues
• The restriction introduced in iOS 11, macOS 10.13, tvOS 11, and watchOS 4 that required TLS version 1.2 for cipher suites as defined in RFC 5246 has been removed. (33140907)

1. iOS System Version:
iOS 11 beta

2. Language:
* [x] Objective-C

3. Prototype(是否是真机)
YES

4. Test devices:
iPhone 6 Plus

## Here is a Demo.

因为测试环境在内网搭建,您无法访问到。我只贴出使用的关键代码,如有需要我配合请联系我,邮箱: samlfei@163.com

```
/*code

- (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential * _Nullable credential))completionHandler {
NSLog(@"证书认证");
//NSURLAuthenticationMethodClientCertificate
//NSURLAuthenticationMethodServerTrust
if ([[[challenge protectionSpace] authenticationMethod]isEqualToString:@"NSURLAuthenticationMethodServerTrust"])
{
OSStatus err;
SecTrustRef trust ;
SecCertificateRef serverCert;
SecTrustResultType trustResult;
BOOL trusted;
trust = [[challenge protectionSpace] serverTrust];
if (SecTrustGetCertificateCount(trust) > 0) {
serverCert = SecTrustGetCertificateAtIndex(trust, 0);
}

NSArray *anchors = [NSArray array];
SecTrustSetAnchorCertificates(trust, (CFArrayRef)anchors);
err = SecTrustEvaluate(trust,&trustResult);
trusted = (err == noErr) && ((trustResult == kSecTrustResultProceed) || (trustResult == kSecTrustResultUnspecified));

NSURLCredential* newCredential = [NSURLCredential credentialForTrust:trust];
completionHandler(NSURLSessionAuthChallengeUseCredential, newCredential);

} else {
if ([[[challenge protectionSpace] authenticationMethod]isEqualToString:@"NSURLAuthenticationMethodClientCertificate"])
{
SecIdentityRef identity = NULL;
SecTrustRef trust = NULL;
NSURLCredential* credential;

NSData * cerData ;
NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"user_cert" ofType:@"p12"];//自签名证书
cerData = [NSData dataWithContentsOfFile:cerPath];

SecCertificateRef certificate = NULL;
if ([self extractIdentity:&identity andTrust:&trust fromPKCS12Data:cerData])
{
SecIdentityCopyCertificate(identity, &certificate);
const void*certs[] = {certificate};
CFArrayRef certArray =CFArrayCreate(kCFAllocatorDefault, certs,1,NULL);
credential =[NSURLCredential credentialWithIdentity:identity certificates:(__bridge NSArray*)certArray persistence:NSURLCredentialPersistencePermanent];
}
completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
}
}

return;
}
- (BOOL)extractIdentity:(SecIdentityRef*)outIdentity andTrust:(SecTrustRef *)outTrust fromPKCS12Data:(NSData *)inPKCS12Data {
OSStatus securityError = errSecSuccess;
//client certificate password
NSDictionary *optionsDictionary = [NSDictionary dictionaryWithObject:@"123456"
forKey:(__bridge id)kSecImportExportPassphrase];

CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
securityError = SecPKCS12Import((__bridge CFDataRef)inPKCS12Data,(__bridge CFDictionaryRef)optionsDictionary,&items);

if(securityError == 0) {
CFDictionaryRef myIdentityAndTrust =CFArrayGetValueAtIndex(items,0);
const void*tempIdentity =NULL;
tempIdentity= CFDictionaryGetValue (myIdentityAndTrust,kSecImportItemIdentity);
*outIdentity = (SecIdentityRef)tempIdentity;
const void*tempTrust =NULL;
tempTrust = CFDictionaryGetValue(myIdentityAndTrust,kSecImportItemTrust);
*outTrust = (SecTrustRef)tempTrust;
} else {
NSLog(@"Failedwith error code %d",(int)securityError);
return NO;
}
return YES;
}
*/
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.