| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/parsed_certificate.h" | 5 #include "net/cert/internal/parsed_certificate.h" |
| 6 | 6 |
| 7 #include "net/cert/internal/name_constraints.h" | 7 #include "net/cert/internal/name_constraints.h" |
| 8 #include "net/cert/internal/signature_algorithm.h" | 8 #include "net/cert/internal/signature_algorithm.h" |
| 9 #include "net/cert/internal/verify_name_match.h" | 9 #include "net/cert/internal/verify_name_match.h" |
| 10 #include "net/der/parser.h" | 10 #include "net/der/parser.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 WARN_UNUSED_RESULT bool GetSequenceValue(const der::Input& tlv, | 16 WARN_UNUSED_RESULT bool GetSequenceValue(const der::Input& tlv, |
| 17 der::Input* value) { | 17 der::Input* value) { |
| 18 der::Parser parser(tlv); | 18 der::Parser parser(tlv); |
| 19 return parser.ReadTag(der::kSequence, value) && !parser.HasMore(); | 19 return parser.ReadTag(der::kSequence, value) && !parser.HasMore(); |
| 20 } | 20 } |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 ParsedCertificate::ParsedCertificate() {} | 24 ParsedCertificate::ParsedCertificate() {} |
| 25 ParsedCertificate::~ParsedCertificate() {} | 25 ParsedCertificate::~ParsedCertificate() {} |
| 26 | 26 |
| 27 scoped_refptr<ParsedCertificate> ParsedCertificate::CreateFromCertificateData( | 27 scoped_refptr<ParsedCertificate> ParsedCertificate::Create( |
| 28 const uint8_t* data, |
| 29 size_t length, |
| 30 const ParseCertificateOptions& options, |
| 31 CertErrors* errors) { |
| 32 return CreateInternal(data, length, DataSource::INTERNAL_COPY, options, |
| 33 errors); |
| 34 } |
| 35 |
| 36 scoped_refptr<ParsedCertificate> ParsedCertificate::Create( |
| 37 const base::StringPiece& data, |
| 38 const ParseCertificateOptions& options, |
| 39 CertErrors* errors) { |
| 40 return ParsedCertificate::Create( |
| 41 reinterpret_cast<const uint8_t*>(data.data()), data.size(), options, |
| 42 errors); |
| 43 } |
| 44 |
| 45 bool ParsedCertificate::CreateAndAddToVector( |
| 46 const uint8_t* data, |
| 47 size_t length, |
| 48 const ParseCertificateOptions& options, |
| 49 ParsedCertificateList* chain, |
| 50 CertErrors* errors) { |
| 51 scoped_refptr<ParsedCertificate> cert(Create(data, length, options, errors)); |
| 52 if (!cert) |
| 53 return false; |
| 54 chain->push_back(std::move(cert)); |
| 55 return true; |
| 56 } |
| 57 |
| 58 bool ParsedCertificate::CreateAndAddToVector( |
| 59 const base::StringPiece& data, |
| 60 const ParseCertificateOptions& options, |
| 61 ParsedCertificateList* chain, |
| 62 CertErrors* errors) { |
| 63 return CreateAndAddToVector(reinterpret_cast<const uint8_t*>(data.data()), |
| 64 data.size(), options, chain, errors); |
| 65 } |
| 66 |
| 67 scoped_refptr<ParsedCertificate> ParsedCertificate::CreateWithoutCopyingUnsafe( |
| 68 const uint8_t* data, |
| 69 size_t length, |
| 70 const ParseCertificateOptions& options, |
| 71 CertErrors* errors) { |
| 72 return CreateInternal(data, length, DataSource::EXTERNAL_REFERENCE, options, |
| 73 errors); |
| 74 } |
| 75 |
| 76 scoped_refptr<ParsedCertificate> ParsedCertificate::CreateInternal( |
| 28 const uint8_t* data, | 77 const uint8_t* data, |
| 29 size_t length, | 78 size_t length, |
| 30 DataSource source, | 79 DataSource source, |
| 31 const ParseCertificateOptions& options) { | 80 const ParseCertificateOptions& options, |
| 81 CertErrors* errors) { |
| 32 scoped_refptr<ParsedCertificate> result(new ParsedCertificate); | 82 scoped_refptr<ParsedCertificate> result(new ParsedCertificate); |
| 33 | 83 |
| 34 switch (source) { | 84 switch (source) { |
| 35 case DataSource::INTERNAL_COPY: | 85 case DataSource::INTERNAL_COPY: |
| 36 result->cert_data_.assign(data, data + length); | 86 result->cert_data_.assign(data, data + length); |
| 37 result->cert_ = | 87 result->cert_ = |
| 38 der::Input(result->cert_data_.data(), result->cert_data_.size()); | 88 der::Input(result->cert_data_.data(), result->cert_data_.size()); |
| 39 break; | 89 break; |
| 40 case DataSource::EXTERNAL_REFERENCE: | 90 case DataSource::EXTERNAL_REFERENCE: |
| 41 result->cert_ = der::Input(data, length); | 91 result->cert_ = der::Input(data, length); |
| 42 break; | 92 break; |
| 43 } | 93 } |
| 44 | 94 |
| 45 if (!ParseCertificate(result->cert_, &result->tbs_certificate_tlv_, | 95 if (!ParseCertificate(result->cert_, &result->tbs_certificate_tlv_, |
| 46 &result->signature_algorithm_tlv_, | 96 &result->signature_algorithm_tlv_, |
| 47 &result->signature_value_)) { | 97 &result->signature_value_, errors)) { |
| 48 return nullptr; | 98 return nullptr; |
| 49 } | 99 } |
| 50 | 100 |
| 51 if (!ParseTbsCertificate(result->tbs_certificate_tlv_, options, | 101 if (!ParseTbsCertificate(result->tbs_certificate_tlv_, options, |
| 52 &result->tbs_)) { | 102 &result->tbs_)) { |
| 53 return nullptr; | 103 return nullptr; |
| 54 } | 104 } |
| 55 | 105 |
| 56 // Attempt to parse the signature algorithm contained in the Certificate. | 106 // Attempt to parse the signature algorithm contained in the Certificate. |
| 57 // Do not give up on failure here, since SignatureAlgorithm::CreateFromDer | 107 // Do not give up on failure here, since SignatureAlgorithm::CreateFromDer |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 192 |
| 143 // NOTE: if additional extensions are consumed here, the verification code | 193 // NOTE: if additional extensions are consumed here, the verification code |
| 144 // must be updated to process those extensions, since the | 194 // must be updated to process those extensions, since the |
| 145 // VerifyNoUnconsumedCriticalExtensions uses the unparsed_extensions_ | 195 // VerifyNoUnconsumedCriticalExtensions uses the unparsed_extensions_ |
| 146 // variable to tell which extensions were processed. | 196 // variable to tell which extensions were processed. |
| 147 } | 197 } |
| 148 | 198 |
| 149 return result; | 199 return result; |
| 150 } | 200 } |
| 151 | 201 |
| 152 scoped_refptr<ParsedCertificate> ParsedCertificate::CreateFromCertificateCopy( | |
| 153 const base::StringPiece& data, | |
| 154 const ParseCertificateOptions& options) { | |
| 155 return ParsedCertificate::CreateFromCertificateData( | |
| 156 reinterpret_cast<const uint8_t*>(data.data()), data.size(), | |
| 157 DataSource::INTERNAL_COPY, options); | |
| 158 } | |
| 159 | |
| 160 bool ParsedCertificate::CreateAndAddToVector( | |
| 161 const uint8_t* data, | |
| 162 size_t length, | |
| 163 DataSource source, | |
| 164 const ParseCertificateOptions& options, | |
| 165 ParsedCertificateList* chain) { | |
| 166 scoped_refptr<ParsedCertificate> cert( | |
| 167 CreateFromCertificateData(data, length, source, options)); | |
| 168 if (!cert) | |
| 169 return false; | |
| 170 chain->push_back(std::move(cert)); | |
| 171 return true; | |
| 172 } | |
| 173 | |
| 174 } // namespace net | 202 } // namespace net |
| OLD | NEW |