Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed SecTrustEvaluate deprecated warning #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions JFRSecurity.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,21 @@ - (BOOL)isValid:(SecTrustRef)trust domain:(NSString*)domain {
[collect addObject:CFBridgingRelease(SecCertificateCreateWithData(nil,(__bridge CFDataRef)data))];
}
SecTrustSetAnchorCertificates(trust,(__bridge CFArrayRef)collect);
SecTrustResultType result = 0;
SecTrustEvaluate(trust,&result);
if(result == kSecTrustResultUnspecified || result == kSecTrustResultProceed) {
BOOL evaluates = NO;
if (@available(iOS 12.0, macOS 10.14, *)) {
evaluates = (SecTrustEvaluateWithError(trust, nil));
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Fallback on earlier versions
SecTrustResultType result = 0;
SecTrustEvaluate(trust,&result);
if(result == kSecTrustResultUnspecified || result == kSecTrustResultProceed) {
evaluates = YES;
}
#pragma clang diagnostic pop
}
if (evaluates) {
NSInteger trustedCount = 0;
for(NSData *serverData in serverCerts) {
for(NSData *certData in self.certificates) {
Expand Down Expand Up @@ -182,8 +194,18 @@ - (SecKeyRef)extractPublicKeyFromCert:(SecCertificateRef)cert policy:(SecPolicyR

SecTrustRef trust;
SecTrustCreateWithCertificates(cert,policy,&trust);
SecTrustResultType result = kSecTrustResultInvalid;
SecTrustEvaluate(trust,&result);
if (@available(iOS 12.0, macOS 10.14, *)) {
if (SecTrustEvaluateWithError(trust, nil)) {

}
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Fallback on earlier versions
SecTrustResultType result = kSecTrustResultInvalid;
SecTrustEvaluate(trust,&result);
#pragma clang diagnostic pop
}
SecKeyRef key = SecTrustCopyPublicKey(trust);
CFRelease(trust);
return key;
Expand Down