• R/O
  • HTTP
  • SSH
  • HTTPS

MUtilities: 提交

MUtilities development repository


Commit MetaInfo

修订版4c8df65031ace054ff34595a5adf9565fb4f6050 (tree)
时间2015-09-01 05:56:39
作者LoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

Make signature validation work, when keyring file is not located in the same directory as the file to be validated.

更改概述

差异

--- a/include/MUtils/Global.h
+++ b/include/MUtils/Global.h
@@ -84,6 +84,9 @@ namespace MUtils
8484 MUTILS_API quint32 next_rand32(void);
8585 MUTILS_API quint64 next_rand64(void);
8686
87+ //Temp File Name
88+ MUTILS_API QString make_temp_file(const QString &basePath, const QString &extension, const bool placeholder = false);
89+
8790 //Parity
8891 MUTILS_API bool parity(quint32 value);
8992
--- a/src/Global.cpp
+++ b/src/Global.cpp
@@ -110,6 +110,37 @@ QString MUtils::rand_str(const bool &bLong)
110110 }
111111
112112 ///////////////////////////////////////////////////////////////////////////////
113+// GET TEMP FILE NAME
114+///////////////////////////////////////////////////////////////////////////////
115+
116+QString MUtils::make_temp_file(const QString &basePath, const QString &extension, const bool placeholder)
117+{
118+ for(int i = 0; i < 4096; i++)
119+ {
120+ const QString tempFileName = QString("%1/%2.%3").arg(basePath, rand_str(), extension);
121+ if(!QFileInfo(tempFileName).exists())
122+ {
123+ if(placeholder)
124+ {
125+ QFile file(tempFileName);
126+ if(file.open(QFile::ReadWrite))
127+ {
128+ file.close();
129+ return tempFileName;
130+ }
131+ }
132+ else
133+ {
134+ return tempFileName;
135+ }
136+ }
137+ }
138+
139+ qWarning("Failed to generate unique temp file name!");
140+ return QString();
141+}
142+
143+///////////////////////////////////////////////////////////////////////////////
113144 // COMPUTE PARITY
114145 ///////////////////////////////////////////////////////////////////////////////
115146
@@ -195,7 +226,8 @@ static bool temp_folder_cleanup_helper(const QString &tempPath)
195226 static void temp_folder_cleaup(void)
196227 {
197228 QWriteLocker writeLock(&g_temp_folder_lock);
198-
229+ qWarning("------------ temp_folder_cleaup ------------");
230+
199231 //Clean the directory
200232 while(!g_temp_folder_file.isNull())
201233 {
--- a/src/UpdateChecker.cpp
+++ b/src/UpdateChecker.cpp
@@ -648,10 +648,17 @@ bool UpdateChecker::checkSignature(const QString &file, const QString &signature
648648 return false;
649649 }
650650
651+ QString keyRingPath(m_binaryKeys);
652+ bool removeKeyring = false;
651653 if(QFileInfo(file).absolutePath().compare(QFileInfo(m_binaryKeys).absolutePath(), Qt::CaseInsensitive) != 0)
652654 {
653- qWarning("CheckSignature: File and keyring should be in same folder!");
654- return false;
655+ keyRingPath = make_temp_file(QFileInfo(file).absolutePath(), "gpg");
656+ removeKeyring = true;
657+ if(!QFile::copy(m_binaryKeys, keyRingPath))
658+ {
659+ qWarning("CheckSignature: Failed to copy the key-ring file!");
660+ return false;
661+ }
655662 }
656663
657664 QProcess process;
@@ -662,10 +669,14 @@ bool UpdateChecker::checkSignature(const QString &file, const QString &signature
662669 connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit()));
663670 connect(&process, SIGNAL(readyRead()), &loop, SLOT(quit()));
664671
665- process.start(m_binaryGnuPG, QStringList() << "--homedir" << "." << "--keyring" << QFileInfo(m_binaryKeys).fileName() << QFileInfo(signature).fileName() << QFileInfo(file).fileName());
672+ process.start(m_binaryGnuPG, QStringList() << "--homedir" << "." << "--keyring" << QFileInfo(keyRingPath).fileName() << QFileInfo(signature).fileName() << QFileInfo(file).fileName());
666673
667674 if(!process.waitForStarted())
668675 {
676+ if(removeKeyring)
677+ {
678+ remove_file(keyRingPath);
679+ }
669680 return false;
670681 }
671682
@@ -678,6 +689,11 @@ bool UpdateChecker::checkSignature(const QString &file, const QString &signature
678689 }
679690 }
680691
692+ if(removeKeyring)
693+ {
694+ remove_file(keyRingPath);
695+ }
696+
681697 log(QString().sprintf("Exited with code %d", process.exitCode()));
682698 return (process.exitCode() == 0);
683699 }
Show on old repository browser