[WebAuthN] Import U2F command/response converters from Chromium
authorjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Jan 2019 02:08:20 +0000 (02:08 +0000)
committerjiewen_tan@apple.com <jiewen_tan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 Jan 2019 02:08:20 +0000 (02:08 +0000)
commita6fe38d05ce31783abfc09f68bc4709c88acea2a
treed9d82e63142b536e5378aa1aa29597ce39f162dd
parent85121801a962f5d8aae6380b41e0c5c95b0ed71e
[WebAuthN] Import U2F command/response converters from Chromium
https://bugs.webkit.org/show_bug.cgi?id=193150
<rdar://problem/47054028>

Reviewed by Brent Fulgham.

Source/WebCore:

This patch imports Chromium's U2F command/response converters:
https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-client-to-authenticator-protocol-v2.0-id-20180227.html#u2f-interoperability
1. It directly imports the following files and suit them to WebKit's coding style:
https://cs.chromium.org/chromium/src/device/fido/u2f_command_constructor.cc?l=1&rcl=db624110317d01efa78cd32e7be1524190e1beb0
https://cs.chromium.org/chromium/src/device/fido/u2f_command_constructor.h?rcl=db624110317d01efa78cd32e7be1524190e1beb0
https://cs.chromium.org/chromium/src/device/fido/u2f_command_constructor_unittest.cc?rcl=db624110317d01efa78cd32e7be1524190e1beb0
2. It gathers the following methods into U2fResponseConverter:
AuthenticatorMakeCredentialResponse::CreateFromU2fRegisterResponse()
AuthenticatorGetAssertionResponse::CreateFromU2fSignResponse()
3. It also updates FidoConstants.h, FidoTestData.h and CtapResponseTest.cpp accordingly.

Besides importing stuff from Chroimum, it also gathers a bunch of constants and helper functions into WebAuthenticationConstants.h
and WebAuthenticationUtils.h. It also fixes Bug 183534: 2) and 7).

Covered by API tests.

* Modules/webauthn/AuthenticatorCoordinator.cpp:
(WebCore::AuthenticatorCoordinatorInternal::produceClientDataJsonHash):
* Modules/webauthn/WebAuthenticationConstants.h: Copied from Source/WebCore/Modules/webauthn/COSEConstants.h.
* Modules/webauthn/WebAuthenticationUtils.cpp: Added.
(WebCore::convertBytesToVector):
(WebCore::produceRpIdHash):
(WebCore::encodeES256PublicKeyAsCBOR):
(WebCore::buildAttestedCredentialData):
(WebCore::buildAuthData):
(WebCore::buildAttestationObject):
* Modules/webauthn/WebAuthenticationUtils.h: Renamed from Source/WebCore/Modules/webauthn/COSEConstants.h.
* Modules/webauthn/fido/DeviceResponseConverter.cpp:
(fido::getCredentialId):
(fido::readCTAPGetInfoResponse):
* Modules/webauthn/fido/FidoConstants.h:
* Modules/webauthn/fido/U2fCommandConstructor.cpp: Added.
(fido::WebCore::constructU2fRegisterCommand):
(fido::WebCore::constructU2fSignCommand):
(fido::isConvertibleToU2fRegisterCommand):
(fido::isConvertibleToU2fSignCommand):
(fido::convertToU2fRegisterCommand):
(fido::convertToU2fCheckOnlySignCommand):
(fido::convertToU2fSignCommand):
(fido::constructBogusU2fRegistrationCommand):
* Modules/webauthn/fido/U2fCommandConstructor.h: Added.
* Modules/webauthn/fido/U2fResponseConverter.cpp: Added.
(fido::WebCore::extractECPublicKeyFromU2fRegistrationResponse):
(fido::WebCore::extractCredentialIdFromU2fRegistrationResponse):
(fido::WebCore::createAttestedCredentialDataFromU2fRegisterResponse):
(fido::WebCore::parseX509Length):
(fido::WebCore::createFidoAttestationStatementFromU2fRegisterResponse):
(fido::readU2fRegisterResponse):
(fido::readFromU2fSignResponse):
* Modules/webauthn/fido/U2fResponseConverter.h: Added.
* Modules/webgpu/WebGPUCommandBuffer.cpp:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

Source/WebKit:

Moves helper functions to WebAuthenticationUtils.

* UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm:
(WebKit::LocalAuthenticatorInternal::produceHashSet):
(WebKit::LocalAuthenticator::continueMakeCredentialAfterAttested):
(): Deleted.
(WebKit::LocalAuthenticatorInternal::buildAuthData): Deleted.
* UIProcess/WebAuthentication/Mock/MockHidConnection.cpp:
(WebKit::MockHidConnection::feedReports):

Tools:

Adds API tests.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp:
(TestWebKitAPI::getTestAttestedCredentialDataBytes):
(TestWebKitAPI::getTestAuthenticatorDataBytes):
(TestWebKitAPI::getTestAttestationObjectBytes):
(TestWebKitAPI::getTestSignResponse):
(TestWebKitAPI::getTestU2fRegisterResponse):
(TestWebKitAPI::TEST):
(TestWebKitAPI::convertToVector): Deleted.
* TestWebKitAPI/Tests/WebCore/FidoTestData.h:
* TestWebKitAPI/Tests/WebCore/U2fCommandConstructorTest.cpp: Added.
(TestWebKitAPI::constructMakeCredentialRequest):
(TestWebKitAPI::constructGetAssertionRequest):
(TestWebKitAPI::TEST):

LayoutTests:

Fixes Bug 183534:
7) Change little endian bytes (ARM and x86 default) to big endian as requested by the spec.

* http/wpt/webauthn/public-key-credential-create-success-hid.https.html:
* http/wpt/webauthn/public-key-credential-get-success-hid.https.html:
* http/wpt/webauthn/resources/util.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239665 268f45cc-cd09-0410-ab3c-d52691b4dbfc
26 files changed:
LayoutTests/ChangeLog
LayoutTests/http/wpt/webauthn/public-key-credential-create-success-hid.https.html
LayoutTests/http/wpt/webauthn/public-key-credential-get-success-hid.https.html
LayoutTests/http/wpt/webauthn/resources/util.js
Source/WebCore/ChangeLog
Source/WebCore/Modules/webauthn/AuthenticatorCoordinator.cpp
Source/WebCore/Modules/webauthn/WebAuthenticationConstants.h [moved from Source/WebCore/Modules/webauthn/COSEConstants.h with 64% similarity]
Source/WebCore/Modules/webauthn/WebAuthenticationUtils.cpp [new file with mode: 0644]
Source/WebCore/Modules/webauthn/WebAuthenticationUtils.h [new file with mode: 0644]
Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.cpp
Source/WebCore/Modules/webauthn/fido/FidoConstants.h
Source/WebCore/Modules/webauthn/fido/U2fCommandConstructor.cpp [new file with mode: 0644]
Source/WebCore/Modules/webauthn/fido/U2fCommandConstructor.h [new file with mode: 0644]
Source/WebCore/Modules/webauthn/fido/U2fResponseConverter.cpp [new file with mode: 0644]
Source/WebCore/Modules/webauthn/fido/U2fResponseConverter.h [new file with mode: 0644]
Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm
Source/WebKit/UIProcess/WebAuthentication/Mock/MockHidConnection.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp
Tools/TestWebKitAPI/Tests/WebCore/FidoTestData.h
Tools/TestWebKitAPI/Tests/WebCore/U2fCommandConstructorTest.cpp [new file with mode: 0644]