Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: net/base/x509_certificate_openssl.cc

Issue 11579002: Add X509Certificate::IsIssuedByEncoded() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: simple rebase to check that everything's still ok Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/x509_certificate_nss.cc ('k') | net/base/x509_certificate_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/base/x509_certificate.h" 5 #include "net/base/x509_certificate.h"
6 6
7 #include <openssl/asn1.h> 7 #include <openssl/asn1.h>
8 #include <openssl/crypto.h> 8 #include <openssl/crypto.h>
9 #include <openssl/obj_mac.h> 9 #include <openssl/obj_mac.h>
10 #include <openssl/pem.h> 10 #include <openssl/pem.h>
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if (data_length <= 0 || !data) 226 if (data_length <= 0 || !data)
227 return false; 227 return false;
228 internal_cache = SetDERCache(cert, x509_der_cache_index, data, data_length); 228 internal_cache = SetDERCache(cert, x509_der_cache_index, data, data_length);
229 if (!internal_cache) 229 if (!internal_cache)
230 return false; 230 return false;
231 } 231 }
232 *der_cache = *internal_cache; 232 *der_cache = *internal_cache;
233 return true; 233 return true;
234 } 234 }
235 235
236 // Used to free a list of X509_NAMEs and the objects it points to.
237 void sk_X509_NAME_free_all(STACK_OF(X509_NAME)* sk) {
238 sk_X509_NAME_pop_free(sk, X509_NAME_free);
239 }
240
236 } // namespace 241 } // namespace
237 242
238 // static 243 // static
239 X509Certificate::OSCertHandle X509Certificate::DupOSCertHandle( 244 X509Certificate::OSCertHandle X509Certificate::DupOSCertHandle(
240 OSCertHandle cert_handle) { 245 OSCertHandle cert_handle) {
241 DCHECK(cert_handle); 246 DCHECK(cert_handle);
242 // Using X509_dup causes the entire certificate to be reparsed. This 247 // Using X509_dup causes the entire certificate to be reparsed. This
243 // conversion, besides being non-trivial, drops any associated 248 // conversion, besides being non-trivial, drops any associated
244 // application-specific data set by X509_set_ex_data. Using CRYPTO_add 249 // application-specific data set by X509_set_ex_data. Using CRYPTO_add
245 // just bumps up the ref-count for the cert, without causing any allocations 250 // just bumps up the ref-count for the cert, without causing any allocations
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 *type = kPublicKeyTypeECDSA; 469 *type = kPublicKeyTypeECDSA;
465 *size_bits = EVP_PKEY_size(key); 470 *size_bits = EVP_PKEY_size(key);
466 break; 471 break;
467 case EVP_PKEY_DH: 472 case EVP_PKEY_DH:
468 *type = kPublicKeyTypeDH; 473 *type = kPublicKeyTypeDH;
469 *size_bits = EVP_PKEY_size(key) * 8; 474 *size_bits = EVP_PKEY_size(key) * 8;
470 break; 475 break;
471 } 476 }
472 } 477 }
473 478
479 bool X509Certificate::IsIssuedByEncoded(
480 const std::vector<std::string>& valid_issuers) {
481 if (valid_issuers.empty())
482 return false;
483
484 // Convert to a temporary list of X509_NAME objects.
485 // It will own the objects it points to.
486 crypto::ScopedOpenSSL<STACK_OF(X509_NAME), sk_X509_NAME_free_all>
487 issuer_names(sk_X509_NAME_new_null());
488 if (!issuer_names.get())
489 return false;
490
491 for (std::vector<std::string>::const_iterator it = valid_issuers.begin();
492 it != valid_issuers.end(); ++it) {
493 const unsigned char* p =
494 reinterpret_cast<const unsigned char*>(it->data());
495 long len = static_cast<long>(it->length());
496 X509_NAME* ca_name = d2i_X509_NAME(NULL, &p, len);
497 if (ca_name == NULL)
498 return false;
499 sk_X509_NAME_push(issuer_names.get(), ca_name);
500 }
501
502 // Create a temporary list of X509_NAME objects corresponding
503 // to the certificate chain. It doesn't own the object it points to.
504 std::vector<X509_NAME*> cert_names;
505 X509_NAME* issuer = X509_get_issuer_name(cert_handle_);
506 if (issuer == NULL)
507 return false;
508
509 cert_names.push_back(issuer);
510 for (OSCertHandles::iterator it = intermediate_ca_certs_.begin();
511 it != intermediate_ca_certs_.end(); ++it) {
512 issuer = X509_get_issuer_name(*it);
513 if (issuer == NULL)
514 return false;
515 cert_names.push_back(issuer);
516 }
517
518 // and 'cert_names'.
519 for (size_t n = 0; n < cert_names.size(); ++n) {
520 for (int m = 0; m < sk_X509_NAME_num(issuer_names.get()); ++m) {
521 X509_NAME* issuer = sk_X509_NAME_value(issuer_names.get(), m);
522 if (X509_NAME_cmp(issuer, cert_names[n]) == 0) {
523 return true;
524 }
525 }
526 }
527
528 return false;
529 }
530
474 } // namespace net 531 } // namespace net
OLDNEW
« no previous file with comments | « net/base/x509_certificate_nss.cc ('k') | net/base/x509_certificate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698