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

//device/fido: check that EC public keys start with 0x04.

The spec says that they have to, but we weren't checking it from what I
can see.

Bug: 827574
Change-Id: I96f1a7b5078cfc4c5e88647f47e3a60821901848
Reviewed-on: https://chromium-review.googlesource.com/982632
Commit-Queue: Adam Langley <agl@chromium.org>
Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548146}
parent fe3abe01
...@@ -13,11 +13,12 @@ namespace device { ...@@ -13,11 +13,12 @@ namespace device {
namespace { namespace {
// The key is located after the first byte of the response // The key is located after the first byte of the response
// (which is a reserved byte). // (which is a reserved byte). It's in X9.62 format:
// The uncompressed form consists of 65 bytes: // - a constant 0x04 prefix to indicate an uncompressed key
// - a constant 0x04 prefix
// - the 32-byte x coordinate // - the 32-byte x coordinate
// - the 32-byte y coordinate. // - the 32-byte y coordinate.
constexpr size_t kKeyCompressionTypeOffset = 1;
constexpr size_t kUncompressedKey = 0x04;
constexpr size_t kHeaderLength = 2; // Account for reserved byte and prefix. constexpr size_t kHeaderLength = 2; // Account for reserved byte and prefix.
constexpr size_t kKeyLength = 32; constexpr size_t kKeyLength = 32;
} // namespace } // namespace
...@@ -26,6 +27,10 @@ constexpr size_t kKeyLength = 32; ...@@ -26,6 +27,10 @@ constexpr size_t kKeyLength = 32;
std::unique_ptr<ECPublicKey> ECPublicKey::ExtractFromU2fRegistrationResponse( std::unique_ptr<ECPublicKey> ECPublicKey::ExtractFromU2fRegistrationResponse(
std::string algorithm, std::string algorithm,
base::span<const uint8_t> u2f_data) { base::span<const uint8_t> u2f_data) {
if (u2f_data.size() < kHeaderLength ||
u2f_data[kKeyCompressionTypeOffset] != kUncompressedKey)
return nullptr;
std::vector<uint8_t> x = std::vector<uint8_t> x =
u2f_parsing_utils::Extract(u2f_data, kHeaderLength, kKeyLength); u2f_parsing_utils::Extract(u2f_data, kHeaderLength, kKeyLength);
......
...@@ -41,6 +41,7 @@ class COMPONENT_EXPORT(DEVICE_FIDO) ECPublicKey : public PublicKey { ...@@ -41,6 +41,7 @@ class COMPONENT_EXPORT(DEVICE_FIDO) ECPublicKey : public PublicKey {
std::vector<uint8_t> EncodeAsCOSEKey() const override; std::vector<uint8_t> EncodeAsCOSEKey() const override;
private: private:
// Note that these values might not be minimal and might not be on the curve.
const std::vector<uint8_t> x_coordinate_; const std::vector<uint8_t> x_coordinate_;
const std::vector<uint8_t> y_coordinate_; const std::vector<uint8_t> y_coordinate_;
......
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