crypto: fix EdDSA support for KeyObject · nodejs/node@247c14c (original) (raw)
8 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1133,11 +1133,16 @@ bytes. This property is `undefined` for symmetric keys. | ||
1133 | 1133 | ### keyObject.asymmetricKeyType |
1134 | 1134 | <!-- YAML |
1135 | 1135 | added: v11.6.0 |
1136 | +changes: | |
1137 | + - version: REPLACEME | |
1138 | + pr-url: https://github.com/nodejs/node/pull/26319 | |
1139 | + description: Added support for `'ed25519'` and `'ed448'` | |
1136 | 1140 | --> |
1137 | 1141 | * {string} |
1138 | 1142 | |
1139 | 1143 | For asymmetric keys, this property represents the type of the embedded key |
1140 | -(`'rsa'`, `'dsa'` or `'ec'`). This property is `undefined` for symmetric keys. | |
1144 | +(`'rsa'`, `'dsa'`, `'ec'`, `'ed25519'`, or `'ed448'`). | |
1145 | +This property is `undefined` for symmetric keys. | |
1141 | 1146 | |
1142 | 1147 | ### keyObject.export([options]) |
1143 | 1148 | <!-- YAML |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -144,6 +144,8 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2; | ||
144 | 144 | V(constants_string, "constants") \ |
145 | 145 | V(crypto_dsa_string, "dsa") \ |
146 | 146 | V(crypto_ec_string, "ec") \ |
147 | +V(crypto_ed25519_string, "ed25519") \ | |
148 | +V(crypto_ed448_string, "ed448") \ | |
147 | 149 | V(crypto_rsa_string, "rsa") \ |
148 | 150 | V(cwd_string, "cwd") \ |
149 | 151 | V(data_string, "data") \ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3468,6 +3468,10 @@ Local KeyObject::GetAsymmetricKeyType() const { | ||
3468 | 3468 | return env()->crypto_dsa_string(); |
3469 | 3469 | case EVP_PKEY_EC: |
3470 | 3470 | return env()->crypto_ec_string(); |
3471 | +case EVP_PKEY_ED25519: | |
3472 | +return env()->crypto_ed25519_string(); | |
3473 | +case EVP_PKEY_ED448: | |
3474 | +return env()->crypto_ed448_string(); | |
3471 | 3475 | default: |
3472 | 3476 | CHECK(false); |
3473 | 3477 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
1 | +-----BEGIN PRIVATE KEY----- | |
2 | +MC4CAQAwBQYDK2VwBCIEIHXLsXm1lsq5HtyqJwQyFmpfEluuf0KOqP6DqMgGxxDL | |
3 | +-----END PRIVATE KEY----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
1 | +-----BEGIN PUBLIC KEY----- | |
2 | +MCowBQYDK2VwAyEAEXRYV3v5ucrHVR3mKqyPXxXqU34lASwc7Y7MoOvaqcs= | |
3 | +-----END PUBLIC KEY----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1 | +-----BEGIN PRIVATE KEY----- | |
2 | +MEcCAQAwBQYDK2VxBDsEObxytD95dGN3Hxk7kVk+Lig1rGYTRr3YdaHjRog++Sgk | |
3 | +QD7KwKmxroBURtkE2N0JbQ3ctdrpGRB5DQ== | |
4 | +-----END PRIVATE KEY----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1 | +-----BEGIN PUBLIC KEY----- | |
2 | +MEMwBQYDK2VxAzoAIESY3jnpGdB5UVJDCznrv0vmBFIzgSMu+gafsbCX1rFtsJwR | |
3 | +M6XUDQiEY7dk6rmm/Fktyawna5EA | |
4 | +-----END PUBLIC KEY----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -170,3 +170,34 @@ const privatePem = fixtures.readSync('test_rsa_privkey.pem', 'ascii'); | ||
170 | 170 | createPrivateKey({ key: '' }); |
171 | 171 | }, /null/); |
172 | 172 | } |
173 | + | |
174 | +[ | |
175 | +{ private: fixtures.readSync('test_ed25519_privkey.pem', 'ascii'), | |
176 | +public: fixtures.readSync('test_ed25519_pubkey.pem', 'ascii'), | |
177 | +keyType: 'ed25519' }, | |
178 | +{ private: fixtures.readSync('test_ed448_privkey.pem', 'ascii'), | |
179 | +public: fixtures.readSync('test_ed448_pubkey.pem', 'ascii'), | |
180 | +keyType: 'ed448' } | |
181 | +].forEach((info) => { | |
182 | +const keyType = info.keyType; | |
183 | + | |
184 | +{ | |
185 | +const exportOptions = { type: 'pkcs8', format: 'pem' }; | |
186 | +const key = createPrivateKey(info.private); | |
187 | +assert.strictEqual(key.type, 'private'); | |
188 | +assert.strictEqual(key.asymmetricKeyType, keyType); | |
189 | +assert.strictEqual(key.symmetricKeySize, undefined); | |
190 | +assert.strictEqual(key.export(exportOptions), info.private); | |
191 | +} | |
192 | + | |
193 | +{ | |
194 | +const exportOptions = { type: 'spki', format: 'pem' }; | |
195 | +[info.private, info.public].forEach((pem) => { | |
196 | +const key = createPublicKey(pem); | |
197 | +assert.strictEqual(key.type, 'public'); | |
198 | +assert.strictEqual(key.asymmetricKeyType, keyType); | |
199 | +assert.strictEqual(key.symmetricKeySize, undefined); | |
200 | +assert.strictEqual(key.export(exportOptions), info.public); | |
201 | +}); | |
202 | +} | |
203 | +}); |