From e15089a2b230a252b46a60db59caeb45c8f83d7f Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Thu, 22 Dec 2022 17:57:39 -0800 Subject: [PATCH 1/3] fixed --- .../jdbc/SQLServerVSMEnclaveProvider.java | 8 ++++---- .../ParameterMetaDataCacheTest.java | 14 ++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerVSMEnclaveProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerVSMEnclaveProvider.java index c04687c9c..8a329dcf7 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerVSMEnclaveProvider.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerVSMEnclaveProvider.java @@ -333,12 +333,12 @@ void validateStatementSignature() throws SQLServerException, GeneralSecurityExce * Signature Blob - signatureSize bytes */ ByteBuffer enclaveReportPackageBuffer = ByteBuffer.wrap(enclaveReportPackage).order(ByteOrder.LITTLE_ENDIAN); - // packageSize - // version - // signatureScheme + enclaveReportPackageBuffer.getInt(); // packageSize + enclaveReportPackageBuffer.getInt(); // version + enclaveReportPackageBuffer.getInt(); // signatureScheme int signedStatementSize = enclaveReportPackageBuffer.getInt(); int signatureSize = enclaveReportPackageBuffer.getInt(); - // reserved + enclaveReportPackageBuffer.getInt(); // reserved byte[] signedStatement = new byte[signedStatementSize]; enclaveReportPackageBuffer.get(signedStatement, 0, signedStatementSize); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java index 727be2b67..35e266e30 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java @@ -7,6 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.sql.SQLException; import java.sql.Statement; @@ -90,13 +91,18 @@ public void testParameterMetaDataCache() throws Exception { public void testParameterMetaDataCacheTrim() throws Exception { Field cacheSize = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache") .getDeclaredField("CACHE_SIZE"); + Field modifier = Field.class.getDeclaredField("CACHE_SIZE"); + modifier.setAccessible(true); + modifier.setInt(cacheSize, cacheSize.getModifiers() & ~Modifier.FINAL); + cacheSize.setAccessible(true); + cacheSize.set(cacheSize.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), 0); + Field maximumWeightedCapacity = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache") .getDeclaredField("MAX_WEIGHTED_CAPACITY"); - - cacheSize.setAccessible(true); + modifier = Field.class.getDeclaredField("MAX_WEIGHTED_CAPACITY"); + modifier.setAccessible(true); + modifier.setInt(maximumWeightedCapacity, maximumWeightedCapacity.getModifiers() & ~Modifier.FINAL); maximumWeightedCapacity.setAccessible(true); - - cacheSize.set(cacheSize.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), 0); maximumWeightedCapacity.set( maximumWeightedCapacity.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), 0); From d5b91c57a00c214722a0f86e10557090497597b6 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Thu, 22 Dec 2022 18:29:13 -0800 Subject: [PATCH 2/3] fix --- .../AlwaysEncrypted/ParameterMetaDataCacheTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java index 35e266e30..c0be77649 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java @@ -89,19 +89,18 @@ public void testParameterMetaDataCache() throws Exception { @Tag(Constants.xSQLv14) @Tag(Constants.reqExternalSetup) public void testParameterMetaDataCacheTrim() throws Exception { + Field modifiers = Field.class.getDeclaredField("modifiers"); + modifiers.setAccessible(true); + Field cacheSize = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache") .getDeclaredField("CACHE_SIZE"); - Field modifier = Field.class.getDeclaredField("CACHE_SIZE"); - modifier.setAccessible(true); - modifier.setInt(cacheSize, cacheSize.getModifiers() & ~Modifier.FINAL); + modifiers.setInt(cacheSize, cacheSize.getModifiers() & ~Modifier.FINAL); cacheSize.setAccessible(true); cacheSize.set(cacheSize.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), 0); Field maximumWeightedCapacity = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache") .getDeclaredField("MAX_WEIGHTED_CAPACITY"); - modifier = Field.class.getDeclaredField("MAX_WEIGHTED_CAPACITY"); - modifier.setAccessible(true); - modifier.setInt(maximumWeightedCapacity, maximumWeightedCapacity.getModifiers() & ~Modifier.FINAL); + modifiers.setInt(maximumWeightedCapacity, maximumWeightedCapacity.getModifiers() & ~Modifier.FINAL); maximumWeightedCapacity.setAccessible(true); maximumWeightedCapacity.set( maximumWeightedCapacity.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), 0); From e24c7d512db9e3b66fe0e94417f5c37471e768c2 Mon Sep 17 00:00:00 2001 From: lilgreenbird Date: Thu, 22 Dec 2022 19:40:11 -0800 Subject: [PATCH 3/3] update --- .../ParameterMetaDataCacheTest.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java index c0be77649..5f84e7cbb 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/ParameterMetaDataCacheTest.java @@ -89,21 +89,25 @@ public void testParameterMetaDataCache() throws Exception { @Tag(Constants.xSQLv14) @Tag(Constants.reqExternalSetup) public void testParameterMetaDataCacheTrim() throws Exception { - Field modifiers = Field.class.getDeclaredField("modifiers"); - modifiers.setAccessible(true); - - Field cacheSize = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache") - .getDeclaredField("CACHE_SIZE"); - modifiers.setInt(cacheSize, cacheSize.getModifiers() & ~Modifier.FINAL); - cacheSize.setAccessible(true); - cacheSize.set(cacheSize.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), 0); - - Field maximumWeightedCapacity = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache") - .getDeclaredField("MAX_WEIGHTED_CAPACITY"); - modifiers.setInt(maximumWeightedCapacity, maximumWeightedCapacity.getModifiers() & ~Modifier.FINAL); - maximumWeightedCapacity.setAccessible(true); - maximumWeightedCapacity.set( - maximumWeightedCapacity.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), 0); + // changing static final values does not work after java 17 + try { + Field modifiers = Field.class.getDeclaredField("modifiers"); + modifiers.setAccessible(true); + + Field cacheSize = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache") + .getDeclaredField("CACHE_SIZE"); + modifiers.setInt(cacheSize, cacheSize.getModifiers() & ~Modifier.FINAL); + cacheSize.setAccessible(true); + cacheSize.set(cacheSize.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), 0); + + Field maximumWeightedCapacity = Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache") + .getDeclaredField("MAX_WEIGHTED_CAPACITY"); + modifiers.setInt(maximumWeightedCapacity, maximumWeightedCapacity.getModifiers() & ~Modifier.FINAL); + maximumWeightedCapacity.setAccessible(true); + maximumWeightedCapacity.set( + maximumWeightedCapacity.get(Class.forName("com.microsoft.sqlserver.jdbc.ParameterMetaDataCache")), + 0); + } catch (Exception NoSuchFieldException) {} try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString); Statement stmt = con.createStatement()) {