You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2013/01/15 07:37:12 UTC
ios commit: [CB-478] FileTransfer upload - handle "trustAllHosts"
parameter
Updated Branches:
refs/heads/master f4e7a2b0d -> adf226876
[CB-478] FileTransfer upload - handle "trustAllHosts" parameter
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/adf22687
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/adf22687
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/adf22687
Branch: refs/heads/master
Commit: adf226876d03723b89b4e3a9d2e9d0cfa8f2eb07
Parents: f4e7a2b
Author: Shazron Abdullah <sh...@apache.org>
Authored: Mon Jan 14 22:36:35 2013 -0800
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Mon Jan 14 22:36:44 2013 -0800
----------------------------------------------------------------------
CordovaLib/Classes/CDVFileTransfer.h | 1 +
CordovaLib/Classes/CDVFileTransfer.m | 41 +++++++++++-----------------
2 files changed, 17 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/adf22687/CordovaLib/Classes/CDVFileTransfer.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.h b/CordovaLib/Classes/CDVFileTransfer.h
index 76c6a95..5392236 100644
--- a/CordovaLib/Classes/CDVFileTransfer.h
+++ b/CordovaLib/Classes/CDVFileTransfer.h
@@ -67,5 +67,6 @@ extern NSString* const kOptionsKeyCookie;
@property (assign) int responseCode; // atomic
@property (nonatomic, assign) NSInteger bytesTransfered;
@property (nonatomic, assign) NSInteger bytesExpected;
+@property (nonatomic, assign) BOOL trustAllHosts;
@end;
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/adf22687/CordovaLib/Classes/CDVFileTransfer.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVFileTransfer.m b/CordovaLib/Classes/CDVFileTransfer.m
index 81d573f..128c954 100644
--- a/CordovaLib/Classes/CDVFileTransfer.m
+++ b/CordovaLib/Classes/CDVFileTransfer.m
@@ -130,7 +130,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
NSString* fileName = [arguments objectAtIndex:3 withDefault:@"no-filename"];
NSString* mimeType = [arguments objectAtIndex:4 withDefault:nil];
NSDictionary* options = [arguments objectAtIndex:5 withDefault:nil];
- // NSString* trustAllHosts = (NSString*)[arguments objectAtIndex:6]; // allow self-signed certs
+ // BOOL trustAllHosts = [[arguments objectAtIndex:6 withDefault:[NSNumber numberWithBool:YES]] boolValue]; // allow self-signed certs
BOOL chunkedMode = [[arguments objectAtIndex:7 withDefault:[NSNumber numberWithBool:YES]] boolValue];
NSDictionary* headers = [arguments objectAtIndex:8 withDefault:nil];
@@ -238,6 +238,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
{
NSString* source = [command.arguments objectAtIndex:0];
NSString* server = [command.arguments objectAtIndex:1];
+ BOOL trustAllHosts = [[command.arguments objectAtIndex:6 withDefault:[NSNumber numberWithBool:YES]] boolValue]; // allow self-signed certs
NSString* objectId = [command.arguments objectAtIndex:9];
CDVFileTransferDelegate* delegate = [[CDVFileTransferDelegate alloc] init];
@@ -248,6 +249,8 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
delegate.objectId = objectId;
delegate.source = source;
delegate.target = server;
+ delegate.trustAllHosts = trustAllHosts;
+
return delegate;
}
@@ -319,7 +322,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
DLog(@"File Transfer downloading file...");
NSString* sourceUrl = [command.arguments objectAtIndex:0];
NSString* filePath = [command.arguments objectAtIndex:1];
- // NSString* trustAllHosts = (NSString*)[arguments objectAtIndex:6]; // allow self-signed certs
+ BOOL trustAllHosts = [[command.arguments objectAtIndex:2 withDefault:[NSNumber numberWithBool:YES]] boolValue]; // allow self-signed certs
NSString* objectId = [command.arguments objectAtIndex:3];
// return unsupported result for assets-library URLs
@@ -366,6 +369,7 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
delegate.objectId = objectId;
delegate.source = sourceUrl;
delegate.target = filePath;
+ delegate.trustAllHosts = trustAllHosts;
delegate.connection = [NSURLConnection connectionWithRequest:req delegate:delegate];
@@ -550,33 +554,20 @@ static CFIndex WriteDataToStream(NSData* data, CFWriteStreamRef stream)
self.bytesTransfered = totalBytesWritten;
}
-/* TESTING ONLY CODE
-// use ONLY for testing with self signed certificates
-// uncomment and modify server name in connection didReceiveAuthenticationChallenge
-- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
+// for self signed certificates
+- (void)connection:(NSURLConnection*)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge
{
- return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
-}
-
-- (void)connection:(NSURLConnection *) connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge
-{
- if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust])
- {
- //NSLog(@"challenge host: %@", challenge.protectionSpace.host);
- // we only trust our own domain
- if ([challenge.protectionSpace.host isEqualToString:@"serverName.domain.com"]){
- NSURLCredential* myCredential = [NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust];
-
- [challenge.sender useCredential:myCredential forAuthenticationChallenge:challenge];
-
+ if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
+ if (self.trustAllHosts) {
+ NSURLCredential* credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
+ [challenge.sender useCredential:credential forAuthenticationChallenge:challenge];
}
+ [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
+ } else {
+ [challenge.sender performDefaultHandlingForAuthenticationChallenge:challenge];
}
-
- [challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}
-// uncomment the above two methods for testing servers with self signed certificates
-// END TESTING ONLY CODE
- */
+
- (id)init
{
if ((self = [super init])) {