简体   繁体   中英

Connecting to the HTTPS using self signed SSL certificate

I've a problem connecting to the server using SSL. I'm using ASIHTTPRequest.

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"https://server:port"]];
//[request setValidatesSecureCertificate:NO];
[request setRequestMethod:@"POST"];
[request setTimeOutSeconds:10];

[request addRequestHeader:@"Host" value:@"server:port"];    
[request addRequestHeader:@"Content-Type" value:@"text/json; charset=utf-8"];

Above gives me the "A connection failure occurred: SSL problem (possibly a bad/expired/self-signed certificate)". If I uncomment the line [request setValidatesSecureCertificate:NO]; I get 404.

I know that that in the development environment the server uses the self-signed certificate, on production server the certificate is signed by "thawte".

So I emailed the certificate to myself, tap the attachement using Mail app on my device - it redirected me to the settings and I installted the certificate. Of course as it was self-signed it tells me that the certificate is not trusted, but it's the only problem with the certificate, it's not expired etc.

Now I do the same approach and I again receives either "A connection failure occurred: SSL problem (possibly a bad/expired/self-signed certificate)" or 404.

I've also added the certificate to my project and add following lines:

NSData* certData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"cert" ofType:@"cer"]];

SecCertificateRef cert = SecCertificateCreateWithData(NULL, (CFDataRef)certData);
[request setClientCertificates:[NSArray arrayWithObject:(id)cert]];

but it doesn't change anything.

Am I missing something?

I would use something like the REST client addon for firefox to do the identical POST from a browser. To see what the site is really returning. It just might be that a 404 is the correct response from the server for the specified URL and the invalid cert is just preventing the SSL negotiation from completing so you never see the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM