Commit 1dc1dffc authored by ukai@chromium.org's avatar ukai@chromium.org

Check cert_handle_ is not NULL to Verify()

If X509Certificate is created in URLRequestAutomationJob or
URLRequestInterceptJob, cert_handle_ is NULL.
So if such certificate is being to be verified (not sure it happens), it would cause crash or some
problem.

BUG=15614
TEST=none

Review URL: http://codereview.chromium.org/329036

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30319 0039d316-1c4b-4281-b951-d872f2087c98
parent 1f410001
...@@ -436,6 +436,7 @@ void X509Certificate::Initialize() { ...@@ -436,6 +436,7 @@ void X509Certificate::Initialize() {
std::wstring subject_info; std::wstring subject_info;
std::wstring issuer_info; std::wstring issuer_info;
DWORD name_size; DWORD name_size;
DCHECK(cert_handle_);
name_size = CertNameToStr(cert_handle_->dwCertEncodingType, name_size = CertNameToStr(cert_handle_->dwCertEncodingType,
&cert_handle_->pCertInfo->Subject, &cert_handle_->pCertInfo->Subject,
CERT_X500_NAME_STR | CERT_NAME_STR_CRLF_FLAG, CERT_X500_NAME_STR | CERT_NAME_STR_CRLF_FLAG,
...@@ -484,6 +485,7 @@ X509Certificate* X509Certificate::CreateFromPickle(const Pickle& pickle, ...@@ -484,6 +485,7 @@ X509Certificate* X509Certificate::CreateFromPickle(const Pickle& pickle,
} }
void X509Certificate::Persist(Pickle* pickle) { void X509Certificate::Persist(Pickle* pickle) {
DCHECK(cert_handle_);
DWORD length; DWORD length;
if (!CertSerializeCertificateStoreElement(cert_handle_, 0, if (!CertSerializeCertificateStoreElement(cert_handle_, 0,
NULL, &length)) { NULL, &length)) {
...@@ -501,16 +503,19 @@ void X509Certificate::Persist(Pickle* pickle) { ...@@ -501,16 +503,19 @@ void X509Certificate::Persist(Pickle* pickle) {
void X509Certificate::GetDNSNames(std::vector<std::string>* dns_names) const { void X509Certificate::GetDNSNames(std::vector<std::string>* dns_names) const {
dns_names->clear(); dns_names->clear();
scoped_ptr_malloc<CERT_ALT_NAME_INFO> alt_name_info; if (cert_handle_) {
GetCertSubjectAltName(cert_handle_, &alt_name_info); scoped_ptr_malloc<CERT_ALT_NAME_INFO> alt_name_info;
CERT_ALT_NAME_INFO* alt_name = alt_name_info.get(); GetCertSubjectAltName(cert_handle_, &alt_name_info);
if (alt_name) { CERT_ALT_NAME_INFO* alt_name = alt_name_info.get();
int num_entries = alt_name->cAltEntry; if (alt_name) {
for (int i = 0; i < num_entries; i++) { int num_entries = alt_name->cAltEntry;
// dNSName is an ASN.1 IA5String representing a string of ASCII for (int i = 0; i < num_entries; i++) {
// characters, so we can use WideToASCII here. // dNSName is an ASN.1 IA5String representing a string of ASCII
if (alt_name->rgAltEntry[i].dwAltNameChoice == CERT_ALT_NAME_DNS_NAME) // characters, so we can use WideToASCII here.
dns_names->push_back(WideToASCII(alt_name->rgAltEntry[i].pwszDNSName)); if (alt_name->rgAltEntry[i].dwAltNameChoice == CERT_ALT_NAME_DNS_NAME)
dns_names->push_back(
WideToASCII(alt_name->rgAltEntry[i].pwszDNSName));
}
} }
} }
if (dns_names->empty()) if (dns_names->empty())
...@@ -521,6 +526,8 @@ int X509Certificate::Verify(const std::string& hostname, ...@@ -521,6 +526,8 @@ int X509Certificate::Verify(const std::string& hostname,
int flags, int flags,
CertVerifyResult* verify_result) const { CertVerifyResult* verify_result) const {
verify_result->Reset(); verify_result->Reset();
if (!cert_handle_)
return ERR_UNEXPECTED;
// Build and validate certificate chain. // Build and validate certificate chain.
...@@ -671,6 +678,7 @@ int X509Certificate::Verify(const std::string& hostname, ...@@ -671,6 +678,7 @@ int X509Certificate::Verify(const std::string& hostname,
// of the EV Certificate Guidelines Version 1.0 at // of the EV Certificate Guidelines Version 1.0 at
// http://cabforum.org/EV_Certificate_Guidelines.pdf. // http://cabforum.org/EV_Certificate_Guidelines.pdf.
bool X509Certificate::VerifyEV() const { bool X509Certificate::VerifyEV() const {
DCHECK(cert_handle_);
net::EVRootCAMetadata* metadata = net::EVRootCAMetadata::GetInstance(); net::EVRootCAMetadata* metadata = net::EVRootCAMetadata::GetInstance();
PCCERT_CHAIN_CONTEXT chain_context = ConstructCertChain(cert_handle_, PCCERT_CHAIN_CONTEXT chain_context = ConstructCertChain(cert_handle_,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment