summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-10-27 12:11:02 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-10-27 12:11:02 +0300
commita2ffd393137aeb33b256be87cd318141bf91c3b0 (patch)
treecf649c767967cde74388b561834cb9da91df2376 /src/ui
parentc6a81d733fd6c0340f68ecc220b3dec7005b1039 (diff)
DocumentWidget: Security warnings
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/banner.c14
-rw-r--r--src/ui/banner.h4
-rw-r--r--src/ui/documentwidget.c61
3 files changed, 55 insertions, 24 deletions
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) {
159 updateHeight_Banner_(d); 159 updateHeight_Banner_(d);
160} 160}
161 161
162void add_Banner(iBanner *d, enum iBannerType type, enum iGmStatusCode code, const iString *message) { 162void add_Banner(iBanner *d, enum iBannerType type, enum iGmStatusCode code,
163 const iString *message, const iString *details) {
163 iBannerItem item; 164 iBannerItem item;
164 init_BannerItem(&item); 165 init_BannerItem(&item);
165 item.type = type; 166 item.type = type;
166 item.code = code; 167 item.code = code;
167 const iGmError *error = get_GmError(code); 168 const iGmError *error = get_GmError(code);
168 if (error->icon) { 169 iChar icon = code && error->icon ? error->icon : 0x26a0; /* /!\ */
169 appendCStr_String(&item.text, escape_Color(tmBannerIcon_ColorId)); 170 appendCStr_String(&item.text, escape_Color(tmBannerIcon_ColorId));
170 appendChar_String(&item.text, error->icon); 171 appendChar_String(&item.text, icon);
171 appendCStr_String(&item.text, restore_ColorEscape); 172 appendCStr_String(&item.text, restore_ColorEscape);
172 }
173 appendFormat_String(&item.text, " \x1b[1m%s%s\x1b[0m \u2014 %s%s", 173 appendFormat_String(&item.text, " \x1b[1m%s%s\x1b[0m \u2014 %s%s",
174 escape_Color(tmBannerItemTitle_ColorId), 174 escape_Color(tmBannerItemTitle_ColorId),
175 !isEmpty_String(message) ? cstr_String(message) : error->title, 175 !isEmpty_String(message) ? cstr_String(message) : error->title,
176 escape_Color(tmBannerItemText_ColorId), 176 escape_Color(tmBannerItemText_ColorId),
177 error->info); 177 !isEmpty_String(details) ? cstr_String(details) : error->info);
178 translate_Lang(&item.text); 178 translate_Lang(&item.text);
179 updateItemHeight_Banner_(d, &item); 179 updateItemHeight_Banner_(d, &item);
180 pushBack_Array(&d->items, &item); 180 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) {
51 51
52void clear_Banner (iBanner *); 52void clear_Banner (iBanner *);
53void setSite_Banner (iBanner *, iRangecc site, iChar icon); 53void setSite_Banner (iBanner *, iRangecc site, iChar icon);
54void add_Banner (iBanner *, enum iBannerType type, enum iGmStatusCode code, const iString *message); 54void add_Banner (iBanner *, enum iBannerType type, enum iGmStatusCode code,
55 const iString *message,
56 const iString *details);
55void remove_Banner (iBanner *, enum iGmStatusCode code); 57void remove_Banner (iBanner *, enum iGmStatusCode code);
56 58
57iBool processEvent_Banner (iBanner *, const SDL_Event *ev); 59iBool 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) {
1152 updateBanner_DocumentWidget_(d); 1152 updateBanner_DocumentWidget_(d);
1153} 1153}
1154 1154
1155#if 0
1156static enum iGmDocumentBanner bannerType_DocumentWidget_(const iDocumentWidget *d) {
1157 if (d->certFlags & available_GmCertFlag) {
1158 const int req = domainVerified_GmCertFlag | timeVerified_GmCertFlag | trusted_GmCertFlag;
1159 if ((d->certFlags & req) != req) {
1160 return certificateWarning_GmDocumentBanner;
1161 }
1162 }
1163 return siteDomain_GmDocumentBanner;
1164}
1165#endif
1166
1167static void makeFooterButtons_DocumentWidget_(iDocumentWidget *d, const iMenuItem *items, size_t count) { 1155static void makeFooterButtons_DocumentWidget_(iDocumentWidget *d, const iMenuItem *items, size_t count) {
1168 iWidget *w = as_Widget(d); 1156 iWidget *w = as_Widget(d);
1169 destroy_Widget(d->footerButtons); 1157 destroy_Widget(d->footerButtons);
@@ -1289,7 +1277,7 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode
1289 replaceDocument_DocumentWidget_(d, errorDoc); 1277 replaceDocument_DocumentWidget_(d, errorDoc);
1290 iRelease(errorDoc); 1278 iRelease(errorDoc);
1291 clear_Banner(d->banner); 1279 clear_Banner(d->banner);
1292 add_Banner(d->banner, error_BannerType, code, meta); 1280 add_Banner(d->banner, error_BannerType, code, meta, NULL);
1293 d->state = ready_RequestState; 1281 d->state = ready_RequestState;
1294 setSource_DocumentWidget(d, src); 1282 setSource_DocumentWidget(d, src);
1295 updateTheme_DocumentWidget_(d); 1283 updateTheme_DocumentWidget_(d);
@@ -1771,7 +1759,6 @@ static void updateTrust_DocumentWidget_(iDocumentWidget *d, const iGmResponse *r
1771 else { 1759 else {
1772 updateTextCStr_LabelWidget(lock, green_ColorEscape closedLock_Icon); 1760 updateTextCStr_LabelWidget(lock, green_ColorEscape closedLock_Icon);
1773 } 1761 }
1774// setBanner_GmDocument(d->doc, bannerType_DocumentWidget_(d));
1775} 1762}
1776 1763
1777static void parseUser_DocumentWidget_(iDocumentWidget *d) { 1764static void parseUser_DocumentWidget_(iDocumentWidget *d) {
@@ -1797,17 +1784,59 @@ static void cacheDocumentGlyphs_DocumentWidget_(const iDocumentWidget *d) {
1797} 1784}
1798 1785
1799static void addBannerWarnings_DocumentWidget_(iDocumentWidget *d) { 1786static void addBannerWarnings_DocumentWidget_(iDocumentWidget *d) {
1787 /* Warnings related to certificates and trust. */
1788 const int certFlags = d->certFlags;
1789 const int req = timeVerified_GmCertFlag | domainVerified_GmCertFlag | trusted_GmCertFlag;
1790 if (certFlags & available_GmCertFlag && (certFlags & req) != req &&
1791 numItems_Banner(d->banner) == 0) {
1792 iString *title = collectNewCStr_String(cstr_Lang("dlg.certwarn.title"));
1793 iString *str = collectNew_String();
1794 if (certFlags & timeVerified_GmCertFlag && certFlags & domainVerified_GmCertFlag) {
1795 iUrl parts;
1796 init_Url(&parts, d->mod.url);
1797 const iTime oldUntil =
1798 domainValidUntil_GmCerts(certs_App(), parts.host, port_Url(&parts));
1799 iDate exp;
1800 init_Date(&exp, &oldUntil);
1801 iTime now;
1802 initCurrent_Time(&now);
1803 const int days = secondsSince_Time(&oldUntil, &now) / 3600 / 24;
1804 if (days <= 30) {
1805 appendCStr_String(str,
1806 format_CStr(cstrCount_Lang("dlg.certwarn.mayberenewed.n", days),
1807 cstrCollect_String(format_Date(&exp, "%Y-%m-%d")),
1808 days));
1809 }
1810 else {
1811 appendCStr_String(str, cstr_Lang("dlg.certwarn.different"));
1812 }
1813 }
1814 else if (certFlags & domainVerified_GmCertFlag) {
1815 setCStr_String(title, get_GmError(tlsServerCertificateExpired_GmStatusCode)->title);
1816 appendFormat_String(str, cstr_Lang("dlg.certwarn.expired"),
1817 cstrCollect_String(format_Date(&d->certExpiry, "%Y-%m-%d")));
1818 }
1819 else if (certFlags & timeVerified_GmCertFlag) {
1820 appendFormat_String(str, cstr_Lang("dlg.certwarn.domain"),
1821 cstr_String(d->certSubject));
1822 }
1823 else {
1824 appendCStr_String(str, cstr_Lang("dlg.certwarn.domain.expired"));
1825 }
1826 add_Banner(d->banner, warning_BannerType, none_GmStatusCode, title, str);
1827 }
1828 /* Warnings related to page contents. */
1800 const int dismissed = 1829 const int dismissed =
1801 value_SiteSpec(collectNewRange_String(urlRoot_String(d->mod.url)), 1830 value_SiteSpec(collectNewRange_String(urlRoot_String(d->mod.url)),
1802 dismissWarnings_SiteSpecKey) | 1831 dismissWarnings_SiteSpecKey) |
1803 (!prefs_App()->warnAboutMissingGlyphs ? missingGlyphs_GmDocumentWarning : 0); 1832 (!prefs_App()->warnAboutMissingGlyphs ? missingGlyphs_GmDocumentWarning : 0);
1804 const int warnings = warnings_GmDocument(d->doc) & ~dismissed; 1833 const int warnings = warnings_GmDocument(d->doc) & ~dismissed;
1805 if (warnings & missingGlyphs_GmDocumentWarning) { 1834 if (warnings & missingGlyphs_GmDocumentWarning) {
1806 add_Banner(d->banner, warning_BannerType, missingGlyphs_GmStatusCode, NULL); 1835 add_Banner(d->banner, warning_BannerType, missingGlyphs_GmStatusCode, NULL, NULL);
1807 /* TODO: List one or more of the missing characters and/or their Unicode blocks? */ 1836 /* TODO: List one or more of the missing characters and/or their Unicode blocks? */
1808 } 1837 }
1809 if (warnings & ansiEscapes_GmDocumentWarning) { 1838 if (warnings & ansiEscapes_GmDocumentWarning) {
1810 add_Banner(d->banner, warning_BannerType, ansiEscapes_GmStatusCode, NULL); 1839 add_Banner(d->banner, warning_BannerType, ansiEscapes_GmStatusCode, NULL, NULL);
1811 } 1840 }
1812} 1841}
1813 1842