enrollment.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. // Copyright 2019 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_BIO_ENROLLMENT_H_
  5. #define DEVICE_FIDO_BIO_ENROLLMENT_H_
  6. #include <map>
  7. #include "base/component_export.h"
  8. #include "components/cbor/values.h"
  9. #include "device/fido/fido_constants.h"
  10. #include "device/fido/pin.h"
  11. #include "third_party/abseil-cpp/absl/types/optional.h"
  12. namespace device {
  13. // This file defines structures and values required to interact with
  14. // an authenticator that supports authenticatorBioEnrollment (0x09,
  15. // or vendor-specific 0x40). This command currently exists in the
  16. // pre-standardization CTAP2.1 specification, section 5.7.
  17. // TODO(martinkr) add link to standard when published
  18. enum class BioEnrollmentRequestKey : uint8_t {
  19. kModality = 0x01,
  20. kSubCommand = 0x02,
  21. kSubCommandParams = 0x03,
  22. kPinProtocol = 0x04,
  23. kPinAuth = 0x05,
  24. kGetModality = 0x06
  25. };
  26. enum class BioEnrollmentModality : uint8_t {
  27. kFingerprint = 0x01,
  28. kMin = kFingerprint,
  29. kMax = kFingerprint
  30. };
  31. enum class BioEnrollmentFingerprintKind : uint8_t {
  32. kTouch = 0x01,
  33. kSwipe = 0x02,
  34. kMin = kTouch,
  35. kMax = kSwipe
  36. };
  37. enum class BioEnrollmentSubCommand : uint8_t {
  38. kEnrollBegin = 0x01,
  39. kEnrollCaptureNextSample = 0x02,
  40. kCancelCurrentEnrollment = 0x03,
  41. kEnumerateEnrollments = 0x04,
  42. kSetFriendlyName = 0x05,
  43. kRemoveEnrollment = 0x06,
  44. kGetFingerprintSensorInfo = 0x07,
  45. kMin = kEnrollBegin,
  46. kMax = kGetFingerprintSensorInfo
  47. };
  48. enum class BioEnrollmentSubCommandParam : uint8_t {
  49. kTemplateId = 0x01,
  50. kTemplateFriendlyName = 0x02,
  51. kTimeoutMilliseconds = 0x03
  52. };
  53. enum class BioEnrollmentResponseKey : uint8_t {
  54. kModality = 0x01,
  55. kFingerprintKind = 0x02,
  56. kMaxCaptureSamplesRequiredForEnroll = 0x03,
  57. kTemplateId = 0x04,
  58. kLastEnrollSampleStatus = 0x05,
  59. kRemainingSamples = 0x06,
  60. kTemplateInfos = 0x07,
  61. kMaxTemplateFriendlyName = 0x08,
  62. };
  63. enum class BioEnrollmentTemplateInfoParam : uint8_t {
  64. kTemplateId = 0x01,
  65. kTemplateFriendlyName = 0x02
  66. };
  67. enum class BioEnrollmentSampleStatus : uint8_t {
  68. kGood = 0x00,
  69. kTooHigh = 0x01,
  70. kTooLow = 0x02,
  71. kTooLeft = 0x03,
  72. kTooRight = 0x04,
  73. kTooFast = 0x05,
  74. kTooSlow = 0x06,
  75. kPoorQuality = 0x07,
  76. kTooSkewed = 0x08,
  77. kTooShort = 0x09,
  78. kMergeFailure = 0x0A,
  79. kExists = 0x0B,
  80. kNoUserActivity = 0x0D,
  81. kNoUserPresenceTransition = 0x0E,
  82. kMin = kGood,
  83. kMax = kNoUserPresenceTransition
  84. };
  85. template <typename T>
  86. static absl::optional<T> ToBioEnrollmentEnum(uint8_t v) {
  87. // Check if enum-class is in range...
  88. if (v < static_cast<int>(T::kMin) || v > static_cast<int>(T::kMax)) {
  89. // ...to avoid possible undefined behavior (casting from int to enum).
  90. return absl::nullopt;
  91. }
  92. return static_cast<T>(v);
  93. }
  94. struct BioEnrollmentRequest {
  95. enum Version {
  96. kDefault,
  97. kPreview,
  98. };
  99. static BioEnrollmentRequest ForGetModality(Version);
  100. static BioEnrollmentRequest ForGetSensorInfo(Version);
  101. static BioEnrollmentRequest ForEnrollBegin(
  102. Version,
  103. const pin::TokenResponse& pin_token);
  104. static BioEnrollmentRequest ForEnrollNextSample(
  105. Version,
  106. const pin::TokenResponse& pin_token,
  107. std::vector<uint8_t> template_id);
  108. static BioEnrollmentRequest ForCancel(Version);
  109. static BioEnrollmentRequest ForEnumerate(Version,
  110. const pin::TokenResponse& token);
  111. static BioEnrollmentRequest ForRename(Version,
  112. const pin::TokenResponse& token,
  113. std::vector<uint8_t> id,
  114. std::string name);
  115. static BioEnrollmentRequest ForDelete(Version,
  116. const pin::TokenResponse& token,
  117. std::vector<uint8_t> id);
  118. Version version;
  119. absl::optional<BioEnrollmentModality> modality;
  120. absl::optional<BioEnrollmentSubCommand> subcommand;
  121. absl::optional<cbor::Value::MapValue> params;
  122. absl::optional<PINUVAuthProtocol> pin_protocol;
  123. absl::optional<std::vector<uint8_t>> pin_auth;
  124. absl::optional<bool> get_modality;
  125. BioEnrollmentRequest(BioEnrollmentRequest&&);
  126. BioEnrollmentRequest& operator=(BioEnrollmentRequest&&);
  127. ~BioEnrollmentRequest();
  128. private:
  129. explicit BioEnrollmentRequest(Version);
  130. };
  131. struct COMPONENT_EXPORT(DEVICE_FIDO) BioEnrollmentResponse {
  132. static absl::optional<BioEnrollmentResponse> Parse(
  133. const absl::optional<cbor::Value>& cbor_response);
  134. BioEnrollmentResponse();
  135. BioEnrollmentResponse(BioEnrollmentResponse&&);
  136. BioEnrollmentResponse& operator=(BioEnrollmentResponse&&) = default;
  137. ~BioEnrollmentResponse();
  138. bool operator==(const BioEnrollmentResponse&) const;
  139. absl::optional<BioEnrollmentModality> modality;
  140. absl::optional<BioEnrollmentFingerprintKind> fingerprint_kind;
  141. absl::optional<uint8_t> max_samples_for_enroll;
  142. absl::optional<std::vector<uint8_t>> template_id;
  143. absl::optional<BioEnrollmentSampleStatus> last_status;
  144. absl::optional<uint8_t> remaining_samples;
  145. absl::optional<std::map<std::vector<uint8_t>, std::string>> template_infos;
  146. absl::optional<uint32_t> max_template_friendly_name;
  147. };
  148. COMPONENT_EXPORT(DEVICE_FIDO)
  149. std::pair<CtapRequestCommand, absl::optional<cbor::Value>>
  150. AsCTAPRequestValuePair(const BioEnrollmentRequest& request);
  151. } // namespace device
  152. #endif // DEVICE_FIDO_BIO_ENROLLMENT_H_