<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -217,6 +217,9 @@ extern NSString* const NetworkRequestErrorDomain;
 	
 	// When YES, requests will automatically redirect when they get a HTTP 30x header (defaults to YES)
 	BOOL shouldRedirect;
+	
+	// When NO, requests will not check the secure certificate is valid (use for self-signed cerficates during development, DO NOT USE IN PRODUCTION) Default is YES
+	BOOL validatesSecureCertificate;
 
 }
 
@@ -401,4 +404,5 @@ extern NSString* const NetworkRequestErrorDomain;
 @property (assign) BOOL useHTTPVersionOne;
 @property (assign, readonly) unsigned long long partialDownloadSize;
 @property (assign) BOOL shouldRedirect;
+@property (assign) BOOL validatesSecureCertificate;
 @end</diff>
      <filename>Classes/ASIHTTPRequest.h</filename>
    </modified>
    <modified>
      <diff>@@ -97,6 +97,7 @@ static NSError *ASIUnableToCreateRequestError;
 	[self setTimeOutSeconds:10];
 	[self setUseSessionPersistance:YES];
 	[self setUseCookiePersistance:YES];
+	[self setValidatesSecureCertificate:YES];
 	[self setRequestCookies:[[[NSMutableArray alloc] init] autorelease]];
 	[self setDidFinishSelector:@selector(requestFinished:)];
 	[self setDidFailSelector:@selector(requestFailed:)];
@@ -434,6 +435,11 @@ static NSError *ASIUnableToCreateRequestError;
 	// Tell CFNetwork to automatically redirect for 30x status codes
 	CFReadStreamSetProperty(readStream, kCFStreamPropertyHTTPShouldAutoredirect, [self shouldRedirect] ? kCFBooleanTrue : kCFBooleanFalse);
     
+	// Tell CFNetwork not to validate SSL certificates
+	if (!validatesSecureCertificate) {
+		CFReadStreamSetProperty(readStream, kCFStreamPropertySSLSettings, [NSMutableDictionary dictionaryWithObject:(NSString *)kCFBooleanFalse forKey:(NSString *)kCFStreamSSLValidatesCertificateChain]); 
+	}
+	
     // Set the client
 	CFStreamClientContext ctxt = {0, self, NULL, NULL, NULL};
     if (!CFReadStreamSetClient(readStream, kNetworkEvents, ReadStreamClientCallBack, &amp;ctxt)) {
@@ -1350,12 +1356,28 @@ static NSError *ASIUnableToCreateRequestError;
 {
 	NSError *underlyingError = [(NSError *)CFReadStreamCopyError(readStream) autorelease];
 	
+	
+	
 	[self cancelLoad];
 	[self setComplete:YES];
 	
 	if (![self error]) { // We may already have handled this error
 		
-		[self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIConnectionFailureErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@&quot;A connection failure occurred&quot;,NSLocalizedDescriptionKey,underlyingError,NSUnderlyingErrorKey,nil]]];
+		
+		NSString *reason = @&quot;A connection failure occurred&quot;;
+		
+		// We'll use a custom error message for common SSL errors, but you should always check underlying error if you want more details
+		if ([[underlyingError domain] isEqualToString:NSOSStatusErrorDomain]) {
+			if ([underlyingError code] == errSSLUnknownRootCert) {
+				reason = [NSString stringWithFormat:@&quot;%@: Secure certificate had an untrusted root&quot;,reason];
+			} else if ([underlyingError code] == errSSLCertExpired) {
+				reason = [NSString stringWithFormat:@&quot;%@: Secure certificate expired&quot;,reason];
+			} else if ([underlyingError code] &gt;= -9807 || [underlyingError code] &lt;= -9818) {
+				reason = [NSString stringWithFormat:@&quot;%@: SSL problem (probably a bad certificate)&quot;,reason];
+			}
+		}
+		
+		[self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIConnectionFailureErrorType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:reason,NSLocalizedDescriptionKey,underlyingError,NSUnderlyingErrorKey,nil]]];
 	}
     [super cancel];
 }
@@ -1640,4 +1662,5 @@ static NSError *ASIUnableToCreateRequestError;
 @synthesize authenticationRetryCount;
 @synthesize updatedProgress;
 @synthesize shouldRedirect;
+@synthesize validatesSecureCertificate;
 @end</diff>
      <filename>Classes/ASIHTTPRequest.m</filename>
    </modified>
    <modified>
      <diff>@@ -32,5 +32,5 @@
 - (void)testCharacterEncoding;
 - (void)testCompressedResponse;
 - (void)testCompressedResponseDownloadToFile;
-
+- (void)testSSL;
 @end</diff>
      <filename>Classes/Tests/ASIHTTPRequestTests.h</filename>
    </modified>
    <modified>
      <diff>@@ -616,4 +616,24 @@
 	GHAssertTrue(success,@&quot;Failed to correctly display increment progress for a partial download&quot;);
 }
 
+- (void)testSSL
+{
+	NSURL *url = [NSURL URLWithString:@&quot;https://selfsigned.allseeing-i.com&quot;];
+	ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
+	[request start];
+	
+	GHAssertNotNil([request error],@&quot;Failed to generate an error for a self-signed certificate&quot;);		
+	
+	// Just for testing the request generated a custom error description - don't do this! You should look at the domain / code of the underlyingError in your own programs.
+	BOOL success = ([[[request error] localizedDescription] isEqualToString:@&quot;A connection failure occurred: Secure certificate had an untrusted root&quot;]);
+	GHAssertTrue(success,@&quot;Basic synchronous request failed&quot;);
+	
+	// Turn off certificate validation, and try again
+	request = [ASIHTTPRequest requestWithURL:url];
+	[request setValidatesSecureCertificate:NO];
+	[request start];
+	
+	GHAssertNil([request error],@&quot;Failed to accept a self-signed certificate&quot;);	
+}
+
 @end</diff>
      <filename>Classes/Tests/ASIHTTPRequestTests.m</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e0588624747533db3748366d29d22685fdcdcfbd</id>
    </parent>
  </parents>
  <author>
    <name>Ben Copsey</name>
    <email>ben@allseeing-i.com</email>
  </author>
  <url>http://github.com/pokeb/asi-http-request/commit/e81d5707a04634e2436f83897ed2208977112133</url>
  <id>e81d5707a04634e2436f83897ed2208977112133</id>
  <committed-date>2009-06-07T04:07:56-07:00</committed-date>
  <authored-date>2009-06-07T04:07:56-07:00</authored-date>
  <message>Added validatesSecureCertificate property to turn off SSL cert validation for testing with self-signed certs</message>
  <tree>4938fcb2d9cf662fad76126d1d9cdd0c8a6fd57c</tree>
  <committer>
    <name>Ben Copsey</name>
    <email>ben@allseeing-i.com</email>
  </committer>
</commit>
