Skip to content

Node RSA is broken with React Native #9427

Closed

Description

@SamSaffron

https://github.com/rzcoder/node-rsa is broken in React Native for some reason:

image

This is also reported here:

rzcoder/node-rsa#65

This ticket is mentioned but I do not think it is exactly the same.

#4968

Activity

  1. SamSaffron commented on Aug 16, 2016

    @SamSaffron
    Author

    Some further analysis shows that the root of the issue is that react native does not ship with the native nodejs crypto module.

  2. ryankask commented on Aug 16, 2016

    @ryankask
    Contributor

    react-native doesn't use node to run apps so you can't access any node modules. You can read about the JS environment here: https://facebook.github.io/react-native/docs/javascript-environment.html.

    Check out js.coach for some of the available crypto packages available on npm.

    Please let me know if there's any other way I can help.

  3. ryankask commented on Aug 16, 2016

    @ryankask
    Contributor
  4. ghost closed this as completedon Aug 16, 2016
  5. ghost added
    Ran CommandsOne of our bots successfully processed a command.
    on Aug 16, 2016
  6. SamSaffron commented on Aug 16, 2016

    @SamSaffron
    Author

    @ryankask I still feel react native could be doing a bit better here...

    • If in dev
    • and you require something that can not be found
    • and that module ships with node.js (should be straightforward to get the list)
    • display a custom message that informs user about this issue (eg: you are trying to require a module that ships with node and does not exist in react native)

    long term backfilling some of the modules also makes sense, crypto could be implemented in pure js, for example

    btw @facebook-github-bot-2 http://blog.stackoverflow.com/2010/06/welcome-stack-overflow-valued-associate-00008/ I know its a robot ... still :)

  7. ryankask commented on Aug 16, 2016

    @ryankask
    Contributor

    I knew the bot's response would be awkward 😄

    Better error messages are always good. I've seen this happen a few times so the JS environment doc could make it clear that your app isn't running node and the node packages aren't available.

    I think if anything the W3C's Web Cryptography API could be implemented although I'm not sure if anyone would maintain that.

  8. SamSaffron commented on Aug 16, 2016

    @SamSaffron
    Author

    @ryankask no worries at all :)

    Web Crypto API would be fantastic addition. Though perhaps there are some smaller steps that can be taken first.

    I think the big problem at the moment in the RSA department is that too many people are now leaning on "pure JS" implementations and the trouble is you can not properly get random numbers from pure JS cause you can't get entropy and need to lean native implementations for that.

    Perhaps a smaller addition that could at least pave the way for proper crypto would be simply implementing https://developer.mozilla.org/en-US/docs/Web/API/RandomSource/getRandomValues (which would be a tiny subset of the crypto api, but "unlock" the ability to do RSA key generation properly.)

  9. ide commented on Aug 16, 2016

    @ide
    Contributor

    React Native is a third JS environment. Similar to how you don't expect document.createElement to work in Node or require('http') to work in Chrome, expect modules that haven't been written with React Native not to always work.

    Implementing async crypto primitives is maybe a good idea and someone should try it and publish their package to npm if it works well.

  10. locked as resolved and limited conversation to collaborators on May 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.Resolution: LockedThis issue was locked by the bot.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions