Change SSL error detection code to fix issues with iPhone platform (Thanks to Ja…
…ne Sales for her report!)
Showing
3 changed files
with
26 additions
and
16 deletions
@@ -1366,14 +1366,12 @@ static NSError *ASIUnableToCreateRequestError; | @@ -1366,14 +1366,12 @@ static NSError *ASIUnableToCreateRequestError; | ||
1366 | 1366 | ||
1367 | NSString *reason = @"A connection failure occurred"; | 1367 | NSString *reason = @"A connection failure occurred"; |
1368 | 1368 | ||
1369 | - // We'll use a custom error message for common SSL errors, but you should always check underlying error if you want more details | 1369 | + // We'll use a custom error message for SSL errors, but you should always check underlying error if you want more details |
1370 | + // For some reason SecureTransport.h doesn't seem to be available on iphone, so error codes hard-coded | ||
1371 | + // 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 | ||
1370 | if ([[underlyingError domain] isEqualToString:NSOSStatusErrorDomain]) { | 1372 | if ([[underlyingError domain] isEqualToString:NSOSStatusErrorDomain]) { |
1371 | - if ([underlyingError code] == errSSLUnknownRootCert) { | 1373 | + if ([underlyingError code] <= -9800 && [underlyingError code] >= -9818) { |
1372 | - reason = [NSString stringWithFormat:@"%@: Secure certificate had an untrusted root",reason]; | 1374 | + reason = [NSString stringWithFormat:@"%@: SSL problem (possibily a bad/expired/self-signed certificate)",reason]; |
1373 | - } else if ([underlyingError code] == errSSLCertExpired) { | ||
1374 | - reason = [NSString stringWithFormat:@"%@: Secure certificate expired",reason]; | ||
1375 | - } else if ([underlyingError code] >= -9807 || [underlyingError code] <= -9818) { | ||
1376 | - reason = [NSString stringWithFormat:@"%@: SSL problem (probably a bad certificate)",reason]; | ||
1377 | } | 1375 | } |
1378 | } | 1376 | } |
1379 | 1377 |
@@ -625,7 +625,7 @@ | @@ -625,7 +625,7 @@ | ||
625 | GHAssertNotNil([request error],@"Failed to generate an error for a self-signed certificate"); | 625 | GHAssertNotNil([request error],@"Failed to generate an error for a self-signed certificate"); |
626 | 626 | ||
627 | // 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. | 627 | // 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. |
628 | - BOOL success = ([[[request error] localizedDescription] isEqualToString:@"A connection failure occurred: Secure certificate had an untrusted root"]); | 628 | + BOOL success = ([[[request error] localizedDescription] isEqualToString:@"A connection failure occurred: SSL problem (possibily a bad/expired/self-signed certificate)"]); |
629 | GHAssertTrue(success,@"Generated the wrong error for a self signed cert"); | 629 | GHAssertTrue(success,@"Generated the wrong error for a self signed cert"); |
630 | 630 | ||
631 | // Turn off certificate validation, and try again | 631 | // Turn off certificate validation, and try again |
@@ -2,9 +2,9 @@ | @@ -2,9 +2,9 @@ | ||
2 | <archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.03"> | 2 | <archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.03"> |
3 | <data> | 3 | <data> |
4 | <int key="IBDocument.SystemTarget">528</int> | 4 | <int key="IBDocument.SystemTarget">528</int> |
5 | - <string key="IBDocument.SystemVersion">9G55</string> | 5 | + <string key="IBDocument.SystemVersion">9J61</string> |
6 | <string key="IBDocument.InterfaceBuilderVersion">677</string> | 6 | <string key="IBDocument.InterfaceBuilderVersion">677</string> |
7 | - <string key="IBDocument.AppKitVersion">949.43</string> | 7 | + <string key="IBDocument.AppKitVersion">949.46</string> |
8 | <string key="IBDocument.HIToolboxVersion">353.00</string> | 8 | <string key="IBDocument.HIToolboxVersion">353.00</string> |
9 | <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> | 9 | <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> |
10 | <bool key="EncodedWithXMLCoder">YES</bool> | 10 | <bool key="EncodedWithXMLCoder">YES</bool> |
@@ -39,14 +39,14 @@ | @@ -39,14 +39,14 @@ | ||
39 | <object class="IBUILabel" id="652745716"> | 39 | <object class="IBUILabel" id="652745716"> |
40 | <reference key="NSNextResponder" ref="191373211"/> | 40 | <reference key="NSNextResponder" ref="191373211"/> |
41 | <int key="NSvFlags">292</int> | 41 | <int key="NSvFlags">292</int> |
42 | - <string key="NSFrame">{{20, 20}, {280, 91}}</string> | 42 | + <string key="NSFrame">{{20, 20}, {280, 127}}</string> |
43 | <reference key="NSSuperview" ref="191373211"/> | 43 | <reference key="NSSuperview" ref="191373211"/> |
44 | <bool key="IBUIOpaque">NO</bool> | 44 | <bool key="IBUIOpaque">NO</bool> |
45 | <bool key="IBUIClipsSubviews">YES</bool> | 45 | <bool key="IBUIClipsSubviews">YES</bool> |
46 | <bool key="IBUIUserInteractionEnabled">NO</bool> | 46 | <bool key="IBUIUserInteractionEnabled">NO</bool> |
47 | <string type="base64-UTF8" key="IBUIText">RGVtb25zdHJhdGVzIFBPU1RpbmcgY29udGVudCB0byBhIFVSTCwgc2hvd2luZyB1cGxvYWQgcHJvZ3Jl | 47 | <string type="base64-UTF8" key="IBUIText">RGVtb25zdHJhdGVzIFBPU1RpbmcgY29udGVudCB0byBhIFVSTCwgc2hvd2luZyB1cGxvYWQgcHJvZ3Jl |
48 | c3MuCgpZb3UnbGwgb25seSBzZWUgYWNjdXJhdGUgcHJvZ3Jlc3MgZm9yIHVwbG9hZHMgd2hlbiB0aGUg | 48 | c3MuCgpZb3UnbGwgb25seSBzZWUgYWNjdXJhdGUgcHJvZ3Jlc3MgZm9yIHVwbG9hZHMgd2hlbiB0aGUg |
49 | -cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string> | 49 | +cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCIChpbiAyLjIuMSBTREspA</string> |
50 | <object class="NSFont" key="IBUIFont"> | 50 | <object class="NSFont" key="IBUIFont"> |
51 | <string key="NSName">Helvetica</string> | 51 | <string key="NSName">Helvetica</string> |
52 | <double key="NSSize">1.400000e+01</double> | 52 | <double key="NSSize">1.400000e+01</double> |
@@ -65,7 +65,7 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string> | @@ -65,7 +65,7 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string> | ||
65 | <object class="IBUIButton" id="117120328"> | 65 | <object class="IBUIButton" id="117120328"> |
66 | <reference key="NSNextResponder" ref="191373211"/> | 66 | <reference key="NSNextResponder" ref="191373211"/> |
67 | <int key="NSvFlags">292</int> | 67 | <int key="NSvFlags">292</int> |
68 | - <string key="NSFrame">{{20, 136}, {72, 37}}</string> | 68 | + <string key="NSFrame">{{20, 161}, {72, 37}}</string> |
69 | <reference key="NSSuperview" ref="191373211"/> | 69 | <reference key="NSSuperview" ref="191373211"/> |
70 | <bool key="IBUIOpaque">NO</bool> | 70 | <bool key="IBUIOpaque">NO</bool> |
71 | <bool key="IBUIClearsContextBeforeDrawing">NO</bool> | 71 | <bool key="IBUIClearsContextBeforeDrawing">NO</bool> |
@@ -89,11 +89,15 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string> | @@ -89,11 +89,15 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string> | ||
89 | <int key="NSColorSpace">1</int> | 89 | <int key="NSColorSpace">1</int> |
90 | <bytes key="NSRGB">MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA</bytes> | 90 | <bytes key="NSRGB">MC4xOTYwNzg0MyAwLjMwOTgwMzkzIDAuNTIxNTY4NjYAA</bytes> |
91 | </object> | 91 | </object> |
92 | + <object class="NSColor" key="IBUINormalTitleShadowColor"> | ||
93 | + <int key="NSColorSpace">3</int> | ||
94 | + <bytes key="NSWhite">MAA</bytes> | ||
95 | + </object> | ||
92 | </object> | 96 | </object> |
93 | <object class="IBUIProgressView" id="975702463"> | 97 | <object class="IBUIProgressView" id="975702463"> |
94 | <reference key="NSNextResponder" ref="191373211"/> | 98 | <reference key="NSNextResponder" ref="191373211"/> |
95 | <int key="NSvFlags">292</int> | 99 | <int key="NSvFlags">292</int> |
96 | - <string key="NSFrame">{{20, 190}, {280, 9}}</string> | 100 | + <string key="NSFrame">{{20, 215}, {280, 9}}</string> |
97 | <reference key="NSSuperview" ref="191373211"/> | 101 | <reference key="NSSuperview" ref="191373211"/> |
98 | <bool key="IBUIOpaque">NO</bool> | 102 | <bool key="IBUIOpaque">NO</bool> |
99 | <bool key="IBUIClipsSubviews">YES</bool> | 103 | <bool key="IBUIClipsSubviews">YES</bool> |
@@ -239,6 +243,13 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string> | @@ -239,6 +243,13 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string> | ||
239 | <object class="NSMutableArray" key="referencedPartialClassDescriptions"> | 243 | <object class="NSMutableArray" key="referencedPartialClassDescriptions"> |
240 | <bool key="EncodedWithXMLCoder">YES</bool> | 244 | <bool key="EncodedWithXMLCoder">YES</bool> |
241 | <object class="IBPartialClassDescription"> | 245 | <object class="IBPartialClassDescription"> |
246 | + <string key="className">NSObject</string> | ||
247 | + <object class="IBClassDescriptionSource" key="sourceIdentifier"> | ||
248 | + <string key="majorKey">IBProjectSource</string> | ||
249 | + <string key="minorKey">Frameworks/libGHUnitIPhone/GHUNSObject+Swizzle.h</string> | ||
250 | + </object> | ||
251 | + </object> | ||
252 | + <object class="IBPartialClassDescription"> | ||
242 | <string key="className">UploadViewController</string> | 253 | <string key="className">UploadViewController</string> |
243 | <string key="superclassName">UIViewController</string> | 254 | <string key="superclassName">UIViewController</string> |
244 | <object class="NSMutableDictionary" key="actions"> | 255 | <object class="NSMutableDictionary" key="actions"> |
@@ -251,13 +262,14 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string> | @@ -251,13 +262,14 @@ cmVxdWVzdCBib2R5IGlzIGxhcmdlciB0aGFuIDEyOEtCLg</string> | ||
251 | </object> | 262 | </object> |
252 | <object class="IBClassDescriptionSource" key="sourceIdentifier"> | 263 | <object class="IBClassDescriptionSource" key="sourceIdentifier"> |
253 | <string key="majorKey">IBProjectSource</string> | 264 | <string key="majorKey">IBProjectSource</string> |
254 | - <string key="minorKey">UploadViewController.h</string> | 265 | + <string key="minorKey">iPhone Sample/UploadViewController.h</string> |
255 | </object> | 266 | </object> |
256 | </object> | 267 | </object> |
257 | </object> | 268 | </object> |
258 | </object> | 269 | </object> |
259 | <int key="IBDocument.localizationMode">0</int> | 270 | <int key="IBDocument.localizationMode">0</int> |
260 | - <string key="IBDocument.LastKnownRelativeProjectPath">../asi-http-request.xcodeproj</string> | 271 | + <string key="IBDocument.LastKnownRelativeProjectPath">../../iPhone.xcodeproj</string> |
261 | <int key="IBDocument.defaultPropertyAccessControl">3</int> | 272 | <int key="IBDocument.defaultPropertyAccessControl">3</int> |
273 | + <string key="IBCocoaTouchPluginVersion">3.0</string> | ||
262 | </data> | 274 | </data> |
263 | </archive> | 275 | </archive> |
-
Please register or login to post a comment