Sorry there are some errors in my last post but I can't edit it. Re-post it again:
I also reproduced the same error and I created my p12 file with "step certificate" command on Windows WSL. How can I tell if my issue has the same root cause and how to fix it? This is how I created the my certificates:
Create self-signed ca:
step ca init
--deployment-type standalone
--name MqttAppSamplesCA
--dns localhost
--address 127.0.0.1:443
--provisioner MqttAppSamplesCAProvisioner
Create client crt and key files:
step certificate create
sample_client3 sample_client3.pem sample_client3.key
--ca ~/.step/certs/intermediate_ca.crt
--ca-key ~/.step/secrets/intermediate_ca_key
--no-password --insecure
--not-after 2400h
Create p12 file:
step certificate p12 sample_client3.p12 sample_client3.pem sample_client3.key --password-file=password.txt
Call SecPKCS12Import
let clientCertPath = Bundle.main.path(forResource: "sample_client3", ofType: "p12") let status = loadP12(filename: clientCertPath!, password: password)
public static func loadP12(filename: String, password: String) throws -> OSStatus {
let data = try Data(contentsOf: URL(fileURLWithPath: filename))
let options: [String: String] = [kSecImportExportPassphrase as String: password]
var rawItems: CFArray?
return SecPKCS12Import(data as CFData, options as CFDictionary, &rawItems)
}