|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +if (!common.hasCrypto) |
| 5 | + common.skip('missing crypto'); |
| 6 | +const { hasOpenSSL, isBoringSSL } = require('../common/crypto'); |
| 7 | +if (isBoringSSL || !hasOpenSSL(3, 5)) |
| 8 | + common.skip('requires OpenSSL 3.5 or later'); |
| 9 | + |
| 10 | +const assert = require('assert'); |
| 11 | +const { createPrivateKey } = require('crypto'); |
| 12 | +const fixtures = require('../common/fixtures'); |
| 13 | +const { subtle } = globalThis.crypto; |
| 14 | + |
| 15 | +(async () => { |
| 16 | + const algorithm = { name: 'AES-GCM', iv: new Uint8Array(12) }; |
| 17 | + const wrappingKey = await subtle.generateKey({ name: 'AES-GCM', length: 128 }, |
| 18 | + false, ['wrapKey']); |
| 19 | + for (const [name, usage] of [ |
| 20 | + ['ML-KEM-512', 'decapsulateBits'], |
| 21 | + ['ML-KEM-768', 'decapsulateBits'], |
| 22 | + ['ML-KEM-1024', 'decapsulateBits'], |
| 23 | + ['ML-DSA-44', 'sign'], |
| 24 | + ['ML-DSA-65', 'sign'], |
| 25 | + ['ML-DSA-87', 'sign'], |
| 26 | + ]) { |
| 27 | + const file = `${name.toLowerCase().replaceAll('-', '_')}_private_priv_only.pem`; |
| 28 | + const key = createPrivateKey(fixtures.readKey(file)).toCryptoKey(name, true, [usage]); |
| 29 | + await assert.rejects(subtle.exportKey('jwk', key), { |
| 30 | + name: 'OperationError', constructor: DOMException, |
| 31 | + }); |
| 32 | + await assert.rejects(subtle.wrapKey('jwk', key, wrappingKey, algorithm), { |
| 33 | + name: 'OperationError', constructor: DOMException, |
| 34 | + }); |
| 35 | + } |
| 36 | +})().then(common.mustCall()); |
0 commit comments