webcrypto-liner icon indicating copy to clipboard operation
webcrypto-liner copied to clipboard

wrapKey permission is not sufficient in iOS Safari to wrap a key

Open borisreitman opened this issue 7 years ago • 6 comments

The wrapping_key in this code has a "wrapKey" permission. However, this gave an error when I tired to used it. But, when the wrapping key also has an "encrypt" permission, there is no error.

The "wrapKey" permission should be sufficient, and it works in other browsers.

crypto.subtle.wrapKey(
  "jwk",
  key,
  wrapping_key, //the AES-GCM key with "wrapKey" usage flag
  {  
    name: "AES-GCM",
    iv: nonce,
    tagLength: 128
  }
)

borisreitman avatar Feb 09 '18 01:02 borisreitman

This is because wrapKey = exportKey + encrypt https://github.com/PeculiarVentures/webcrypto-liner/blob/master/src/rsa/crypto.ts#L246

I'm not sure there is another way to resolve it. I think the best way is to use wrapKey usage with encrypt, and unwrapKey usage with decrypt

microshine avatar Feb 09 '18 06:02 microshine

So, how come it works in Chrome with just wrapKey without decrypt ? Is this non-standard ?

borisreitman avatar Feb 10 '18 16:02 borisreitman

Same question.

When I user RSA-OAEP, got a error of "CryptoKey has wrong key usage. Must be 'encrypt'".

FalconIA avatar Apr 02 '18 06:04 FalconIA

@borisreitman webcrypto-liner uses native Crypto if it's possible. This is why it doesn't throw error on wrapKey without encrypt key usage

microshine avatar Apr 02 '18 08:04 microshine

@FalconIA this is source code for RSA wrapKey https://github.com/PeculiarVentures/webcrypto-liner/blob/master/src/rsa/crypto.ts#L230-L248

As I told before wrapKey = exportKey + encrypt. This is main problem for encrypt key usage error. I've got some ideas how to fix it. I'll do it soon

microshine avatar Apr 02 '18 08:04 microshine

@FalconIA @borisreitman I published new version of webcrypto-liner. Can you check it?

microshine avatar Apr 02 '18 10:04 microshine