mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-15 15:53:41 +00:00
store server password encrypted
This commit is contained in:
@@ -67,8 +67,9 @@ namespace Bit.Console
|
||||
case "directory":
|
||||
await DirectoryAsync();
|
||||
break;
|
||||
case "4":
|
||||
case "sync":
|
||||
|
||||
await SyncAsync();
|
||||
break;
|
||||
case "svc":
|
||||
case "service":
|
||||
@@ -213,7 +214,7 @@ namespace Bit.Console
|
||||
|
||||
if(parameters.ContainsKey("path"))
|
||||
{
|
||||
config.Password = parameters["path"];
|
||||
config.Path = parameters["path"];
|
||||
}
|
||||
|
||||
if(parameters.ContainsKey("u"))
|
||||
@@ -223,7 +224,7 @@ namespace Bit.Console
|
||||
|
||||
if(parameters.ContainsKey("p"))
|
||||
{
|
||||
config.Password = parameters["p"];
|
||||
config.Password = new EncryptedData(parameters["p"]);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -241,7 +242,12 @@ namespace Bit.Console
|
||||
Con.Write("Username: ");
|
||||
config.Username = Con.ReadLine().Trim();
|
||||
Con.Write("Password: ");
|
||||
config.Password = ReadSecureLine();
|
||||
var passwordInput = ReadSecureLine();
|
||||
if(!string.IsNullOrWhiteSpace(passwordInput))
|
||||
{
|
||||
config.Password = new EncryptedData(passwordInput);
|
||||
passwordInput = null;
|
||||
}
|
||||
}
|
||||
|
||||
Con.WriteLine();
|
||||
@@ -260,6 +266,23 @@ namespace Bit.Console
|
||||
Con.ResetColor();
|
||||
}
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
private static Task SyncAsync()
|
||||
{
|
||||
if(!Core.Services.AuthService.Instance.Authenticated)
|
||||
{
|
||||
Con.WriteLine("You are not logged in.");
|
||||
}
|
||||
else if(Core.Services.SettingsService.Instance.Server == null)
|
||||
{
|
||||
Con.WriteLine("Server is not configured.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Con.WriteLine("Syncing...");
|
||||
}
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
@@ -17,6 +17,13 @@ namespace Bit.Core.Models
|
||||
Value = ProtectedData.Protect(plainValue, IV, DataProtectionScope.CurrentUser);
|
||||
}
|
||||
|
||||
public EncryptedData(string plainValue)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(plainValue);
|
||||
IV = RandomBytes();
|
||||
Value = ProtectedData.Protect(bytes, IV, DataProtectionScope.CurrentUser);
|
||||
}
|
||||
|
||||
public byte[] Value { get; set; }
|
||||
public byte[] IV { get; set; }
|
||||
|
||||
@@ -25,6 +32,12 @@ namespace Bit.Core.Models
|
||||
return ProtectedData.Unprotect(Value, IV, DataProtectionScope.CurrentUser);
|
||||
}
|
||||
|
||||
public string DecryptToString()
|
||||
{
|
||||
var bytes = ProtectedData.Unprotect(Value, IV, DataProtectionScope.CurrentUser);
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
|
||||
private byte[] RandomBytes()
|
||||
{
|
||||
var entropy = new byte[16];
|
||||
|
||||
@@ -12,6 +12,6 @@ namespace Bit.Core.Models
|
||||
public string Port { get; set; } = "389";
|
||||
public string Path { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Password { get; set; }
|
||||
public EncryptedData Password { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user