| 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Copyright (C) 2018 Apple Inc. All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | #pragma once |
| 31 | |
| 32 | #if ENABLE(WEB_AUTHN) |
| 33 | |
| 34 | #include "CBORValue.h" |
| 35 | #include <wtf/Forward.h> |
| 36 | |
| 37 | namespace fido { |
| 38 | |
| 39 | // Represents CTAP device properties and capabilities received as a response to |
| 40 | // AuthenticatorGetInfo command. |
| 41 | class WEBCORE_EXPORT AuthenticatorSupportedOptions { |
| 42 | WTF_MAKE_NONCOPYABLE(AuthenticatorSupportedOptions); |
| 43 | public: |
| 44 | enum class UserVerificationAvailability { |
| 45 | // e.g. Authenticator with finger print sensor and user's fingerprint is |
| 46 | // registered to the device. |
| 47 | kSupportedAndConfigured, |
| 48 | // e.g. Authenticator with fingerprint sensor without user's fingerprint |
| 49 | // registered. |
| 50 | kSupportedButNotConfigured, |
| 51 | kNotSupported |
| 52 | }; |
| 53 | |
| 54 | enum class ClientPinAvailability { |
| 55 | kSupportedAndPinSet, |
| 56 | kSupportedButPinNotSet, |
| 57 | kNotSupported, |
| 58 | }; |
| 59 | |
| 60 | AuthenticatorSupportedOptions() = default; |
| 61 | AuthenticatorSupportedOptions(AuthenticatorSupportedOptions&&) = default; |
| 62 | AuthenticatorSupportedOptions& operator=(AuthenticatorSupportedOptions&&) = default; |
| 63 | |
| 64 | AuthenticatorSupportedOptions& setIsPlatformDevice(bool); |
| 65 | AuthenticatorSupportedOptions& setSupportsResidentKey(bool); |
| 66 | AuthenticatorSupportedOptions& setUserVerificationAvailability(UserVerificationAvailability); |
| 67 | AuthenticatorSupportedOptions& setUserPresenceRequired(bool); |
| 68 | AuthenticatorSupportedOptions& setClientPinAvailability(ClientPinAvailability); |
| 69 | |
| 70 | bool isPlatformDevice() const { return m_isPlatformDevice; } |
| 71 | bool supportsResidentKey() const { return m_supportsResidentKey; } |
| 72 | UserVerificationAvailability userVerificationAvailability() const { return m_userVerificationAvailability; } |
| 73 | bool userPresenceRequired() const { return m_userPresenceRequired; } |
| 74 | ClientPinAvailability clientPinAvailability() const { return m_clientPinAvailability; } |
| 75 | |
| 76 | private: |
| 77 | // Indicates that the device is attached to the client and therefore can't be |
| 78 | // removed and used on another client. |
| 79 | bool m_isPlatformDevice { false }; |
| 80 | // Indicates that the device is capable of storing keys on the device itself |
| 81 | // and therefore can satisfy the authenticatorGetAssertion request with |
| 82 | // allowList parameter not specified or empty. |
| 83 | bool m_supportsResidentKey { false }; |
| 84 | // Indicates whether the device is capable of verifying the user on its own. |
| 85 | UserVerificationAvailability m_userVerificationAvailability { UserVerificationAvailability::kNotSupported }; |
| 86 | bool m_userPresenceRequired { true }; |
| 87 | // Represents whether client pin in set and stored in device. Set as null |
| 88 | // optional if client pin capability is not supported by the authenticator. |
| 89 | ClientPinAvailability m_clientPinAvailability { ClientPinAvailability::kNotSupported }; |
| 90 | }; |
| 91 | |
| 92 | WEBCORE_EXPORT cbor::CBORValue convertToCBOR(const AuthenticatorSupportedOptions&); |
| 93 | |
| 94 | } // namespace fido |
| 95 | |
| 96 | #endif // ENABLE(WEB_AUTHN) |
| 97 | |