Skip to content

Commit

Permalink
message event now indicates if messge was encrypted or not, no need t…
Browse files Browse the repository at this point in the history
…o check for session.isEncrypted()
  • Loading branch information
mnaamani committed Dec 18, 2012
1 parent 997945b commit 5deb1bf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
6 changes: 3 additions & 3 deletions doc/API.md
Expand Up @@ -228,7 +228,7 @@ True only if the fingerprint of the buddy has been authenticated/verified by SMP

### Handling Session events

* message(msg) - received decrypted 'msg' message.
* message(msg, encrypted) - received message **msg**. If message was encrypted **encrypted** will be true.

* inject_message(msg_fragment) - encrypted msg_fragment to be sent to buddy

Expand All @@ -251,8 +251,8 @@ True only if the fingerprint of the buddy has been authenticated/verified by SMP

* msg_event(event_no, message, err) - event_no, message if appropriate and a GcryptError() err
* received_symkey(use_num, usedata_buff, key_buff) - buddy wants to use the current extra symmetric key.
buddy has sent additional use information and use-specific data in **use** (number) and **usedata_buff** (ArrayBuffer).
**key_buff(( is the 32byte ArrayBuffer holding the synchronised symmetric key.
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)
Returns on of the corresponding event names below of event_number
Expand Down
4 changes: 2 additions & 2 deletions lib/otr-module.js
Expand Up @@ -216,7 +216,7 @@ OTRChannel.prototype.send = function(message,instag){
OTRChannel.prototype.recv = function(message){
//message can be any object that can be serialsed to a string using it's .toString() method.
var msg = this.ops.messageReceiving(this.user.state, this.context.accountname(), this.context.protocol(), this.context.username(), message.toString(), this);
if(msg) this.emit("message",msg);
if(msg) this.emit("message",msg,this.isEncrypted());
};
OTRChannel.prototype.close = function(){
this.ops.disconnect(this.user.state,this.context.accountname(),this.context.protocol(),this.context.username(),this.context.their_instance());
Expand Down Expand Up @@ -328,7 +328,7 @@ 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);
return emit("message",o.message,false);
}
if(OTRL_MSGEVENT(o.event) == "CONNECTION_ENDED"){
return emit("remote_disconnected");
Expand Down
41 changes: 24 additions & 17 deletions test/index.js
Expand Up @@ -14,6 +14,7 @@ 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){
Expand Down Expand Up @@ -88,19 +89,21 @@ otrchan_b.on("inject_message",function(msg){
});

//output incoming messages to console
otrchan_a.on("message",function(msg){
if(this.isEncrypted()) {
otrchan_a.on("message",function(msg,encrypted){
if(encrypted) {
console.log('encrypted: Bob->Alice: ', 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!!!: Bob->Alice: ',msg);
}
});

//output incoming messages to console
otrchan_b.on("message",function(msg){
if(this.isEncrypted()) {
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);
Expand All @@ -121,34 +124,38 @@ otrchan_a.on("remote_disconnected",function(){
});

otrchan_a.on("gone_secure",function(){

if(!this.isAuthenticated() || FORCE_SMP ){
if(!this.isAuthenticated() || FORCE_SMP ){
console.log("Alice initiating SMP authentication to verify keys...");
otrchan_a.start_smp();
}

//test the extra symmertric key
console.log("settings up symmetric key for file transfer (1): ", this.extraSymKey(1000,"ftp://website.net/files-A.tgz"));
this.start_smp();
}
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){
console.log("Alice wants to do something with extra symkey");
console.log(" use:", use);
console.log("usedata:", ab2str(usedata));
console.log(" key:", key);
this.send("EXIT_TEST");
});

otrchan_b.on("smp_request",function(){
console.log("Bob responding to SMP request.");
otrchan_b.respond_smp('s3cr37');
this.respond_smp('s3cr37');
});

otrchan_a.on("smp_complete",function(){
otrchan_a.send("Hello Bob! - 2");
SUCCESSFULL_SMP = true;
console.log("########## smp_complete #########");
this.send("EXIT_TEST");
SUCCESSFULL_SMP = true;
});
//otrchan_a.connect();
otrchan_a.send("Hello Bob! - 1");

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..?

Expand All @@ -157,7 +164,7 @@ var loop = setInterval(function(){
if(FORCE_SMP && !SUCCESSFULL_SMP){
return;
}
if(otrchan_a.isEncrypted() && otrchan_a.isAuthenticated() && otrchan_b.isEncrypted() && otrchan_b.isAuthenticated()){
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:");
Expand Down

0 comments on commit 5deb1bf

Please sign in to comment.