From 5a67df60def8d41c03eee22e3e5347fab034ea3c Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 19 Jun 2017 09:46:59 -0400 Subject: [PATCH] new encryption types for rsa with hmac --- src/Core/Enums/EncryptionType.cs | 4 +- src/Core/Utilities/EncryptedValueAttribute.cs | 60 ++++++++++++++----- 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/Core/Enums/EncryptionType.cs b/src/Core/Enums/EncryptionType.cs index e52140d5ed..2b6eaf086c 100644 --- a/src/Core/Enums/EncryptionType.cs +++ b/src/Core/Enums/EncryptionType.cs @@ -6,6 +6,8 @@ AesCbc128_HmacSha256_B64 = 1, AesCbc256_HmacSha256_B64 = 2, Rsa2048_OaepSha256_B64 = 3, - Rsa2048_OaepSha1_B64 = 4 + Rsa2048_OaepSha1_B64 = 4, + Rsa2048_OaepSha256_HmacSha256_B64 = 5, + Rsa2048_OaepSha1_HmacSha256_B64 = 6 } } diff --git a/src/Core/Utilities/EncryptedValueAttribute.cs b/src/Core/Utilities/EncryptedValueAttribute.cs index e58dca4bd6..c9de2e6579 100644 --- a/src/Core/Utilities/EncryptedValueAttribute.cs +++ b/src/Core/Utilities/EncryptedValueAttribute.cs @@ -55,6 +55,8 @@ namespace Bit.Core.Utilities switch(encType) { case Enums.EncryptionType.AesCbc256_B64: + case Enums.EncryptionType.Rsa2048_OaepSha1_HmacSha256_B64: + case Enums.EncryptionType.Rsa2048_OaepSha256_HmacSha256_B64: if(encStringPieces.Length != 2) { return false; @@ -78,26 +80,52 @@ namespace Bit.Core.Utilities return false; } - if(encType != Enums.EncryptionType.Rsa2048_OaepSha1_B64 && - encType != Enums.EncryptionType.Rsa2048_OaepSha256_B64) + switch(encType) { - var iv = Convert.FromBase64String(encStringPieces[0]); - var ct = Convert.FromBase64String(encStringPieces[1]); + case Enums.EncryptionType.AesCbc256_B64: + case Enums.EncryptionType.AesCbc128_HmacSha256_B64: + case Enums.EncryptionType.AesCbc256_HmacSha256_B64: + var iv = Convert.FromBase64String(encStringPieces[0]); + var ct = Convert.FromBase64String(encStringPieces[1]); + if(iv.Length < 1 || ct.Length < 1) + { + return false; + } - if(iv.Length < 1 || ct.Length < 1) - { - return false; - } - } + if(encType == Enums.EncryptionType.AesCbc128_HmacSha256_B64 || + encType == Enums.EncryptionType.AesCbc256_HmacSha256_B64) + { + var mac = Convert.FromBase64String(encStringPieces[2]); + if(mac.Length < 1) + { + return false; + } + } - if(encType == Enums.EncryptionType.AesCbc128_HmacSha256_B64 || - encType == Enums.EncryptionType.AesCbc256_HmacSha256_B64) - { - var mac = Convert.FromBase64String(encStringPieces[2]); - if(mac.Length < 1) - { + break; + case Enums.EncryptionType.Rsa2048_OaepSha256_B64: + case Enums.EncryptionType.Rsa2048_OaepSha1_B64: + case Enums.EncryptionType.Rsa2048_OaepSha1_HmacSha256_B64: + case Enums.EncryptionType.Rsa2048_OaepSha256_HmacSha256_B64: + var rsaCt = Convert.FromBase64String(encStringPieces[0]); + if(rsaCt.Length < 1) + { + return false; + } + + if(encType == Enums.EncryptionType.Rsa2048_OaepSha1_HmacSha256_B64 || + encType == Enums.EncryptionType.Rsa2048_OaepSha256_HmacSha256_B64) + { + var mac = Convert.FromBase64String(encStringPieces[1]); + if(mac.Length < 1) + { + return false; + } + } + + break; + default: return false; - } } } catch