diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/device/fido/rsa_public_key.cc | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/device/fido/rsa_public_key.cc')
-rw-r--r-- | chromium/device/fido/rsa_public_key.cc | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/chromium/device/fido/rsa_public_key.cc b/chromium/device/fido/rsa_public_key.cc index e4abd88f606..be9af40234d 100644 --- a/chromium/device/fido/rsa_public_key.cc +++ b/chromium/device/fido/rsa_public_key.cc @@ -7,6 +7,7 @@ #include <utility> #include "components/cbor/writer.h" +#include "device/fido/cbor_extract.h" #include "device/fido/fido_constants.h" #include "third_party/boringssl/src/include/openssl/bn.h" #include "third_party/boringssl/src/include/openssl/bytestring.h" @@ -15,6 +16,11 @@ #include "third_party/boringssl/src/include/openssl/obj.h" #include "third_party/boringssl/src/include/openssl/rsa.h" +using device::cbor_extract::IntKey; +using device::cbor_extract::Is; +using device::cbor_extract::StepOrByte; +using device::cbor_extract::Stop; + namespace device { // static @@ -23,30 +29,36 @@ std::unique_ptr<PublicKey> RSAPublicKey::ExtractFromCOSEKey( base::span<const uint8_t> cbor_bytes, const cbor::Value::MapValue& map) { // See https://tools.ietf.org/html/rfc8230#section-4 - cbor::Value::MapValue::const_iterator it = - map.find(cbor::Value(static_cast<int64_t>(CoseKeyKey::kKty))); - if (it == map.end() || !it->second.is_integer() || - it->second.GetInteger() != static_cast<int64_t>(CoseKeyTypes::kRSA)) { - return nullptr; - } + struct COSEKey { + const int64_t* kty; + const std::vector<uint8_t>* n; + const std::vector<uint8_t>* e; + } cose_key; + + static constexpr cbor_extract::StepOrByte<COSEKey> kSteps[] = { + // clang-format off + ELEMENT(Is::kRequired, COSEKey, kty), + IntKey<COSEKey>(static_cast<int>(CoseKeyKey::kKty)), - cbor::Value::MapValue::const_iterator it_n = - map.find(cbor::Value(static_cast<int64_t>(CoseKeyKey::kRSAModulus))); - cbor::Value::MapValue::const_iterator it_e = map.find( - cbor::Value(static_cast<int64_t>(CoseKeyKey::kRSAPublicExponent))); + ELEMENT(Is::kRequired, COSEKey, n), + IntKey<COSEKey>(static_cast<int>(CoseKeyKey::kRSAModulus)), - if (it_n == map.end() || !it_n->second.is_bytestring() || it_e == map.end() || - !it_e->second.is_bytestring()) { + ELEMENT(Is::kRequired, COSEKey, e), + IntKey<COSEKey>(static_cast<int>(CoseKeyKey::kRSAPublicExponent)), + + Stop<COSEKey>(), + // clang-format on + }; + + if (!cbor_extract::Extract<COSEKey>(&cose_key, kSteps, map) || + *cose_key.kty != static_cast<int64_t>(CoseKeyTypes::kRSA)) { return nullptr; } - const std::vector<uint8_t>& n(it_n->second.GetBytestring()); - const std::vector<uint8_t>& e(it_e->second.GetBytestring()); - bssl::UniquePtr<BIGNUM> n_bn(BN_new()); bssl::UniquePtr<BIGNUM> e_bn(BN_new()); - if (!BN_bin2bn(n.data(), n.size(), n_bn.get()) || - !BN_bin2bn(e.data(), e.size(), e_bn.get())) { + if (!BN_bin2bn(cose_key.n->data(), cose_key.n->size(), n_bn.get()) || + !BN_bin2bn(cose_key.e->data(), cose_key.e->size(), e_bn.get())) { return nullptr; } |