Skip to content

Commit

Permalink
support salted passwords during wamp cra
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenjs committed Apr 11, 2018
1 parent a75ad5c commit ef0280c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
2 changes: 2 additions & 0 deletions javascript/test_client/js/crypto-js/pbkdf2.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 29 additions & 8 deletions javascript/test_client/test_client.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,15 @@

</head>

<body>
<body>
<script src="js/crypto-js/hmac-sha256.js"></script>
<script src="js/crypto-js/enc-base64-min.js"></script>
<script src="js/crypto-js/pbkdf2.min.js"></script>

<script type="text/javascript">

var wsUri = "ws://127.0.0.1:55555/";
var output;
var websocket;


var wamp_session;

wamp_session_reset = function()
Expand Down Expand Up @@ -242,9 +240,33 @@
return;
}

console.log("challenge is :" + challenge);
var key;
if ("salt" in wampChallenge[2]) {

var salt = wampChallenge[2]['salt'];
var iterations = wampChallenge[2]['iterations'];
var keylen = wampChallenge[2]['keylen'];

// compute the derived key from the naked password and the salt
console.log("creating the derived key from salt");

var key=CryptoJS.PBKDF2(
secret,
salt,
{ keySize: 256 / keylen,
hasher: CryptoJS.algo.SHA256,
iterations: iterations }
);

var hash = CryptoJS.HmacSHA256(challenge, secret);
var key_base64 =CryptoJS.enc.Base64.stringify(key);
key = key_base64;
}
else {
// no salting
key = secret;
}

var hash = CryptoJS.HmacSHA256(challenge, key);
var strhash = CryptoJS.enc.Base64.stringify(hash);

wampAuthenticate = [5, strhash, {}];
Expand Down Expand Up @@ -309,7 +331,7 @@

var newdiv = document.createElement("DIV");
newdiv.className = "alert alert-info";

var spanItem = document.createElement("SPAN");
spanItem.className = "sent";
senttext = datetimestamp();
Expand Down Expand Up @@ -516,4 +538,3 @@
</body>

</html>

0 comments on commit ef0280c

Please sign in to comment.