We are developing an HTTP streaming iOS application that requires us to receive playlists from a secure site. This site requires us to authenticate using a self-signed SSL certificate.
We read the credentials from a .p12 file before using NSURLConnection with a delegate to respond to an authorization call.
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { [[challenge sender] useCredential: self.credentials forAuthenticationChallenge:challenge]; } - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace { return YES; }
By making this initial connection to the URL where we get the .m3u8 playlist, we can play the playlist using AVPlayer. The problem is that this method only works in the simulator.
NOTE. We can download the playlist using NSURLConnection on the device. This should mean that AVPlayer somehow cannot continue to use the trust established during this initial connection.
We also tried adding credentials to [NSURLCredentialStorage sharedCredentialStorage] with no luck.
The following is our shotgun approach:
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost:host port:443 protocol:@"https" realm:nil authenticationMethod:NSURLAuthenticationMethodClientCertificate]; [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:creds forProtectionSpace:protectionSpace]; NSURLProtectionSpace *protectionSpace2 = [[NSURLProtectionSpace alloc] initWithHost:host port:443 protocol:@"https" realm:nil authenticationMethod:NSURLAuthenticationMethodServerTrust]; [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential:creds forProtectionSpace:protectionSpace2];
EDIT: According to this question : the above method does not work with certificates.
Any hint as to why it doesn't work on the device, or an alternative solution is welcome!
source share