| 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 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 const_cast<void*>(CFArrayGetValueAtIndex(cert_chain, i))); | 117 const_cast<void*>(CFArrayGetValueAtIndex(cert_chain, i))); |
| 118 if (i == 0) { | 118 if (i == 0) { |
| 119 verified_cert = chain_cert; | 119 verified_cert = chain_cert; |
| 120 } else { | 120 } else { |
| 121 verified_chain.push_back(chain_cert); | 121 verified_chain.push_back(chain_cert); |
| 122 } | 122 } |
| 123 | 123 |
| 124 std::string der_bytes; | 124 std::string der_bytes; |
| 125 if (!X509Certificate::GetDEREncoded(chain_cert, &der_bytes)) | 125 if (!X509Certificate::GetDEREncoded(chain_cert, &der_bytes)) |
| 126 return; | 126 return; |
| 127 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(der_bytes.data()); | |
| 128 bssl::UniquePtr<X509> x509_cert(d2i_X509(NULL, &bytes, der_bytes.size())); | |
| 129 | 127 |
| 130 base::StringPiece spki_bytes; | 128 base::StringPiece spki_bytes; |
| 131 if (!asn1::ExtractSPKIFromDERCert(der_bytes, &spki_bytes)) | 129 if (!asn1::ExtractSPKIFromDERCert(der_bytes, &spki_bytes)) |
| 132 continue; | 130 continue; |
| 133 | 131 |
| 134 HashValue sha1(HASH_VALUE_SHA1); | 132 HashValue sha1(HASH_VALUE_SHA1); |
| 135 CC_SHA1(spki_bytes.data(), spki_bytes.size(), sha1.data()); | 133 CC_SHA1(spki_bytes.data(), spki_bytes.size(), sha1.data()); |
| 136 verify_result->public_key_hashes.push_back(sha1); | 134 verify_result->public_key_hashes.push_back(sha1); |
| 137 | 135 |
| 138 HashValue sha256(HASH_VALUE_SHA256); | 136 HashValue sha256(HASH_VALUE_SHA256); |
| 139 CC_SHA256(spki_bytes.data(), spki_bytes.size(), sha256.data()); | 137 CC_SHA256(spki_bytes.data(), spki_bytes.size(), sha256.data()); |
| 140 verify_result->public_key_hashes.push_back(sha256); | 138 verify_result->public_key_hashes.push_back(sha256); |
| 141 | 139 |
| 142 // Ignore the signature algorithm for the trust anchor. | 140 // Ignore the signature algorithm for the trust anchor. |
| 143 if ((verify_result->cert_status & CERT_STATUS_AUTHORITY_INVALID) == 0 && | 141 if ((verify_result->cert_status & CERT_STATUS_AUTHORITY_INVALID) == 0 && |
| 144 i == count - 1) { | 142 i == count - 1) { |
| 145 continue; | 143 continue; |
| 146 } | 144 } |
| 147 | 145 FillCertVerifyResultWeakSignature(chain_cert, i == 0, verify_result); |
| 148 int sig_alg = OBJ_obj2nid(x509_cert->sig_alg->algorithm); | |
| 149 if (sig_alg == NID_md2WithRSAEncryption) { | |
| 150 verify_result->has_md2 = true; | |
| 151 } else if (sig_alg == NID_md4WithRSAEncryption) { | |
| 152 verify_result->has_md4 = true; | |
| 153 } else if (sig_alg == NID_md5WithRSAEncryption || | |
| 154 sig_alg == NID_md5WithRSA) { | |
| 155 verify_result->has_md5 = true; | |
| 156 } else if (sig_alg == NID_sha1WithRSAEncryption || | |
| 157 sig_alg == NID_dsaWithSHA || sig_alg == NID_dsaWithSHA1 || | |
| 158 sig_alg == NID_dsaWithSHA1_2 || sig_alg == NID_sha1WithRSA || | |
| 159 sig_alg == NID_ecdsa_with_SHA1) { | |
| 160 verify_result->has_sha1 = true; | |
| 161 if (i == 0) | |
| 162 verify_result->has_sha1_leaf = true; | |
| 163 } | |
| 164 } | 146 } |
| 165 if (!verified_cert) { | 147 if (!verified_cert) { |
| 166 NOTREACHED(); | 148 NOTREACHED(); |
| 167 return; | 149 return; |
| 168 } | 150 } |
| 169 | 151 |
| 170 verify_result->verified_cert = | 152 verify_result->verified_cert = |
| 171 X509Certificate::CreateFromHandle(verified_cert, verified_chain); | 153 X509Certificate::CreateFromHandle(verified_cert, verified_chain); |
| 172 } | 154 } |
| 173 | 155 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 281 |
| 300 verify_result->is_issued_by_known_root = false; | 282 verify_result->is_issued_by_known_root = false; |
| 301 | 283 |
| 302 if (IsCertStatusError(verify_result->cert_status)) | 284 if (IsCertStatusError(verify_result->cert_status)) |
| 303 return MapCertStatusToNetError(verify_result->cert_status); | 285 return MapCertStatusToNetError(verify_result->cert_status); |
| 304 | 286 |
| 305 return OK; | 287 return OK; |
| 306 } | 288 } |
| 307 | 289 |
| 308 } // namespace net | 290 } // namespace net |
| OLD | NEW |