Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public ColumnMasterKeyMetadata(RSA rsa, string masterKeyPath, string providerNam
/// </returns>
/// <exception cref="CryptographicException">Thrown when the signing operation fails.</exception>
public byte[] Sign() =>
// CodeQL [SM03799] Required for an external standard: Always Encrypted signs column master key metadata with RSA PKCS#1 v1.5 (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-master-key-transact-sql?view=sql-server-ver16)
_rsa.SignHash(_hash, s_hashAlgorithm, RSASignaturePadding.Pkcs1);

/// <summary>
Expand All @@ -146,8 +147,9 @@ public byte[] Sign() =>
/// <returns>
/// <see langword="true"/> if the signature is valid and matches the computed hash; otherwise, <see langword="false"/>.
/// </returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="signature"/> is <see langword="null"/>.</exception>"
/// <exception cref="ArgumentNullException">Thrown when <paramref name="signature"/> is <see langword="null"/>.</exception>
public bool Verify(byte[] signature) =>
// CodeQL [SM03799] Required for an external standard: Always Encrypted signs column master key metadata with RSA PKCS#1 v1.5 (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-master-key-transact-sql?view=sql-server-ver16)
_rsa.VerifyHash(_hash, signature, s_hashAlgorithm, RSASignaturePadding.Pkcs1);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ public byte[] Encrypt(byte[] columnEncryptionKey)
Debug.Assert(bytesWritten == HashSize, @"Hash size does not match the expected size.");

bytesWritten = _keyType == SqlColumnEncryptionCertificateStoreProvider.MasterKeyType
// CodeQL [SM03799] Required for an external standard: Always Encrypted signs encrypted column encryption keys with RSA PKCS#1 v1.5 (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-encryption-key-transact-sql?view=sql-server-ver16)
? _rsa.SignHash(hash, encryptedColumnEncryptionKey.AsSpan(signatureOffset), s_hashAlgorithm, RSASignaturePadding.Pkcs1)
// CodeQL [SM03799] Required for an external standard: Always Encrypted signs encrypted column encryption keys with RSA PKCS#1 v1.5 (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-encryption-key-transact-sql?view=sql-server-ver16)
: _rsa.SignData(hash, encryptedColumnEncryptionKey.AsSpan(signatureOffset), s_hashAlgorithm, RSASignaturePadding.Pkcs1);
Debug.Assert(bytesWritten == _rsaKeySize, @"Signature length does not match the RSA key size.");

Expand All @@ -166,7 +168,9 @@ public byte[] Encrypt(byte[] columnEncryptionKey)
Debug.Assert(bytesWritten == HashSize, @"Hash size does not match the expected size.");

byte[] signedHash = _keyType == SqlColumnEncryptionCertificateStoreProvider.MasterKeyType
// CodeQL [SM03799] Required for an external standard: Always Encrypted signs encrypted column encryption keys with RSA PKCS#1 v1.5 (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-encryption-key-transact-sql?view=sql-server-ver16)
? _rsa.SignHash(hash, s_hashAlgorithm, RSASignaturePadding.Pkcs1)
// CodeQL [SM03799] Required for an external standard: Always Encrypted signs encrypted column encryption keys with RSA PKCS#1 v1.5 (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-encryption-key-transact-sql?view=sql-server-ver16)
: _rsa.SignData(hash, s_hashAlgorithm, RSASignaturePadding.Pkcs1);
bytesWritten = signedHash.Length;
Debug.Assert(bytesWritten == _rsaKeySize, @"Signature length does not match the RSA key size.");
Expand Down Expand Up @@ -246,7 +250,9 @@ public byte[] Decrypt(byte[] encryptedCek)
#endif

bool dataVerified = _keyType == SqlColumnEncryptionCertificateStoreProvider.MasterKeyType
// CodeQL [SM03799] Required for an external standard: Always Encrypted signs encrypted column encryption keys with RSA PKCS#1 v1.5 (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-encryption-key-transact-sql?view=sql-server-ver16)
? _rsa.VerifyHash(hash, signature, s_hashAlgorithm, RSASignaturePadding.Pkcs1)
// CodeQL [SM03799] Required for an external standard: Always Encrypted signs encrypted column encryption keys with RSA PKCS#1 v1.5 (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-encryption-key-transact-sql?view=sql-server-ver16)
: _rsa.VerifyData(hash, signature, s_hashAlgorithm, RSASignaturePadding.Pkcs1);

// Validate the signature
Expand Down
Loading