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.
5 #ifndef CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_
6 #define CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_
11 #include "chromeos/chromeos_export.h"
14 class DictionaryValue
;
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
{
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();
30 // Returns true if all fields in the pattern are empty.
33 // Clears out all values in this pattern (so Empty returns true).
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
;
41 void set_organizational_unit(const std::string
& unit
) {
42 organizational_unit_
= unit
;
45 const std::string
& common_name() const {
48 const std::string
& locality() const {
51 const std::string
& organization() const {
54 const std::string
& organizational_unit() const {
55 return organizational_unit_
;
58 // Creates a new dictionary with the issuer subject pattern as its contents.
59 // Caller assumes ownership.
60 base::DictionaryValue
* CreateAsDictionary() const;
62 bool CopyFromDictionary(const base::DictionaryValue
& dictionary
);
65 std::string common_name_
;
66 std::string locality_
;
67 std::string organization_
;
68 std::string organizational_unit_
;
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
{
76 ~CertificatePattern();
78 // Returns true if this pattern has nothing set (and so would match
79 // all certs). Ignores enrollment_uri_;
82 // Clears out all the values in this pattern (so Empty returns true).
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
;
91 const IssuerSubjectPattern
& issuer() const {
94 const IssuerSubjectPattern
& subject() const {
97 const std::vector
<std::string
>& issuer_ca_pems() const {
98 return issuer_ca_pems_
;
100 const std::vector
<std::string
>& enrollment_uri_list() const {
101 return enrollment_uri_list_
;
104 // Creates a new dictionary containing the data in the certificate pattern.
105 base::DictionaryValue
* CreateAsDictionary() const;
107 // Replaces the contents of this CertificatePattern object with
108 // the values in the dictionary. Returns false if the dictionary is
110 bool CopyFromDictionary(const base::DictionaryValue
& dictionary
);
113 std::vector
<std::string
> issuer_ca_pems_
;
114 IssuerSubjectPattern issuer_
;
115 IssuerSubjectPattern subject_
;
116 std::vector
<std::string
> enrollment_uri_list_
;
119 } // namespace chromeos
121 #endif // CHROMEOS_NETWORK_CERTIFICATE_PATTERN_H_