Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/base/x509_certificate.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "net/android/network_library.h" | |
| 9 #include "net/base/cert_status_flags.h" | |
| 10 #include "net/base/cert_verify_result.h" | |
| 11 #include "net/base/net_errors.h" | |
| 12 | |
| 13 namespace net { | |
| 14 | |
| 15 int X509Certificate::VerifyInternal(const std::string& hostname, | |
| 16 int flags, | |
| 17 CertVerifyResult* verify_result) const { | |
| 18 if (!VerifyNameMatch(hostname)) | |
| 19 verify_result->cert_status |= CERT_STATUS_COMMON_NAME_INVALID; | |
| 20 | |
| 21 std::vector<std::string> cert_bytes; | |
| 22 GetChainDEREncodedBytes(&cert_bytes); | |
| 23 | |
| 24 // TODO(joth): Fetch the authentication type from SSL rather than hardcode. | |
| 25 net::android::VerifyResult result = | |
| 26 net::android::VerifyX509CertChain(cert_bytes, hostname, "RSA"); | |
|
wtc
2011/08/09 18:47:22
Remove the net:: prefixes because this is inside t
michaelbai
2011/08/11 16:10:18
There is a TODO in Java code to try to decide whet
| |
| 27 switch (result) { | |
| 28 case net::android::VERIFY_OK: | |
| 29 return OK; | |
| 30 case net::android::VERIFY_BAD_HOSTNAME: | |
| 31 verify_result->cert_status |= CERT_STATUS_COMMON_NAME_INVALID; | |
| 32 break; | |
| 33 case net::android::VERIFY_NO_TRUSTED_ROOT: | |
| 34 verify_result->cert_status |= CERT_STATUS_AUTHORITY_INVALID; | |
| 35 break; | |
| 36 case net::android::VERIFY_INVOCATION_ERROR: | |
| 37 default: | |
| 38 verify_result->cert_status |= ERR_CERT_INVALID; | |
| 39 break; | |
| 40 } | |
| 41 return MapCertStatusToNetError(verify_result->cert_status); | |
| 42 } | |
| 43 | |
| 44 void X509Certificate::GetChainDEREncodedBytes( | |
| 45 std::vector<std::string>* chain_bytes) const { | |
| 46 OSCertHandles cert_handles(intermediate_ca_certs_); | |
| 47 // Make sure the peer's own cert is the first in the chain, if it's not | |
| 48 // already there. | |
| 49 if (cert_handles.empty() || cert_handles[0] != cert_handle_) | |
| 50 cert_handles.insert(cert_handles.begin(), cert_handle_); | |
|
wtc
2011/08/09 18:47:22
The cert_handles[0] != cert_handle_ test is not ne
michaelbai
2011/08/11 16:10:18
Done.
| |
| 51 | |
| 52 chain_bytes->reserve(cert_handles.size()); | |
| 53 for (OSCertHandles::const_iterator it = cert_handles.begin(); | |
| 54 it != cert_handles.end(); ++it) { | |
| 55 DERCache der_cache = {0}; | |
| 56 GetDERAndCacheIfNeeded(*it, &der_cache); | |
| 57 std::string cert_bytes = std::string( | |
| 58 reinterpret_cast<const char*>(der_cache.data), der_cache.data_length); | |
|
wtc
2011/08/09 18:47:22
Write this as
std::string cert_bytes(
michaelbai
2011/08/11 16:10:18
Done.
| |
| 59 chain_bytes->push_back(cert_bytes); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 } // namespace net | |
| OLD | NEW |