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

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

Issue 1383873002: Add a function for parsing an RFC 5280 Extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix U-A-F in tests Created 5 years, 1 month 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
« no previous file with comments | « net/cert/internal/parse_certificate.h ('k') | net/cert/internal/parse_certificate_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 return false; 346 return false;
347 347
348 // By definition the input was a single TBSCertificate, so there shouldn't be 348 // By definition the input was a single TBSCertificate, so there shouldn't be
349 // unconsumed data. 349 // unconsumed data.
350 if (parser.HasMore()) 350 if (parser.HasMore())
351 return false; 351 return false;
352 352
353 return true; 353 return true;
354 } 354 }
355 355
356 // From RFC 5280:
357 //
358 // Extension ::= SEQUENCE {
359 // extnID OBJECT IDENTIFIER,
360 // critical BOOLEAN DEFAULT FALSE,
361 // extnValue OCTET STRING
362 // -- contains the DER encoding of an ASN.1 value
363 // -- corresponding to the extension type identified
364 // -- by extnID
365 // }
366 bool ParseExtension(const der::Input& extension_tlv, ParsedExtension* out) {
367 der::Parser parser(extension_tlv);
368
369 // Extension ::= SEQUENCE {
370 der::Parser extension_parser;
371 if (!parser.ReadSequence(&extension_parser))
372 return false;
373
374 // extnID OBJECT IDENTIFIER,
375 if (!extension_parser.ReadTag(der::kOid, &out->oid))
376 return false;
377
378 // critical BOOLEAN DEFAULT FALSE,
379 out->critical = false;
380 bool has_critical;
381 der::Input critical;
382 if (!extension_parser.ReadOptionalTag(der::kBool, &critical, &has_critical))
383 return false;
384 if (has_critical) {
385 if (!der::ParseBool(critical, &out->critical))
386 return false;
387 if (!out->critical)
388 return false; // DER-encoding requires DEFAULT values be omitted.
389 }
390
391 // extnValue OCTET STRING
392 if (!extension_parser.ReadTag(der::kOctetString, &out->value))
393 return false;
394
395 // The Extension type does not have an extension point (everything goes in
396 // extnValue).
397 if (extension_parser.HasMore())
398 return false;
399
400 // By definition the input was a single Extension sequence, so there shouldn't
401 // be unconsumed data.
402 if (parser.HasMore())
403 return false;
404
405 return true;
406 }
407
356 } // namespace net 408 } // namespace net
OLDNEW
« no previous file with comments | « net/cert/internal/parse_certificate.h ('k') | net/cert/internal/parse_certificate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698