Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: net/cert/internal/parse_certificate.cc

Issue 2872113002: Add parsing code for RFC 5280 PolicyConstraints. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/parse_certificate.h" 5 #include "net/cert/internal/parse_certificate.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "net/cert/internal/cert_errors.h" 10 #include "net/cert/internal/cert_errors.h"
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 // the broken encoding. 631 // the broken encoding.
632 } 632 }
633 633
634 // pathLenConstraint INTEGER (0..MAX) OPTIONAL } 634 // pathLenConstraint INTEGER (0..MAX) OPTIONAL }
635 der::Input encoded_path_len; 635 der::Input encoded_path_len;
636 if (!sequence_parser.ReadOptionalTag(der::kInteger, &encoded_path_len, 636 if (!sequence_parser.ReadOptionalTag(der::kInteger, &encoded_path_len,
637 &out->has_path_len)) { 637 &out->has_path_len)) {
638 return false; 638 return false;
639 } 639 }
640 if (out->has_path_len) { 640 if (out->has_path_len) {
641 // TODO(eroman): Surface reason for failure if length was longer than uint8.
641 if (!der::ParseUint8(encoded_path_len, &out->path_len)) 642 if (!der::ParseUint8(encoded_path_len, &out->path_len))
642 return false; 643 return false;
643 } else { 644 } else {
644 // Default initialize to 0 as a precaution. 645 // Default initialize to 0 as a precaution.
645 out->path_len = 0; 646 out->path_len = 0;
646 } 647 }
647 648
648 // There shouldn't be any unconsumed data in the extension. 649 // There shouldn't be any unconsumed data in the extension.
649 if (sequence_parser.HasMore()) 650 if (sequence_parser.HasMore())
650 return false; 651 return false;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 if (access_method_oid == AdCaIssuersOid()) 723 if (access_method_oid == AdCaIssuersOid())
723 out_ca_issuers_uris->push_back(uri); 724 out_ca_issuers_uris->push_back(uri);
724 else if (access_method_oid == AdOcspOid()) 725 else if (access_method_oid == AdOcspOid())
725 out_ocsp_uris->push_back(uri); 726 out_ocsp_uris->push_back(uri);
726 } 727 }
727 } 728 }
728 729
729 return true; 730 return true;
730 } 731 }
731 732
733 // From RFC 5280:
734 //
735 // PolicyConstraints ::= SEQUENCE {
736 // requireExplicitPolicy [0] SkipCerts OPTIONAL,
737 // inhibitPolicyMapping [1] SkipCerts OPTIONAL }
738 //
739 // SkipCerts ::= INTEGER (0..MAX)
740 bool ParsePolicyConstraints(const der::Input& policy_constraints_tlv,
741 ParsedPolicyConstraints* out) {
742 der::Parser parser(policy_constraints_tlv);
743
744 // PolicyConstraints ::= SEQUENCE {
745 der::Parser sequence_parser;
746 if (!parser.ReadSequence(&sequence_parser))
747 return false;
748
749 // RFC 5280 prohibits CAs from issuing PolicyConstraints as an empty sequence:
750 //
751 // Conforming CAs MUST NOT issue certificates where policy constraints
752 // is an empty sequence. That is, either the inhibitPolicyMapping field
753 // or the requireExplicitPolicy field MUST be present. The behavior of
754 // clients that encounter an empty policy constraints field is not
755 // addressed in this profile.
756 if (!sequence_parser.HasMore())
757 return false;
758
759 der::Input value;
760 if (!sequence_parser.ReadOptionalTag(der::ContextSpecificPrimitive(0), &value,
761 &out->has_require_explicit_policy)) {
762 return false;
763 }
764
765 if (out->has_require_explicit_policy) {
766 if (!ParseUint8(value, &out->require_explicit_policy)) {
767 // TODO(eroman): Surface reason for failure if length was longer than
768 // uint8.
769 return false;
770 }
771 } else {
772 out->require_explicit_policy = 0;
773 }
774
775 if (!sequence_parser.ReadOptionalTag(der::ContextSpecificPrimitive(1), &value,
776 &out->has_inhibit_policy_mapping)) {
777 return false;
778 }
779
780 if (out->has_inhibit_policy_mapping) {
781 if (!ParseUint8(value, &out->inhibit_policy_mapping)) {
782 // TODO(eroman): Surface reason for failure if length was longer than
783 // uint8.
784 return false;
785 }
786 } else {
787 out->inhibit_policy_mapping = 0;
788 }
789
790 // There should be no remaining data.
791 if (sequence_parser.HasMore() || parser.HasMore())
792 return false;
793
794 return true;
795 }
796
732 } // namespace net 797 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698