Resolve #4526 added local fingerprint in server GUI

This commit is contained in:
XinyuHou 2015-04-16 15:10:33 +01:00
parent 7ab1081b3f
commit 88538e5ee6
6 changed files with 113 additions and 4 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="utf-8"?>
<ui version="4.0">
<class>MainWindowBase</class>
<widget class="QMainWindow" name="MainWindowBase">
@ -117,6 +117,30 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="m_pLabelFingerprint">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Fingerprint:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="m_pLabelLocalFingerprint">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="m_pRadioInternalConfig">
<property name="text">
@ -128,7 +152,7 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="m_pButtonConfigureServer">
<property name="text">

View File

@ -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;
}

View File

@ -33,6 +33,8 @@ public:
static Fingerprint trustedServers();
static Fingerprint trustedClients();
static QString localFingerprint();
private:
QString m_Filename;
};

View File

@ -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());
}

View File

@ -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();
}

View File

@ -67,6 +67,7 @@ private:
int m_DownloadIndex;
DataDownloader m_DataDownloader;
CoreInterface m_CoreInterface;
QString m_standardOutput;
};
#endif // PLUGINMANAGER_H