Code Monkey home page Code Monkey logo

Comments (5)

siyengar avatar siyengar commented on August 24, 2024

I'll try to get one of these devices to repro this. I agree with your point about the hiding of the original exception. I will change it so that the original exception is the cause of the new one. I'll get this fix out today.

We decided to throw rather than not throw since this has security implications and we'd rather not promise that we're generating random numbers if we're not actually generating random numbers. I would rather solve the original cause. My best guess right now without a stack trace is that it is a SELinux violation. I'll put up a version with the fix above, so that we can get a stack trace and debug the root cause.

Are you also getting these violations when running with robolectric. That's strange, because we have robolectric tests in the repo which actually exercises this code. Take a look at SharedPrefsBackedKeyChainTest in javatests/

from conceal.

lnanek avatar lnanek commented on August 24, 2024

Hmm, I wouldn't really expect Robolectric to work. Here's a typical Robolectric error on a Mac here:

        Caused by:
        com.facebook.crypto.exception.CryptoInitializationException: java.lang.UnsatisfiedLinkError: no cryptox in java.library.path
            at com.facebook.crypto.util.SystemNativeCryptoLibrary.ensureCryptoLoaded(SystemNativeCryptoLibrary.java:41)
            at com.facebook.crypto.cipher.NativeGCMCipher.encryptInit(NativeGCMCipher.java:54)
            at com.facebook.crypto.CipherHelper.getCipherOutputStream(CipherHelper.java:38)
            at com.facebook.crypto.Crypto.encrypt(Crypto.java:102)
            at PLACE_USED
            ... 2 more

            Caused by:
            java.lang.UnsatisfiedLinkError: no cryptox in java.library.path
                at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
                at java.lang.Runtime.loadLibrary0(Runtime.java:849)
                at java.lang.System.loadLibrary(System.java:1088)
                at com.facebook.crypto.util.SystemNativeCryptoLibrary.loadLibraries(SystemNativeCryptoLibrary.java:51)
                at com.facebook.crypto.util.SystemNativeCryptoLibrary.ensureCryptoLoaded(SystemNativeCryptoLibrary.java:40)
                ... 6 more

Since Robolectric can't load native libraries anyway. Still trying to figure what parts I need to make fake implementations of and drop into place in the test application subclass to make Robolectric able to continue on its way. Real encryption isn't needed there, but not blowing up is.

from conceal.

lnanek avatar lnanek commented on August 24, 2024

Ah, the Motorola Solutions crash was it detecting a different copy of the PRNG fix from that Android blog post being installed by some other code. After I added initCause I got this:

E/AndroidRuntime( 9787): Caused by: com.facebook.crypto.exception.KeyChainException: Random number generated
E/AndroidRuntime( 9787):    at com.facebook.crypto.keychain.FixedSecureRandomFix.tryApplyFixes(FixedSecureRandomFix.java:69)
E/AndroidRuntime( 9787):    at com.facebook.crypto.keychain.FixedSharedPrefsBackedKeyChain.getNewIV(FixedSharedPrefsBackedKeyChain.java:79)
E/AndroidRuntime( 9787):    at com.facebook.crypto.CipherHelper.getCipherOutputStream(CipherHelper.java:36)
E/AndroidRuntime( 9787):    at com.facebook.crypto.Crypto.encrypt(Crypto.java:102)
E/AndroidRuntime( 9787):    at PLACE_USED
E/AndroidRuntime( 9787):    ... 16 more
E/AndroidRuntime( 9787): Caused by: java.lang.SecurityException: new SecureRandom() backed by wrong Provider: class OTHER_PACKAGE.PRNGFixes$LinuxPRNGSecureRandomProvider
E/AndroidRuntime( 9787):    at com.facebook.crypto.keychain.FixedSecureRandomFix.tryInstallLinuxPRNGSecureRandom(FixedSecureRandomFix.java:189)
E/AndroidRuntime( 9787):    at com.facebook.crypto.keychain.FixedSecureRandomFix.tryApplyFixes(FixedSecureRandomFix.java:63)
E/AndroidRuntime( 9787):    ... 20 more

The other copy is already a source dependency instead of an AAR dependency, so I can just change it to use Facebook's.

from conceal.

siyengar avatar siyengar commented on August 24, 2024
  • Our robolectric tests don't actually touch places that load native code. That gets a little bit tricky to test. You'd probably have to find a way to load the x86 binary versions in memory before invoking the Crypto class. We instead have instrumentation tests for those cases which test all of the crypto functions.
    If a class is using Crypto, I suggest you mock out the Crypto class using easy mock or something if you want to run tests against crypto as you have mentioned.
  • That's great to know about the crash is solved. I will close out this task with a follow up to add cause to the exception. We have made it a point to not include detailed stack traces in order to minimize oracles about where the encryption failed, but in this case it seems fine to include it. Please re-open if you have other concerns.

from conceal.

siyengar avatar siyengar commented on August 24, 2024

#31

from conceal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.