react-native-pinch icon indicating copy to clipboard operation
react-native-pinch copied to clipboard

react-native-pinch returns error while dealing with self-signed certificate

Open ambilibmenon opened this issue 4 years ago • 1 comments

Generated certificate(.cer file) and added to android/app/src/main/assets/mycert.cer & inside project folder in iOS. But doesn't work on both iOS and Android

For certificate generation :

$ openssl s_client \
  -servername your.service.com \
  -connect your.service.com:443 \
  -prexit \
  -showcerts

Copy the certificate to a new file and save as leaf-certificate.pem. Installed TrustKit in Podfile $ python get_pin_from_certificate.py path/to/leaf-certificate.pem

openssl x509 -in leaf-certificate.pem -outform der -out mycert.cer

Below is my code :

pinch.fetch('https://my_domain:11443/websrc/api/v1.0/auth/login', {
  method: 'post',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json'
},
body: '{"username": "driver1", "password": "password"}',
  timeoutInterval: 10000, // timeout after 10 seconds
  sslPinning: {
    cert: 'mycert', // cert file name without the `.cer`
  }
})
.then((res) => {
    console.log(res)
})
.catch((error) => {
   console.log(error);
})

Output :

In iOS, returns below error TypeError: null is not an object (evaluating '_reactNative.NativeModules.RNPinch.fetch')

In Android, returns below error

javax.net.ssl.SSLPeerUnverifiedException: Hostname my_domain not verified:
    certificate: sha1/N5a+uvPcQhPqz4BSdYCtNEJ2Hlk=
    DN: OU=INS,O=Nest,L=Kochi,ST=Kerala,C=IN
    subjectAltNames: []

ambilibmenon avatar Sep 10 '21 14:09 ambilibmenon