|
2 | 2 | const common = require('../common'); |
3 | 3 | if (!common.hasCrypto) |
4 | 4 | common.skip('missing crypto'); |
5 | | -const { hasOpenSSL } = require('../common/crypto'); |
| 5 | +const { hasFIPS, hasOpenSSL } = require('../common/crypto'); |
6 | 6 | if (!hasOpenSSL(3)) |
7 | 7 | common.skip('requires OpenSSL 3.x'); |
8 | 8 |
|
@@ -84,26 +84,32 @@ const data = Buffer.from('hello store'); |
84 | 84 | } |
85 | 85 |
|
86 | 86 | { |
87 | | - const alice = generateKeyPairSync('x25519'); |
88 | | - const bob = generateKeyPairSync('x25519'); |
89 | | - const file = path.join(tmpdir.path, 'x25519.pem'); |
90 | | - fs.writeFileSync(file, alice.privateKey.export({ |
91 | | - format: 'pem', |
92 | | - type: 'pkcs8', |
93 | | - })); |
94 | | - const url = pathToFileURL(file); |
| 87 | + if (hasFIPS(3, 5)) { |
| 88 | + assert.throws(() => generateKeyPairSync('x25519'), { |
| 89 | + code: 'ERR_OSSL_EVP_UNSUPPORTED', |
| 90 | + }); |
| 91 | + } else { |
| 92 | + const alice = generateKeyPairSync('x25519'); |
| 93 | + const bob = generateKeyPairSync('x25519'); |
| 94 | + const file = path.join(tmpdir.path, 'x25519.pem'); |
| 95 | + fs.writeFileSync(file, alice.privateKey.export({ |
| 96 | + format: 'pem', |
| 97 | + type: 'pkcs8', |
| 98 | + })); |
| 99 | + const url = pathToFileURL(file); |
95 | 100 |
|
96 | | - const expected = diffieHellman({ |
97 | | - privateKey: alice.privateKey, |
98 | | - publicKey: bob.publicKey, |
99 | | - }); |
100 | | - assert.deepStrictEqual( |
101 | | - diffieHellman({ privateKey: url, publicKey: bob.publicKey }), |
102 | | - expected); |
| 101 | + const expected = diffieHellman({ |
| 102 | + privateKey: alice.privateKey, |
| 103 | + publicKey: bob.publicKey, |
| 104 | + }); |
| 105 | + assert.deepStrictEqual( |
| 106 | + diffieHellman({ privateKey: url, publicKey: bob.publicKey }), |
| 107 | + expected); |
103 | 108 |
|
104 | | - if (hasOpenSSL(3, 2)) { |
105 | | - const { sharedKey, ciphertext } = encapsulate(alice.publicKey); |
106 | | - assert.deepStrictEqual(decapsulate(url, ciphertext), sharedKey); |
| 109 | + if (hasOpenSSL(3, 2)) { |
| 110 | + const { sharedKey, ciphertext } = encapsulate(alice.publicKey); |
| 111 | + assert.deepStrictEqual(decapsulate(url, ciphertext), sharedKey); |
| 112 | + } |
107 | 113 | } |
108 | 114 | } |
109 | 115 |
|
|
0 commit comments