diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-03 15:28:16 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-03 15:28:16 +0300 |
commit | 856fbf1bf25038997b3dd61fc8707370f085e6da (patch) | |
tree | 90c6526fc839184d24bdbd770a956c8568b2956b /src/ui | |
parent | 922ad3220909b7314ca629949b44d7d3aa0336b2 (diff) |
Server certificate TOFU
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/documentwidget.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 954ded0c..4c20a188 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -1,11 +1,11 @@ | |||
1 | #include "documentwidget.h" | 1 | #include "documentwidget.h" |
2 | #include "scrollwidget.h" | 2 | #include "scrollwidget.h" |
3 | #include "inputwidget.h" | 3 | #include "inputwidget.h" |
4 | #include "labelwidget.h" | ||
4 | #include "paint.h" | 5 | #include "paint.h" |
5 | #include "command.h" | 6 | #include "command.h" |
6 | #include "util.h" | 7 | #include "util.h" |
7 | #include "app.h" | 8 | #include "app.h" |
8 | #include "../gemini.h" | ||
9 | #include "../gmdocument.h" | 9 | #include "../gmdocument.h" |
10 | #include "../gmrequest.h" | 10 | #include "../gmrequest.h" |
11 | #include "../gmutil.h" | 11 | #include "../gmutil.h" |
@@ -406,13 +406,37 @@ static void scrollTo_DocumentWidget_(iDocumentWidget *d, int documentY) { | |||
406 | scroll_DocumentWidget_(d, 0); /* clamp it */ | 406 | scroll_DocumentWidget_(d, 0); /* clamp it */ |
407 | } | 407 | } |
408 | 408 | ||
409 | static void checkResponseCode_DocumentWidget_(iDocumentWidget *d) { | 409 | static void updateTrust_DocumentWidget_(iDocumentWidget *d) { |
410 | iAssert(d->request); | ||
411 | #define openLock_CStr "\U0001f513" | ||
412 | #define closedLock_CStr "\U0001f512" | ||
413 | int certFlags = certFlags_GmRequest(d->request); | ||
414 | iLabelWidget *lock = findWidget_App("navbar.lock"); | ||
415 | if (~certFlags & available_GmRequestCertFlag) { | ||
416 | setFlags_Widget(as_Widget(lock), disabled_WidgetFlag, iTrue); | ||
417 | updateTextCStr_LabelWidget(lock, gray50_ColorEscape openLock_CStr); | ||
418 | return; | ||
419 | } | ||
420 | setFlags_Widget(as_Widget(lock), disabled_WidgetFlag, iFalse); | ||
421 | if (~certFlags & domainVerified_GmRequestCertFlag) { | ||
422 | updateTextCStr_LabelWidget(lock, red_ColorEscape closedLock_CStr); | ||
423 | } | ||
424 | else if (certFlags & trusted_GmRequestCertFlag) { | ||
425 | updateTextCStr_LabelWidget(lock, green_ColorEscape closedLock_CStr); | ||
426 | } | ||
427 | else { | ||
428 | updateTextCStr_LabelWidget(lock, orange_ColorEscape closedLock_CStr); | ||
429 | } | ||
430 | } | ||
431 | |||
432 | static void checkResponse_DocumentWidget_(iDocumentWidget *d) { | ||
410 | if (!d->request) { | 433 | if (!d->request) { |
411 | return; | 434 | return; |
412 | } | 435 | } |
413 | enum iGmStatusCode statusCode = status_GmRequest(d->request); | 436 | enum iGmStatusCode statusCode = status_GmRequest(d->request); |
414 | if (d->state == fetching_DocumentState) { | 437 | if (d->state == fetching_DocumentState) { |
415 | d->state = receivedPartialResponse_DocumentState; | 438 | d->state = receivedPartialResponse_DocumentState; |
439 | updateTrust_DocumentWidget_(d); | ||
416 | switch (statusCode / 10) { | 440 | switch (statusCode / 10) { |
417 | case 1: /* input required */ { | 441 | case 1: /* input required */ { |
418 | iUrl parts; | 442 | iUrl parts; |
@@ -594,14 +618,13 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
594 | } | 618 | } |
595 | else if (isCommand_Widget(w, ev, "document.request.updated") && | 619 | else if (isCommand_Widget(w, ev, "document.request.updated") && |
596 | pointerLabel_Command(command_UserEvent(ev), "request") == d->request) { | 620 | pointerLabel_Command(command_UserEvent(ev), "request") == d->request) { |
597 | checkResponseCode_DocumentWidget_(d); | 621 | checkResponse_DocumentWidget_(d); |
598 | // updateSource_DocumentWidget_(d); | ||
599 | return iFalse; | 622 | return iFalse; |
600 | } | 623 | } |
601 | else if (isCommand_Widget(w, ev, "document.request.finished") && | 624 | else if (isCommand_Widget(w, ev, "document.request.finished") && |
602 | pointerLabel_Command(command_UserEvent(ev), "request") == d->request) { | 625 | pointerLabel_Command(command_UserEvent(ev), "request") == d->request) { |
603 | // updateSource_DocumentWidget_(d); | 626 | iAssert(d->state == receivedPartialResponse_DocumentState); /* must already have been updated at least once */ |
604 | checkResponseCode_DocumentWidget_(d); | 627 | checkResponse_DocumentWidget_(d); |
605 | d->state = ready_DocumentState; | 628 | d->state = ready_DocumentState; |
606 | iReleasePtr(&d->request); | 629 | iReleasePtr(&d->request); |
607 | postCommandf_App("document.changed url:%s", cstr_String(d->url)); | 630 | postCommandf_App("document.changed url:%s", cstr_String(d->url)); |