GeezerVison is showing github.com — crypto: fix ECDH webcrypto public CryptoKey usages · nodejs/node@ef64b86
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/crypto/ec.js +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -58,7 +58,14 @@ function verifyAcceptableEcKeyUse(name, type, usages) { | 58 | 58 | let checkSet; | 59 | 59 | switch (name) { | 60 | 60 | case 'ECDH': | 61 | | - checkSet = ['deriveKey', 'deriveBits']; | | 61 | + switch (type) { | | 62 | + case 'private': | | 63 | + checkSet = ['deriveKey', 'deriveBits']; | | 64 | + break; | | 65 | + case 'public': | | 66 | + checkSet = []; | | 67 | + break; | | 68 | + } | 62 | 69 | break; | 63 | 70 | case 'ECDSA': | 64 | 71 | switch (type) { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-webcrypto-derivebits-ecdh.js +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -73,7 +73,7 @@ async function prepareKeys() { | 73 | 73 | namedCurve | 74 | 74 | }, | 75 | 75 | true, | 76 | | - ['deriveKey', 'deriveBits']), | | 76 | + []), | 77 | 77 | ]); | 78 | 78 | keys[namedCurve] = { | 79 | 79 | privateKey, | @@ -235,17 +235,17 @@ async function prepareKeys() { | 235 | 235 | name: 'ECDH', | 236 | 236 | public: keys['P-521'].publicKey | 237 | 237 | }, keys['P-521'].publicKey, null), { | 238 | | - message: /baseKey must be a private key/ | | 238 | + name: 'InvalidAccessError' | 239 | 239 | }); | 240 | 240 | } | 241 | 241 |
| 242 | 242 | { | 243 | | - // Base key is not a private key | | 243 | + // Public is not a public key | 244 | 244 | await assert.rejects(subtle.deriveBits({ | 245 | 245 | name: 'ECDH', | 246 | 246 | public: keys['P-521'].privateKey | 247 | | - }, keys['P-521'].publicKey, null), { | 248 | | - message: /algorithm\.public must be a public key/ | | 247 | + }, keys['P-521'].privateKey, null), { | | 248 | + name: 'InvalidAccessError' | 249 | 249 | }); | 250 | 250 | } | 251 | 251 |
| @@ -262,7 +262,7 @@ async function prepareKeys() { | 262 | 262 | name: 'ECDH', | 263 | 263 | public: key | 264 | 264 | }, keys['P-521'].publicKey, null), { | 265 | | - message: /algorithm\.public must be a public key/ | | 265 | + name: 'InvalidAccessError' | 266 | 266 | }); | 267 | 267 | } | 268 | 268 | })().then(common.mustCall()); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-webcrypto-derivekey-ecdh.js +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -68,7 +68,7 @@ async function prepareKeys() { | 68 | 68 | namedCurve | 69 | 69 | }, | 70 | 70 | true, | 71 | | - ['deriveKey', 'deriveBits']), | | 71 | + []), | 72 | 72 | ]); | 73 | 73 | keys[namedCurve] = { | 74 | 74 | privateKey, | @@ -209,7 +209,7 @@ async function prepareKeys() { | 209 | 209 | }, | 210 | 210 | keys['P-521'].publicKey, | 211 | 211 | ...otherArgs), | 212 | | - { message: /baseKey must be a private key/ }); | | 212 | + { name: 'InvalidAccessError' }); | 213 | 213 | } | 214 | 214 |
| 215 | 215 | { | @@ -222,7 +222,7 @@ async function prepareKeys() { | 222 | 222 | }, | 223 | 223 | keys['P-521'].publicKey, | 224 | 224 | ...otherArgs), | 225 | | - { message: /algorithm\.public must be a public key/ }); | | 225 | + { name: 'InvalidAccessError' }); | 226 | 226 | } | 227 | 227 |
| 228 | 228 | { | @@ -242,6 +242,6 @@ async function prepareKeys() { | 242 | 242 | }, | 243 | 243 | keys['P-521'].publicKey, | 244 | 244 | ...otherArgs), | 245 | | - { message: /algorithm\.public must be a public key/ }); | | 245 | + { name: 'InvalidAccessError' }); | 246 | 246 | } | 247 | 247 | })().then(common.mustCall()); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-webcrypto-export-import-ec.js +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -333,19 +333,19 @@ async function testImportRaw({ name, publicUsages }, namedCurve) { | 333 | 333 | const rsaPrivate = crypto.createPrivateKey( | 334 | 334 | fixtures.readKey('rsa_private_2048.pem')); | 335 | 335 |
| 336 | | - for (const [name, [publicUsage, privateUsage]] of Object.entries({ | 337 | | - 'ECDSA': ['verify', 'sign'], | 338 | | - 'ECDH': ['deriveBits', 'deriveBits'], | 339 | | - })) { | | 336 | + for (const [name, publicUsages, privateUsages] of [ | | 337 | + ['ECDSA', ['verify'], ['sign']], | | 338 | + ['ECDH', [], ['deriveBits', 'deriveBits']], | | 339 | + ]) { | 340 | 340 | assert.rejects(subtle.importKey( | 341 | 341 | 'spki', | 342 | 342 | rsaPublic.export({ format: 'der', type: 'spki' }), | 343 | 343 | { name, hash: 'SHA-256', namedCurve: 'P-256' }, | 344 | | - true, [publicUsage]), { message: /Invalid key type/ }); | | 344 | + true, publicUsages), { message: /Invalid key type/ }); | 345 | 345 | assert.rejects(subtle.importKey( | 346 | 346 | 'pkcs8', | 347 | 347 | rsaPrivate.export({ format: 'der', type: 'pkcs8' }), | 348 | 348 | { name, hash: 'SHA-256', namedCurve: 'P-256' }, | 349 | | - true, [privateUsage]), { message: /Invalid key type/ }); | | 349 | + true, privateUsages), { message: /Invalid key type/ }); | 350 | 350 | } | 351 | 351 | } |
|