Skip to content

Key usages should be an unique set #62899

Description

@ChALkeR
>constk=awaitcrypto.subtle.exportKey('jwk',awaitcrypto.subtle.generateKey({name: "ChaCha20-Poly1305"},true,['encrypt']))>awaitcrypto.subtle.importKey('jwk',k,"ChaCha20-Poly1305",true,['encrypt','encrypt'])CryptoKey{type: 'secret',extractable: true,algorithm: {name: 'ChaCha20-Poly1305'},usages: ['encrypt','encrypt']// duplicated}>awaitcrypto.subtle.exportKey('jwk',_){key_ops: ['encrypt','encrypt'],// duplicatedext: true,alg: 'C20P',kty: 'oct',k: '...'}
>constk=awaitcrypto.subtle.exportKey('jwk',awaitcrypto.subtle.generateKey({name: "AES-GCM",length: 256},true,['encrypt']))undefined>awaitcrypto.subtle.importKey('jwk',k,{name: "AES-GCM",length: 256},true,['encrypt','encrypt'])CryptoKey{type: 'secret',extractable: true,algorithm: {name: 'AES-GCM',length: 256},usages: ['encrypt','encrypt']// duplicated}>awaitcrypto.subtle.exportKey('jwk',_){key_ops: ['encrypt','encrypt'],// duplicatedext: true,alg: 'A256GCM',kty: 'oct',k: '...'}
>k=awaitcrypto.subtle.generateKey({name: "RSA-OAEP",hash: "SHA-256",modulusLength: 2048,publicExponent: Uint8Array.of(1,0,1)},true,['encrypt','decrypt'])>p=awaitcrypto.subtle.exportKey('jwk',k.publicKey)>awaitcrypto.subtle.importKey('jwk',p,{name: "RSA-OAEP",hash: "SHA-256"},true,['encrypt','encrypt'])CryptoKey{type: 'public',extractable: true,algorithm: {name: 'RSA-OAEP',modulusLength: 2048,publicExponent: [Uint8Array],hash: [Object]},usages: ['encrypt','encrypt']// duplicate}>awaitcrypto.subtle.exportKey('jwk',_){key_ops: ['encrypt','encrypt'],// duplicateext: true,alg: 'RSA-OAEP-256',kty: 'RSA',n: '...',e: 'AQAB'}

Chrome deduplicates:

Image

Source:

chacha20_poly1305

https://github.com/nodejs/node/blob/HEAD/lib/internal/crypto/chacha20_poly1305.js#L143

Image

aes

https://github.com/nodejs/node/blob/HEAD/lib/internal/crypto/aes.js#L288

Image

rsa

https://github.com/nodejs/node/blob/HEAD/lib/internal/crypto/rsa.js#L284

Image

Metadata

Metadata

Assignees

Labels

cryptoIssues and PRs related to the crypto subsystem.web-standardsIssues and PRs related to Web APIswebcrypto

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions