QSslCertificate::importPkcs12 fails to parse PFX file

六眼飞鱼酱① 提交于 2019-12-04 22:45:40

Try using Qt < 5.6 like Qt 5.5.

In the Qt 5.6 the default SSL backend was changed from OpenSSL to Secure Transport on the Mac OS platform.

This problem already filled as a Bug: https://bugreports.qt.io/browse/QTBUG-56596

After beating my head against the wall with this a few times with this sort of thing, I found a good shortcut.

I import the certificate into a Windows machine (ensuring that the private key is marked as exportable) and verify that the certificate path is valid in the certificate manager. If I need to import certificates, I do it here until the issued certificate path is good. Once this is done, I re-export the certificate and private key into a new PKCS12 file, including the root and intermediary certificates. This produces a single file that can be imported into an ASA or IOS router and works flawlessly because everything the unit needs is present in one file.

Be sure to delete the certificate from the Windows machine when you're done exporting the certificate set.

Maybe this link will help you out:

TAKEN FROM: https://supportforums.cisco.com/discussion/12347971/failed-parse-or-verify-imported-certifiate-asa-5505-831

QSslCertificate::importPkcs12() will return "Unimplemented code." on macOS or iOS platforms because those Qt kits were been configured to use Secure Transport instead of OpenSSL.

To get the best of both worlds, I found that one could keep their Qt kits configured for Secure Transport, but, at the same time, link to OpenSSL to implement an OpenSSL specific implementation of importPkcs12.

The following is a snippet where we turn on our custom implementation for macOS and iOS:

#ifdef Q_OS_IOS
#define IMPORTPKCS12_OPENSSL
#endif
#ifdef Q_OS_MACOS
#define IMPORTPKCS12_OPENSSL
#endif

bool ImportPkcs12Patch::importPkcs12(QIODevice *device, QSslKey *key, QSslCertificate *certificate, QList<QSslCertificate> *caCertificates, const QByteArray &passPhrase)
{
#ifdef IMPORTPKCS12_OPENSSL
    return importPkcs12_openssl(device, key, certificate, caCertificates, passPhrase );
#else
    return QSslCertificate::importPkcs12(device, key, certificate, caCertificates, passPhrase );
#endif
}

For a complete working example, consult the sample here:

https://github.com/stephenquan/QtImportPKCS12

To build OpenSSL prerequisites for iOS and macOS, consult here:

https://github.com/stephenquan/build_openssl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!