Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
62d59ff3
Commit
62d59ff3
authored
Feb 12, 2014
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor some OTR code into a Backbone model and adapt tests.
parent
398142c7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
43 deletions
+55
-43
converse.js
converse.js
+43
-38
spec/otr.js
spec/otr.js
+3
-4
tests_main.js
tests_main.js
+9
-1
No files found.
converse.js
View file @
62d59ff3
...
@@ -262,20 +262,6 @@
...
@@ -262,20 +262,6 @@
}
}
};
};
this
.
getSessionPassphrase
=
function
()
{
if
(
this
.
prebind
)
{
var
key
=
hex_sha1
(
this
.
connection
.
jid
),
pass
=
window
.
sessionStorage
[
key
];
if
(
typeof
pass
===
'
undefined
'
)
{
pass
=
Math
.
floor
(
Math
.
random
()
*
4294967295
).
toString
();
window
.
sessionStorage
[
key
]
=
pass
;
}
return
pass
;
}
else
{
return
this
.
connection
.
pass
;
}
};
this
.
getVCard
=
function
(
jid
,
callback
,
errback
)
{
this
.
getVCard
=
function
(
jid
,
callback
,
errback
)
{
if
(
!
this
.
use_vcards
)
{
if
(
!
this
.
use_vcards
)
{
if
(
callback
)
{
if
(
callback
)
{
...
@@ -561,6 +547,44 @@
...
@@ -561,6 +547,44 @@
// Backbone Models and Views
// Backbone Models and Views
// -------------------------
// -------------------------
this
.
OTR
=
Backbone
.
Model
.
extend
({
// A model for managing OTR settings.
getSessionPassphrase
:
function
()
{
if
(
converse
.
prebind
)
{
var
key
=
hex_sha1
(
converse
.
connection
.
jid
),
pass
=
window
.
sessionStorage
[
key
];
if
(
typeof
pass
===
'
undefined
'
)
{
pass
=
Math
.
floor
(
Math
.
random
()
*
4294967295
).
toString
();
window
.
sessionStorage
[
key
]
=
pass
;
}
return
pass
;
}
else
{
return
converse
.
connection
.
pass
;
}
},
generatePrivateKey
:
function
(
callback
,
instance_tag
)
{
var
key
=
new
DSA
();
var
jid
=
converse
.
connection
.
jid
;
if
(
converse
.
cache_otr_key
)
{
var
cipher
=
CryptoJS
.
lib
.
PasswordBasedCipher
;
var
pass
=
this
.
getSessionPassphrase
();
if
(
typeof
pass
!==
"
undefined
"
)
{
// Encrypt the key and set in sessionStorage. Also store instance tag.
window
.
sessionStorage
[
hex_sha1
(
jid
+
'
priv_key
'
)]
=
cipher
.
encrypt
(
CryptoJS
.
algo
.
AES
,
key
.
packPrivate
(),
pass
).
toString
();
window
.
sessionStorage
[
hex_sha1
(
jid
+
'
instance_tag
'
)]
=
instance_tag
;
window
.
sessionStorage
[
hex_sha1
(
jid
+
'
pass_check
'
)]
=
cipher
.
encrypt
(
CryptoJS
.
algo
.
AES
,
'
match
'
,
pass
).
toString
();
}
}
callback
({
'
key
'
:
key
,
'
instance_tag
'
:
instance_tag
});
}
});
this
.
Message
=
Backbone
.
Model
.
extend
();
this
.
Message
=
Backbone
.
Model
.
extend
();
this
.
Messages
=
Backbone
.
Collection
.
extend
({
this
.
Messages
=
Backbone
.
Collection
.
extend
({
...
@@ -581,35 +605,15 @@
...
@@ -581,35 +605,15 @@
}
}
},
},
generatePrivateKey
:
function
(
callback
,
instance_tag
)
{
var
cipher
=
CryptoJS
.
lib
.
PasswordBasedCipher
;
var
key
=
new
DSA
();
if
(
converse
.
cache_otr_key
)
{
pass
=
converse
.
getSessionPassphrase
();
if
(
typeof
pass
!==
"
undefined
"
)
{
// Encrypt the key and set in sessionStorage. Also store instance tag.
window
.
sessionStorage
[
hex_sha1
(
this
.
id
+
'
priv_key
'
)]
=
cipher
.
encrypt
(
CryptoJS
.
algo
.
AES
,
key
.
packPrivate
(),
pass
).
toString
();
window
.
sessionStorage
[
hex_sha1
(
this
.
id
+
'
instance_tag
'
)]
=
instance_tag
;
this
.
save
({
'
pass_check
'
:
cipher
.
encrypt
(
CryptoJS
.
algo
.
AES
,
'
match
'
,
pass
).
toString
()});
}
}
this
.
trigger
(
'
showHelpMessages
'
,
[
__
(
'
Private key generated.
'
)],
null
,
false
);
callback
({
'
key
'
:
key
,
'
instance_tag
'
:
instance_tag
});
},
getSession
:
function
(
callback
)
{
getSession
:
function
(
callback
)
{
var
cipher
=
CryptoJS
.
lib
.
PasswordBasedCipher
;
var
cipher
=
CryptoJS
.
lib
.
PasswordBasedCipher
;
var
result
,
pass
,
instance_tag
,
saved_key
;
var
result
,
pass
,
instance_tag
,
saved_key
,
pass_check
;
if
(
converse
.
cache_otr_key
)
{
if
(
converse
.
cache_otr_key
)
{
pass
=
converse
.
getSessionPassphrase
();
pass
=
converse
.
otr
.
getSessionPassphrase
();
if
(
typeof
pass
!==
"
undefined
"
)
{
if
(
typeof
pass
!==
"
undefined
"
)
{
instance_tag
=
window
.
sessionStorage
[
hex_sha1
(
this
.
id
+
'
instance_tag
'
)];
instance_tag
=
window
.
sessionStorage
[
hex_sha1
(
this
.
id
+
'
instance_tag
'
)];
saved_key
=
window
.
sessionStorage
[
hex_sha1
(
this
.
id
+
'
priv_key
'
)];
saved_key
=
window
.
sessionStorage
[
hex_sha1
(
this
.
id
+
'
priv_key
'
)];
var
pass_check
=
this
.
get
(
'
pass_check
'
)
;
pass_check
=
window
.
sessionStorage
[
hex_sha1
(
this
.
connection
.
jid
+
'
pass_check
'
)]
;
if
(
saved_key
&&
instance_tag
&&
typeof
pass_check
!==
'
undefined
'
)
{
if
(
saved_key
&&
instance_tag
&&
typeof
pass_check
!==
'
undefined
'
)
{
var
decrypted
=
cipher
.
decrypt
(
CryptoJS
.
algo
.
AES
,
saved_key
,
pass
);
var
decrypted
=
cipher
.
decrypt
(
CryptoJS
.
algo
.
AES
,
saved_key
,
pass
);
var
key
=
DSA
.
parsePrivate
(
decrypted
.
toString
(
CryptoJS
.
enc
.
Latin1
));
var
key
=
DSA
.
parsePrivate
(
decrypted
.
toString
(
CryptoJS
.
enc
.
Latin1
));
...
@@ -633,7 +637,7 @@
...
@@ -633,7 +637,7 @@
null
,
null
,
true
// show spinner
true
// show spinner
);
);
setTimeout
(
$
.
proxy
(
this
.
generatePrivateKey
,
this
),
500
,
callback
,
instance_tag
);
setTimeout
(
$
.
proxy
(
converse
.
otr
.
generatePrivateKey
,
this
),
500
,
callback
,
instance_tag
);
},
},
updateOTRStatus
:
function
(
state
)
{
updateOTRStatus
:
function
(
state
)
{
...
@@ -3561,6 +3565,7 @@
...
@@ -3561,6 +3565,7 @@
this
.
chatboxes
=
new
this
.
ChatBoxes
();
this
.
chatboxes
=
new
this
.
ChatBoxes
();
this
.
chatboxesview
=
new
this
.
ChatBoxesView
({
model
:
this
.
chatboxes
});
this
.
chatboxesview
=
new
this
.
ChatBoxesView
({
model
:
this
.
chatboxes
});
this
.
controlboxtoggle
=
new
this
.
ControlBoxToggle
();
this
.
controlboxtoggle
=
new
this
.
ControlBoxToggle
();
this
.
otr
=
new
this
.
OTR
();
if
((
this
.
prebind
)
&&
(
!
this
.
connection
))
{
if
((
this
.
prebind
)
&&
(
!
this
.
connection
))
{
if
((
!
this
.
jid
)
||
(
!
this
.
sid
)
||
(
!
this
.
rid
)
||
(
!
this
.
bosh_service_url
))
{
if
((
!
this
.
jid
)
||
(
!
this
.
sid
)
||
(
!
this
.
rid
)
||
(
!
this
.
bosh_service_url
))
{
...
...
spec/
converse
.js
→
spec/
otr
.js
View file @
62d59ff3
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
}
}
);
);
}
(
this
,
function
(
mock
,
utils
)
{
}
(
this
,
function
(
mock
,
utils
)
{
return
describe
(
"
Convers
e
"
,
$
.
proxy
(
function
(
mock
,
utils
)
{
return
describe
(
"
The OTR modul
e
"
,
$
.
proxy
(
function
(
mock
,
utils
)
{
beforeEach
(
$
.
proxy
(
function
()
{
beforeEach
(
$
.
proxy
(
function
()
{
window
.
localStorage
.
clear
();
window
.
localStorage
.
clear
();
...
@@ -20,14 +20,14 @@
...
@@ -20,14 +20,14 @@
// stored in session storage.
// stored in session storage.
this
.
prebind
=
false
;
this
.
prebind
=
false
;
this
.
connection
.
pass
=
'
s3cr3t!
'
;
this
.
connection
.
pass
=
'
s3cr3t!
'
;
expect
(
this
.
getSessionPassphrase
()).
toBe
(
this
.
connection
.
pass
);
expect
(
this
.
otr
.
getSessionPassphrase
()).
toBe
(
this
.
connection
.
pass
);
expect
(
window
.
sessionStorage
.
length
).
toBe
(
0
);
expect
(
window
.
sessionStorage
.
length
).
toBe
(
0
);
expect
(
window
.
localStorage
.
length
).
toBe
(
0
);
expect
(
window
.
localStorage
.
length
).
toBe
(
0
);
// With prebind, a random passphrase is generated and stored in
// With prebind, a random passphrase is generated and stored in
// session storage.
// session storage.
this
.
prebind
=
true
;
this
.
prebind
=
true
;
pp
=
this
.
getSessionPassphrase
();
pp
=
this
.
otr
.
getSessionPassphrase
();
expect
(
pp
).
not
.
toBe
(
this
.
connection
.
pass
);
expect
(
pp
).
not
.
toBe
(
this
.
connection
.
pass
);
expect
(
window
.
sessionStorage
.
length
).
toBe
(
1
);
expect
(
window
.
sessionStorage
.
length
).
toBe
(
1
);
expect
(
window
.
localStorage
.
length
).
toBe
(
0
);
expect
(
window
.
localStorage
.
length
).
toBe
(
0
);
...
@@ -36,6 +36,5 @@
...
@@ -36,6 +36,5 @@
// Clean up
// Clean up
this
.
prebind
=
false
;
this
.
prebind
=
false
;
},
converse
));
},
converse
));
},
converse
,
mock
,
utils
));
},
converse
,
mock
,
utils
));
}));
}));
tests_main.js
View file @
62d59ff3
...
@@ -111,10 +111,18 @@ require([
...
@@ -111,10 +111,18 @@ require([
testing
:
true
testing
:
true
},
function
(
converse
)
{
},
function
(
converse
)
{
window
.
converse
=
converse
;
window
.
converse
=
converse
;
window
.
crypto
=
{
getRandomValues
:
function
(
buf
)
{
var
i
;
for
(
i
=
0
,
len
=
buf
.
length
;
i
<
len
;
i
++
)
{
buf
[
i
]
=
Math
.
floor
(
Math
.
random
()
*
256
);
}
}
};
require
([
require
([
"
jasmine-console-reporter
"
,
"
jasmine-console-reporter
"
,
"
jasmine-junit-reporter
"
,
"
jasmine-junit-reporter
"
,
"
spec/
converse
"
,
"
spec/
otr
"
,
"
spec/eventemitter
"
,
"
spec/eventemitter
"
,
"
spec/controlbox
"
,
"
spec/controlbox
"
,
"
spec/chatbox
"
,
"
spec/chatbox
"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment