|
|
@ -69,6 +69,17 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
return nil;
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The leaf is always the first certificate.
|
|
|
|
|
|
|
|
NSData *_Nullable leafCertificateData = [certificateDerDatas firstObject];
|
|
|
|
|
|
|
|
if (!leafCertificateData) {
|
|
|
|
|
|
|
|
DDLogError(@"%@ Could not extract leaf certificate data.", self.logTag);
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (![self verifyDistinguishedNameOfCertificate:leafCertificateData]) {
|
|
|
|
|
|
|
|
OWSProdLogAndFail(@"%@ Leaf certificate has invalid name.", self.logTag);
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NSMutableArray *certificates = [NSMutableArray new];
|
|
|
|
NSMutableArray *certificates = [NSMutableArray new];
|
|
|
|
for (NSData *certificateDerData in certificateDerDatas) {
|
|
|
|
for (NSData *certificateDerData in certificateDerDatas) {
|
|
|
|
SecCertificateRef certificate = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)(certificateDerData));
|
|
|
|
SecCertificateRef certificate = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)(certificateDerData));
|
|
|
@ -117,10 +128,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
OWSProdLogAndFail(@"%@ Could not load DER.", self.logTag);
|
|
|
|
OWSProdLogAndFail(@"%@ Could not load DER.", self.logTag);
|
|
|
|
return nil;
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (![self verifyDistinguishedNameOfCertificate:certificateData]) {
|
|
|
|
|
|
|
|
OWSProdLogAndFail(@"%@ Certificate has invalid name.", self.logTag);
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[pinnedCertificates addObject:(__bridge_transfer id)certificate];
|
|
|
|
[pinnedCertificates addObject:(__bridge_transfer id)certificate];
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -271,11 +278,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// NSString *expectedDistinguishedName
|
|
|
|
// NSString *expectedDistinguishedName
|
|
|
|
// = @"CN=Intel SGX Attestation Report Signing,O=Intel Corporation,L=Santa Clara,ST=CA,C=US";
|
|
|
|
// = @"CN=Intel SGX Attestation Report Signing,O=Intel Corporation,L=Santa Clara,ST=CA,C=US";
|
|
|
|
// NOTE: "Intel SGX Attestation Report Signing CA" is not the same as:
|
|
|
|
|
|
|
|
// "Intel SGX Attestation Report Signing"
|
|
|
|
|
|
|
|
NSDictionary<NSString *, NSString *> *expectedProperties = @{
|
|
|
|
NSDictionary<NSString *, NSString *> *expectedProperties = @{
|
|
|
|
@(SN_commonName) : // "CN"
|
|
|
|
@(SN_commonName) : // "CN"
|
|
|
|
@"Intel SGX Attestation Report Signing CA",
|
|
|
|
@"Intel SGX Attestation Report Signing",
|
|
|
|
@(SN_organizationName) : // "O"
|
|
|
|
@(SN_organizationName) : // "O"
|
|
|
|
@"Intel Corporation",
|
|
|
|
@"Intel Corporation",
|
|
|
|
@(SN_localityName) : // "L"
|
|
|
|
@(SN_localityName) : // "L"
|
|
|
@ -285,6 +290,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@(SN_countryName) : // "C"
|
|
|
|
@(SN_countryName) : // "C"
|
|
|
|
@"US",
|
|
|
|
@"US",
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (![properties isEqualToDictionary:expectedProperties]) {
|
|
|
|
if (![properties isEqualToDictionary:expectedProperties]) {
|
|
|
|
OWSFail(@"%@ Unexpected certificate properties. %@ != %@", self.logTag, expectedProperties, properties);
|
|
|
|
OWSFail(@"%@ Unexpected certificate properties. %@ != %@", self.logTag, expectedProperties, properties);
|
|
|
|
return NO;
|
|
|
|
return NO;
|
|
|
@ -307,7 +313,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
return nil;
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
X509_NAME *_Nullable subjectName = X509_get_issuer_name(certificateX509);
|
|
|
|
X509_NAME *_Nullable subjectName = X509_get_subject_name(certificateX509);
|
|
|
|
if (!subjectName) {
|
|
|
|
if (!subjectName) {
|
|
|
|
OWSFail(@"%@ could not extract subject name.", self.logTag);
|
|
|
|
OWSFail(@"%@ could not extract subject name.", self.logTag);
|
|
|
|
return nil;
|
|
|
|
return nil;
|
|
|
@ -346,8 +352,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
OWSFail(@"%@ could not parse entry name data.", self.logTag);
|
|
|
|
OWSFail(@"%@ could not parse entry name data.", self.logTag);
|
|
|
|
return nil;
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DDLogVerbose(@"%@ certificate[%@]: %@", self.logTag, oid, entryString);
|
|
|
|
|
|
|
|
[DDLog flushLog];
|
|
|
|
|
|
|
|
certificateProperties[oid] = entryString;
|
|
|
|
certificateProperties[oid] = entryString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return certificateProperties;
|
|
|
|
return certificateProperties;
|
|
|
|