Commit bc9894e6 authored by Adam Langley's avatar Adam Langley Committed by Commit Bot

VirtualU2fDevice: don't hold attestation as object state.

U2fDevice objects only exist for a single request so there's no point
holding these values in the class.

Change-Id: Ia42f40e4564a4128014f397a9669f0c22675bd4b
Reviewed-on: https://chromium-review.googlesource.com/963095Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Commit-Queue: Adam Langley <agl@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543418}
parent 27b9eefd
...@@ -99,14 +99,7 @@ VirtualU2fDevice::RegistrationData& VirtualU2fDevice::RegistrationData:: ...@@ -99,14 +99,7 @@ VirtualU2fDevice::RegistrationData& VirtualU2fDevice::RegistrationData::
operator=(RegistrationData&& other) = default; operator=(RegistrationData&& other) = default;
VirtualU2fDevice::RegistrationData::~RegistrationData() = default; VirtualU2fDevice::RegistrationData::~RegistrationData() = default;
VirtualU2fDevice::VirtualU2fDevice() VirtualU2fDevice::VirtualU2fDevice() : weak_factory_(this) {}
: attestation_private_key_(
crypto::ECPrivateKey::CreateFromPrivateKeyInfo(GetAttestationKey())),
attestation_cert_(std::begin(kAttestationCert),
std::end(kAttestationCert)),
weak_factory_(this) {
DCHECK(attestation_private_key_);
}
VirtualU2fDevice::~VirtualU2fDevice() = default; VirtualU2fDevice::~VirtualU2fDevice() = default;
...@@ -203,20 +196,22 @@ void VirtualU2fDevice::DoRegister(uint8_t ins, ...@@ -203,20 +196,22 @@ void VirtualU2fDevice::DoRegister(uint8_t ins,
// Note: Non-deterministic, you need to mock this out if you rely on // Note: Non-deterministic, you need to mock this out if you rely on
// deterministic behavior. // deterministic behavior.
std::vector<uint8_t> sig; std::vector<uint8_t> sig;
std::unique_ptr<crypto::ECPrivateKey> attestation_private_key =
crypto::ECPrivateKey::CreateFromPrivateKeyInfo(GetAttestationKey());
auto signer = auto signer =
crypto::ECSignatureCreator::Create(attestation_private_key_.get()); crypto::ECSignatureCreator::Create(attestation_private_key.get());
status = signer->Sign(sign_buffer.data(), sign_buffer.size(), &sig); status = signer->Sign(sign_buffer.data(), sign_buffer.size(), &sig);
DCHECK(status); DCHECK(status);
// U2F response data. // U2F response data.
std::vector<uint8_t> response; std::vector<uint8_t> response;
response.reserve(1 + public_key.size() + 1 + key_handle.size() + response.reserve(1 + public_key.size() + 1 + key_handle.size() +
attestation_cert_.size() + sig.size()); sizeof(kAttestationCert) + sig.size());
response.push_back(kU2fRegistrationResponseHeader); response.push_back(kU2fRegistrationResponseHeader);
AppendTo(&response, public_key); AppendTo(&response, public_key);
response.push_back(key_handle.size()); response.push_back(key_handle.size());
AppendTo(&response, key_handle); AppendTo(&response, key_handle);
AppendTo(&response, attestation_cert_); AppendTo(&response, kAttestationCert);
AppendTo(&response, sig); AppendTo(&response, sig);
// Store the registration. // Store the registration.
......
...@@ -70,9 +70,6 @@ class COMPONENT_EXPORT(DEVICE_FIDO) VirtualU2fDevice : public U2fDevice { ...@@ -70,9 +70,6 @@ class COMPONENT_EXPORT(DEVICE_FIDO) VirtualU2fDevice : public U2fDevice {
base::span<const uint8_t> data, base::span<const uint8_t> data,
DeviceCallback cb); DeviceCallback cb);
std::unique_ptr<crypto::ECPrivateKey> attestation_private_key_;
std::vector<uint8_t> attestation_cert_;
// Keyed on appId/rpId hash (aka "applicationParam") // Keyed on appId/rpId hash (aka "applicationParam")
std::map<std::vector<uint8_t>, RegistrationData> registrations_; std::map<std::vector<uint8_t>, RegistrationData> registrations_;
base::WeakPtrFactory<U2fDevice> weak_factory_; base::WeakPtrFactory<U2fDevice> weak_factory_;
......
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