1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

Add support for Steam TOTP (#20)

This commit is contained in:
h44z 2018-11-26 14:12:39 +01:00 committed by Kyle Spearrin
parent 1536f161f7
commit 46ad445951

View File

@ -48,6 +48,8 @@ export class TotpService implements TotpServiceAbstraction {
alg = algParam; alg = algParam;
} }
} }
} else if(key.toLowerCase().indexOf('steam://') === 0) {
keyB32 = key.substr('steam://'.length);
} }
const epoch = Math.round(new Date().getTime() / 1000.0); const epoch = Math.round(new Date().getTime() / 1000.0);
@ -71,6 +73,20 @@ export class TotpService implements TotpServiceAbstraction {
/* tslint:enable */ /* tslint:enable */
let otp = (binary % Math.pow(10, digits)).toString(); let otp = (binary % Math.pow(10, digits)).toString();
otp = this.leftpad(otp, digits, '0'); otp = this.leftpad(otp, digits, '0');
if(key.toLowerCase().indexOf('steam://') === 0) {
const 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'];
otp = "";
let fullcode = binary & 0x7fffffff;
for (var i = 0; i < 5; i++) {
otp += steamchars[fullcode % steamchars.length];
fullcode = Math.trunc(fullcode / steamchars.length);
}
}
return otp; return otp;
} }