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 =开发者_Python百科 [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.
精彩评论