Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Merge pull request #113 from tavrez/master
Browse files Browse the repository at this point in the history
Support for Steam tokens
  • Loading branch information
Sneezry authored May 9, 2017
2 parents 90cb00e + 2cf8d66 commit 970dd85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion javascript/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ function copyCode() {
document.getElementById('passphrase').style.opacity = 1;
}, 200);
return;
} else if (!/^\d+$/.test(code)) {
} else if (!/^[0-9A-Z]+$/.test(code)) {
return;
}
chrome.permissions.request({
Expand Down
25 changes: 25 additions & 0 deletions totp/totp.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,26 @@ var KeyUtilities = function() {
return str;
};

var base26 = function(num) {
chars = '23456789BCDFGHJKMNPQRTVWXY';
output = '';
len = 5;
for(i=0;i<len;i++)
{
output += chars[num % chars.length];
num = Math.floor(num / chars.length);
}
if(output.length < len)
{
output = new Array(len - output.length + 1).join(chars[0]) + output;
}
return output;
};

var generate = function(secret, counter) {
secret = secret.replace(/\s/g, '');
var len = 6;
var b26 = false;
if(/^[a-z2-7]+=*$/.test(secret.toLowerCase())) {
var key = base32tohex(secret);
}
Expand All @@ -56,6 +73,11 @@ var KeyUtilities = function() {
var key = base32tohex(secret.substr(4));
len = 8;
}
else if(/^stm\-/.test(secret.toLowerCase())) {
var key = base32tohex(secret.substr(4));
len = 10;
b26 = true;
}
if(isNaN(counter)){
var epoch = Math.round(new Date().getTime() / 1000.0);
if(localStorage.offset){
Expand All @@ -76,6 +98,9 @@ var KeyUtilities = function() {
}

var otp = (hex2dec(hmac.substr(offset * 2, 8)) & hex2dec('7fffffff')) + '';
if(b26) {
return base26(otp);
}
if(otp.length < len){
otp = new Array(len - otp.length + 1).join('0') + otp;
}
Expand Down

0 comments on commit 970dd85

Please sign in to comment.