From 458de2d2e0022578c335bbbccdd52ecf11112697 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 20 Apr 2017 10:29:18 -0400 Subject: [PATCH] set private key on login --- src/App/Abstractions/Services/ICryptoService.cs | 2 +- src/App/Models/CipherString.cs | 2 +- src/App/Services/AuthService.cs | 5 +++++ src/App/Services/CryptoService.cs | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/App/Abstractions/Services/ICryptoService.cs b/src/App/Abstractions/Services/ICryptoService.cs index 7b5203323..e0bc27996 100644 --- a/src/App/Abstractions/Services/ICryptoService.cs +++ b/src/App/Abstractions/Services/ICryptoService.cs @@ -9,7 +9,7 @@ namespace Bit.App.Abstractions CryptoKey Key { get; set; } CryptoKey PreviousKey { get; } bool KeyChanged { get; } - byte[] PrivateKey { get; set; } + byte[] PrivateKey { get; } IDictionary OrgKeys { get; set; } void SetPrivateKey(CipherString privateKeyEnc, CryptoKey key); diff --git a/src/App/Models/CipherString.cs b/src/App/Models/CipherString.cs index 6b5c1600b..ae093b2a0 100644 --- a/src/App/Models/CipherString.cs +++ b/src/App/Models/CipherString.cs @@ -11,7 +11,7 @@ namespace Bit.App.Models public CipherString(string encryptedString) { - if(string.IsNullOrWhiteSpace(encryptedString) || !encryptedString.Contains("|")) + if(string.IsNullOrWhiteSpace(encryptedString)) { throw new ArgumentException(nameof(encryptedString)); } diff --git a/src/App/Services/AuthService.cs b/src/App/Services/AuthService.cs index 5a299c1ea..d99b46cf6 100644 --- a/src/App/Services/AuthService.cs +++ b/src/App/Services/AuthService.cs @@ -263,6 +263,11 @@ namespace Bit.App.Services private void ProcessLoginSuccess(CryptoKey key, TokenResponse response) { + if(response.PrivateKey != null) + { + _cryptoService.SetPrivateKey(new CipherString(response.PrivateKey), key); + } + _cryptoService.Key = key; _tokenService.Token = response.AccessToken; _tokenService.RefreshToken = response.RefreshToken; diff --git a/src/App/Services/CryptoService.cs b/src/App/Services/CryptoService.cs index f88747cd7..d8d32b2ac 100644 --- a/src/App/Services/CryptoService.cs +++ b/src/App/Services/CryptoService.cs @@ -112,7 +112,7 @@ namespace Bit.App.Services return _privateKey; } - set + private set { if(value != null) {