Chromium Code Reviews| 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/parse_certificate.h" | 5 #include "net/cert/internal/parse_certificate.h" |
| 6 | 6 |
| 7 #include "net/der/input.h" | 7 #include "net/der/input.h" |
| 8 #include "net/der/parse_values.h" | 8 #include "net/der/parse_values.h" |
| 9 #include "net/der/parser.h" | 9 #include "net/der/parser.h" |
| 10 | 10 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 if (!reader.ReadByte(&second_byte)) | 117 if (!reader.ReadByte(&second_byte)) |
| 118 return false; // Unexpected | 118 return false; // Unexpected |
| 119 | 119 |
| 120 if ((second_byte & 0x80) == 0) | 120 if ((second_byte & 0x80) == 0) |
| 121 return false; // MSB must be 1. | 121 return false; // MSB must be 1. |
| 122 } | 122 } |
| 123 | 123 |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Consumes a "Time" value (as defined by RFC 5280) from |parser|. On success | |
| 128 // writes the result to |*out| and returns true. On failure no guarantees are | |
| 129 // made about the state of |parser|. | |
| 130 // | |
| 131 // From RFC 5280: | |
| 132 // | |
| 133 // Time ::= CHOICE { | |
| 134 // utcTime UTCTime, | |
| 135 // generalTime GeneralizedTime } | |
| 136 WARN_UNUSED_RESULT bool ReadTime(der::Parser* parser, | |
| 137 der::GeneralizedTime* out) { | |
| 138 der::Input value; | |
| 139 der::Tag tag; | |
| 140 | |
| 141 if (!parser->ReadTagAndValue(&tag, &value)) | |
| 142 return false; | |
| 143 | |
| 144 // TODO(eroman): Justify using the "relaxed" flavor rather | |
| 145 // than strict. The CT database of certificates do not | |
| 146 // require the relaxed parsing, however certificates in the | |
| 147 // wild may. | |
|
davidben
2015/08/18 17:24:27
Nit: This probably can be word-wrapped more loosel
davidben
2015/08/18 17:24:27
[If we don't have example certs, where did this be
eroman
2015/08/18 17:34:51
I am not sure, I will ask Nick about the history.
| |
| 148 if (tag == der::kUtcTime) | |
| 149 return der::ParseUTCTimeRelaxed(value, out); | |
| 150 | |
| 151 if (tag == der::kGeneralizedTime) | |
| 152 return der::ParseGeneralizedTime(value, out); | |
| 153 | |
| 154 // Unrecognized tag. | |
| 155 return false; | |
| 156 } | |
| 157 | |
| 127 } // namespace | 158 } // namespace |
| 128 | 159 |
| 129 ParsedTbsCertificate::ParsedTbsCertificate() | 160 ParsedTbsCertificate::ParsedTbsCertificate() |
| 130 : version(CertificateVersion::V1), | 161 : version(CertificateVersion::V1), |
| 131 has_issuer_unique_id(false), | 162 has_issuer_unique_id(false), |
| 132 has_subject_unique_id(false), | 163 has_subject_unique_id(false), |
| 133 has_extensions(false) {} | 164 has_extensions(false) {} |
| 134 | 165 |
| 135 ParsedTbsCertificate::~ParsedTbsCertificate() {} | 166 ParsedTbsCertificate::~ParsedTbsCertificate() {} |
| 136 | 167 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 return false; | 328 return false; |
| 298 | 329 |
| 299 // By definition the input was a single TBSCertificate, so there shouldn't be | 330 // By definition the input was a single TBSCertificate, so there shouldn't be |
| 300 // unconsumed data. | 331 // unconsumed data. |
| 301 if (parser.HasMore()) | 332 if (parser.HasMore()) |
| 302 return false; | 333 return false; |
| 303 | 334 |
| 304 return true; | 335 return true; |
| 305 } | 336 } |
| 306 | 337 |
| 338 // From RFC 5280: | |
| 339 // | |
| 340 // Validity ::= SEQUENCE { | |
| 341 // notBefore Time, | |
| 342 // notAfter Time } | |
| 343 bool ParseValidity(const der::Input& validity_tlv, | |
| 344 der::GeneralizedTime* not_before, | |
| 345 der::GeneralizedTime* not_after) { | |
| 346 der::Parser parser(validity_tlv); | |
| 347 | |
| 348 // Validity ::= SEQUENCE { | |
| 349 der::Parser validity_parser; | |
| 350 if (!parser.ReadSequence(&validity_parser)) | |
| 351 return false; | |
| 352 | |
| 353 // notBefore Time, | |
| 354 if (!ReadTime(&validity_parser, not_before)) | |
| 355 return false; | |
| 356 | |
| 357 // notAfter Time } | |
| 358 if (!ReadTime(&validity_parser, not_after)) | |
| 359 return false; | |
| 360 | |
| 361 // By definition the input was a single Validity sequence, so there shouldn't | |
| 362 // be unconsumed data. | |
| 363 if (parser.HasMore()) | |
| 364 return false; | |
| 365 | |
| 366 // The Validity type does not have an extension point. | |
| 367 if (validity_parser.HasMore()) | |
| 368 return false; | |
| 369 | |
| 370 // Note that RFC 5280 doesn't require notBefore to be <= | |
| 371 // notAfter, so that will not be considered a "parsing" error here. Instead it | |
| 372 // will be considered an expired certificate later when testing against the | |
| 373 // current timestamp. | |
| 374 return true; | |
| 375 } | |
| 376 | |
| 307 } // namespace net | 377 } // namespace net |
| OLD | NEW |