react-native-ssl-pinning icon indicating copy to clipboard operation
react-native-ssl-pinning copied to clipboard

Certificates pinning not working on IOS

Open Caophuc799 opened this issue 2 years ago • 2 comments
trafficstars

I drag mycert.cer to Xcode project, mark my target and 'Copy items if needed' and I use this code, but it does not work:

import {fetch} from 'react-native-ssl-pinning';

fetch('****.com', {
	method: "GET" ,
	timeoutInterval: communication_timeout, // milliseconds
	body: {},
	sslPinning: {
		certs: ["mycert"]
	},
	headers: {
		Accept: "application/json; charset=utf-8", "Access-Control-Allow-Origin": "*", "e_platform": "mobile",
	}
})
.then(response => {
	console.log(`response received ${response}`)
})
.catch(err => {
	console.log(`error: ${err}`)
})

It threw error that: URL unsupport or The certificate for this server is not valid. You may be connecting to a server posing as “****.com”, which could jeopardize your security information.

Can anyone help me? Thanks in Advance

Caophuc799 avatar Jul 13 '23 09:07 Caophuc799

I am having the same problem. Can anyone who has found a solution share it? I am using a self-signed certificate.

suleymanbasbug avatar Sep 05 '23 17:09 suleymanbasbug

For iOS, your certificate must be a valid SSL (eg. not self-signed) and it must be in binary, instead of plain text. Just use the openssl command to generate them.

openssl x509 -in my-site.pem -outform der -out my-site.cer

You can see if its binary of plain text by opening it inside VSCode.

idrakimuhamad avatar Sep 08 '23 09:09 idrakimuhamad