2012-09-10 2 views
5

인증 할 .bks 키 저장소가 필요한 iPhone 응용 프로그램을 작성 중입니다. iOS 앱에 대한 정보는 찾지 못했습니다.사용. iPhone 응용 프로그램의 bks 키 저장소 인증서

Apple에서 앱의 키 스토어 사용을 허용하고 iOS를 시작하는 방법을 알고 싶습니다. 인증서는 BouncyCastle을 사용하여 생성됩니다. 나는 안드로이드에 대한 정보를 찾았지만 iOS에는 운이 없었습니다. 어떤 도움을 주시면 감사하겠습니다.

답변

2

당신은 당신이 상점 유형 및 저장소 공급자, look here에 대해 키 도구 말할 필요가 수도

keytool -exportcert -keystore <keystore> -file some.cer 

같은 키 스토어에서 필요한 인증서를 내보낼 수 있습니다.

당신이 코드와 아이폰 OS 키 체인에 그 .cer 파일을 읽을 수

: 인증서를 필요로 할 때

- (void) importCertToKeyChain: (NSData *) data 
{ 
    // Delete the old certificate, otherwise SecItemAdd complains. 
    OSStatus oss = SecItemDelete((__bridge CFDictionaryRef)([self clientCertificateQuery])); 

    // Import the certificate 
    SecCertificateRef certRef = NULL; 
    certRef = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)(data)); 

    NSDictionary *att = [NSDictionary dictionaryWithObjectsAndKeys: (__bridge id)(kSecClassCertificate), kSecClass, (__bridge id) certRef, kSecValueRef, nil]; 

    oss = SecItemAdd((__bridge CFDictionaryRef)(att), NULL); 
} 

는이 같은 키 체인에서 얻을 수 있습니다

- (SecCertificateRef) getCertFromKeyChain 
{ 
    CFTypeRef ref = NULL; 
    SecItemCopyMatching((__bridge CFDictionaryRef)([self clientCertificateQuery]), &ref); 

    return (SecCertificateRef) ref; 
} 

clientCertificateQuery의 모습 이렇게.

static NSString *clientCertSubject = @"TestSubjectClient"; 

-(NSMutableDictionary *) clientCertificateQuery 
{ 
    NSMutableDictionary *query = [[NSMutableDictionary alloc] init]; 
    [query setObject:(__bridge id) kSecClassCertificate forKey:(__bridge id)kSecClass]; 
    [query setObject:clientCertSubject forKey:(__bridge id<NSCopying>)(kSecMatchSubjectContains)]; 
    [query setObject:[NSNumber numberWithBool:YES] forKey:(__bridge id)kSecReturnRef]; 
id)kSecAttrKeyType]; 
    return query; 
} 

또한 PCKS12 저장소를 읽는 기능이 있습니다 (BKS 저장소를 해당 형식으로 변환해야 함). SecPKCS12Import이라고하며, iOS 키 체인에 인증서를 가져올 필요가 없습니다. 나는 운이 없었고 어쨌든 키 체인에 인증서가 필요했지만 여기는 something about this입니다.

업데이트 : camdaochemgio으로

는 응용 프로그램에서 (개인 키와 같은) 비밀 정보를 포함하는 인증서를 포함 할 때 권장되지 않는 방법보다 사용 코멘트에 지적했다. .cer 파일은 보호되지 않으므로 .ipa에서 쉽게 추출 할 수 있습니다.

PKCS # P12는 암호 보호 기능을 지원하므로이 기능을 사용하는 것이 좋습니다.

당신은 (from here를 촬영)이 같은 PKCS 번호의 P12에 키 스토어 은밀한 할 수 있습니다

keytool -importkeystore -srckeystore KEYSTORE.jks -destkeystore KEYSTORE.p12 -srcstoretype BKS -deststoretype PKCS12 -srcstorepass mysecret -deststorepass mysecret -srcalias myalias -destalias myalias -srckeypass mykeypass -destkeypass mykeypass -noprompt 

그런 다음이 같은 .P12 파일을 (크레딧 here 갈)로드 할 수

// Load Certificate 
NSString *path = [[NSBundle mainBundle] pathForResource:@"cert" ofType:@"p12"]; 
NSData *p12data = [NSData dataWithContentsOfFile:path]; 
CFDataRef inP12data = (__bridge CFDataRef)p12data; 

// Only password based PKCS#12 blobs are supported 
CFStringRef password = CFSTR("Password"); 
const void *keys[] = { kSecImportExportPassphrase }; 
const void *values[] = { password }; 
CFDictionaryRef options = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL); 

// The import 
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL); 
OSStatus securityError = SecPKCS12Import(inP12data, options, &items); 

if (securityError == 0) 
{ 
    // Exploring the content 
    CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex(items, 0); 
    const void *tempIdentity = NULL; 
    tempIdentity = CFDictionaryGetValue(myIdentityAndTrust, kSecImportItemIdentity); 
    *identity = (SecIdentityRef)tempIdentity; 
    const void *tempTrust = NULL; 
    tempTrust = CFDictionaryGetValue(myIdentityAndTrust, kSecImportItemTrust); 
    *trust = (SecTrustRef)tempTrust; 
} 

if (options) { 
    CFRelease(options); 
} 

마지막 이 주제에 관한 링크는 최소한

+0

  • https://developer.apple.com/library/ios/documentation/Security/Conceptual/CertKeyTrustProgGuide/iPhone_Tasks/iPhone_Tasks.html
  • 이 방법
  • https://developer.apple.com/library/ios/documentation/Security/Reference/certifkeytrustservices/Reference/reference.html
  • 은 안전하지 않습니다. 일부는 번들을 추출한 다음 암호없이 파일을 가져올 수 있습니다. 안드로이드로 키 스토어를 사용하는 것이 좋지만 iOS에서 키 스토어를 수행할지 여부는 알지 못합니다. 어떤 생각? –

    +0

    @camdaochemgio 맞습니다. PCKS12 상점 작업 방법에 대한 게시물을 업데이트했습니다. – sofacoder

    관련 문제