MaxToyberman / react-native-ssl-pinning

React Native ssl pinning and cookies handling based on okhttp3 on (Android). and AFNetworking on (iOS)
MIT License
346 stars 104 forks source link

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

Open ek018 opened 4 years ago

ek018 commented 4 years ago

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

shrynshjn commented 3 years ago

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

shrynshjn commented 3 years ago

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

shrynshjn commented 3 years ago

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.

mkilp commented 3 years ago

@shrynshjn Did you fix it with adding public keys?

shrynshjn commented 3 years ago

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 commented 3 years ago

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

shrynshjn commented 3 years ago

@shrynshjn Did you fix it with adding public keys?

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

mgroupservice commented 1 year ago

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