Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PREDICTABLE RANDOM NUMBER GENERATOR [Security issue] #57

Open
lhuria94 opened this issue Jun 10, 2020 · 6 comments
Open

PREDICTABLE RANDOM NUMBER GENERATOR [Security issue] #57

lhuria94 opened this issue Jun 10, 2020 · 6 comments

Comments

@lhuria94
Copy link

Issue:
The mobile application uses a predictable Random Number Generator (RNG).
Under certain conditions this weakness may jeopardize mobile application data encryption or other protection based on randomization. For example,
if encryption tokens are generated inside of the application and an attacker can provide application with a predictable token to validate and then
execute a sensitive activity within the application or its backend.

Reference:

Can you help if this is related to crypto randomBytes function?

@mvayngrib
Copy link
Member

@lhuria94 what makes u say it uses a predictable random number generator?

@lhuria94
Copy link
Author

lhuria94 commented Jun 10, 2020

I am not saying, its the scan by the security team.

Here is the example reference they provided:
Screenshot 2020-06-10 at 5 48 57 PM

Screenshot 2020-06-10 at 5 49 40 PM

With details like:

  • Binary match usage of 'random' function/method.
    • Binary match usage of 'srand' function/method.

@mvayngrib
Copy link
Member

this it the randombytes module used: https://github.com/mvayngrib/react-native-randombytes

the method of getting random bytes depends on async/sync usage: https://github.com/mvayngrib/react-native-randombytes#usage

the async method: https://github.com/mvayngrib/react-native-randombytes/blob/master/RNRandomBytes.m#L32

the sync method uses SJCL with a random seed generated by SecRandomCopyBytes

@lhuria94
Copy link
Author

Oh okay, that means instead of using it like:
const password = crypto.randomBytes(10).toString('hex');

We should use:

// asynchronous API
// uses iOS-side SecRandomCopyBytes
const password = randomBytes(10, (err, bytes) => {
  // bytes is a Buffer object
  return bytes.toString('hex'));
})

@mvayngrib
Copy link
Member

@lhuria94 yes, that would be the more secure way to use it. I've been meaning to update react-native-randombytes to use the newly available synchronous react-native bridge methods (via RCT_EXPORT_SYNCHRONOUS_TYPED_METHOD), so that the sync method would work as well but haven't gotten to it yet

@lhuria94
Copy link
Author

No worries, Thanks a lot for the quick help. Ill update if this resolves the security issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants