diff --git a/src/Console/Program.cs b/src/Console/Program.cs index 7f6d9d4e..1ca9a5c0 100644 --- a/src/Console/Program.cs +++ b/src/Console/Program.cs @@ -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); } diff --git a/src/Core/Models/EncryptedData.cs b/src/Core/Models/EncryptedData.cs index 3935b562..92e67a2e 100644 --- a/src/Core/Models/EncryptedData.cs +++ b/src/Core/Models/EncryptedData.cs @@ -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]; diff --git a/src/Core/Models/ServerConfiguration.cs b/src/Core/Models/ServerConfiguration.cs index a5667d43..77ede252 100644 --- a/src/Core/Models/ServerConfiguration.cs +++ b/src/Core/Models/ServerConfiguration.cs @@ -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; } } }