frw / react-native-ssl-public-key-pinning

Simple and secure SSL public key pinning for React Native. No native configuration needed, set up in <5 minutes.
MIT License
178 stars 13 forks source link

Initialization failed due to "package doesn't seem to be linked" error #404

Closed dtalbot-goto closed 1 week ago

dtalbot-goto commented 1 month ago

I'm working on an app where turbo modules are not enabled. I've been trying to initialize SSL pinning on my App's componentDidMount. In fact, I've been trying at different places:

import { addSslPinningErrorListener, initializeSslPinning } from 'react-native-ssl-public-key-pinning';
try {
    logger.info('SSL pinning initialization...');

    await initializeSslPinning({
    'google.com': {
      includeSubdomains: true,
      publicKeyHashes: [
        'CLOmM1/OXvSPjw5UOYbAf9GKOxImEp9hhku9W90fHMk=',
        'hxqRlPTu1bMS/0DITB1SSu0vd4u/8l8TjPgfaAp63Gc=',
        'Vfd95BwDeSQo+NUYxVEEIlvkOlWY2SalKK1lPhzOx78=',
        'QXnt2YHvdHR3tJYmQIr0Paosp6t/nggsEGD4QJZ3Q0g=',
        'mEflZT5enoR1FuXLgYYGqnVEoZvmf9c2bVBpiOjYQ0c=',
      ],
    },
  });
  } catch (error) {
    logger.error('SSL pinning initialization failed', JSON.stringify(error));
  }

This error is always thrown:

[Error: The package 'react-native-ssl-public-key-pinning' doesn't seem to be linked. Make sure: 

- You rebuilt the app after installing the package
- You are not using Expo Go
]

Looking at this other issue (https://github.com/frw/react-native-ssl-public-key-pinning/issues/329) I believe I'm importing correctly in package.json dependencies. My typescript is at 4.9.5, babel:

"@babel/core": "7.20.12",
"@babel/node": "7.20.7",
"@babel/parser": "7.20.15",

Updating them would be difficult... I'm not sure the error is related though. Could it be related to the fact that NativeModules.SslPublicKeyPinning is not properly set ?

Thanks for your help

frw commented 1 month ago

The error message is indicating that the library is not properly linked (i.e. the native code for ssl pinning is not included in the build)

A couple of questions:

dtalbot-goto commented 1 month ago

Hi, thanks for replying. I am:

frw commented 1 month ago

Are you able to provide a repo with a minimal reproducible example? Unfortunately I'm not sure where the problem lies with just this information. You can also refer to the example app to see if there are any differences in setup.

dtalbot-goto commented 1 month ago

I think part of the issue might be that I added the package in package.json and did yarn install. I thought linking would be done automatically. I'm on a big project with lots of dependencies, it will be difficult to reproduce. I already had a look at your example project but I didn't find anything helping my situation yet. I must find a way to link the native manually I think. I'll investigate further and post my findings here.

frw commented 1 month ago

Linking should generally happen automatically, so it's weird that it didn't happen in your case. Try deleting node_modules and re-running yarn install.

You mentioned that you are using this in a project "where turbo modules are not enabled". How exactly is turbo modules turned off?

dtalbot-goto commented 1 month ago

I'll do as you mention. Turbo modules are disabled at initialization. Though there is a fallback on your lib so this should not impact I think. We'll investigate more on why the linking is not done automatically.

frw commented 1 week ago

Closing this due to inactivity. Please reopen an issue if you're still facing issues.