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
398142c7
Commit
398142c7
authored
Feb 12, 2014
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a test for the passphrase storage. Updates #111
parent
e3b8a8f9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
71 deletions
+43
-71
converse.js
converse.js
+16
-18
spec/converse.js
spec/converse.js
+27
-53
No files found.
converse.js
View file @
398142c7
...
@@ -262,6 +262,20 @@
...
@@ -262,6 +262,20 @@
}
}
};
};
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
)
{
...
@@ -567,25 +581,11 @@
...
@@ -567,25 +581,11 @@
}
}
},
},
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
);
window
.
sessionStorage
[
key
]
=
pass
;
}
return
pass
;
}
else
{
return
converse
.
connection
.
pass
;
}
},
generatePrivateKey
:
function
(
callback
,
instance_tag
)
{
generatePrivateKey
:
function
(
callback
,
instance_tag
)
{
var
cipher
=
CryptoJS
.
lib
.
PasswordBasedCipher
;
var
cipher
=
CryptoJS
.
lib
.
PasswordBasedCipher
;
var
key
=
new
DSA
();
var
key
=
new
DSA
();
if
(
converse
.
cache_otr_key
)
{
if
(
converse
.
cache_otr_key
)
{
pass
=
this
.
getSessionPassphrase
();
pass
=
converse
.
getSessionPassphrase
();
if
(
typeof
pass
!==
"
undefined
"
)
{
if
(
typeof
pass
!==
"
undefined
"
)
{
// Encrypt the key and set in sessionStorage. Also store instance tag.
// Encrypt the key and set in sessionStorage. Also store instance tag.
window
.
sessionStorage
[
hex_sha1
(
this
.
id
+
'
priv_key
'
)]
=
window
.
sessionStorage
[
hex_sha1
(
this
.
id
+
'
priv_key
'
)]
=
...
@@ -602,12 +602,10 @@
...
@@ -602,12 +602,10 @@
},
},
getSession
:
function
(
callback
)
{
getSession
:
function
(
callback
)
{
// FIXME: sessionStorage is not supported in IE < 8. Perhaps a
// user alert is required here...
var
cipher
=
CryptoJS
.
lib
.
PasswordBasedCipher
;
var
cipher
=
CryptoJS
.
lib
.
PasswordBasedCipher
;
var
result
,
pass
,
instance_tag
,
saved_key
;
var
result
,
pass
,
instance_tag
,
saved_key
;
if
(
converse
.
cache_otr_key
)
{
if
(
converse
.
cache_otr_key
)
{
pass
=
this
.
getSessionPassphrase
();
pass
=
converse
.
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
'
)];
...
...
spec/converse.js
View file @
398142c7
...
@@ -8,60 +8,34 @@
...
@@ -8,60 +8,34 @@
);
);
}
(
this
,
function
(
mock
,
utils
)
{
}
(
this
,
function
(
mock
,
utils
)
{
return
describe
(
"
Converse
"
,
$
.
proxy
(
function
(
mock
,
utils
)
{
return
describe
(
"
Converse
"
,
$
.
proxy
(
function
(
mock
,
utils
)
{
window
.
localStorage
.
clear
();
it
(
"
allows you to subscribe to emitted events
"
,
function
()
{
this
.
callback
=
function
()
{};
spyOn
(
this
,
'
callback
'
);
converse
.
on
(
'
onInitialized
'
,
this
.
callback
);
converse
.
emit
(
'
onInitialized
'
);
expect
(
this
.
callback
).
toHaveBeenCalled
();
converse
.
emit
(
'
onInitialized
'
);
expect
(
this
.
callback
.
callCount
,
2
);
converse
.
emit
(
'
onInitialized
'
);
expect
(
this
.
callback
.
callCount
,
3
);
});
it
(
"
allows you to listen once for an emitted event
"
,
function
()
{
this
.
callback
=
function
()
{};
spyOn
(
this
,
'
callback
'
);
converse
.
once
(
'
onInitialized
'
,
this
.
callback
);
converse
.
emit
(
'
onInitialized
'
);
expect
(
this
.
callback
).
toHaveBeenCalled
();
converse
.
emit
(
'
onInitialized
'
);
expect
(
this
.
callback
.
callCount
,
1
);
converse
.
emit
(
'
onInitialized
'
);
expect
(
this
.
callback
.
callCount
,
1
);
});
it
(
"
allows you to stop listening or subscribing to an event
"
,
function
()
{
this
.
callback
=
function
()
{};
this
.
anotherCallback
=
function
()
{};
this
.
neverCalled
=
function
()
{};
spyOn
(
this
,
'
callback
'
);
spyOn
(
this
,
'
anotherCallback
'
);
spyOn
(
this
,
'
neverCalled
'
);
converse
.
on
(
'
onInitialized
'
,
this
.
callback
);
converse
.
on
(
'
onInitialized
'
,
this
.
anotherCallback
);
converse
.
emit
(
'
onInitialized
'
);
beforeEach
(
$
.
proxy
(
function
()
{
expect
(
this
.
callback
).
toHaveBeenCalled
();
window
.
localStorage
.
clear
();
expect
(
this
.
anotherCallback
).
toHaveBeenCalled
();
window
.
sessionStorage
.
clear
();
},
converse
));
converse
.
off
(
'
onInitialized
'
,
this
.
callback
);
it
(
"
can store a session passphrase in session storage
"
,
$
.
proxy
(
function
()
{
converse
.
emit
(
'
onInitialized
'
);
var
pp
;
expect
(
this
.
callback
.
callCount
,
1
);
// With no prebind, the user's XMPP password is used and nothing is
expect
(
this
.
anotherCallback
.
callCount
,
2
);
// stored in session storage.
this
.
prebind
=
false
;
converse
.
once
(
'
onInitialized
'
,
this
.
neverCalled
);
this
.
connection
.
pass
=
'
s3cr3t!
'
;
converse
.
off
(
'
onInitialized
'
,
this
.
neverCalled
);
expect
(
this
.
getSessionPassphrase
()).
toBe
(
this
.
connection
.
pass
);
expect
(
window
.
sessionStorage
.
length
).
toBe
(
0
);
expect
(
window
.
localStorage
.
length
).
toBe
(
0
);
// With prebind, a random passphrase is generated and stored in
// session storage.
this
.
prebind
=
true
;
pp
=
this
.
getSessionPassphrase
();
expect
(
pp
).
not
.
toBe
(
this
.
connection
.
pass
);
expect
(
window
.
sessionStorage
.
length
).
toBe
(
1
);
expect
(
window
.
localStorage
.
length
).
toBe
(
0
);
expect
(
pp
).
toBe
(
window
.
sessionStorage
[
hex_sha1
(
converse
.
connection
.
jid
)]);
// Clean up
this
.
prebind
=
false
;
},
converse
));
converse
.
emit
(
'
onInitialized
'
);
expect
(
this
.
callback
.
callCount
,
1
);
expect
(
this
.
anotherCallback
.
callCount
,
3
);
expect
(
this
.
neverCalled
).
not
.
toHaveBeenCalled
();
});
},
converse
,
mock
,
utils
));
},
converse
,
mock
,
utils
));
}));
}));
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