-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto: fix WebCrypto import of RSA-PSS keys
This patch changes GetRsaKeyDetail to work in older supported versions of OpenSSL. Refs: openssl/openssl#10217 PR-URL: #36877 Refs: #36188 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
Showing
2 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const { | ||
createPrivateKey, | ||
createPublicKey, | ||
webcrypto: { | ||
subtle | ||
} | ||
} = require('crypto'); | ||
|
||
const fixtures = require('../common/fixtures'); | ||
|
||
{ | ||
const rsaPssKeyWithoutParams = fixtures.readKey('rsa_pss_private_2048.pem'); | ||
|
||
const pkcs8 = createPrivateKey(rsaPssKeyWithoutParams).export({ | ||
type: 'pkcs8', | ||
format: 'der' | ||
}); | ||
const spki = createPublicKey(rsaPssKeyWithoutParams).export({ | ||
type: 'spki', | ||
format: 'der' | ||
}); | ||
|
||
const hashes = ['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512']; | ||
|
||
const tasks = []; | ||
for (const hash of hashes) { | ||
const algorithm = { name: 'RSA-PSS', hash }; | ||
tasks.push(subtle.importKey('pkcs8', pkcs8, algorithm, true, ['sign'])); | ||
tasks.push(subtle.importKey('spki', spki, algorithm, true, ['verify'])); | ||
} | ||
|
||
Promise.all(tasks).then(common.mustCall()); | ||
} |