From 466721f5f2ee3fb1761a54ffcbf01da9357868f8 Mon Sep 17 00:00:00 2001 From: Javad Date: Fri, 24 Mar 2023 16:26:51 -0700 Subject: [PATCH] Fix | Addressing failure on providing correct error message when symmetric key decryption fails using Always Encrypted. (#1948) --- .../netcore/src/Microsoft/Data/SqlClient/TdsParser.cs | 7 +++++++ .../netfx/src/Microsoft/Data/SqlClient/TdsParser.cs | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs index 36ecb2cd72..f63f8557a6 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -6024,6 +6024,13 @@ internal bool TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, int length, T } catch (Exception e) { + if (stateObj is not null) + { + // call to decrypt column keys has failed. The data wont be decrypted. + // Not setting the value to false, forces the driver to look for column value. + // Packet received from Key Vault will throws invalid token header. + stateObj.HasPendingData = false; + } throw SQL.ColumnDecryptionFailed(columnName, null, e); } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs index 78f5336839..09f586ab8b 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -6828,6 +6828,13 @@ internal bool TryReadSqlValue(SqlBuffer value, } catch (Exception e) { + if (stateObj is not null) + { + // call to decrypt column keys has failed. The data wont be decrypted. + // Not setting the value to false, forces the driver to look for column value. + // Packet received from Key Vault will throws invalid token header. + stateObj._pendingData = false; + } throw SQL.ColumnDecryptionFailed(columnName, null, e); } }