kevlened / jose

:globe_with_meridians: Collection of JSON Web libraries

Home Page:http://jose.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple installs of msrcrypto

JohanObrink opened this issue · comments

When using jwt-lite in a react-native application, mrscrypto gets installed twice, once in a sub node_modules folder of jwk-lite and once in jws-lite. This makes signing crash since the key is imported into one in-memory object and then fails to be retrieved from another instance.

Befor my PR was accepted, I made a fork of all the npm packages to be able to continue working and that version works with msrcrypto being installed in the root node_modules.

The only difference I can find is in the dependency version of isometric-crypto but my packages require that with ^ so it should work the same.

My fork of the libraries can be found at @egendata/jwt-*with all repos under the https://github.com/egendata organization.

If you want to reproduce the error, clone the app repo, run it in ios or android and go through register (just fill in anything and click the buttons choosing [In memory] when asked.

Based on the package-lock.json in the app, the scenario seems like an npm issue. What happens if you delete node_modules and reinstall? (I'm currently installing everything for the app, but it's taking a while)

update: registration fails on Lagring - when deciding between dropbox or local. (Un)fortunately, I couldn't repro on a smaller example.

I tried reinstalling with a complete nuking of the npm cache but to no avail.

The moment it fails (on Lagring) is when it tries to sign a JWS for the first time. If you look in the inspector (sources) you can see that this is due to msrcrypto being imported locally for jwk-lite and jws-lite. That means it cannot find the key since it is cached in another memory structure - hence the weird error message.

I still wasn't able to get past that screen, but here's an example showing that jwt-lite (2.1.0) probably isn't the problem: https://github.com/kevlened/app/commit/0ed44f9248b6db5f393aac5db0a7a74b6c076861

OMG! This is so weird :/ When I run your code, it still fails with key not found (even after updating dep to 2.1.0)... but when I switch to @egendata/jwt-lite it works.

...and I still see the local imports of msrcrypto which explains the failure. What I cannot explain though is why it works on your machine and not mine :(

God I hate non reproducable bugs! I'll ask some collegues to test it as well to see if we can nail it down. Thanks for all the help!

🤔 this is really weird. Is msrcrypto symlinked? It's a shot in the dark, but you could try npm unlink msrcrypto in your project's root.

I definitely did not symlink it... but then again I'll try anything 😉

Sadly it did nothing. The dependency tree still looks like this 😢

image

Here are some quick instructions for your colleagues that try to reproduce the success case:

git clone git@github.com:kevlened/app.git
cd app && npm install && npm run link && cd ios && pod install && cd ..
npm run ios

Turn on debugging, then check the resulting Chrome debug console. You should see this when the app starts:

Screen Shot 2019-09-10 at 9 05 06 AM

No need. I cloned the repo (rather than modifying my code with your example) and it runs just fine. Obviously something is wrong with my setup. I will compare them and fix it myself. Thanks for all the help!

Glad you got it running!