summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
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/documentwidget.c
parentc6a81d733fd6c0340f68ecc220b3dec7005b1039 (diff)
DocumentWidget: Security warnings
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c61
1 files changed, 45 insertions, 16 deletions
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