({ name, privateUsages }, extractable)
| 96 | } |
| 97 | |
| 98 | async function testImportPkcs8({ name, privateUsages }, extractable) { |
| 99 | let key; |
| 100 | try { |
| 101 | key = await subtle.importKey( |
| 102 | 'pkcs8', |
| 103 | keyData[name].pkcs8, |
| 104 | { name }, |
| 105 | extractable, |
| 106 | privateUsages); |
| 107 | } catch (err) { |
| 108 | if (process.features.openssl_is_boringssl) { |
| 109 | assert.strictEqual(err.name, 'DataError'); |
| 110 | // It should really only be ERR_OSSL_EVP_PRIVATE_KEY_WAS_NOT_SEED |
| 111 | // but BoringSSL is inconsistent between handling ML-KEM and ML-DSA |
| 112 | // Fixed in https://github.com/google/boringssl/commit/94c4c7f9e0eeeff72ea1ac6abf1aed5bd2a82c0c |
| 113 | assert.match(err.cause.code, /ERR_OSSL_EVP_UNSUPPORTED_ALGORITHM|ERR_OSSL_EVP_PRIVATE_KEY_WAS_NOT_SEED/); |
| 114 | common.printSkipMessage('Skipping unsupported private key format test'); |
| 115 | return; |
| 116 | } |
| 117 | throw err; |
| 118 | } |
| 119 | assert.strictEqual(key.type, 'private'); |
| 120 | assert.strictEqual(key.extractable, extractable); |
| 121 | assert.deepStrictEqual(key.usages, privateUsages); |
| 122 | assert.deepStrictEqual(key.algorithm.name, name); |
| 123 | assert.strictEqual(key.algorithm, key.algorithm); |
| 124 | assert.strictEqual(key.usages, key.usages); |
| 125 | |
| 126 | if (extractable) { |
| 127 | // Test the roundtrip |
| 128 | const pkcs8 = await subtle.exportKey('pkcs8', key); |
| 129 | assert.strictEqual( |
| 130 | Buffer.from(pkcs8).toString('hex'), |
| 131 | keyData[name].pkcs8_seed_only.toString('hex')); |
| 132 | } else { |
| 133 | await assert.rejects( |
| 134 | subtle.exportKey('pkcs8', key), { |
| 135 | message: /key is not extractable/, |
| 136 | name: 'InvalidAccessError', |
| 137 | }); |
| 138 | } |
| 139 | |
| 140 | await assert.rejects( |
| 141 | subtle.importKey( |
| 142 | 'pkcs8', |
| 143 | keyData[name].pkcs8, |
| 144 | { name }, |
| 145 | extractable, |
| 146 | [/* empty usages */]), |
| 147 | { name: 'SyntaxError', message: 'Usages cannot be empty when importing a private key.' }); |
| 148 | } |
| 149 | |
| 150 | async function testImportPkcs8SeedOnly({ name, privateUsages }, extractable) { |
| 151 | const key = await subtle.importKey( |
no test coverage detected