[Tkabber-dev] r2090 - in trunk/tkabber-plugins: . otr otr/tclotr

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Jan 25 20:27:54 MSK 2014


Author: sergei
Date: 2014-01-25 20:27:54 +0400 (Sat, 25 Jan 2014)
New Revision: 2090

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/otr/otr.tcl
   trunk/tkabber-plugins/otr/tclotr/otr.tcl
Log:
	* otr/otr.tcl, otr/tclotr/otr.tcl: Use the sender's instance tag
	  included into the Diffie-Hellman commit message. Resend the last
	  data message if it was replied by an OTR error message (resend it
	  after a new successful AKE).


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2014-01-25 14:21:31 UTC (rev 2089)
+++ trunk/tkabber-plugins/ChangeLog	2014-01-25 16:27:54 UTC (rev 2090)
@@ -5,6 +5,11 @@
 
 	* otr/*: Added short description to procedures definitions.
 
+	* otr/otr.tcl, otr/tclotr/otr.tcl: Use the sender's instance tag
+	  included into the Diffie-Hellman commit message. Resend the last
+	  data message if it was replied by an OTR error message (resend it
+	  after a new successful AKE).
+
 2014-01-24  Sergei Golovan <sgolovan at nes.ru>
 
 	* otr/key.tcl, otr/otr.tcl: Finish all existing OTR sessions for a

Modified: trunk/tkabber-plugins/otr/otr.tcl
===================================================================
--- trunk/tkabber-plugins/otr/otr.tcl	2014-01-25 14:21:31 UTC (rev 2089)
+++ trunk/tkabber-plugins/otr/otr.tcl	2014-01-25 16:27:54 UTC (rev 2090)
@@ -259,6 +259,8 @@
 proc otr::send {xlib jid message} {
     upvar 2 type type
 
+    debugmsg otr "SEND: $xlib; $jid; $message;"
+
     # Dirty hack to recover message type
     for {set i 1} {$i < 12} {incr i} {
 	if {[catch {upvar $i type type}]} break
@@ -409,7 +411,7 @@
     set lang [get_jid_presence_info lang $xlib $jid]
 
     ::otr::requestConversation $ctx($xlib,$jid) \
-	    [format [::trans::trans $lang \
+	  \n[format [::trans::trans $lang \
 		    "%s has requested an Off-the-Record private conversation\
 		    <http://otr.cypherpunks.ca/>. However, you do not have a\
 		    plugin to support that.\nSee http://otr.cypherpunks.ca/\
@@ -865,7 +867,7 @@
 
     set result [::otr::incomingMessage $ctx($xlib,$from) $body] 
 
-    debugmsg otr "INCOMING MESSAGE: $xlib; $from; $result"
+    debugmsg otr "INCOMING MESSAGE: $xlib; $from; $result;"
 
     array set res $result
 
@@ -939,7 +941,7 @@
     # Only the message body is encrypted if appropriate
     set result [::otr::outgoingMessage $ctx($xlib,$to) $body]
 
-    debugmsg otr "OUTGOING MESSAGE: $xlib; $to; $result"
+    debugmsg otr "OUTGOING MESSAGE: $xlib; $to; $result;"
 
     array set res $result
 

Modified: trunk/tkabber-plugins/otr/tclotr/otr.tcl
===================================================================
--- trunk/tkabber-plugins/otr/tclotr/otr.tcl	2014-01-25 14:21:31 UTC (rev 2089)
+++ trunk/tkabber-plugins/otr/tclotr/otr.tcl	2014-01-25 16:27:54 UTC (rev 2090)
@@ -486,7 +486,8 @@
     switch -- $state(msgstate) {
         MSGSTATE_PLAINTEXT {
             if {[QueryPolicy $token REQUIRE_ENCRYPTION]} {
-                Store $token $message
+                # TODO: Think about resending message after AKE
+                #Store $token $message
                 CallBack $token info "Message is not sent. Trying to start\
                                       private conversation..."
                 CallBack $token send [::otr::data::queryMessage $state(policy)]
@@ -509,7 +510,8 @@
             return [list message $message]
         }
         MSGSTATE_FINISHED {
-            Store $token $message
+            # TODO: Think about resending message after AKE
+            #Store $token $message
             CallBack $token info "Message is not sent. Either end your private\
                                   conversation, or restart it."
             return {}
@@ -548,12 +550,14 @@
 
         Debug $token 2 "OTR binary message"
 
+        # Delete stored message only if type==3
         return [DispatchBinaryMessage $token $data]
     } elseif {![catch {::otr::data::findErrorMessage $message} error]} {
         # OTR error message
 
         Debug $token 2 "OTR error message"
 
+        # Don't delete stored message
         CallBack $token error $error
         if {[QueryPolicy $token ERROR_START_AKE] &&
             ([QueryPolicy $token ALLOW_V2] || [QueryPolicy $token ALLOW_V3])} {
@@ -568,6 +572,7 @@
 
         NewSession $token $version
 
+        Delete $token
         set keyid [expr {$state(keyid)-1}]
         lassign [::otr::auth::createDHCommitMessage \
                         $state(version) \
@@ -586,6 +591,7 @@
 
         Debug $token 2 "Plaintext message"
 
+        Delete $token
         if {![catch {::otr::data::findWhitespaceTag $message} versions]} {
             # Plaintext with the whitespace tag
 
@@ -724,17 +730,23 @@
 
     Debug $token 2 "$version $type [::otr::data::Bin2Hex $binary]"
 
+    if {$type == 2} {
+        # If this is a D-H Commit message, it specifies the protocol version
+        # and the peer's instance tag
+
+        if {$version == 3 && [QueryPolicy $token ALLOW_V3]} {
+            set state(version) 3
+        } elseif {$version == 2 && [QueryPolicy $token ALLOW_V2]} {
+            set state(version) 2
+        } else {
+            return {}
+        }
+
+        set state(rinstance) $sinstance
+    }
+
     if {![info exists state(version)]} {
         switch -- $type {
-            2 {
-                if {$version == 3 && [QueryPolicy $token ALLOW_V3]} {
-                    set state(version) 3
-                } elseif {$version == 2 && [QueryPolicy $token ALLOW_V2]} {
-                    set state(version) 2
-                } else {
-                    return {}
-                }
-            }
             3 {
                 Debug $token 1 "Var state(version) is not set"
                 set error "Encrypted message can't be deciphered"
@@ -778,6 +790,7 @@
         }
         3 {
             # Data message
+            Delete $token
             return [ProcessDataMessage $token $binary]
         }
         10 {
@@ -897,11 +910,14 @@
         UpdatePeerDHKeysAfterAKE $token $gy $keyidy
         StoreSSID $token
 
-        # TODO: Send stored messages
         CallBack $token send $message
+        set state(authstate) $authstate
+        set state(msgstate) $msgstate
+        Resend $token
+    } else {
+        set state(authstate) $authstate
+        set state(msgstate) $msgstate
     }
-    set state(authstate) $authstate
-    set state(msgstate) $msgstate
     return {}
 }
 
@@ -928,10 +944,13 @@
         UpdatePeerDHKeysAfterAKE $token $state(gy) $keyidy
         StoreSSID $token
 
-        # TODO: Send stored messages
+        set state(authstate) $authstate
+        set state(msgstate) $msgstate
+        Resend $token
+    } else {
+        set state(authstate) $authstate
+        set state(msgstate) $msgstate
     }
-    set state(authstate) $authstate
-    set state(msgstate) $msgstate
     return {}
 }
 
@@ -1325,10 +1344,38 @@
     variable $token
     upvar 0 $token state
 
-    # TODO
-    #lappend state(storedmessages) $message
+    # Store only the last message
+    set state(storedmessages) [list $message]
 }
 
+# ::otr::Resend --
+
+proc ::otr::Resend {token} {
+    variable $token
+    upvar 0 $token state
+
+    switch -- $state(msgstate) {
+        MSGSTATE_ENCRYPTED {
+            foreach message $state(storedmessages) {
+                set state(lastmessage) [clock seconds]
+                set message [CreateEncryptedMessage \
+                                    $token {} "\[resent\] $message" {}]
+                CallBack $token send $message
+            }
+        }
+    }
+    set state(storedmessages) {}
+}
+
+# ::otr::Delete --
+
+proc ::otr::Delete {token} {
+    variable $token
+    upvar 0 $token state
+
+    set state(storedmessages) {}
+}
+
 # ::otr::QueryPolicy --
 
 proc ::otr::QueryPolicy {token item} {



More information about the Tkabber-dev mailing list