| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "net/cert/internal/certificate_policies.h" | 7 #include "net/cert/internal/certificate_policies.h" |
| 8 | 8 |
| 9 #include "net/der/input.h" | 9 #include "net/der/input.h" |
| 10 #include "net/der/parse_values.h" |
| 10 #include "net/der/parser.h" | 11 #include "net/der/parser.h" |
| 11 #include "net/der/tag.h" | 12 #include "net/der/tag.h" |
| 12 | 13 |
| 13 namespace net { | 14 namespace net { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 // -- policyQualifierIds for Internet policy qualifiers | 18 // -- policyQualifierIds for Internet policy qualifiers |
| 18 // | 19 // |
| 19 // id-qt OBJECT IDENTIFIER ::= { id-pkix 2 } | 20 // id-qt OBJECT IDENTIFIER ::= { id-pkix 2 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // Should not have trailing data after policyQualifiers sequence. | 168 // Should not have trailing data after policyQualifiers sequence. |
| 168 if (policy_information_parser.HasMore()) | 169 if (policy_information_parser.HasMore()) |
| 169 return false; | 170 return false; |
| 170 if (!ParsePolicyQualifiers(policy_oid, &policy_qualifiers_sequence_parser)) | 171 if (!ParsePolicyQualifiers(policy_oid, &policy_qualifiers_sequence_parser)) |
| 171 return false; | 172 return false; |
| 172 } | 173 } |
| 173 | 174 |
| 174 return true; | 175 return true; |
| 175 } | 176 } |
| 176 | 177 |
| 178 // From RFC 5280: |
| 179 // |
| 180 // PolicyConstraints ::= SEQUENCE { |
| 181 // requireExplicitPolicy [0] SkipCerts OPTIONAL, |
| 182 // inhibitPolicyMapping [1] SkipCerts OPTIONAL } |
| 183 // |
| 184 // SkipCerts ::= INTEGER (0..MAX) |
| 185 bool ParsePolicyConstraints(const der::Input& policy_constraints_tlv, |
| 186 ParsedPolicyConstraints* out) { |
| 187 der::Parser parser(policy_constraints_tlv); |
| 188 |
| 189 // PolicyConstraints ::= SEQUENCE { |
| 190 der::Parser sequence_parser; |
| 191 if (!parser.ReadSequence(&sequence_parser)) |
| 192 return false; |
| 193 |
| 194 // RFC 5280 prohibits CAs from issuing PolicyConstraints as an empty sequence: |
| 195 // |
| 196 // Conforming CAs MUST NOT issue certificates where policy constraints |
| 197 // is an empty sequence. That is, either the inhibitPolicyMapping field |
| 198 // or the requireExplicitPolicy field MUST be present. The behavior of |
| 199 // clients that encounter an empty policy constraints field is not |
| 200 // addressed in this profile. |
| 201 if (!sequence_parser.HasMore()) |
| 202 return false; |
| 203 |
| 204 der::Input value; |
| 205 if (!sequence_parser.ReadOptionalTag(der::ContextSpecificPrimitive(0), &value, |
| 206 &out->has_require_explicit_policy)) { |
| 207 return false; |
| 208 } |
| 209 |
| 210 if (out->has_require_explicit_policy) { |
| 211 if (!ParseUint8(value, &out->require_explicit_policy)) { |
| 212 // TODO(eroman): Surface reason for failure if length was longer than |
| 213 // uint8. |
| 214 return false; |
| 215 } |
| 216 } else { |
| 217 out->require_explicit_policy = 0; |
| 218 } |
| 219 |
| 220 if (!sequence_parser.ReadOptionalTag(der::ContextSpecificPrimitive(1), &value, |
| 221 &out->has_inhibit_policy_mapping)) { |
| 222 return false; |
| 223 } |
| 224 |
| 225 if (out->has_inhibit_policy_mapping) { |
| 226 if (!ParseUint8(value, &out->inhibit_policy_mapping)) { |
| 227 // TODO(eroman): Surface reason for failure if length was longer than |
| 228 // uint8. |
| 229 return false; |
| 230 } |
| 231 } else { |
| 232 out->inhibit_policy_mapping = 0; |
| 233 } |
| 234 |
| 235 // There should be no remaining data. |
| 236 if (sequence_parser.HasMore() || parser.HasMore()) |
| 237 return false; |
| 238 |
| 239 return true; |
| 240 } |
| 241 |
| 177 } // namespace net | 242 } // namespace net |
| OLD | NEW |