Skip to content

Commit 9a5477c

Browse files
authored
Addressed and suppressed CodeQL warnings with explanatory comments in the JDBC codebase. (#2677)
Description CodeQL static analysis raised warnings for certain cryptographic algorithms and usages in the JDBC driver codebase. These warnings were triggered in files supporting NTLM authentication, Always Encrypted, legacy private key handling, and secure in-memory string encryption. However, these usages are intentional and required for compatibility with SQL Server features, industry standards, and appropriate security contexts. Resolution details: This PR adds CodeQL suppression comments to the affected lines of code. These suppressions are justified and documented to ensure clarity and maintain compliance with external standards or backward compatibility. No functional code changes were made. The updates are as follows: NTLMAuthentication.java (lines 605, 825) Suppression added for use of HmacMD5 algorithm, which is required for NTLM support. // CodeQL [SM05136] HmacMD5 is required for NTLM support KeyStoreProviderCommon.java (line 129) Suppression added for use of RSA_OAEP with SHA1, which is mandated by SQL Server for Always Encrypted. // CodeQL [SM03796] Required for an external standard: Always Encrypted only supports encrypting column encryption keys with RSA_OAEP(SHA1) (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-encryption-key-transact-sql?view=sql-server-ver16) SQLServerCertificateUtils.java (lines 425, 485) Suppressions added to maintain backward compatibility with older private key formats. // CodeQL [SM05136] Required for backwards compatibility reading of old private keys SQLServerColumnEncryptionJavaKeyStoreProvider.java (line 371) Suppression added for RSA_OAEP(SHA1) usage required by Always Encrypted. // CodeQL [SM03796] Required for an external standard: Always Encrypted only supports encrypting column encryption keys with RSA_OAEP(SHA1) (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-encryption-key-transact-sql?view=sql-server-ver16) SecureStringUtil.java (lines 88, 89) Suppressions added for the use of AES/GCM/NoPadding, which is a modern and secure cipher. // This cipher is used appropriately in a short-lived, in-memory scenario, with each nonce only used once for encryption. Testing No functional changes were made; therefore, no new tests were added. Existing test coverage remains valid, and this change is limited to documentation-only suppressions to pass CodeQL analysis while preserving required functionality.
1 parent 72eb3f1 commit 9a5477c

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

src/main/java/com/microsoft/sqlserver/jdbc/KeyStoreProviderCommon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private static byte[] decryptRSAOAEP(byte[] cipherText,
126126
CertificateDetails certificateDetails) throws SQLServerException {
127127
byte[] plainCEK = null;
128128
try {
129-
Cipher rsa = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
129+
Cipher rsa = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding"); // CodeQL [SM03796] Required for an external standard: Always Encrypted only supports encrypting column encryption keys with RSA_OAEP(SHA1) (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-encryption-key-transact-sql?view=sql-server-ver16)
130130
rsa.init(Cipher.DECRYPT_MODE, certificateDetails.privateKey);
131131
rsa.update(cipherText);
132132
plainCEK = rsa.doFinal();

src/main/java/com/microsoft/sqlserver/jdbc/NTLMAuthentication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ private byte[] generateClientChallengeBlob(final byte[] clientNonce) {
602602
* if key is invalid
603603
*/
604604
private byte[] hmacMD5(final byte[] key, final byte[] data) throws InvalidKeyException {
605-
SecretKeySpec keySpec = new SecretKeySpec(key, "HmacMD5");
605+
SecretKeySpec keySpec = new SecretKeySpec(key, "HmacMD5"); // CodeQL [SM05136] HmacMD5 is required for NTLM support
606606
context.mac.init(keySpec);
607607
return context.mac.doFinal(data);
608608
}
@@ -822,7 +822,7 @@ private byte[] generateNtlmAuthenticate() throws SQLServerException {
822822
* MIC is calculated by using a 0 MIC then hmacMD5 of session key and concat of the 3 msgs
823823
*/
824824
if (null != context.timestamp && 0 < context.timestamp.length) {
825-
SecretKeySpec keySpec = new SecretKeySpec(context.sessionBaseKey, "HmacMD5");
825+
SecretKeySpec keySpec = new SecretKeySpec(context.sessionBaseKey, "HmacMD5"); // CodeQL [SM05136] HmacMD5 is required for NTLM support
826826
context.mac.init(keySpec);
827827
context.mac.update(context.negotiateMsg);
828828
context.mac.update(context.challengeMsg);

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCertificateUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ private static PrivateKey loadPrivateKeyFromPVK(String keyPath,
422422
buffer.get(key);
423423

424424
if (encrypted) {
425-
MessageDigest digest = MessageDigest.getInstance("SHA1");
425+
MessageDigest digest = MessageDigest.getInstance("SHA1"); // CodeQL [SM05136] Required for backwards compatibility reading of old private keys
426426
digest.update(salt);
427427
if (null != keyPass) {
428428
digest.update(keyPass.getBytes());
@@ -482,7 +482,7 @@ private static boolean startsWithMagic(byte[] b) {
482482

483483
private static byte[] getSecretKeyFromHash(byte[] originalKey,
484484
byte[] keyHash) throws GeneralSecurityException, SQLServerException {
485-
SecretKey key = new SecretKeySpec(keyHash, 0, 16, RC4_ALG);
485+
SecretKey key = new SecretKeySpec(keyHash, 0, 16, RC4_ALG); // CodeQL [SM05136] Required for backwards compatibility reading of old private keys
486486
byte[] decrypted = decryptSecretKey(key, originalKey);
487487
if (startsWithMagic(decrypted)) {
488488
return decrypted;

src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionJavaKeyStoreProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ public byte[] encryptColumnEncryptionKey(String masterKeyPath, String encryption
368368
private byte[] encryptRSAOAEP(byte[] plainText, CertificateDetails certificateDetails) throws SQLServerException {
369369
byte[] cipherText = null;
370370
try {
371-
Cipher rsa = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
371+
Cipher rsa = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding"); // CodeQL [SM03796] Required for an external standard: Always Encrypted only supports encrypting column encryption keys with RSA_OAEP(SHA1) (https://learn.microsoft.com/en-us/sql/t-sql/statements/create-column-encryption-key-transact-sql?view=sql-server-ver16)
372372
rsa.init(Cipher.ENCRYPT_MODE, certificateDetails.certificate.getPublicKey());
373373
rsa.update(plainText);
374374
cipherText = rsa.doFinal();

src/main/java/com/microsoft/sqlserver/jdbc/SecureStringUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ private SecureStringUtil() throws SQLServerException {
8585
secretKey = new SecretKeySpec(keygen.generateKey().getEncoded(), "AES");
8686

8787
// get ciphers for encryption/decryption
88-
encryptCipher = Cipher.getInstance(CIPHER_TRANSFORMATION);
89-
decryptCipher = Cipher.getInstance(CIPHER_TRANSFORMATION);
88+
encryptCipher = Cipher.getInstance(CIPHER_TRANSFORMATION); // This cipher is used appropriately in a short-lived, in-memory scenario, with each nonce only used once for encryption.
89+
decryptCipher = Cipher.getInstance(CIPHER_TRANSFORMATION); // This cipher is used appropriately in a short-lived, in-memory scenario, with each nonce only used once for encryption.
9090
} catch (Exception e) {
9191
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_SecureStringInitFailed"));
9292
Object[] msgArgs = {e.getMessage()};

0 commit comments

Comments
 (0)