Skip to content

Commit

Permalink
Change SSL error detection code to fix issues with iPhone platform (T…
Browse files Browse the repository at this point in the history
…hanks to Jane Sales for her report!)
  • Loading branch information
pokeb committed Jun 9, 2009
1 parent 4dc5766 commit 03a71b6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
12 changes: 5 additions & 7 deletions Classes/ASIHTTPRequest.m
Expand Up @@ -1366,14 +1366,12 @@ - (void)handleStreamError

NSString *reason = @"A connection failure occurred";

// We'll use a custom error message for common SSL errors, but you should always check underlying error if you want more details
// We'll use a custom error message for SSL errors, but you should always check underlying error if you want more details
// For some reason SecureTransport.h doesn't seem to be available on iphone, so error codes hard-coded
// Also, iPhone seems to handle errors differently from Mac OS X - a self-signed certificate returns a different error code on each platform, so we'll just provide a general error
if ([[underlyingError domain] isEqualToString:NSOSStatusErrorDomain]) {
if ([underlyingError code] == errSSLUnknownRootCert) {
reason = [NSString stringWithFormat:@"%@: Secure certificate had an untrusted root",reason];
} else if ([underlyingError code] == errSSLCertExpired) {
reason = [NSString stringWithFormat:@"%@: Secure certificate expired",reason];
} else if ([underlyingError code] >= -9807 || [underlyingError code] <= -9818) {
reason = [NSString stringWithFormat:@"%@: SSL problem (probably a bad certificate)",reason];
if ([underlyingError code] <= -9800 && [underlyingError code] >= -9818) {
reason = [NSString stringWithFormat:@"%@: SSL problem (possibily a bad/expired/self-signed certificate)",reason];
}
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/Tests/ASIHTTPRequestTests.m
Expand Up @@ -625,7 +625,7 @@ - (void)testSSL
GHAssertNotNil([request error],@"Failed to generate an error for a self-signed certificate");

// 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:@"A connection failure occurred: Secure certificate had an untrusted root"]);
BOOL success = ([[[request error] localizedDescription] isEqualToString:@"A connection failure occurred: SSL problem (possibily a bad/expired/self-signed certificate)"]);
GHAssertTrue(success,@"Generated the wrong error for a self signed cert");

// Turn off certificate validation, and try again
Expand Down
28 changes: 20 additions & 8 deletions iPhone Sample/XIBs/UploadProgress.xib
Expand Up @@ -2,9 +2,9 @@
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.03">
<data>
<int key="IBDocument.SystemTarget">528</int>
<string key="IBDocument.SystemVersion">9G55</string>
<string key="IBDocument.SystemVersion">9J61</string>
<string key="IBDocument.InterfaceBuilderVersion">677</string>
<string key="IBDocument.AppKitVersion">949.43</string>
<string key="IBDocument.AppKitVersion">949.46</string>
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand Down Expand Up @@ -39,14 +39,14 @@
<object class="IBUILabel" id="652745716">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 20}, {280, 91}}</string>
<string key="NSFrame">{{20, 20}, {280, 127}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string type="base64-UTF8" key="IBUIText">RGVtb25zdHJhdGVzIFBPU1RpbmcgY29udGVudCB0byBhIFVSTCwgc2hvd2luZyB1cGxvYWQgcHJvZ3Jl
c3MuCgpZb3UnbGwgb25seSBzZWUgYWNjdXJhdGUgcHJvZ3Jlc3MgZm9yIHVwbG9hZHMgd2hlbiB0aGUg
cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string>
cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCIChpbiAyLjIuMSBTREspA</string>
<object class="NSFont" key="IBUIFont">
<string key="NSName">Helvetica</string>
<double key="NSSize">1.400000e+01</double>
Expand All @@ -65,7 +65,7 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string>
<object class="IBUIButton" id="117120328">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 136}, {72, 37}}</string>
<string key="NSFrame">{{20, 161}, {72, 37}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
Expand All @@ -89,11 +89,15 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string>
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA</bytes>
</object>
<object class="NSColor" key="IBUINormalTitleShadowColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MAA</bytes>
</object>
</object>
<object class="IBUIProgressView" id="975702463">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 190}, {280, 9}}</string>
<string key="NSFrame">{{20, 215}, {280, 9}}</string>
<reference key="NSSuperview" ref="191373211"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
Expand Down Expand Up @@ -238,6 +242,13 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">Frameworks/libGHUnitIPhone/GHUNSObject+Swizzle.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">UploadViewController</string>
<string key="superclassName">UIViewController</string>
Expand All @@ -251,13 +262,14 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">UploadViewController.h</string>
<string key="minorKey">iPhone Sample/UploadViewController.h</string>
</object>
</object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.LastKnownRelativeProjectPath">../asi-http-request.xcodeproj</string>
<string key="IBDocument.LastKnownRelativeProjectPath">../../iPhone.xcodeproj</string>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">3.0</string>
</data>
</archive>

0 comments on commit 03a71b6

Please sign in to comment.