Chromium Code Reviews| 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/ev_root_ca_metadata.h" | 5 #include "net/cert/ev_root_ca_metadata.h" |
| 6 | 6 |
| 7 #if defined(USE_NSS_CERTS) | 7 #if defined(USE_NSS_CERTS) |
| 8 #include <cert.h> | 8 #include <cert.h> |
| 9 #include <pkcs11n.h> | 9 #include <pkcs11n.h> |
| 10 #include <secerr.h> | 10 #include <secerr.h> |
| 11 #include <secoid.h> | 11 #include <secoid.h> |
| 12 #elif defined(OS_WIN) | 12 #elif defined(OS_WIN) |
| 13 #include <stdlib.h> | 13 #include <stdlib.h> |
| 14 #elif defined(OS_MACOSX) | |
| 15 #include <openssl/obj.h> | |
|
davidben
2016/11/09 00:15:03
#include "third_party/boringssl/src/include/openss
mattm
2016/11/10 05:40:41
Done.
| |
| 14 #endif | 16 #endif |
| 15 | 17 |
| 16 #include "base/lazy_instance.h" | 18 #include "base/lazy_instance.h" |
| 17 #include "base/logging.h" | 19 #include "base/logging.h" |
| 18 #if defined(USE_NSS_CERTS) | 20 #if defined(USE_NSS_CERTS) |
| 19 #include "crypto/nss_util.h" | 21 #include "crypto/nss_util.h" |
| 22 #elif defined(OS_MACOSX) | |
| 23 #include "net/der/input.h" | |
| 20 #endif | 24 #endif |
| 21 | 25 |
| 22 namespace net { | 26 namespace net { |
| 23 | 27 |
| 24 #if defined(USE_NSS_CERTS) || defined(OS_WIN) | 28 #if defined(USE_NSS_CERTS) || defined(OS_WIN) || defined(OS_MACOSX) |
| 25 // Raw metadata. | 29 // Raw metadata. |
| 26 struct EVMetadata { | 30 struct EVMetadata { |
| 27 // kMaxOIDsPerCA is the number of OIDs that we can support per root CA. At | 31 // kMaxOIDsPerCA is the number of OIDs that we can support per root CA. At |
| 28 // least one CA has different EV policies for business vs government | 32 // least one CA has different EV policies for business vs government |
| 29 // entities and, in the case of cross-signing, we might need to list another | 33 // entities and, in the case of cross-signing, we might need to list another |
| 30 // CA's policy OID under the cross-signing root. | 34 // CA's policy OID under the cross-signing root. |
| 31 static const size_t kMaxOIDsPerCA = 2; | 35 static const size_t kMaxOIDsPerCA = 2; |
| 32 // This is the maximum length of an OID string (including the trailing NUL). | 36 // This is the maximum length of an OID string (including the trailing NUL). |
| 33 static const size_t kMaxOIDLength = 32; | 37 static const size_t kMaxOIDLength = 32; |
| 34 | 38 |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 701 } | 705 } |
| 702 | 706 |
| 703 bool EVRootCAMetadata::RemoveEVCA(const SHA1HashValue& fingerprint) { | 707 bool EVRootCAMetadata::RemoveEVCA(const SHA1HashValue& fingerprint) { |
| 704 ExtraEVCAMap::iterator it = extra_cas_.find(fingerprint); | 708 ExtraEVCAMap::iterator it = extra_cas_.find(fingerprint); |
| 705 if (it == extra_cas_.end()) | 709 if (it == extra_cas_.end()) |
| 706 return false; | 710 return false; |
| 707 extra_cas_.erase(it); | 711 extra_cas_.erase(it); |
| 708 return true; | 712 return true; |
| 709 } | 713 } |
| 710 | 714 |
| 715 #elif defined(OS_MACOSX) | |
| 716 | |
| 717 namespace { | |
| 718 | |
| 719 std::string OIDStringToDER(const char* policy) { | |
| 720 std::string der_policy; | |
| 721 int nid = OBJ_txt2nid(policy); | |
| 722 if (nid == NID_undef) | |
| 723 nid = OBJ_create(policy, nullptr, nullptr); | |
| 724 if (nid == NID_undef) | |
| 725 return der_policy; | |
| 726 uint8_t* der; | |
| 727 size_t der_len; | |
| 728 bssl::ScopedCBB cbb; | |
| 729 if (!CBB_init(cbb.get(), 0) || !OBJ_nid2cbb(cbb.get(), nid) || | |
| 730 !CBB_finish(cbb.get(), &der, &der_len)) | |
| 731 return der_policy; | |
| 732 | |
| 733 DCHECK_GT(der_len, 2U); | |
| 734 DCHECK_EQ(der[0], 0x6); // OBJECT IDENTIFIER | |
| 735 der_policy.assign(reinterpret_cast<char*>(der) + 2, der_len - 2); | |
| 736 return der_policy; | |
| 737 } | |
|
Ryan Sleevi
2016/11/08 23:54:09
@davidben to comment on if there's anything cleane
davidben
2016/11/09 00:15:03
I'll probably have to tweak this slightly at some
davidben
2016/11/09 00:15:55
Sorry, that should be if (!obj) {
And I guess you
mattm
2016/11/10 05:40:41
Done.
| |
| 738 | |
| 739 } // namespace | |
| 740 | |
| 741 bool EVRootCAMetadata::IsEVPolicyOID(PolicyOID policy_oid) const { | |
| 742 return policy_oids_.find(policy_oid.AsString()) != policy_oids_.end(); | |
| 743 } | |
| 744 | |
| 745 bool EVRootCAMetadata::HasEVPolicyOID(const SHA1HashValue& fingerprint, | |
| 746 PolicyOID policy_oid) const { | |
| 747 PolicyOIDMap::const_iterator iter = ev_policy_.find(fingerprint); | |
| 748 if (iter == ev_policy_.end()) | |
| 749 return false; | |
| 750 for (const std::string& ev_oid : iter->second) { | |
| 751 if (der::Input(&ev_oid) == policy_oid) | |
| 752 return true; | |
| 753 } | |
| 754 return false; | |
| 755 } | |
| 756 | |
| 757 bool EVRootCAMetadata::AddEVCA(const SHA1HashValue& fingerprint, | |
| 758 const char* policy) { | |
| 759 if (ev_policy_.find(fingerprint) != ev_policy_.end()) | |
| 760 return false; | |
| 761 | |
| 762 std::string der_policy = OIDStringToDER(policy); | |
| 763 if (der_policy.empty()) | |
| 764 return false; | |
| 765 | |
| 766 ev_policy_[fingerprint].push_back(der_policy); | |
| 767 policy_oids_.insert(der_policy); | |
| 768 return true; | |
| 769 } | |
| 770 | |
| 771 bool EVRootCAMetadata::RemoveEVCA(const SHA1HashValue& fingerprint) { | |
| 772 PolicyOIDMap::iterator it = ev_policy_.find(fingerprint); | |
| 773 if (it == ev_policy_.end()) | |
| 774 return false; | |
| 775 std::string oid = it->second[0]; | |
| 776 ev_policy_.erase(it); | |
| 777 policy_oids_.erase(oid); | |
| 778 return true; | |
| 779 } | |
| 780 | |
| 711 #else | 781 #else |
| 712 | 782 |
| 713 // These are just stub functions for platforms where we don't use this EV | 783 // These are just stub functions for platforms where we don't use this EV |
| 714 // metadata. | 784 // metadata. |
| 715 | 785 |
| 716 bool EVRootCAMetadata::AddEVCA(const SHA1HashValue& fingerprint, | 786 bool EVRootCAMetadata::AddEVCA(const SHA1HashValue& fingerprint, |
| 717 const char* policy) { | 787 const char* policy) { |
| 718 return true; | 788 return true; |
| 719 } | 789 } |
| 720 | 790 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 739 PolicyOID policy; | 809 PolicyOID policy; |
| 740 if (!RegisterOID(policy_oid, &policy)) { | 810 if (!RegisterOID(policy_oid, &policy)) { |
| 741 LOG(ERROR) << "Failed to register OID: " << policy_oid; | 811 LOG(ERROR) << "Failed to register OID: " << policy_oid; |
| 742 continue; | 812 continue; |
| 743 } | 813 } |
| 744 | 814 |
| 745 ev_policy_[metadata.fingerprint].push_back(policy); | 815 ev_policy_[metadata.fingerprint].push_back(policy); |
| 746 policy_oids_.insert(policy); | 816 policy_oids_.insert(policy); |
| 747 } | 817 } |
| 748 } | 818 } |
| 819 #elif defined(OS_MACOSX) | |
| 820 for (size_t i = 0; i < arraysize(ev_root_ca_metadata); i++) { | |
| 821 const EVMetadata& metadata = ev_root_ca_metadata[i]; | |
| 822 for (size_t j = 0; j < arraysize(metadata.policy_oids); j++) { | |
| 823 if (metadata.policy_oids[j][0] == '\0') | |
| 824 break; | |
| 825 const char* policy_oid = metadata.policy_oids[j]; | |
| 826 | |
| 827 PolicyOID policy; | |
| 828 std::string policy_der = OIDStringToDER(policy_oid); | |
| 829 if (policy_der.empty()) { | |
| 830 LOG(ERROR) << "Failed to register OID: " << policy_oid; | |
| 831 continue; | |
| 832 } | |
| 833 | |
| 834 ev_policy_[metadata.fingerprint].push_back(policy_der); | |
| 835 policy_oids_.insert(policy_der); | |
| 836 } | |
| 837 } | |
| 749 #endif | 838 #endif |
| 750 } | 839 } |
| 751 | 840 |
| 752 EVRootCAMetadata::~EVRootCAMetadata() { } | 841 EVRootCAMetadata::~EVRootCAMetadata() { } |
| 753 | 842 |
| 754 } // namespace net | 843 } // namespace net |
| OLD | NEW |