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 5 #ifndef DEVICE_FIDO_WIN_TYPE_CONVERSIONS_H_ 6 #define DEVICE_FIDO_WIN_TYPE_CONVERSIONS_H_ 7 8 #include <windows.h> 9 10 #include "base/component_export.h" 11 #include "base/optional.h" 12 #include "base/strings/string16.h" 13 #include "device/fido/authenticator_get_assertion_response.h" 14 #include "device/fido/authenticator_make_credential_response.h" 15 #include "device/fido/fido_constants.h" 16 #include "third_party/microsoft_webauthn/webauthn.h" 17 18 namespace device { 19 20 enum class GetAssertionStatus; 21 enum class MakeCredentialStatus; 22 23 COMPONENT_EXPORT(DEVICE_FIDO) 24 base::Optional<AuthenticatorMakeCredentialResponse> 25 ToAuthenticatorMakeCredentialResponse( 26 const WEBAUTHN_CREDENTIAL_ATTESTATION& credential_attestation); 27 28 COMPONENT_EXPORT(DEVICE_FIDO) 29 base::Optional<AuthenticatorGetAssertionResponse> 30 ToAuthenticatorGetAssertionResponse( 31 const WEBAUTHN_ASSERTION& credential_attestation); 32 33 COMPONENT_EXPORT(DEVICE_FIDO) 34 uint32_t ToWinUserVerificationRequirement( 35 UserVerificationRequirement user_verification_requirement); 36 37 COMPONENT_EXPORT(DEVICE_FIDO) 38 uint32_t ToWinAuthenticatorAttachment( 39 AuthenticatorAttachment authenticator_attachment); 40 41 COMPONENT_EXPORT(DEVICE_FIDO) 42 std::vector<WEBAUTHN_CREDENTIAL> ToWinCredentialVector( 43 const std::vector<PublicKeyCredentialDescriptor>* credentials); 44 45 COMPONENT_EXPORT(DEVICE_FIDO) 46 std::vector<WEBAUTHN_CREDENTIAL_EX> ToWinCredentialExVector( 47 const std::vector<PublicKeyCredentialDescriptor>* credentials); 48 49 // WinErrorNameToCtapDeviceResponseCode maps a string returned by 50 // WebAuthNGetErrorName() to a CtapDeviceResponseCode. 51 // 52 // The Windows WebAuthn API returns errors as defined by the WebAuthn spec, 53 // whereas FidoAuthenticator callbacks generally resolve with a 54 // CtapDeviceResponseCode. This method hence yields a "synthetic" 55 // CtapDeviceResponseCode that can then be mapped to the corresponding 56 // {MakeCredential,GetAssertion}Status by calling 57 // WinCtapDeviceResponseCodeTo{MakeCredential,GetAssertion}Status(). 58 COMPONENT_EXPORT(DEVICE_FIDO) 59 CtapDeviceResponseCode WinErrorNameToCtapDeviceResponseCode( 60 const base::string16& error_name); 61 62 // WinCtapDeviceResponseCodeToMakeCredentialStatus returns the 63 // MakeCredentialStatus that corresponds to a synthetic CtapDeviceResponseCode 64 // obtained from WinErrorNameToCtapDeviceResponseCode(). Return values are one 65 // of {kSuccess, kWinInvalidStateError, kWinNotAllowedError}. 66 COMPONENT_EXPORT(DEVICE_FIDO) 67 MakeCredentialStatus WinCtapDeviceResponseCodeToMakeCredentialStatus( 68 CtapDeviceResponseCode status); 69 70 // WinCtapDeviceResponseCodeToGetAssertionStatus returns the GetAssertionStatus 71 // that corresponds to a synthetic CtapDeviceResponseCode obtained from 72 // WinErrorNameToCtapDeviceResponseCode(). Return values are one of {kSuccess, 73 // kWinNotAllowedError}. 74 COMPONENT_EXPORT(DEVICE_FIDO) 75 GetAssertionStatus WinCtapDeviceResponseCodeToGetAssertionStatus( 76 CtapDeviceResponseCode status); 77 78 COMPONENT_EXPORT(DEVICE_FIDO) 79 uint32_t ToWinAttestationConveyancePreference( 80 const AttestationConveyancePreference&); 81 82 } // namespace device 83 84 #endif // DEVICE_FIDO_WIN_TYPE_CONVERSIONS_H_ 85