forked from oracle/graaljs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To avoid timing out on ARM machines in the CI. PR-URL: nodejs/node#49221 Refs: nodejs/node#49202 Refs: nodejs/node#41206 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- Loading branch information
Showing
32 changed files
with
1,456 additions
and
1,042 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
32 changes: 32 additions & 0 deletions
32
graal-nodejs/test/parallel/test-crypto-keygen-async-dsa-key-object.js
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,32 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const { | ||
generateKeyPair, | ||
} = require('crypto'); | ||
|
||
// Test async DSA key object generation. | ||
{ | ||
generateKeyPair('dsa', { | ||
modulusLength: common.hasOpenSSL3 ? 2048 : 512, | ||
divisorLength: 256 | ||
}, common.mustSucceed((publicKey, privateKey) => { | ||
assert.strictEqual(publicKey.type, 'public'); | ||
assert.strictEqual(publicKey.asymmetricKeyType, 'dsa'); | ||
assert.deepStrictEqual(publicKey.asymmetricKeyDetails, { | ||
modulusLength: common.hasOpenSSL3 ? 2048 : 512, | ||
divisorLength: 256 | ||
}); | ||
|
||
assert.strictEqual(privateKey.type, 'private'); | ||
assert.strictEqual(privateKey.asymmetricKeyType, 'dsa'); | ||
assert.deepStrictEqual(privateKey.asymmetricKeyDetails, { | ||
modulusLength: common.hasOpenSSL3 ? 2048 : 512, | ||
divisorLength: 256 | ||
}); | ||
})); | ||
} |
64 changes: 64 additions & 0 deletions
64
graal-nodejs/test/parallel/test-crypto-keygen-async-dsa.js
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,64 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const { | ||
generateKeyPair, | ||
} = require('crypto'); | ||
const { | ||
assertApproximateSize, | ||
testSignVerify, | ||
spkiExp, | ||
} = require('../common/crypto'); | ||
|
||
// Test async DSA key generation. | ||
{ | ||
const privateKeyEncoding = { | ||
type: 'pkcs8', | ||
format: 'der' | ||
}; | ||
|
||
generateKeyPair('dsa', { | ||
modulusLength: common.hasOpenSSL3 ? 2048 : 512, | ||
divisorLength: 256, | ||
publicKeyEncoding: { | ||
type: 'spki', | ||
format: 'pem' | ||
}, | ||
privateKeyEncoding: { | ||
cipher: 'aes-128-cbc', | ||
passphrase: 'secret', | ||
...privateKeyEncoding | ||
} | ||
}, common.mustSucceed((publicKey, privateKeyDER) => { | ||
assert.strictEqual(typeof publicKey, 'string'); | ||
assert.match(publicKey, spkiExp); | ||
// The private key is DER-encoded. | ||
assert(Buffer.isBuffer(privateKeyDER)); | ||
|
||
assertApproximateSize(publicKey, common.hasOpenSSL3 ? 1194 : 440); | ||
assertApproximateSize(privateKeyDER, common.hasOpenSSL3 ? 721 : 336); | ||
|
||
// Since the private key is encrypted, signing shouldn't work anymore. | ||
assert.throws(() => { | ||
return testSignVerify(publicKey, { | ||
key: privateKeyDER, | ||
...privateKeyEncoding | ||
}); | ||
}, { | ||
name: 'TypeError', | ||
code: 'ERR_MISSING_PASSPHRASE', | ||
message: 'Passphrase required for encrypted key' | ||
}); | ||
|
||
// Signing should work with the correct password. | ||
testSignVerify(publicKey, { | ||
key: privateKeyDER, | ||
...privateKeyEncoding, | ||
passphrase: 'secret' | ||
}); | ||
})); | ||
} |
100 changes: 100 additions & 0 deletions
100
graal-nodejs/test/parallel/test-crypto-keygen-async-elliptic-curve-jwk.js
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,100 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const { | ||
generateKeyPair, | ||
} = require('crypto'); | ||
|
||
// Test async elliptic curve key generation with 'jwk' encoding | ||
{ | ||
[ | ||
['ec', ['P-384', 'P-256', 'P-521', 'secp256k1']], | ||
['rsa'], | ||
['ed25519'], | ||
['ed448'], | ||
['x25519'], | ||
['x448'], | ||
].forEach((types) => { | ||
const [type, options] = types; | ||
switch (type) { | ||
case 'ec': { | ||
return options.forEach((curve) => { | ||
generateKeyPair(type, { | ||
namedCurve: curve, | ||
publicKeyEncoding: { | ||
format: 'jwk' | ||
}, | ||
privateKeyEncoding: { | ||
format: 'jwk' | ||
} | ||
}, common.mustSucceed((publicKey, privateKey) => { | ||
assert.strictEqual(typeof publicKey, 'object'); | ||
assert.strictEqual(typeof privateKey, 'object'); | ||
assert.strictEqual(publicKey.x, privateKey.x); | ||
assert.strictEqual(publicKey.y, privateKey.y); | ||
assert(!publicKey.d); | ||
assert(privateKey.d); | ||
assert.strictEqual(publicKey.kty, 'EC'); | ||
assert.strictEqual(publicKey.kty, privateKey.kty); | ||
assert.strictEqual(publicKey.crv, curve); | ||
assert.strictEqual(publicKey.crv, privateKey.crv); | ||
})); | ||
}); | ||
} | ||
case 'rsa': { | ||
return generateKeyPair(type, { | ||
modulusLength: 4096, | ||
publicKeyEncoding: { | ||
format: 'jwk' | ||
}, | ||
privateKeyEncoding: { | ||
format: 'jwk' | ||
} | ||
}, common.mustSucceed((publicKey, privateKey) => { | ||
assert.strictEqual(typeof publicKey, 'object'); | ||
assert.strictEqual(typeof privateKey, 'object'); | ||
assert.strictEqual(publicKey.kty, 'RSA'); | ||
assert.strictEqual(publicKey.kty, privateKey.kty); | ||
assert.strictEqual(typeof publicKey.n, 'string'); | ||
assert.strictEqual(publicKey.n, privateKey.n); | ||
assert.strictEqual(typeof publicKey.e, 'string'); | ||
assert.strictEqual(publicKey.e, privateKey.e); | ||
assert.strictEqual(typeof privateKey.d, 'string'); | ||
assert.strictEqual(typeof privateKey.p, 'string'); | ||
assert.strictEqual(typeof privateKey.q, 'string'); | ||
assert.strictEqual(typeof privateKey.dp, 'string'); | ||
assert.strictEqual(typeof privateKey.dq, 'string'); | ||
assert.strictEqual(typeof privateKey.qi, 'string'); | ||
})); | ||
} | ||
case 'ed25519': | ||
case 'ed448': | ||
case 'x25519': | ||
case 'x448': { | ||
generateKeyPair(type, { | ||
publicKeyEncoding: { | ||
format: 'jwk' | ||
}, | ||
privateKeyEncoding: { | ||
format: 'jwk' | ||
} | ||
}, common.mustSucceed((publicKey, privateKey) => { | ||
assert.strictEqual(typeof publicKey, 'object'); | ||
assert.strictEqual(typeof privateKey, 'object'); | ||
assert.strictEqual(publicKey.x, privateKey.x); | ||
assert(!publicKey.d); | ||
assert(privateKey.d); | ||
assert.strictEqual(publicKey.kty, 'OKP'); | ||
assert.strictEqual(publicKey.kty, privateKey.kty); | ||
const expectedCrv = `${type.charAt(0).toUpperCase()}${type.slice(1)}`; | ||
assert.strictEqual(publicKey.crv, expectedCrv); | ||
assert.strictEqual(publicKey.crv, privateKey.crv); | ||
})); | ||
} | ||
} | ||
}); | ||
} |
50 changes: 50 additions & 0 deletions
50
graal-nodejs/test/parallel/test-crypto-keygen-async-encrypted-private-key-der.js
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,50 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const { | ||
generateKeyPair, | ||
} = require('crypto'); | ||
const { | ||
assertApproximateSize, | ||
testEncryptDecrypt, | ||
testSignVerify, | ||
} = require('../common/crypto'); | ||
|
||
// Test async RSA key generation with an encrypted private key, but encoded as DER. | ||
{ | ||
generateKeyPair('rsa', { | ||
publicExponent: 0x10001, | ||
modulusLength: 512, | ||
publicKeyEncoding: { | ||
type: 'pkcs1', | ||
format: 'der' | ||
}, | ||
privateKeyEncoding: { | ||
type: 'pkcs8', | ||
format: 'der' | ||
} | ||
}, common.mustSucceed((publicKeyDER, privateKeyDER) => { | ||
assert(Buffer.isBuffer(publicKeyDER)); | ||
assertApproximateSize(publicKeyDER, 74); | ||
|
||
assert(Buffer.isBuffer(privateKeyDER)); | ||
|
||
const publicKey = { | ||
key: publicKeyDER, | ||
type: 'pkcs1', | ||
format: 'der', | ||
}; | ||
const privateKey = { | ||
key: privateKeyDER, | ||
format: 'der', | ||
type: 'pkcs8', | ||
passphrase: 'secret' | ||
}; | ||
testEncryptDecrypt(publicKey, privateKey); | ||
testSignVerify(publicKey, privateKey); | ||
})); | ||
} |
Oops, something went wrong.