PeculiarVentures / webcrypto-liner

webcrypto-liner is a polyfill that let's down-level User Agents (like IE/Edge) use libraries that depend on WebCrypto. (Keywords: Javascript, WebCrypto, Shim, Polyfill)
MIT License
149 stars 26 forks source link

Fix exportKey/importKey in JWK format for EC keys under Safari v11 #39

Closed microshine closed 7 years ago

microshine commented 7 years ago

node-webcrypto-ossl can't import JWK which was exported from Safari

https://github.com/PeculiarVentures/webcrypto-local/issues/178

microshine commented 7 years ago

JWK

{ 
  crv: 'P-256',
  ext: true,
  key_ops: [ 'verify' ],
  kty: 'EC',
  x: '62WZY0i_D6kwAnpeplBNBRDXw0FQauuaXS2XgXMmOQA',
  y: 'JtsjBDrLKijihVDmjKREIFafztFrZWN_j2T0Nn4nXyg' 
}

Test code

crypto.subtle.importKey("jwk", { 
  crv: 'P-256',
  ext: true,
  key_ops: [ 'verify' ],
  kty: 'EC',
  x: '62WZY0i_D6kwAnpeplBNBRDXw0FQauuaXS2XgXMmOQA',
  y: 'JtsjBDrLKijihVDmjKREIFafztFrZWN_j2T0Nn4nXyg' 
}, {name: "ECDSA", namedCurve: "P-256"}, true, ["verify"])
.then(() => {console.log("success")})
.catch((err) => {console.error(err)})

Chrome, Firefox, node-webcrypto-ossl throw exception for this JWK

microshine commented 7 years ago

Module creates new CryptoKeyPair for EC if public key has incorrect data on export JWK format.