Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to accept self-signed certificate with asihttprequest

I am trying to get a self-signed certificate to work with my application.

I am using the ASIHTTPRequest library at the moment like so :

- (IBAction)sendHttpsRequest
{    
    //Set request address
    NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"https://142.18.87.46:443"];

    //call ASIHTTP delegates (Used to connect to database)
    NSURL *url = [NSURL URLWithString:databaseURL];

    //This sets up all other request
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    [request setDelegate:self];
    [request setValidatesSecureCertificate:YES];
    [request startAsynchronous];
}

I have set setValidatesSecureCertificate to YES in the hope that something would happen but obviously nothing has because I'm not sure what I have to do.

This is the error I'm getting in my log

2011-12-06 14:27:33.514 connectionTest[916:207] Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred: SSL problem (Possible causes may include a bad/expired/self-signed certificate, clock set to wrong date)" UserInfo=0x683a860 {NSUnderlyingError=0x68390d0 "The operation couldn’t be completed. (OSStatus error -9807.)", NSLocalizedDescription=A connection failure occurred: SSL problem (Possible causes may include a bad/expired/self-signed certificate, clock set to wrong date)}

Any help would be greatly appreciated.

like image 336
C.Johns Avatar asked Dec 06 '11 01:12

C.Johns


People also ask

How to create self-signed certificates?

You can create self-signed certificates using commands or automate them using a shell script by following this guide. Openssl is a handy utility to create self-signed certificates. You can use OpenSSL on all the operating systems such as Windows, MAC, and Linux flavors.

How do I use a self-signed public certificate for testing?

For testing, you can use a self-signed public certificate instead of a Certificate Authority (CA)-signed certificate. This article shows you how to use Windows PowerShell to create and export a self-signed certificate. Using a self-signed certificate is only recommended for development, not production.

How do I remove a self-signed certificate?

First, run the following command to retrieve the certificate thumbprint. Then, copy the thumbprint that is displayed and use it to delete the certificate and its private key. The self-signed certificate you created following the steps above has a limited lifetime before it expires.

How do I create a self-signed certificate in azure automation?

Your application running in Azure Automation will use the private key to initiate authentication and obtain access tokens for Microsoft Graph. This article uses the New-SelfSignedCertificate PowerShell cmdlet to create the self-signed certificate and the Export-Certificate cmdlet to export it to a location that is easily accessible.


1 Answers

I have set setValidatesSecureCertificate to YES in the hope that something would happen but obviously nothing has because I'm not sure what I have to do.

This is the problem. It defaults to YES and you need to set it to NO. As your certificate is self-signed, iOS can't validate the certificate - there is no trusted authority in the system that has signed the certificate, so it has no basis for saying that it is valid. So if you ask it to validate the certificate (which is the default), it has to reject it. You have to disable certificate validation to get self-signed certificates to work.

like image 120
Jim Avatar answered Oct 13 '22 01:10

Jim