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 CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_ 6 #define CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "chromeos/chromeos_export.h" 12 13 namespace base { 14 class DictionaryValue; 15 } 16 17 namespace chromeos { 18 19 // Class to represent the DER fields of an issuer or a subject in a 20 // certificate and compare them. 21 class CHROMEOS_EXPORT IssuerSubjectPattern { 22 public: 23 IssuerSubjectPattern(); 24 IssuerSubjectPattern(const std::string& common_name, 25 const std::string& locality, 26 const std::string& organization, 27 const std::string& organizational_unit); 28 ~IssuerSubjectPattern(); 29 30 // Returns true if all fields in the pattern are empty. 31 bool Empty() const; 32 33 // Clears out all values in this pattern (so Empty returns true). 34 void Clear(); 35 36 void set_common_name(const std::string& name) { common_name_ = name; } 37 void set_locality(const std::string& locality) { locality_ = locality; } 38 void set_organization(const std::string& organization) { 39 organization_ = organization; 40 } 41 void set_organizational_unit(const std::string& unit) { 42 organizational_unit_ = unit; 43 } 44 45 const std::string& common_name() const { 46 return common_name_; 47 } 48 const std::string& locality() const { 49 return locality_; 50 } 51 const std::string& organization() const { 52 return organization_; 53 } 54 const std::string& organizational_unit() const { 55 return organizational_unit_; 56 } 57 58 // Creates a new dictionary with the issuer subject pattern as its contents. 59 // Caller assumes ownership. 60 base::DictionaryValue* CreateAsDictionary() const; 61 62 bool CopyFromDictionary(const base::DictionaryValue& dictionary); 63 64 private: 65 std::string common_name_; 66 std::string locality_; 67 std::string organization_; 68 std::string organizational_unit_; 69 }; 70 71 // A class to contain a certificate pattern and find existing matches to the 72 // pattern in the certificate database. 73 class CHROMEOS_EXPORT CertificatePattern { 74 public: 75 CertificatePattern(); 76 ~CertificatePattern(); 77 78 // Returns true if this pattern has nothing set (and so would match 79 // all certs). Ignores enrollment_uri_; 80 bool Empty() const; 81 82 // Clears out all the values in this pattern (so Empty returns true). 83 void Clear(); 84 85 void set_issuer(const IssuerSubjectPattern& issuer) { issuer_ = issuer; } 86 void set_subject(const IssuerSubjectPattern& subject) { subject_ = subject; } 87 void set_enrollment_uri_list(const std::vector<std::string>& uri_list) { 88 enrollment_uri_list_ = uri_list; 89 } 90 91 const IssuerSubjectPattern& issuer() const { 92 return issuer_; 93 } 94 const IssuerSubjectPattern& subject() const { 95 return subject_; 96 } 97 const std::vector<std::string>& issuer_ca_pems() const { 98 return issuer_ca_pems_; 99 } 100 const std::vector<std::string>& enrollment_uri_list() const { 101 return enrollment_uri_list_; 102 } 103 104 // Creates a new dictionary containing the data in the certificate pattern. 105 base::DictionaryValue* CreateAsDictionary() const; 106 107 // Replaces the contents of this CertificatePattern object with 108 // the values in the dictionary. Returns false if the dictionary is 109 // malformed. 110 bool CopyFromDictionary(const base::DictionaryValue& dictionary); 111 112 private: 113 std::vector<std::string> issuer_ca_pems_; 114 IssuerSubjectPattern issuer_; 115 IssuerSubjectPattern subject_; 116 std::vector<std::string> enrollment_uri_list_; 117 }; 118 119 } // namespace chromeos 120 121 #endif // CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_ 122