OLD | NEW |
---|---|
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/cert/cert_verify_proc_ios.h" | 5 #include "net/cert/cert_verify_proc_ios.h" |
6 | 6 |
7 #include <CommonCrypto/CommonDigest.h> | 7 #include <CommonCrypto/CommonDigest.h> |
8 #include <Security/Security.h> | 8 #include <Security/Security.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 continue; | 133 continue; |
134 | 134 |
135 HashValue sha1(HASH_VALUE_SHA1); | 135 HashValue sha1(HASH_VALUE_SHA1); |
136 CC_SHA1(spki_bytes.data(), spki_bytes.size(), sha1.data()); | 136 CC_SHA1(spki_bytes.data(), spki_bytes.size(), sha1.data()); |
137 verify_result->public_key_hashes.push_back(sha1); | 137 verify_result->public_key_hashes.push_back(sha1); |
138 | 138 |
139 HashValue sha256(HASH_VALUE_SHA256); | 139 HashValue sha256(HASH_VALUE_SHA256); |
140 CC_SHA256(spki_bytes.data(), spki_bytes.size(), sha256.data()); | 140 CC_SHA256(spki_bytes.data(), spki_bytes.size(), sha256.data()); |
141 verify_result->public_key_hashes.push_back(sha256); | 141 verify_result->public_key_hashes.push_back(sha256); |
142 | 142 |
143 // Ignore the signature algorithm for the root (self-signed) certificate. | |
Ryan Sleevi
2016/04/08 20:01:58
1) s/root (self-signed) certificate/trust anchor/
svaldez
2016/04/08 20:22:47
This is only for setting the has_XXX bits on the v
Ryan Sleevi
2016/04/08 20:44:21
Yes, but has_sha1 is valid if, for example, the in
| |
144 if (i == count - 1) | |
145 continue; | |
146 | |
143 int sig_alg = OBJ_obj2nid(x509_cert->sig_alg->algorithm); | 147 int sig_alg = OBJ_obj2nid(x509_cert->sig_alg->algorithm); |
144 if (sig_alg == NID_md2WithRSAEncryption) { | 148 if (sig_alg == NID_md2WithRSAEncryption) { |
145 verify_result->has_md2 = true; | 149 verify_result->has_md2 = true; |
146 } else if (sig_alg == NID_md4WithRSAEncryption) { | 150 } else if (sig_alg == NID_md4WithRSAEncryption) { |
147 verify_result->has_md4 = true; | 151 verify_result->has_md4 = true; |
148 } else if (sig_alg == NID_md5WithRSAEncryption || | 152 } else if (sig_alg == NID_md5WithRSAEncryption || |
149 sig_alg == NID_md5WithRSA) { | 153 sig_alg == NID_md5WithRSA) { |
150 verify_result->has_md5 = true; | 154 verify_result->has_md5 = true; |
151 } else if (sig_alg == NID_sha1WithRSAEncryption || | 155 } else if (sig_alg == NID_sha1WithRSAEncryption || |
152 sig_alg == NID_dsaWithSHA || sig_alg == NID_dsaWithSHA1 || | 156 sig_alg == NID_dsaWithSHA || sig_alg == NID_dsaWithSHA1 || |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 &final_chain, &trust_result); | 207 &final_chain, &trust_result); |
204 if (status) | 208 if (status) |
205 return NetErrorFromOSStatus(status); | 209 return NetErrorFromOSStatus(status); |
206 | 210 |
207 if (CFArrayGetCount(final_chain) == 0) | 211 if (CFArrayGetCount(final_chain) == 0) |
208 return ERR_FAILED; | 212 return ERR_FAILED; |
209 | 213 |
210 GetCertChainInfo(final_chain, verify_result); | 214 GetCertChainInfo(final_chain, verify_result); |
211 | 215 |
212 // TODO(sleevi): Support CRLSet revocation. | 216 // TODO(sleevi): Support CRLSet revocation. |
213 // TODO(svaldez): Add specific error codes for trust errors resulting from | |
214 // expired/not-yet-valid certs. | |
215 switch (trust_result) { | 217 switch (trust_result) { |
216 case kSecTrustResultUnspecified: | 218 case kSecTrustResultUnspecified: |
217 case kSecTrustResultProceed: | 219 case kSecTrustResultProceed: |
218 break; | 220 break; |
219 case kSecTrustResultDeny: | 221 case kSecTrustResultDeny: |
220 verify_result->cert_status |= CERT_STATUS_AUTHORITY_INVALID; | 222 verify_result->cert_status |= CERT_STATUS_AUTHORITY_INVALID; |
223 break; | |
221 default: | 224 default: |
222 verify_result->cert_status |= CERT_STATUS_INVALID; | 225 CFArrayRef properties = SecTrustCopyProperties(trust_ref); |
226 if (properties && CFArrayGetCount(properties) != 0) { | |
Ryan Sleevi
2016/04/08 20:01:58
Can you expand documentation comment to explain th
svaldez
2016/04/08 20:22:48
Done.
| |
227 CFBundleRef bundle = | |
228 CFBundleGetBundleWithIdentifier(CFSTR("com.apple.Security")); | |
229 CFStringRef date_string = CFSTR( | |
230 "One or more certificates have expired or are not valid yet."); | |
231 CFStringRef date_error = CFBundleCopyLocalizedString( | |
232 bundle, date_string, date_string, CFSTR("SecCertificate")); | |
233 CFStringRef trust_string = CFSTR("Root certificate is not trusted."); | |
234 CFStringRef trust_error = CFBundleCopyLocalizedString( | |
235 bundle, trust_string, trust_string, CFSTR("SecCertificate")); | |
236 CFStringRef weak_string = | |
237 CFSTR("One or more certificates is using a weak key size."); | |
238 CFStringRef weak_error = CFBundleCopyLocalizedString( | |
239 bundle, weak_string, weak_string, CFSTR("SecCertificate")); | |
240 const CFIndex properties_length = CFArrayGetCount(properties); | |
Ryan Sleevi
2016/04/08 20:01:58
newline between 239 & 240 would help readability h
svaldez
2016/04/08 20:22:47
Done.
| |
241 for (CFIndex i = 0; i < properties_length; ++i) { | |
242 CFDictionaryRef dict = | |
243 (CFDictionaryRef)CFArrayGetValueAtIndex(properties, i); | |
Ryan Sleevi
2016/04/08 20:01:58
C-style casts aren't allowed ;(
svaldez
2016/04/08 20:22:47
Done.
| |
244 CFStringRef error = | |
245 (CFStringRef)CFDictionaryGetValue(dict, CFSTR("value")); | |
Ryan Sleevi
2016/04/08 20:01:58
Ditto
svaldez
2016/04/08 20:22:47
Done.
| |
246 if (CFStringCompare(error, date_error, 0) == kCFCompareEqualTo) { | |
Ryan Sleevi
2016/04/08 20:01:58
Why not CFEqual for these?
svaldez
2016/04/08 20:22:48
Done.
| |
247 verify_result->cert_status |= CERT_STATUS_DATE_INVALID; | |
248 } else if (CFStringCompare(error, trust_error, 0) == | |
249 kCFCompareEqualTo) { | |
250 verify_result->cert_status |= CERT_STATUS_AUTHORITY_INVALID; | |
251 } else if (CFStringCompare(error, weak_error, 0) == | |
252 kCFCompareEqualTo) { | |
253 verify_result->cert_status |= CERT_STATUS_WEAK_KEY; | |
254 } else { | |
255 verify_result->cert_status |= CERT_STATUS_INVALID; | |
256 } | |
257 } | |
258 } else { | |
259 verify_result->cert_status |= CERT_STATUS_INVALID; | |
260 } | |
223 } | 261 } |
224 | 262 |
225 // Perform hostname verification independent of SecTrustEvaluate. | 263 // Perform hostname verification independent of SecTrustEvaluate. |
226 if (!verify_result->verified_cert->VerifyNameMatch( | 264 if (!verify_result->verified_cert->VerifyNameMatch( |
227 hostname, &verify_result->common_name_fallback_used)) { | 265 hostname, &verify_result->common_name_fallback_used)) { |
228 verify_result->cert_status |= CERT_STATUS_COMMON_NAME_INVALID; | 266 verify_result->cert_status |= CERT_STATUS_COMMON_NAME_INVALID; |
229 } | 267 } |
230 | 268 |
231 verify_result->is_issued_by_known_root = false; | 269 verify_result->is_issued_by_known_root = false; |
232 | 270 |
233 if (IsCertStatusError(verify_result->cert_status)) | 271 if (IsCertStatusError(verify_result->cert_status)) |
234 return MapCertStatusToNetError(verify_result->cert_status); | 272 return MapCertStatusToNetError(verify_result->cert_status); |
235 | 273 |
236 return OK; | 274 return OK; |
237 } | 275 } |
238 | 276 |
239 } // namespace net | 277 } // namespace net |
OLD | NEW |