Fix AddFingerprintCommand
This commit is contained in:
@@ -41,21 +41,28 @@ namespace Akari.Prototype.Server.Cli.Commands
|
||||
throw new CommandException("Name can't be more than 50 characters");
|
||||
}
|
||||
|
||||
var data = Encoding.UTF8.GetBytes(Name);
|
||||
|
||||
if (data.Length > TcpProviderService.MaxNameLength)
|
||||
if (Encoding.UTF8.GetBytes(Name).Length > TcpProviderService.MaxNameLength)
|
||||
{
|
||||
throw new CommandException("Name can't be more than 200 bytes (UTF-8)");
|
||||
}
|
||||
|
||||
var hash = Security.NewArgon2idHash(data);
|
||||
|
||||
if (!_fingerprintManager.Add(Name, hash))
|
||||
if (_fingerprintManager.Contains(Name))
|
||||
{
|
||||
throw new CommandException("A fingerprint with this name is already registered.");
|
||||
}
|
||||
|
||||
console.AsAnsiConsole().Markup($"[green]Successfully added {Name}:\n{hash}[/]");
|
||||
var token = new byte[TcpProviderService.MaxTokenLength];
|
||||
|
||||
RandomNumberGenerator.Fill(token);
|
||||
|
||||
var hash = Security.NewArgon2idHash(token);
|
||||
|
||||
_fingerprintManager.Add(Name, hash);
|
||||
|
||||
console.AsAnsiConsole().MarkupLine($"[green]Successfully added {Name}\n[/]");
|
||||
console.AsAnsiConsole().MarkupLine($"[yellow]Token: {Convert.ToBase64String(token)}[/]");
|
||||
console.AsAnsiConsole().MarkupLine($"[grey]Hash: {hash}\n[/]");
|
||||
console.AsAnsiConsole().MarkupLine($"[silver]Note that you won't be able to retrieve the [yellow]token[/] later, it's [red]never stored[/][/]");
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user