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 NET_CERT_X509_CERT_TYPES_H_ | 5 #ifndef NET_CERT_X509_CERT_TYPES_H_ |
6 #define NET_CERT_X509_CERT_TYPES_H_ | 6 #define NET_CERT_X509_CERT_TYPES_H_ |
7 | 7 |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 std::string locality_name; | 61 std::string locality_name; |
62 std::string state_or_province_name; | 62 std::string state_or_province_name; |
63 std::string country_name; | 63 std::string country_name; |
64 | 64 |
65 std::vector<std::string> street_addresses; | 65 std::vector<std::string> street_addresses; |
66 std::vector<std::string> organization_names; | 66 std::vector<std::string> organization_names; |
67 std::vector<std::string> organization_unit_names; | 67 std::vector<std::string> organization_unit_names; |
68 std::vector<std::string> domain_components; | 68 std::vector<std::string> domain_components; |
69 }; | 69 }; |
70 | 70 |
71 // This class is useful for maintaining policies about which certificates are | |
72 // permitted or forbidden for a particular purpose. | |
73 class NET_EXPORT CertPolicy { | |
74 public: | |
75 // The judgments this policy can reach. | |
76 enum Judgment { | |
77 // We don't have policy information for this certificate. | |
78 UNKNOWN, | |
79 | |
80 // This certificate is allowed. | |
81 ALLOWED, | |
82 | |
83 // This certificate is denied. | |
84 DENIED, | |
85 }; | |
86 | |
87 CertPolicy(); | |
88 ~CertPolicy(); | |
89 | |
90 // Returns the judgment this policy makes about this certificate. | |
91 // For a certificate to be allowed, it must not have any *additional* errors | |
92 // from when it was allowed. For a certificate to be denied, it need only | |
93 // match *any* of the errors that caused it to be denied. We check denial | |
94 // first, before checking whether it's been allowed. | |
95 Judgment Check(X509Certificate* cert, CertStatus error) const; | |
96 | |
97 // Causes the policy to allow this certificate for a given |error|. | |
98 void Allow(X509Certificate* cert, CertStatus error); | |
99 | |
100 // Causes the policy to deny this certificate for a given |error|. | |
101 void Deny(X509Certificate* cert, CertStatus error); | |
102 | |
103 // Returns true if this policy has allowed at least one certificate. | |
104 bool HasAllowedCert() const; | |
105 | |
106 // Returns true if this policy has denied at least one certificate. | |
107 bool HasDeniedCert() const; | |
108 | |
109 private: | |
110 // The set of fingerprints of allowed certificates. | |
111 std::map<SHA1HashValue, CertStatus, SHA1HashValueLessThan> allowed_; | |
112 | |
113 // The set of fingerprints of denied certificates. | |
114 std::map<SHA1HashValue, CertStatus, SHA1HashValueLessThan> denied_; | |
115 }; | |
116 | |
117 #if defined(OS_MACOSX) && !defined(OS_IOS) | 71 #if defined(OS_MACOSX) && !defined(OS_IOS) |
118 // Compares two OIDs by value. | 72 // Compares two OIDs by value. |
119 inline bool CSSMOIDEqual(const CSSM_OID* oid1, const CSSM_OID* oid2) { | 73 inline bool CSSMOIDEqual(const CSSM_OID* oid1, const CSSM_OID* oid2) { |
120 return oid1->Length == oid2->Length && | 74 return oid1->Length == oid2->Length && |
121 (memcmp(oid1->Data, oid2->Data, oid1->Length) == 0); | 75 (memcmp(oid1->Data, oid2->Data, oid1->Length) == 0); |
122 } | 76 } |
123 #endif | 77 #endif |
124 | 78 |
125 // A list of ASN.1 date/time formats that ParseCertificateDate() supports, | 79 // A list of ASN.1 date/time formats that ParseCertificateDate() supports, |
126 // encoded in the canonical forms specified in RFC 2459/3280/5280. | 80 // encoded in the canonical forms specified in RFC 2459/3280/5280. |
127 enum CertDateFormat { | 81 enum CertDateFormat { |
128 // UTCTime: Format is YYMMDDHHMMSSZ | 82 // UTCTime: Format is YYMMDDHHMMSSZ |
129 CERT_DATE_FORMAT_UTC_TIME, | 83 CERT_DATE_FORMAT_UTC_TIME, |
130 | 84 |
131 // GeneralizedTime: Format is YYYYMMDDHHMMSSZ | 85 // GeneralizedTime: Format is YYYYMMDDHHMMSSZ |
132 CERT_DATE_FORMAT_GENERALIZED_TIME, | 86 CERT_DATE_FORMAT_GENERALIZED_TIME, |
133 }; | 87 }; |
134 | 88 |
135 // Attempts to parse |raw_date|, an ASN.1 date/time string encoded as | 89 // Attempts to parse |raw_date|, an ASN.1 date/time string encoded as |
136 // |format|, and writes the result into |*time|. If an invalid date is | 90 // |format|, and writes the result into |*time|. If an invalid date is |
137 // specified, or if parsing fails, returns false, and |*time| will not be | 91 // specified, or if parsing fails, returns false, and |*time| will not be |
138 // updated. | 92 // updated. |
139 NET_EXPORT_PRIVATE bool ParseCertificateDate(const base::StringPiece& raw_date, | 93 NET_EXPORT_PRIVATE bool ParseCertificateDate(const base::StringPiece& raw_date, |
140 CertDateFormat format, | 94 CertDateFormat format, |
141 base::Time* time); | 95 base::Time* time); |
142 } // namespace net | 96 } // namespace net |
143 | 97 |
144 #endif // NET_CERT_X509_CERT_TYPES_H_ | 98 #endif // NET_CERT_X509_CERT_TYPES_H_ |
OLD | NEW |