Skip to content

Commit

Permalink
fix!: ensure 2048 RSA keys are used
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Apr 1, 2022
1 parent 6cf7e3c commit ad707c0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3361,6 +3361,12 @@ function checkSupportedJwsAlg(alg: unknown) {
return <JWSAlgorithm>alg
}

function checkRsaKeyAlgorithm(algorithm: RsaKeyAlgorithm) {
if (typeof algorithm.modulusLength !== 'number' || algorithm.modulusLength < 2048) {
throw new OPE(`${algorithm.name} modulusLength must be at least 2048 bits`)
}
}

function subtleAlgorithm(
alg: string,
key: CryptoKey,
Expand All @@ -3369,10 +3375,13 @@ function subtleAlgorithm(
case 'ECDSA':
return <EcdsaParams>{ name: key.algorithm.name, hash: `SHA-${alg.slice(-3)}` }
case 'RSA-PSS':
checkRsaKeyAlgorithm(<RsaKeyAlgorithm>key.algorithm)
return <RsaPssParams>{
name: key.algorithm.name,
saltLength: parseInt(alg.slice(-3), 10) >> 3,
}
case 'RSASSA-PKCS1-v1_5':
checkRsaKeyAlgorithm(<RsaKeyAlgorithm>key.algorithm)
default:
return <AlgorithmIdentifier>{ name: key.algorithm.name }
}
Expand Down

0 comments on commit ad707c0

Please sign in to comment.