Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Safari Support #995

Closed
lightninglu10 opened this issue Sep 5, 2017 · 9 comments
Closed

Safari Support #995

lightninglu10 opened this issue Sep 5, 2017 · 9 comments
Labels
env:Safari exp/wizard Extensive knowledge (implications, ramifications) required help wanted Seeking public contribution on this issue P2 Medium: Good to have, but can wait until someone steps up

Comments

@lightninglu10
Copy link

  • 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: libp2p/js-libp2p-crypto#18

Getting an error in Safari that

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

Is there anyway to remedy this?

@lightninglu10
Copy link
Author

lightninglu10 commented Sep 6, 2017

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
        }

@daviddias
Copy link
Member

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: libp2p/js-libp2p-crypto#18

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

@daviddias daviddias added kind/bug A bug in existing code (including security flaws) exp/wizard Extensive knowledge (implications, ramifications) required P2 Medium: Good to have, but can wait until someone steps up help wanted Seeking public contribution on this issue labels Sep 6, 2017
@daviddias daviddias changed the title SyntaxError: Bad algorithm name -- IPFS not working in Safari Safari Support Sep 8, 2017
@daviddias daviddias added status/ready Ready to be worked and removed kind/bug A bug in existing code (including security flaws) labels Sep 8, 2017
@bertrandrustle
Copy link

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 libp2p/js-libp2p-crypto#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

@daviddias
Copy link
Member

daviddias commented Oct 9, 2017

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

@bertrandrustle
Copy link

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

@victorb
Copy link
Member

victorb commented Oct 9, 2017

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 (vibornoff/webcrypto-shim#22).

However, there is a merged PR with a working commit though, vibornoff/webcrypto-shim@ae3e9fa made a PR to our fork that fixes it and now it works 🎉

dignifiedquire/webcrypto-shim#2

screen shot 2017-10-09 at 18 46 18

@victorb
Copy link
Member

victorb commented Oct 10, 2017

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!

@daviddias
Copy link
Member

Safari support is here! 🚀

image

image

@alexsicart
Copy link

Ohh coool thanks @diasdavid !!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
env:Safari exp/wizard Extensive knowledge (implications, ramifications) required help wanted Seeking public contribution on this issue P2 Medium: Good to have, but can wait until someone steps up
Projects
None yet
Development

No branches or pull requests

5 participants