1
0
Fork 0
mirror of https://github.com/seiichiro0185/sailotp.git synced 2024-11-25 00:29:42 +00:00

Add suport for generating steam authenticator tokens

This commit is contained in:
Robin Appelman 2015-12-04 15:52:19 +01:00
parent 168463cacb
commit 53e0f1f32b
2 changed files with 27 additions and 4 deletions

View file

@ -63,6 +63,11 @@ function leftpad(str, len, pad) {
return str;
}
// characters steam uses to generate the final code
var steamChars = ['2', '3', '4', '5', '6', '7', '8', '9', 'B', 'C',
'D', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q',
'R', 'T', 'V', 'W', 'X', 'Y']
// *** Main Function *** //
// Calculate an OTP-Value from the given secret
@ -75,7 +80,7 @@ function calcOTP(secret, type, counter) {
var key = base32tohex(secret);
var factor = "";
if (type == "TOTP") {
if (type.substr(0, 4) == "TOTP") {
// Get current Time in UNIX Timestamp format (Seconds since 01.01.1970 00:00 UTC)
var epoch = Math.round(new Date().getTime() / 1000.0);
// Get last full 30 / 60 Seconds and convert to HEX
@ -92,8 +97,19 @@ function calcOTP(secret, type, counter) {
// Finally convert the HMAC-Value to the corresponding 6-digit token
var offset = hex2dec(hmac.substring(hmac.length - 1));
var otp = (hex2dec(hmac.substr(offset * 2, 8)) & hex2dec('7fffffff')) + '';
var code = hex2dec(hmac.substr(offset * 2, 8)) & hex2dec('7fffffff');
var otp = '';
// Steam has it's own way of creating the code from the result
if (type == "TOTP_STEAM") {
for (var i = 0; i < 5; i++) {
otp += steamChars[code % steamChars.length];
code = Math.floor(code/steamChars.length);
}
} else {
otp = code + '';
otp = (otp).substr(otp.length - 6, 6);
}
} catch (e) {
otp = "Invalid Secret!"
}

View file

@ -69,13 +69,20 @@ Page {
// get seconds from current Date
var curDate = new Date();
var seconds = curDate.getSeconds();
var type;
// Iterate over all List entries
for (var i=0; i<appWin.listModel.count; i++) {
if (appWin.listModel.get(i).type == "TOTP") {
// Only update on full 30 / 60 Seconds or if last run of the Functions is more than 2s in the past (e.g. app was in background)
if (appWin.listModel.get(i).otp == "------" || seconds == 30 || seconds == 0 || (curDate.getTime() - lastUpdated > 2000)) {
var curOTP = OTP.calcOTP(appWin.listModel.get(i).secret, "TOTP")
if (appWin.listModel.get(i).title.substr(0,6) == "Steam:") {
type = "TOTP_STEAM"
} else {
type = "TOTP"
}
var curOTP = OTP.calcOTP(appWin.listModel.get(i).secret, type)
appWin.listModel.setProperty(i, "otp", curOTP);
}
} else if (appWin.coverType == "HOTP" && (curDate.getTime() - lastUpdated > 2000) && appWin.listModel.get(i).fav == 1) {