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/name_constraints.h" | 5 #include "net/cert/internal/name_constraints.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "net/cert/internal/verify_name_match.h" | 8 #include "net/cert/internal/verify_name_match.h" |
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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 // id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 17 } | 392 // id-ce-subjectAltName OBJECT IDENTIFIER ::= { id-ce 17 } |
393 // | 393 // |
394 // SubjectAltName ::= GeneralNames | 394 // SubjectAltName ::= GeneralNames |
395 // | 395 // |
396 // GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName | 396 // GeneralNames ::= SEQUENCE SIZE (1..MAX) OF GeneralName |
397 | 397 |
398 GeneralNames san_names; | 398 GeneralNames san_names; |
399 if (subject_alt_name_extnvalue_tlv.Length()) { | 399 if (subject_alt_name_extnvalue_tlv.Length()) { |
400 der::Parser extnvalue_parser(subject_alt_name_extnvalue_tlv); | 400 der::Parser extnvalue_parser(subject_alt_name_extnvalue_tlv); |
401 der::Input subject_alt_name_tlv; | 401 der::Input subject_alt_name_tlv; |
402 if (!extnvalue_parser.ReadTag(der::kOctetString, &subject_alt_name_tlv)) | 402 if (!extnvalue_parser.ReadTag(der::kOctetString, &subject_alt_name_tlv)) |
davidben
2016/01/05 19:34:44
[Existing, but this should also check extnvalue_pa
mattm
2016/01/05 20:40:25
yeah. Although, looking at parse_certificate.h and
| |
403 return false; | 403 return false; |
404 | 404 |
405 der::Parser subject_alt_name_parser(subject_alt_name_tlv); | 405 der::Parser subject_alt_name_parser(subject_alt_name_tlv); |
406 der::Parser san_sequence_parser; | 406 der::Parser san_sequence_parser; |
407 if (!subject_alt_name_parser.ReadSequence(&san_sequence_parser)) | 407 if (!subject_alt_name_parser.ReadSequence(&san_sequence_parser)) |
408 return false; | 408 return false; |
409 // Should not have trailing data after subjectAltName sequence. | 409 // Should not have trailing data after subjectAltName sequence. |
410 if (subject_alt_name_parser.HasMore()) | 410 if (subject_alt_name_parser.HasMore()) |
411 return false; | 411 return false; |
412 // The subjectAltName sequence should have at least 1 element. | 412 // The subjectAltName sequence should have at least 1 element. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 subject_rdn_sequence.Length() == 0) { | 489 subject_rdn_sequence.Length() == 0) { |
490 return true; | 490 return true; |
491 } | 491 } |
492 | 492 |
493 return IsPermittedDirectoryName(subject_rdn_sequence); | 493 return IsPermittedDirectoryName(subject_rdn_sequence); |
494 } | 494 } |
495 | 495 |
496 bool NameConstraints::IsPermittedDNSName(const std::string& name) const { | 496 bool NameConstraints::IsPermittedDNSName(const std::string& name) const { |
497 // If there are no name constraints for DNS names, all names are accepted. | 497 // If there are no name constraints for DNS names, all names are accepted. |
498 if (!(ConstrainedNameTypes() & GENERAL_NAME_DNS_NAME)) | 498 if (!(ConstrainedNameTypes() & GENERAL_NAME_DNS_NAME)) |
499 return true; | 499 return true; |
davidben
2016/01/05 19:34:44
I think this check no longer does anything, does i
mattm
2016/01/05 20:40:25
Yeah. Removed.
| |
500 | 500 |
501 for (const std::string& excluded_name : excluded_subtrees_.dns_names) { | 501 for (const std::string& excluded_name : excluded_subtrees_.dns_names) { |
502 // When matching wildcard hosts against excluded subtrees, consider it a | 502 // When matching wildcard hosts against excluded subtrees, consider it a |
503 // match if the constraint would match any expansion of the wildcard. Eg, | 503 // match if the constraint would match any expansion of the wildcard. Eg, |
504 // *.bar.com should match a constraint of foo.bar.com. | 504 // *.bar.com should match a constraint of foo.bar.com. |
505 if (DNSNameMatches(name, excluded_name, WILDCARD_PARTIAL_MATCH)) | 505 if (DNSNameMatches(name, excluded_name, WILDCARD_PARTIAL_MATCH)) |
506 return false; | 506 return false; |
507 } | 507 } |
508 | |
509 // If permitted subtrees are not constrained, any name that is not excluded is | |
510 // allowed. | |
511 if (!(permitted_subtrees_.present_name_types & GENERAL_NAME_DNS_NAME)) | |
512 return true; | |
513 | |
508 for (const std::string& permitted_name : permitted_subtrees_.dns_names) { | 514 for (const std::string& permitted_name : permitted_subtrees_.dns_names) { |
509 // When matching wildcard hosts against permitted subtrees, consider it a | 515 // When matching wildcard hosts against permitted subtrees, consider it a |
510 // match only if the constraint would match all expansions of the wildcard. | 516 // match only if the constraint would match all expansions of the wildcard. |
511 // Eg, *.bar.com should match a constraint of bar.com, but not foo.bar.com. | 517 // Eg, *.bar.com should match a constraint of bar.com, but not foo.bar.com. |
512 if (DNSNameMatches(name, permitted_name, WILDCARD_FULL_MATCH)) | 518 if (DNSNameMatches(name, permitted_name, WILDCARD_FULL_MATCH)) |
513 return true; | 519 return true; |
514 } | 520 } |
515 | 521 |
516 return false; | 522 return false; |
517 } | 523 } |
518 | 524 |
519 bool NameConstraints::IsPermittedDirectoryName( | 525 bool NameConstraints::IsPermittedDirectoryName( |
520 const der::Input& name_rdn_sequence) const { | 526 const der::Input& name_rdn_sequence) const { |
521 // If there are no name constraints for directory names, all names are | 527 // If there are no name constraints for directory names, all names are |
522 // accepted. | 528 // accepted. |
523 if (!(ConstrainedNameTypes() & GENERAL_NAME_DIRECTORY_NAME)) | 529 if (!(ConstrainedNameTypes() & GENERAL_NAME_DIRECTORY_NAME)) |
524 return true; | 530 return true; |
davidben
2016/01/05 19:34:44
Ditto.
mattm
2016/01/05 20:40:25
Done.
| |
525 | 531 |
526 for (const auto& excluded_name : excluded_subtrees_.directory_names) { | 532 for (const auto& excluded_name : excluded_subtrees_.directory_names) { |
527 if (VerifyNameInSubtree( | 533 if (VerifyNameInSubtree( |
528 name_rdn_sequence, | 534 name_rdn_sequence, |
529 der::Input(excluded_name.data(), excluded_name.size()))) { | 535 der::Input(excluded_name.data(), excluded_name.size()))) { |
530 return false; | 536 return false; |
531 } | 537 } |
532 } | 538 } |
539 | |
540 // If permitted subtrees are not constrained, any name that is not excluded is | |
541 // allowed. | |
542 if (!(permitted_subtrees_.present_name_types & GENERAL_NAME_DIRECTORY_NAME)) | |
543 return true; | |
544 | |
533 for (const auto& permitted_name : permitted_subtrees_.directory_names) { | 545 for (const auto& permitted_name : permitted_subtrees_.directory_names) { |
534 if (VerifyNameInSubtree( | 546 if (VerifyNameInSubtree( |
535 name_rdn_sequence, | 547 name_rdn_sequence, |
536 der::Input(permitted_name.data(), permitted_name.size()))) { | 548 der::Input(permitted_name.data(), permitted_name.size()))) { |
537 return true; | 549 return true; |
538 } | 550 } |
539 } | 551 } |
540 | 552 |
541 return false; | 553 return false; |
542 } | 554 } |
543 | 555 |
544 bool NameConstraints::IsPermittedIP(const IPAddressNumber& ip) const { | 556 bool NameConstraints::IsPermittedIP(const IPAddressNumber& ip) const { |
545 // If there are no name constraints for IP Address names, all names are | 557 // If there are no name constraints for IP Address names, all names are |
546 // accepted. | 558 // accepted. |
547 if (!(ConstrainedNameTypes() & GENERAL_NAME_IP_ADDRESS)) | 559 if (!(ConstrainedNameTypes() & GENERAL_NAME_IP_ADDRESS)) |
548 return true; | 560 return true; |
davidben
2016/01/05 19:34:44
Ditto.
mattm
2016/01/05 20:40:25
Done.
| |
549 | 561 |
550 for (const auto& excluded_ip : excluded_subtrees_.ip_address_ranges) { | 562 for (const auto& excluded_ip : excluded_subtrees_.ip_address_ranges) { |
551 if (IPNumberMatchesPrefix(ip, excluded_ip.first, excluded_ip.second)) | 563 if (IPNumberMatchesPrefix(ip, excluded_ip.first, excluded_ip.second)) |
552 return false; | 564 return false; |
553 } | 565 } |
566 | |
567 // If permitted subtrees are not constrained, any name that is not excluded is | |
568 // allowed. | |
569 if (!(permitted_subtrees_.present_name_types & GENERAL_NAME_IP_ADDRESS)) | |
570 return true; | |
571 | |
554 for (const auto& permitted_ip : permitted_subtrees_.ip_address_ranges) { | 572 for (const auto& permitted_ip : permitted_subtrees_.ip_address_ranges) { |
555 if (IPNumberMatchesPrefix(ip, permitted_ip.first, permitted_ip.second)) | 573 if (IPNumberMatchesPrefix(ip, permitted_ip.first, permitted_ip.second)) |
556 return true; | 574 return true; |
557 } | 575 } |
558 | 576 |
559 return false; | 577 return false; |
560 } | 578 } |
561 | 579 |
562 int NameConstraints::ConstrainedNameTypes() const { | 580 int NameConstraints::ConstrainedNameTypes() const { |
563 return (permitted_subtrees_.present_name_types | | 581 return (permitted_subtrees_.present_name_types | |
564 excluded_subtrees_.present_name_types); | 582 excluded_subtrees_.present_name_types); |
565 } | 583 } |
566 | 584 |
567 } // namespace net | 585 } // namespace net |
OLD | NEW |