[geary/wip/20-cert-pinning: 31/36] Don't block handling GTlsConnection::accept-certificate



commit c0b5d44575867e780b17dc8d67f42160a27495e0
Author: Michael Gratton <mike vee net>
Date:   Tue Jan 8 23:52:54 2019 +1100

    Don't block handling GTlsConnection::accept-certificate
    
    The docs for accept-certificate require that clients do not block while
    handling it, and Geary will typically prompt the user when handling it.
    
    This fix schedules handling the signal to be executed seperately on the
    main loop.

 src/engine/api/geary-endpoint.vala | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/src/engine/api/geary-endpoint.vala b/src/engine/api/geary-endpoint.vala
index c85cd38c..4968751a 100644
--- a/src/engine/api/geary-endpoint.vala
+++ b/src/engine/api/geary-endpoint.vala
@@ -166,7 +166,7 @@ public class Geary.Endpoint : BaseObject {
         tls_cx.accept_certificate.connect(on_accept_certificate);
     }
 
-    private bool report_tls_warnings(GLib.TlsConnection cx,
+    private void report_tls_warnings(GLib.TlsConnection cx,
                                      GLib.TlsCertificate cert,
                                      GLib.TlsCertificateFlags warnings) {
         // TODO: Report or verify flags with user, but for now merely
@@ -181,8 +181,6 @@ public class Geary.Endpoint : BaseObject {
         untrusted_certificate = cert;
 
         untrusted_host(cx);
-
-        return false;
     }
 
     private string tls_flags_to_string(TlsCertificateFlags flags) {
@@ -213,7 +211,15 @@ public class Geary.Endpoint : BaseObject {
     private bool on_accept_certificate(GLib.TlsConnection cx,
                                        GLib.TlsCertificate cert,
                                        GLib.TlsCertificateFlags flags) {
-        return report_tls_warnings(cx, cert, flags);
+        // Per the docs for GTlsConnection.accept-certificate,
+        // handling this signal must not block, so do this when idle
+        GLib.Idle.add(() => {
+                report_tls_warnings(cx, cert, flags);
+                return GLib.Source.REMOVE;
+            },
+            GLib.Priority.HIGH
+        );
+        return false;
     }
 
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]