| 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 #ifndef CHROME_BROWSER_CHROMEOS_CROS_CERTIFICATE_PATTERN_H_ | 5 #ifndef CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CROS_CERTIFICATE_PATTERN_H_ | 6 #define CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_ |
| 7 | 7 |
| 8 #include <list> | |
| 9 #include <string> | 8 #include <string> |
| 10 #include <vector> | 9 #include <vector> |
| 11 | 10 |
| 12 #include "base/memory/ref_counted.h" | 11 #include "chromeos/chromeos_export.h" |
| 13 | 12 |
| 14 namespace base { | 13 namespace base { |
| 15 class DictionaryValue; | 14 class DictionaryValue; |
| 16 } | 15 } |
| 17 | 16 |
| 18 namespace net { | |
| 19 struct CertPrincipal; | |
| 20 class X509Certificate; | |
| 21 } | |
| 22 | |
| 23 namespace chromeos { | 17 namespace chromeos { |
| 24 | 18 |
| 25 // Class to represent the DER fields of an issuer or a subject in a | 19 // Class to represent the DER fields of an issuer or a subject in a |
| 26 // certificate and compare them. | 20 // certificate and compare them. |
| 27 class IssuerSubjectPattern { | 21 class CHROMEOS_EXPORT IssuerSubjectPattern { |
| 28 public: | 22 public: |
| 29 IssuerSubjectPattern(); | 23 IssuerSubjectPattern(); |
| 30 IssuerSubjectPattern(const std::string& common_name, | 24 IssuerSubjectPattern(const std::string& common_name, |
| 31 const std::string& locality, | 25 const std::string& locality, |
| 32 const std::string& organization, | 26 const std::string& organization, |
| 33 const std::string& organizational_unit); | 27 const std::string& organizational_unit); |
| 34 ~IssuerSubjectPattern(); | 28 ~IssuerSubjectPattern(); |
| 35 | 29 |
| 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. | 30 // Returns true if all fields in the pattern are empty. |
| 43 bool Empty() const; | 31 bool Empty() const; |
| 44 | 32 |
| 45 // Clears out all values in this pattern (so Empty returns true). | 33 // Clears out all values in this pattern (so Empty returns true). |
| 46 void Clear(); | 34 void Clear(); |
| 47 | 35 |
| 48 void set_common_name(const std::string& name) { common_name_ = name; } | 36 void set_common_name(const std::string& name) { common_name_ = name; } |
| 49 void set_locality(const std::string& locality) { locality_ = locality; } | 37 void set_locality(const std::string& locality) { locality_ = locality; } |
| 50 void set_organization(const std::string& organization) { | 38 void set_organization(const std::string& organization) { |
| 51 organization_ = organization; | 39 organization_ = organization; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 75 | 63 |
| 76 private: | 64 private: |
| 77 std::string common_name_; | 65 std::string common_name_; |
| 78 std::string locality_; | 66 std::string locality_; |
| 79 std::string organization_; | 67 std::string organization_; |
| 80 std::string organizational_unit_; | 68 std::string organizational_unit_; |
| 81 }; | 69 }; |
| 82 | 70 |
| 83 // A class to contain a certificate pattern and find existing matches to the | 71 // A class to contain a certificate pattern and find existing matches to the |
| 84 // pattern in the certificate database. | 72 // pattern in the certificate database. |
| 85 class CertificatePattern { | 73 class CHROMEOS_EXPORT CertificatePattern { |
| 86 public: | 74 public: |
| 87 CertificatePattern(); | 75 CertificatePattern(); |
| 88 ~CertificatePattern(); | 76 ~CertificatePattern(); |
| 89 | 77 |
| 90 // Returns true if this pattern has nothing set (and so would match | 78 // Returns true if this pattern has nothing set (and so would match |
| 91 // all certs). Ignores enrollment_uri_; | 79 // all certs). Ignores enrollment_uri_; |
| 92 bool Empty() const; | 80 bool Empty() const; |
| 93 | 81 |
| 94 // Clears out all the values in this pattern (so Empty returns true). | 82 // Clears out all the values in this pattern (so Empty returns true). |
| 95 void Clear(); | 83 void Clear(); |
| 96 | 84 |
| 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) { | 85 void set_issuer_ca_ref_list(const std::vector<std::string>& ref_list) { |
| 102 issuer_ca_ref_list_ = ref_list; | 86 issuer_ca_ref_list_ = ref_list; |
| 103 } | 87 } |
| 104 void set_issuer(const IssuerSubjectPattern& issuer) { issuer_ = issuer; } | 88 void set_issuer(const IssuerSubjectPattern& issuer) { issuer_ = issuer; } |
| 105 void set_subject(const IssuerSubjectPattern& subject) { subject_ = subject; } | 89 void set_subject(const IssuerSubjectPattern& subject) { subject_ = subject; } |
| 106 void set_enrollment_uri_list(const std::vector<std::string>& uri_list) { | 90 void set_enrollment_uri_list(const std::vector<std::string>& uri_list) { |
| 107 enrollment_uri_list_ = uri_list; | 91 enrollment_uri_list_ = uri_list; |
| 108 } | 92 } |
| 109 | 93 |
| 110 const IssuerSubjectPattern& issuer() const { | 94 const IssuerSubjectPattern& issuer() const { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 130 | 114 |
| 131 private: | 115 private: |
| 132 std::vector<std::string> issuer_ca_ref_list_; | 116 std::vector<std::string> issuer_ca_ref_list_; |
| 133 IssuerSubjectPattern issuer_; | 117 IssuerSubjectPattern issuer_; |
| 134 IssuerSubjectPattern subject_; | 118 IssuerSubjectPattern subject_; |
| 135 std::vector<std::string> enrollment_uri_list_; | 119 std::vector<std::string> enrollment_uri_list_; |
| 136 }; | 120 }; |
| 137 | 121 |
| 138 } // namespace chromeos | 122 } // namespace chromeos |
| 139 | 123 |
| 140 #endif // CHROME_BROWSER_CHROMEOS_CROS_CERTIFICATE_PATTERN_H_ | 124 #endif // CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_ |
| OLD | NEW |