diff --git a/lib/asn1time.cpp b/lib/asn1time.cpp index dc0dffa7..813864dd 100644 --- a/lib/asn1time.cpp +++ b/lib/asn1time.cpp @@ -10,6 +10,7 @@ #include #include #include +#include a1time::a1time() { @@ -73,29 +74,31 @@ a1time &a1time::set(int y, int mon, int d, int h, int m, int s) return set(gt); } +/* As defined in rfc-5280 4.1.2.5 */ +#define UNDEFINED_DATE "99991231235959Z" QString a1time::toPretty() const { - QString t = ""; - if (!time) return t; - BIO * bio = BIO_new(BIO_s_mem()); + if (!time) + return QString(); + if (QString::fromAscii((char*)time->data, time->length) == UNDEFINED_DATE) + return QObject::tr("Undefined"); + char buf[200]; + BIO * bio = BIO_new(BIO_s_mem()); ASN1_TIME_print(bio, time); BIO_gets(bio, buf, 200); - t = buf; BIO_free(bio); - return t; + return QString(buf); } QString a1time::toPlain() const { - QString t = ""; - char b[15]; - if (!time) return t; - memcpy(b, time->data, time->length); - b[time->length] = '\0'; - t = b; - return t; + QString t; + if (time) { + t = QString::fromAscii((char*)time->data, time->length); + } + return t; } QString a1time::toSortable() const @@ -119,6 +122,11 @@ a1time &a1time::set(const QString &s) return *this; } +void a1time::setUndefined() +{ + ASN1_GENERALIZEDTIME_set_string(time, UNDEFINED_DATE); +} + int a1time::ymdg(int *y, int *m, int *d, int *g) const { int h, M, s; diff --git a/lib/asn1time.h b/lib/asn1time.h index 60e112b9..e653ee49 100644 --- a/lib/asn1time.h +++ b/lib/asn1time.h @@ -25,6 +25,7 @@ class a1time a1time &set(time_t t); a1time &set(const QString &s); a1time &set(int y, int mon, int d, int h, int m, int s); + void setUndefined(); QString toPretty() const; QString toPlain() const; QString toSortable() const; diff --git a/lib/db_x509.cpp b/lib/db_x509.cpp index b44151b2..d702f778 100644 --- a/lib/db_x509.cpp +++ b/lib/db_x509.cpp @@ -481,8 +481,14 @@ void db_x509::newCert(NewX509 *dlg) // Step 3 - Choose the Date // Date handling - cert->setNotBefore( dlg->notBefore->getDate() ); - cert->setNotAfter( dlg->notAfter->getDate() ); + cert->setNotBefore(dlg->notBefore->getDate()); + a1time a; + if (dlg->noWellDefinedExpDate->isChecked()) + a.setUndefined(); + else + a = dlg->notAfter->getDate(); + + cert->setNotAfter(a); if (cert->resetTimes(signcert) > 0) { if (QMessageBox::information(mainwin,tr(XCA_TITLE), diff --git a/lib/pki_scard.cpp b/lib/pki_scard.cpp index cb603faa..05b5701f 100644 --- a/lib/pki_scard.cpp +++ b/lib/pki_scard.cpp @@ -92,8 +92,10 @@ bool pki_scard::init_p11engine(QString file, bool silent) // XCA_ENGINE_cmd(e, "VERBOSE", NULL); ENGINE_init(e); - if (ERR_peek_error() != 0) + if (ERR_peek_error() != 0) { + ign_openssl_error(); return false; + } p11_engine = e; return true; } diff --git a/ui/NewX509.ui b/ui/NewX509.ui index b9a30342..c81e106b 100644 --- a/ui/NewX509.ui +++ b/ui/NewX509.ui @@ -5,20 +5,14 @@ 0 0 - 499 - 539 + 547 + 599 Dialog - - - 6 - - - 9 - + @@ -85,7 +79,7 @@ - 0 + 2 @@ -626,9 +620,6 @@ If this list is disabled, you only can create a self-signed certificate. - - This funny button creates a key. Go figure. - &Generate a new key @@ -643,13 +634,7 @@ If this list is disabled, you only can create a self-signed certificate. Extensions - - - 6 - - - 9 - + @@ -811,25 +796,29 @@ It also copies the issuer and serial number from the issuer certificate. Normall - + + true + + - 6 + -1 - 9 + 0 Validity - - - 8 - - - 6 - + + + + + Not before + + + @@ -843,6 +832,13 @@ It also copies the issuer and serial number from the issuer certificate. Normall + + + + Not after + + + @@ -856,20 +852,6 @@ It also copies the issuer and serial number from the issuer certificate. Normall - - - - Not before - - - - - - - Not after - - - @@ -878,19 +860,9 @@ It also copies the issuer and serial number from the issuer certificate. Normall Time range - - - 8 - - - 6 - - - - - Apply - - + + + @@ -911,6 +883,19 @@ It also copies the issuer and serial number from the issuer certificate. Normall + + + + + 0 + 0 + + + + Apply + + + @@ -921,8 +906,12 @@ It also copies the issuer and serial number from the issuer certificate. Normall - - + + + + No well-defined expiration + + diff --git a/widgets/NewX509.cpp b/widgets/NewX509.cpp index c4876dc8..a6592439 100644 --- a/widgets/NewX509.cpp +++ b/widgets/NewX509.cpp @@ -507,6 +507,11 @@ void NewX509::newKeyDone(QString name) keyList->setCurrentIndex(keys.indexOf(name)); } +void NewX509::on_noWellDefinedExpDate_toggled(bool) +{ + notAfter->setEnabled(!noWellDefinedExpDate->isChecked()); +} + void NewX509::on_usedKeysToo_toggled(bool) { QString cur = keyList->currentText(); @@ -762,7 +767,7 @@ QString NewX509::mandatoryDnRemain() x509name n; int i; - if (fromReqCB->isChecked()) + if (fromReqCB->isChecked() && !reqSubChange->isChecked()) n = getSelectedReq()->getSubject(); else n = getX509name(); @@ -849,23 +854,8 @@ void NewX509::on_okButton_clicked() return; } } - if (notBefore->getDate().get_utc() == NULL || - notAfter->getDate().get_utc() == NULL) { - switch (QMessageBox::warning(this, tr(XCA_TITLE), - tr("The validity dates are out of range (1950 - 2049) to create " - "valid certificates. If you continue, your client may " - "reject the certificate."), - tr("Ok"), tr("Abort rollout"), tr("Continue rollout"))) - { - case -1: - case 0: - return; - case 1: - reject(); - return; - } - } - if (notBefore->getDate() > notAfter->getDate()) { + if (notBefore->getDate() > notAfter->getDate() && + !noWellDefinedExpDate->isChecked()) { switch (QMessageBox::warning(this, tr(XCA_TITLE), tr("The certificate will be out of date before it becomes valid. " "You most probably mixed up both dates."), diff --git a/widgets/NewX509.h b/widgets/NewX509.h index 293322e0..58f6d0aa 100644 --- a/widgets/NewX509.h +++ b/widgets/NewX509.h @@ -115,6 +115,7 @@ class NewX509: public QDialog, public Ui::NewX509 void on_usedKeysToo_toggled(bool checked); void on_tabWidget_currentChanged(int idx); void on_reqSubChange_clicked(); + void on_noWellDefinedExpDate_toggled(bool); signals: void genKey(QString);