[DOM] WebCrypto: Check decoded key type before using it.

Just in case someone forces the wrong key type and misuses WebCrypto.
It won't be usable anyway so better to throw.
This commit is contained in:
Moonchild 2023-02-21 21:07:04 +01:00 committed by roytam1
commit 0b9698c80a

View file

@ -1741,6 +1741,10 @@ private:
return NS_ERROR_DOM_SYNTAX_ERR;
}
if (pubKey->keyType != rsaKey) {
return NS_ERROR_DOM_DATA_ERR;
}
// Extract relevant information from the public key
mModulusLength = 8 * pubKey->u.rsa.modulus.len;
if (!mPublicExponent.Assign(&pubKey->u.rsa.publicExponent)) {
@ -1874,6 +1878,10 @@ private:
}
if (mFormat.EqualsLiteral(WEBCRYPTO_KEY_FORMAT_SPKI)) {
if (pubKey->keyType != ecKey) {
return NS_ERROR_DOM_DATA_ERR;
}
if (!CheckEncodedECParameters(&pubKey->u.ec.DEREncodedParams)) {
return NS_ERROR_DOM_OPERATION_ERR;
}