Js-ipfs: Safari Support

Created on 6 Sep 2017  Â·  9Comments  Â·  Source: ipfs/js-ipfs

  • Version: 0.25.0
  • Platform: JS
  • Subsystem:

Type: Bug

Severity: High

Description: IPFS does not work in Safari. It looks like something dealing with the webcrypto package here: https://github.com/libp2p/js-libp2p-crypto/issues/18

Getting an error in Safari that

alg — ipfs.min.js:42864SyntaxError: Bad algorithm name

Is there anyway to remedy this?

P2 diexpert Safari help wanted

Most helpful comment

Safari support is here! 🚀

image

image

All 9 comments

Tracked it down to an algorithm named ECDH in this part of the code:

function alg(a) {
            var r = {
                name: (a.name || a || "").toUpperCase().replace("V", "v")
            };
            switch (r.name) {
            case "SHA-1":
            case "SHA-256":
            case "SHA-384":
            case "SHA-512":
                break;
            case "AES-CBC":
            case "AES-GCM":
            case "AES-KW":
                a.length && (r.length = a.length);
                break;
            case "HMAC":
                a.hash && (r.hash = alg(a.hash)), a.length && (r.length = a.length);
                break;
            case "RSAES-PKCS1-v1_5":
                a.publicExponent && (r.publicExponent = new Uint8Array(a.publicExponent)), a.modulusLength && (r.modulusLength = a.modulusLength);
                break;
            case "RSASSA-PKCS1-v1_5":
            case "RSA-OAEP":
                a.hash && (r.hash = alg(a.hash)), a.publicExponent && (r.publicExponent = new Uint8Array(a.publicExponent)), a.modulusLength && (r.modulusLength = a.modulusLength);
                break;
            default:
                throw new SyntaxError("Bad algorithm name")
            }
            return r
        }

Thanks for reporting this @lightninglu10. It is a known issue for a while as we focused on developing for Chrome and Firefox (due to their WebRTC support). See compat table here: https://github.com/libp2p/js-libp2p-crypto/issues/18

This means that missing alg need to be shimmed. Is this something you would like to help with?

A major version of Safari (11.0) was released a couple of weeks ago. The WebCrypto API section of the release notes is a little vague and the JS API docs are even less informative, but the release appears to include recent commits to WebKit adding support for the remaining WebCrypto spec ciphers mentioned in https://github.com/libp2p/js-libp2p-crypto/issues/18. See:

https://bugs.webkit.org/show_bug.cgi?id=166746
https://bugs.webkit.org/show_bug.cgi?id=160880
https://trac.webkit.org/browser/webkit/releases/Apple/Safari%2011.0/WebCore/crypto/algorithms

Do we have a volunteer to go and test these new grounds? Thank you for the update, @bertrandrustle

Here's an exhaustive browser test of the WebCrypto API:
https://diafygi.github.io/webcrypto-examples/

Source code:
https://github.com/diafygi/webcrypto-examples/

When Safari is detected the test shims in Safari's soon-to-be-removed crypto.webKitSubtle JS interface. These are the results using Safari 11:

webcryptoapi live table

So that interface already seems to support everything IPFS needs. After modifying the test to make Safari use the standard crypto.subtle interface instead, the results with Safari 11 are identical (except now there's no warning in the console about the deprecated crypto.webKitSubtle):

webcryptoapi live table - crypto subtle

Got × Unhandled Rejection (TypeError): Member JsonWebKey.kty is required and must be an instance of DOMString from webcrypto-shim which there is a open issue for (https://github.com/vibornoff/webcrypto-shim/issues/22).

However, there is a merged PR with a working commit though, https://github.com/vibornoff/webcrypto-shim/pull/15/commits/ae3e9fa3ad0cf24748c9025085b4883ba8ed0038 made a PR to our fork that fixes it and now it works 🎉

https://github.com/dignifiedquire/webcrypto-shim/pull/2

screen shot 2017-10-09 at 18 46 18

PR linked in previous commit has been merged and libp2p-crypto module points to github:dignifiedquire/webcrypto-shim#master so no more changes should be required (just another npm install), js-ipfs should work on Safari 11 now!

Safari support is here! 🚀

image

image

Ohh coool thanks @diasdavid !!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ntmf picture Ntmf  Â·  4Comments

lifeBCE picture lifeBCE  Â·  3Comments

daviddias picture daviddias  Â·  3Comments

beingmohit picture beingmohit  Â·  3Comments

fazo96 picture fazo96  Â·  3Comments