diff --git a/src/gui/res/MainWindowBase.ui b/src/gui/res/MainWindowBase.ui index 73917975..0a47e0d3 100644 --- a/src/gui/res/MainWindowBase.ui +++ b/src/gui/res/MainWindowBase.ui @@ -1,4 +1,4 @@ - + MainWindowBase @@ -117,6 +117,30 @@ + + + + + + + 0 + 0 + + + + Fingerprint: + + + + + + + + + + + + @@ -128,7 +152,7 @@ - + diff --git a/src/gui/src/Fingerprint.cpp b/src/gui/src/Fingerprint.cpp index 70b5c786..e120ef55 100644 --- a/src/gui/src/Fingerprint.cpp +++ b/src/gui/src/Fingerprint.cpp @@ -102,3 +102,32 @@ Fingerprint Fingerprint::trustedClients() { return Fingerprint(kTrustedClientsFilename); } + +QString Fingerprint::localFingerprint() +{ + CoreInterface coreInterface; + QString profileDir = coreInterface.getProfileDir(); + + QString dirName = QString("%1/%2") + .arg(profileDir) + .arg(kDirName); + + QString path = QString("%1/%2").arg(dirName).arg(kLocalFilename); + + QFile file(path); + QString fingerprint; + if (file.open(QIODevice::ReadOnly)) + { + QTextStream in(&file); + while (!in.atEnd()) + { + QString context = in.readLine(); + if (!context.isEmpty()) { + fingerprint = context; + } + } + file.close(); + } + + return fingerprint; +} diff --git a/src/gui/src/Fingerprint.h b/src/gui/src/Fingerprint.h index 8618b521..342c51bc 100644 --- a/src/gui/src/Fingerprint.h +++ b/src/gui/src/Fingerprint.h @@ -33,6 +33,8 @@ public: static Fingerprint trustedServers(); static Fingerprint trustedClients(); + static QString localFingerprint(); + private: QString m_Filename; }; diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 794359f9..72f38516 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -941,6 +941,17 @@ void MainWindow::setEdition(int type) } setWindowTitle(title); + + if (type == Pro) { + m_pLabelFingerprint->setVisible(true); + m_pLabelLocalFingerprint->setVisible(true); + m_pLabelLocalFingerprint->setText( + Fingerprint::localFingerprint()); + } + else { + m_pLabelFingerprint->setVisible(false); + m_pLabelLocalFingerprint->setVisible(false); + } } void MainWindow::on_m_pGroupClient_toggled(bool on) @@ -1222,6 +1233,7 @@ void MainWindow::updateEdition() QString mac = getFirstMacAddress(); QString hashSrc = m_AppConfig.activateEmail() + mac; QString hashResult = hash(hashSrc); + if (hashResult == m_AppConfig.userToken()) { setEdition(m_AppConfig.edition()); } diff --git a/src/gui/src/PluginManager.cpp b/src/gui/src/PluginManager.cpp index c3ce8d03..813f52e1 100644 --- a/src/gui/src/PluginManager.cpp +++ b/src/gui/src/PluginManager.cpp @@ -39,6 +39,8 @@ static QString kCertificateLifetime = "365"; static QString kCertificateSubjectInfo = "/CN=Synergy"; static QString kCertificateFilename = "Synergy.pem"; static QString kUnixOpenSslCommand = "openssl"; +static const char kFingerprintDir[] = "ssl/fingerprints"; +static const char kFingerprintLocalFilename[] = "local.txt"; #if defined(Q_OS_WIN) static const char kWinPluginExt[] = ".dll"; @@ -353,6 +355,45 @@ void PluginManager::doGenerateCertificate() return; } + // generate fingerprint + arguments.clear(); + arguments.append("x509"); + arguments.append("-fingerprint"); + arguments.append("-sha1"); + arguments.append("-noout"); + arguments.append("-in"); + arguments.append(filename); + + if (!runProgram(openSslProgramFile, arguments, environment)) { + return; + } + + // write the standard output into file + filename.clear(); + filename.append(m_ProfileDir); + filename.append(QDir::separator()).append(kFingerprintDir); + QDir dir(filename); + if (!dir.exists()) { + dir.mkpath("."); + } + filename.append(QDir::separator()).append(kFingerprintLocalFilename); + + // only write the fingerprint part + int i = m_standardOutput.indexOf("="); + if (i != -1) { + i++; + QString fingerprint = m_standardOutput.mid(i, m_standardOutput.size() - i); + + QFile file(filename); + file.resize(0); + if (file.open(QIODevice::Append)) + { + QTextStream out(&file); + out << fingerprint << "\n"; + file.close(); + } + } + emit generateCertificateFinished(); } @@ -365,10 +406,10 @@ bool PluginManager::runProgram( bool success = process.waitForStarted(); - QString standardOutput, standardError; + QString standardError; if (success && process.waitForFinished()) { - standardOutput = process.readAllStandardOutput().trimmed(); + m_standardOutput = process.readAllStandardOutput().trimmed(); standardError = process.readAllStandardError().trimmed(); } diff --git a/src/gui/src/PluginManager.h b/src/gui/src/PluginManager.h index 31b987a9..c7e52c30 100644 --- a/src/gui/src/PluginManager.h +++ b/src/gui/src/PluginManager.h @@ -67,6 +67,7 @@ private: int m_DownloadIndex; DataDownloader m_DataDownloader; CoreInterface m_CoreInterface; + QString m_standardOutput; }; #endif // PLUGINMANAGER_H