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 "net/cert/internal/verify_name_match.h" | 5 #include "net/cert/internal/verify_name_match.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 std::string a_normalized, b_normalized; | 282 std::string a_normalized, b_normalized; |
283 if (!NormalizeValue(a_tag, a_value, &a_normalized) || | 283 if (!NormalizeValue(a_tag, a_value, &a_normalized) || |
284 !NormalizeValue(b_tag, b_value, &b_normalized)) | 284 !NormalizeValue(b_tag, b_value, &b_normalized)) |
285 return false; | 285 return false; |
286 return a_normalized == b_normalized; | 286 return a_normalized == b_normalized; |
287 } | 287 } |
288 // Attributes encoded with different types may be assumed to be unequal. | 288 // Attributes encoded with different types may be assumed to be unequal. |
289 if (a_tag != b_tag) | 289 if (a_tag != b_tag) |
290 return false; | 290 return false; |
291 // All other types use binary comparison. | 291 // All other types use binary comparison. |
292 return a_value.Equals(b_value); | 292 return a_value == b_value; |
293 } | 293 } |
294 | 294 |
295 struct AttributeTypeAndValue { | 295 struct AttributeTypeAndValue { |
296 AttributeTypeAndValue(der::Input in_type, | 296 AttributeTypeAndValue(der::Input in_type, |
297 der::Tag in_value_tag, | 297 der::Tag in_value_tag, |
298 der::Input in_value) | 298 der::Input in_value) |
299 : type(in_type), value_tag(in_value_tag), value(in_value) {} | 299 : type(in_type), value_tag(in_value_tag), value(in_value) {} |
300 der::Input type; | 300 der::Input type; |
301 der::Tag value_tag; | 301 der::Tag value_tag; |
302 der::Input value; | 302 der::Input value; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 374 |
375 // The ordering of elements may differ due to denormalized values sorting | 375 // The ordering of elements may differ due to denormalized values sorting |
376 // differently in the DER encoding. Since the number of elements should be | 376 // differently in the DER encoding. Since the number of elements should be |
377 // small, a naive linear search for each element should be fine. (Hostile | 377 // small, a naive linear search for each element should be fine. (Hostile |
378 // certificates already have ways to provoke pathological behavior.) | 378 // certificates already have ways to provoke pathological behavior.) |
379 for (const auto& a : a_type_and_values) { | 379 for (const auto& a : a_type_and_values) { |
380 std::vector<AttributeTypeAndValue>::iterator b_iter = | 380 std::vector<AttributeTypeAndValue>::iterator b_iter = |
381 b_type_and_values.begin(); | 381 b_type_and_values.begin(); |
382 for (; b_iter != b_type_and_values.end(); ++b_iter) { | 382 for (; b_iter != b_type_and_values.end(); ++b_iter) { |
383 const auto& b = *b_iter; | 383 const auto& b = *b_iter; |
384 if (a.type.Equals(b.type) && | 384 if (a.type == b.type && |
385 VerifyValueMatch(a.value_tag, a.value, b.value_tag, b.value)) { | 385 VerifyValueMatch(a.value_tag, a.value, b.value_tag, b.value)) { |
386 break; | 386 break; |
387 } | 387 } |
388 } | 388 } |
389 if (b_iter == b_type_and_values.end()) | 389 if (b_iter == b_type_and_values.end()) |
390 return false; | 390 return false; |
391 // Remove the matched element from b_type_and_values to ensure duplicate | 391 // Remove the matched element from b_type_and_values to ensure duplicate |
392 // elements in a_type_and_values can't match the same element in | 392 // elements in a_type_and_values can't match the same element in |
393 // b_type_and_values multiple times. | 393 // b_type_and_values multiple times. |
394 b_type_and_values.erase(b_iter); | 394 b_type_and_values.erase(b_iter); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 while (rdn_sequence_parser.HasMore()) { | 485 while (rdn_sequence_parser.HasMore()) { |
486 der::Parser rdn_parser; | 486 der::Parser rdn_parser; |
487 if (!rdn_sequence_parser.ReadConstructed(der::kSet, &rdn_parser)) | 487 if (!rdn_sequence_parser.ReadConstructed(der::kSet, &rdn_parser)) |
488 return false; | 488 return false; |
489 | 489 |
490 std::vector<AttributeTypeAndValue> type_and_values; | 490 std::vector<AttributeTypeAndValue> type_and_values; |
491 if (!ReadRdn(&rdn_parser, &type_and_values)) | 491 if (!ReadRdn(&rdn_parser, &type_and_values)) |
492 return false; | 492 return false; |
493 | 493 |
494 for (const auto& type_and_value : type_and_values) { | 494 for (const auto& type_and_value : type_and_values) { |
495 if (type_and_value.type.Equals(der::Input(kOidEmailAddress))) { | 495 if (type_and_value.type == der::Input(kOidEmailAddress)) { |
496 *contained_email_address = true; | 496 *contained_email_address = true; |
497 return true; | 497 return true; |
498 } | 498 } |
499 } | 499 } |
500 } | 500 } |
501 | 501 |
502 *contained_email_address = false; | 502 *contained_email_address = false; |
503 return true; | 503 return true; |
504 } | 504 } |
505 | 505 |
506 } // namespace net | 506 } // namespace net |
OLD | NEW |