Permalink
Browse files

fix handling of create_instag and create_privkey events

  • Loading branch information...
1 parent 5deb1bf commit 5ddb1c541376b5ad7474a10114b517dbf7214ac7 @mnaamani committed Dec 20, 2012
Showing with 358 additions and 53 deletions.
  1. +5 −6 doc/API.md
  2. +15 −4 lib/libotr-js-bindings.js
  3. +8 −1 lib/libotr4.js
  4. +5 −7 lib/otr-module.js
  5. +8 −1 src/otr_pre.js
  6. +12 −34 test/index.js
  7. +305 −0 test/testing-events.js
View
@@ -233,11 +233,10 @@ True only if the fingerprint of the buddy has been authenticated/verified by SMP
* inject_message(msg_fragment) - encrypted msg_fragment to be sent to buddy
* gone_secure() - message exchange is now encrypted.
-* gone_insecure() - message exchange is now in plain text.
* still_secure() - encryption re-negotiated. message exchange is encrypted.
-* create_privkey() - a private key for account/protocol specified was not found and needs to be created.
-* create_instag() - an instance tag for account/protocol specified was not found and needs to be created.
+* create_privkey(accountname,protocol) - a private key for account/protocol specified was not found and needs to be created.
+* create_instag(accountname,protocol) - an instance tag for account/protocol specified was not found and needs to be created.
* new_fingerprint(fingerprint) - first time we are seeing remote buddy's fingerprint. This is a que to begin authentication.
* smp_request(question) - buddy has started a SMP authentication. (possibly with a question)
@@ -254,13 +253,13 @@ True only if the fingerprint of the buddy has been authenticated/verified by SMP
buddy has sent additional use information and use-specific data in **use_num** (number) and **usedata_buff** (ArrayBuffer).
**key_buff** is the 32-byte ArrayBuffer holding the synchronised symmetric key.
-## otr.MSGEVENT(event_number)
+## otr.MSGEVENT(event_number)
Returns on of the corresponding event names below of event_number
NONE
ENCRYPTION_REQUIRED
ENCRYPTION_ERROR
- CONNECTION_ENDED //internally 'remote_disconnected' event is fired instead of msg_event
+ CONNECTION_ENDED
SETUP_ERROR
MSG_REFLECTED
MSG_RESENT
@@ -270,7 +269,7 @@ Returns on of the corresponding event names below of event_number
LOG_HEARTBEAT_RCVD
LOG_HEARTBEAT_SENT
RCVDMSG_GENERAL_ERR
- RCVDMSG_UNENCRYPTED //internally 'message' event is fired instead of msg_event
+ RCVDMSG_UNENCRYPTED //'message' event will also be fired with encrypted parameter = false
RCVDMSG_UNRECOGNIZED
RCVDMSG_FOR_OTHER_INSTANCE
View
@@ -438,12 +438,23 @@ function ops_handle_event(O,callback){
function ops_event($opsdata, ev_obj, ev_name){
var $index = getValue($opsdata,"i32");
if(ev_name) ev_obj.EVENT = ev_name;
+ var event_handled = false;
+ var ret_value;
+
+ //handle ops synchronously
+ ['is_logged_in','policy','max_message_size','create_instag','create_privkey','new_fingerprint','write_fingerprints'].forEach(function(E){
+ if(ev_name == E){
+ event_handled = true;
+ ret_value = MAO[$index].instance._event_handler(ev_obj);
+ }
+ });
- if(ev_name=='is_logged_in' || ev_name=='policy' || ev_name=='max_message_size'){
- return MAO[$index].instance._event_handler(ev_obj);
+ if(event_handled){
+ return ret_value;
}else{
- ev_obj._ = MAO[$index].instance;
- OPS_QUEUE.push(ev_obj);
+ //fire events synchronously
+ ev_obj._ = MAO[$index].instance;
+ OPS_QUEUE.push(ev_obj);
}
}
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -202,7 +202,7 @@ if(!events){
}
OTRChannel.prototype.connect = function(){
- return this.send("");
+ return this.send("?OTR?");
};
OTRChannel.prototype.send = function(message,instag){
instag = instag || 1;//default instag = BEST
@@ -297,6 +297,7 @@ function OtrEventHandler( otrChannel ){
emit(o.EVENT);
return;
case "gone_insecure":
+ //never get's called by libotr4.0.0?
emit(o.EVENT);
return;
case "policy":
@@ -313,7 +314,7 @@ function OtrEventHandler( otrChannel ){
emit(o.EVENT,o.message);
return;
case "create_privkey":
- emit(o.EVENT);
+ emit(o.EVENT,o.accountname,o.protocol);
return;
case "new_fingerprint":
debug("NEW FINGERPRINT: "+o.fingerprint);
@@ -328,15 +329,12 @@ function OtrEventHandler( otrChannel ){
case "msg_event":
debug(o.EVENT+"[ "+OTRL_MSGEVENT(o.event)+" ] - "+o.message);
if(OTRL_MSGEVENT(o.event) == "RCVDMSG_UNENCRYPTED"){
- return emit("message",o.message,false);
- }
- if(OTRL_MSGEVENT(o.event) == "CONNECTION_ENDED"){
- return emit("remote_disconnected");
+ emit("message",o.message,false);
}
emit(o.EVENT,o.event,o.message,o.err);
return;
case "create_instag":
- emit(o.EVENT);
+ emit(o.EVENT,o.accountname,o.protocol);
return;
case "received_symkey":
emit(o.EVENT,o.use,o.usedata,o.key);
View
@@ -274,6 +274,10 @@ Module['preRun'].push(function(){
});//preRun
+
+// __msgops_callback_ functions are called from jsapi.c to bubble up to
+// to eventually fire the corresponding event emitted by otr.Session()
+
function __msgops_callback_smp_request($opdata,$context,$question){
var obj = (new Module["ConnContext"]($context))["obj"]();
if($question!=0) obj["question"] = Module["Pointer_stringify"]($question);
@@ -297,7 +301,10 @@ function __msgops_callback_policy($opdata, $context) {
}
function __msgops_callback_create_privkey($opdata,$accountname,$protocol){
- Module["ops_event"]($opdata,{},"create_privkey");
+ Module["ops_event"]($opdata,{
+ "accountname":Module["Pointer_stringify"]($accountname),
+ "protocol":Module["Pointer_stringify"]($protocol)
+ },"create_privkey");
}
function __msgops_callback_is_logged_in($opdata,$accountname,$protocol,$recipient){
View
@@ -10,11 +10,9 @@ console.log("== loaded libotr version:",otr.version());
var debug = function(){};
var USE_VFS = false;
-var TEST_PASSED=false;
var verbose =false;
+
var FORCE_SMP = false;
-var SUCCESSFULL_SMP = false;
-var EXIT_TEST = false;
if(typeof process !== "undefined" ){
process.argv.forEach(function(arg){
@@ -92,9 +90,8 @@ otrchan_b.on("inject_message",function(msg){
otrchan_a.on("message",function(msg,encrypted){
if(encrypted) {
console.log('encrypted: Bob->Alice: ', msg);
- if(msg == "EXIT_TEST") EXIT_TEST = true;
+ this.send(msg);
}else{
- //policy is set to ALWAYS so we should not get any unencrypted messages!
console.log('not-encrypted!!!: Bob->Alice: ',msg);
}
});
@@ -103,11 +100,12 @@ otrchan_a.on("message",function(msg,encrypted){
otrchan_b.on("message",function(msg,encrypted){
if(encrypted) {
console.log('encrypted: Alice->Bob: ', msg);
- if(msg == "EXIT_TEST") EXIT_TEST = true;
}else{
//policy is set to ALWAYS so we should not get any unencrypted messages!
console.log('not-encrypted!!!: Alice->Bob: ',msg);
}
+ if(msg=="EXIT_TEST") exit_test(true);
+
});
@@ -123,17 +121,16 @@ otrchan_a.on("remote_disconnected",function(){
exit_test("");
});
-otrchan_a.on("gone_secure",function(){
+otrchan_a.on("new_fingerprint",function(fingerprint){
+ console.log("new fingerprint:",fingerprint);
+});
+
+otrchan_a.on("gone_secure",function(fingerprint){
if(!this.isAuthenticated() || FORCE_SMP ){
console.log("Alice initiating SMP authentication to verify keys...");
this.start_smp();
+ console.log("settings up symmetric key for file transfer (1): ", this.extraSymKey(1000,"ftp://website.net/files-A.tgz"));
}
- setTimeout(function(self){
- //console.log("sending hello bob3");
- //self.send("Hello Bob! - 3");//too early bob will not realize private context is active..also a bug it seems to disturb SMP!
- },25,this);
- //test the extra symmertric key -- doesn't effect SMP in progress..
- console.log("settings up symmetric key for file transfer (1): ", this.extraSymKey(1000,"ftp://website.net/files-A.tgz"));
});
otrchan_b.on("received_symkey",function(use,usedata,key){
@@ -150,32 +147,13 @@ otrchan_b.on("smp_request",function(){
});
otrchan_a.on("smp_complete",function(){
- console.log("########## smp_complete #########");
- this.send("EXIT_TEST");
- SUCCESSFULL_SMP = true;
+ console.log("SMP COMPLETE");
});
otrchan_a.send("IF POLICY IS ALWAYS THIS WILL NOT BE TRANSMITTED");
//in libotr4 if policy is ALWAYS - initiall message doesn't seem to get resent or is the test
-//failing because of timing/race condition due to handling alice and bob in same thread..?
-
-var loop = setInterval(function(){
- console.log("_");
- if(FORCE_SMP && !SUCCESSFULL_SMP){
- return;
- }
- if(otrchan_a.isEncrypted() && otrchan_a.isAuthenticated() && otrchan_b.isEncrypted() && otrchan_b.isAuthenticated() && EXIT_TEST){
- console.log("Finger print verification successful");
- dumpConnContext(otrchan_a,"Alice's ConnContext:");
- dumpConnContext(otrchan_b,"Bob's ConnContext:");
- TEST_PASSED=true;
- if(loop) clearInterval(loop);
- otrchan_b.close();
- }
-},500);
-function exit_test(msg){
- console.log(msg);
+function exit_test(TEST_PASSED){
if(TEST_PASSED){ console.log("== TEST PASSED ==\n"); } else { console.log("== TEST FAILED ==\n"); }
if(VFS) VFS.save();
process.exit();
Oops, something went wrong.

0 comments on commit 5ddb1c5

Please sign in to comment.