asn1_util.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (c) 2012 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. #ifndef NET_CERT_ASN1_UTIL_H_
  5. #define NET_CERT_ASN1_UTIL_H_
  6. #include "base/strings/string_piece.h"
  7. #include "net/base/net_export.h"
  8. namespace net::asn1 {
  9. // ExtractSubjectFromDERCert parses the DER encoded certificate in |cert| and
  10. // extracts the bytes of the X.501 Subject. On successful return, |subject_out|
  11. // is set to contain the Subject, pointing into |cert|.
  12. NET_EXPORT_PRIVATE bool ExtractSubjectFromDERCert(
  13. base::StringPiece cert,
  14. base::StringPiece* subject_out);
  15. // ExtractSPKIFromDERCert parses the DER encoded certificate in |cert| and
  16. // extracts the bytes of the SubjectPublicKeyInfo. On successful return,
  17. // |spki_out| is set to contain the SPKI, pointing into |cert|.
  18. NET_EXPORT_PRIVATE bool ExtractSPKIFromDERCert(base::StringPiece cert,
  19. base::StringPiece* spki_out);
  20. // ExtractSubjectPublicKeyFromSPKI parses the DER encoded SubjectPublicKeyInfo
  21. // in |spki| and extracts the bytes of the SubjectPublicKey. On successful
  22. // return, |spk_out| is set to contain the public key, pointing into |spki|.
  23. NET_EXPORT_PRIVATE bool ExtractSubjectPublicKeyFromSPKI(
  24. base::StringPiece spki,
  25. base::StringPiece* spk_out);
  26. // HasCanSignHttpExchangesDraftExtension parses the DER encoded certificate
  27. // in |cert| and extracts the canSignHttpExchangesDraft extension
  28. // (https://wicg.github.io/webpackage/draft-yasskin-http-origin-signed-responses.html)
  29. // if present. Returns true if the extension was present, and false if
  30. // the extension was not present or if there was a parsing failure.
  31. NET_EXPORT bool HasCanSignHttpExchangesDraftExtension(base::StringPiece cert);
  32. // Extracts the two (SEQUENCE) tag-length-values for the signature
  33. // AlgorithmIdentifiers in a DER encoded certificate. Does not use strict
  34. // parsing or validate the resulting AlgorithmIdentifiers.
  35. //
  36. // On success returns true, and assigns |cert_signature_algorithm_sequence| and
  37. // |tbs_signature_algorithm_sequence| to point into |cert|:
  38. //
  39. // * |cert_signature_algorithm_sequence| points at the TLV for
  40. // Certificate.signatureAlgorithm.
  41. //
  42. // * |tbs_signature_algorithm_sequence| points at the TLV for
  43. // TBSCertificate.algorithm.
  44. NET_EXPORT_PRIVATE bool ExtractSignatureAlgorithmsFromDERCert(
  45. base::StringPiece cert,
  46. base::StringPiece* cert_signature_algorithm_sequence,
  47. base::StringPiece* tbs_signature_algorithm_sequence);
  48. // Extracts the contents of the extension (if any) with OID |extension_oid| from
  49. // the DER-encoded, X.509 certificate in |cert|.
  50. //
  51. // Returns false on parse error or true if the parse was successful. Sets
  52. // |*out_extension_present| to whether or not the extension was found. If found,
  53. // sets |*out_extension_critical| to match the extension's "critical" flag, and
  54. // sets |*out_contents| to the contents of the extension (after unwrapping the
  55. // OCTET STRING).
  56. NET_EXPORT bool ExtractExtensionFromDERCert(base::StringPiece cert,
  57. base::StringPiece extension_oid,
  58. bool* out_extension_present,
  59. bool* out_extension_critical,
  60. base::StringPiece* out_contents);
  61. } // namespace net::asn1
  62. #endif // NET_CERT_ASN1_UTIL_H_