Always Encrypted | Align reads of CekMdVersion and EkValueCount with TDS specification#4240
Open
edwardneal wants to merge 3 commits intodotnet:mainfrom
Open
Always Encrypted | Align reads of CekMdVersion and EkValueCount with TDS specification#4240edwardneal wants to merge 3 commits intodotnet:mainfrom
edwardneal wants to merge 3 commits intodotnet:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
SqlClient contains a the structure of a table of
CIPHER_INFOentries. The table is represented as aSqlTceCipherInfoTableand each entry is represented as aSqlTceCipherInfoEntryinstance. This corresponds to anEK_INFOstructure in the TDS specification. A table ofEK_INFOentries appears in theCOLMETADATAstructure.In the TDS specification, the
EK_INFOstructure'sCekMdVersionfield is defined as aULONGLONGand theCOLMETADATAstructure'sEkValueCountfield is defined as aUSHORT.This PR aligns SqlClient with these type definitions. The
cekMdVersionfield onSqlTceCipherInfoTableis currently defined as an eight byte array, and is redefined as aulong. This eliminates one allocation, so it technically improves performance (marginally.) ThetableSizeis currently defined a short, and is redefined as aushort. This is a correctness improvement and a bugfix in an edge case where the same column is encrypted with an unreasonably large number of encryption keys.One slight edge case lies in SqlCommand.Encryption.cs, where we read the CekMdVersion from a byte array as a little-endian ulong. This byte array is the result of reading the
column_encryption_key_metadata_versioncolumn from the first result set ofsp_describe_parameter_encryption, and this column is declared asbinary(8). I've usedBinaryPrimitives.ReadUInt64LittleEndianto bridge this gap between the stored procedure's result set and the TDS specification.Issues
None.
Testing
Automated Always Encrypted tests continue to pass.