[PATCH] (Issue 9) Log key's sha256 fingerprint
Wald Commits
scm-commit at wald.intevation.org
Mon Jun 30 17:22:12 CEST 2014
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1404141704 -7200
# Node ID 75cd2fbf9ac6fa190845acfee18d67fddf4fa749
# Parent 237af0c824540f22343bc3fee190ad72912b829c
(Issue 9) Log key's sha256 fingerprint
diff -r 237af0c82454 -r 75cd2fbf9ac6 ui/administratorwindow.cpp
--- a/ui/administratorwindow.cpp Mon Jun 30 15:41:13 2014 +0200
+++ b/ui/administratorwindow.cpp Mon Jun 30 17:21:44 2014 +0200
@@ -224,7 +224,7 @@
}
}
-void AdministratorWindow::logChanges(const QString ¤tCerts)
+void AdministratorWindow::logChanges(const QString ¤tCerts, const QString& keyFingerprint)
{
QDir logDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
QString logFilePath = logDir.filePath("log.txt");
@@ -239,7 +239,7 @@
CertificateList newCertList;
newCertList.readList(currentCerts.toLocal8Bit());
- QByteArray entries = createLogEntries(newCertList);
+ QByteArray entries = createLogEntries(newCertList, keyFingerprint);
if(logFile.write(entries) != entries.size()) {
QMessageBox::warning(this, tr("Error!"), tr("Failed to write log file: ") +
logFilePath + tr(" Changes are not logged!"));
@@ -248,7 +248,7 @@
logFile.close();
}
-QByteArray AdministratorWindow::createLogEntries(const CertificateList &list)
+QByteArray AdministratorWindow::createLogEntries(const CertificateList &list, const QString& keyFingerprint)
{
QByteArray entries;
QByteArray removeListEntries;
@@ -265,7 +265,9 @@
listDate.toString(Qt::ISODate) +
"#####\r\n");
entries.append(tr("signing certificate: \r\n"));
- entries.append(tr("new certificates:\r\n"));
+ entries.append(keyFingerprint);
+
+ entries.append(tr("\r\nnew certificates:\r\n"));
foreach (const Certificate& cert, list.getCertificates()) {
if (!mCertList.getCertificates().contains(cert)) {
diff -r 237af0c82454 -r 75cd2fbf9ac6 ui/administratorwindow.h
--- a/ui/administratorwindow.h Mon Jun 30 15:41:13 2014 +0200
+++ b/ui/administratorwindow.h Mon Jun 30 17:21:44 2014 +0200
@@ -48,8 +48,9 @@
* saved as current.
*
* @param currentCerts Path to the current certificate list file.
+ * @param certFingerprint The fingerprint of the signing key used.
*/
- void logChanges(const QString ¤tCerts);
+ void logChanges(const QString ¤tCerts, const QString &keyFingerprint);
/** @brief get the currently changed certificates.
* @return a list of certificates.
@@ -71,7 +72,7 @@
void createContent();
void loadCertificateTable();
void addToCertificateTable(const QList<Certificate> &certs);
- QByteArray createLogEntries(const CertificateList &list);
+ QByteArray createLogEntries(const CertificateList &list, const QString &keyFingerprint);
QSettings mSettings;
diff -r 237af0c82454 -r 75cd2fbf9ac6 ui/createcertlistdialog.cpp
--- a/ui/createcertlistdialog.cpp Mon Jun 30 15:41:13 2014 +0200
+++ b/ui/createcertlistdialog.cpp Mon Jun 30 17:21:44 2014 +0200
@@ -272,7 +272,33 @@
return;
}
+
+ QString keyFingerprint;
+
+ {
+ /* Calculate sha256 sum of the der key */
+ unsigned char output_buf[16000]; /* Buf size taken from examples */
+ int ret;
+ ret = pk_write_key_der (mPk, output_buf, 16000);
+ if (ret <= 0) {
+ showErrorMessage(tr("Failed to calculate key hash."));
+ return;
+ }
+ QByteArray derKey((const char*)output_buf, ret);
+ QByteArray fp = sha256sum(derKey);
+
+ for (int i=0; i < fp.size(); i++) {
+ keyFingerprint += QString("%1").arg(
+ (unsigned char)(fp[i]), 0, 16).rightJustified(2, '0');
+ if (i != fp.size() - 1) {
+ keyFingerprint += ":";
+ }
+ }
+ keyFingerprint = keyFingerprint.toUpper();
+ }
+
+ mAdminWindow->logChanges(curCerts, keyFingerprint);
+
QMessageBox::information(this, "", tr("Saved certificate list:\n%1").arg(fileName));
- mAdminWindow->logChanges(curCerts);
close();
}
More information about the Trustbridge-commits
mailing list