Search code examples
iosreact-nativessl-certificatetls1.2hl7-fhir

IOS TLS certificat invalid on api request


I'm currently developing a React-Native app (first for IOS) and I have to do an API request on a FHIR connector (medical standard). This API uses a TLS certificate generated by the PKI of my state that is by default not trusted by IOS. I added manually the root certificate G1, the second certificate G2, and the certificate of the API URL.

After it, I trusted the Root certificate using this explanation of the apple support : https://support.apple.com/en-us/HT204477

From now I thought that it was ready to be used and I checked with Chrome and now I have the following error: NET::ERR_CERT_VALIDITY_TOO_LONG

I don't have access to the PKI so I can't generate a certificate with a lowest validity time. After some research I found this : https://support.apple.com/en-us/HT210176

That explains the requirements of certificate TLS to be validated by the OS. I thought that there is no solution except generate a new certificate but I found this : https://support.apple.com/en-us/HT211025

That explains that the certificate installed manually by a user doesn't have to respect the validity of 398 days.

I'm a bit confuse ... My certificate validity time is 10 years. My application React-native work fine with http, but i have the following error with https :

[connection] nw_socket_handle_socket_event [C7:1] Socket SO_ERROR [61: Connection refused]
[connection] nw_connection_get_connected_socket [C7] Client called nw_connection_get_connected_socket on unconnected nw_connection
TCP Conn 0x2835e42c0 Failed : error 0:61 [61]
[native] [GESTURE HANDLER] Initialize gesture handler for root view <RCTRootContentView: 0x106d05890; reactTag: 11; frame = (0 0; 834 1194); gestureRecognizers = <NSArray: 0x280c16640>; layer = <CALayer: 0x280303060>>
Connection 12: default TLS Trust evaluation failed(-9807)
Connection 12: TLS Trust encountered error 3:-9807
Connection 12: encountered error(3:-9807)
Connection 12: unable to determine interface type without an established connection
Task <344A51D7-3F78-47DF-94E4-4A70D6B4E026>.<4> HTTP load failed, 0/0 bytes (error code: -1202 [3:-9807])
Task <344A51D7-3F78-47DF-94E4-4A70D6B4E026>.<4> finished with error [-1202] Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “<API URL REQUEST>” which could put your confidential information at risk." UserInfo={NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, _kCFStreamErrorDomainKey=3, NSErrorPeerCertificateChainKey=(
    "<cert(0x104814000) s: <API URL CERTIF> i: <CERTIF G2>>",
    "<cert(0x104811000) s: <CERTIF G2> i: <CERTIF ROOT G1>>",
    "<cert(0x10488d000) s: <CERTIF ROOT G1> i: <CERTIF ROOT G1>>"
), NSErrorClientCertificateStateKey=0, NSErrorFailingURLKey=<API URL>, NSErrorFailingURLStringKey=<API UTL>, NSUnderlyingError=0x280c36310 {Error Domain=kCFErrorDomainCFNetwork Code=-1202 "(null)" UserInfo={_kCFStreamPropertySSLClientCertificateState=0, kCFStreamPropertySSLPeerTrust=<SecTrustRef: 0x2830f7330>, _kCFNetworkCFStreamSSLErrorOriginalValue=-9807, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9807, kCFStreamPropertySSLPeerCertificates=(
    "<cert(0x104814000) s: <API URL CERTIF> i: <CERTIF G1>>",
    "<cert(0x104811000) s: <CERTIF G2> i: <CERTIF G1>",
    "<cert(0x10488d000) s: <CERTIF G1> i: <CERTIF G1>"
)}},

The question is : Am i doing something wrong or is there any way to use this certificate (10 years validity time) for my application ?

Thank you for helping me


Solution

  • I finally had access to the PKI to generate a TLS certificate with a shorter validity time and this solved my problem. Now the certificate is accepted by IOS. I strongly think that there is no other solutions.