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

Unified Diff: net/cert/internal/parse_certificate.h

Issue 1279963003: Add a function for parsing RFC 5280's "TBSCertificate". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert_mapper
Patch Set: rebase onto master Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/cert/internal/parse_certificate.cc » ('j') | net/cert/internal/parse_certificate.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/internal/parse_certificate.h
diff --git a/net/cert/internal/parse_certificate.h b/net/cert/internal/parse_certificate.h
index d4968435826820e73b718d176e3ff3449a403744..cf8b431b69e6bf6d3c93f54a24ce06bd8b35c0cf 100644
--- a/net/cert/internal/parse_certificate.h
+++ b/net/cert/internal/parse_certificate.h
@@ -14,6 +14,7 @@
namespace net {
struct ParsedCertificate;
+struct ParsedTbsCertificate;
davidben 2015/08/14 17:51:42 [Whatever we end up doing for the other CL, do for
eroman 2015/08/14 21:26:13 Acknowledged.
// Parses a DER-encoded "Certificate" as specified by RFC 5280. Returns true on
// success and sets the results in |out|.
@@ -28,6 +29,39 @@ struct ParsedCertificate;
NET_EXPORT bool ParseCertificate(const der::Input& certificate_tlv,
ParsedCertificate* out) WARN_UNUSED_RESULT;
+// Parses a DER-encoded "TBSCertificate" as specified by RFC 5280. Returns true
+// on success and sets the results in |out|.
davidben 2015/08/14 17:51:42 Add: The resulting ParsedTbsCertificate is valid a
eroman 2015/08/14 21:26:12 Done.
+//
+// Refer to the per-field documentation of ParsedTbsCertificate for details on
+// what validity checks parsing performs.
+//
+// TBSCertificate ::= SEQUENCE {
+// version [0] EXPLICIT Version DEFAULT v1,
+// serialNumber CertificateSerialNumber,
+// signature AlgorithmIdentifier,
+// issuer Name,
+// validity Validity,
+// subject Name,
+// subjectPublicKeyInfo SubjectPublicKeyInfo,
+// issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL,
+// -- If present, version MUST be v2 or v3
+// subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL,
+// -- If present, version MUST be v2 or v3
+// extensions [3] EXPLICIT Extensions OPTIONAL
+// -- If present, version MUST be v3
+// }
+NET_EXPORT bool ParseTbsCertificate(const der::Input& tbs_tlv,
+ ParsedTbsCertificate* out)
+ WARN_UNUSED_RESULT;
+
+// Represents a "Version" from RFC 5280:
+// Version ::= INTEGER { v1(0), v2(1), v3(2) }
+enum class CertificateVersion {
+ V1,
+ V2,
+ V3,
+};
+
// ParsedCertificate contains pointers to the main fields of a DER-encoded RFC
// 5280 "Certificate".
//
@@ -39,6 +73,8 @@ struct NET_EXPORT ParsedCertificate {
//
// This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
// guarantees are made regarding the value of this SEQUENCE.
+ //
+ // This can be further parsed using ParseTbsCertificate().
der::Input tbs_certificate_tlv;
// Corresponds with "signatureAlgorithm" from RFC 5280:
@@ -57,6 +93,103 @@ struct NET_EXPORT ParsedCertificate {
der::BitString signature_value;
};
+// ParsedTbsCertificate contains pointers to the main fields of a DER-encoded
+// RFC 5280 "TBSCertificate".
+//
+// ParsedTbsCertificate is expected to be filled by ParseTbsCertificate(), so
+// subsequent field descriptions are in terms of what ParseTbsCertificate()
+// sets.
+struct NET_EXPORT ParsedTbsCertificate {
+ ParsedTbsCertificate();
+ ~ParsedTbsCertificate();
+
+ // Corresponds with "version" from RFC 5280:
+ // version [0] EXPLICIT Version DEFAULT v1,
+ //
+ // Parsing guarantees that the version is one of v1, v2, or v3.
+ CertificateVersion version;
+
+ // Corresponds with "serialNumber" from RFC 5280:
+ // serialNumber CertificateSerialNumber,
+ //
+ // This field specifically contains the content bytes of the INTEGER. So for
+ // instance if the serial number was 1000 then this would contain bytes
+ // {0x03, 0xE8}.
+ //
+ // In addition to being a valid DER-encoded INTEGER, parsing guarantees that
+ // the serial number is at most 20 bytes long. Parsing does NOT guarantee
+ // that the integer is positive (might be zero or negative).
+ der::Input serial_number;
+
+ // Corresponds with "signatureAlgorithm" from RFC 5280:
+ // signatureAlgorithm AlgorithmIdentifier,
+ //
+ // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
+ // guarantees are made regarding the value of this SEQUENCE.
+ //
+ // This can be further parsed using SignatureValue::CreateFromDer().
+ der::Input signature_algorithm_tlv;
+
+ // Corresponds with "issuer" from RFC 5280:
+ // issuer Name,
+ //
+ // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
+ // guarantees are made regarding the value of this SEQUENCE.
+ der::Input issuer_tlv;
+
+ // Corresponds with "validity" from RFC 5280:
+ // validity Validity,
+ //
+ // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
+ // guarantees are made regarding the value of this SEQUENCE.
+ der::Input validity_tlv;
+
+ // Corresponds with "subject" from RFC 5280:
+ // subject Name,
+ //
+ // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
+ // guarantees are made regarding the value of this SEQUENCE.
+ der::Input subject_tlv;
+
+ // Corresponds with "subjectPublicKeyInfo" from RFC 5280:
+ // subjectPublicKeyInfo SubjectPublicKeyInfo,
+ //
+ // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
+ // guarantees are made regarding the value of this SEQUENCE.
+ der::Input spki_tlv;
+
+ // Corresponds with "issuerUniqueID" from RFC 5280:
+ // issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL,
+ // -- If present, version MUST be v2 or v3
+ //
+ // Parsing guarantees that if issuer_unique_id is present it is a valid BIT
+ // STRING, and that the version is either v2 or v3
+ bool has_issuer_unique_id;
+ der::BitString issuer_unique_id;
+
+ // Corresponds with "subjectUniqueID" from RFC 5280:
+ // subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL,
+ // -- If present, version MUST be v2 or v3
+ //
+ // Parsing guarantees that if subject_unique_id is present it is a valid BIT
+ // STRING, and that the version is either v2 or v3
+ bool has_subject_unique_id;
+ der::BitString subject_unique_id;
+
+ // Corresponds with "extensions" from RFC 5280:
+ // extensions [3] EXPLICIT Extensions OPTIONAL
+ // -- If present, version MUST be v3
+ //
+ //
+ // This contains the full (unverified) Tag-Length-Value for a SEQUENCE. No
+ // guarantees are made regarding the value of this SEQUENCE. (Note that the
+ // EXPLICIT outter tag was stripped).
davidben 2015/08/14 17:51:42 outter -> outer was -> is? ). -> .) (I was always
eroman 2015/08/14 21:26:13 Done.
+ //
+ // Parsing guarantees that if extensions is present the version is v3.
+ bool has_extensions;
+ der::Input extensions_tlv;
+};
+
} // namespace net
#endif // NET_CERT_INTERNAL_PARSE_CERTIFICATE_H_
« no previous file with comments | « no previous file | net/cert/internal/parse_certificate.cc » ('j') | net/cert/internal/parse_certificate.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698