attestation_statement.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2017 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 DEVICE_FIDO_ATTESTATION_STATEMENT_H_
  5. #define DEVICE_FIDO_ATTESTATION_STATEMENT_H_
  6. #include <string>
  7. #include "base/component_export.h"
  8. #include "base/containers/span.h"
  9. #include "components/cbor/values.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. namespace device {
  12. // A signed data object containing statements about a credential itself and
  13. // the authenticator that created it.
  14. // Each attestation statement format is defined by the following attributes:
  15. // - The attestation statement format identifier.
  16. // - The set of attestation types supported by the format.
  17. // - The syntax of an attestation statement produced in this format.
  18. // https://www.w3.org/TR/2017/WD-webauthn-20170505/#cred-attestation.
  19. class COMPONENT_EXPORT(DEVICE_FIDO) AttestationStatement {
  20. public:
  21. AttestationStatement(const AttestationStatement&) = delete;
  22. AttestationStatement& operator=(const AttestationStatement&) = delete;
  23. virtual ~AttestationStatement();
  24. // The CBOR map data to be added to the attestation object, structured
  25. // in a way that is specified by its particular attestation format:
  26. // https://www.w3.org/TR/2017/WD-webauthn-20170505/#defined-attestation-formats
  27. // This is not a CBOR-encoded byte array, but the map that will be
  28. // nested within another CBOR object and encoded then.
  29. virtual cbor::Value AsCBOR() const = 0;
  30. // Returns true if the attestation is a "self" attestation, i.e. is just the
  31. // private key signing itself to show that it is fresh.
  32. virtual bool IsSelfAttestation() const = 0;
  33. // Returns true if the attestation is known to be inappropriately identifying.
  34. // Some tokens return unique attestation certificates even when the bit to
  35. // request that is not set. (Normal attestation certificates are not
  36. // indended to be trackable.)
  37. virtual bool IsAttestationCertificateInappropriatelyIdentifying() const = 0;
  38. // Return the DER bytes of the leaf X.509 certificate, if any.
  39. virtual absl::optional<base::span<const uint8_t>> GetLeafCertificate()
  40. const = 0;
  41. const std::string& format_name() const { return format_; }
  42. protected:
  43. explicit AttestationStatement(std::string format);
  44. const std::string format_;
  45. };
  46. // NoneAttestationStatement represents a “none” attestation, which is used when
  47. // attestation information will not be returned. See
  48. // https://w3c.github.io/webauthn/#none-attestation
  49. class COMPONENT_EXPORT(DEVICE_FIDO) NoneAttestationStatement
  50. : public AttestationStatement {
  51. public:
  52. NoneAttestationStatement();
  53. NoneAttestationStatement(const NoneAttestationStatement&) = delete;
  54. NoneAttestationStatement& operator=(const NoneAttestationStatement&) = delete;
  55. ~NoneAttestationStatement() override;
  56. cbor::Value AsCBOR() const override;
  57. bool IsSelfAttestation() const override;
  58. bool IsAttestationCertificateInappropriatelyIdentifying() const override;
  59. absl::optional<base::span<const uint8_t>> GetLeafCertificate() const override;
  60. };
  61. COMPONENT_EXPORT(DEVICE_FIDO)
  62. cbor::Value AsCBOR(const AttestationStatement&);
  63. } // namespace device
  64. #endif // DEVICE_FIDO_ATTESTATION_STATEMENT_H_