mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 11:36:10 +00:00
LibWeb: Fix bogus AesGcm
and AesCtr
key import length validation
The validation of the key size and specified algorithm was out of spec. It is now implemented correctly like in `AesCbc`. The issue was discovered while implementing `wrapKey` and `unwrapKey` in the next commits.
This commit is contained in:
parent
2174e5dfcc
commit
1e98fa96d7
Notes:
github-actions[bot]
2024-12-16 10:37:08 +00:00
Author: https://github.com/devgianlu Commit: https://github.com/LadybirdBrowser/ladybird/commit/1e98fa96d74 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2915
1 changed files with 18 additions and 12 deletions
|
@ -1573,12 +1573,15 @@ WebIDL::ExceptionOr<GC::Ref<CryptoKey>> AesCtr::import_key(AlgorithmParams const
|
|||
// throw a DataError.
|
||||
auto data_bits = data.size() * 8;
|
||||
auto const& alg = jwk.alg;
|
||||
if (data_bits == 128 && alg != "A128CTR") {
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 128 bits, but alg specifies non-128-bit algorithm"_string);
|
||||
} else if (data_bits == 192 && alg != "A192CTR") {
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 192 bits, but alg specifies non-192-bit algorithm"_string);
|
||||
} else if (data_bits == 256 && alg != "A256CTR") {
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 256 bits, but alg specifies non-256-bit algorithm"_string);
|
||||
if (data_bits == 128) {
|
||||
if (alg.has_value() && alg != "A128CTR")
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 128 bits, but alg specifies non-128-bit algorithm"_string);
|
||||
} else if (data_bits == 192) {
|
||||
if (alg.has_value() && alg != "A192CTR")
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 192 bits, but alg specifies non-192-bit algorithm"_string);
|
||||
} else if (data_bits == 256) {
|
||||
if (alg.has_value() && alg != "A256CTR")
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 256 bits, but alg specifies non-256-bit algorithm"_string);
|
||||
} else {
|
||||
return WebIDL::DataError::create(m_realm, MUST(String::formatted("Invalid key size: {} bits", data_bits)));
|
||||
}
|
||||
|
@ -1890,12 +1893,15 @@ WebIDL::ExceptionOr<GC::Ref<CryptoKey>> AesGcm::import_key(AlgorithmParams const
|
|||
// throw a DataError.
|
||||
auto data_bits = data.size() * 8;
|
||||
auto const& alg = jwk.alg;
|
||||
if (data_bits == 128 && alg != "A128GCM") {
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 128 bits, but alg specifies non-128-bit algorithm"_string);
|
||||
} else if (data_bits == 192 && alg != "A192GCM") {
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 192 bits, but alg specifies non-192-bit algorithm"_string);
|
||||
} else if (data_bits == 256 && alg != "A256GCM") {
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 256 bits, but alg specifies non-256-bit algorithm"_string);
|
||||
if (data_bits == 128) {
|
||||
if (alg.has_value() && alg != "A128GCM")
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 128 bits, but alg specifies non-128-bit algorithm"_string);
|
||||
} else if (data_bits == 192) {
|
||||
if (alg.has_value() && alg != "A192GCM")
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 192 bits, but alg specifies non-192-bit algorithm"_string);
|
||||
} else if (data_bits == 256) {
|
||||
if (alg.has_value() && alg != "A256GCM")
|
||||
return WebIDL::DataError::create(m_realm, "Contradictory key size: key has 256 bits, but alg specifies non-256-bit algorithm"_string);
|
||||
} else {
|
||||
return WebIDL::DataError::create(m_realm, MUST(String::formatted("Invalid key size: {} bits", data_bits)));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue