Read Me About AdvancedURLConnections
====================================
1.1
AdvancedURLConnections demonstrates various advanced networking techniques with NSURLConnection. Specifically, it demonstrates how to respond to authentication challenges, how to modify the default server trust evaluation (for example, to support a server with a self-signed certificate), and how to provide client identities.
AdvancedURLConnections requires features that were introduced in iOS 3.0.
Packing List
------------
The sample contains the following items:
o Read Me About AdvancedURLConnections.txt -- This file.
o AdvancedURLConnections.xcodeproj -- An Xcode project for the sample.
o Resources -- The project nib, images, and so on.
o Ancillary Code -- A directory full of code that's not directly relevant to the main function of this sample.
o AdvancedGetController.[h,m,xib] -- A view controller that manages the Get tab. This is a relatively dull application of NSURLConnection. What's interesting here is how it passes the authentication challenges off to the challenge handlers.
o ChallengeHandler.[h,m] -- An abstract base class for handling NSURLConnection authentication challenges.
o ChallengeHandlers -- A directory containing a number of concrete subclasses of ChallengeHandler for handling specific types of authentication challenges.
o UI Building Blocks -- A directory containing general purpose user interface elements used by other parts of the program, most notably the various challenge handlers.
o CredentialsController.[h,m,xib] -- A view controller that manages the Credentials tab. This lets you manage credentials so as to test various features implemented by the AdvancedGetController.
o DebugController.[h,m,xib] -- A view controller that manages the Debug tab.
o Credentials.[h,m] -- A singleton model object that vends credentials such as certificates and identities.
o DebugOptions.[h,m] -- A singleton model object that vends our debugging preferences.
Using the Sample
----------------
Testing all of the functionality within AdvancedURLConnections requires some complex server setup (see "Server Configuration", below). However, you can test some basic functionality without setting up a server at all.
1. Run the program on a device or simulator.
2. Switch to the Get tab.
3. Tap in the URL field and pick the first item on the pick list ("http://www.cacert.org/images/cacert4.png"). The program will download and display an image.
4. Tap in the URL field and pick the second item on the pick list ("https://www.cacert.org/images/cacert4.png"). The download will fail because CAcert's root certificate is not trusted by default.
5. Switch to the Credentials tab.
6. Tap in the URL field and pick the first item on the pick list ("http://www.cacert.org/certs/root.der"). The program will download the CAcert's root certificate and offer to import it. Tap Import to do so.
7. Switch to the Debug tab.
8. Tap on "Trust Imported Certificates" in the "TLS Server Validation" section of the table.
9. Now switch back to the Get tab.
10. Tap the Get button.
This time the download succeeds because the program now trusts CAcert's root certificate.
IMPORTANT: The above will work on both the simulator and a real device. However, some features of this sample only work on a real device. See the "Caveats" section, below, for details.
Building the Sample
-------------------
The sample was built using Xcode 3.2.3 on Mac OS X 10.6.4 with iPhone SDK 4.0. You should be able to just open the project and choose Build from the Build menu. The resulting program should be compatible with all devices running iOS 3.2 and later. The bulk of my testing was done with an iPod touch (second generation) running iOS 4.0.
How It Works
------------
To get started with this sample you should have a basic understanding of how the NSURLConnection API works. If you're not already familiar with downloading data via NSURLConnection, you should look at the SimpleURLConnections sample code.
<http://developer.apple.com/iphone/library/samplecode/SimpleURLConnections/index.html>
The differences between the AdvancedGetController and the equivalent code in SimpleURLConnections is quite small. The critical change is that AdvancedGetController implements the authentication challenge delegate methods (-connection:canAuthenticateAgainstProtectionSpace: and -connection:didReceiveAuthenticationChallenge:) using the ChallengeHandler class and its various concrete subclasses.
The ChallengeHandler class maintains a registry of subclasses that are capable of handling challenges. The registry is keyed off the authentication method (NSString) associated with the protection space (NSURLProtectionSpace) associated with the challenge (NSURLAuthenticationChallenge). AdvancedGetController uses this in two ways:
o -[AdvancedGetController connection:canAuthenticateAgainstProtectionSpace:] calls +[ChallengeHandler supportsProtectionSpace:] to determine whether there's a handler for a specific challenge.
o -[AdvancedGetController connection:didReceiveAuthenticationChallenge:] calls +[ChallengeHandler handlerForChallenge:parentViewController:] to instantiate a challenge handler for the challenge.
It then holds on to the challenge handler while the challenge is running. When the challenge handler is done, it calls its -challengeHandlerDidFinish: delegate method. AdvancedGetController implements that method and, in response, resolves the challenge (it calls -[ChallengeHandler resolveChallenge], which applies the credentials to the challenge) and then forgets about the current challenge and waits for the next one (or for the connection to start running normally).
Each concrete subclass of ChallengeHandler is responsible for handling one specific type of challenge. The current handlers include:
o AuthenticationChallengeHandler -- This handles HTTP authentication challenges (authentication methods NSURLAuthenticationMethodDefault, NSURLAuthenticationMethodHTTPBasic and NSURLAuthenticationMethodHTTPDigest) from both origin servers and proxies.
o ClientIdentityChallengeHandler -- This handles HTTPS client identity challenges (authentication method NSURLAuthenticationMethodClientCertificate), which occur when the server requires that the client supply an identity.
o ServerTrustChallengeHandler -- This handles HTTPS server trust challenges (authentication method NSURLAuthenticationMethodServerTrust) which allows the client to override the default HTTPS TLS server trust evaluation (for example, to allow a specific self-signed certificate).
The first two challenge handlers have an associated view controller in the "UI Building Blocks" directory. These do the actual work of running the UI presented in response to the challenge. The challenge handler itself is basically glue code that attaches these view controllers to the AdvancedGetController. AdvancedGetController can't use these view controllers directly because not all challenge handling UI is done by way of a view controller; for example, the ServerTrustChallengeHandler does all of its work using UIAlertViews.
Server Configuration
--------------------
Testing AdvancedURLConnections is tricky because it requires you to have access to a server that presents all of the authentication challenges handled by the program. I did the bulk of my testing with the personal Web Sharing built in to Mac OS X 10.6.x. Web Sharing is based on Apache HTTP Server, a full-featured web server that you can tweak for testing purposes. The following is a summary of the tweaks that I did.
WARNING: These suggestions are for testing purposes only and may result in security vulnerabilities. Do not apply them to a production web server, or to a web server that's accessible to untrusted clients.
A. enable password authentication -- To password protect a directory, I created a "protected" directory within "/Library/WebServer/Documents" and added the following to "/etc/apache2/
没有合适的资源?快使用搜索试试~ 我知道了~
AdvancedURLConnections
共180个文件
m:30个
h:28个
png:27个
需积分: 4 8 下载量 60 浏览量
2011-02-11
17:23:00
上传
评论
收藏 1.05MB RAR 举报
温馨提示
iphone端URl实例。 详细给出了从、通过URL上传下载文件的详细代码。 可运行在iphone3,0以上的sdk版本。很适合初学者学习iphoneurl开发
资源推荐
资源详情
资源评论
收起资源包目录
AdvancedURLConnections (180个子文件)
._Ancillary Code 4KB
._build 4KB
._ChallengeHandlers 4KB
._Images 4KB
._iTunesArtwork 4KB
._Resources 4KB
._UI Building Blocks 4KB
AdvURLs 359KB
AdvURLs 202KB
._AdvancedURLConnections.build 4KB
control 256KB
build-state.dat 111KB
build-state~.dat 87KB
build-state.dat 7KB
AdvancedURLConnections.dep 19KB
AdvancedURLConnections~.dep 9KB
AdvancedURLConnections.dep 5KB
.DS_Store 6KB
._.DS_Store 4KB
ChallengeHandler.h 9KB
ClientIdentityController.h 6KB
CredentialImportController.h 6KB
AuthenticationController.h 6KB
DebugOptions.h 5KB
CredentialsController.h 5KB
PickListController.h 4KB
AdvancedGetController.h 4KB
Credentials.h 4KB
._AppDelegate.h 4KB
._DebugOptions.h 4KB
._AuthenticationController.h 4KB
._ClientIdentityController.h 4KB
._CredentialImportController.h 4KB
._PickListController.h 4KB
._ClientIdentityChallengeHandler.h 4KB
._ServerTrustChallengeHandler.h 4KB
._AuthenticationChallengeHandler.h 4KB
._AdvancedGetController.h 4KB
._ChallengeHandler.h 4KB
._Credentials.h 4KB
._CredentialsController.h 4KB
._DebugController.h 4KB
AppDelegate.h 4KB
ClientIdentityChallengeHandler.h 3KB
AuthenticationChallengeHandler.h 3KB
ServerTrustChallengeHandler.h 3KB
DebugController.h 3KB
pbxindex.header 24B
AdvURLs.hmap 2KB
AdvURLs-project-headers.hmap 1KB
AdvURLs-own-target-headers.hmap 793B
AdvURLs-all-target-headers.hmap 793B
AdvURLs-generated-files.hmap 121B
iTunesArtwork 5KB
iTunesArtwork 5KB
AdvURLs.LinkFileList 3KB
._English.lproj 4KB
CredentialsController.m 32KB
Credentials.m 27KB
AdvancedGetController.m 20KB
ServerTrustChallengeHandler.m 15KB
DebugController.m 13KB
CredentialImportController.m 12KB
ClientIdentityChallengeHandler.m 12KB
ChallengeHandler.m 11KB
ClientIdentityController.m 10KB
AuthenticationController.m 9KB
PickListController.m 9KB
AuthenticationChallengeHandler.m 9KB
AppDelegate.m 7KB
DebugOptions.m 6KB
._AppDelegate.m 4KB
._main.m 4KB
._CredentialImportController.m 4KB
._AuthenticationController.m 4KB
._PickListController.m 4KB
._ClientIdentityController.m 4KB
._ServerTrustChallengeHandler.m 4KB
._AuthenticationChallengeHandler.m 4KB
._ClientIdentityChallengeHandler.m 4KB
._DebugController.m 4KB
._CredentialsController.m 4KB
._Credentials.m 4KB
._DebugOptions.m 4KB
._ChallengeHandler.m 4KB
._AdvancedGetController.m 4KB
main.m 3KB
qqaa.mode1v3 40KB
CredentialImportController.nib 3KB
CredentialsController.nib 3KB
AuthenticationController.nib 2KB
AdvancedGetController.nib 2KB
MainWindow.nib 2KB
ClientIdentityController.nib 2KB
DebugController.nib 992B
CredentialsController.o 113KB
AdvancedGetController.o 82KB
CredentialImportController.o 59KB
ServerTrustChallengeHandler.o 56KB
ClientIdentityChallengeHandler.o 55KB
共 180 条
- 1
- 2
资源评论
jiuqiaozi
- 粉丝: 1
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功