digitalbazaar / forge

A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
https://digitalbazaar.com/
Other
5.06k stars 779 forks source link

Add support for crypto.webkitSubtle in rsa.js #436

Open kimtuck opened 7 years ago

kimtuck commented 7 years ago

According to http://caniuse.com/#feat=cryptography the prefix for safari is crypto.webkitSubtle. It should be pretty straightforward to add in this support in rsa.js. If you'd like, I can do the code edit and make a pull request.

dlongley commented 7 years ago

If you'd like, I can do the code edit and make a pull request.

Do you mean for RSA key generation? If so, yes, we'd really appreciate such a PR, thanks!

kimtuck commented 7 years ago

Yes that's what I mean; and I'd be happy to. Might be a day or two.

kimtuck commented 7 years ago

It's not quite as easy as it sounds.
1) Use webkitSubtle instead of subtle 2) the webkit implementation cannot directly export to pkcs8; you need an intermediate step. The suggestion here http://stackoverflow.com/questions/31241713/webcrypto-safari-cannot-exportkey-and-promise-seems-to-never-resolve-fail suggests exporting to jwk then converting to pkcs8.

kimtuck commented 7 years ago

Adding the webcrypto-shim found here (https://github.com/vibornoff/webcrypto-shim/blob/master/webcrypto-shim.js) fixes the issue. See this pen https://codepen.io/kimtuck/pen/rrbzp for a working test.

I would suggest adding a note to include the shim before forge; and then closing this ticket.