From 0c8df14b7e7e1f5b2366a462daa2efabb834ecd0 Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Thu, 10 May 2018 12:38:41 +0200 Subject: [PATCH] Close #27: Configurable certificate expiry warning threshold Add configuration values in the Options dialog to control the time when certificates get marked yellow and the expiration alarm time in calendar entries. --- Makefile | 2 +- configure.ac | 15 +----- lib/pki_base.cpp | 3 +- lib/pki_x509.cpp | 18 +++++-- lib/settings.cpp | 2 + misc/build-mac.sh | 9 ++-- ui/Options.ui | 116 +++++++++++++++++++++++++++++++------------ widgets/FocusCombo.h | 15 ++++++ widgets/Options.cpp | 19 +++++++ 9 files changed, 143 insertions(+), 56 deletions(-) diff --git a/Makefile b/Makefile index d257fbd7..15520c62 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ INSTTARGET=$(patsubst %, install.%, $(INSTDIR)) APPTARGET=$(patsubst %, app.%, $(INSTDIR)) DMGSTAGE=$(BUILD)/xca-$(VERSION) -MACTARGET=$(DMGSTAGE)-$(DARWIN)${EXTRA_VERSION} +MACTARGET=$(DMGSTAGE)-${EXTRA_VERSION} APPDIR=$(DMGSTAGE)/xca.app/Contents OSSLSIGN_OPT=sign -pkcs12 "$(HOME)"/Christian_Hohnstaedt.p12 -askpass \ -n "XCA $(VERSION)" -i https://hohnstaedt.de/xca \ diff --git a/configure.ac b/configure.ac index 339f8e0f..f8be786e 100644 --- a/configure.ac +++ b/configure.ac @@ -13,22 +13,11 @@ AC_CHECK_TOOL(STRIP, [strip], [:]) DVERSION="`${CXX} --version | grep apple-darwin || :`" case "$DVERSION" in - *-apple-darwin17*) DARWIN="High-Sierra" ;; - *-apple-darwin16*) DARWIN="Sierra" ;; - *-apple-darwin15*) DARWIN="El-Capitan" ;; - *-apple-darwin14*) DARWIN="Yosemite" ;; - *-apple-darwin13*) DARWIN="Mavericks" ;; - *-apple-darwin12*) DARWIN="Mountain-Lion" ;; - *-apple-darwin11*) DARWIN="Lion" ;; - *-apple-darwin10*) DARWIN="Snow-Leopard" ;; - *-apple-darwin9*) DARWIN="Leopard" ;; - *-apple-darwin?) - AC_MSG_ERROR([echo Unsupported Mac OSX version $DVERSION]) - ;; + *-apple-darwin*) DARWIN="true" ;; esac if test -n "${DARWIN}"; then - AC_MSG_NOTICE([Mac OSX ${DARWIN} detected]) + AC_MSG_NOTICE([Mac OSX detected]) CXXFLAGS="${CXXFLAGS} -pipe -gdwarf-2 -Wno-overloaded-virtual" fi AC_SUBST([DARWIN]) diff --git a/lib/pki_base.cpp b/lib/pki_base.cpp index 451975ba..b22ace01 100644 --- a/lib/pki_base.cpp +++ b/lib/pki_base.cpp @@ -372,6 +372,7 @@ QStringList pki_base::icsVEVENT(const a1time &expires, MD5((const unsigned char *)ba.constData(), ba.length(), md); QString uniqueid = formatHash(md, MD5_DIGEST_LENGTH, false); QString desc = icsValue(description + "\n----------\n" + comment); + QString alarm = Settings["ical_expiry"]; return QStringList() << "BEGIN:VEVENT" << @@ -386,7 +387,7 @@ QStringList pki_base::icsVEVENT(const a1time &expires, "ACTION:EMAIL" << QString("SUMMARY:%1").arg(icsValue(summary)) << QString("DESCRIPTION:%1").arg(desc) << - "TRIGGER:-P1W" << + QString("TRIGGER:-P%1").arg(alarm) << "END:VALARM" << "END:VEVENT"; } diff --git a/lib/pki_x509.cpp b/lib/pki_x509.cpp index e08e1f87..5b75bbe4 100644 --- a/lib/pki_x509.cpp +++ b/lib/pki_x509.cpp @@ -1054,17 +1054,25 @@ QVariant pki_x509::bg_color(const dbheader *hd) const if (Settings["no_expire_colors"]) return QVariant(); + QString unit, cert_expiry_num = Settings["cert_expiry"]; + unit = cert_expiry_num.right(1); + cert_expiry_num.chop(1); + int n = cert_expiry_num.toInt(); + a1time nb, na, now, certwarn; nb = getNotBefore(); na = getNotAfter(); now = a1time::now(); - int lifetime = nb.secsTo(na); - - /* warn after 4/5 certificate lifetime */ - certwarn = na.addSecs(- lifetime /5); - + if (unit == "%") { + quint64 lifetime = nb.secsTo(na); + certwarn = nb.addSecs(lifetime *n /100); + } else if (unit == "D") { + certwarn = na.addDays(-n); + } else if (unit == "W") { + certwarn = na.addDays(-n*7); + } switch (hd->id) { case HD_cert_notBefore: if (nb > now || !nb.isValid() || nb.isUndefined()) diff --git a/lib/settings.cpp b/lib/settings.cpp index dc065248..699ae14c 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -31,6 +31,8 @@ settings::settings() defaul["string_opt"] = "MASK:0x2002"; defaul["workingdir"] = QDir::currentPath(); defaul["default_hash"] = hashBox::getDefault(); + defaul["ical_expiry"] = "1W"; + defaul["cert_expiry"] = "80%"; clear(); } diff --git a/misc/build-mac.sh b/misc/build-mac.sh index f9ffcf8c..adae71ca 100755 --- a/misc/build-mac.sh +++ b/misc/build-mac.sh @@ -7,7 +7,7 @@ read openssl < "`dirname $0`/../OpenSSL.version" test -f "$openssl".tar.gz || curl https://www.openssl.org/source/"$openssl".tar.gz > "$openssl".tar.gz tar zxf "$openssl".tar.gz (cd $openssl - ./Configure darwin64-x86_64-cc shared --prefix=$INSTALL_DIR + ./Configure darwin64-x86_64-cc shared --prefix=$INSTALL_DIR $CFLAGS #./config shared --prefix=$INSTALL_DIR make && make install_sw ) @@ -30,10 +30,11 @@ XCA_DIR="`cd $XCA_DIR/.. && pwd`" # define the installation dir and the path to the new library # it will be installed locally in the home directory -export EXTRA_VERSION="$i" export INSTALL_DIR="`pwd`"/install export DYLD_LIBRARY_PATH=$INSTALL_DIR/lib export QTDIR=/Users/chris/Qt/5.9.1/clang_64 +export CFLAGS="-mmacosx-version-min=10.10" +export EXTRA_VERSION="Yosemite" if test -f build-libs; then do_libtool @@ -46,8 +47,8 @@ rm -rf "$XCA_BUILD" mkdir -p "$XCA_BUILD" cd "$XCA_BUILD" -export CPPFLAGS="-I${INSTALL_DIR}/include -F$QTDIR" -export CXXFLAGS="-F$QTDIR" +export CPPFLAGS="$CFLAGS -I${INSTALL_DIR}/include -F$QTDIR" +export CXXFLAGS="$CFLAGS -F$QTDIR" export LDFLAGS="-L${INSTALL_DIR}/lib" (cd $XCA_DIR && ./bootstrap) diff --git a/ui/Options.ui b/ui/Options.ui index ad0ad8f5..39da6b3c 100644 --- a/ui/Options.ui +++ b/ui/Options.ui @@ -44,12 +44,6 @@ - - 6 - - - 0 - @@ -64,12 +58,6 @@ - - 6 - - - 0 - @@ -90,9 +78,9 @@ - + - Don't colorize expired certificates + Disable legacy Netscape extensions @@ -116,12 +104,51 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification. - + - Disable legacy Netscape extensions + Don't colorize expired certificates + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + Certificate expiry warning threshold + + + + + + + + + + + + + + + + + + + Send iCalendar expiry reminder + + + + + @@ -150,12 +177,6 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification. - - 6 - - - 0 - @@ -206,12 +227,6 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification. - - 6 - - - 0 - @@ -351,6 +366,11 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification.QComboBox
widgets/hashBox.h
+ + focusCombo + QComboBox +
widgets/FocusCombo.h
+
hashAlgo @@ -364,8 +384,8 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification.accept() - 370 - 406 + 376 + 495 109 @@ -380,8 +400,8 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification.reject() - 447 - 394 + 453 + 495 194 @@ -389,5 +409,37 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification. + + noColorize + toggled(bool) + cert_expiry_num + setDisabled(bool) + + + 139 + 241 + + + 333 + 267 + + + + + noColorize + toggled(bool) + cert_expiry_unit + setDisabled(bool) + + + 448 + 242 + + + 529 + 266 + + + diff --git a/widgets/FocusCombo.h b/widgets/FocusCombo.h index 7e78d4cb..811dff4d 100644 --- a/widgets/FocusCombo.h +++ b/widgets/FocusCombo.h @@ -19,6 +19,21 @@ class focusCombo : public QComboBox QComboBox::hidePopup(); emit highlighted(currentIndex()); } + QVariant currentItemData() + { + return QComboBox::itemData(currentIndex()); + } + void addItemsData(const QStringList &textdata, const QString &selected) + { + int c = 0; + Q_ASSERT(textdata.size() % 2 == 0); + for (int i=0; i< textdata.size(); i+=2) { + addItem(textdata[i], textdata[i+1]); + if (textdata[i+1] == selected) + c = i/2; + } + setCurrentIndex(c); + } }; #endif diff --git a/widgets/Options.cpp b/widgets/Options.cpp index f6aac205..0ec0bdbf 100644 --- a/widgets/Options.cpp +++ b/widgets/Options.cpp @@ -51,6 +51,20 @@ Options::Options(MainWindow *parent) transDnEntries->setCheckState(Settings["translate_dn"]); onlyTokenHashes->setCheckState(Settings["only_token_hashes"]); disableNetscape->setCheckState(Settings["disable_netscape"]); + + QStringList units; + QString x = Settings["ical_expiry"]; + + units << tr("Days") << "D" << tr("Weeks") << "W"; + ical_expiry_unit->addItemsData(units, x.right(1)); + x.chop(1); + ical_expiry_num->setText(x); + + units << "%" << "%"; + x = QString(Settings["cert_expiry"]); + cert_expiry_unit->addItemsData(units, x.right(1)); + x.chop(1); + cert_expiry_num->setText(x); } Options::~Options() @@ -129,6 +143,11 @@ int Options::exec() Settings["string_opt"] = string_opts[mbstring->currentIndex()]; Settings["pkcs11path"] = getPkcs11Provider(); + Settings["cert_expiry"] = cert_expiry_num->text() + + cert_expiry_unit->currentItemData().toString(); + Settings["ical_expiry"] = ical_expiry_num->text() + + ical_expiry_unit->currentItemData().toString(); + return TransCommit() ? QDialog::Accepted : QDialog::Rejected; }