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.
This commit is contained in:
Christian Hohnstaedt 2018-05-10 12:38:41 +02:00
parent dc36728df8
commit 0c8df14b7e
9 changed files with 143 additions and 56 deletions

View File

@ -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 \

View File

@ -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])

View File

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

View File

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

View File

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

View File

@ -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)

View File

@ -44,12 +44,6 @@
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
@ -64,12 +58,6 @@
</item>
<item>
<layout class="QHBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="text">
@ -90,9 +78,9 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="noColorize">
<widget class="QCheckBox" name="disableNetscape">
<property name="text">
<string>Don't colorize expired certificates</string>
<string>Disable legacy Netscape extensions</string>
</property>
</widget>
</item>
@ -116,12 +104,51 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification.</
</widget>
</item>
<item>
<widget class="QCheckBox" name="disableNetscape">
<widget class="QCheckBox" name="noColorize">
<property name="text">
<string>Disable legacy Netscape extensions</string>
<string>Don't colorize expired certificates</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Certificate expiry warning threshold</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="cert_expiry_num"/>
</item>
<item row="0" column="3">
<widget class="focusCombo" name="cert_expiry_unit"/>
</item>
<item row="1" column="3">
<widget class="focusCombo" name="ical_expiry_unit"/>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="ical_expiry_num"/>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Send iCalendar expiry reminder</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
@ -150,12 +177,6 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification.</
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="extDNobj"/>
</item>
@ -206,12 +227,6 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification.</
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="_2">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="expDNobj"/>
</item>
@ -351,6 +366,11 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification.</
<extends>QComboBox</extends>
<header>widgets/hashBox.h</header>
</customwidget>
<customwidget>
<class>focusCombo</class>
<extends>QComboBox</extends>
<header>widgets/FocusCombo.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>hashAlgo</tabstop>
@ -364,8 +384,8 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification.</
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>370</x>
<y>406</y>
<x>376</x>
<y>495</y>
</hint>
<hint type="destinationlabel">
<x>109</x>
@ -380,8 +400,8 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification.</
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>447</x>
<y>394</y>
<x>453</x>
<y>495</y>
</hint>
<hint type="destinationlabel">
<x>194</x>
@ -389,5 +409,37 @@ Especially EC and DSA are only defined with SHA1 in the PKCS#11 specification.</
</hint>
</hints>
</connection>
<connection>
<sender>noColorize</sender>
<signal>toggled(bool)</signal>
<receiver>cert_expiry_num</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>139</x>
<y>241</y>
</hint>
<hint type="destinationlabel">
<x>333</x>
<y>267</y>
</hint>
</hints>
</connection>
<connection>
<sender>noColorize</sender>
<signal>toggled(bool)</signal>
<receiver>cert_expiry_unit</receiver>
<slot>setDisabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>448</x>
<y>242</y>
</hint>
<hint type="destinationlabel">
<x>529</x>
<y>266</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

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

View File

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