OLD | NEW |
---|---|
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" |
26 #include "crypto/scoped_openssl_types.h" | |
25 #include "net/cert/x509_util_mac.h" | 27 #include "net/cert/x509_util_mac.h" |
28 #include "net/cert/x509_util_openssl.h" | |
26 | 29 |
27 using base::ScopedCFTypeRef; | 30 using base::ScopedCFTypeRef; |
28 using base::Time; | 31 using base::Time; |
29 | 32 |
30 namespace net { | 33 namespace net { |
31 | 34 |
32 namespace { | 35 namespace { |
33 | 36 |
34 void GetCertDistinguishedName( | 37 void GetCertDistinguishedName( |
35 const x509_util::CSSMCachedCertificate& cached_cert, | 38 const x509_util::CSSMCachedCertificate& cached_cert, |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 case CSSM_ALGID_DH: | 527 case CSSM_ALGID_DH: |
525 *type = kPublicKeyTypeDH; | 528 *type = kPublicKeyTypeDH; |
526 break; | 529 break; |
527 default: | 530 default: |
528 *type = kPublicKeyTypeUnknown; | 531 *type = kPublicKeyTypeUnknown; |
529 *size_bits = 0; | 532 *size_bits = 0; |
530 break; | 533 break; |
531 } | 534 } |
532 } | 535 } |
533 | 536 |
537 // static | |
538 bool X509Certificate::IsSelfSigned(OSCertHandle cert_handle) { | |
539 std::string der_cert; | |
540 if (!GetDEREncoded(cert_handle, &der_cert)) | |
541 return false; | |
542 | |
543 const unsigned char* cert_data = | |
544 reinterpret_cast<const unsigned char*>(der_cert.data()); | |
545 int cert_data_len = base::checked_cast<int>(der_cert.size()); | |
546 typedef crypto::ScopedOpenSSL<X509, X509_free>::Type ScopedX509; | |
547 ScopedX509 cert(d2i_X509(NULL, &cert_data, cert_data_len)); | |
548 crypto::ScopedEVP_PKEY scoped_key(X509_get_pubkey(cert.get())); | |
549 if (!scoped_key) | |
550 return false; | |
551 DCHECK(scoped_key.get()); | |
552 EVP_PKEY* key = scoped_key.get(); | |
553 | |
554 // NOTE: X509_verify() returns 1 in case of success, 0 or -1 on error. | |
555 return X509_verify(cert.get(), key) == 1; | |
Ryan Sleevi
2014/10/21 22:27:43
Mixing BoringSSL types like this with a platform-s
palmer
2014/10/21 23:02:13
Done.
| |
556 } | |
557 | |
534 } // namespace net | 558 } // namespace net |
OLD | NEW |