Skip to content

Commit 35fccb9

Browse files
committed
2FA: bug fixes
1 parent f0cf5b4 commit 35fccb9

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Commander/ConnectedCommands.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,11 @@ private async Task GetCommand(string uid)
568568
tab.AddRow("$url:", legacy.Link);
569569
if (!string.IsNullOrEmpty(legacy.Totp))
570570
{
571+
if (totps == null)
572+
{
573+
totps = new List<string>();
574+
}
575+
totps.Add(legacy.Totp);
571576
tab.AddRow("$oneTimeCode:", legacy.Totp);
572577
}
573578
if (legacy.Custom != null && legacy.Custom.Count > 0)
@@ -583,7 +588,7 @@ private async Task GetCommand(string uid)
583588
tab.AddRow("Notes:", typed.Notes);
584589
foreach (var f in typed.Fields.Concat(typed.Custom))
585590
{
586-
if (f.FieldName == "totp")
591+
if (f.FieldName == "oneTimeCode")
587592
{
588593
if (totps == null)
589594
{
@@ -627,10 +632,14 @@ private async Task GetCommand(string uid)
627632
{
628633
foreach (var url in totps)
629634
{
635+
tab.AddRow("$oneTimeCode:", url);
630636
try
631637
{
632638
var tup = CryptoUtils.GetTotpCode(url);
633-
tab.AddRow($"{tup.Item1}:", $"expires in {tup.Item3 - tup.Item2} sec.");
639+
if (tup != null)
640+
{
641+
tab.AddRow($"{tup.Item1}:", $"expires in {tup.Item3 - tup.Item2} sec.");
642+
}
634643
}
635644
catch (Exception e)
636645
{

KeeperSdk/utils/CryptoUtils.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ internal static byte[] Base32ToBytes(string base32)
514514
const string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
515515
var output = new List<byte>();
516516
var bytes = base32.ToCharArray();
517-
for (var bitIndex = 0; bitIndex < base32.Length * 5; bitIndex += 8)
517+
for (var bitIndex = 0; bitIndex / 5 + 1 < bytes.Length; bitIndex += 8)
518518
{
519519
var dualByte = alphabet.IndexOf(bytes[bitIndex / 5]) << 10;
520520
if (bitIndex / 5 + 1 < bytes.Length)
@@ -586,6 +586,9 @@ public static Tuple<string, int, int> GetTotpCode(string url)
586586
case "SHA256":
587587
hmac = new HMACSHA256(secretBytes);
588588
break;
589+
case "SHA512":
590+
hmac = new HMACSHA512(secretBytes);
591+
break;
589592
case "MD5":
590593
hmac = new HMACMD5(secretBytes);
591594
break;

PowerCommander/RecordCommands.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function Show-TwoFactorCode {
201201
End {
202202
$output = @()
203203
foreach ($totp in $totps) {
204-
[Tuple[string, int, int]]$code = [KeeperSecurity.Utils.CryptoUtils]::GetTotpCode($totps.TotpData)
204+
[Tuple[string, int, int]]$code = [KeeperSecurity.Utils.CryptoUtils]::GetTotpCode($totp.TotpData)
205205
if ($code) {
206206
$output += [PSCustomObject]@{
207207
PSTypeName = 'TOTP.Codes'

0 commit comments

Comments
 (0)