react-native-google-safetynet icon indicating copy to clipboard operation
react-native-google-safetynet copied to clipboard

[Bug] Application crashed while using sendAndVerifyAttestation method

Open karandpr opened this issue 6 years ago • 12 comments
trafficstars

Application crashed while using sendAndVerifyAttestation method. The logs were not very helpful. I will investigate when I have time. For now creating an issue.

My app details

"react": "16.8.3",
"react-native": "0.59.1",
"react-native-google-safetynet": "^0.3.3"

Code Block

    RNGoogleSafetyNet.sendAndVerifyAttestation('asdas','API_KEY').then((res) => {
      console.log('send&verify', res);
    }).catch(err => {
      console.error('send&ver', err);
    })

Error Logs

E ReactNativeJS: 'send&ver', { [Error: 10: ]
E ReactNativeJS:   framesToPop: 1,
E ReactNativeJS:   nativeStackAndroid:
E ReactNativeJS:    [ { methodName: 'fromStatus', lineNumber: 14, file: null },
E ReactNativeJS:      { methodName: 'convert', lineNumber: 0, file: null },
E ReactNativeJS:      { methodName: 'onComplete', lineNumber: 32, file: null },
E ReactNativeJS:      { methodName: 'zza', lineNumber: 81, file: null },
E ReactNativeJS:      { methodName: 'setResult', lineNumber: 41, file: null },
E ReactNativeJS:      { methodName: 'zza', lineNumber: 7, file: null },
E ReactNativeJS:      { methodName: 'dispatchTransaction',
E ReactNativeJS:        lineNumber: 155,
E ReactNativeJS:        file: null },
E ReactNativeJS:      { methodName: 'onTransact', lineNumber: 22, file: null },
E ReactNativeJS:      { methodName: 'execTransact',
E ReactNativeJS:        lineNumber: 731,
E ReactNativeJS:        file: 'Binder.java' } ],
E ReactNativeJS:   userInfo: null,
E ReactNativeJS:   code: 'EUNSPECIFIED',
E ReactNativeJS:   line: 2108,
E ReactNativeJS:   column: 26,

karandpr avatar Mar 26 '19 13:03 karandpr

Hmm, that's weird. I'll look into this now

rajivshah3 avatar Mar 29 '19 22:03 rajivshah3

@karandpr I can't seem to reproduce this on the (newly added) example app in the repo. I noticed you're using RN 0.59 though, so that might be the cause. I haven't tested the module with that version of RN yet

rajivshah3 avatar Apr 08 '19 02:04 rajivshah3

I see. I will check if it's fixed in latest version.

karandpr avatar Apr 08 '19 09:04 karandpr

@karandpr are you still seeing issues?

rajivshah3 avatar May 27 '20 19:05 rajivshah3

Ha. I never got around testing in new version. I will make a sample project with 0.63 ( After 5 June) and see if I can reproduce and troubleshoot. Looks like we have a duplicate ? https://github.com/rajivshah3/react-native-google-safetynet/issues/369

karandpr avatar May 27 '20 19:05 karandpr

Ah yikes, didn't even notice that it was a duplicate. I need to be better about managing this repo 😅

rajivshah3 avatar May 27 '20 19:05 rajivshah3

It's alright. I will see if I can find why it's failing on newer react versions (or certain versions ?).

karandpr avatar May 27 '20 19:05 karandpr

@karandpr you are passing the wrong nonce value. Either generate it with generateNonce function of the library or you can generate it with Math functions.

Math.round(Math.pow(36, 16 + 1) - Math.random() * Math.pow(36, 16))
    .toString(36)
    .slice(1)

Miti063 avatar May 28 '20 09:05 Miti063

@Miti063 Well you are right , but this is not why the error occurred.

I agree, it's no ideal nonce but this is demo code and that nonce works with Native Android SafetyNet , earlier version of react and my implementation in ionic. I have discussed nonce in a feature request earlier (https://github.com/rajivshah3/react-native-google-safetynet/issues/136) . As a plug I have covered SafetyNet and nonce generation in an article published last year (https://blog.jscrambler.com/extended-guide-to-safetynet/).

karandpr avatar May 28 '20 11:05 karandpr

@karandpr Agreed that it's demo code, but because of that nonce, it's not able to convert into byte using Base64 which is mentioned in the RNGoogleSafetyNetModule.java file & causes the app to crash.

Miti063 avatar May 28 '20 13:05 Miti063

Hey @Miti063 . Interesting. Thanks to your observation I have some pointers towards the issue. @rajivshah3 Hey Rajiv ,so here is the weird thing. I have checked in version 0.62.2

let nonce = "asdas";
 RNGoogleSafetyNet.sendAndVerifyAttestation(nonce,'API_KEY').then((res) => {
      console.log('send&verify', res);
    }).catch(err => {
      console.error('send&ver', err);
    })

The code doesn't work if nonce string length is

  • 1
  • 5 (asdas) My original issue.
  • 9
  • 17
  • 33
  • ~~2^n + 1~~/ 4n + 1

I will look into this later. Thanks again @Miti063 .

karandpr avatar May 28 '20 14:05 karandpr

Sorry for the long delay. I think #399 might help figure out where this is coming from. My guess is that it's having trouble decoding nonces like asdas

rajivshah3 avatar Jul 19 '20 15:07 rajivshah3