opaque_attestation_statement.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2018 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. #include "device/fido/opaque_attestation_statement.h"
  5. #include <utility>
  6. #include "components/cbor/values.h"
  7. using cbor::Value;
  8. namespace device {
  9. OpaqueAttestationStatement::OpaqueAttestationStatement(
  10. std::string attestation_format,
  11. Value attestation_statement_map)
  12. : AttestationStatement(std::move(attestation_format)),
  13. attestation_statement_map_(std::move(attestation_statement_map)) {}
  14. OpaqueAttestationStatement::~OpaqueAttestationStatement() = default;
  15. // Returns the deep copied cbor map value of |attestation_statement_map_|.
  16. Value OpaqueAttestationStatement::AsCBOR() const {
  17. DCHECK(attestation_statement_map_.is_map());
  18. Value::MapValue new_map;
  19. new_map.reserve(attestation_statement_map_.GetMap().size());
  20. for (const auto& map_it : attestation_statement_map_.GetMap()) {
  21. new_map.try_emplace(new_map.end(), map_it.first.Clone(),
  22. map_it.second.Clone());
  23. }
  24. return cbor::Value(std::move(new_map));
  25. }
  26. bool OpaqueAttestationStatement::IsSelfAttestation() const {
  27. DCHECK(attestation_statement_map_.is_map());
  28. const Value::MapValue& m(attestation_statement_map_.GetMap());
  29. const Value alg("alg");
  30. const Value sig("sig");
  31. return format_ == "packed" && m.size() == 2 && m.count(std::move(alg)) == 1 &&
  32. m.count(std::move(sig)) == 1;
  33. }
  34. bool OpaqueAttestationStatement::
  35. IsAttestationCertificateInappropriatelyIdentifying() const {
  36. return false;
  37. }
  38. absl::optional<base::span<const uint8_t>>
  39. OpaqueAttestationStatement::GetLeafCertificate() const {
  40. DCHECK(attestation_statement_map_.is_map());
  41. const Value::MapValue& m(attestation_statement_map_.GetMap());
  42. const Value x5c("x5c");
  43. const auto it = m.find(x5c);
  44. if (it == m.end() || !it->second.is_array()) {
  45. return absl::nullopt;
  46. }
  47. const Value::ArrayValue& certs = it->second.GetArray();
  48. if (certs.empty() || !certs[0].is_bytestring()) {
  49. return absl::nullopt;
  50. }
  51. return certs[0].GetBytestring();
  52. }
  53. } // namespace device