Commit 0080859a authored by Jun Choi's avatar Jun Choi Committed by Commit Bot

Add serialization logic for GetAssertion response

Add serialization logic for GetAsserion response needed to implement
virtual CTAP2 device.

Bug: 829413
Change-Id: I144a48bd99be2fa09231d76718ecf97bb9ad75b4
Reviewed-on: https://chromium-review.googlesource.com/1114286
Commit-Queue: Jun Choi <hongjunchoi@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570689}
parent 736aa40b
......@@ -7,6 +7,8 @@
#include <utility>
#include "base/optional.h"
#include "components/cbor/cbor_values.h"
#include "components/cbor/cbor_writer.h"
#include "device/fido/authenticator_data.h"
#include "device/fido/fido_parsing_utils.h"
......@@ -89,4 +91,24 @@ AuthenticatorGetAssertionResponse::SetNumCredentials(uint8_t num_credentials) {
return *this;
}
std::vector<uint8_t> GetSerializedCtapDeviceResponse(
const AuthenticatorGetAssertionResponse& response) {
cbor::CBORValue::MapValue response_map;
if (response.credential())
response_map.emplace(1, response.credential()->ConvertToCBOR());
response_map.emplace(2, response.auth_data().SerializeToByteArray());
response_map.emplace(3, response.signature());
if (response.user_entity())
response_map.emplace(4, response.user_entity()->ConvertToCBOR());
// Multiple account selection is not supported.
response_map.emplace(5, 1);
auto encoded_response =
cbor::CBORWriter::Write(cbor::CBORValue(std::move(response_map)));
DCHECK(encoded_response);
return *encoded_response;
}
} // namespace device
......@@ -70,6 +70,10 @@ class COMPONENT_EXPORT(DEVICE_FIDO) AuthenticatorGetAssertionResponse
DISALLOW_COPY_AND_ASSIGN(AuthenticatorGetAssertionResponse);
};
COMPONENT_EXPORT(DEVICE_FIDO)
std::vector<uint8_t> GetSerializedCtapDeviceResponse(
const AuthenticatorGetAssertionResponse& response);
} // namespace device
#endif // DEVICE_FIDO_AUTHENTICATOR_GET_ASSERTION_RESPONSE_H_
......@@ -586,4 +586,50 @@ TEST(CTAPResponseTest, TestSerializeMakeCredentialResponse) {
base::make_span(test_data::kTestMakeCredentialResponse).subspan(1)));
}
TEST(CTAPResponseTest, TestSerializeGetAssertionResponse) {
constexpr std::array<uint8_t, kRpIdHashLength> kApplicationParameter = {{
0x62, 0x5d, 0xda, 0xdf, 0x74, 0x3f, 0x57, 0x27, 0xe6, 0x6b, 0xba,
0x8c, 0x2e, 0x38, 0x79, 0x22, 0xd1, 0xaf, 0x43, 0xc5, 0x03, 0xd9,
0x11, 0x4a, 0x8f, 0xba, 0x10, 0x4d, 0x84, 0xd0, 0x2b, 0xfa,
}};
constexpr uint8_t kUserId[] = {
0x30, 0x82, 0x01, 0x93, 0x30, 0x82, 0x01, 0x38, 0xa0, 0x03, 0x02,
0x01, 0x02, 0x30, 0x82, 0x01, 0x93, 0x30, 0x82, 0x01, 0x38, 0xa0,
0x03, 0x02, 0x01, 0x02, 0x30, 0x82, 0x01, 0x93, 0x30, 0x82,
};
constexpr uint8_t kCredentialId[] = {
0xf2, 0x20, 0x06, 0xde, 0x4f, 0x90, 0x5a, 0xf6, 0x8a, 0x43, 0x94,
0x2f, 0x02, 0x4f, 0x2a, 0x5e, 0xce, 0x60, 0x3d, 0x9c, 0x6d, 0x4b,
0x3d, 0xf8, 0xbe, 0x08, 0xed, 0x01, 0xfc, 0x44, 0x26, 0x46, 0xd0,
0x34, 0x85, 0x8a, 0xc7, 0x5b, 0xed, 0x3f, 0xd5, 0x80, 0xbf, 0x98,
0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e,
};
AuthenticatorData authenticator_data(
kApplicationParameter,
base::strict_cast<uint8_t>(AuthenticatorData::Flag::kTestOfUserPresence),
std::array<uint8_t, kSignCounterLength>{
{0x00, 0x00, 0x00, 0x11}} /* signature_counter */,
base::nullopt /* attested_credential_data */);
AuthenticatorGetAssertionResponse response(
std::move(authenticator_data),
fido_parsing_utils::Materialize(test_data::kCtap2GetAssertionSignature));
response.SetCredential({CredentialType::kPublicKey,
fido_parsing_utils::Materialize(kCredentialId)});
PublicKeyCredentialUserEntity user(fido_parsing_utils::Materialize(kUserId));
user.SetDisplayName("John P. Smith");
user.SetUserName("johnpsmith@example.com");
user.SetIconUrl(GURL("https://pics.acme.com/00/p/aBjjjpqPb.png"));
response.SetUserEntity(std::move(user));
response.SetNumCredentials(1);
EXPECT_THAT(
GetSerializedCtapDeviceResponse(response),
::testing::ElementsAreArray(
base::make_span(test_data::kDeviceGetAssertionResponse).subspan(1)));
}
} // namespace device
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment