OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 NET_CERT_INTERNAL_NAME_CONSTRAINTS_H_ | |
6 #define NET_CERT_INTERNAL_NAME_CONSTRAINTS_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "net/base/ip_address_number.h" | |
12 | |
13 namespace net { | |
14 | |
15 namespace der { | |
16 class Input; | |
17 } // namespace der | |
18 | |
19 enum GeneralNameTypes { | |
20 GENERAL_NAME_OTHER_NAME = 1 << 0, | |
21 GENERAL_NAME_RFC822_NAME = 1 << 1, | |
22 GENERAL_NAME_DNS_NAME = 1 << 2, | |
23 GENERAL_NAME_X400_ADDRESS = 1 << 3, | |
24 GENERAL_NAME_DIRECTORY_NAME = 1 << 4, | |
25 GENERAL_NAME_EDI_PARTY_NAME = 1 << 5, | |
26 GENERAL_NAME_UNIFORM_RESOURCE_IDENTIFIER = 1 << 6, | |
27 GENERAL_NAME_IP_ADDRESS = 1 << 7, | |
28 GENERAL_NAME_REGISTERED_ID = 1 << 8, | |
29 }; | |
30 | |
31 // Parses a NameConstraints extension value and allows testing whether names are | |
32 // allowed under those constraints as defined by RFC 5280 section 4.2.1.10. | |
33 class NET_EXPORT NameConstraints { | |
34 public: | |
35 // TODO(mattm): This may need to be split out into a public class, since | |
36 // GeneralNames is used other places in a certificate also... | |
37 struct GeneralNames { | |
38 GeneralNames(); | |
39 ~GeneralNames(); | |
40 | |
41 // ASCII hostnames. | |
42 std::vector<std::string> dns_names; | |
43 | |
44 // DER encoded Name values (not including the Sequence tag). | |
eroman
2015/09/10 17:48:28
"DER-encoded" to match the rest of the comments
mattm
2015/09/22 22:12:31
Done.
| |
45 std::vector<std::vector<uint8_t>> directory_names; | |
46 | |
47 // iPAddresses. For Subject Alternative Name this will be 4 bytes for IPv4 | |
48 // or 16 bytes for IPv6. For Name Constraints, it will be ip + netmask | |
49 // (8 bytes for IPv4, 32 bytes for IPv6). | |
50 std::vector<std::vector<uint8_t>> ip_addresses; | |
51 | |
52 // Which name types were present, as a bitfield of GeneralNameTypes. | |
53 // Includes both the supported and unsupported types (although unsupported | |
54 // ones may not be recorded depending on the context, like non-critical name | |
55 // constraints.) | |
56 int present_name_types = 0; | |
57 }; | |
58 | |
59 ~NameConstraints(); | |
60 | |
61 // Parses a DER-encoded NameConstraints extension and initializes this object. | |
62 // Should only be called once on a given NameConstraints object (whether | |
63 // successful or not). | |
64 // |extension_value| should be the extnValue from the extension (not including | |
65 // the OCTET STRING tag). |is_critical| should be true if the extension was | |
66 // marked critical. Returns true if the extension was parsed successfully, | |
67 // after which the IsPermitted methods may be used to test if Names are | |
68 // permitted by the NameConstraints. | |
69 // The object lifetime is not bound to the lifetime of |extension_value| data. | |
70 bool Parse(const der::Input& extension_value, | |
eroman
2015/09/10 17:48:28
When I was writing the SignatureAlgorithm class wh
mattm
2015/09/22 22:12:31
Done.
| |
71 bool is_critical) WARN_UNUSED_RESULT; | |
72 | |
73 // Tests if a certificate is allowed by the name constraints. | |
74 // |subject_rdn_sequence| should be the DER-encoded value of the subject's | |
75 // RDNSequence field (not including Sequence tag), and may be an empty ASN.1 | |
eroman
2015/09/10 17:48:28
nit: This reads a bit weird to me. In particular "
mattm
2015/09/22 22:12:31
I removed the "field"
| |
76 // sequence. |subject_alt_name_extnvalue_tlv| should be the extnValue of the | |
77 // subjectAltName extension (including the OCTET STRING tag & length), or | |
78 // empty if the cert did not have a subjectAltName extension. |is_leaf_cert| | |
79 // should be true if the certificate is the leaf of the certificate chain, in | |
80 // which case subject commonName hostname/ip checking is done. | |
81 bool IsPermittedCert(const der::Input& subject_rdn_sequence, | |
82 const der::Input& subject_alt_name_extnvalue_tlv, | |
83 bool is_leaf_cert) const; | |
84 | |
85 // Returns true if the ASCII hostname |name| is permitted. | |
86 // |name| may be a wildcard hostname (starts with "*."). Eg, "*.bar.com" | |
eroman
2015/09/10 17:48:28
Where does this wildcard behavior come from?
mattm
2015/09/22 22:12:31
(Should be addressed by the discussion in the .cc
| |
87 // would not be permitted if "bar.com" is permitted and "foo.bar.com" is | |
88 // excluded, while "*.baz.com" would only be permitted if "baz.com" is | |
89 // permitted. | |
90 bool IsPermittedDNSName(const std::string& name) const; | |
91 | |
92 // Returns true if the directoryName |name_rdn_sequence| is permitted. | |
93 // |name_rdn_sequence| should be the DER-encoded RDNSequence value (not | |
94 // including the Sequence tag.) | |
95 bool IsPermittedDirectoryName(const der::Input& name_rdn_sequence) const; | |
96 | |
97 // Returns true if the iPAddress |ip| is permitted. | |
98 bool IsPermittedIP(const IPAddressNumber& ip) const; | |
99 | |
100 // Returns a bitfield of GeneralNameTypes of all the types constrained by this | |
101 // NameConstraints. Name types that aren't supported will only be present if | |
102 // the name constraint they appeared in was marked critical. | |
103 // | |
104 // RFC 5280 section 4.2.1.10 says: | |
105 // Applications conforming to this profile MUST be able to process name | |
106 // constraints that are imposed on the directoryName name form and SHOULD be | |
107 // able to process name constraints that are imposed on the rfc822Name, | |
108 // uniformResourceIdentifier, dNSName, and iPAddress name forms. | |
109 // If a name constraints extension that is marked as critical | |
110 // imposes constraints on a particular name form, and an instance of | |
111 // that name form appears in the subject field or subjectAltName | |
112 // extension of a subsequent certificate, then the application MUST | |
113 // either process the constraint or reject the certificate. | |
114 int ConstrainedNameTypes() const; | |
115 | |
116 private: | |
117 GeneralNames permitted_subtrees_; | |
118 GeneralNames excluded_subtrees_; | |
119 }; | |
120 | |
121 } // namespace net | |
122 | |
123 #endif // NET_CERT_INTERNAL_NAME_CONSTRAINTS_H_ | |
OLD | NEW |