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

Side by Side Diff: net/cert/x509_certificate_mac.cc

Issue 634033002: Check whether or not a certificate is self-signed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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/cert/x509_certificate.h" 5 #include "net/cert/x509_certificate.h"
6 6
7 #include <CommonCrypto/CommonDigest.h> 7 #include <CommonCrypto/CommonDigest.h>
8 #include <CoreServices/CoreServices.h> 8 #include <CoreServices/CoreServices.h>
9 #include <Security/Security.h> 9 #include <Security/Security.h>
10 10
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/mac/mac_logging.h" 15 #include "base/mac/mac_logging.h"
16 #include "base/mac/scoped_cftyperef.h" 16 #include "base/mac/scoped_cftyperef.h"
17 #include "base/memory/singleton.h" 17 #include "base/memory/singleton.h"
18 #include "base/numerics/safe_conversions.h"
18 #include "base/pickle.h" 19 #include "base/pickle.h"
19 #include "base/sha1.h" 20 #include "base/sha1.h"
20 #include "base/strings/string_piece.h" 21 #include "base/strings/string_piece.h"
21 #include "base/strings/sys_string_conversions.h" 22 #include "base/strings/sys_string_conversions.h"
22 #include "base/synchronization/lock.h" 23 #include "base/synchronization/lock.h"
23 #include "crypto/cssm_init.h" 24 #include "crypto/cssm_init.h"
24 #include "crypto/mac_security_services_lock.h" 25 #include "crypto/mac_security_services_lock.h"
25 #include "net/cert/x509_util_mac.h" 26 #include "net/cert/x509_util_mac.h"
26 27
27 using base::ScopedCFTypeRef; 28 using base::ScopedCFTypeRef;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 case CSSM_ALGID_DH: 507 case CSSM_ALGID_DH:
507 *type = kPublicKeyTypeDH; 508 *type = kPublicKeyTypeDH;
508 break; 509 break;
509 default: 510 default:
510 *type = kPublicKeyTypeUnknown; 511 *type = kPublicKeyTypeUnknown;
511 *size_bits = 0; 512 *size_bits = 0;
512 break; 513 break;
513 } 514 }
514 } 515 }
515 516
517 // static
518 bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) {
519 std::string der_cert;
520 if (!GetDEREncoded(cert_handle, &der_cert))
521 return false;
522
523 const unsigned char* cert_data =
524 reinterpret_cast<const unsigned char*>(der_cert.data());
525 int cert_data_len = checked_cast<int>(der_cert.size());
526 ScopedX509 cert(d2i_X509(NULL, &cert_data, cert_data_len));
527 crypto::ScopedEVP_PKEY scoped_key(X509_get_pubkey(cert_handle));
528 if (!scoped_key)
529 return false;
530 DCHECK(scoped_key.get());
531 EVP_PKEY* key = scoped_key.get();
532
533 // NOTE: X509_verify() returns 1 in case of success, 0 or -1 on error.
534 return X509_verify(cert.get(), key) == 1;
535 }
536
516 } // namespace net 537 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698