From a2ffd393137aeb33b256be87cd318141bf91c3b0 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Wed, 27 Oct 2021 12:11:02 +0300 Subject: DocumentWidget: Security warnings --- src/ui/banner.c | 14 ++++++------ src/ui/banner.h | 4 +++- src/ui/documentwidget.c | 61 ++++++++++++++++++++++++++++++++++++------------- 3 files changed, 55 insertions(+), 24 deletions(-) (limited to 'src/ui') diff --git a/src/ui/banner.c b/src/ui/banner.c index cb30d8c5..0ffb1d9f 100644 --- a/src/ui/banner.c +++ b/src/ui/banner.c @@ -159,22 +159,22 @@ void setSite_Banner(iBanner *d, iRangecc site, iChar icon) { updateHeight_Banner_(d); } -void add_Banner(iBanner *d, enum iBannerType type, enum iGmStatusCode code, const iString *message) { +void add_Banner(iBanner *d, enum iBannerType type, enum iGmStatusCode code, + const iString *message, const iString *details) { iBannerItem item; init_BannerItem(&item); item.type = type; item.code = code; const iGmError *error = get_GmError(code); - if (error->icon) { - appendCStr_String(&item.text, escape_Color(tmBannerIcon_ColorId)); - appendChar_String(&item.text, error->icon); - appendCStr_String(&item.text, restore_ColorEscape); - } + iChar icon = code && error->icon ? error->icon : 0x26a0; /* /!\ */ + appendCStr_String(&item.text, escape_Color(tmBannerIcon_ColorId)); + appendChar_String(&item.text, icon); + appendCStr_String(&item.text, restore_ColorEscape); appendFormat_String(&item.text, " \x1b[1m%s%s\x1b[0m \u2014 %s%s", escape_Color(tmBannerItemTitle_ColorId), !isEmpty_String(message) ? cstr_String(message) : error->title, escape_Color(tmBannerItemText_ColorId), - error->info); + !isEmpty_String(details) ? cstr_String(details) : error->info); translate_Lang(&item.text); updateItemHeight_Banner_(d, &item); pushBack_Array(&d->items, &item); diff --git a/src/ui/banner.h b/src/ui/banner.h index d652c85f..5147603a 100644 --- a/src/ui/banner.h +++ b/src/ui/banner.h @@ -51,7 +51,9 @@ iLocalDef iBool isEmpty_Banner(const iBanner *d) { void clear_Banner (iBanner *); void setSite_Banner (iBanner *, iRangecc site, iChar icon); -void add_Banner (iBanner *, enum iBannerType type, enum iGmStatusCode code, const iString *message); +void add_Banner (iBanner *, enum iBannerType type, enum iGmStatusCode code, + const iString *message, + const iString *details); void remove_Banner (iBanner *, enum iGmStatusCode code); iBool processEvent_Banner (iBanner *, const SDL_Event *ev); diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 633b72d8..79bfea7b 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -1152,18 +1152,6 @@ static void updateTheme_DocumentWidget_(iDocumentWidget *d) { updateBanner_DocumentWidget_(d); } -#if 0 -static enum iGmDocumentBanner bannerType_DocumentWidget_(const iDocumentWidget *d) { - if (d->certFlags & available_GmCertFlag) { - const int req = domainVerified_GmCertFlag | timeVerified_GmCertFlag | trusted_GmCertFlag; - if ((d->certFlags & req) != req) { - return certificateWarning_GmDocumentBanner; - } - } - return siteDomain_GmDocumentBanner; -} -#endif - static void makeFooterButtons_DocumentWidget_(iDocumentWidget *d, const iMenuItem *items, size_t count) { iWidget *w = as_Widget(d); destroy_Widget(d->footerButtons); @@ -1289,7 +1277,7 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode replaceDocument_DocumentWidget_(d, errorDoc); iRelease(errorDoc); clear_Banner(d->banner); - add_Banner(d->banner, error_BannerType, code, meta); + add_Banner(d->banner, error_BannerType, code, meta, NULL); d->state = ready_RequestState; setSource_DocumentWidget(d, src); updateTheme_DocumentWidget_(d); @@ -1771,7 +1759,6 @@ static void updateTrust_DocumentWidget_(iDocumentWidget *d, const iGmResponse *r else { updateTextCStr_LabelWidget(lock, green_ColorEscape closedLock_Icon); } -// setBanner_GmDocument(d->doc, bannerType_DocumentWidget_(d)); } static void parseUser_DocumentWidget_(iDocumentWidget *d) { @@ -1797,17 +1784,59 @@ static void cacheDocumentGlyphs_DocumentWidget_(const iDocumentWidget *d) { } static void addBannerWarnings_DocumentWidget_(iDocumentWidget *d) { + /* Warnings related to certificates and trust. */ + const int certFlags = d->certFlags; + const int req = timeVerified_GmCertFlag | domainVerified_GmCertFlag | trusted_GmCertFlag; + if (certFlags & available_GmCertFlag && (certFlags & req) != req && + numItems_Banner(d->banner) == 0) { + iString *title = collectNewCStr_String(cstr_Lang("dlg.certwarn.title")); + iString *str = collectNew_String(); + if (certFlags & timeVerified_GmCertFlag && certFlags & domainVerified_GmCertFlag) { + iUrl parts; + init_Url(&parts, d->mod.url); + const iTime oldUntil = + domainValidUntil_GmCerts(certs_App(), parts.host, port_Url(&parts)); + iDate exp; + init_Date(&exp, &oldUntil); + iTime now; + initCurrent_Time(&now); + const int days = secondsSince_Time(&oldUntil, &now) / 3600 / 24; + if (days <= 30) { + appendCStr_String(str, + format_CStr(cstrCount_Lang("dlg.certwarn.mayberenewed.n", days), + cstrCollect_String(format_Date(&exp, "%Y-%m-%d")), + days)); + } + else { + appendCStr_String(str, cstr_Lang("dlg.certwarn.different")); + } + } + else if (certFlags & domainVerified_GmCertFlag) { + setCStr_String(title, get_GmError(tlsServerCertificateExpired_GmStatusCode)->title); + appendFormat_String(str, cstr_Lang("dlg.certwarn.expired"), + cstrCollect_String(format_Date(&d->certExpiry, "%Y-%m-%d"))); + } + else if (certFlags & timeVerified_GmCertFlag) { + appendFormat_String(str, cstr_Lang("dlg.certwarn.domain"), + cstr_String(d->certSubject)); + } + else { + appendCStr_String(str, cstr_Lang("dlg.certwarn.domain.expired")); + } + add_Banner(d->banner, warning_BannerType, none_GmStatusCode, title, str); + } + /* Warnings related to page contents. */ const int dismissed = value_SiteSpec(collectNewRange_String(urlRoot_String(d->mod.url)), dismissWarnings_SiteSpecKey) | (!prefs_App()->warnAboutMissingGlyphs ? missingGlyphs_GmDocumentWarning : 0); const int warnings = warnings_GmDocument(d->doc) & ~dismissed; if (warnings & missingGlyphs_GmDocumentWarning) { - add_Banner(d->banner, warning_BannerType, missingGlyphs_GmStatusCode, NULL); + add_Banner(d->banner, warning_BannerType, missingGlyphs_GmStatusCode, NULL, NULL); /* TODO: List one or more of the missing characters and/or their Unicode blocks? */ } if (warnings & ansiEscapes_GmDocumentWarning) { - add_Banner(d->banner, warning_BannerType, ansiEscapes_GmStatusCode, NULL); + add_Banner(d->banner, warning_BannerType, ansiEscapes_GmStatusCode, NULL, NULL); } } -- cgit v1.2.3