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

[IOS] Crash [__NSArrayM insertObject:atIndex:]: object cannot be nil

Open ek018 opened this issue 4 years ago • 8 comments

Hello @MaxToyberman ,

For these 2 weeks on IOS app always got crash from thread [__NSArrayM insertObject:atIndex:]: object cannot be nil Using this code was work on Android but always got crash on IOS, Could you elaborate how to solve this?

Thanks,

Code

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

static sslPinning(
		axiosInstance,
		url: string,
		method: string,
		body?: any,
		incomingConfig?: {[key: string]: any},
	): Promise<any> {
		const requestBodyJSON = body && JSON.stringify(body)
		const requestURL = axiosInstance.defaults.baseURL + url

		const config = {
			timeoutInterval: 10000,
			sslPinning: {
				certs: ["19_9_2021"]
			},
			headers: axiosInstance.defaults.headers.common,
			method,
			...(body && { body: requestBodyJSON }),
			...(incomingConfig && incomingConfig),
		}

		return sslFetch(requestURL, config)
			.then(response => {
				console.log("[ServiceUtils] sslPinning ssFetch response ",response)
				})
			.catch( error => {
				console.log("[ServiceUtils] sslPinning ssFetch error",error)
			});
	}

Setup

Screen Shot 2020-09-22 at 16 51 15

Error

Screen Shot 2020-09-22 at 16 51 33 Screen Shot 2020-09-22 at 17 21 02

Environment

  • react-native version 0.61.5
  • react-native-ssl-pinning 1.5.0

ek018 avatar Sep 22 '20 10:09 ek018

Hi @ek018 , Were you able to fix the issue, if yes, would you mind sharing the solution? Thanks

shrynshjn avatar May 27 '21 17:05 shrynshjn

@MaxToyberman this is the same issue as #60 but there isnt any conculsive solution for the problem, is pkPinning mandatory for certificate pinning?

shrynshjn avatar May 28 '21 09:05 shrynshjn

Make sure the certificate file use you are using is in binary format and ".cer" extension, the AFSecurity only supports binary format certificates and not plain text certificates. As both certificates could have an extension of .cer this is most likely the reason why it was failing, as it was in my case. To check if it is in binary format or not, just open the contents of the file, if it has words BEING KEY, END key then its plain text and the certificate can easily be converted to binary format using online tools or a command prompt command.

shrynshjn avatar May 30 '21 11:05 shrynshjn

@shrynshjn Did you fix it with adding public keys?

mkilp avatar Aug 23 '21 16:08 mkilp

Yes. @mkilp, the certificate should be in the proper format. The steps in documentation works fine, it just doesn't mention the format of the public certificate

shrynshjn avatar Aug 23 '21 17:08 shrynshjn

Make sure it's a binary certificate with .cer extension

shrynshjn avatar Aug 23 '21 17:08 shrynshjn

@shrynshjn Did you fix it with adding public keys?

adding public key pinning is not mandatory, only certificate pinning works, with the right certficate

shrynshjn avatar Aug 24 '21 23:08 shrynshjn

Make sure the certificate file use you are using is in binary format and ".cer" extension, the AFSecurity only supports binary format certificates and not plain text certificates. As both certificates could have an extension of .cer this is most likely the reason why it was failing, as it was in my case. To check if it is in binary format or not, just open the contents of the file, if it has words BEING KEY, END key then its plain text and the certificate can easily be converted to binary format using online tools or a command prompt command.

You are a life saver

mgroupservice avatar Sep 06 '23 09:09 mgroupservice