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

fetch() gives SSL error on iOS, use of own trust manager but none defined on Android #166

Closed
reeinohio opened this issue Jun 23, 2022 · 7 comments
Labels

Comments

@reeinohio
Copy link

reeinohio commented Jun 23, 2022

rn-fetch-blob isn't working anymore when I upgraded to RN 0.67.4 and target/compile for android 12 (SDK 31). Now, I am trying react-native-blob-util to replace rn-fetch-blob, however it is giving me an error during fetch call. The error I got is similar for both android or iOS.
On iOS I get:
[Error: An SSL error has occurred and a secure connection to the server cannot be made.]
On Android I get:
[Error: ReactNativeBlobUtil request error: java.lang.IllegalStateException: Use of own trust manager but none definedjava.lang.IllegalStateException: Use of own trust manager but none defined]

Any ideas what maybe causing this or suggested changes i should do?
Any input will highly appreciated. Thank you!

  • Library versions and config
    react-native-blob-util 0.16.0
    react-native 0.67.4
    Android build.gradle: Compile and target SDK: 31
  • Sample code
import ReactNativeBlobUtil from "react-native-blob-util";
import { Platform, PermissionsAndroid } from "react-native";

...
let allPermissionsGranted = false;
if (Platform.OS === "android") {
   const granted = await PermissionsAndroid.requestMultiple([
            PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
            PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
        ]);
   allPermissionsGranted =
            granted["android.permission.READ_EXTERNAL_STORAGE"] === "granted" && granted["android.permission.WRITE_EXTERNAL_STORAGE"] === "granted";
}
try {
  const res = await ReactNativeBlobUtil.config({
                trusty: true,
                fileCache: false,
                path: directory + "/" + filename,
            }).fetch("GET", docUrl, headers);
  const status = res.info().status;
  if (status === 200) {
      if (Platform.OS === "ios") {
          ReactNativeBlobUtil.ios.openDocument(res.path());
       } else {
           if (allPermissionsGranted) {
               const android = ReactNativeBlobUtil.android;
               android.actionViewIntent(res.path(), mimetype);
           }
         }
      }
    } else {
       console.log("Error fetching file");
       throw new Error("...")
    }
} catch (e) {
    console.error(e);
}
@RonRadtke
Copy link
Owner

Yes you're using trusty = true.
The implementation changed so you need to specify your own trustmanager for that.
Please check the readme to see how you can do that.

@dirkpostma
Copy link

dirkpostma commented Jan 19, 2023

@RonRadtke Request: I think there needs to be added an import on top of MainApplication.java in order to specify the trustmanager. Can this be added to the README how to do that..? And/or mention here in ticket. Thanks!

@timothyerwin
Copy link

it's failing in iOS on the simulator (v16) no matter what is set for trusty.

@msbit
Copy link

msbit commented Jul 3, 2023

@RonRadtke did you consider using a system provided trust manager (something like this) instead of requiring the user to provide it?

EDIT:

Disregard this, I'm troubleshooting an issue a couple of levels of dependencies deep, and I see that an intermediate dependency is setting the trusty flag, causing the error I'm seeing ✌️

@RonRadtke
Copy link
Owner

@RonRadtke did you consider using a system provided trust manager (something like this) instead of requiring the user to provide it?

EDIT:

Disregard this, I'm troubleshooting an issue a couple of levels of dependencies deep, and I see that an intermediate dependency is setting the trusty flag, causing the error I'm seeing ✌️

So your problem is solved?

The reason I require the user to set it, is that in the past we had reports about denied apps due to it.
Google does a static code analysis and recognized a trust manager that just allows everything. And by that the app got denied.

@RonRadtke
Copy link
Owner

@RonRadtke Request: I think there needs to be added an import on top of MainApplication.java in order to specify the trustmanager. Can this be added to the README how to do that..? And/or mention here in ticket. Thanks!

Yes I will fix that in the readme. There is also another issue about the trustmanager in the readme i habe to fix.

@msbit
Copy link

msbit commented Jul 8, 2023

So your problem is solved?

Yep, solved, thanks for checking in.

The reason I require the user to set it, is that in the past we had reports about denied apps due to it. Google does a static code analysis and recognized a trust manager that just allows everything. And by that the app got denied.

Interesting! and a good thing to know for future submissions to the app stores 👍

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

No branches or pull requests

5 participants