Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QSslCertificate::importPkcs12 fails to parse PFX file

I'm trying to unpack my pkcs12 file in my Qt application - but having no luck. I'm building a Qt Console App (GUI disabled).

(I've followed this guide: https://github.com/trueos/sysadm-ui-qt/blob/master/src-qt5/gui_client/SSLNotes.txt)

Pkcs12 creation commands:

"openssl req -newkey rsa:2048 -nodes -keyout test_key.pem"
"openssl req -key test_key -new -x509 -out test_crt.crt"
"openssl pkcs12 -inkey test_key.pem -in test_crt.crt -export -passout stdin -out new.pfx"

Qt Code:

QString password="1234";
QFile pkcs("/Users/test/Desktop/certs/new.pfx");
pkcs.open(QFile::ReadOnly);
QSslKey key;
QSslCertificate cert;
QList<QSslCertificate> imported_certs;
static bool import=QSslCertificate::importPkcs12(&pkcs,&key,&cert,&imported_certs,QByteArray::fromStdString(password.toStdString()));

pkcs.close();
qDebug()<<import;

Manually extracting the key and the file have worked using openssl commands.

Error Message:

"Unimplemented Code."

Any ideas?

like image 675
Babra Cunningham Avatar asked Sep 08 '16 14:09

Babra Cunningham


1 Answers

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

like image 191
Israel Lins Albuquerque Avatar answered Oct 13 '22 00:10

Israel Lins Albuquerque