Skip to content

Commit

Permalink
lib: refactor SubtleCrypto experimental warnings
Browse files Browse the repository at this point in the history
PR-URL: #54620
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
panva authored and targos committed Oct 2, 2024
1 parent 7c83c15 commit b85c8ce
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
5 changes: 0 additions & 5 deletions lib/internal/crypto/cfrg.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const {
} = require('internal/crypto/util');

const {
emitExperimentalWarning,
lazyDOMException,
promisify,
} = require('internal/util');
Expand Down Expand Up @@ -105,7 +104,6 @@ function createCFRGRawKey(name, keyData, isPublic) {

async function cfrgGenerateKey(algorithm, extractable, keyUsages) {
const { name } = algorithm;
emitExperimentalWarning(`The ${name} Web Crypto API algorithm`);

const usageSet = new SafeSet(keyUsages);
switch (name) {
Expand Down Expand Up @@ -187,7 +185,6 @@ async function cfrgGenerateKey(algorithm, extractable, keyUsages) {
}

function cfrgExportKey(key, format) {
emitExperimentalWarning(`The ${key.algorithm.name} Web Crypto API algorithm`);
return jobPromise(() => new ECKeyExportJob(
kCryptoJobAsync,
format,
Expand All @@ -202,7 +199,6 @@ async function cfrgImportKey(
keyUsages) {

const { name } = algorithm;
emitExperimentalWarning(`The ${name} Web Crypto API algorithm`);
let keyObject;
const usagesSet = new SafeSet(keyUsages);
switch (format) {
Expand Down Expand Up @@ -319,7 +315,6 @@ async function cfrgImportKey(
}

function eddsaSignVerify(key, data, { name, context }, signature) {
emitExperimentalWarning(`The ${name} Web Crypto API algorithm`);
const mode = signature === undefined ? kSignJobModeSign : kSignJobModeVerify;
const type = mode === kSignJobModeSign ? 'private' : 'public';

Expand Down
58 changes: 44 additions & 14 deletions lib/internal/crypto/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const {
DataViewPrototypeGetByteOffset,
FunctionPrototypeBind,
Number,
ObjectDefineProperty,
ObjectEntries,
ObjectKeys,
ObjectPrototypeHasOwnProperty,
Promise,
Expand Down Expand Up @@ -63,6 +65,7 @@ const { Buffer } = require('buffer');

const {
cachedResult,
emitExperimentalWarning,
filterDuplicateStrings,
lazyDOMException,
} = require('internal/util');
Expand Down Expand Up @@ -195,26 +198,18 @@ const kSupportedAlgorithms = {
'AES-GCM': 'AesKeyGenParams',
'AES-KW': 'AesKeyGenParams',
'HMAC': 'HmacKeyGenParams',
'X25519': null,
'Ed25519': null,
'X448': null,
'Ed448': null,
},
'sign': {
'RSASSA-PKCS1-v1_5': null,
'RSA-PSS': 'RsaPssParams',
'ECDSA': 'EcdsaParams',
'HMAC': null,
'Ed25519': null,
'Ed448': 'Ed448Params',
},
'verify': {
'RSASSA-PKCS1-v1_5': null,
'RSA-PSS': 'RsaPssParams',
'ECDSA': 'EcdsaParams',
'HMAC': null,
'Ed25519': null,
'Ed448': 'Ed448Params',
},
'importKey': {
'RSASSA-PKCS1-v1_5': 'RsaHashedImportParams',
Expand All @@ -229,17 +224,11 @@ const kSupportedAlgorithms = {
'AES-CBC': null,
'AES-GCM': null,
'AES-KW': null,
'Ed25519': null,
'X25519': null,
'Ed448': null,
'X448': null,
},
'deriveBits': {
'HKDF': 'HkdfParams',
'PBKDF2': 'Pbkdf2Params',
'ECDH': 'EcdhKeyDeriveParams',
'X25519': 'EcdhKeyDeriveParams',
'X448': 'EcdhKeyDeriveParams',
},
'encrypt': {
'RSA-OAEP': 'RsaOaepParams',
Expand Down Expand Up @@ -270,6 +259,47 @@ const kSupportedAlgorithms = {
},
};

const experimentalAlgorithms = ObjectEntries({
'X25519': {
generateKey: null,
importKey: null,
deriveBits: 'EcdhKeyDeriveParams',
},
'Ed25519': {
generateKey: null,
sign: null,
verify: null,
importKey: null,
},
'X448': {
generateKey: null,
importKey: null,
deriveBits: 'EcdhKeyDeriveParams',
},
'Ed448': {
generateKey: null,
sign: 'Ed448Params',
verify: 'Ed448Params',
importKey: null,
},
});

for (let i = 0; i < experimentalAlgorithms.length; i++) {
const name = experimentalAlgorithms[i][0];
const ops = ObjectEntries(experimentalAlgorithms[i][1]);
for (let j = 0; j < ops.length; j++) {
const { 0: op, 1: dict } = ops[j];
ObjectDefineProperty(kSupportedAlgorithms[op], name, {
get() {
emitExperimentalWarning(`The ${name} Web Crypto API algorithm`);
return dict;
},
__proto__: null,
enumerable: true,
});
}
}

const simpleAlgorithmDictionaries = {
AesGcmParams: { iv: 'BufferSource', additionalData: 'BufferSource' },
RsaHashedKeyGenParams: { hash: 'HashAlgorithmIdentifier' },
Expand Down

0 comments on commit b85c8ce

Please sign in to comment.