[Tkabber-dev] [tclgpg] r72 committed - * tclgpg.tcl: Fixed decrypting and signing if gpg-agent is used for...

tclgpg at googlecode.com tclgpg at googlecode.com
Sun Nov 15 12:51:30 MSK 2009


Revision: 72
Author: sgolovan
Date: Sun Nov 15 01:50:54 2009
Log: 	* tclgpg.tcl: Fixed decrypting and signing if gpg-agent is used for
	  passphrase handling (closes: #2). Clarified error message in case
	  when passphrase callback isn't specified.

	* tclgpg.test: Added test for decrypting without passphrase callback.

http://code.google.com/p/tclgpg/source/detail?r=72

Modified:
  /trunk/ChangeLog
  /trunk/tclgpg.tcl
  /trunk/tclgpg.test

=======================================
--- /trunk/ChangeLog	Fri Oct  9 14:24:30 2009
+++ /trunk/ChangeLog	Sun Nov 15 01:50:54 2009
@@ -1,3 +1,11 @@
+2009-11-15  Sergei Golovan  <sgolovan at nes.ru>
+
+	* tclgpg.tcl: Fixed decrypting and signing if gpg-agent is used for
+	  passphrase handling (closes: #2). Clarified error message in case
+	  when passphrase callback isn't specified.
+
+	* tclgpg.test: Added test for decrypting without passphrase callback.
+
  2009-10-10  Sergei Golovan  <sgolovan at nes.ru>

  	* tclgpg.tcl, tclgpg.test: Don't issue broken pipe error in case when
=======================================
--- /trunk/tclgpg.tcl	Fri Oct  9 14:24:30 2009
+++ /trunk/tclgpg.tcl	Sun Nov 15 01:50:54 2009
@@ -1405,64 +1405,44 @@
              }
              NEED_PASSPHRASE {
                  set state(badpassphrase) 0
-                if {![package vsatisfies $Version 2.0]} {
-                    if {![info exists state(hint)]} {
-                        set state(hint) enter
-                    } else {
-                        set state(hint) try_again
-                    }
-                    if {[catch {Set $token -property passphrase-callback}  
pcb]} {
-                        FinishWithError $channels $commands "No passphrase"
-                        return
-                    }
-                    set arglist [list token $token \
-                                      hint $state(hint) \
-                                      userid $state(userid_hint) \
-                                      keyid [lindex $fields 2] \
-                                      subkeyid [lindex $fields 3]]
-                    Debug 2 $arglist
-                    if {[catch {eval $pcb [list $arglist]} passphrase]} {
-                        FinishWithError $channels $commands "No passphrase"
-                        return
-                    } else {
-                        # Passphrase encoding may differ from message  
encoding,
-                        # so we have to save command-fd encoding in case  
when
-                        # command-fd and stdin are the same channel.
-
-                        set encoding [fconfigure $command_fd -encoding]
-                        fconfigure $command_fd \
-                            -encoding [Set $token -property  
passphrase-encoding]
-                        puts $command_fd $passphrase
-                        flush $command_fd
-                        fconfigure $command_fd -encoding $encoding
-                    }
-                }
+                if {![info exists state(hint)]} {
+                    set state(hint) enter
+                } else {
+                    set state(hint) try_again
+                }
+                set state(arglist) [list token $token \
+                                         hint $state(hint) \
+                                         userid $state(userid_hint) \
+                                         keyid [lindex $fields 2] \
+                                         subkeyid [lindex $fields 3]]
+                Debug 2 $state(arglist)
              }
              NEED_PASSPHRASE_SYM {
                  set state(badpassphrase) 0
-                if {![package vsatisfies $Version 2.0]} {
-                    if {[catch {Set $token -property passphrase-callback}  
pcb]} {
-                        FinishWithError $channels $commands "No passphrase"
-                        return
-                    }
-                    if {[catch {
-                            eval $pcb [list [list token $token \
-                                                  hint enter]]
-                         } passphrase]} {
-                        FinishWithError $channels $commands "No passphrase"
-                        return
-                    } else {
-                        # Passphrase encoding may differ from message  
encoding,
-                        # so we have to save command-fd encoding in case  
when
-                        # command-fd and stdin are the same channel.
-
-                        set encoding [fconfigure $command_fd -encoding]
-                        fconfigure $command_fd \
-                            -encoding [Set $token -property  
passphrase-encoding]
-                        puts $command_fd $passphrase
-                        flush $command_fd
-                        fconfigure $command_fd -encoding $encoding
-                    }
+                set state(hint) enter
+                set state(arglist) [list token $token \
+                                         hint $state(hint)]
+                Debug 2 $state(arglist)
+            }
+            GET_HIDDEN {
+                if {[catch {Set $token -property passphrase-callback}  
pcb]} {
+                    FinishWithError $channels $commands "No passphrase  
callback"
+                    return
+                }
+                if {[catch {eval $pcb [list $state(arglist)]} passphrase]}  
{
+                    FinishWithError $channels $commands "No passphrase"
+                    return
+                } else {
+                    # Passphrase encoding may differ from message encoding,
+                    # so we have to save command-fd encoding in case when
+                    # command-fd and stdin are the same channel.
+
+                    set encoding [fconfigure $command_fd -encoding]
+                    fconfigure $command_fd \
+                        -encoding [Set $token -property  
passphrase-encoding]
+                    puts $command_fd $passphrase
+                    flush $command_fd
+                    fconfigure $command_fd -encoding $encoding
                  }
              }
              BAD_PASSPHRASE {
=======================================
--- /trunk/tclgpg.test	Fri Oct  9 14:24:30 2009
+++ /trunk/tclgpg.test	Sun Nov 15 01:50:54 2009
@@ -300,6 +300,19 @@
      $c free
      unset msg
  } -returnCodes error -result {No passphrase}
+
+test encrypt-decrypt-1.5 {Symmetric cipher & missing passphrase callback}  
-body {
+    set c [::gpg::new]
+    $c set -property armor -value true
+    $c set -property passphrase-callback -value pcb1
+    $c set -property encoding -value utf-8
+    set msg [$c encrypt -input $message]
+    $c unset -property passphrase-callback
+    $c decrypt -input $msg
+} -cleanup {
+    $c free
+    unset msg
+} -returnCodes error -result {No passphrase callback}

  test sign-verify-1.1 {Ordinary sign (armored)} -body {
      set c [::gpg::new]


More information about the Tkabber-dev mailing list