OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/cert/internal/parse_certificate.h" |
| 6 |
| 7 #include "net/der/input.h" |
| 8 #include "net/der/parse_values.h" |
| 9 #include "net/der/parser.h" |
| 10 |
| 11 namespace net { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // Returns true if |input| is a SEQUENCE and nothing else. |
| 16 WARN_UNUSED_RESULT bool IsSequenceTLV(const der::Input& input) { |
| 17 der::Parser parser(input); |
| 18 der::Parser unused_sequence_parser; |
| 19 if (!parser.ReadSequence(&unused_sequence_parser)) |
| 20 return false; |
| 21 // Should by a single SEQUENCE by definition of the function. |
| 22 return !parser.HasMore(); |
| 23 } |
| 24 |
| 25 // Reads a SEQUENCE from |parser| and writes the full tag-length-value into |
| 26 // |out|. On failure |parser| may or may not have been advanced. |
| 27 WARN_UNUSED_RESULT bool ReadSequenceTLV(der::Parser* parser, der::Input* out) { |
| 28 return parser->ReadRawTLV(out) && IsSequenceTLV(*out); |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
| 33 bool ParseCertificate(const der::Input& certificate_tlv, |
| 34 ParsedCertificate* out) { |
| 35 der::Parser parser(certificate_tlv); |
| 36 |
| 37 // Certificate ::= SEQUENCE { |
| 38 der::Parser certificate_parser; |
| 39 if (!parser.ReadSequence(&certificate_parser)) |
| 40 return false; |
| 41 |
| 42 // tbsCertificate TBSCertificate, |
| 43 if (!ReadSequenceTLV(&certificate_parser, &out->tbs_certificate_tlv)) |
| 44 return false; |
| 45 |
| 46 // signatureAlgorithm AlgorithmIdentifier, |
| 47 if (!ReadSequenceTLV(&certificate_parser, &out->signature_algorithm_tlv)) |
| 48 return false; |
| 49 |
| 50 // signatureValue BIT STRING } |
| 51 if (!certificate_parser.ReadBitString(&out->signature_value)) |
| 52 return false; |
| 53 |
| 54 // There isn't an extension point at the end of Certificate. |
| 55 if (certificate_parser.HasMore()) |
| 56 return false; |
| 57 |
| 58 // By definition the input was a single Certificate, so there shouldn't be |
| 59 // unconsumed data. |
| 60 if (parser.HasMore()) |
| 61 return false; |
| 62 |
| 63 return true; |
| 64 } |
| 65 |
| 66 } // namespace net |
OLD | NEW |