Title: [256201] trunk/Source/WebCore
- Revision
- 256201
- Author
- [email protected]
- Date
- 2020-02-10 12:26:04 -0800 (Mon, 10 Feb 2020)
Log Message
[WebAuthn] Merge some of the CTAP response decoder's code
https://bugs.webkit.org/show_bug.cgi?id=205375
Reviewed by Darin Adler.
This patch makes those code more compact and maintainable.
No change of behaviors.
* Modules/webauthn/fido/DeviceResponseConverter.cpp:
(fido::decodeResponseMap):
(fido::readCTAPMakeCredentialResponse):
(fido::readCTAPGetAssertionResponse):
(fido::readCTAPGetInfoResponse):
* Modules/webauthn/fido/DeviceResponseConverter.h:
* Modules/webauthn/fido/Pin.cpp:
(fido::pin::encodePinCommand):
(fido::pin::RetriesResponse::parse):
(fido::pin::KeyAgreementResponse::parse):
(fido::pin::TokenResponse::parse):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (256200 => 256201)
--- trunk/Source/WebCore/ChangeLog 2020-02-10 20:24:03 UTC (rev 256200)
+++ trunk/Source/WebCore/ChangeLog 2020-02-10 20:26:04 UTC (rev 256201)
@@ -1,3 +1,26 @@
+2020-02-10 Jiewen Tan <[email protected]>
+
+ [WebAuthn] Merge some of the CTAP response decoder's code
+ https://bugs.webkit.org/show_bug.cgi?id=205375
+
+ Reviewed by Darin Adler.
+
+ This patch makes those code more compact and maintainable.
+
+ No change of behaviors.
+
+ * Modules/webauthn/fido/DeviceResponseConverter.cpp:
+ (fido::decodeResponseMap):
+ (fido::readCTAPMakeCredentialResponse):
+ (fido::readCTAPGetAssertionResponse):
+ (fido::readCTAPGetInfoResponse):
+ * Modules/webauthn/fido/DeviceResponseConverter.h:
+ * Modules/webauthn/fido/Pin.cpp:
+ (fido::pin::encodePinCommand):
+ (fido::pin::RetriesResponse::parse):
+ (fido::pin::KeyAgreementResponse::parse):
+ (fido::pin::TokenResponse::parse):
+
2020-02-10 Megan Gardner <[email protected]>
Rename SelectionData classes and structures HighlightData, etc to be more inclusive for their new use cases
Modified: trunk/Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.cpp (256200 => 256201)
--- trunk/Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.cpp 2020-02-10 20:24:03 UTC (rev 256200)
+++ trunk/Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.cpp 2020-02-10 20:26:04 UTC (rev 256201)
@@ -54,6 +54,19 @@
return ProtocolVersion::kUnknown;
}
+Optional<cbor::CBORValue> decodeResponseMap(const Vector<uint8_t>& inBuffer)
+{
+ if (inBuffer.size() <= kResponseCodeLength || getResponseCode(inBuffer) != CtapDeviceResponseCode::kSuccess)
+ return WTF::nullopt;
+
+ Vector<uint8_t> buffer;
+ buffer.append(inBuffer.data() + 1, inBuffer.size() - 1);
+ Optional<CBOR> decodedResponse = cbor::CBORReader::read(buffer);
+ if (!decodedResponse || !decodedResponse->isMap())
+ return WTF::nullopt;
+ return decodedResponse;
+}
+
CtapDeviceResponseCode getResponseCode(const Vector<uint8_t>& buffer)
{
if (buffer.isEmpty())
@@ -85,23 +98,18 @@
// checks for correct encoding format.
RefPtr<AuthenticatorAttestationResponse> readCTAPMakeCredentialResponse(const Vector<uint8_t>& inBuffer, const AttestationConveyancePreference& attestation)
{
- if (inBuffer.size() <= kResponseCodeLength)
+ auto decodedMap = decodeResponseMap(inBuffer);
+ if (!decodedMap)
return nullptr;
+ const auto& responseMap = decodedMap->getMap();
- Vector<uint8_t> buffer;
- buffer.append(inBuffer.data() + 1, inBuffer.size() - 1);
- Optional<CBOR> decodedResponse = cbor::CBORReader::read(buffer);
- if (!decodedResponse || !decodedResponse->isMap())
+ auto it = responseMap.find(CBOR(1));
+ if (it == responseMap.end() || !it->second.isString())
return nullptr;
- const auto& decodedMap = decodedResponse->getMap();
-
- auto it = decodedMap.find(CBOR(1));
- if (it == decodedMap.end() || !it->second.isString())
- return nullptr;
auto format = it->second.clone();
- it = decodedMap.find(CBOR(2));
- if (it == decodedMap.end() || !it->second.isByteString())
+ it = responseMap.find(CBOR(2));
+ if (it == responseMap.end() || !it->second.isByteString())
return nullptr;
auto authenticatorData = it->second.clone();
@@ -109,8 +117,8 @@
if (credentialId.isEmpty())
return nullptr;
- it = decodedMap.find(CBOR(3));
- if (it == decodedMap.end() || !it->second.isMap())
+ it = responseMap.find(CBOR(3));
+ if (it == responseMap.end() || !it->second.isMap())
return nullptr;
auto attStmt = it->second.clone();
@@ -133,18 +141,11 @@
RefPtr<AuthenticatorAssertionResponse> readCTAPGetAssertionResponse(const Vector<uint8_t>& inBuffer)
{
- if (inBuffer.size() <= kResponseCodeLength)
+ auto decodedMap = decodeResponseMap(inBuffer);
+ if (!decodedMap)
return nullptr;
+ const auto& responseMap = decodedMap->getMap();
- Vector<uint8_t> buffer;
- buffer.append(inBuffer.data() + 1, inBuffer.size() - 1);
- Optional<CBOR> decodedResponse = cbor::CBORReader::read(buffer);
-
- if (!decodedResponse || !decodedResponse->isMap())
- return nullptr;
-
- auto& responseMap = decodedResponse->getMap();
-
auto it = responseMap.find(CBOR(1));
if (it == responseMap.end() || !it->second.isMap())
return nullptr;
@@ -200,16 +201,11 @@
Optional<AuthenticatorGetInfoResponse> readCTAPGetInfoResponse(const Vector<uint8_t>& inBuffer)
{
- if (inBuffer.size() <= kResponseCodeLength || getResponseCode(inBuffer) != CtapDeviceResponseCode::kSuccess)
+ auto decodedMap = decodeResponseMap(inBuffer);
+ if (!decodedMap)
return WTF::nullopt;
+ const auto& responseMap = decodedMap->getMap();
- Vector<uint8_t> buffer;
- buffer.append(inBuffer.data() + 1, inBuffer.size() - 1);
- Optional<CBOR> decodedResponse = cbor::CBORReader::read(buffer);
- if (!decodedResponse || !decodedResponse->isMap())
- return WTF::nullopt;
- const auto& responseMap = decodedResponse->getMap();
-
auto it = responseMap.find(CBOR(1));
if (it == responseMap.end() || !it->second.isArray())
return WTF::nullopt;
Modified: trunk/Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.h (256200 => 256201)
--- trunk/Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.h 2020-02-10 20:24:03 UTC (rev 256200)
+++ trunk/Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.h 2020-02-10 20:26:04 UTC (rev 256201)
@@ -42,6 +42,8 @@
// CTAP protocol, null optional is returned.
namespace fido {
+Optional<cbor::CBORValue> decodeResponseMap(const Vector<uint8_t>&);
+
// Parses response code from response received from the authenticator. If
// unknown response code value is received, then CTAP2_ERR_OTHER is returned.
WEBCORE_EXPORT CtapDeviceResponseCode getResponseCode(const Vector<uint8_t>&);
Modified: trunk/Source/WebCore/Modules/webauthn/fido/Pin.cpp (256200 => 256201)
--- trunk/Source/WebCore/Modules/webauthn/fido/Pin.cpp 2020-02-10 20:24:03 UTC (rev 256200)
+++ trunk/Source/WebCore/Modules/webauthn/fido/Pin.cpp 2020-02-10 20:26:04 UTC (rev 256201)
@@ -102,7 +102,6 @@
if (addAdditional)
addAdditional(&map);
- // FIXME(205375)
auto serializedParam = CBORWriter::write(CBORValue(WTFMove(map)));
ASSERT(serializedParam);
@@ -115,17 +114,11 @@
Optional<RetriesResponse> RetriesResponse::parse(const Vector<uint8_t>& inBuffer)
{
- // FIXME(205375)
- if (inBuffer.size() <= kResponseCodeLength || getResponseCode(inBuffer) != CtapDeviceResponseCode::kSuccess)
+ auto decodedMap = decodeResponseMap(inBuffer);
+ if (!decodedMap)
return WTF::nullopt;
+ const auto& responseMap = decodedMap->getMap();
- Vector<uint8_t> buffer;
- buffer.append(inBuffer.data() + 1, inBuffer.size() - 1);
- Optional<CBOR> decodedResponse = cbor::CBORReader::read(buffer);
- if (!decodedResponse || !decodedResponse->isMap())
- return WTF::nullopt;
- const auto& responseMap = decodedResponse->getMap();
-
auto it = responseMap.find(CBORValue(static_cast<int64_t>(ResponseKey::kRetries)));
if (it == responseMap.end() || !it->second.isUnsigned())
return WTF::nullopt;
@@ -142,17 +135,11 @@
Optional<KeyAgreementResponse> KeyAgreementResponse::parse(const Vector<uint8_t>& inBuffer)
{
- // FIXME(205375)
- if (inBuffer.size() <= kResponseCodeLength || getResponseCode(inBuffer) != CtapDeviceResponseCode::kSuccess)
+ auto decodedMap = decodeResponseMap(inBuffer);
+ if (!decodedMap)
return WTF::nullopt;
+ const auto& responseMap = decodedMap->getMap();
- Vector<uint8_t> buffer;
- buffer.append(inBuffer.data() + 1, inBuffer.size() - 1);
- auto decodedResponse = cbor::CBORReader::read(buffer);
- if (!decodedResponse || !decodedResponse->isMap())
- return WTF::nullopt;
- const auto& responseMap = decodedResponse->getMap();
-
// The ephemeral key is encoded as a COSE structure.
auto it = responseMap.find(CBORValue(static_cast<int64_t>(ResponseKey::kKeyAgreement)));
if (it == responseMap.end() || !it->second.isMap())
@@ -216,17 +203,11 @@
Optional<TokenResponse> TokenResponse::parse(const WebCore::CryptoKeyAES& sharedKey, const Vector<uint8_t>& inBuffer)
{
- // FIXME(205375)
- if (inBuffer.size() <= kResponseCodeLength || getResponseCode(inBuffer) != CtapDeviceResponseCode::kSuccess)
+ auto decodedMap = decodeResponseMap(inBuffer);
+ if (!decodedMap)
return WTF::nullopt;
+ const auto& responseMap = decodedMap->getMap();
- Vector<uint8_t> buffer;
- buffer.append(inBuffer.data() + 1, inBuffer.size() - 1);
- auto decodedResponse = cbor::CBORReader::read(buffer);
- if (!decodedResponse || !decodedResponse->isMap())
- return WTF::nullopt;
- const auto& responseMap = decodedResponse->getMap();
-
auto it = responseMap.find(CBORValue(static_cast<int64_t>(ResponseKey::kPinToken)));
if (it == responseMap.end() || !it->second.isByteString())
return WTF::nullopt;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes