Fixed encryption info in cli
This commit is contained in:
parent
20e46418ba
commit
eda2563d03
7 changed files with 33 additions and 10 deletions
|
@ -1,6 +1,6 @@
|
|||
|
||||
add_executable(kdeconnect-cli kdeconnect-cli.cpp)
|
||||
|
||||
target_link_libraries(kdeconnect-cli kdeconnectinterfaces Qt5::Network KF5::CoreAddons KF5::I18n)
|
||||
target_link_libraries(kdeconnect-cli kdeconnectinterfaces KF5::CoreAddons KF5::I18n)
|
||||
|
||||
install(TARGETS kdeconnect-cli ${INSTALL_TARGETS_DEFAULT_ARGS})
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusConnection>
|
||||
#include <QCoreApplication>
|
||||
#include <QSslCertificate>
|
||||
#include <QTextStream>
|
||||
|
||||
#include <KAboutData>
|
||||
|
@ -148,11 +148,24 @@ int main(int argc, char** argv)
|
|||
<< ": " << idx.data(NotificationsModel::NameModelRole).toString() << endl;
|
||||
}
|
||||
} else if(parser.isSet("encryption-info")) {
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall("org.kde.kdeconnect", "/modules/kdeconnect/devices/"+device, "org.kde.kdeconnect.device", "certificate");
|
||||
msg.setArguments(QVariantList() << QSsl::Pem);
|
||||
QDBusMessage reply = QDBusConnection::sessionBus().call(msg);
|
||||
QSslCertificate certificate = QSslCertificate::fromData(reply.arguments().first().toByteArray()).first();
|
||||
QTextStream(stderr) << certificate.toText() << endl;
|
||||
DeviceDbusInterface dev(device);
|
||||
QDBusPendingReply<QByteArray> devReply = dev.certificate(1); // QSsl::Der = 1
|
||||
devReply.waitForFinished();
|
||||
if (devReply.value().isEmpty()) {
|
||||
QTextStream(stderr) << i18n("The other device doesn\'t use a recent version of KDE Connect, using the legacy encryption method.") << endl;
|
||||
} else {
|
||||
QByteArray remoteCertificate = QCryptographicHash::hash(devReply.value(), QCryptographicHash::Sha1).toHex();
|
||||
for (int i=2 ; i<remoteCertificate.size() ; i+=3) remoteCertificate.insert(i, ':'); // Improve readability
|
||||
|
||||
DaemonDbusInterface iface;
|
||||
QDBusPendingReply<QByteArray> ifaceReply = iface.certificate(1); // QSsl::Der = 1
|
||||
ifaceReply.waitForFinished();
|
||||
QByteArray myCertificate = QCryptographicHash::hash(ifaceReply.value(), QCryptographicHash::Sha1).toHex();
|
||||
for (int i=2 ; i<myCertificate.size() ; i+=3) myCertificate.insert(i, ':'); // Improve readability
|
||||
|
||||
QTextStream(stderr) << i18n("SHA1 fingerprint of your device certificate is : ") << myCertificate << endl;
|
||||
QTextStream(stderr) << i18n("SHA1 fingerprint of remote device certificate is : ") << remoteCertificate << endl;
|
||||
}
|
||||
} else {
|
||||
QTextStream(stderr) << i18n("Nothing to be done") << endl;
|
||||
}
|
||||
|
|
|
@ -129,6 +129,13 @@ QStringList Daemon::devices(bool onlyReachable, bool onlyVisible) const
|
|||
return ret;
|
||||
}
|
||||
|
||||
QByteArray Daemon::certificate(int format) const
|
||||
{
|
||||
if (format == QSsl::Pem) return KdeConnectConfig::instance()->certificate().toPem();
|
||||
else return KdeConnectConfig::instance()->certificate().toDer();
|
||||
}
|
||||
|
||||
|
||||
void Daemon::onNewDeviceLink(const NetworkPackage& identityPackage, DeviceLink* dl)
|
||||
{
|
||||
const QString& id = identityPackage.get<QString>("deviceId");
|
||||
|
|
|
@ -62,6 +62,9 @@ public Q_SLOTS:
|
|||
//Returns a list of ids. The respective devices can be manipulated using the dbus path: "/modules/kdeconnect/Devices/"+id
|
||||
Q_SCRIPTABLE QStringList devices(bool onlyReachable = false, bool onlyVisible = false) const;
|
||||
|
||||
//Exposing kdeconnectconfig through daemon, needed to show certificate hash in cli, but this can be extended to name, id, public key etc. if needed
|
||||
Q_SCRIPTABLE QByteArray certificate(int format) const;
|
||||
|
||||
virtual void requestPairing(Device *d) = 0;
|
||||
virtual void reportError(const QString &title, const QString &description) = 0;
|
||||
virtual QNetworkAccessManager* networkAccessManager();
|
||||
|
|
|
@ -87,7 +87,7 @@ public:
|
|||
QString type() const { return type2str(m_deviceType); }
|
||||
QCA::PublicKey publicKey() const { return m_publicKey; }
|
||||
QSslCertificate certificate() const { return m_certificate; }
|
||||
Q_SCRIPTABLE QByteArray certificate(int format) const { return (format == QSsl::Pem) ? m_certificate.toPem() : m_certificate.toDer() ;} // To expose certificate through dbus
|
||||
Q_SCRIPTABLE QByteArray certificate(int format) const { return (format == QSsl::Pem) ? m_certificate.toPem() : m_certificate.toDer() ;} // To expose certificate through dbus for cli
|
||||
QString iconName() const;
|
||||
QString statusIconName() const;
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
|
||||
#include <KLocalizedString>
|
||||
|
||||
#include <QtCrypto>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
|
@ -297,3 +296,4 @@ QDir KdeConnectConfig::pluginConfigDir(QString deviceId, QString pluginName)
|
|||
return QDir(pluginConfigDir);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include <QtCrypto>
|
||||
#include <QDir>
|
||||
#include <QtNetwork/qsslcertificate.h>
|
||||
#include <QSslCertificate>
|
||||
|
||||
#include "kdeconnectcore_export.h"
|
||||
|
||||
|
|
Loading…
Reference in a new issue