2010-10-22 29 views
5

Sunucumla güvenli bir şekilde iletişim kurmak için iOS güvenlik çerçevesini kullanmaya çalışıyorum. Genel anahtar referansını alabildiğim bir sertifika dosyam var. Yaptığım bu.SecTrustCreateWithCertificates iPad'de kilitleniyor

NSString *certPath = [[NSBundle mainBundle] pathForResource:@"supportwarriors.com" ofType:@"cer"]; 
SecCertificateRef myCertificate = nil; 

NSData *certificateData = [[NSData alloc] initWithContentsOfFile:certPath]; 
myCertificate  = SecCertificateCreateWithData(kCFAllocatorDefault, (CFDataRef)certificateData); 

//got certificate ref..Now get public key secKeyRef reference from certificate.. 
SecPolicyRef myPolicy = SecPolicyCreateBasicX509(); 
SecTrustRef myTrust; 
OSStatus status  = SecTrustCreateWithCertificates(myCertificate,myPolicy,&myTrust); 

    SecTrustResultType trustResult; 
    if (status == noErr) { 
     status = SecTrustEvaluate(myTrust, &trustResult); 
    } 
publicKey  = SecTrustCopyPublicKey(myTrust); 

Kod parçasının üstünde iPhone üzerinde mükemmel çalışır ve bunu test ettim. Sunucumla güvenli bir şekilde iletişim kurabiliyorum. Ancak iPad'imde uygulamanızı çalıştırmayı denediğimde (2x modunda) yukarıdaki kod çöküyor. Hata ayıkladıktan sonra, secTrustCreateWithCertificate'ın kilitlendiğini ve çökme günlüğünün aşağıda verildiğini öğrendim. Kullanılan sertifika hem iPad hem de iPhone için aynıdır ... Yukarıdaki sertifika secCertificateCreateWithData bir sertifika başvurusunu döndürür ve nil değildir ... çökme nedenini değil .. Ne yapıyorum yanlış.

*** -[NSCFType count]: unrecognized selector sent to instance 0x14af24 
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '***  -[NSCFType count]: unrecognized selector sent to instance 0x14af24' 
+0

Sertifikayı gönderir misiniz? – rook

cevap

4

tek bir sertifika veya dizi geçebilir SecTrustCreateWithCertificates İstem belgelerine. Aldığınız istisna, -[NSCFType count]: unrecognized selector sent to instance. IOS 3.2'de olan şey, SecCertificateRef tekil olup olmadığını görmek için ilk kez kontrol etmeden SecTrustCreateWithCertificates'un bir CFArray gibi giriş değerini işlemesidir.

SecCertificateRef certs[1] = { certificate }; 
    CFArrayRef array = CFArrayCreate(NULL, (const void **) certs, 1, NULL); 
    if(SecTrustCreateWithCertificates(array, x509Policy, &trustChain) == errSecSuccess) 

sadece uygun kapsamda CFRelease(array) unutmayın:

bu sorunu, aşağıdaki koda benzer bir şey yapabilirsiniz almak için.

İlgili konular