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