| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_CERTIFICATE_PATTERN_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_CERTIFICATE_PATTERN_H_ | |
| 7 | |
| 8 #include <list> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 | |
| 14 namespace base { | |
| 15 class DictionaryValue; | |
| 16 } | |
| 17 | |
| 18 namespace net { | |
| 19 struct CertPrincipal; | |
| 20 class X509Certificate; | |
| 21 } | |
| 22 | |
| 23 namespace chromeos { | |
| 24 | |
| 25 // Class to represent the DER fields of an issuer or a subject in a | |
| 26 // certificate and compare them. | |
| 27 class IssuerSubjectPattern { | |
| 28 public: | |
| 29 IssuerSubjectPattern(); | |
| 30 IssuerSubjectPattern(const std::string& common_name, | |
| 31 const std::string& locality, | |
| 32 const std::string& organization, | |
| 33 const std::string& organizational_unit); | |
| 34 ~IssuerSubjectPattern(); | |
| 35 | |
| 36 // Returns true only if any fields set in this pattern match exactly with | |
| 37 // similar fields in the principal. If organization_ or organizational_unit_ | |
| 38 // are set, then at least one of the organizations or units in the principal | |
| 39 // must match. | |
| 40 bool Matches(const net::CertPrincipal& principal) const; | |
| 41 | |
| 42 // Returns true if all fields in the pattern are empty. | |
| 43 bool Empty() const; | |
| 44 | |
| 45 // Clears out all values in this pattern (so Empty returns true). | |
| 46 void Clear(); | |
| 47 | |
| 48 void set_common_name(const std::string& name) { common_name_ = name; } | |
| 49 void set_locality(const std::string& locality) { locality_ = locality; } | |
| 50 void set_organization(const std::string& organization) { | |
| 51 organization_ = organization; | |
| 52 } | |
| 53 void set_organizational_unit(const std::string& unit) { | |
| 54 organizational_unit_ = unit; | |
| 55 } | |
| 56 | |
| 57 const std::string& common_name() const { | |
| 58 return common_name_; | |
| 59 } | |
| 60 const std::string& locality() const { | |
| 61 return locality_; | |
| 62 } | |
| 63 const std::string& organization() const { | |
| 64 return organization_; | |
| 65 } | |
| 66 const std::string& organizational_unit() const { | |
| 67 return organizational_unit_; | |
| 68 } | |
| 69 | |
| 70 // Creates a new dictionary with the issuer subject pattern as its contents. | |
| 71 // Caller assumes ownership. | |
| 72 base::DictionaryValue* CreateAsDictionary() const; | |
| 73 | |
| 74 bool CopyFromDictionary(const base::DictionaryValue& dictionary); | |
| 75 | |
| 76 private: | |
| 77 std::string common_name_; | |
| 78 std::string locality_; | |
| 79 std::string organization_; | |
| 80 std::string organizational_unit_; | |
| 81 }; | |
| 82 | |
| 83 // A class to contain a certificate pattern and find existing matches to the | |
| 84 // pattern in the certificate database. | |
| 85 class CertificatePattern { | |
| 86 public: | |
| 87 CertificatePattern(); | |
| 88 ~CertificatePattern(); | |
| 89 | |
| 90 // Returns true if this pattern has nothing set (and so would match | |
| 91 // all certs). Ignores enrollment_uri_; | |
| 92 bool Empty() const; | |
| 93 | |
| 94 // Clears out all the values in this pattern (so Empty returns true). | |
| 95 void Clear(); | |
| 96 | |
| 97 // Fetches the matching certificate that has the latest valid start date. | |
| 98 // Returns a NULL refptr if there is no such match. | |
| 99 scoped_refptr<net::X509Certificate> GetMatch() const; | |
| 100 | |
| 101 void set_issuer_ca_ref_list(const std::vector<std::string>& ref_list) { | |
| 102 issuer_ca_ref_list_ = ref_list; | |
| 103 } | |
| 104 void set_issuer(const IssuerSubjectPattern& issuer) { issuer_ = issuer; } | |
| 105 void set_subject(const IssuerSubjectPattern& subject) { subject_ = subject; } | |
| 106 void set_enrollment_uri_list(const std::vector<std::string>& uri_list) { | |
| 107 enrollment_uri_list_ = uri_list; | |
| 108 } | |
| 109 | |
| 110 const IssuerSubjectPattern& issuer() const { | |
| 111 return issuer_; | |
| 112 } | |
| 113 const IssuerSubjectPattern& subject() const { | |
| 114 return subject_; | |
| 115 } | |
| 116 const std::vector<std::string>& issuer_ca_ref_list() const { | |
| 117 return issuer_ca_ref_list_; | |
| 118 } | |
| 119 const std::vector<std::string>& enrollment_uri_list() const { | |
| 120 return enrollment_uri_list_; | |
| 121 } | |
| 122 | |
| 123 // Creates a new dictionary containing the data in the certificate pattern. | |
| 124 base::DictionaryValue* CreateAsDictionary() const; | |
| 125 | |
| 126 // Replaces the contents of this CertificatePattern object with | |
| 127 // the values in the dictionary. Returns false if the dictionary is | |
| 128 // malformed. | |
| 129 bool CopyFromDictionary(const base::DictionaryValue& dictionary); | |
| 130 | |
| 131 private: | |
| 132 std::vector<std::string> issuer_ca_ref_list_; | |
| 133 IssuerSubjectPattern issuer_; | |
| 134 IssuerSubjectPattern subject_; | |
| 135 std::vector<std::string> enrollment_uri_list_; | |
| 136 }; | |
| 137 | |
| 138 } // namespace chromeos | |
| 139 | |
| 140 #endif // CHROME_BROWSER_CHROMEOS_CROS_CERTIFICATE_PATTERN_H_ | |
| OLD | NEW |