| 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/parser.h" | 10 #include "net/der/parser.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 if (!policy_qualifiers_sequence_parser->ReadSequence( | 49 if (!policy_qualifiers_sequence_parser->ReadSequence( |
| 50 &policy_information_parser)) { | 50 &policy_information_parser)) { |
| 51 return false; | 51 return false; |
| 52 } | 52 } |
| 53 der::Input qualifier_oid; | 53 der::Input qualifier_oid; |
| 54 if (!policy_information_parser.ReadTag(der::kOid, &qualifier_oid)) | 54 if (!policy_information_parser.ReadTag(der::kOid, &qualifier_oid)) |
| 55 return false; | 55 return false; |
| 56 // RFC 5280 section 4.2.1.4: When qualifiers are used with the special | 56 // RFC 5280 section 4.2.1.4: When qualifiers are used with the special |
| 57 // policy anyPolicy, they MUST be limited to the qualifiers identified in | 57 // policy anyPolicy, they MUST be limited to the qualifiers identified in |
| 58 // this section. | 58 // this section. |
| 59 if (policy_oid.Equals(AnyPolicy()) && | 59 if (policy_oid == AnyPolicy() && qualifier_oid != CpsPointerId() && |
| 60 !qualifier_oid.Equals(CpsPointerId()) && | 60 qualifier_oid != UserNoticeId()) { |
| 61 !qualifier_oid.Equals(UserNoticeId())) { | |
| 62 return false; | 61 return false; |
| 63 } | 62 } |
| 64 der::Tag tag; | 63 der::Tag tag; |
| 65 der::Input value; | 64 der::Input value; |
| 66 if (!policy_information_parser.ReadTagAndValue(&tag, &value)) | 65 if (!policy_information_parser.ReadTagAndValue(&tag, &value)) |
| 67 return false; | 66 return false; |
| 68 // Should not have trailing data after qualifier. | 67 // Should not have trailing data after qualifier. |
| 69 if (policy_information_parser.HasMore()) | 68 if (policy_information_parser.HasMore()) |
| 70 return false; | 69 return false; |
| 71 } | 70 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 if (!policy_information_parser.ReadTag(der::kOid, &policy_oid)) | 144 if (!policy_information_parser.ReadTag(der::kOid, &policy_oid)) |
| 146 return false; | 145 return false; |
| 147 | 146 |
| 148 // Build the |policies| vector in sorted order (sorted on DER encoded policy | 147 // Build the |policies| vector in sorted order (sorted on DER encoded policy |
| 149 // OID). Use a binary search to check whether a duplicate policy is present, | 148 // OID). Use a binary search to check whether a duplicate policy is present, |
| 150 // and if not, where to insert the policy to maintain the sorted order. | 149 // and if not, where to insert the policy to maintain the sorted order. |
| 151 std::vector<der::Input>::iterator i = | 150 std::vector<der::Input>::iterator i = |
| 152 std::lower_bound(policies->begin(), policies->end(), policy_oid); | 151 std::lower_bound(policies->begin(), policies->end(), policy_oid); |
| 153 // RFC 5280 section 4.2.1.4: A certificate policy OID MUST NOT appear more | 152 // RFC 5280 section 4.2.1.4: A certificate policy OID MUST NOT appear more |
| 154 // than once in a certificate policies extension. | 153 // than once in a certificate policies extension. |
| 155 if (i != policies->end() && i->Equals(policy_oid)) | 154 if (i != policies->end() && *i == policy_oid) |
| 156 return false; | 155 return false; |
| 157 | 156 |
| 158 policies->insert(i, policy_oid); | 157 policies->insert(i, policy_oid); |
| 159 | 158 |
| 160 if (!policy_information_parser.HasMore()) | 159 if (!policy_information_parser.HasMore()) |
| 161 continue; | 160 continue; |
| 162 | 161 |
| 163 der::Parser policy_qualifiers_sequence_parser; | 162 der::Parser policy_qualifiers_sequence_parser; |
| 164 if (!policy_information_parser.ReadSequence( | 163 if (!policy_information_parser.ReadSequence( |
| 165 &policy_qualifiers_sequence_parser)) { | 164 &policy_qualifiers_sequence_parser)) { |
| 166 return false; | 165 return false; |
| 167 } | 166 } |
| 168 // Should not have trailing data after policyQualifiers sequence. | 167 // Should not have trailing data after policyQualifiers sequence. |
| 169 if (policy_information_parser.HasMore()) | 168 if (policy_information_parser.HasMore()) |
| 170 return false; | 169 return false; |
| 171 if (!ParsePolicyQualifiers(policy_oid, &policy_qualifiers_sequence_parser)) | 170 if (!ParsePolicyQualifiers(policy_oid, &policy_qualifiers_sequence_parser)) |
| 172 return false; | 171 return false; |
| 173 } | 172 } |
| 174 | 173 |
| 175 return true; | 174 return true; |
| 176 } | 175 } |
| 177 | 176 |
| 178 } // namespace net | 177 } // namespace net |
| OLD | NEW |