[gnome-keysign: 4/11] send: show the "return" button if the sender is known




commit 4f99043b2c118a4e4ed974976fcc13dddf8606c2
Author: Tobias Mueller <muelli cryptobitch de>
Date:   Fri Sep 11 21:44:51 2020 +0200

    send: show the "return" button if the sender is known
    
    We don't know the sender, currently. So the button is never shown. We
    probably can find it, though. This lays the infrastructure for returning
    the certification back to the sender, although we need to prepare an
    email, still.

 keysign/send.py | 38 ++++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)
---
diff --git a/keysign/send.py b/keysign/send.py
index 4205622..d9aa1ad 100644
--- a/keysign/send.py
+++ b/keysign/send.py
@@ -131,13 +131,24 @@ class SendApp:
             with open(filename, "rb") as si:
                 signatures.append(si.read())
 
+        # We currently do not know how to obtain the sender of the email.
+        # We could parse the email for a From: header.
+        # But if only the attachment is dropped, we don't have that information.
+        # We could probably find the issuer in the hashed area of the certification packet,
+        # and then try to find that key in our keyring.
+        sender = None
+
         try:
+            decrypted_certifications = []
             for signature in signatures:
-                gpgmeh.decrypt_and_import_signature(signature)
-            self.signature_imported()
+                decrypted_certification = gpgmeh.decrypt_signature(signature)
+                import_result = gpgmeh.import_signature(decrypted_certification)
+                decrypted_certifications.append(decrypted_certification)
         except errors.GPGMEError as e:
             log.exception("Could not import signatures")
             self.signature_import_error(e)
+        else:
+            self.signature_imported(decrypted_certifications, sender)
 
     @inlineCallbacks
     def on_key_activated(self, widget, key):
@@ -214,11 +225,26 @@ class SendApp:
         self.klw.ib_internet.show()
         log.info("No Internet connection")
 
-    def signature_imported(self):
+    def signature_imported(self, decrypted_certifications, sender=None):
+        """When we have received, decrypted, and imported a certification,
+        this function will show the infobar and offer to return the certification
+        to the sender.
+        We appreciate that the sender, i.e. an email address, is not always known,
+        simply because that information is currently not included in the certification
+        the attestor sends.
+        """
         self.klw.ib_import_okay.show()
-        def return_certification(button):
-            log.info("Return certification")
-        self.klw.button_ib_import_okay.connect('clicked', return_certification)
+        if not sender:
+            # We do not know where to return the certification to, so we hide the button
+            self.klw.button_ib_import_okay.hide()
+        else:
+            def return_certification(button):
+                log.info("Return certification to %s (%d)",
+                    sender, len(decrypted_certifications))
+                
+            self.klw.button_ib_import_okay.connect('clicked', return_certification)
+            self.klw.button_ib_import_okay.show()
+
         log.info("Signature imported")
 
     def signature_import_error(self, e):


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