Still failing
used the apple development certificate(from keychain access) my code.
the certificate is protected with alogs:
pbeWithSHA1And3-KeyTripleDES-CBC
pbeWithSHA1And40BitRC2-CBC
in openssl PKCS12_create used the above algos for creating PKCS12. which is further passed to SecPKCS12Import
attaching my code below:
BIO* createPKCS12fromPKCS12(const unsigned char* data, long dataLength, char* originalPassphrase, char* newPassphrase) {
OSSL_PROVIDER legacy = OSSL_PROVIDER_try_load(NULL, "legacy", 1);
OSSL_PROVIDER defaultProvider = OSSL_PROVIDER_try_load(NULL, "default", 1);
int nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
int nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC;
BIO bp = BIO_new_mem_buf(data, (int)dataLength);
PKCS12 originalPKCS12 = NULL;
d2i_PKCS12_bio(bp, &originalPKCS12);
BIO_free(bp);
EVP_PKEY* privateKey;
X509* x509;
STACK_OF(X509)* caChain = NULL;
PKCS12_parse(originalPKCS12, originalPassphrase, &privateKey, &x509, &caChain);
PKCS12_free(originalPKCS12);
// printf("%d", nid_key);
// printf("%d", nid_cert);
PKCS12* newPKCS12 = PKCS12_create(newPassphrase, "SAP Identity", privateKey, x509, caChain, nid_key, nid_cert, 0,\ PKCS12_DEFAULT_ITER, 0);
unsigned long a = ERR_get_error();
printf("%lu", a);
EVP_PKEY_free(privateKey);
X509_free(x509);
sk_X509_free(caChain);
BIO* mem = NULL;
int verify = PKCS12_verify_mac(newPKCS12, newPassphrase, 0);
printf("%d", verify);
if (newPKCS12 != NULL) {
mem = BIO_new(BIO_s_mem());
i2d_PKCS12_bio(mem, newPKCS12);
PKCS12_free(newPKCS12);
}
return mem;
}\
public func obtainUserIdentity(completionHandler: @escaping (Data?, Error?) -> Void) {
logger.debug("Called: obtainUserIdentity(completionHandler:)")
let data = try Data(contentsOf: fileURL) // fileurl i spath of p12 file \
guard let pkcs12Data = OpenSSLHelperProxy.shared.createPKCS12fromPKCS12Data(data, passp\hraseOriginal: passphrase, passphraseNew: "") else {
logger.error("Create PKCS #12 from PKCS #12 data failed")
completionHandler(nil, IdentityError.failedToCreateIdentity)
return
}
completionHandler(pkcs12Data, nil)
}
\
-(NSData* _Nullable)createPKCS12fromPKCS12Data:(NSData* _Nonnull)PKCS12Data passphraseOriginal:(NSString* _Nonnull)passphraseOriginal passphraseNew:(NSString* _Nonnull)passphraseNew {/
BIO* mem = createPKCS12fromPKCS12([PKCS12Data bytes], [PKCS12Data length], (char*)[passphraseOriginal UTF8String], (char*)[passphraseNew UTF8String]);/
NSData* data = [OpenSSLHelperProxy NSDataFromBIO:mem];/
return data;/
}/
/
+(NSData*)NSDataFromBIO:(BIO*)mem {/
NSData* data = nil;/
if (mem != NULL) {/
char* ptr = NULL;/
/
size_t size = BIO_get_mem_data(mem, &ptr);/
data = [NSData dataWithBytes:ptr length:size];/
BIO_free(mem);/
}/
return data;/
}/
/
this Data is sent to
SecPKCS12Import(pkcs12Data as CFData, query as CFDictionary, &items)
which isthrowingg error