Skip to content

Unable to trigger SSLHandshakeException errors with react-native-ssl-public-key-pinning #489

@ismailyagci

Description

@ismailyagci

İşte metnin birinci ağızdan çekilmiş hali:


I am currently experiencing an issue where SSLHandshakeException errors are not being triggered when using the react-native-ssl-public-key-pinning library.

Here is the code for setting up the listener:

import {
  initializeSslPinning,
  addSslPinningErrorListener,
} from 'react-native-ssl-public-key-pinning';

const listener = addSslPinningErrorListener((error) => {
  Alert.alert('SSL Pinning Error', error.message || 'SSL Pinning Error');
});

Unfortunately, errors related to SSLHandshakeException are not being captured by the listener. I attempted to reproduce the issue using mitmproxy for interception but couldn't trigger the error in this way.

Suggested Solution:

As a potential solution, I suggest modifying the code to catch SSLHandshakeException and SSLPeerUnverifiedException exceptions in the intercept method:

@NonNull
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
  Request request = chain.request();
  try {
    return chain.proceed(request);
  } catch (SSLPeerUnverifiedException | SSLHandshakeException e) {
    String message = e.getMessage();
    if (message != null) {
      emitPinningErrorEvent(request, message);
    }
    throw e;
  }
}

This solution would allow the listener to receive the error messages correctly.

Next Steps:

  • I would appreciate it if a similar approach could be implemented on the iOS side as well.
  • Any insights on how to replicate this issue on iOS would be very helpful, as I haven’t tested it there yet.

Environment:

  • React Native version: 0.74.5
  • react-native-ssl-public-key-pinning version: 1.2.5
  • Platform(s): Android (and iOS if applicable)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions