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

Error: Unsupported algorithm 'hmac' -- Safari #40

Open lightninglu10 opened 7 years ago

lightninglu10 commented 7 years ago

Hey guys, I'm trying to use this package or webcrypto-shim to fix Safari's webcrypto package.

I'm getting this error though:

Error: Unsupported algorithm 'hmac'

I've included asymcrypto and elliptic in my html:

    <script src="%PUBLIC_URL%/webcrypto-liner.shim.js"></script>
    <script src="%PUBLIC_URL%/asmcrypto.min.js"></script>
    <script src="%PUBLIC_URL%/elliptic.min.js"></script>

Any advice here?

rmhrisk commented 7 years ago

We did not add HMAC to liner yet.

You can see the algorithms we did add support for in the README.

asymcrypto.js does support HMAC so you could easily do a PR that added it to liner.

You would basically use the SHA2 logic as the prototype

lightninglu10 commented 7 years ago

For hmac, asymcrypto supports

HMAC-SHA1 HMAC-SHA256 HMAC-SHA512

but in webcryptocore, there's only algorithm name Hmac.

Looking at what you guys did for sha2, how would it know which one to use?

Or can I use any of the sha schemes?

rmhrisk commented 7 years ago

Webcrypto core is a generic layer we use for input validation in our various WebCrypto libraries.

You would need to add support for HMAC-SHA256 (and maybe HMAC-SHA512) to liner for it to work.

You can use the existing SHA256 code as a guide.

@microshine is busy with another work right now so we cant commit to doing it ourselves in the near term but if you or someone else wanted to add these we would be open to a solid PR.

microshine commented 7 years ago

It'll be helpful if somebody wants to make PR

HMAC examples W3 HMAC specification - webcrypto-core checks incoming data

  1. Create HmacCryptoKey and HmacCrypto, similar to RSA implementation
  2. Add HmacCrypto to SubtleCrypto
  3. Make tests