Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QSslCertificate::importPkcs12() not implemented on macosx
I developed a cross-platform qt app which can work on both mac and windows, I need to import the .p12 file, so I use the QSslCertificate::importPkcs12() method, it can work fine on windows, but when I run my app on mac, it shows error 'Unimplemented code.'
here is my code about load .p12 file
QDir temDir3(QString::fromLocal8Bit(g_license_dir.c_str())); QString abs_license_path = temDir3.absolutePath(); QFile license_file(abs_license_path); //Q_ASSERT(license_file.open(QIODevice::ReadOnly)); license_file.open(QIODevice::ReadOnly); QSslCertificate certificate; QSslKey key; QList<QSslCertificate> importedCerts; std::string passphrase = "";//123456 bool imported = QSslCertificate::importPkcs12(&license_file, &key, &certificate, &importedCerts, QByteArray::fromStdString(passphrase));
I certain the 'license_file' file path is right, and after large search, I found it is similar to the bug https://bugreports.qt.io/browse/QTBUG-56596,but it seems the bug is not solved,
what should I do for import the .p12 file success on macosx? thanks a lot!
Did you try to use the patch linked to the bug report ?
@SGaist yes, I had try, but it still can not solve this question!
This patch implements the missing method. Are you sure you are using your self build version of Qt that added this method ?
@SGaist but how use the patch to fix the bug?
@Princein If you're on Linux/MacOS then enter "man patch" in a terminal and read.
Also there is a lot information about applying patches on the Internet.
You need Qt source code, then you apply the patch and build Qt.
To add to @jsulm, there's also no need to rebuild all of Qt, qtbase will be enough for your test.
@SGaist, yes, I had download the qtbase directory, It seems the QSslCertificate::importPkcs12 method is implemented in the QtNetwork.framework, I will the change qsslsocket_mac.cpp file in the '~/Desktop/qt5/qtbase/src/network/ssl/' use the patch, after I fixed the code in network sub directory , how to build the qtbase directory to get the QtNetwork.framework? there is a network.pro file in the network sub directory , can I use QtCreator IDE open it to build and get the QtNetwork.framework?
I always build the full qtbase module when testing such changes.
@SGaist I must use the 5.6.1 qt framework because the history reason, so in my project, I use the QtNetwork.framework which version is 5.6.1 when I use the QSslCertificate::importPkcs12 method, it shows me error 'Unimplemented code.' I had read the document 'Qt for macOS - Building from Source' https://doc.qt.io/qt-5/macos-building.html and can build the QtNetwork.framework which version is 5.6.1 on my mac successfully as I expect;
I see the patch on https://codereview.qt-project.org/#/c/199128/, it seems the patch only changes the 'src/network/ssl/qsslsocket_mac.cpp' file, so I use the qsslsocket_mac.cpp file in the patch instead of the qsslsocket_mac.cpp in the qt-everywhere-opensource-src-5.6.1 which I had download, when I rebuild qtbase in the the qt-everywhere-opensource-src-5.6.1 directory, it's show errors which tip me lack some method,
now I wonder whether the patch suitable for qt5.6.1 source code qt-everywhere-opensource-src-5.6.1?
how can I use the patch correct?
thanks a lot!
so I use the qsslsocket_mac.cpp file in the patch instead of the qsslsocket_mac.cpp in the qt-everywhere-opensource-src-5.6.1
What do you mean by that ? A patch is meant to be applied on a file, not replace it.
@SGaist, the patch has Dependencies source code
is that means I must check out the dev branch on the git://code.qt.io/qt/qt5.git or other right git repository, after that using the patch for the dev branch? and then rebuild the qtbase subdirectory to get the fixed QtNetwork.framework?
@SGaist I had download the whole source code which includes the patch https://bugreports.qt.io/browse/QTBUG-56596 using 'git pull https://codereview.qt-project.org/qt/qtbase refs/changes/28/199128/11', and I build it successfully,I get the QtNetwork.framework after build,but the QtNetwork.framework which had the patch fix the bug version is 5.10.0, now in my qt project, the qt frameworks version is 5.6.1,can I change the QtNetwork.framework version from 5.10.0 to 5.6.1 by changing the source code config file? and how change the source code which includes the patch https://bugreports.qt.io/browse/QTBUG-56596 config file to generate 5.6.1 QtNetwork.framework? thanks a lot!
What you should do is get the 5.6.1 sources, and then apply the patch on top of the file of that version. You may have to do some adaptation by hand (maybe not)
Don't try to mix and match stuff.
@SGaist hahaha, I had solved this problem by changing the 5.6.1 version qtbase/network source code file by hand, thank you!
You're welcome !
Since you have it working now, pleas mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found.