当使用客户端证书认证,为什么我不断收到NSURLErrorDomain code = -1206? [英] When using Client Certificate Authentication, why do I keep getting NSURLErrorDomain Code=-1206?

查看:258
本文介绍了当使用客户端证书认证,为什么我不断收到NSURLErrorDomain code = -1206?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code是用从约IOS客户端证书验证previous帖子code我。每次说这个作品,但为什么它为我工作?!?!

我不断收到以下错误:

 连接didFailWithError:错误域= NSURLErrorDomain code = -1206服务器www.mywebsite.com要求客户端证书。

我已经照着至少4员额有关计算器和2其他类似的网站同样的话题。他们都说同样的事情,但它不工作。

我知道我的 PKCS12 文件的工作,因为我把它通过电子邮件发送给我的iPad,在那里我安装了它在iPad上的钥匙串,我能够访问并授权与使用Safari证书的身份。这只是当我试图在第三方应用程序做使用它 NSURLConnection的,它拒绝让我做这件事。

任何建议,欢迎,我觉得我已经用尽了我的选择。


  //从我的FTP服务器上下载PKCS12证书。    * NSString的stringURL = @的ftp://用户:password@myipaddress/myclientId.p12
    * NSString的webStringURL = [stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL * URL = [NSURL URLWithString:webStringURL];
    NSData的* p12Data = [NSData的dataWithContentsOfURL:URL]
    如果(p12Data)
    {
        CFDataRef inP12data =(__bridge CFDataRef)p12Data;        SecIdentityRef myIdentity;
        SecTrustRef myTrust;
        OSStatus ERRMSG = NULL;        //这是一个已经在大约IOS客户端证书身份验证的所有其他职位被转贴相同的功能。所以我不打算重新发布的。
        ERRMSG = extractIdentityAndTrust(inP12data,&安培; myIdentity,&安培; myTrust);        SecCertificateRef myCertificate;
        SecIdentityCopyCertificate(myIdentity,&安培; myCertificate);        常量无效*证书[] = {} myCertificate;        CFArrayRef certsArray = CFArrayCreate(NULL,证书,1,NULL);        NSURLCredential *证书= [NSURLCredential credentialWithIdentity:myIdentity证书:(__桥的NSArray *)certsArray持久性:NSURLCredentialPersistenceNone];        [挑战发件人] useCredential:凭证forAuthenticationChallenge:挑战]


解决方案

错误是在这条线。第二个参数需要被设置为无

  NSURLCredential *证书= [NSURLCredential credentialWithIdentity:myIdentity证书:(__桥的NSArray *)certsArray持久性:NSURLCredentialPersistenceNone];

更改为:

  NSURLCredential *证书= [NSURLCredential credentialWithIdentity:myIdentity证书:无持久性:NSURLCredentialPersistenceNone];

The following code is me using code from previous posts about ios client certificate authentication. Every says this works, however why does it work for me?!?!

I keep getting the following error:

connection didFailWithError: Error Domain=NSURLErrorDomain Code=-1206 "The server "www.mywebsite.com" requires a client certificate.

I've followed at least 4 posts about this same topic on stackoverflow and 2 on other similar sites. They all say the same thing, except it isn't working.

I know my PKCS12 file works because i emailed it to my ipad, where i installed it on the ipad keychain and i'm able to access and authorize with the certificate identity using Safari. It is just when i'm trying to do it using a NSURLConnection in a 3rd party app, it refuses to allow me to do it.

Any suggestions are welcome, I feel like i've exhausted my options.


    // Download PKCS12 Cert from my FTP server.

    NSString *stringURL = @"ftp://user:password@myipaddress/myclientId.p12";        
    NSString* webStringURL = [stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL  *url = [NSURL URLWithString:webStringURL];
    NSData *p12Data = [NSData dataWithContentsOfURL:url];


    if ( p12Data )
    {   
        CFDataRef inP12data = (__bridge CFDataRef)p12Data;

        SecIdentityRef myIdentity;
        SecTrustRef myTrust;
        OSStatus errMsg = NULL;

        // This is the same function that has been reposted in all the other posts about ios client certification authentication.  So i'm not going to repost that.
        errMsg = extractIdentityAndTrust(inP12data, &myIdentity, &myTrust);

        SecCertificateRef myCertificate;
        SecIdentityCopyCertificate(myIdentity, &myCertificate);

        const void *certs[] = { myCertificate };

        CFArrayRef certsArray = CFArrayCreate(NULL, certs, 1, NULL);

        NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity certificates:(__bridge NSArray*)certsArray persistence:NSURLCredentialPersistenceNone];

        [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];

解决方案

Error was on this line. Second parameter needs to be set to "nil"

    NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity certificates:(__bridge NSArray*)certsArray persistence:NSURLCredentialPersistenceNone];

Changed to:

    NSURLCredential *credential = [NSURLCredential credentialWithIdentity:myIdentity certificates:nil persistence:NSURLCredentialPersistenceNone];

这篇关于当使用客户端证书认证,为什么我不断收到NSURLErrorDomain code = -1206?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆