From 060c6573e5d5d71ab6b597936353f43751cc1f3e Mon Sep 17 00:00:00 2001 From: ulvii Date: Wed, 16 Oct 2019 11:36:48 -0700 Subject: [PATCH] Revert "Release | Merge dev to master for v8.1.0-preview (#1161)" (#1163) This reverts commit e88884c23c330541232f541661f9676323bee6ef. --- .../{incident-report.md => bug_report.md} | 8 +- .github/ISSUE_TEMPLATE/question.md | 2 +- CHANGELOG.md | 22 - README.md | 22 +- azure-pipelines.yml | 29 +- build.gradle | 20 +- pom.xml | 19 +- .../java/com/microsoft/sqlserver/jdbc/AE.java | 14 +- .../sqlserver/jdbc/AuthenticationJNI.java | 3 - .../microsoft/sqlserver/jdbc/IOBuffer.java | 28 +- .../sqlserver/jdbc/ISQLServerBulkData.java | 79 -- .../sqlserver/jdbc/ISQLServerBulkRecord.java | 90 +- .../jdbc/ISQLServerCallableStatement.java | 130 +-- .../sqlserver/jdbc/ISQLServerConnection.java | 52 +- .../jdbc/ISQLServerConnection43.java | 4 +- .../sqlserver/jdbc/ISQLServerDataRecord.java | 8 +- .../sqlserver/jdbc/ISQLServerDataSource.java | 53 +- .../jdbc/ISQLServerEnclaveProvider.java | 98 -- .../jdbc/ISQLServerPreparedStatement.java | 89 +- .../sqlserver/jdbc/ISQLServerResultSet.java | 207 +++-- .../jdbc/ISQLServerResultSetMetaData.java | 2 +- .../sqlserver/jdbc/ISQLServerSavepoint.java | 6 +- .../sqlserver/jdbc/ISQLServerStatement.java | 8 +- .../jdbc/KeyStoreProviderCommon.java | 2 +- .../sqlserver/jdbc/SQLJdbcVersion.java | 6 +- .../sqlserver/jdbc/SQLServerBulkCopy.java | 69 +- .../jdbc/SQLServerCallableStatement.java | 68 +- ...ColumnEncryptionAzureKeyVaultProvider.java | 65 +- ...umnEncryptionCertificateStoreProvider.java | 11 - ...rColumnEncryptionJavaKeyStoreProvider.java | 47 +- ...erverColumnEncryptionKeyStoreProvider.java | 15 - .../sqlserver/jdbc/SQLServerConnection.java | 147 +-- .../sqlserver/jdbc/SQLServerDataColumn.java | 31 - .../sqlserver/jdbc/SQLServerDataSource.java | 40 +- .../sqlserver/jdbc/SQLServerDataTable.java | 76 -- .../jdbc/SQLServerDatabaseMetaData.java | 18 +- .../sqlserver/jdbc/SQLServerDriver.java | 47 - ...LServerKeyVaultAuthenticationCallback.java | 2 +- .../jdbc/SQLServerParameterMetaData.java | 4 +- .../jdbc/SQLServerPreparedStatement.java | 56 +- .../sqlserver/jdbc/SQLServerResource.java | 24 +- .../sqlserver/jdbc/SQLServerResultSet.java | 34 +- .../jdbc/SQLServerSecurityUtility.java | 26 - .../jdbc/SQLServerSpatialDatatype.java | 58 +- .../sqlserver/jdbc/SQLServerStatement.java | 23 +- .../jdbc/SQLServerSymmetricKeyCache.java | 32 +- .../jdbc/SQLServerVSMEnclaveProvider.java | 589 ------------ .../sqlserver/jdbc/SQLServerXAConnection.java | 16 - .../jdbc/AlwaysEncrypted/AESetup.java | 758 +++++++++------ .../CallableStatementTest.java | 275 ++++-- .../JDBCEncryptionDecryptionTest.java | 873 +++++------------- .../AlwaysEncrypted/PrecisionScaleTest.java | 158 ++-- .../RegressionAlwaysEncryptedTest.java | 97 +- .../sqlserver/jdbc/ComparisonUtil.java | 47 +- .../sqlserver/jdbc/TestResource.java | 5 +- .../microsoft/sqlserver/jdbc/TestUtils.java | 64 -- .../jdbc/bulkCopy/BulkCopyCSVTest.java | 2 +- .../jdbc/bulkCopy/BulkCopyTestUtil.java | 6 +- .../jdbc/connection/XADataSourceTest.java | 44 - .../DatabaseMetaDataForeignKeyTest.java | 79 +- .../DatabaseMetaDataTest.java | 54 +- .../SQLServerSpatialDatatypeTest.java | 5 +- .../jdbc/tvp/SQLServerDataTableTest.java | 103 --- .../sqlserver/testframework/AbstractTest.java | 6 +- .../sqlserver/testframework/Constants.java | 19 +- 65 files changed, 1741 insertions(+), 3353 deletions(-) rename .github/ISSUE_TEMPLATE/{incident-report.md => bug_report.md} (91%) delete mode 100644 src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkData.java delete mode 100644 src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerEnclaveProvider.java delete mode 100644 src/main/java/com/microsoft/sqlserver/jdbc/SQLServerVSMEnclaveProvider.java delete mode 100644 src/test/java/com/microsoft/sqlserver/jdbc/connection/XADataSourceTest.java delete mode 100644 src/test/java/com/microsoft/sqlserver/jdbc/tvp/SQLServerDataTableTest.java diff --git a/.github/ISSUE_TEMPLATE/incident-report.md b/.github/ISSUE_TEMPLATE/bug_report.md similarity index 91% rename from .github/ISSUE_TEMPLATE/incident-report.md rename to .github/ISSUE_TEMPLATE/bug_report.md index 2eb2e3a78..a43efd7d3 100644 --- a/.github/ISSUE_TEMPLATE/incident-report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,8 +1,8 @@ --- -name: Incident report -about: Report an incident -title: '' -labels: '' +name: Bug report +about: Report a bug to help us improve +title: "[BUG]" +labels: bug assignees: '' --- diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md index 9681d198d..1131f35db 100644 --- a/.github/ISSUE_TEMPLATE/question.md +++ b/.github/ISSUE_TEMPLATE/question.md @@ -1,6 +1,6 @@ --- name: Question -about: Ask a question +about: Discuss an idea to see if it would be an appropriate Issue. title: "[QUESTION]" labels: question assignees: '' diff --git a/CHANGELOG.md b/CHANGELOG.md index c319b9d72..1ed74ab66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,28 +3,6 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) -## [8.1.0] Preview Release -### Added -- Added ISQLServerBulkData to remove implementation details from ISQLServerBulkRecord [#1099](https://github.com/microsoft/mssql-jdbc/pull/1099) -- Added support for Azure national clouds when using Azure Key Vault [#1130](https://github.com/microsoft/mssql-jdbc/pull/1130) -- Implemented hashCode() and equals() APIs for SQLServerDataTable and SQLServerDataColumn [#1146](https://github.com/Microsoft/mssql-jdbc/pull/1146) -- Added support for JAVA 13 [#1151](https://github.com/Microsoft/mssql-jdbc/pull/1151) -- Added support for Always Encrypted with Secure Enclaves [#1155](https://github.com/Microsoft/mssql-jdbc/pull/1155) - -### Fixed Issues -- Fixed Geography.STAsBinary() returning null for a single point [#1074](https://github.com/microsoft/mssql-jdbc/pull/1074) -- Fixed DatabaseMetaData.getImportedKeys() returning duplicate rows [#1092](https://github.com/microsoft/mssql-jdbc/pull/1092) -- Fixed issue with truststore password being removed too early for XA connections [#1133](https://github.com/microsoft/mssql-jdbc/pull/1133) -- Fixed issue with SQLServerDatabaseMetada.getColumns() not escaping wildcard characters [#1138](https://github.com/microsoft/mssql-jdbc/pull/1138) -- Removed extra spaces in SQLServerDatabaseMetaData.getNumericFunctions() and SQLServerDatabaseMetaData.getStringFunctions() return values [#1117](https://github.com/microsoft/mssql-jdbc/pull/1117) - -### Changed -- Improved performance of column name lookups [#1066](https://github.com/microsoft/mssql-jdbc/pull/1066) -- Test improvements [#1100](https://github.com/microsoft/mssql-jdbc/pull/1100) -- Updated issue templates [#1148](https://github.com/microsoft/mssql-jdbc/pull/1148) -- Improved performance of CallableStatement and ParameterMetaData when using procedure names that contain wildcard characters [#1149](https://github.com/microsoft/mssql-jdbc/pull/1149) -- Updated CI to use SQL Server 2012 instead of 2008R2 [#1153](https://github.com/microsoft/mssql-jdbc/pull/1153) - ## [7.4.1] HotFix & Stable Release ### Fixed Issues - Reverted [#1025](https://github.com/Microsoft/mssql-jdbc/pull/1025) as it contains breaking changes. This removes `hashCode()` and `equals()` APIs from `SQLServerDataTable` and `SQLServerDataColumn`. diff --git a/README.md b/README.md index 71408da85..02dabfedd 100644 --- a/README.md +++ b/README.md @@ -48,16 +48,16 @@ To build the jar files, you must use minimum version of Java 11 with Maven. You * Maven: 1. If you have not already done so, add the environment variable `mssql_jdbc_test_connection_properties` in your system with the connection properties for your SQL Server or SQL DB instance. 2. Run one of the commands below to build a JRE 11 and newer versions compatible jar or JRE 8 compatible jar in the `\target` directory. - * Run `mvn install -Pjre13`. This creates JRE 13 compatible jar in `\target` directory which is JDBC 4.3 compliant (Build with JDK 13+). - * Run `mvn install -Pjre11`. This creates JRE 11 compatible jar in `\target` directory which is JDBC 4.3 compliant (Build with JDK 11+). - * Run `mvn install -Pjre8`. This creates JRE 8 compatible jar in `\target` directory which is JDBC 4.2 compliant (Build with JDK 11+). + * Run `mvn install -Pjre12`. This creates JRE 12 compatible jar in `\target` directory which is JDBC 4.3 compliant (Build with JDK 12+). + * Run `mvn install -Pjre11`. This creates JRE 11 compatible jar in `\target` directory which is JDBC 4.3 compliant (Build with JDK 11+). + * Run `mvn install -Pjre8`. This creates JRE 8 compatible jar in `\target` directory which is JDBC 4.2 compliant (Build with JDK 11+). * Gradle: 1. If you have not already done so, add the environment variable `mssql_jdbc_test_connection_properties` in your system with the connection properties for your SQL Server or SQL DB instance. 2. Run one of the commands below to build a JRE 11 and newer versions compatible jar or JRE 8 compatible jar in the `\build\libs` directory. - * Run `gradle build -PbuildProfile=jre13`. This creates JRE 13 compatible jar in `\build\libs` directory which is JDBC 4.3 compliant (Build with JDK 13+). - * Run `gradle build -PbuildProfile=jre11`. This creates JRE 11 compatible jar in `\build\libs` directory which is JDBC 4.3 compliant (Build with JDK 11+). - * Run `gradle build -PbuildProfile=jre8`. This creates JRE 8 compatible jar in `\build\libs` directory which is JDBC 4.2 compliant (Build with JDK 11+). + * Run `gradle build -PbuildProfile=jre12`. This creates JRE 12 compatible jar in `\build\libs` directory which is JDBC 4.3 compliant (Build with JDK 12+). + * Run `gradle build -PbuildProfile=jre11`. This creates JRE 11 compatible jar in `\build\libs` directory which is JDBC 4.3 compliant (Build with JDK 11+). + * Run `gradle build -PbuildProfile=jre8`. This creates JRE 8 compatible jar in `\build\libs` directory which is JDBC 4.2 compliant (Build with JDK 11+). ## Resources @@ -92,7 +92,7 @@ To get the latest preview version of the driver, add the following to your POM f com.microsoft.sqlserver mssql-jdbc - 8.1.0.jre13-preview + 7.3.1.jre12-preview ``` @@ -127,7 +127,7 @@ Projects that require either of the two features need to explicitly declare the com.microsoft.sqlserver mssql-jdbc - 8.1.0.jre13-preview + 7.4.1.jre12 compile @@ -150,7 +150,7 @@ Projects that require either of the two features need to explicitly declare the com.microsoft.sqlserver mssql-jdbc - 8.1.0.jre13-preview + 7.4.1.jre12 compile @@ -183,7 +183,7 @@ When setting 'useFmtOnly' property to 'true' for establishing a connection or cr com.microsoft.sqlserver mssql-jdbc - 8.1.0.jre13-preview + 7.4.1.jre12 @@ -223,7 +223,7 @@ Preview releases happen approximately monthly between stable releases. This give You can see what is going into a future release by monitoring [Milestones](https://github.com/Microsoft/mssql-jdbc/milestones) in the repository. ### Version conventions -Starting with 6.0, stable versions have an even minor version. For example, 6.0, 6.2, 6.4, 7.0, 7.2, 7.4. Preview versions have an odd minor version. For example, 6.1, 6.3, 6.5, 7.1, 7.3, 8.1 and so on +Starting with 6.0, stable versions have an even minor version. For example, 6.0, 6.2, 6.4, 7.0, 7.2, 7.4. Preview versions have an odd minor version. For example, 6.1, 6.3, 6.5, 7.1, 7.3, and so on ## Contributors Special thanks to everyone who has contributed to the project. diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3c025fa33..e80e73dae 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,6 +1,6 @@ -# Microsoft JDBC Driver for SQL Server CI build triggers tests against below SQL Servers: +# Microsoft JDBC Driver for SQL Server CI Build triggers tests against below SQL Servers: # - SQL Server 2019 -# - SQL Server 2012 +# - SQL Server 2008 R2 jobs: - job: "CI_Build" pool: @@ -11,8 +11,8 @@ jobs: SQL-2019: Target_SQL: 'SQL-2k19-01' Ex_Groups: 'xSQLv15' - SQL-2012: - Target_SQL: 'SQL-2K12-SP3-1' + SQL-2008R2: + Target_SQL: 'SQL-2k8R2-SP3-1' Ex_Groups: 'xSQLv12' maxParallel: 2 steps: @@ -29,35 +29,30 @@ jobs: Get-Content .\JavaKeyStoreBase.txt | Set-Content -Encoding utf8 JavaKeyStore.txt Remove-Item –path .\JavaKeyStoreBase.txt displayName: 'PowerShell Script' - - task: DownloadSecureFile@1 - name: pkcs12_truststore - displayName: 'Download PKCS12 truststore file' - inputs: - secureFile: 'pkcs12_truststore' - task: Maven@3 - displayName: 'Maven build jre13' + displayName: 'Maven build jre12' inputs: mavenPomFile: 'pom.xml' - goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pjre13 -DuserNTLM=$(userNTLM) -DpasswordNTLM=$(passwordNTLM) -DdomainNTLM=$(domainNTLM) -DexcludedGroups=$(Ex_Groups) -Dpkcs12_truststore_password=$(pkcs12_truststore_password) -Dpkcs12_truststore=$(pkcs12_truststore.secureFilePath)' + goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pjre12 -DuserNTLM=$(userNTLM) -DpasswordNTLM=$(passwordNTLM) -DdomainNTLM=$(domainNTLM) -DexcludedGroups=$(Ex_Groups)' testResultsFiles: '**/TEST-*.xml' - testRunTitle: 'Maven build jre13' + testRunTitle: 'Maven build jre12' javaHomeOption: Path - jdkDirectory: $(JDK13) + jdkDirectory: $(JDK12) - task: Maven@3 displayName: 'Maven build jre11' inputs: mavenPomFile: 'pom.xml' - goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pjre11 -DuserNTLM=$(userNTLM) -DpasswordNTLM=$(passwordNTLM) -DdomainNTLM=$(domainNTLM) -DexcludedGroups=$(Ex_Groups) -Dpkcs12_truststore_password=$(pkcs12_truststore_password) -Dpkcs12_truststore=$(pkcs12_truststore.secureFilePath)' + goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pjre11 -DuserNTLM=$(userNTLM) -DpasswordNTLM=$(passwordNTLM) -DdomainNTLM=$(domainNTLM) -DexcludedGroups=$(Ex_Groups)' testResultsFiles: '**/TEST-*.xml' testRunTitle: 'Maven build jre11' javaHomeOption: Path - jdkDirectory: $(JDK13) + jdkDirectory: $(JDK12) - task: Maven@3 displayName: 'Maven build jre8' inputs: mavenPomFile: 'pom.xml' - goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pjre8 -DuserNTLM=$(userNTLM) -DpasswordNTLM=$(passwordNTLM) -DdomainNTLM=$(domainNTLM) -DexcludedGroups=$(Ex_Groups) -Dpkcs12_truststore_password=$(pkcs12_truststore_password) -Dpkcs12_truststore=$(pkcs12_truststore.secureFilePath)' + goals: 'clean -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pjre8 -DuserNTLM=$(userNTLM) -DpasswordNTLM=$(passwordNTLM) -DdomainNTLM=$(domainNTLM) -DexcludedGroups=$(Ex_Groups)' testResultsFiles: '**/TEST-*.xml' testRunTitle: 'Maven build jre8' javaHomeOption: Path - jdkDirectory: $(JDK13) + jdkDirectory: $(JDK12) diff --git a/build.gradle b/build.gradle index cda572c46..c5ead5be4 100644 --- a/build.gradle +++ b/build.gradle @@ -3,8 +3,8 @@ **************************************************************** * Instruction for Building JDBC Driver: * For building particular version of the driver, use commands: - * jre13 - - PS> gradle build - PS> gradle build -PbuildProfile=jre13 + * jre12 - - PS> gradle build + PS> gradle build -PbuildProfile=jre12 * jre11 - - PS> gradle build -PbuildProfile=jre11 * jre8 - - PS> gradle build -PbuildProfile=jre8 * @@ -14,7 +14,7 @@ apply plugin: 'java' -version = '8.1.0' +version = '7.4.1' def jreVersion = "" def testOutputDir = file("build/classes/java/test") def archivesBaseName = 'mssql-jdbc' @@ -31,21 +31,21 @@ allprojects { test { useJUnitPlatform { - excludeTags (hasProperty('excludedGroups') ? excludedGroups : 'xSQLv15','xGradle','reqExternalSetup','NTLM') + excludeTags (hasProperty('excludedGroups') ? excludedGroups : 'xSQLv15','xGradle','NTLM') } } -if (!hasProperty('buildProfile') || (hasProperty('buildProfile') && buildProfile == "jre13")){ +if (!hasProperty('buildProfile') || (hasProperty('buildProfile') && buildProfile == "jre12")){ - jreVersion = "jre13" + jreVersion = "jre12" excludedFile = 'com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java' jar { manifest { attributes 'Automatic-Module-Name': 'com.microsoft.sqlserver.jdbc' } } - sourceCompatibility = 13 - targetCompatibility = 13 + sourceCompatibility = 12 + targetCompatibility = 12 } if (hasProperty('buildProfile') && buildProfile == "jre11"){ @@ -70,12 +70,12 @@ if(hasProperty('buildProfile') && buildProfile == "jre8") { targetCompatibility = 1.8 test { useJUnitPlatform { - excludeTags (hasProperty('excludedGroups') ? excludedGroups : 'xSQLv15','xGradle','NTLM','reqExternalSetup','xJDBC42') + excludeTags (hasProperty('excludedGroups') ? excludedGroups : 'xSQLv15','xGradle','NTLM','xJDBC42') } } } -jar.archiveName = "${archivesBaseName}-${version}.${jreVersion}-preview.jar" +jar.archiveName = "${archivesBaseName}-${version}.${jreVersion}.jar" jar { manifest { attributes 'Title': "Microsoft JDBC Driver ${version} for SQL Server", diff --git a/pom.xml b/pom.xml index ebdd69f7c..2c7c0bbdd 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.microsoft.sqlserver mssql-jdbc - 8.1.0 + 7.4.1 jar Microsoft JDBC Driver for SQL Server @@ -49,11 +49,10 @@ xAzureSQLDB - - - - For tests not compatible with Azure SQL Database - - xAzureSQLDW - - - - For tests not compatible with Azure Data Warehouse - xAzureSQLMI - - - - For tests not compatible with Azure SQL Managed Instance - NTLM - - - - - - - For tests using NTLM Authentication mode (excluded by default) - reqExternalSetup - For tests requiring external setup (excluded by default) + NTLM - - - - - - For tests using NTLM Authentication mode (excluded by default) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default testing enabled with SQL Server 2019 (SQLv14) --> - xSQLv15, NTLM, reqExternalSetup + xSQLv15, NTLM 1.2.1 @@ -197,7 +196,7 @@ jre8 - ${project.artifactId}-${project.version}.jre8-preview + ${project.artifactId}-${project.version}.jre8 org.apache.maven.plugins @@ -243,7 +242,7 @@ jre11 - ${project.artifactId}-${project.version}.jre11-preview + ${project.artifactId}-${project.version}.jre11 org.apache.maven.plugins @@ -274,12 +273,12 @@ - jre13 + jre12 true - ${project.artifactId}-${project.version}.jre13-preview + ${project.artifactId}-${project.version}.jre12 org.apache.maven.plugins @@ -289,8 +288,8 @@ **/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java - 13 - 13 + 12 + 12 diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/AE.java b/src/main/java/com/microsoft/sqlserver/jdbc/AE.java index c75e3c46d..4ba6d0f69 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/AE.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/AE.java @@ -242,9 +242,7 @@ enum DescribeParameterEncryptionResultSet1 { EncryptedKey, ProviderName, KeyPath, - KeyEncryptionAlgorithm, - IsRequestedByEnclave, - EnclaveCMKSignature; + KeyEncryptionAlgorithm; int value() { // Column indexing starts from 1; @@ -268,15 +266,5 @@ int value() { // Column indexing starts from 1; return ordinal() + 1; } -} - -enum ColumnEncryptionVersion { - AE_NotSupported, - AE_v1, - AE_v2; - int value() { - // Column indexing starts from 1; - return ordinal() + 1; - } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/AuthenticationJNI.java b/src/main/java/com/microsoft/sqlserver/jdbc/AuthenticationJNI.java index 859a9f96d..ae53c3c6c 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/AuthenticationJNI.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/AuthenticationJNI.java @@ -160,7 +160,4 @@ private static native FedAuthDllInfo ADALGetAccessTokenForWindowsIntegrated(Stri static native byte[] DecryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm, byte[] encryptedColumnEncryptionKey) throws DLLException; - - static native boolean VerifyColumnMasterKeyMetadata(String keyPath, boolean allowEnclaveComputations, - byte[] signature) throws DLLException; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index 2cd9404f8..c82b0e628 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -40,7 +40,6 @@ import java.text.MessageFormat; import java.time.OffsetDateTime; import java.time.OffsetTime; -import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Collection; @@ -114,9 +113,7 @@ final class TDS { // AE constants // 0x03 is for x_eFeatureExtensionId_Rcs static final byte TDS_FEATURE_EXT_AE = 0x04; - static final byte COLUMNENCRYPTION_NOT_SUPPORTED = 0x00; // column encryption not supported - static final byte COLUMNENCRYPTION_VERSION1 = 0x01; // column encryption without enclave - static final byte COLUMNENCRYPTION_VERSION2 = 0x02; // column encryption with enclave + static final byte MAX_SUPPORTED_TCE_VERSION = 0x01; // max version static final int CUSTOM_CIPHER_ALGORITHM_ID = 0; // max version // 0x06 is for x_eFeatureExtensionId_LoginToken // 0x07 is for x_eFeatureExtensionId_ClientSideTelemetry @@ -3704,9 +3701,8 @@ void writeBytes(byte[] value, int offset, int length) throws SQLServerException int bytesWritten = 0; int bytesToWrite; - if (logger.isLoggable(Level.FINEST)) { + if (logger.isLoggable(Level.FINEST)) logger.finest(toString() + " Writing " + length + " bytes"); - } while ((bytesToWrite = length - bytesWritten) > 0) { if (0 == stagingBuffer.remaining()) @@ -6193,22 +6189,6 @@ void writeRPCReaderUnicode(String sName, Reader re, long reLength, boolean bOut, // Write the data writeReader(re, reLength, usePLP); } - - void sendEnclavePackage(String sql, ArrayList enclaveCEKs) throws SQLServerException { - if (null != con && con.isAEv2()) { - if (null != sql && "" != sql && null != enclaveCEKs && 0 < enclaveCEKs.size() && con.enclaveEstablished()) { - byte[] b = con.generateEncalvePackage(sql, enclaveCEKs); - if (null != b && 0 != b.length) { - this.writeShort((short) b.length); - this.writeBytes(b); - } else { - this.writeShort((short) 0); - } - } else { - this.writeShort((short) 0); - } - } - } } @@ -6304,7 +6284,6 @@ final SQLServerConnection getConnection() { private boolean useColumnEncryption = false; private boolean serverSupportsColumnEncryption = false; private boolean serverSupportsDataClassification = false; - private ColumnEncryptionVersion columnEncryptionVersion; private final byte valueBytes[] = new byte[256]; @@ -6329,7 +6308,6 @@ private static int nextReaderID() { useColumnEncryption = true; } serverSupportsColumnEncryption = con.getServerSupportsColumnEncryption(); - columnEncryptionVersion = con.getServerColumnEncryptionVersion(); serverSupportsDataClassification = con.getServerSupportsDataClassification(); } @@ -7184,8 +7162,6 @@ final boolean readingResponse() { return readingResponse; } - protected ArrayList enclaveCEKs; - /** * Creates this command with an optional timeout. * diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkData.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkData.java deleted file mode 100644 index 0b60a8fcd..000000000 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkData.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made - * available under the terms of the MIT License. See the LICENSE file in the project root for more information. - */ - -package com.microsoft.sqlserver.jdbc; - -import java.io.Serializable; - -/** - * Provides an interface used to create classes that read in data from any source (such as a file) and allows a - * SQLServerBulkCopy class to write the data to SQL Server tables. - */ -public interface ISQLServerBulkData extends Serializable { - - /** - * Returns the ordinals for each of the columns represented in this data record. - * - * @return Set of ordinals for the columns. - */ - java.util.Set getColumnOrdinals(); - - /** - * Returns the name of the given column. - * - * @param column - * Column ordinal - * @return Name of the column - */ - String getColumnName(int column); - - /** - * Returns the JDBC data type of the given column. - * - * @param column - * Column ordinal - * @return JDBC data type of the column - */ - int getColumnType(int column); - - /** - * Returns the precision for the given column. - * - * @param column - * Column ordinal - * @return Precision of the column - */ - int getPrecision(int column); - - /** - * Returns the scale for the given column. - * - * @param column - * Column ordinal - * @return Scale of the column - */ - int getScale(int column); - - /** - * Returns the data for the current row as an array of Objects. - * - * Each Object must match the Java language Type that is used to represent the indicated JDBC data type for the - * given column. For more information, see 'Understanding the JDBC Driver Data Types' for the appropriate mappings. - * - * @return The data for the row. - * @throws SQLServerException - * If there are any errors in obtaining the data. - */ - Object[] getRowData() throws SQLServerException; - - /** - * Advances to the next data row. - * - * @return True if rows are available; false if there are no more rows - * @throws SQLServerException - * If there are any errors in advancing to the next row. - */ - boolean next() throws SQLServerException; -} diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkRecord.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkRecord.java index 7767cf868..36aa40ebd 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkRecord.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerBulkRecord.java @@ -5,6 +5,7 @@ package com.microsoft.sqlserver.jdbc; +import java.io.Serializable; import java.time.format.DateTimeFormatter; @@ -13,20 +14,81 @@ * SQLServerBulkCopy class to write the data to SQL Server tables. * * This interface is implemented by {@link SQLServerBulkRecord} Class - * - * @deprecated as of 7.5.0, because the interface contains methods which are not called as part of actual bulk copy - * process. Use {@link ISQLServerBulkData}} instead. */ -@Deprecated -public interface ISQLServerBulkRecord extends ISQLServerBulkData { +public interface ISQLServerBulkRecord extends Serializable { + + /** + * Returns the ordinals for each of the columns represented in this data record. + * + * @return Set of ordinals for the columns. + */ + public java.util.Set getColumnOrdinals(); + + /** + * Returns the name of the given column. + * + * @param column + * Column ordinal + * @return Name of the column + */ + public String getColumnName(int column); + + /** + * Returns the JDBC data type of the given column. + * + * @param column + * Column ordinal + * @return JDBC data type of the column + */ + public int getColumnType(int column); + + /** + * Returns the precision for the given column. + * + * @param column + * Column ordinal + * @return Precision of the column + */ + public int getPrecision(int column); + + /** + * Returns the scale for the given column. + * + * @param column + * Column ordinal + * @return Scale of the column + */ + public int getScale(int column); + /** * Returns whether the column represents an identity column. - * + * * @param column * Column ordinal * @return True if the column is an identity column; false otherwise. */ - boolean isAutoIncrement(int column); + public boolean isAutoIncrement(int column); + + /** + * Returns the data for the current row as an array of Objects. + * + * Each Object must match the Java language Type that is used to represent the indicated JDBC data type for the + * given column. For more information, see 'Understanding the JDBC Driver Data Types' for the appropriate mappings. + * + * @return The data for the row. + * @throws SQLServerException + * If there are any errors in obtaining the data. + */ + public Object[] getRowData() throws SQLServerException; + + /** + * Advances to the next data row. + * + * @return True if rows are available; false if there are no more rows + * @throws SQLServerException + * If there are any errors in advancing to the next row. + */ + public boolean next() throws SQLServerException; /** * Adds metadata for the given column in the file. @@ -46,7 +108,7 @@ public interface ISQLServerBulkRecord extends ISQLServerBulkData { * @throws SQLServerException * when an error occurs */ - void addColumnMetadata(int positionInFile, String name, int jdbcType, int precision, int scale, + public void addColumnMetadata(int positionInFile, String name, int jdbcType, int precision, int scale, DateTimeFormatter dateTimeFormatter) throws SQLServerException; /** @@ -65,7 +127,7 @@ void addColumnMetadata(int positionInFile, String name, int jdbcType, int precis * @throws SQLServerException * when an error occurs */ - void addColumnMetadata(int positionInFile, String name, int jdbcType, int precision, + public void addColumnMetadata(int positionInFile, String name, int jdbcType, int precision, int scale) throws SQLServerException; /** @@ -74,7 +136,7 @@ void addColumnMetadata(int positionInFile, String name, int jdbcType, int precis * @param dateTimeFormat * format to parse data sent as java.sql.Types.TIMESTAMP_WITH_TIMEZONE */ - void setTimestampWithTimezoneFormat(String dateTimeFormat); + public void setTimestampWithTimezoneFormat(String dateTimeFormat); /** * Sets the format for reading in dates from the file. @@ -82,7 +144,7 @@ void addColumnMetadata(int positionInFile, String name, int jdbcType, int precis * @param dateTimeFormatter * format to parse data sent as java.sql.Types.TIMESTAMP_WITH_TIMEZONE */ - void setTimestampWithTimezoneFormat(DateTimeFormatter dateTimeFormatter); + public void setTimestampWithTimezoneFormat(DateTimeFormatter dateTimeFormatter); /** * Sets the format for reading in dates from the file. @@ -90,7 +152,7 @@ void addColumnMetadata(int positionInFile, String name, int jdbcType, int precis * @param timeFormat * format to parse data sent as java.sql.Types.TIME_WITH_TIMEZONE */ - void setTimeWithTimezoneFormat(String timeFormat); + public void setTimeWithTimezoneFormat(String timeFormat); /** * Sets the format for reading in dates from the file. @@ -98,7 +160,7 @@ void addColumnMetadata(int positionInFile, String name, int jdbcType, int precis * @param dateTimeFormatter * format to parse data sent as java.sql.Types.TIME_WITH_TIMEZONE */ - void setTimeWithTimezoneFormat(DateTimeFormatter dateTimeFormatter); + public void setTimeWithTimezoneFormat(DateTimeFormatter dateTimeFormatter); /** * Returns the dateTimeFormatter for the given column. @@ -107,5 +169,5 @@ void addColumnMetadata(int positionInFile, String name, int jdbcType, int precis * Column ordinal * @return dateTimeFormatter */ - DateTimeFormatter getColumnDateTimeFormatter(int column); + public DateTimeFormatter getColumnDateTimeFormatter(int column); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerCallableStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerCallableStatement.java index 9ad83fc86..da7d75fde 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerCallableStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerCallableStatement.java @@ -17,7 +17,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, ISQLServerPreparedStatement { @Deprecated - BigDecimal getBigDecimal(String parameterName, int scale) throws SQLServerException; + public BigDecimal getBigDecimal(String parameterName, int scale) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -29,7 +29,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - Timestamp getDateTime(int index) throws SQLServerException; + public Timestamp getDateTime(int index) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -42,7 +42,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - Timestamp getDateTime(String parameterName) throws SQLServerException; + public Timestamp getDateTime(String parameterName) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -57,7 +57,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - Timestamp getDateTime(int index, Calendar cal) throws SQLServerException; + public Timestamp getDateTime(int index, Calendar cal) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -72,7 +72,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - Timestamp getDateTime(String name, Calendar cal) throws SQLServerException; + public Timestamp getDateTime(String name, Calendar cal) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -84,7 +84,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - Timestamp getSmallDateTime(int index) throws SQLServerException; + public Timestamp getSmallDateTime(int index) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -96,7 +96,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - Timestamp getSmallDateTime(String parameterName) throws SQLServerException; + public Timestamp getSmallDateTime(String parameterName) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -110,7 +110,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - Timestamp getSmallDateTime(int index, Calendar cal) throws SQLServerException; + public Timestamp getSmallDateTime(int index, Calendar cal) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -124,7 +124,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - Timestamp getSmallDateTime(String name, Calendar cal) throws SQLServerException; + public Timestamp getSmallDateTime(String name, Calendar cal) throws SQLServerException; /** * Returns the DateTimeOffset value of parameter with index parameterIndex. @@ -136,7 +136,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * if parameterIndex is out of range; if a database access error occurs or this method is called on a closed * CallableStatement */ - microsoft.sql.DateTimeOffset getDateTimeOffset(int parameterIndex) throws SQLServerException; + public microsoft.sql.DateTimeOffset getDateTimeOffset(int parameterIndex) throws SQLServerException; /** * Returns the DateTimeOffset value of parameter with name parameterName. @@ -148,7 +148,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - microsoft.sql.DateTimeOffset getDateTimeOffset(String parameterName) throws SQLServerException; + public microsoft.sql.DateTimeOffset getDateTimeOffset(String parameterName) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a stream @@ -169,7 +169,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * if the columnIndex is not valid; if a database access error occurs or this method is called on a closed * result set */ - java.io.InputStream getAsciiStream(int parameterIndex) throws SQLServerException; + public java.io.InputStream getAsciiStream(int parameterIndex) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a stream @@ -190,7 +190,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * if the columnLabel is not valid; if a database access error occurs or this method is called on a closed * result set */ - java.io.InputStream getAsciiStream(String parameterName) throws SQLServerException; + public java.io.InputStream getAsciiStream(String parameterName) throws SQLServerException; /** * Returns the value of the column specified as a java.math.BigDecimal object. @@ -201,7 +201,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - BigDecimal getMoney(int parameterIndex) throws SQLServerException; + public BigDecimal getMoney(int parameterIndex) throws SQLServerException; /** * Returns the value of the column specified as a java.math.BigDecimal object. @@ -212,7 +212,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - BigDecimal getMoney(String parameterName) throws SQLServerException; + public BigDecimal getMoney(String parameterName) throws SQLServerException; /** * Returns the value of the column specified as a java.math.BigDecimal object. @@ -223,7 +223,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - BigDecimal getSmallMoney(int parameterIndex) throws SQLServerException; + public BigDecimal getSmallMoney(int parameterIndex) throws SQLServerException; /** * Returns the value of the column specified as a java.math.BigDecimal object. @@ -234,7 +234,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * @throws SQLServerException * when an error occurs */ - BigDecimal getSmallMoney(String parameterName) throws SQLServerException; + public BigDecimal getSmallMoney(String parameterName) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a stream @@ -254,7 +254,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * if the columnIndex is not valid; if a database access error occurs or this method is called on a closed * result set */ - java.io.InputStream getBinaryStream(int parameterIndex) throws SQLServerException; + public java.io.InputStream getBinaryStream(int parameterIndex) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a stream @@ -274,7 +274,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * if the columnLabel is not valid; if a database access error occurs or this method is called on a closed * result set */ - java.io.InputStream getBinaryStream(String parameterName) throws SQLServerException; + public java.io.InputStream getBinaryStream(String parameterName) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Timestamp value. The driver converts this to an @@ -295,7 +295,7 @@ public interface ISQLServerCallableStatement extends java.sql.CallableStatement, * method is called on a closed CallableStatement * @see #getTimestamp */ - void setTimestamp(String parameterName, java.sql.Timestamp value, Calendar calendar, + public void setTimestamp(String parameterName, java.sql.Timestamp value, Calendar calendar, boolean forceEncrypt) throws SQLServerException; /** @@ -320,7 +320,7 @@ void setTimestamp(String parameterName, java.sql.Timestamp value, Calendar calen * method is called on a closed CallableStatement * @see #getTime */ - void setTime(String parameterName, java.sql.Time value, Calendar calendar, + public void setTime(String parameterName, java.sql.Time value, Calendar calendar, boolean forceEncrypt) throws SQLServerException; /** @@ -345,7 +345,7 @@ void setTime(String parameterName, java.sql.Time value, Calendar calendar, * method is called on a closed CallableStatement * @see #getDate */ - void setDate(String parameterName, java.sql.Date value, Calendar calendar, + public void setDate(String parameterName, java.sql.Date value, Calendar calendar, boolean forceEncrypt) throws SQLServerException; /** @@ -365,7 +365,7 @@ void setDate(String parameterName, java.sql.Date value, Calendar calendar, * character sets; if the driver can detect that a data conversion error could occur; if a database access * error occurs or this method is called on a closed CallableStatement */ - void setNString(String parameterName, String value, boolean forceEncrypt) throws SQLServerException; + public void setNString(String parameterName, String value, boolean forceEncrypt) throws SQLServerException; /** * Sets the value of the designated parameter with the given object. @@ -401,7 +401,7 @@ void setDate(String parameterName, java.sql.Date value, Calendar calendar, * @see java.sql.Types * @see #getObject */ - void setObject(String parameterName, Object value, int sqlType, int decimals, + public void setObject(String parameterName, Object value, int sqlType, int decimals, boolean forceEncrypt) throws SQLServerException; /** @@ -435,7 +435,7 @@ void setObject(String parameterName, Object value, int sqlType, int decimals, * @see java.sql.Types * @see #getObject */ - void setObject(String parameterName, Object value, int targetSqlType, Integer precision, + public void setObject(String parameterName, Object value, int targetSqlType, Integer precision, int scale) throws SQLServerException; /** @@ -453,7 +453,7 @@ void setObject(String parameterName, Object value, int targetSqlType, Integer pr * method is called on a closed CallableStatement * @see #getTimestamp */ - void setTimestamp(String parameterName, java.sql.Timestamp value, int scale) throws SQLServerException; + public void setTimestamp(String parameterName, java.sql.Timestamp value, int scale) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Timestamp value. The driver converts this to an @@ -474,7 +474,7 @@ void setObject(String parameterName, Object value, int targetSqlType, Integer pr * method is called on a closed CallableStatement * @see #getTimestamp */ - void setTimestamp(String parameterName, java.sql.Timestamp value, int scale, + public void setTimestamp(String parameterName, java.sql.Timestamp value, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -487,7 +487,7 @@ void setTimestamp(String parameterName, java.sql.Timestamp value, int scale, * @throws SQLServerException * if an error occurs */ - void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value) throws SQLServerException; + public void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value) throws SQLServerException; /** * Sets parameter parameterName to DateTimeOffset value. @@ -501,7 +501,7 @@ void setTimestamp(String parameterName, java.sql.Timestamp value, int scale, * @throws SQLServerException * if an error occurs */ - void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, + public void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, int scale) throws SQLServerException; /** @@ -520,7 +520,7 @@ void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, * @throws SQLServerException * if an error occurs */ - void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, int scale, + public void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -538,7 +538,7 @@ void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, * method is called on a closed CallableStatement * @see #getTime */ - void setTime(String parameterName, java.sql.Time value, int scale) throws SQLServerException; + public void setTime(String parameterName, java.sql.Time value, int scale) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Time value. The driver converts this to an SQL @@ -559,7 +559,8 @@ void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, * method is called on a closed CallableStatement * @see #getTime */ - void setTime(String parameterName, java.sql.Time value, int scale, boolean forceEncrypt) throws SQLServerException; + public void setTime(String parameterName, java.sql.Time value, int scale, + boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Timestamp value. The driver converts this to an @@ -573,7 +574,7 @@ void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setDateTime(String parameterName, java.sql.Timestamp value) throws SQLServerException; + public void setDateTime(String parameterName, java.sql.Timestamp value) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Timestamp value. The driver converts this to an @@ -591,7 +592,8 @@ void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setDateTime(String parameterName, java.sql.Timestamp value, boolean forceEncrypt) throws SQLServerException; + public void setDateTime(String parameterName, java.sql.Timestamp value, + boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Timestamp value. The driver converts this to an @@ -605,7 +607,7 @@ void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setSmallDateTime(String parameterName, java.sql.Timestamp value) throws SQLServerException; + public void setSmallDateTime(String parameterName, java.sql.Timestamp value) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Timestamp value. The driver converts this to an @@ -623,7 +625,7 @@ void setDateTimeOffset(String parameterName, microsoft.sql.DateTimeOffset value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setSmallDateTime(String parameterName, java.sql.Timestamp value, + public void setSmallDateTime(String parameterName, java.sql.Timestamp value, boolean forceEncrypt) throws SQLServerException; /** @@ -638,7 +640,7 @@ void setSmallDateTime(String parameterName, java.sql.Timestamp value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setUniqueIdentifier(String parameterName, String guid) throws SQLServerException; + public void setUniqueIdentifier(String parameterName, String guid) throws SQLServerException; /** * Sets the designated parameter to the given String value. The driver converts this to an SQL @@ -656,7 +658,7 @@ void setSmallDateTime(String parameterName, java.sql.Timestamp value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setUniqueIdentifier(String parameterName, String guid, boolean forceEncrypt) throws SQLServerException; + public void setUniqueIdentifier(String parameterName, String guid, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java array of bytes. The driver converts this to an SQL @@ -675,7 +677,7 @@ void setSmallDateTime(String parameterName, java.sql.Timestamp value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setBytes(String parameterName, byte[] value, boolean forceEncrypt) throws SQLServerException; + public void setBytes(String parameterName, byte[] value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java byte value. The driver converts this to an SQL @@ -693,7 +695,7 @@ void setSmallDateTime(String parameterName, java.sql.Timestamp value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setByte(String parameterName, byte value, boolean forceEncrypt) throws SQLServerException; + public void setByte(String parameterName, byte value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java String value. The driver converts this to an SQL @@ -712,7 +714,7 @@ void setSmallDateTime(String parameterName, java.sql.Timestamp value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setString(String parameterName, String value, boolean forceEncrypt) throws SQLServerException; + public void setString(String parameterName, String value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java java.math.BigDecimal value. The driver converts this @@ -726,7 +728,7 @@ void setSmallDateTime(String parameterName, java.sql.Timestamp value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setMoney(String parameterName, BigDecimal value) throws SQLServerException; + public void setMoney(String parameterName, BigDecimal value) throws SQLServerException; /** * Sets the designated parameter to the given Java java.math.BigDecimal value. The driver converts this @@ -744,7 +746,7 @@ void setSmallDateTime(String parameterName, java.sql.Timestamp value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setMoney(String parameterName, BigDecimal value, boolean forceEncrypt) throws SQLServerException; + public void setMoney(String parameterName, BigDecimal value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java java.math.BigDecimal value. The driver converts this @@ -758,7 +760,7 @@ void setSmallDateTime(String parameterName, java.sql.Timestamp value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setSmallMoney(String parameterName, BigDecimal value) throws SQLServerException; + public void setSmallMoney(String parameterName, BigDecimal value) throws SQLServerException; /** * Sets the designated parameter to the given Java java.math.BigDecimal value. The driver converts this @@ -776,7 +778,7 @@ void setSmallDateTime(String parameterName, java.sql.Timestamp value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setSmallMoney(String parameterName, BigDecimal value, boolean forceEncrypt) throws SQLServerException; + public void setSmallMoney(String parameterName, BigDecimal value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given java.math.BigDecimal value. The driver converts this to @@ -794,7 +796,8 @@ void setSmallDateTime(String parameterName, java.sql.Timestamp value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setBigDecimal(String parameterName, BigDecimal value, int precision, int scale) throws SQLServerException; + public void setBigDecimal(String parameterName, BigDecimal value, int precision, + int scale) throws SQLServerException; /** * Sets the designated parameter to the given java.math.BigDecimal value. The driver converts this to @@ -816,7 +819,7 @@ void setSmallDateTime(String parameterName, java.sql.Timestamp value, * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setBigDecimal(String parameterName, BigDecimal value, int precision, int scale, + public void setBigDecimal(String parameterName, BigDecimal value, int precision, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -835,7 +838,7 @@ void setBigDecimal(String parameterName, BigDecimal value, int precision, int sc * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setDouble(String parameterName, double value, boolean forceEncrypt) throws SQLServerException; + public void setDouble(String parameterName, double value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java float value. The driver converts this to an SQL @@ -853,7 +856,7 @@ void setBigDecimal(String parameterName, BigDecimal value, int precision, int sc * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setFloat(String parameterName, float value, boolean forceEncrypt) throws SQLServerException; + public void setFloat(String parameterName, float value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java int value. The driver converts this to an SQL @@ -871,7 +874,7 @@ void setBigDecimal(String parameterName, BigDecimal value, int precision, int sc * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setInt(String parameterName, int value, boolean forceEncrypt) throws SQLServerException; + public void setInt(String parameterName, int value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java long value. The driver converts this to an SQL @@ -889,7 +892,7 @@ void setBigDecimal(String parameterName, BigDecimal value, int precision, int sc * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setLong(String parameterName, long value, boolean forceEncrypt) throws SQLServerException; + public void setLong(String parameterName, long value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java short value. The driver converts this to an SQL @@ -907,7 +910,7 @@ void setBigDecimal(String parameterName, BigDecimal value, int precision, int sc * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setShort(String parameterName, short value, boolean forceEncrypt) throws SQLServerException; + public void setShort(String parameterName, short value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java boolean value. The driver converts this to an SQL @@ -925,7 +928,7 @@ void setBigDecimal(String parameterName, BigDecimal value, int precision, int sc * if parameterName does not correspond to a named parameter; if a database access error occurs or this * method is called on a closed CallableStatement */ - void setBoolean(String parameterName, boolean value, boolean forceEncrypt) throws SQLServerException; + public void setBoolean(String parameterName, boolean value, boolean forceEncrypt) throws SQLServerException; /** * Populates a table valued parameter passed to a stored procedure with a data table. @@ -939,7 +942,8 @@ void setBigDecimal(String parameterName, BigDecimal value, int precision, int sc * @throws SQLServerException * when an error occurs */ - void setStructured(String parameterName, String tvpName, SQLServerDataTable tvpDataTable) throws SQLServerException; + public void setStructured(String parameterName, String tvpName, + SQLServerDataTable tvpDataTable) throws SQLServerException; /** * Populates a table valued parameter passed to a stored procedure with a ResultSet retrieved from another table @@ -953,7 +957,8 @@ void setBigDecimal(String parameterName, BigDecimal value, int precision, int sc * @throws SQLServerException * when an error occurs */ - void setStructured(String parameterName, String tvpName, java.sql.ResultSet tvpResultSet) throws SQLServerException; + public void setStructured(String parameterName, String tvpName, + java.sql.ResultSet tvpResultSet) throws SQLServerException; /** * Populates a table valued parameter passed to a stored procedure with an ISQLServerDataRecord object. @@ -968,7 +973,7 @@ void setBigDecimal(String parameterName, BigDecimal value, int precision, int sc * @throws SQLServerException * when an error occurs */ - void setStructured(String parameterName, String tvpName, + public void setStructured(String parameterName, String tvpName, ISQLServerDataRecord tvpDataRecord) throws SQLServerException; /** @@ -990,7 +995,7 @@ void setStructured(String parameterName, String tvpName, * @throws SQLServerException * If any errors occur. */ - void registerOutParameter(String parameterName, SQLType sqlType, int precision, + public void registerOutParameter(String parameterName, SQLType sqlType, int precision, int scale) throws SQLServerException; /** @@ -1012,7 +1017,8 @@ void registerOutParameter(String parameterName, SQLType sqlType, int precision, * @throws SQLServerException * If any errors occur. */ - void registerOutParameter(int parameterIndex, SQLType sqlType, int precision, int scale) throws SQLServerException; + public void registerOutParameter(int parameterIndex, SQLType sqlType, int precision, + int scale) throws SQLServerException; /** * Registers the parameter in ordinal position index to be of JDBC type sqlType. All OUT parameters must be @@ -1033,7 +1039,8 @@ void registerOutParameter(String parameterName, SQLType sqlType, int precision, * @throws SQLServerException * If any errors occur. */ - void registerOutParameter(int parameterIndex, int sqlType, int precision, int scale) throws SQLServerException; + public void registerOutParameter(int parameterIndex, int sqlType, int precision, + int scale) throws SQLServerException; /** * Registers the parameter in ordinal position index to be of JDBC type sqlType. All OUT parameters must be @@ -1054,7 +1061,8 @@ void registerOutParameter(String parameterName, SQLType sqlType, int precision, * @throws SQLServerException * If any errors occur. */ - void registerOutParameter(String parameterName, int sqlType, int precision, int scale) throws SQLServerException; + public void registerOutParameter(String parameterName, int sqlType, int precision, + int scale) throws SQLServerException; /** * Sets the value of the designated parameter with the given object. @@ -1089,6 +1097,6 @@ void registerOutParameter(String parameterName, SQLType sqlType, int precision, * @see java.sql.Types * @see #getObject */ - void setObject(String parameterName, Object value, SQLType jdbcType, int scale, + public void setObject(String parameterName, Object value, SQLType jdbcType, int scale, boolean forceEncrypt) throws SQLServerException; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection.java index 58e5e5f75..19b9fe2f9 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection.java @@ -18,7 +18,7 @@ public interface ISQLServerConnection extends java.sql.Connection { // Transaction types. // TRANSACTION_SNAPSHOT corresponds to -> SET TRANSACTION ISOLATION LEVEL SNAPSHOT - int TRANSACTION_SNAPSHOT = 0x1000; + public final static int TRANSACTION_SNAPSHOT = 0x1000; /** * Returns the connection ID of the most recent connection attempt, regardless of whether the attempt succeeded or @@ -29,7 +29,7 @@ public interface ISQLServerConnection extends java.sql.Connection { * @throws SQLServerException * If any errors occur. */ - UUID getClientConnectionId() throws SQLServerException; + public UUID getClientConnectionId() throws SQLServerException; /** * Creates a Statement object that will generate ResultSet objects with the given type, @@ -53,7 +53,7 @@ public interface ISQLServerConnection extends java.sql.Connection { * if a database access error occurs, this method is called on a closed connection or the given parameters * are not ResultSet constants indicating type, concurrency, and holdability */ - Statement createStatement(int nType, int nConcur, int nHold, + public Statement createStatement(int nType, int nConcur, int nHold, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException; /** @@ -85,7 +85,7 @@ Statement createStatement(int nType, int nConcur, int nHold, * if a database access error occurs, this method is called on a closed connection or the given parameter is * not a Statement constant indicating whether auto-generated keys should be returned */ - PreparedStatement prepareStatement(String sql, int flag, + public PreparedStatement prepareStatement(String sql, int flag, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException; /** @@ -119,7 +119,7 @@ PreparedStatement prepareStatement(String sql, int flag, * @throws SQLServerException * if a database access error occurs or this method is called on a closed connection */ - PreparedStatement prepareStatement(String sql, int[] columnIndexes, + public PreparedStatement prepareStatement(String sql, int[] columnIndexes, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException; /** @@ -153,7 +153,7 @@ PreparedStatement prepareStatement(String sql, int[] columnIndexes, * @throws SQLServerException * if a database access error occurs or this method is called on a closed connection */ - PreparedStatement prepareStatement(String sql, String[] columnNames, + public PreparedStatement prepareStatement(String sql, String[] columnNames, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException; /** @@ -183,7 +183,7 @@ PreparedStatement prepareStatement(String sql, String[] columnNames, * if a database access error occurs, this method is called on a closed connection or the given parameters * are not ResultSet constants indicating type, concurrency, and holdability */ - PreparedStatement prepareStatement(java.lang.String sql, int nType, int nConcur, int resultSetHoldability, + public PreparedStatement prepareStatement(java.lang.String sql, int nType, int nConcur, int resultSetHoldability, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException; /** @@ -211,7 +211,7 @@ PreparedStatement prepareStatement(java.lang.String sql, int nType, int nConcur, * if a database access error occurs, this method is called on a closed connection or the given parameters * are not ResultSet constants indicating type, concurrency, and holdability */ - CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold, + public CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold, SQLServerStatementColumnEncryptionSetting stmtColEncSetting) throws SQLServerException; /** @@ -229,7 +229,7 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold, * @throws SQLServerException * if a database access error occurs */ - void setSendTimeAsDatetime(boolean sendTimeAsDateTimeValue) throws SQLServerException; + public void setSendTimeAsDatetime(boolean sendTimeAsDateTimeValue) throws SQLServerException; /** * Returns the value of the sendTimeAsDatetime property. @@ -239,19 +239,19 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold, * @throws SQLServerException * if a database access error occurs */ - boolean getSendTimeAsDatetime() throws SQLServerException; + public boolean getSendTimeAsDatetime() throws SQLServerException; /** * Returns the number of currently outstanding prepared statement un-prepare actions. * * @return Returns the current value per the description. */ - int getDiscardedServerPreparedStatementCount(); + public int getDiscardedServerPreparedStatementCount(); /** * Forces the un-prepare requests for any outstanding discarded prepared statements to be executed. */ - void closeUnreferencedPreparedStatementHandles(); + public void closeUnreferencedPreparedStatementHandles(); /** * Returns the behavior for a specific connection instance. If false the first execution will call sp_executesql and @@ -262,7 +262,7 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold, * * @return Returns the current setting per the description. */ - boolean getEnablePrepareOnFirstPreparedStatementCall(); + public boolean getEnablePrepareOnFirstPreparedStatementCall(); /** * Sets the behavior for a specific connection instance. If value is false the first execution will call @@ -273,7 +273,7 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold, * @param value * Changes the setting per the description. */ - void setEnablePrepareOnFirstPreparedStatementCall(boolean value); + public void setEnablePrepareOnFirstPreparedStatementCall(boolean value); /** * Returns the behavior for a specific connection instance. This setting controls how many outstanding prepared @@ -285,7 +285,7 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold, * * @return Returns the current setting per the description. */ - int getServerPreparedStatementDiscardThreshold(); + public int getServerPreparedStatementDiscardThreshold(); /** * Sets the behavior for a specific connection instance. This setting controls how many outstanding prepared @@ -297,7 +297,7 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold, * @param value * Changes the setting per the description. */ - void setServerPreparedStatementDiscardThreshold(int value); + public void setServerPreparedStatementDiscardThreshold(int value); /** * Sets the size of the prepared statement cache for this connection. A value less than 1 means no cache. @@ -306,28 +306,28 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold, * The new cache size. * */ - void setStatementPoolingCacheSize(int value); + public void setStatementPoolingCacheSize(int value); /** * Returns the size of the prepared statement cache for this connection. A value less than 1 means no cache. * * @return Returns the current setting per the description. */ - int getStatementPoolingCacheSize(); + public int getStatementPoolingCacheSize(); /** * Returns whether statement pooling is enabled or not for this connection. * * @return Returns the current setting per the description. */ - boolean isStatementPoolingEnabled(); + public boolean isStatementPoolingEnabled(); /** * Returns the current number of pooled prepared statement handles. * * @return Returns the current setting per the description. */ - int getStatementHandleCacheEntryCount(); + public int getStatementHandleCacheEntryCount(); /** * Sets the value to Disable/enable statement pooling. @@ -335,27 +335,27 @@ CallableStatement prepareCall(String sql, int nType, int nConcur, int nHold, * @param value * true to disable statement pooling, false to enable it. */ - void setDisableStatementPooling(boolean value); + public void setDisableStatementPooling(boolean value); /** * Returns the value whether statement pooling is disabled. * * @return true if statement pooling is disabled, false if it is enabled. */ - boolean getDisableStatementPooling(); + public boolean getDisableStatementPooling(); /** * Returns the current flag value for useFmtOnly. - * + * * @return 'useFmtOnly' property value. */ - boolean getUseFmtOnly(); + public boolean getUseFmtOnly(); /** * Specifies the flag to use FMTONLY for parameter metadata queries. - * + * * @param useFmtOnly * boolean value for 'useFmtOnly'. */ - void setUseFmtOnly(boolean useFmtOnly); + public void setUseFmtOnly(boolean useFmtOnly); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection43.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection43.java index 9eb725def..b17597aa6 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection43.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerConnection43.java @@ -43,7 +43,7 @@ public interface ISQLServerConnection43 extends ISQLServerConnection { * @see #endRequest() */ @Override - void beginRequest() throws SQLException; + public void beginRequest() throws SQLException; /** * Hints to the driver that a request, an independent unit of work, has completed. It rolls back the open @@ -59,5 +59,5 @@ public interface ISQLServerConnection43 extends ISQLServerConnection { * @see #beginRequest() */ @Override - void endRequest() throws SQLException; + public void endRequest() throws SQLException; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataRecord.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataRecord.java index 288479e73..7c45b8449 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataRecord.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataRecord.java @@ -17,14 +17,14 @@ public interface ISQLServerDataRecord { * the first column is 1, the second is 2, and so on * @return SQLServerMetaData of column */ - SQLServerMetaData getColumnMetaData(int column); + public SQLServerMetaData getColumnMetaData(int column); /** * Returns the column count. * * @return Set of ordinals for the columns. */ - int getColumnCount(); + public int getColumnCount(); /** * Returns the data for the current row as an array of Objects. @@ -34,12 +34,12 @@ public interface ISQLServerDataRecord { * * @return The data for the row. */ - Object[] getRowData(); + public Object[] getRowData(); /** * Advances to the next data row. * * @return True if rows are available; false if there are no more rows */ - boolean next(); + public boolean next(); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java index c9e4e1379..b1c15c048 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerDataSource.java @@ -843,14 +843,7 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource { * Client Key of Azure Key Vault (AKV) Provider to be used for column encryption. */ void setKeyVaultProviderClientKey(String keyVaultProviderClientKey); - - /** - * Returns the value for the connection property 'domain'. - * - * @return 'domain' property value - */ - String getDomain(); - + /** * Sets the 'domain' connection property used for NTLM Authentication. * @@ -860,48 +853,24 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource { void setDomain(String domain); /** - * Returns the current flag value for useFmtOnly. - * - * @return 'useFmtOnly' property value. - */ - boolean getUseFmtOnly(); - - /** - * Specifies the flag to use FMTONLY for parameter metadata queries. - * - * @param useFmtOnly - * boolean value for 'useFmtOnly'. - */ - void setUseFmtOnly(boolean useFmtOnly); - - /** - * Returns the enclave attestation URL used in Always Encrypted with Secure Enclaves. - * - * @return enclave attestation URL. - */ - String getEnclaveAttestationUrl(); - - /** - * Sets the enclave attestation URL used in Always Encrypted with Secure Enclaves. + * Returns the value for the connection property 'domain'. * - * @param url - * Enclave attestation URL. + * @return 'domain' property value */ - void setEnclaveAttestationUrl(String url); + String getDomain(); /** - * Returns the enclave attestation protocol used in Always Encrypted with Secure Enclaves. + * Returns the current flag value for useFmtOnly. * - * @return Enclave attestation protocol. + * @return 'useFmtOnly' property value. */ - String getEnclaveAttestationProtocol(); + public boolean getUseFmtOnly(); /** - * Sets the enclave attestation protocol to be used in Always Encrypted with Secure Enclaves. + * Specifies the flag to use FMTONLY for parameter metadata queries. * - * @param protocol - * Enclave attestation protocol. + * @param useFmtOnly + * boolean value for 'useFmtOnly'. */ - void setEnclaveAttestationProtocol(String protocol); - + public void setUseFmtOnly(boolean useFmtOnly); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerEnclaveProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerEnclaveProvider.java deleted file mode 100644 index 51f75ec6a..000000000 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerEnclaveProvider.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made - * available under the terms of the MIT License. See the LICENSE file in the project root for more information. - */ - -package com.microsoft.sqlserver.jdbc; - -import java.security.PrivateKey; -import java.util.ArrayList; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * - * Provides an interface to create an Enclave Session - * - */ -public interface ISQLServerEnclaveProvider { - byte[] getEnclavePackage(String userSQL, ArrayList enclaveCEKs) throws SQLServerException; - - /** - * Returns the attestation parameters - * @param createNewParameters - * indicates whether to create new parameters - * @param url - * attestation url - * @throws SQLServerException - * when an error occurs. - */ - void getAttestationParameters(boolean createNewParameters, String url) throws SQLServerException; - - /** - * Creates the enclave session - * - * @param connection - * connection - * @param userSql - * user sql - * @param preparedTypeDefinitions - * preparedTypeDefinitions - * @param params - * params - * @param parameterNames - * parameterNames - * @return - * list of enclave requested CEKs - * @throws SQLServerException - * when an error occurs. - */ - ArrayList createEnclaveSession(SQLServerConnection connection, String userSql, - String preparedTypeDefinitions, Parameter[] params, - ArrayList parameterNames) throws SQLServerException; - - /** - * Invalidates an enclave session - */ - void invalidateEnclaveSession(); - - /** - * Returns the enclave session - * @return - * the enclave session - */ - EnclaveSession getEnclaveSession(); -} - - -abstract class BaseAttestationRequest { - protected PrivateKey privateKey; - - byte[] getBytes() { - return null; - }; -} - - -class EnclaveSession { - private byte[] sessionID; - private AtomicInteger counter; - private byte[] sessionSecret; - - EnclaveSession(byte[] cs, byte[] b) { - sessionID = cs; - sessionSecret = b; - counter = new AtomicInteger(0); - } - - byte[] getSessionID() { - return sessionID; - } - - byte[] getSessionSecret() { - return sessionSecret; - } - - long getCounter() { - return counter.getAndIncrement(); - } -} diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerPreparedStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerPreparedStatement.java index 647185163..e8eb211db 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerPreparedStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerPreparedStatement.java @@ -26,7 +26,7 @@ public interface ISQLServerPreparedStatement extends java.sql.PreparedStatement, * if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access * error occurs or this method is called on a closed PreparedStatement */ - void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x) throws SQLServerException; + public void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x) throws SQLServerException; /** * Sets the value of the designated parameter with the given object. @@ -51,7 +51,7 @@ public interface ISQLServerPreparedStatement extends java.sql.PreparedStatement, * if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access * error occurs or this method is called on a closed {@code PreparedStatement} */ - void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer precision, + public void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer precision, Integer scale) throws SQLServerException; /** @@ -81,7 +81,7 @@ void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer prec * if parameterIndex does not correspond to a parameter marker in the SQL statement; if a database access * error occurs or this method is called on a closed {@code PreparedStatement} */ - void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer precision, Integer scale, + public void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer precision, Integer scale, boolean forceEncrypt) throws SQLServerException; /** @@ -91,7 +91,7 @@ void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer prec * @throws SQLServerException * when an error occurs */ - int getPreparedStatementHandle() throws SQLServerException; + public int getPreparedStatementHandle() throws SQLServerException; /** * Sets the designated parameter to the given java.math.BigDecimal value. The driver converts this to @@ -108,7 +108,7 @@ void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer prec * @throws SQLServerException * when an error occurs */ - void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale) throws SQLServerException; + public void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale) throws SQLServerException; /** * Sets the designated parameter to the given java.math.BigDecimal value. The driver converts this to @@ -129,7 +129,7 @@ void setObject(int parameterIndex, Object x, SQLType targetSqlType, Integer prec * @throws SQLServerException * when an error occurs */ - void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, + public void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -143,7 +143,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setMoney(int parameterIndex, BigDecimal x) throws SQLServerException; + public void setMoney(int parameterIndex, BigDecimal x) throws SQLServerException; /** * Sets the designated parameter to the given java.math.BigDecimal value. The driver converts this to @@ -160,7 +160,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setMoney(int parameterIndex, BigDecimal x, boolean forceEncrypt) throws SQLServerException; + public void setMoney(int parameterIndex, BigDecimal x, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given java.math.BigDecimal value. The driver converts this to @@ -173,7 +173,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setSmallMoney(int parameterIndex, BigDecimal x) throws SQLServerException; + public void setSmallMoney(int parameterIndex, BigDecimal x) throws SQLServerException; /** * Sets the designated parameter to the given java.math.BigDecimal value. The driver converts this to @@ -190,7 +190,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setSmallMoney(int parameterIndex, BigDecimal x, boolean forceEncrypt) throws SQLServerException; + public void setSmallMoney(int parameterIndex, BigDecimal x, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java boolean value. The driver converts this to an SQL @@ -207,7 +207,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setBoolean(int parameterIndex, boolean x, boolean forceEncrypt) throws SQLServerException; + public void setBoolean(int parameterIndex, boolean x, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java byte value. The driver converts this to an SQL @@ -224,7 +224,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setByte(int parameterIndex, byte x, boolean forceEncrypt) throws SQLServerException; + public void setByte(int parameterIndex, byte x, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java array of bytes. The driver converts this to an SQL @@ -242,7 +242,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setBytes(int parameterIndex, byte x[], boolean forceEncrypt) throws SQLServerException; + public void setBytes(int parameterIndex, byte x[], boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given String. The driver converts this to an SQL GUID @@ -254,7 +254,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setUniqueIdentifier(int parameterIndex, String guid) throws SQLServerException; + public void setUniqueIdentifier(int parameterIndex, String guid) throws SQLServerException; /** * Sets the designated parameter to the given String. The driver converts this to an SQL GUID @@ -270,7 +270,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setUniqueIdentifier(int parameterIndex, String guid, boolean forceEncrypt) throws SQLServerException; + public void setUniqueIdentifier(int parameterIndex, String guid, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java double value. The driver converts this to an SQL @@ -287,7 +287,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setDouble(int parameterIndex, double x, boolean forceEncrypt) throws SQLServerException; + public void setDouble(int parameterIndex, double x, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java float value. The driver converts this to an SQL @@ -304,7 +304,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setFloat(int parameterIndex, float x, boolean forceEncrypt) throws SQLServerException; + public void setFloat(int parameterIndex, float x, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given microsoft.sql.Geometry Class object. The driver converts @@ -317,7 +317,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setGeometry(int parameterIndex, Geometry x) throws SQLServerException; + public void setGeometry(int parameterIndex, Geometry x) throws SQLServerException; /** * Sets the designated parameter to the given microsoft.sql.Geography Class object. The driver converts @@ -330,7 +330,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setGeography(int parameterIndex, Geography x) throws SQLServerException; + public void setGeography(int parameterIndex, Geography x) throws SQLServerException; /** * Sets the designated parameter to the given Java int value. The driver converts this to an SQL @@ -347,7 +347,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setInt(int parameterIndex, int value, boolean forceEncrypt) throws SQLServerException; + public void setInt(int parameterIndex, int value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java long value. The driver converts this to an SQL @@ -364,7 +364,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setLong(int parameterIndex, long x, boolean forceEncrypt) throws SQLServerException; + public void setLong(int parameterIndex, long x, boolean forceEncrypt) throws SQLServerException; /** * Sets the value of the designated parameter with the given object. @@ -395,7 +395,7 @@ void setBigDecimal(int parameterIndex, BigDecimal x, int precision, int scale, * @throws SQLServerException * when an error occurs */ - void setObject(int parameterIndex, Object x, int targetSqlType, Integer precision, + public void setObject(int parameterIndex, Object x, int targetSqlType, Integer precision, int scale) throws SQLServerException; /** @@ -431,7 +431,7 @@ void setObject(int parameterIndex, Object x, int targetSqlType, Integer precisio * @throws SQLServerException * when an error occurs */ - void setObject(int parameterIndex, Object x, int targetSqlType, Integer precision, int scale, + public void setObject(int parameterIndex, Object x, int targetSqlType, Integer precision, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -449,7 +449,7 @@ void setObject(int parameterIndex, Object x, int targetSqlType, Integer precisio * @throws SQLServerException * when an error occurs */ - void setShort(int parameterIndex, short x, boolean forceEncrypt) throws SQLServerException; + public void setShort(int parameterIndex, short x, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given Java String value. The driver converts this to an SQL @@ -467,7 +467,7 @@ void setObject(int parameterIndex, Object x, int targetSqlType, Integer precisio * @throws SQLServerException * when an error occurs */ - void setString(int parameterIndex, String str, boolean forceEncrypt) throws SQLServerException; + public void setString(int parameterIndex, String str, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given String object. The driver converts this to a SQL @@ -485,7 +485,7 @@ void setObject(int parameterIndex, Object x, int targetSqlType, Integer precisio * @throws SQLServerException * when an error occurs */ - void setNString(int parameterIndex, String value, boolean forceEncrypt) throws SQLServerException; + public void setNString(int parameterIndex, String value, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Time value. @@ -499,7 +499,7 @@ void setObject(int parameterIndex, Object x, int targetSqlType, Integer precisio * @throws SQLServerException * when an error occurs */ - void setTime(int parameterIndex, java.sql.Time x, int scale) throws SQLServerException; + public void setTime(int parameterIndex, java.sql.Time x, int scale) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Time value. @@ -517,7 +517,7 @@ void setObject(int parameterIndex, Object x, int targetSqlType, Integer precisio * @throws SQLServerException * when an error occurs */ - void setTime(int parameterIndex, java.sql.Time x, int scale, boolean forceEncrypt) throws SQLServerException; + public void setTime(int parameterIndex, java.sql.Time x, int scale, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Timestamp value. @@ -531,7 +531,7 @@ void setObject(int parameterIndex, Object x, int targetSqlType, Integer precisio * @throws SQLServerException * when an error occurs */ - void setTimestamp(int parameterIndex, java.sql.Timestamp x, int scale) throws SQLServerException; + public void setTimestamp(int parameterIndex, java.sql.Timestamp x, int scale) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Timestamp value. @@ -549,7 +549,7 @@ void setObject(int parameterIndex, Object x, int targetSqlType, Integer precisio * @throws SQLServerException * when an error occurs */ - void setTimestamp(int parameterIndex, java.sql.Timestamp x, int scale, + public void setTimestamp(int parameterIndex, java.sql.Timestamp x, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -564,7 +564,8 @@ void setTimestamp(int parameterIndex, java.sql.Timestamp x, int scale, * @throws SQLServerException * when an error occurs */ - void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, int scale) throws SQLServerException; + public void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, + int scale) throws SQLServerException; /** * Sets the designated parameter to the given microsoft.sql.DatetimeOffset value. @@ -582,7 +583,7 @@ void setTimestamp(int parameterIndex, java.sql.Timestamp x, int scale, * @throws SQLServerException * when an error occurs */ - void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, int scale, + public void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -595,7 +596,7 @@ void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, int s * @throws SQLServerException * when an error occurs */ - void setDateTime(int parameterIndex, java.sql.Timestamp x) throws SQLServerException; + public void setDateTime(int parameterIndex, java.sql.Timestamp x) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Timestamp value. @@ -611,7 +612,7 @@ void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, int s * @throws SQLServerException * when an error occurs */ - void setDateTime(int parameterIndex, java.sql.Timestamp x, boolean forceEncrypt) throws SQLServerException; + public void setDateTime(int parameterIndex, java.sql.Timestamp x, boolean forceEncrypt) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Timestamp value. @@ -623,7 +624,7 @@ void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, int s * @throws SQLServerException * when an error occurs */ - void setSmallDateTime(int parameterIndex, java.sql.Timestamp x) throws SQLServerException; + public void setSmallDateTime(int parameterIndex, java.sql.Timestamp x) throws SQLServerException; /** * Sets the designated parameter to the given java.sql.Timestamp value. @@ -639,7 +640,8 @@ void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, int s * @throws SQLServerException * when an error occurs */ - void setSmallDateTime(int parameterIndex, java.sql.Timestamp x, boolean forceEncrypt) throws SQLServerException; + public void setSmallDateTime(int parameterIndex, java.sql.Timestamp x, + boolean forceEncrypt) throws SQLServerException; /** * Sets the data table to populates a table valued parameter. @@ -653,7 +655,8 @@ void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, int s * @throws SQLServerException * when an error occurs */ - void setStructured(int parameterIndex, String tvpName, SQLServerDataTable tvpDataTable) throws SQLServerException; + public void setStructured(int parameterIndex, String tvpName, + SQLServerDataTable tvpDataTable) throws SQLServerException; /** * Sets the result set to populate a table-valued parameter. @@ -667,7 +670,7 @@ void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, int s * @throws SQLServerException * when an error occurs */ - void setStructured(int parameterIndex, String tvpName, ResultSet tvpResultSet) throws SQLServerException; + public void setStructured(int parameterIndex, String tvpName, ResultSet tvpResultSet) throws SQLServerException; /** * Sets the server bulk record to populate a table valued parameter. @@ -681,7 +684,7 @@ void setDateTimeOffset(int parameterIndex, microsoft.sql.DateTimeOffset x, int s * @throws SQLServerException * when an error occurs */ - void setStructured(int parameterIndex, String tvpName, + public void setStructured(int parameterIndex, String tvpName, ISQLServerDataRecord tvpBulkRecord) throws SQLServerException; /** @@ -704,7 +707,7 @@ void setStructured(int parameterIndex, String tvpName, * @throws SQLServerException * when an error occurs */ - void setDate(int parameterIndex, java.sql.Date x, java.util.Calendar cal, + public void setDate(int parameterIndex, java.sql.Date x, java.util.Calendar cal, boolean forceEncrypt) throws SQLServerException; /** @@ -724,7 +727,7 @@ void setDate(int parameterIndex, java.sql.Date x, java.util.Calendar cal, * @throws SQLServerException * when an error occurs */ - void setTime(int parameterIndex, java.sql.Time x, java.util.Calendar cal, + public void setTime(int parameterIndex, java.sql.Time x, java.util.Calendar cal, boolean forceEncrypt) throws SQLServerException; /** @@ -744,7 +747,7 @@ void setTime(int parameterIndex, java.sql.Time x, java.util.Calendar cal, * @throws SQLServerException * when an error occurs */ - void setTimestamp(int parameterIndex, java.sql.Timestamp x, java.util.Calendar cal, + public void setTimestamp(int parameterIndex, java.sql.Timestamp x, java.util.Calendar cal, boolean forceEncrypt) throws SQLServerException; /** @@ -756,7 +759,7 @@ void setTimestamp(int parameterIndex, java.sql.Timestamp x, java.util.Calendar c * @throws SQLServerException * when an error occurs */ - ParameterMetaData getParameterMetaData(boolean forceRefresh) throws SQLServerException; + public ParameterMetaData getParameterMetaData(boolean forceRefresh) throws SQLServerException; /** * Returns the current flag value for useFmtOnly. diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSet.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSet.java index 068d3cb5f..2ac7bc1b5 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSet.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSet.java @@ -17,16 +17,16 @@ */ public interface ISQLServerResultSet extends java.sql.ResultSet { - int TYPE_SS_DIRECT_FORWARD_ONLY = 2003; // TYPE_FORWARD_ONLY + 1000 - int TYPE_SS_SERVER_CURSOR_FORWARD_ONLY = 2004; // TYPE_FORWARD_ONLY + 1001 - int TYPE_SS_SCROLL_STATIC = 1004; // TYPE_SCROLL_INSENSITIVE - int TYPE_SS_SCROLL_KEYSET = 1005; // TYPE_SCROLL_SENSITIVE - int TYPE_SS_SCROLL_DYNAMIC = 1006; // TYPE_SCROLL_SENSITIVE + 1 + public static final int TYPE_SS_DIRECT_FORWARD_ONLY = 2003; // TYPE_FORWARD_ONLY + 1000 + public static final int TYPE_SS_SERVER_CURSOR_FORWARD_ONLY = 2004; // TYPE_FORWARD_ONLY + 1001 + public static final int TYPE_SS_SCROLL_STATIC = 1004; // TYPE_SCROLL_INSENSITIVE + public static final int TYPE_SS_SCROLL_KEYSET = 1005; // TYPE_SCROLL_SENSITIVE + public static final int TYPE_SS_SCROLL_DYNAMIC = 1006; // TYPE_SCROLL_SENSITIVE + 1 /* SQL Server concurrency values */ - int CONCUR_SS_OPTIMISTIC_CC = 1008; // CONCUR_UPDATABLE - int CONCUR_SS_SCROLL_LOCKS = 1009; // CONCUR_UPDATABLE + 1 - int CONCUR_SS_OPTIMISTIC_CCVAL = 1010; // CONCUR_UPDATABLE + 2 + public static final int CONCUR_SS_OPTIMISTIC_CC = 1008; // CONCUR_UPDATABLE + public static final int CONCUR_SS_SCROLL_LOCKS = 1009; // CONCUR_UPDATABLE + 1 + public static final int CONCUR_SS_OPTIMISTIC_CCVAL = 1010; // CONCUR_UPDATABLE + 2 /** * Returns the value of the designated column in the current row of this ResultSet object as a @@ -38,7 +38,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - Geometry getGeometry(int columnIndex) throws SQLServerException; + public Geometry getGeometry(int columnIndex) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a @@ -50,7 +50,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - Geometry getGeometry(String columnName) throws SQLServerException; + public Geometry getGeometry(String columnName) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a @@ -62,7 +62,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - Geography getGeography(int columnIndex) throws SQLServerException; + public Geography getGeography(int columnIndex) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a @@ -74,7 +74,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - Geography getGeography(String columnName) throws SQLServerException; + public Geography getGeography(String columnName) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a String object in the @@ -86,7 +86,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - String getUniqueIdentifier(int columnIndex) throws SQLServerException; + public String getUniqueIdentifier(int columnIndex) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a String object in the @@ -98,7 +98,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - String getUniqueIdentifier(String columnLabel) throws SQLServerException; + public String getUniqueIdentifier(String columnLabel) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -110,7 +110,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - java.sql.Timestamp getDateTime(int columnIndex) throws SQLServerException; + public java.sql.Timestamp getDateTime(int columnIndex) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -122,7 +122,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * If any errors occur. */ - java.sql.Timestamp getDateTime(String columnName) throws SQLServerException; + public java.sql.Timestamp getDateTime(String columnName) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -137,7 +137,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * If any errors occur. */ - java.sql.Timestamp getDateTime(int columnIndex, Calendar cal) throws SQLServerException; + public java.sql.Timestamp getDateTime(int columnIndex, Calendar cal) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -153,7 +153,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * If any errors occur. */ - java.sql.Timestamp getDateTime(String colName, Calendar cal) throws SQLServerException; + public java.sql.Timestamp getDateTime(String colName, Calendar cal) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -165,7 +165,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - java.sql.Timestamp getSmallDateTime(int columnIndex) throws SQLServerException; + public java.sql.Timestamp getSmallDateTime(int columnIndex) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -177,7 +177,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * If any errors occur. */ - java.sql.Timestamp getSmallDateTime(String columnName) throws SQLServerException; + public java.sql.Timestamp getSmallDateTime(String columnName) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -191,7 +191,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * If any errors occur. */ - java.sql.Timestamp getSmallDateTime(int columnIndex, Calendar cal) throws SQLServerException; + public java.sql.Timestamp getSmallDateTime(int columnIndex, Calendar cal) throws SQLServerException; /** * Returns the value of the designated column in the current row of this ResultSet object as a java.sql.Timestamp @@ -205,7 +205,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * If any errors occur. */ - java.sql.Timestamp getSmallDateTime(String colName, Calendar cal) throws SQLServerException; + public java.sql.Timestamp getSmallDateTime(String colName, Calendar cal) throws SQLServerException; /** * Returns the value of the designated column as a microsoft.sql.DateTimeOffset object, given a zero-based column @@ -217,7 +217,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - microsoft.sql.DateTimeOffset getDateTimeOffset(int columnIndex) throws SQLServerException; + public microsoft.sql.DateTimeOffset getDateTimeOffset(int columnIndex) throws SQLServerException; /** * Returns the value of the column specified as a microsoft.sql.DateTimeOffset object, given a column name. @@ -228,7 +228,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - microsoft.sql.DateTimeOffset getDateTimeOffset(String columnName) throws SQLServerException; + public microsoft.sql.DateTimeOffset getDateTimeOffset(String columnName) throws SQLServerException; /** * Returns the value of the column specified as a java.math.BigDecimal object. @@ -239,7 +239,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - BigDecimal getMoney(int columnIndex) throws SQLServerException; + public BigDecimal getMoney(int columnIndex) throws SQLServerException; /** * Returns the value of the column specified as a java.math.BigDecimal object. @@ -250,7 +250,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * If any errors occur. */ - BigDecimal getMoney(String columnName) throws SQLServerException; + public BigDecimal getMoney(String columnName) throws SQLServerException; /** * Returns the value of the column specified as a java.math.BigDecimal object. @@ -261,7 +261,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * If any errors occur. */ - BigDecimal getSmallMoney(int columnIndex) throws SQLServerException; + public BigDecimal getSmallMoney(int columnIndex) throws SQLServerException; /** * Returns the value of the column specified as a java.math.BigDecimal object. @@ -272,7 +272,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * If any errors occur. */ - BigDecimal getSmallMoney(String columnName) throws SQLServerException; + public BigDecimal getSmallMoney(String columnName) throws SQLServerException; /** * Updates the value of the column specified to the DateTimeOffset Class value, given a zero-based column ordinal. @@ -284,7 +284,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x) throws SQLServerException; + public void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x) throws SQLServerException; /** * Updates the value of the column specified to the DateTimeOffset Class value, given a column name. @@ -296,7 +296,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x) throws SQLServerException; + public void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x) throws SQLServerException; /** * Updates the designated column with an {@code Object} value. @@ -316,7 +316,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * when an error occurs */ - void updateObject(int index, Object x, int precision, int scale) throws SQLServerException; + public void updateObject(int index, Object x, int precision, int scale) throws SQLServerException; /** * Updates the designated column with an Object value. The updater methods are used to update column values in the @@ -344,7 +344,7 @@ public interface ISQLServerResultSet extends java.sql.ResultSet { * @throws SQLServerException * If any errors occur. */ - void updateObject(int index, Object obj, SQLType targetSqlType, int scale, + public void updateObject(int index, Object obj, SQLType targetSqlType, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -375,7 +375,7 @@ void updateObject(int index, Object obj, SQLType targetSqlType, int scale, * @throws SQLServerException * If any errors occur. */ - void updateObject(String columnName, Object obj, SQLType targetSqlType, int scale, + public void updateObject(String columnName, Object obj, SQLType targetSqlType, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -394,7 +394,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateBoolean(int index, boolean x, boolean forceEncrypt) throws SQLServerException; + public void updateBoolean(int index, boolean x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a byte value. The updater methods are used to update column @@ -412,7 +412,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateByte(int index, byte x, boolean forceEncrypt) throws SQLServerException; + public void updateByte(int index, byte x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a short value. The updater methods are used to update column @@ -430,7 +430,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateShort(int index, short x, boolean forceEncrypt) throws SQLServerException; + public void updateShort(int index, short x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with an int value. The updater methods are used to update column @@ -448,7 +448,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateInt(int index, int x, boolean forceEncrypt) throws SQLServerException; + public void updateInt(int index, int x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a long value. The updater methods are used to update column @@ -466,7 +466,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateLong(int index, long x, boolean forceEncrypt) throws SQLServerException; + public void updateLong(int index, long x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a float value. The updater methods are used to update column @@ -484,7 +484,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateFloat(int index, float x, boolean forceEncrypt) throws SQLServerException; + public void updateFloat(int index, float x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a double value. The updater methods are used to update column @@ -502,7 +502,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateDouble(int index, double x, boolean forceEncrypt) throws SQLServerException; + public void updateDouble(int index, double x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a money value. The updater methods are used to update column @@ -516,7 +516,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateMoney(int index, BigDecimal x) throws SQLServerException; + public void updateMoney(int index, BigDecimal x) throws SQLServerException; /** * Updates the designated column with a money value. The updater methods are used to update column @@ -534,7 +534,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateMoney(int index, BigDecimal x, boolean forceEncrypt) throws SQLServerException; + public void updateMoney(int index, BigDecimal x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a money value. The updater methods are used to update column @@ -548,7 +548,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * If any errors occur. */ - void updateMoney(String columnName, BigDecimal x) throws SQLServerException; + public void updateMoney(String columnName, BigDecimal x) throws SQLServerException; /** * Updates the designated column with a money value. The updater methods are used to update column @@ -566,7 +566,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * If any errors occur. */ - void updateMoney(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException; + public void updateMoney(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a smallmoney value. The updater methods are used to update column @@ -580,7 +580,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateSmallMoney(int index, BigDecimal x) throws SQLServerException; + public void updateSmallMoney(int index, BigDecimal x) throws SQLServerException; /** * Updates the designated column with a smallmoney value. The updater methods are used to update column @@ -598,7 +598,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateSmallMoney(int index, BigDecimal x, boolean forceEncrypt) throws SQLServerException; + public void updateSmallMoney(int index, BigDecimal x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a smallmoney value. The updater methods are used to update column @@ -612,7 +612,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * If any errors occur. */ - void updateSmallMoney(String columnName, BigDecimal x) throws SQLServerException; + public void updateSmallMoney(String columnName, BigDecimal x) throws SQLServerException; /** * Updates the designated column with a smallmoney value. The updater methods are used to update column @@ -630,7 +630,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * If any errors occur. */ - void updateSmallMoney(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException; + public void updateSmallMoney(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a java.math.BigDecimal value. The updater methods are used to @@ -648,7 +648,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale) throws SQLServerException; + public void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale) throws SQLServerException; /** * Updates the designated column with a java.math.BigDecimal value. The updater methods are used to @@ -670,7 +670,7 @@ void updateObject(String columnName, Object obj, SQLType targetSqlType, int scal * @throws SQLServerException * when an error occurs */ - void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, + public void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, boolean forceEncrypt) throws SQLServerException; /** @@ -689,7 +689,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateString(int columnIndex, String stringValue, boolean forceEncrypt) throws SQLServerException; + public void updateString(int columnIndex, String stringValue, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a String value. It is intended for use when updating @@ -708,7 +708,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateNString(int columnIndex, String nString, boolean forceEncrypt) throws SQLServerException; + public void updateNString(int columnIndex, String nString, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a String value. It is intended for use when updating @@ -728,7 +728,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateNString(String columnLabel, String nString, boolean forceEncrypt) throws SQLServerException; + public void updateNString(String columnLabel, String nString, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a byte array value. The updater methods are used to update column @@ -746,7 +746,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateBytes(int index, byte x[], boolean forceEncrypt) throws SQLServerException; + public void updateBytes(int index, byte x[], boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a java.sql.Date value. The updater methods are used to update @@ -764,7 +764,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateDate(int index, java.sql.Date x, boolean forceEncrypt) throws SQLServerException; + public void updateDate(int index, java.sql.Date x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a java.sql.Time value. The updater methods are used to update @@ -780,7 +780,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateTime(int index, java.sql.Time x, Integer scale) throws SQLServerException; + public void updateTime(int index, java.sql.Time x, Integer scale) throws SQLServerException; /** * Updates the designated column with a java.sql.Time value. The updater methods are used to update @@ -800,7 +800,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateTime(int index, java.sql.Time x, Integer scale, boolean forceEncrypt) throws SQLServerException; + public void updateTime(int index, java.sql.Time x, Integer scale, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -816,7 +816,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateTimestamp(int index, java.sql.Timestamp x, int scale) throws SQLServerException; + public void updateTimestamp(int index, java.sql.Timestamp x, int scale) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -836,7 +836,8 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateTimestamp(int index, java.sql.Timestamp x, int scale, boolean forceEncrypt) throws SQLServerException; + public void updateTimestamp(int index, java.sql.Timestamp x, int scale, + boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -850,7 +851,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateDateTime(int index, java.sql.Timestamp x) throws SQLServerException; + public void updateDateTime(int index, java.sql.Timestamp x) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -866,7 +867,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateDateTime(int index, java.sql.Timestamp x, Integer scale) throws SQLServerException; + public void updateDateTime(int index, java.sql.Timestamp x, Integer scale) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -886,7 +887,8 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateDateTime(int index, java.sql.Timestamp x, Integer scale, boolean forceEncrypt) throws SQLServerException; + public void updateDateTime(int index, java.sql.Timestamp x, Integer scale, + boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -900,7 +902,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateSmallDateTime(int index, java.sql.Timestamp x) throws SQLServerException; + public void updateSmallDateTime(int index, java.sql.Timestamp x) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -916,7 +918,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateSmallDateTime(int index, java.sql.Timestamp x, Integer scale) throws SQLServerException; + public void updateSmallDateTime(int index, java.sql.Timestamp x, Integer scale) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -936,7 +938,7 @@ void updateBigDecimal(int index, BigDecimal x, Integer precision, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateSmallDateTime(int index, java.sql.Timestamp x, Integer scale, + public void updateSmallDateTime(int index, java.sql.Timestamp x, Integer scale, boolean forceEncrypt) throws SQLServerException; /** @@ -951,7 +953,8 @@ void updateSmallDateTime(int index, java.sql.Timestamp x, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer scale) throws SQLServerException; + public void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, + Integer scale) throws SQLServerException; /** * Updates the value of the column specified to the DateTimeOffset Class value, given a zero-based column ordinal. @@ -969,7 +972,7 @@ void updateSmallDateTime(int index, java.sql.Timestamp x, Integer scale, * @throws SQLServerException * when an error occurs */ - void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer scale, + public void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer scale, boolean forceEncrypt) throws SQLServerException; /** @@ -984,7 +987,7 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * when an error occurs */ - void updateUniqueIdentifier(int index, String x) throws SQLServerException; + public void updateUniqueIdentifier(int index, String x) throws SQLServerException; /** * Updates the designated column with a String value. The updater methods are used to update column @@ -1002,7 +1005,7 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * when an error occurs */ - void updateUniqueIdentifier(int index, String x, boolean forceEncrypt) throws SQLServerException; + public void updateUniqueIdentifier(int index, String x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with an {@code Object} value. @@ -1026,7 +1029,8 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * when an error occurs */ - void updateObject(int index, Object x, int precision, int scale, boolean forceEncrypt) throws SQLServerException; + public void updateObject(int index, Object x, int precision, int scale, + boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a boolean value. The updater methods are used to update column @@ -1044,7 +1048,7 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * when an error occurs */ - void updateBoolean(String columnName, boolean x, boolean forceEncrypt) throws SQLServerException; + public void updateBoolean(String columnName, boolean x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a byte value. The updater methods are used to update column @@ -1063,7 +1067,7 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * If any errors occur. */ - void updateByte(String columnName, byte x, boolean forceEncrypt) throws SQLServerException; + public void updateByte(String columnName, byte x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a short value. The updater methods are used to update column @@ -1081,7 +1085,7 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * If any errors occur. */ - void updateShort(String columnName, short x, boolean forceEncrypt) throws SQLServerException; + public void updateShort(String columnName, short x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with an int value. The updater methods are used to update column @@ -1099,7 +1103,7 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * If any errors occur. */ - void updateInt(String columnName, int x, boolean forceEncrypt) throws SQLServerException; + public void updateInt(String columnName, int x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a long value. The updater methods are used to update column @@ -1117,7 +1121,7 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * If any errors occur. */ - void updateLong(String columnName, long x, boolean forceEncrypt) throws SQLServerException; + public void updateLong(String columnName, long x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a float value. The updater methods are used to update column @@ -1135,7 +1139,7 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * If any errors occur. */ - void updateFloat(String columnName, float x, boolean forceEncrypt) throws SQLServerException; + public void updateFloat(String columnName, float x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a double value. The updater methods are used to update column @@ -1153,7 +1157,7 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * If any errors occur. */ - void updateDouble(String columnName, double x, boolean forceEncrypt) throws SQLServerException; + public void updateDouble(String columnName, double x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a java.sql.BigDecimal value. The updater methods are used to @@ -1171,7 +1175,7 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * If any errors occur. */ - void updateBigDecimal(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException; + public void updateBigDecimal(String columnName, BigDecimal x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a java.sql.BigDecimal value. The updater methods are used to @@ -1190,7 +1194,8 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * If any errors occur. */ - void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Integer scale) throws SQLServerException; + public void updateBigDecimal(String columnName, BigDecimal x, Integer precision, + Integer scale) throws SQLServerException; /** * Updates the designated column with a java.sql.BigDecimal value. The updater methods are used to @@ -1213,7 +1218,7 @@ void updateDateTimeOffset(int index, microsoft.sql.DateTimeOffset x, Integer sca * @throws SQLServerException * If any errors occur. */ - void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Integer scale, + public void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Integer scale, boolean forceEncrypt) throws SQLServerException; /** @@ -1232,7 +1237,7 @@ void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Intege * @throws SQLServerException * If any errors occur. */ - void updateString(String columnName, String x, boolean forceEncrypt) throws SQLServerException; + public void updateString(String columnName, String x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a byte array value. @@ -1252,7 +1257,7 @@ void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Intege * @throws SQLServerException * If any errors occur. */ - void updateBytes(String columnName, byte x[], boolean forceEncrypt) throws SQLServerException; + public void updateBytes(String columnName, byte x[], boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a java.sql.Date value. The updater methods are used to update @@ -1270,7 +1275,7 @@ void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Intege * @throws SQLServerException * If any errors occur. */ - void updateDate(String columnName, java.sql.Date x, boolean forceEncrypt) throws SQLServerException; + public void updateDate(String columnName, java.sql.Date x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a java.sql.Time value. The updater methods are used to update @@ -1286,7 +1291,7 @@ void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Intege * @throws SQLServerException * If any errors occur. */ - void updateTime(String columnName, java.sql.Time x, int scale) throws SQLServerException; + public void updateTime(String columnName, java.sql.Time x, int scale) throws SQLServerException; /** * Updates the designated column with a java.sql.Time value. The updater methods are used to update @@ -1306,7 +1311,8 @@ void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Intege * @throws SQLServerException * If any errors occur. */ - void updateTime(String columnName, java.sql.Time x, int scale, boolean forceEncrypt) throws SQLServerException; + public void updateTime(String columnName, java.sql.Time x, int scale, + boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -1322,7 +1328,7 @@ void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Intege * @throws SQLServerException * If any errors occur. */ - void updateTimestamp(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException; + public void updateTimestamp(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -1342,7 +1348,7 @@ void updateBigDecimal(String columnName, BigDecimal x, Integer precision, Intege * @throws SQLServerException * If any errors occur. */ - void updateTimestamp(String columnName, java.sql.Timestamp x, int scale, + public void updateTimestamp(String columnName, java.sql.Timestamp x, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -1357,7 +1363,7 @@ void updateTimestamp(String columnName, java.sql.Timestamp x, int scale, * @throws SQLServerException * If any errors occur. */ - void updateDateTime(String columnName, java.sql.Timestamp x) throws SQLServerException; + public void updateDateTime(String columnName, java.sql.Timestamp x) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -1373,7 +1379,7 @@ void updateTimestamp(String columnName, java.sql.Timestamp x, int scale, * @throws SQLServerException * If any errors occur. */ - void updateDateTime(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException; + public void updateDateTime(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -1393,7 +1399,7 @@ void updateTimestamp(String columnName, java.sql.Timestamp x, int scale, * @throws SQLServerException * If any errors occur. */ - void updateDateTime(String columnName, java.sql.Timestamp x, int scale, + public void updateDateTime(String columnName, java.sql.Timestamp x, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -1408,7 +1414,7 @@ void updateDateTime(String columnName, java.sql.Timestamp x, int scale, * @throws SQLServerException * If any errors occur. */ - void updateSmallDateTime(String columnName, java.sql.Timestamp x) throws SQLServerException; + public void updateSmallDateTime(String columnName, java.sql.Timestamp x) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -1424,7 +1430,7 @@ void updateDateTime(String columnName, java.sql.Timestamp x, int scale, * @throws SQLServerException * If any errors occur. */ - void updateSmallDateTime(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException; + public void updateSmallDateTime(String columnName, java.sql.Timestamp x, int scale) throws SQLServerException; /** * Updates the designated column with a java.sql.Timestamp value. The updater methods are used to @@ -1444,7 +1450,7 @@ void updateDateTime(String columnName, java.sql.Timestamp x, int scale, * @throws SQLServerException * If any errors occur. */ - void updateSmallDateTime(String columnName, java.sql.Timestamp x, int scale, + public void updateSmallDateTime(String columnName, java.sql.Timestamp x, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -1459,7 +1465,8 @@ void updateSmallDateTime(String columnName, java.sql.Timestamp x, int scale, * @throws SQLServerException * If any errors occur. */ - void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x, int scale) throws SQLServerException; + public void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x, + int scale) throws SQLServerException; /** * Updates the value of the column specified to the DateTimeOffset Class value, given a column name. @@ -1477,7 +1484,7 @@ void updateSmallDateTime(String columnName, java.sql.Timestamp x, int scale, * @throws SQLServerException * If any errors occur. */ - void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x, int scale, + public void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -1492,7 +1499,7 @@ void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x, int * @throws SQLServerException * If any errors occur. */ - void updateUniqueIdentifier(String columnName, String x) throws SQLServerException; + public void updateUniqueIdentifier(String columnName, String x) throws SQLServerException; /** * Updates the designated column with a Stringvalue. The updater methods are used to update column @@ -1510,7 +1517,7 @@ void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x, int * @throws SQLServerException * If any errors occur. */ - void updateUniqueIdentifier(String columnName, String x, boolean forceEncrypt) throws SQLServerException; + public void updateUniqueIdentifier(String columnName, String x, boolean forceEncrypt) throws SQLServerException; /** * Updates the designated column with an {@code Object} value. @@ -1530,7 +1537,7 @@ void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x, int * @throws SQLServerException * If any errors occur. */ - void updateObject(String columnName, Object x, int precision, int scale) throws SQLServerException; + public void updateObject(String columnName, Object x, int precision, int scale) throws SQLServerException; /** * Updates the designated column with an {@code Object} value. @@ -1554,7 +1561,7 @@ void updateDateTimeOffset(String columnName, microsoft.sql.DateTimeOffset x, int * @throws SQLServerException * If any errors occur. */ - void updateObject(String columnName, Object x, int precision, int scale, + public void updateObject(String columnName, Object x, int precision, int scale, boolean forceEncrypt) throws SQLServerException; /** @@ -1563,5 +1570,5 @@ void updateObject(String columnName, Object x, int precision, int scale, * * @return SensitivityClassification */ - SensitivityClassification getSensitivityClassification(); + public SensitivityClassification getSensitivityClassification(); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSetMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSetMetaData.java index 0db7fbb08..6f6366469 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSetMetaData.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerResultSetMetaData.java @@ -23,6 +23,6 @@ public interface ISQLServerResultSetMetaData extends ResultSetMetaData, Serializ * @throws SQLServerException * when an error occurs */ - boolean isSparseColumnSet(int column) throws SQLServerException; + public boolean isSparseColumnSet(int column) throws SQLServerException; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerSavepoint.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerSavepoint.java index f9cd9313e..a988a0204 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerSavepoint.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerSavepoint.java @@ -19,20 +19,20 @@ public interface ISQLServerSavepoint extends Savepoint, Serializable { * * @return the name of savepoint */ - String getSavepointName() throws SQLServerException; + public String getSavepointName() throws SQLServerException; /** * Returns the savepoint label * * @return the label for Savepoint */ - String getLabel(); + public String getLabel(); /** * Returns if the savepoint label is null * * @return true is the savepoint is named. Otherwise, false. */ - boolean isNamed(); + public boolean isNamed(); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerStatement.java index fbc078f37..49ddd7a83 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/ISQLServerStatement.java @@ -28,7 +28,7 @@ public interface ISQLServerStatement extends java.sql.Statement, Serializable { * @throws SQLServerException * If there are any errors in setting the response buffering mode. */ - void setResponseBuffering(String value) throws SQLServerException; + public void setResponseBuffering(String value) throws SQLServerException; /** * Returns the response buffering mode for this SQLServerStatement object. @@ -37,7 +37,7 @@ public interface ISQLServerStatement extends java.sql.Statement, Serializable { * @throws SQLServerException * If there are any errors in retrieving the response buffering mode. */ - String getResponseBuffering() throws SQLServerException; + public String getResponseBuffering() throws SQLServerException; /** * Returns the cancelQueryTimeout property set on this SQLServerStatement object. @@ -46,7 +46,7 @@ public interface ISQLServerStatement extends java.sql.Statement, Serializable { * @throws SQLServerException * if any error occurs */ - int getCancelQueryTimeout() throws SQLServerException; + public int getCancelQueryTimeout() throws SQLServerException; /** * Sets the cancelQueryTimeout property on this SQLServerStatement object to cancel @@ -57,5 +57,5 @@ public interface ISQLServerStatement extends java.sql.Statement, Serializable { * @throws SQLServerException * if any error occurs */ - void setCancelQueryTimeout(int seconds) throws SQLServerException; + public void setCancelQueryTimeout(int seconds) throws SQLServerException; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KeyStoreProviderCommon.java b/src/main/java/com/microsoft/sqlserver/jdbc/KeyStoreProviderCommon.java index d3f0fa9be..32e02dc57 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/KeyStoreProviderCommon.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/KeyStoreProviderCommon.java @@ -139,7 +139,7 @@ private static byte[] decryptRSAOAEP(byte[] cipherText, } - static boolean verifyRSASignature(byte[] hash, byte[] signature, X509Certificate certificate, + private static boolean verifyRSASignature(byte[] hash, byte[] signature, X509Certificate certificate, String masterKeyPath) throws SQLServerException { Signature signVerify; boolean verificationSuccess = false; diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLJdbcVersion.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLJdbcVersion.java index e90e6ff62..e41ebd7f1 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLJdbcVersion.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLJdbcVersion.java @@ -6,8 +6,8 @@ package com.microsoft.sqlserver.jdbc; final class SQLJdbcVersion { - static final int major = 8; - static final int minor = 1; - static final int patch = 0; + static final int major = 7; + static final int minor = 4; + static final int patch = 1; static final int build = 0; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java index 4192d5013..7214164a8 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java @@ -145,7 +145,7 @@ private class ColumnMapping implements Serializable { /** * Source data (from a Record). Is null unless the corresponding version of writeToServer is called. */ - private ISQLServerBulkData serverBulkData; + private ISQLServerBulkRecord sourceBulkRecord; /** * Source data (from ResultSet). Is null unless the corresponding version of writeToServer is called. @@ -583,7 +583,7 @@ private void writeResultSet(ResultSet sourceData, boolean isRowSet) throws SQLSe sourceResultSet = sourceData; - serverBulkData = null; + sourceBulkRecord = null; // Save the resultset metadata as it is used in many places. try { @@ -602,18 +602,18 @@ private void writeResultSet(ResultSet sourceData, boolean isRowSet) throws SQLSe * destinationTableName property of the SQLServerBulkCopy object. * * @param sourceData - * ISQLServerBulkData to read data rows from. + * SQLServerBulkReader to read data rows from. * @throws SQLServerException * If there are any issues encountered when performing the bulk copy operation */ - public void writeToServer(ISQLServerBulkData sourceData) throws SQLServerException { + public void writeToServer(ISQLServerBulkRecord sourceData) throws SQLServerException { loggerExternal.entering(loggerClassName, "writeToServer"); if (null == sourceData) { throwInvalidArgument("sourceData"); } - serverBulkData = sourceData; + sourceBulkRecord = sourceData; sourceResultSet = null; writeToServer(); @@ -627,7 +627,7 @@ public void writeToServer(ISQLServerBulkData sourceData) throws SQLServerExcepti private void initializeDefaults() { columnMappings = new ArrayList<>(); destinationTableName = null; - serverBulkData = null; + sourceBulkRecord = null; sourceResultSet = null; sourceResultSetMetaData = null; srcColumnCount = 0; @@ -1001,7 +1001,7 @@ private void writeTypeInfo(TDSWriter tdsWriter, int srcJdbcType, int srcScale, i case microsoft.sql.Types.DATETIME: case microsoft.sql.Types.SMALLDATETIME: case java.sql.Types.TIMESTAMP: - if ((!isBaseType) && (null != serverBulkData)) { + if ((!isBaseType) && (null != sourceBulkRecord)) { tdsWriter.writeByte(TDSType.BIGVARCHAR.byteValue()); tdsWriter.writeShort((short) (srcPrecision)); collation.writeCollation(tdsWriter); @@ -1039,7 +1039,7 @@ private void writeTypeInfo(TDSWriter tdsWriter, int srcJdbcType, int srcScale, i * unencrypted. string literal formats supported by temporal types are available in MSDN page on data * types. */ - if ((!isBaseType) && (null != serverBulkData)) { + if ((!isBaseType) && (null != sourceBulkRecord)) { tdsWriter.writeByte(TDSType.BIGVARCHAR.byteValue()); tdsWriter.writeShort((short) (srcPrecision)); collation.writeCollation(tdsWriter); @@ -1049,7 +1049,7 @@ private void writeTypeInfo(TDSWriter tdsWriter, int srcJdbcType, int srcScale, i break; case java.sql.Types.TIME: // 0x29 - if ((!isBaseType) && (null != serverBulkData)) { + if ((!isBaseType) && (null != sourceBulkRecord)) { tdsWriter.writeByte(TDSType.BIGVARCHAR.byteValue()); tdsWriter.writeShort((short) (srcPrecision)); collation.writeCollation(tdsWriter); @@ -1067,7 +1067,7 @@ private void writeTypeInfo(TDSWriter tdsWriter, int srcJdbcType, int srcScale, i break; case microsoft.sql.Types.DATETIMEOFFSET: // 0x2B - if ((!isBaseType) && (null != serverBulkData)) { + if ((!isBaseType) && (null != sourceBulkRecord)) { tdsWriter.writeByte(TDSType.BIGVARCHAR.byteValue()); tdsWriter.writeShort((short) (srcPrecision)); collation.writeCollation(tdsWriter); @@ -1314,7 +1314,7 @@ private String getDestTypeFromSrcType(int srcColIndx, int destColIndx, case java.sql.Types.TIMESTAMP: switch (destSSType) { case SMALLDATETIME: - if (null != serverBulkData) { + if (null != sourceBulkRecord) { return "varchar(" + ((0 == bulkPrecision) ? sourceBulkRecordTemporalMaxPrecision : bulkPrecision) + ")"; @@ -1322,7 +1322,7 @@ private String getDestTypeFromSrcType(int srcColIndx, int destColIndx, return "smalldatetime"; } case DATETIME: - if (null != serverBulkData) { + if (null != sourceBulkRecord) { return "varchar(" + ((0 == bulkPrecision) ? sourceBulkRecordTemporalMaxPrecision : bulkPrecision) + ")"; @@ -1337,7 +1337,7 @@ private String getDestTypeFromSrcType(int srcColIndx, int destColIndx, * will do the conversion. if the source is ResultSet, we send the data as the corresponding * temporal type. */ - if (null != serverBulkData) { + if (null != sourceBulkRecord) { return "varchar(" + ((0 == bulkPrecision) ? destPrecision : bulkPrecision) + ")"; } else { return "datetime2(" + bulkScale + ")"; @@ -1350,7 +1350,7 @@ private String getDestTypeFromSrcType(int srcColIndx, int destColIndx, * unencrypted bulk copy if the source is CSV, we send the data as varchar and SQL Server will do the * conversion. if the source is ResultSet, we send the data as the corresponding temporal type. */ - if (null != serverBulkData) { + if (null != sourceBulkRecord) { return "varchar(" + ((0 == bulkPrecision) ? destPrecision : bulkPrecision) + ")"; } else { return "date"; @@ -1362,7 +1362,7 @@ private String getDestTypeFromSrcType(int srcColIndx, int destColIndx, * unencrypted bulk copy if the source is CSV, we send the data as varchar and SQL Server will do the * conversion. if the source is ResultSet, we send the data as the corresponding temporal type. */ - if (null != serverBulkData) { + if (null != sourceBulkRecord) { return "varchar(" + ((0 == bulkPrecision) ? destPrecision : bulkPrecision) + ")"; } else { return "time(" + bulkScale + ")"; @@ -1379,7 +1379,7 @@ private String getDestTypeFromSrcType(int srcColIndx, int destColIndx, * unencrypted bulk copy if the source is CSV, we send the data as varchar and SQL Server will do the * conversion. if the source is ResultSet, we send the data as the corresponding temporal type. */ - if (null != serverBulkData) { + if (null != sourceBulkRecord) { return "varchar(" + ((0 == bulkPrecision) ? destPrecision : bulkPrecision) + ")"; } else { return "datetimeoffset(" + bulkScale + ")"; @@ -1544,14 +1544,13 @@ private TDSWriter sendBulkCopyCommand(TDSCommand command) throws SQLServerExcept // Create and send the initial command for bulk copy ("INSERT BULK ..."). TDSWriter tdsWriter = command.startRequest(TDS.PKT_QUERY); String bulkCmd = createInsertBulkCommand(tdsWriter); - tdsWriter.sendEnclavePackage(null, null); tdsWriter.writeString(bulkCmd); TDSParser.parse(command.startResponse(), command.getLogContext()); // Send the bulk data. This is the BulkLoadBCP TDS stream. tdsWriter = command.startRequest(TDS.PKT_BULK); - // Write the COLUMNMETADATA token in the stream. + // Write the COLUMNMETADATA token in the stream. writeColumnMetaData(tdsWriter); return tdsWriter; @@ -1721,8 +1720,8 @@ private void getSourceMetadata() throws SQLServerException { // Unable to retrieve meta data for destination throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveColMeta"), e); } - } else if (null != serverBulkData) { - Set columnOrdinals = serverBulkData.getColumnOrdinals(); + } else if (null != sourceBulkRecord) { + Set columnOrdinals = sourceBulkRecord.getColumnOrdinals(); if (null == columnOrdinals || 0 == columnOrdinals.size()) { throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveColMeta"), null); } else { @@ -1730,10 +1729,10 @@ private void getSourceMetadata() throws SQLServerException { for (Integer columnOrdinal : columnOrdinals) { currentColumn = columnOrdinal; srcColumnMetadata.put(currentColumn, new BulkColumnMetaData( - serverBulkData.getColumnName(currentColumn), true, - serverBulkData.getPrecision(currentColumn), serverBulkData.getScale(currentColumn), - serverBulkData.getColumnType(currentColumn), - ((serverBulkData instanceof SQLServerBulkCSVFileRecord) ? ((SQLServerBulkCSVFileRecord) serverBulkData) + sourceBulkRecord.getColumnName(currentColumn), true, + sourceBulkRecord.getPrecision(currentColumn), sourceBulkRecord.getScale(currentColumn), + sourceBulkRecord.getColumnType(currentColumn), + ((sourceBulkRecord instanceof SQLServerBulkCSVFileRecord) ? ((SQLServerBulkCSVFileRecord) sourceBulkRecord) .getColumnDateTimeFormatter(currentColumn) : null))); } } @@ -1780,8 +1779,8 @@ private void validateColumnMappings() throws SQLServerException { } } // if no mapping is provided for csv file and metadata is missing for some columns throw error - if (null != serverBulkData) { - Set columnOrdinals = serverBulkData.getColumnOrdinals(); + if (null != sourceBulkRecord) { + Set columnOrdinals = sourceBulkRecord.getColumnOrdinals(); Iterator columnsIterator = columnOrdinals.iterator(); int j = 1; while (columnsIterator.hasNext()) { @@ -1848,9 +1847,9 @@ private void validateColumnMappings() throws SQLServerException { } } } else { - Set columnOrdinals = serverBulkData.getColumnOrdinals(); + Set columnOrdinals = sourceBulkRecord.getColumnOrdinals(); for (Integer currentColumn : columnOrdinals) { - if (serverBulkData.getColumnName(currentColumn).equals(cm.sourceColumnName)) { + if (sourceBulkRecord.getColumnName(currentColumn).equals(cm.sourceColumnName)) { foundColumn = true; cm.sourceColumnOrdinal = currentColumn; break; @@ -1986,7 +1985,7 @@ private void writeColumnToTdsWriter(TDSWriter tdsWriter, int bulkPrecision, int else if (null != sourceCryptoMeta) { bulkJdbcType = destColumnMetadata.get(destColOrdinal).jdbcType; bulkScale = destColumnMetadata.get(destColOrdinal).scale; - } else if (null != serverBulkData) { + } else if (null != sourceBulkRecord) { // Bulk copy from CSV and destination is not encrypted. In this case, we send the temporal types as varchar // and // SQL Server does the conversion. If destination is encrypted, then temporal types can not be sent as @@ -2075,7 +2074,7 @@ else if (null != sourceCryptoMeta) { tdsWriter.writeDouble((float) colValue); } break; - + case java.sql.Types.DOUBLE: if (null == colValue) { writeNullToTdsWriter(tdsWriter, bulkJdbcType, isStreaming); @@ -2862,9 +2861,9 @@ private void writeColumn(TDSWriter tdsWriter, int srcColOrdinal, int destColOrdi } // If we are using ISQLBulkRecord and the data we are passing is char type, we need to check the source and dest // precision - else if (null != serverBulkData && (null == destCryptoMeta)) { + else if (null != sourceBulkRecord && (null == destCryptoMeta)) { validateStringBinaryLengths(colValue, srcColOrdinal, destColOrdinal); - } else if ((null != serverBulkData) && (null != destCryptoMeta)) { + } else if ((null != sourceBulkRecord) && (null != destCryptoMeta)) { // From CSV to encrypted column. Convert to respective object. if ((java.sql.Types.DATE == srcJdbcType) || (java.sql.Types.TIME == srcJdbcType) || (java.sql.Types.TIMESTAMP == srcJdbcType) || (microsoft.sql.Types.DATETIMEOFFSET == srcJdbcType) @@ -3363,7 +3362,7 @@ private byte[] normalizedValue(JDBCType destJdbcType, Object value, JDBCType src Float floatValue = (value instanceof String) ? Float.parseFloat((String) value) : (Float) value; return ByteBuffer.allocate((Float.SIZE / Byte.SIZE)).order(ByteOrder.LITTLE_ENDIAN) .putFloat(floatValue).array(); - + case FLOAT: case DOUBLE: Double doubleValue = (value instanceof String) ? Double.parseDouble((String) value) @@ -3437,7 +3436,7 @@ private boolean goToNextRow() throws SQLServerException { if (null != sourceResultSet) { return sourceResultSet.next(); } else { - return serverBulkData.next(); + return sourceBulkRecord.next(); } } catch (SQLException e) { throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), e); @@ -3494,7 +3493,7 @@ private boolean writeBatchData(TDSWriter tdsWriter, TDSCommand command, Object[] rowObjects; try { - rowObjects = serverBulkData.getRowData(); + rowObjects = sourceBulkRecord.getRowData(); } catch (Exception ex) { // if no more data available to retrive throw new SQLServerException(SQLServerException.getErrString("R_unableRetrieveSourceData"), ex); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCallableStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCallableStatement.java index cf22b6a43..76eabac63 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCallableStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCallableStatement.java @@ -24,9 +24,8 @@ import java.sql.Time; import java.sql.Timestamp; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.Calendar; -import java.util.HashMap; -import java.util.TreeMap; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -50,8 +49,7 @@ public class SQLServerCallableStatement extends SQLServerPreparedStatement imple private static final long serialVersionUID = 5044984771674532350L; /** the call param names */ - private HashMap parameterNames; - private TreeMap insensitiveParameterNames; + private ArrayList parameterNames; /** Number of registered OUT parameters */ int nOutParams = 0; @@ -704,7 +702,7 @@ public Object getObject(int index) throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "getObject", index); checkClosed(); Object value = getValue(index, - null != getterGetParam(index).getJdbcTypeSetByUser() ? getterGetParam(index).getJdbcTypeSetByUser() + getterGetParam(index).getJdbcTypeSetByUser() != null ? getterGetParam(index).getJdbcTypeSetByUser() : getterGetParam(index).getJdbcType()); loggerExternal.exiting(getClassNameLogging(), "getObject", value); return value; @@ -745,7 +743,7 @@ public T getObject(int index, Class type) throws SQLException { } else if (type == UUID.class) { // read binary, avoid string allocation and parsing byte[] guid = getBytes(index); - returnValue = null != guid ? Util.readGUIDtoUUID(guid) : null; + returnValue = guid != null ? Util.readGUIDtoUUID(guid) : null; } else if (type == SQLXML.class) { returnValue = getSQLXML(index); } else if (type == Blob.class) { @@ -780,7 +778,7 @@ public Object getObject(String parameterName) throws SQLServerException { checkClosed(); int parameterIndex = findColumn(parameterName); Object value = getValue(parameterIndex, - null != getterGetParam(parameterIndex).getJdbcTypeSetByUser() ? getterGetParam(parameterIndex) + getterGetParam(parameterIndex).getJdbcTypeSetByUser() != null ? getterGetParam(parameterIndex) .getJdbcTypeSetByUser() : getterGetParam(parameterIndex).getJdbcType()); loggerExternal.exiting(getClassNameLogging(), "getObject", value); return value; @@ -1255,7 +1253,7 @@ public java.sql.Array getArray(String parameterName) throws SQLException { * @return the index */ private int findColumn(String columnName) throws SQLServerException { - if (null == parameterNames) { + if (parameterNames == null) { try (SQLServerStatement s = (SQLServerStatement) connection.createStatement()) { // Note we are concatenating the information from the passed in sql, not any arguments provided by the // user @@ -1279,7 +1277,7 @@ private int findColumn(String columnName) throws SQLServerException { // we should always have a procedure name part metaQuery.append("@procedure_name="); metaQuery.append(threePartName.getProcedurePart()); - metaQuery.append(" , @ODBCVer=3, @fUsePattern=0"); + metaQuery.append(" , @ODBCVer=3"); } else { // This should rarely happen, this will only happen if we can't find the stored procedure name // invalidly formatted call syntax. @@ -1289,15 +1287,11 @@ private int findColumn(String columnName) throws SQLServerException { SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), "07009", false); } - try (ResultSet rs = s.executeQueryInternal(metaQuery.toString())) { - parameterNames = new HashMap<>(); - insensitiveParameterNames = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - int columnIndex = 0; - while (rs.next()) { - String p = rs.getString(4).trim(); - parameterNames.put(p, columnIndex); - insensitiveParameterNames.put(p, columnIndex++); - } + ResultSet rs = s.executeQueryInternal(metaQuery.toString()); + parameterNames = new ArrayList<>(); + while (rs.next()) { + String parameterName = rs.getString(4); + parameterNames.add(parameterName.trim()); } } catch (SQLException e) { SQLServerException.makeFromDriverError(connection, this, e.toString(), null, false); @@ -1316,7 +1310,12 @@ private int findColumn(String columnName) throws SQLServerException { // handle `@name` as well as `name`, since `@name` is what's returned // by DatabaseMetaData#getProcedureColumns - String columnNameWithSign = columnName.startsWith("@") ? columnName : "@" + columnName; + String columnNameWithoutAtSign = null; + if (columnName.startsWith("@")) { + columnNameWithoutAtSign = columnName.substring(1, columnName.length()); + } else { + columnNameWithoutAtSign = columnName; + } // In order to be as accurate as possible when locating parameter name // indexes, as well as be deterministic when running on various client @@ -1324,11 +1323,34 @@ private int findColumn(String columnName) throws SQLServerException { // 1. Search using case-sensitive non-locale specific (binary) compare first. // 2. Search using case-insensitive, non-locale specific (binary) compare last. - Integer matchPos = parameterNames.get(columnNameWithSign); - if (null == matchPos) { - matchPos = insensitiveParameterNames.get(columnNameWithSign); + + int i; + int matchPos = -1; + // Search using case-sensitive, non-locale specific (binary) compare. + // If the user supplies a true match for the parameter name, we will find it here. + for (i = 0; i < l; i++) { + String sParam = parameterNames.get(i); + sParam = sParam.substring(1, sParam.length()); + if (sParam.equals(columnNameWithoutAtSign)) { + matchPos = i; + break; + } } - if (null == matchPos) { + + if (-1 == matchPos) { + // Check for case-insensitive match using a non-locale aware method. + // Use VM supplied String.equalsIgnoreCase to do the "case-insensitive search". + for (i = 0; i < l; i++) { + String sParam = parameterNames.get(i); + sParam = sParam.substring(1, sParam.length()); + if (sParam.equalsIgnoreCase(columnNameWithoutAtSign)) { + matchPos = i; + break; + } + } + } + + if (-1 == matchPos) { MessageFormat form = new MessageFormat( SQLServerException.getErrString("R_parameterNotDefinedForProcedure")); Object[] msgArgs = {columnName, procedureName}; diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java index 2e21f69fb..5b3e25eab 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionAzureKeyVaultProvider.java @@ -50,14 +50,7 @@ public class SQLServerColumnEncryptionAzureKeyVaultProvider extends SQLServerCol private final String baseUrl = "https://{vaultBaseUrl}"; - /** - * List of Azure trusted endpoints https://docs.microsoft.com/en-us/azure/key-vault/key-vault-secure-your-key-vault - */ - private final String azureTrustedEndpoints[] = {"vault.azure.net", // default - "vault.azure.cn", // Azure China - "vault.usgovcloudapi.net", // US Government - "vault.microsoftazure.de" // Azure Germany - }; + private final String azureKeyVaultDomainName = "vault.azure.net"; private final String rsaEncryptionAlgorithmWithOAEPForAKV = "RSA-OAEP"; @@ -448,27 +441,20 @@ private void ValidateNonEmptyAKVPath(String masterKeyPath) throws SQLServerExcep URI parsedUri = null; try { parsedUri = new URI(masterKeyPath); - - // A valid URI. - // Check if it is pointing to a trusted endpoint. - String host = parsedUri.getHost(); - if (null != host) { - host = host.toLowerCase(Locale.ENGLISH); - } - for (final String endpoint : azureTrustedEndpoints) { - if (null != host && host.endsWith(endpoint)) { - return; - } - } } catch (URISyntaxException e) { MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVURLInvalid")); Object[] msgArgs = {masterKeyPath}; throw new SQLServerException(form.format(msgArgs), null, 0, e); } - MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVMasterKeyPathInvalid")); - Object[] msgArgs = {masterKeyPath}; - throw new SQLServerException(null, form.format(msgArgs), null, 0, false); + // A valid URI. + // Check if it is pointing to AKV. + if (!parsedUri.getHost().toLowerCase(Locale.ENGLISH).endsWith(azureKeyVaultDomainName)) { + // Return an error indicating that the AKV url is invalid. + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVMasterKeyPathInvalid")); + Object[] msgArgs = {masterKeyPath}; + throw new SQLServerException(null, form.format(msgArgs), null, 0, false); + } } } @@ -595,37 +581,4 @@ private int getAKVKeySize(String masterKeyPath) throws SQLServerException { return retrievedKey.key().n().length; } - - @Override - public boolean verifyColumnMasterKeyMetadata(String masterKeyPath, boolean allowEnclaveComputations, - byte[] signature) throws SQLServerException { - if (!allowEnclaveComputations) - return false; - - KeyStoreProviderCommon.validateNonEmptyMasterKeyPath(masterKeyPath); - - try { - MessageDigest md = MessageDigest.getInstance("SHA-256"); - md.update(name.toLowerCase().getBytes(java.nio.charset.StandardCharsets.UTF_16LE)); - md.update(masterKeyPath.toLowerCase().getBytes(java.nio.charset.StandardCharsets.UTF_16LE)); - // value of allowEnclaveComputations is always true here - md.update("true".getBytes(java.nio.charset.StandardCharsets.UTF_16LE)); - - byte[] dataToVerify = md.digest(); - if (null == dataToVerify) { - throw new SQLServerException(SQLServerException.getErrString("R_HashNull"), null); - } - - // Sign the hash - byte[] signedHash = AzureKeyVaultSignHashedData(dataToVerify, masterKeyPath); - if (null == signedHash) { - throw new SQLServerException(SQLServerException.getErrString("R_SignedHashLengthError"), null); - } - - // Validate the signature - return AzureKeyVaultVerifySignature(dataToVerify, signature, masterKeyPath); - } catch (NoSuchAlgorithmException e) { - throw new SQLServerException(SQLServerException.getErrString("R_NoSHA256Algorithm"), e); - } - } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionCertificateStoreProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionCertificateStoreProvider.java index f4f6cd458..7733e6db2 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionCertificateStoreProvider.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionCertificateStoreProvider.java @@ -81,15 +81,4 @@ public byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryption "decryptColumnEncryptionKey", "Finished decrypting Column Encryption Key."); return plainCek; } - - @Override - public boolean verifyColumnMasterKeyMetadata(String masterKeyPath, boolean allowEnclaveComputations, - byte[] signature) throws SQLServerException { - try { - return AuthenticationJNI.VerifyColumnMasterKeyMetadata(masterKeyPath, allowEnclaveComputations, signature); - } catch (DLLException e) { - DLLException.buildException(e.GetErrCode(), e.GetParam1(), e.GetParam2(), e.GetParam3()); - return false; - } - } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionJavaKeyStoreProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionJavaKeyStoreProvider.java index 2ffc5125d..41d012b65 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionJavaKeyStoreProvider.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionJavaKeyStoreProvider.java @@ -16,7 +16,6 @@ import java.security.Key; import java.security.KeyStore; import java.security.KeyStoreException; -import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.Signature; @@ -304,6 +303,7 @@ private byte[] rsaSignHashedData(byte[] dataToSign, MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_EncryptionFailed")); Object[] msgArgs = {e.getMessage()}; throw new SQLServerException(this, form.format(msgArgs), null, 0, false); + } return signedHash; @@ -314,52 +314,7 @@ private byte[] getLittleEndianBytesFromShort(short value) { byteBuffer.order(ByteOrder.LITTLE_ENDIAN); byte[] byteValue = byteBuffer.putShort(value).array(); return byteValue; - } - - /* - * Verify signature against certificate - */ - private boolean rsaVerifySignature(byte[] dataToVerify, byte[] signature, - CertificateDetails certificateDetails) throws SQLServerException { - try { - Signature sig = Signature.getInstance("SHA256withRSA"); - sig.initSign((PrivateKey) certificateDetails.privateKey); - sig.update(dataToVerify); - byte[] signedHash = sig.sign(); - - sig.initVerify(certificateDetails.certificate.getPublicKey()); - sig.update(dataToVerify); - - return sig.verify(signedHash); - - } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException e) { - MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_VerifySignatureFailed")); - Object[] msgArgs = {e.getMessage()}; - throw new SQLServerException(this, form.format(msgArgs), null, 0, false); - } - } - - @Override - public boolean verifyColumnMasterKeyMetadata(String masterKeyPath, boolean allowEnclaveComputations, - byte[] signature) throws SQLServerException { - - if (!allowEnclaveComputations) - return false; - KeyStoreProviderCommon.validateNonEmptyMasterKeyPath(masterKeyPath); - CertificateDetails certificateDetails = getCertificateDetails(masterKeyPath); - - try { - MessageDigest md = MessageDigest.getInstance("SHA-256"); - md.update(name.toLowerCase().getBytes(java.nio.charset.StandardCharsets.UTF_16LE)); - md.update(masterKeyPath.toLowerCase().getBytes(java.nio.charset.StandardCharsets.UTF_16LE)); - // value of allowEnclaveComputations is always true here - md.update("true".getBytes(java.nio.charset.StandardCharsets.UTF_16LE)); - return rsaVerifySignature(md.digest(), signature, certificateDetails); - - } catch (NoSuchAlgorithmException e) { - throw new SQLServerException(SQLServerException.getErrString("R_NoSHA256Algorithm"), e); - } } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionKeyStoreProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionKeyStoreProvider.java index 6a11025a8..6fd8b845f 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionKeyStoreProvider.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerColumnEncryptionKeyStoreProvider.java @@ -62,19 +62,4 @@ public abstract byte[] decryptColumnEncryptionKey(String masterKeyPath, String e public abstract byte[] encryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm, byte[] columnEncryptionKey) throws SQLServerException; - /** - * Verify the signature is valid for the column master key - * - * @param masterKeyPath - * column master key path - * @param allowEnclaveComputations - * indicates whether the column master key supports enclave computations - * @param signature - * signature of the column master key metadata - * @return - * whether the signature is valid for the column master key - * @throws SQLServerException - * when an error occurs while verifying the signature - */ - public abstract boolean verifyColumnMasterKeyMetadata (String masterKeyPath, boolean allowEnclaveComputations, byte[] signature) throws SQLServerException; } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java index 04366fa27..2cfe72ca0 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java @@ -125,8 +125,6 @@ public class SQLServerConnection implements ISQLServerConnection, java.io.Serial private ConcurrentLinkedQueue discardedPreparedStatementHandles = new ConcurrentLinkedQueue<>(); private AtomicInteger discardedPreparedStatementHandleCount = new AtomicInteger(0); - private SQLServerColumnEncryptionKeyStoreProvider keystoreProvider = null; - private boolean fedAuthRequiredByUser = false; private boolean fedAuthRequiredPreLoginResponse = false; private boolean federatedAuthenticationRequested = false; @@ -629,23 +627,14 @@ boolean isColumnEncryptionSettingEnabled() { return (columnEncryptionSetting.equalsIgnoreCase(ColumnEncryptionSetting.Enabled.toString())); } - String enclaveAttestationUrl = null; - String enclaveAttestationProtocol = null; - String keyStoreAuthentication = null; String keyStoreSecret = null; String keyStoreLocation = null; - private ColumnEncryptionVersion serverColumnEncryptionVersion = ColumnEncryptionVersion.AE_NotSupported; - - private String enclaveType = null; + private boolean serverSupportsColumnEncryption = false; boolean getServerSupportsColumnEncryption() { - return (serverColumnEncryptionVersion.value() > ColumnEncryptionVersion.AE_NotSupported.value()); - } - - ColumnEncryptionVersion getServerColumnEncryptionVersion() { - return serverColumnEncryptionVersion; + return serverSupportsColumnEncryption; } private boolean serverSupportsDataClassification = false; @@ -716,13 +705,13 @@ public static synchronized void registerColumnEncryptionKeyStoreProviders( + globalCustomColumnEncryptionKeyStoreProviders.size()); } - synchronized SQLServerColumnEncryptionKeyStoreProvider getGlobalSystemColumnEncryptionKeyStoreProvider( + static synchronized SQLServerColumnEncryptionKeyStoreProvider getGlobalSystemColumnEncryptionKeyStoreProvider( String providerName) { return (null != globalSystemColumnEncryptionKeyStoreProviders && globalSystemColumnEncryptionKeyStoreProviders .containsKey(providerName)) ? globalSystemColumnEncryptionKeyStoreProviders.get(providerName) : null; } - synchronized String getAllGlobalCustomSystemColumnEncryptionKeyStoreProviders() { + static synchronized String getAllGlobalCustomSystemColumnEncryptionKeyStoreProviders() { return (null != globalCustomColumnEncryptionKeyStoreProviders) ? globalCustomColumnEncryptionKeyStoreProviders .keySet().toString() : null; } @@ -736,7 +725,7 @@ synchronized String getAllSystemColumnEncryptionKeyStoreProviders() { return keyStores; } - synchronized SQLServerColumnEncryptionKeyStoreProvider getGlobalCustomColumnEncryptionKeyStoreProvider( + static synchronized SQLServerColumnEncryptionKeyStoreProvider getGlobalCustomColumnEncryptionKeyStoreProvider( String providerName) { return (null != globalCustomColumnEncryptionKeyStoreProviders && globalCustomColumnEncryptionKeyStoreProviders .containsKey(providerName)) ? globalCustomColumnEncryptionKeyStoreProviders.get(providerName) : null; @@ -748,35 +737,6 @@ synchronized SQLServerColumnEncryptionKeyStoreProvider getSystemColumnEncryption .containsKey(providerName)) ? systemColumnEncryptionKeyStoreProvider.get(providerName) : null; } - synchronized SQLServerColumnEncryptionKeyStoreProvider getColumnEncryptionKeyStoreProvider( - String providerName) throws SQLServerException { - - // Check for the connection provider first. - keystoreProvider = getSystemColumnEncryptionKeyStoreProvider(providerName); - - // There is no connection provider of this name, check for the global system providers. - if (null == keystoreProvider) { - keystoreProvider = getGlobalSystemColumnEncryptionKeyStoreProvider(providerName); - } - - // There is no global system provider of this name, check for the global custom providers. - if (null == keystoreProvider) { - keystoreProvider = getGlobalCustomColumnEncryptionKeyStoreProvider(providerName); - } - - // No provider was found of this name. - if (null == keystoreProvider) { - String systemProviders = getAllSystemColumnEncryptionKeyStoreProviders(); - String customProviders = getAllGlobalCustomSystemColumnEncryptionKeyStoreProviders(); - MessageFormat form = new MessageFormat( - SQLServerException.getErrString("R_UnrecognizedKeyStoreProviderName")); - Object[] msgArgs = {providerName, systemProviders, customProviders}; - throw new SQLServerException(form.format(msgArgs), null); - } - - return keystoreProvider; - } - private String trustedServerNameAE = null; private static Map> columnEncryptionTrustedMasterKeyPaths = new HashMap<>(); @@ -1462,38 +1422,6 @@ Connection connectInternal(Properties propsIn, } columnEncryptionSetting = ColumnEncryptionSetting.valueOfString(sPropValue).toString(); - sPropKey = SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_URL.toString(); - sPropValue = activeConnectionProperties.getProperty(sPropKey); - if (null != sPropValue) { - enclaveAttestationUrl = sPropValue; - } - - sPropKey = SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_PROTOCOL.toString(); - sPropValue = activeConnectionProperties.getProperty(sPropKey); - if (null != sPropValue) { - enclaveAttestationProtocol = sPropValue; - if (!AttestationProtocol.isValidAttestationProtocol(enclaveAttestationProtocol)) { - if (connectionlogger.isLoggable(Level.SEVERE)) { - connectionlogger.severe(toString() + " " - + SQLServerException.getErrString("R_enclaveInvalidAttestationProtocol")); - } - throw new SQLServerException(SQLServerException.getErrString("R_enclaveInvalidAttestationProtocol"), - null); - } - } - - // both enclaveAttestationUrl must be enclaveAttestationProtocol specified - if ((null != enclaveAttestationUrl && !enclaveAttestationUrl.isEmpty() - && (null == enclaveAttestationProtocol || enclaveAttestationProtocol.isEmpty())) - || (null != enclaveAttestationProtocol && !enclaveAttestationProtocol.isEmpty() - && (null == enclaveAttestationUrl || enclaveAttestationUrl.isEmpty()))) { - if (connectionlogger.isLoggable(Level.SEVERE)) { - connectionlogger.severe( - toString() + " " + SQLServerException.getErrString("R_enclaveNoAttestationProtocol")); - } - throw new SQLServerException(SQLServerException.getErrString("R_enclaveNoAttestationProtocol"), null); - } - sPropKey = SQLServerDriverStringProperty.KEY_STORE_AUTHENTICATION.toString(); sPropValue = activeConnectionProperties.getProperty(sPropKey); if (null != sPropValue) { @@ -3087,13 +3015,12 @@ final class ConnectionCommand extends UninterruptableTDSCommand { } final boolean doExecute() throws SQLServerException { - TDSWriter tdsWriter = startRequest(TDS.PKT_QUERY); - tdsWriter.sendEnclavePackage(null, null); - tdsWriter.writeString(sql); + startRequest(TDS.PKT_QUERY).writeString(sql); TDSParser.parse(startResponse(), getLogContext()); return true; } } + executeCommand(new ConnectionCommand(sql, logContext)); } @@ -3613,13 +3540,9 @@ int writeAEFeatureRequest(boolean write, /* if false just calculates the length int len = 6; // (1byte = featureID, 4bytes = featureData length, 1 bytes = Version) if (write) { - tdsWriter.writeByte(TDS.TDS_FEATURE_EXT_AE); // FEATUREEXT_TC - tdsWriter.writeInt(1); // length of version - if (null == enclaveAttestationUrl || enclaveAttestationUrl.isEmpty()) { - tdsWriter.writeByte(TDS.COLUMNENCRYPTION_VERSION1); - } else { - tdsWriter.writeByte(TDS.COLUMNENCRYPTION_VERSION2); - } + tdsWriter.writeByte(TDS.TDS_FEATURE_EXT_AE); // FEATUREEXT_TCE + tdsWriter.writeInt(1); + tdsWriter.writeByte(TDS.MAX_SUPPORTED_TCE_VERSION); } return len; } @@ -4630,29 +4553,13 @@ private void onFeatureExtAck(byte featureId, byte[] data) throws SQLServerExcept throw new SQLServerException(SQLServerException.getErrString("R_InvalidAEVersionNumber"), null); } - aeVersion = data[0]; - if (TDS.COLUMNENCRYPTION_NOT_SUPPORTED == aeVersion || aeVersion > TDS.COLUMNENCRYPTION_VERSION2) { + byte supportedTceVersion = data[0]; + if (0 == supportedTceVersion || supportedTceVersion > TDS.MAX_SUPPORTED_TCE_VERSION) { throw new SQLServerException(SQLServerException.getErrString("R_InvalidAEVersionNumber"), null); } - serverColumnEncryptionVersion = ColumnEncryptionVersion.AE_v1; - - if (null != enclaveAttestationUrl) { - if (aeVersion < TDS.COLUMNENCRYPTION_VERSION2) { - throw new SQLServerException(SQLServerException.getErrString("R_enclaveNotSupported"), null); - } else { - serverColumnEncryptionVersion = ColumnEncryptionVersion.AE_v2; - enclaveType = new String(data, 2, data.length - 2, UTF_16LE); - } - - if (!EnclaveType.isValidEnclaveType(enclaveType)) { - MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_enclaveTypeInvalid")); - Object[] msgArgs = {enclaveType}; - throw new SQLServerException(null, form.format(msgArgs), null, 0, false); - } - } + serverSupportsColumnEncryption = true; break; - } case TDS.TDS_FEATURE_EXT_DATACLASSIFICATION: { if (connectionlogger.isLoggable(Level.FINER)) { @@ -4712,7 +4619,6 @@ final class DTCCommand extends UninterruptableTDSCommand { final boolean doExecute() throws SQLServerException { TDSWriter tdsWriter = startRequest(TDS.PKT_DTC); - tdsWriter.sendEnclavePackage(null, null); tdsWriter.writeShort((short) requestType); if (null == payload) { @@ -5774,8 +5680,6 @@ public T unwrap(Class iface) throws SQLException { private List openStatements; private boolean originalUseFmtOnly; - int aeVersion = TDS.COLUMNENCRYPTION_NOT_SUPPORTED; - protected void beginRequestInternal() throws SQLException { loggerExternal.entering(getClassNameLogging(), "beginRequest", this); synchronized (this) { @@ -6226,8 +6130,7 @@ final void unprepareUnreferencedPreparedStatementHandles(boolean force) { try { // Execute the batched set. - try (SQLServerStatement stmt = (SQLServerStatement) this.createStatement()) { - stmt.isInternalEncryptionQuery = true; + try (Statement stmt = this.createStatement()) { stmt.execute(sql.toString()); } @@ -6466,28 +6369,6 @@ final synchronized void removeOpenStatement(ISQLServerStatement st) { openStatements.remove(st); } } - - boolean isAEv2() { - return (aeVersion >= TDS.COLUMNENCRYPTION_VERSION2); - } - - ISQLServerEnclaveProvider enclaveProvider = new SQLServerVSMEnclaveProvider(); - - ArrayList initEnclaveParameters(String userSql, String preparedTypeDefinitions, Parameter[] params, - ArrayList parameterNames) throws SQLServerException { - if (!this.enclaveEstablished()) { - enclaveProvider.getAttestationParameters(false, this.enclaveAttestationUrl); - } - return enclaveProvider.createEnclaveSession(this, userSql, preparedTypeDefinitions, params, parameterNames); - } - - boolean enclaveEstablished() { - return (null != enclaveProvider.getEnclaveSession()); - } - - byte[] generateEncalvePackage(String userSQL, ArrayList enclaveCEKs) throws SQLServerException { - return (enclaveCEKs.size() > 0) ? enclaveProvider.getEnclavePackage(userSQL, enclaveCEKs) : null; - } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataColumn.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataColumn.java index 1cb840b3c..218f58dbb 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataColumn.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataColumn.java @@ -45,35 +45,4 @@ public String getColumnName() { public int getColumnType() { return javaSqlType; } - - @Override - public int hashCode() { - int hash = 7; - hash = 31 * hash + javaSqlType; - hash = 31 * hash + precision; - hash = 31 * hash + scale; - hash = 31 * hash + numberOfDigitsIntegerPart; - hash = 31 * hash + (null != columnName ? columnName.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - - if (null != object && object.getClass() == SQLServerDataColumn.class) { - SQLServerDataColumn aSQLServerDataColumn = (SQLServerDataColumn) object; - if (hashCode() == aSQLServerDataColumn.hashCode()) { - // Compare objects to avoid collision - return ((null == columnName && null == aSQLServerDataColumn.columnName - || columnName.equals(aSQLServerDataColumn.columnName)) - && javaSqlType == aSQLServerDataColumn.javaSqlType - && numberOfDigitsIntegerPart == aSQLServerDataColumn.numberOfDigitsIntegerPart - && precision == aSQLServerDataColumn.precision && scale == aSQLServerDataColumn.scale); - } - } - return false; - } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java index 75397e02f..64c523fd7 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java @@ -358,10 +358,6 @@ public void setTrustStorePassword(String trustStorePassword) { trustStorePassword); } - String getTrustStorePassword() { - return getStringProperty(connectionProps, SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString(), null); - } - @Override public void setHostNameInCertificate(String hostName) { setStringProperty(connectionProps, SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(), hostName); @@ -482,10 +478,11 @@ public boolean getSendTimeAsDatetime() { return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.toString(), SQLServerDriverBooleanProperty.SEND_TIME_AS_DATETIME.getDefaultValue()); } - + @Override public void setUseFmtOnly(boolean useFmtOnly) { - setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.USE_FMT_ONLY.toString(), useFmtOnly); + setBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.USE_FMT_ONLY.toString(), + useFmtOnly); } @Override @@ -493,7 +490,7 @@ public boolean getUseFmtOnly() { return getBooleanProperty(connectionProps, SQLServerDriverBooleanProperty.USE_FMT_ONLY.toString(), SQLServerDriverBooleanProperty.USE_FMT_ONLY.getDefaultValue()); } - + /** * Sets whether string parameters are sent to the server in UNICODE format. * @@ -910,38 +907,15 @@ public void setKeyVaultProviderClientKey(String keyVaultProviderClientKey) { keyVaultProviderClientKey); } - @Override - public String getDomain() { - return getStringProperty(connectionProps, SQLServerDriverStringProperty.DOMAIN.toString(), - SQLServerDriverStringProperty.DOMAIN.getDefaultValue()); - } - @Override public void setDomain(String domain) { setStringProperty(connectionProps, SQLServerDriverStringProperty.DOMAIN.toString(), domain); } @Override - public String getEnclaveAttestationUrl() { - return getStringProperty(connectionProps, SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_URL.toString(), - SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_URL.getDefaultValue()); - } - - @Override - public void setEnclaveAttestationUrl(String url) { - setStringProperty(connectionProps, SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_URL.toString(), url); - } - - @Override - public String getEnclaveAttestationProtocol() { - return getStringProperty(connectionProps, SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_PROTOCOL.toString(), - SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_PROTOCOL.getDefaultValue()); - } - - @Override - public void setEnclaveAttestationProtocol(String protocol) { - setStringProperty(connectionProps, SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_PROTOCOL.toString(), - protocol); + public String getDomain() { + return getStringProperty(connectionProps, SQLServerDriverStringProperty.DOMAIN.toString(), + SQLServerDriverStringProperty.DOMAIN.getDefaultValue()); } /** diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataTable.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataTable.java index 9f718d400..8d59c0463 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataTable.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataTable.java @@ -9,7 +9,6 @@ import java.text.MessageFormat; import java.time.OffsetDateTime; import java.time.OffsetTime; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -335,79 +334,4 @@ public String getTvpName() { public void setTvpName(String tvpName) { this.tvpName = tvpName; } - - @Override - public int hashCode() { - int hash = 7; - hash = 31 * hash + rowCount; - hash = 31 * hash + columnCount; - hash = 31 * hash + (null != columnMetadata ? columnMetadata.hashCode() : 0); - hash = 31 * hash + (null != columnNames ? columnNames.hashCode() : 0); - hash = 31 * hash + getRowsHashCode(); - hash = 31 * hash + (null != tvpName ? tvpName.hashCode() : 0); - return hash; - } - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - - if (null != object && object.getClass() == SQLServerDataTable.class) { - SQLServerDataTable aSQLServerDataTable = (SQLServerDataTable) object; - if (hashCode() == aSQLServerDataTable.hashCode()) { - - // Compare objects to avoid collision - boolean equalColumnMetadata = columnMetadata.equals(aSQLServerDataTable.columnMetadata); - boolean equalColumnNames = columnNames.equals(aSQLServerDataTable.columnNames); - boolean equalRowData = compareRows(aSQLServerDataTable.rows); - - return (rowCount == aSQLServerDataTable.rowCount && columnCount == aSQLServerDataTable.columnCount - && tvpName == aSQLServerDataTable.tvpName && equalColumnMetadata && equalColumnNames - && equalRowData); - } - } - return false; - } - - private int getRowsHashCode() { - if (null == rows) { - return 0; - } - int h = 0; - for (Entry entry : rows.entrySet()) { - h += entry.getKey() ^ Arrays.hashCode(entry.getValue()); - } - return h; - } - - private boolean compareRows(Map otherRows) { - if (rows == otherRows) { - return true; - } - if (rows.size() != otherRows.size()) { - return false; - } - try { - for (Entry e : rows.entrySet()) { - Integer key = e.getKey(); - Object[] value = e.getValue(); - if (null == value) { - if (!(null == otherRows.get(key) && otherRows.containsKey(key))) { - return false; - } - } else { - if (!Arrays.equals(value, otherRows.get(key))) { - return false; - } - } - } - } catch (ClassCastException unused) { - return false; - } catch (NullPointerException unused) { - return false; - } - return true; - } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java index 65880bdd2..36b254422 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDatabaseMetaData.java @@ -638,10 +638,10 @@ public java.sql.ResultSet getColumns(String catalog, String schema, String table PreparedStatement pstmt = (SQLServerPreparedStatement) this.connection.prepareStatement(spColumnsSql); pstmt.closeOnCompletion(); try { - pstmt.setString(1, (null != table && !table.isEmpty()) ? EscapeIDName(table) : "%"); - pstmt.setString(2, (null != schema && !schema.isEmpty()) ? EscapeIDName(schema) : "%"); + pstmt.setString(1, (null != table && !table.isEmpty()) ? table : "%"); + pstmt.setString(2, (null != schema && !schema.isEmpty()) ? schema : "%"); pstmt.setString(3, (null != catalog && !catalog.isEmpty()) ? catalog : this.connection.getCatalog()); - pstmt.setString(4, (null != col && !col.isEmpty()) ? EscapeIDName(col) : "%"); + pstmt.setString(4, (null != col && !col.isEmpty()) ? col : "%"); pstmt.setInt(5, 2);// show sparse columns pstmt.setInt(6, 3);// odbc version @@ -677,11 +677,11 @@ public java.sql.ResultSet getColumns(String catalog, String schema, String table */ try (PreparedStatement storedProcPstmt = this.connection .prepareStatement("EXEC sp_columns_100 ?,?,?,?,?,?;")) { - storedProcPstmt.setString(1, (null != table && !table.isEmpty()) ? EscapeIDName(table) : "%"); - storedProcPstmt.setString(2, (null != schema && !schema.isEmpty()) ? EscapeIDName(schema) : "%"); + storedProcPstmt.setString(1, (null != table && !table.isEmpty()) ? table : "%"); + storedProcPstmt.setString(2, (null != schema && !schema.isEmpty()) ? schema : "%"); storedProcPstmt.setString(3, (null != catalog && !catalog.isEmpty()) ? catalog : this.connection.getCatalog()); - storedProcPstmt.setString(4, (null != col && !col.isEmpty()) ? EscapeIDName(col) : "%"); + storedProcPstmt.setString(4, (null != col && !col.isEmpty()) ? col : "%"); storedProcPstmt.setInt(5, 2);// show sparse columns storedProcPstmt.setInt(6, 3);// odbc version @@ -1011,7 +1011,7 @@ private ResultSet executeSPFkeys(String[] procParams) throws SQLException, SQLTi "END as UPDATE_RULE, " + "CASE s.delete_referential_action " + "WHEN 1 THEN 0 " + "WHEN 0 THEN 3 " + "WHEN 2 THEN 2 " + "WHEN 3 THEN 4 " + "END as DELETE_RULE, " + "t.FK_NAME, " + "t.PK_NAME, " + "t.DEFERRABILITY " + "FROM " + tempTableName + " t " - + "LEFT JOIN sys.foreign_keys s ON t.FK_NAME = s.name COLLATE database_default AND schema_id(t.FKTABLE_OWNER) = s.schema_id"; + + "LEFT JOIN sys.foreign_keys s ON t.FK_NAME = s.name collate database_default;"; SQLServerCallableStatement cstmt = (SQLServerCallableStatement) connection.prepareCall(sql); cstmt.closeOnCompletion(); for (int i = 0; i < 6; i++) { @@ -1212,7 +1212,7 @@ public int getMaxUserNameLength() throws SQLServerException { @Override public String getNumericFunctions() throws SQLServerException { checkClosed(); - return "ABS,ACOS,ASIN,ATAN,ATAN2,CEILING,COS,COT,DEGREES,EXP,FLOOR,LOG,LOG10,MOD,PI,POWER,RADIANS,RAND,ROUND,SIGN,SIN,SQRT,TAN,TRUNCATE"; + return "ABS,ACOS,ASIN,ATAN,ATAN2,CEILING,COS,COT,DEGREES,EXP, FLOOR,LOG,LOG10,MOD,PI,POWER,RADIANS,RAND,ROUND,SIGN,SIN,SQRT,TAN,TRUNCATE"; } private static final String[] getPrimaryKeysColumnNames = { /* 1 */ TABLE_CAT, /* 2 */ TABLE_SCHEM, @@ -1470,7 +1470,7 @@ private static String createSqlKeyWords() { @Override public String getStringFunctions() throws SQLServerException { checkClosed(); - return "ASCII,CHAR,CONCAT,DIFFERENCE,INSERT,LCASE,LEFT,LENGTH,LOCATE,LTRIM,REPEAT,REPLACE,RIGHT,RTRIM,SOUNDEX,SPACE,SUBSTRING,UCASE"; + return "ASCII,CHAR,CONCAT, DIFFERENCE,INSERT,LCASE,LEFT,LENGTH,LOCATE,LTRIM,REPEAT,REPLACE,RIGHT,RTRIM,SOUNDEX,SPACE,SUBSTRING,UCASE"; } @Override diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java index 4e30fa3f9..b3fd86735 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDriver.java @@ -113,46 +113,6 @@ static ColumnEncryptionSetting valueOfString(String value) throws SQLServerExcep } -enum AttestationProtocol { - HGS("HGS"); // only protocol supported currently - - private final String protocol; - - AttestationProtocol(String protocol) { - this.protocol = protocol; - } - - static boolean isValidAttestationProtocol(String protocol) { - for (AttestationProtocol p : AttestationProtocol.values()) { - if (protocol.equalsIgnoreCase(p.toString())) { - return true; - } - } - return false; - } -} - - -enum EnclaveType { - VBS("VBS"); // only VBS type supported - - private final String type; - - EnclaveType(String type) { - this.type = type; - } - - static boolean isValidEnclaveType(String type) { - for (EnclaveType t : EnclaveType.values()) { - if (type.equalsIgnoreCase(t.toString())) { - return true; - } - } - return false; - } -} - - enum SSLProtocol { TLS("TLS"), TLS_V10("TLSv1"), @@ -277,7 +237,6 @@ static ApplicationIntent valueOfString(String value) throws SQLServerException { enum SQLServerDriverObjectProperty { GSS_CREDENTIAL("gsscredential", null); - private final String name; private final String defaultValue; @@ -327,8 +286,6 @@ enum SQLServerDriverStringProperty { AUTHENTICATION("authentication", SqlAuthentication.NotSpecified.toString()), ACCESS_TOKEN("accessToken", ""), COLUMN_ENCRYPTION("columnEncryptionSetting", ColumnEncryptionSetting.Disabled.toString()), - ENCLAVE_ATTESTATION_URL("enclaveAttestationUrl", ""), - ENCLAVE_ATTESTATION_PROTOCOL("enclaveAttestationProtocol", ""), KEY_STORE_AUTHENTICATION("keyStoreAuthentication", ""), KEY_STORE_SECRET("keyStoreSecret", ""), KEY_STORE_LOCATION("keyStoreLocation", ""), @@ -443,10 +400,6 @@ public final class SQLServerDriver implements java.sql.Driver { SQLServerDriverStringProperty.COLUMN_ENCRYPTION.getDefaultValue(), false, new String[] {ColumnEncryptionSetting.Disabled.toString(), ColumnEncryptionSetting.Enabled.toString()}), - new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_URL.toString(), - SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_URL.getDefaultValue(), false, null), - new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_PROTOCOL.toString(), - SQLServerDriverStringProperty.ENCLAVE_ATTESTATION_PROTOCOL.getDefaultValue(), false, null), new SQLServerDriverPropertyInfo(SQLServerDriverStringProperty.DATABASE_NAME.toString(), SQLServerDriverStringProperty.DATABASE_NAME.getDefaultValue(), false, null), new SQLServerDriverPropertyInfo(SQLServerDriverBooleanProperty.DISABLE_STATEMENT_POOLING.toString(), diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerKeyVaultAuthenticationCallback.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerKeyVaultAuthenticationCallback.java index c7ac13f5c..daa475b99 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerKeyVaultAuthenticationCallback.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerKeyVaultAuthenticationCallback.java @@ -22,5 +22,5 @@ public interface SQLServerKeyVaultAuthenticationCallback { * - The scope of the authentication request. * @return access token */ - String getAccessToken(String authority, String resource, String scope); + public String getAccessToken(String authority, String resource, String scope); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java index 555221ffa..876495f44 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerParameterMetaData.java @@ -289,8 +289,8 @@ private void checkClosed() throws SQLServerException { try (SQLServerStatement s = (SQLServerStatement) con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); SQLServerResultSet rsProcedureMeta = s.executeQueryInternal( - con.isKatmaiOrLater() ? "exec sp_sproc_columns_100 " + sProc + ", @ODBCVer=3, @fUsePattern=0" - : "exec sp_sproc_columns " + sProc + ", @ODBCVer=3, @fUsePattern=0")) { + con.isKatmaiOrLater() ? "exec sp_sproc_columns_100 " + sProc + ", @ODBCVer=3" + : "exec sp_sproc_columns " + sProc + ", @ODBCVer=3")) { // if rsProcedureMeta has next row, it means the stored procedure is found if (rsProcedureMeta.next()) { diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java index c9d0f90e7..dba2b644f 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerPreparedStatement.java @@ -52,6 +52,9 @@ public class SQLServerPreparedStatement extends SQLServerStatement implements IS */ private static final long serialVersionUID = -6292257029445685221L; + /** Flag to indicate that it is an internal query to retrieve encryption metadata. */ + boolean isInternalEncryptionQuery = false; + /** delimiter for multiple statements in a single batch */ @SuppressWarnings("unused") private static final int BATCH_STATEMENT_DELIMITER_TDS_71 = 0x80; @@ -289,7 +292,6 @@ final boolean doExecute() throws SQLServerException { executedSqlDirectly ? TDS.PROCID_SP_UNPREPARE : TDS.PROCID_SP_CURSORUNPREPARE); tdsWriter.writeByte((byte) 0); // RPC procedure option 1 tdsWriter.writeByte((byte) 0); // RPC procedure option 2 - tdsWriter.sendEnclavePackage(null, null); tdsWriter.writeRPCInt(null, handleToClose, false); TDSParser.parse(startResponse(), getLogContext()); return true; @@ -554,14 +556,6 @@ final void doExecutePreparedStatement(PrepStmtExecCmd command) throws SQLServerE hasNewTypeDefinitions = buildPreparedStrings(inOutParam, false); } - if (connection.isAEv2() && !isInternalEncryptionQuery) { - this.enclaveCEKs = connection.initEnclaveParameters(preparedSQL, preparedTypeDefinitions, inOutParam, - parameterNames); - encryptionMetadataIsRetrieved = true; - setMaxRowsAndMaxFieldSize(); - hasNewTypeDefinitions = buildPreparedStrings(inOutParam, true); - } - if ((Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection)) && (0 < inOutParam.length) && !isInternalEncryptionQuery) { @@ -570,7 +564,7 @@ final void doExecutePreparedStatement(PrepStmtExecCmd command) throws SQLServerE getParameterEncryptionMetadata(inOutParam); encryptionMetadataIsRetrieved = true; - // maxRows is set to 0 when retrieving encryption metadata, + // maxRows is set to 0 when retreving encryption metadata, // need to set it back setMaxRowsAndMaxFieldSize(); } @@ -710,7 +704,6 @@ private void buildServerCursorPrepExecParams(TDSWriter tdsWriter) throws SQLServ tdsWriter.writeShort(TDS.PROCID_SP_CURSORPREPEXEC); tdsWriter.writeByte((byte) 0); // RPC procedure option 1 tdsWriter.writeByte((byte) 0); // RPC procedure option 2 - tdsWriter.sendEnclavePackage(preparedSQL, enclaveCEKs); // // IN (reprepare): Old handle to unprepare before repreparing @@ -754,7 +747,6 @@ private void buildPrepExecParams(TDSWriter tdsWriter) throws SQLServerException tdsWriter.writeShort(TDS.PROCID_SP_PREPEXEC); tdsWriter.writeByte((byte) 0); // RPC procedure option 1 tdsWriter.writeByte((byte) 0); // RPC procedure option 2 - tdsWriter.sendEnclavePackage(preparedSQL, enclaveCEKs); // // IN (reprepare): Old handle to unprepare before repreparing @@ -782,7 +774,6 @@ private void buildExecSQLParams(TDSWriter tdsWriter) throws SQLServerException { tdsWriter.writeShort(TDS.PROCID_SP_EXECUTESQL); tdsWriter.writeByte((byte) 0); // RPC procedure option 1 tdsWriter.writeByte((byte) 0); // RPC procedure option 2 - tdsWriter.sendEnclavePackage(preparedSQL, enclaveCEKs); // No handle used. resetPrepStmtHandle(false); @@ -809,7 +800,6 @@ private void buildServerCursorExecParams(TDSWriter tdsWriter) throws SQLServerEx tdsWriter.writeShort(TDS.PROCID_SP_CURSOREXECUTE); tdsWriter.writeByte((byte) 0); // RPC procedure option 1 tdsWriter.writeByte((byte) 0); // RPC procedure option 2 */ - tdsWriter.sendEnclavePackage(preparedSQL, enclaveCEKs); // IN assert hasPreparedStatementHandle(); @@ -842,7 +832,6 @@ private void buildExecParams(TDSWriter tdsWriter) throws SQLServerException { tdsWriter.writeShort(TDS.PROCID_SP_EXECUTE); tdsWriter.writeByte((byte) 0); // RPC procedure option 1 tdsWriter.writeByte((byte) 0); // RPC procedure option 2 */ - tdsWriter.sendEnclavePackage(preparedSQL, enclaveCEKs); // IN assert hasPreparedStatementHandle(); @@ -1037,8 +1026,6 @@ private boolean reuseCachedHandle(boolean hasNewTypeDefinitions, boolean discard return false; } - private ArrayList enclaveCEKs; - private boolean doPrepExec(TDSWriter tdsWriter, Parameter[] params, boolean hasNewTypeDefinitions, boolean hasExistingTypeDefinitions) throws SQLServerException { @@ -2038,7 +2025,7 @@ public int[] executeBatch() throws SQLServerException, BatchUpdateException, SQL bcOperation.setDestinationTableName(tableName); bcOperation.setStmtColumnEncriptionSetting(this.getStmtColumnEncriptionSetting()); bcOperation.setDestinationTableMetadata(rs); - bcOperation.writeToServer(batchRecord); + bcOperation.writeToServer((ISQLServerBulkRecord) batchRecord); bcOperation.close(); updateCounts = new int[batchParamValues.size()]; for (int i = 0; i < batchParamValues.size(); ++i) { @@ -2195,7 +2182,7 @@ public long[] executeLargeBatch() throws SQLServerException, BatchUpdateExceptio bcOperation.setDestinationTableName(tableName); bcOperation.setStmtColumnEncriptionSetting(this.getStmtColumnEncriptionSetting()); bcOperation.setDestinationTableMetadata(rs); - bcOperation.writeToServer(batchRecord); + bcOperation.writeToServer((ISQLServerBulkRecord) batchRecord); bcOperation.close(); updateCounts = new long[batchParamValues.size()]; for (int i = 0; i < batchParamValues.size(); ++i) { @@ -2722,6 +2709,17 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th // Create the parameter array that we'll use for all the items in this batch. Parameter[] batchParam = new Parameter[inOutParam.length]; + /* + * TDSWriter tdsWriter = null; while (numBatchesExecuted < numBatches) { // Fill in the parameter values for + * this batch Parameter paramValues[] = batchParamValues.get(numBatchesPrepared); assert paramValues.length == + * batchParam.length; System.arraycopy(paramValues, 0, batchParam, 0, paramValues.length); boolean + * hasExistingTypeDefinitions = preparedTypeDefinitions != null; boolean hasNewTypeDefinitions = + * buildPreparedStrings(batchParam, false); // Get the encryption metadata for the first batch only. if ((0 == + * numBatchesExecuted) && (Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection)) && (0 < + * batchParam.length) && !isInternalEncryptionQuery && !encryptionMetadataIsRetrieved) { + * getParameterEncryptionMetadata(batchParam); + */ + TDSWriter tdsWriter = null; while (numBatchesExecuted < numBatches) { // Fill in the parameter values for this batch @@ -2732,30 +2730,12 @@ final void doExecutePreparedStatementBatch(PrepStmtBatchExecCmd batchCommand) th boolean hasExistingTypeDefinitions = preparedTypeDefinitions != null; boolean hasNewTypeDefinitions = buildPreparedStrings(batchParam, false); - if (!isInternalEncryptionQuery && connection.isAEv2()) { - this.enclaveCEKs = connection.initEnclaveParameters(preparedSQL, preparedTypeDefinitions, batchParam, - parameterNames); - encryptionMetadataIsRetrieved = true; - - // fix an issue when inserting unicode into non-encrypted nchar column using setString() and AE is - // on on - // Connection - buildPreparedStrings(batchParam, true); - - // Save the crypto metadata retrieved for the first batch. We will re-use these for the rest of the - // batches. - for (Parameter aBatchParam : batchParam) { - cryptoMetaBatch.add(aBatchParam.cryptoMeta); - } - } - // Get the encryption metadata for the first batch only. if ((0 == numBatchesExecuted) && (Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, connection)) && (0 < batchParam.length) && !isInternalEncryptionQuery && !encryptionMetadataIsRetrieved) { getParameterEncryptionMetadata(batchParam); - // fix an issue when inserting unicode into non-encrypted nchar column using setString() and AE is - // on on + // fix an issue when inserting unicode into non-encrypted nchar column using setString() and AE is on on // Connection buildPreparedStrings(batchParam, true); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java index 093a7a83f..cca3ff929 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java @@ -188,8 +188,6 @@ protected Object[][] getContents() { {"R_portNumberPropertyDescription", "The TCP port where an instance of SQL Server is listening."}, {"R_serverSpnPropertyDescription", "SQL Server SPN."}, {"R_columnEncryptionSettingPropertyDescription", "The column encryption setting."}, - {"R_enclaveAttestationUrlPropertyDescription", "The enclave attestation URL."}, - {"R_enclaveAttestationProtocolPropertyDescription", "The enclave attestation protocol."}, {"R_serverNameAsACEPropertyDescription", "Translates the serverName from Unicode to ASCII Compatible Encoding (ACE), as defined by the ToASCII operation of RFC 3490."}, {"R_sendStringParametersAsUnicodePropertyDescription", @@ -596,25 +594,5 @@ protected Object[][] getContents() { {"R_invalidUserSQL", "An error occurred when attempting to parse user SQL. Please verify SQL syntax."}, {"R_invalidInsertValuesQuery", "An error occurred when matching VALUES list to table columns. Please verify SQL syntax."}, - {"R_invalidValuesList", "An error occurred when reading VALUES list. Please verify SQL syntax."}, - {"R_enclaveNotSupported", "The SQL Server instance does not support enclave based computations."}, - {"R_enclaveNoAttestationProtocol", - "The \"enclaveAttestationProtocol\" connection property must be specified with \"enclaveAttestationUrl\"."}, - {"R_enclaveInvalidAttestationProtocol", "The \"enclaveAttestationProtocol\" is invalid."}, - {"R_enclaveTypeInvalid", "The enclave type {0} is invalid or not supported by the driver."}, - {"R_attestationUrlInvalid", "Unable to attest enclave specified by {0}."}, - {"R_EnclaveResponseLengthError", - "More bytes from the server were received than expected when parsing Enclave Attestation response."}, - {"R_EnclavePackageLengthError", - "More bytes from the server were received than expected when parsing Enclave Package."}, - {"R_EnclavePKLengthError", - "More bytes from the server were received than expected when parsing Enclave PK."}, - {"R_MalformedECDHPublicKey", "The ECDH public key from the server must be 104 bits in length."}, - {"R_MalformedECDHHeader", "Unexpected values for ECDH public key header from the server."}, - {"R_InvalidHealthCert", - " Enclave Attestation failed, the health report certificate provided in the enclave was not signed by the HGS."}, - {"R_InvalidSignedStatement", - " Enclave Attestation failed, the statement bytes were not signed by the health certificate."}, - {"R_InvalidDHKeySignature", - "Enclave Attestation failed, the DH Public Key signature can't be verified with the enclave PK."},}; + {"R_invalidValuesList", "An error occurred when reading VALUES list. Please verify SQL syntax."}}; }; diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java index 4772519a9..ca043a8bc 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResultSet.java @@ -24,8 +24,6 @@ import java.sql.SQLXML; import java.text.MessageFormat; import java.util.Calendar; -import java.util.HashMap; -import java.util.Map; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; @@ -155,9 +153,6 @@ final void setCurrentRowType(RowType rowType) { /** Flag set to true if the current row was updated through this ResultSet object */ private boolean updatedCurrentRow = false; - // Column name hash map for caching. - private final Map columnNames = new HashMap<>(); - final boolean getUpdatedCurrentRow() { return updatedCurrentRow; } @@ -637,22 +632,17 @@ public void close() throws SQLServerException { /** * Finds a column index given a column name. * - * @param userProvidedColumnName + * @param columnName * the name of the column * @throws SQLServerException * If any errors occur. * @return the column index */ @Override - public int findColumn(String userProvidedColumnName) throws SQLServerException { - loggerExternal.entering(getClassNameLogging(), "findColumn", userProvidedColumnName); + public int findColumn(String columnName) throws SQLServerException { + loggerExternal.entering(getClassNameLogging(), "findColumn", columnName); checkClosed(); - Integer value = columnNames.get(userProvidedColumnName); - if (null != value) { - return value; - } - // In order to be as accurate as possible when locating column name // indexes, as well as be deterministic when running on various client // locales, we search for column names using the following scheme: @@ -673,9 +663,9 @@ public int findColumn(String userProvidedColumnName) throws SQLServerException { // Search using case-sensitive, non-locale specific (binary) compare. // If the user supplies a true match for the column name, we will find it here. - for (int i = 0; i < columns.length; i++) { - if (columns[i].getColumnName().equals(userProvidedColumnName)) { - columnNames.put(userProvidedColumnName, i + 1); + int i; + for (i = 0; i < columns.length; i++) { + if (columns[i].getColumnName().equals(columnName)) { loggerExternal.exiting(getClassNameLogging(), "findColumn", i + 1); return i + 1; } @@ -685,15 +675,14 @@ public int findColumn(String userProvidedColumnName) throws SQLServerException { // Per JDBC spec, 27.3 "The driver will do a case-insensitive search for // columnName in it's attempt to map it to the column's index". // Use VM supplied String.equalsIgnoreCase to do the "case-insensitive search". - for (int i = 0; i < columns.length; i++) { - if (columns[i].getColumnName().equalsIgnoreCase(userProvidedColumnName)) { - columnNames.put(userProvidedColumnName, i + 1); + for (i = 0; i < columns.length; i++) { + if (columns[i].getColumnName().equalsIgnoreCase(columnName)) { loggerExternal.exiting(getClassNameLogging(), "findColumn", i + 1); return i + 1; } } MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidColumnName")); - Object[] msgArgs = {userProvidedColumnName}; + Object[] msgArgs = {columnName}; SQLServerException.makeFromDriverError(stmt.connection, stmt, form.format(msgArgs), "07009", false); return 0; @@ -4726,7 +4715,6 @@ private void doInsertRowRPC(TDSCommand command, String tableName) throws SQLServ tdsWriter.writeShort(TDS.PROCID_SP_CURSOR); tdsWriter.writeByte((byte) 0); // RPC procedure option 1 tdsWriter.writeByte((byte) 0); // RPC procedure option 2 - tdsWriter.sendEnclavePackage(null, null); tdsWriter.writeRPCInt(null, serverCursorId, false); tdsWriter.writeRPCInt(null, (int) TDS.SP_CURSOR_OP_INSERT, false); tdsWriter.writeRPCInt(null, fetchBufferGetRow(), false); @@ -4807,7 +4795,6 @@ private void doUpdateRowRPC(TDSCommand command) throws SQLServerException { tdsWriter.writeShort(TDS.PROCID_SP_CURSOR); tdsWriter.writeByte((byte) 0); // RPC procedure option 1 tdsWriter.writeByte((byte) 0); // RPC procedure option 2 - tdsWriter.sendEnclavePackage(null, null); tdsWriter.writeRPCInt(null, serverCursorId, false); tdsWriter.writeRPCInt(null, TDS.SP_CURSOR_OP_UPDATE | TDS.SP_CURSOR_OP_SETPOSITION, false); tdsWriter.writeRPCInt(null, fetchBufferGetRow(), false); @@ -4886,7 +4873,6 @@ private void doDeleteRowRPC(TDSCommand command) throws SQLServerException { tdsWriter.writeShort(TDS.PROCID_SP_CURSOR); tdsWriter.writeByte((byte) 0); // RPC procedure option 1 tdsWriter.writeByte((byte) 0); // RPC procedure option 2 - tdsWriter.sendEnclavePackage(null, null); tdsWriter.writeRPCInt(null, serverCursorId, false); tdsWriter.writeRPCInt(null, TDS.SP_CURSOR_OP_DELETE | TDS.SP_CURSOR_OP_SETPOSITION, false); tdsWriter.writeRPCInt(null, fetchBufferGetRow(), false); @@ -5459,7 +5445,6 @@ final boolean doExecute() throws SQLServerException { tdsWriter.writeShort(TDS.PROCID_SP_CURSORFETCH); tdsWriter.writeByte(TDS.RPC_OPTION_NO_METADATA); tdsWriter.writeByte((byte) 0); // RPC procedure option 2 - tdsWriter.sendEnclavePackage(null, null); tdsWriter.writeRPCInt(null, serverCursorId, false); tdsWriter.writeRPCInt(null, fetchType, false); tdsWriter.writeRPCInt(null, startRow, false); @@ -5635,7 +5620,6 @@ final boolean doExecute() throws SQLServerException { tdsWriter.writeShort(TDS.PROCID_SP_CURSORCLOSE); tdsWriter.writeByte((byte) 0); // RPC procedure option 1 tdsWriter.writeByte((byte) 0); // RPC procedure option 2 - tdsWriter.sendEnclavePackage(null, null); tdsWriter.writeRPCInt(null, serverCursorId, false); TDSParser.parse(startResponse(), getLogContext()); return true; diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSecurityUtility.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSecurityUtility.java index ca5ecc67b..45fa6c87b 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSecurityUtility.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSecurityUtility.java @@ -7,9 +7,7 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; -import java.text.MessageFormat; import java.util.Iterator; -import java.util.List; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; @@ -191,28 +189,4 @@ static byte[] decryptWithKey(byte[] cipherText, CryptoMetadata md, return plainText; } - - /* - * Verify the signature for the CMK - */ - static void verifyColumnMasterKeyMetadata(SQLServerConnection connection, String keyStoreName, String keyPath, - String serverName, boolean isEnclaveEnabled, byte[] CMKSignature) throws SQLServerException { - - // check trusted key paths - Boolean[] hasEntry = new Boolean[1]; - List trustedKeyPaths = SQLServerConnection.getColumnEncryptionTrustedMasterKeyPaths(serverName, - hasEntry); - if (hasEntry[0]) { - if ((null == trustedKeyPaths) || (0 == trustedKeyPaths.size()) || (!trustedKeyPaths.contains(keyPath))) { - MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_UntrustedKeyPath")); - Object[] msgArgs = {keyPath, serverName}; - throw new SQLServerException(form.format(msgArgs), null); - } - } - - if (!connection.getColumnEncryptionKeyStoreProvider(keyStoreName).verifyColumnMasterKeyMetadata(keyPath, - isEnclaveEnabled, CMKSignature)) { - throw new SQLServerException(SQLServerException.getErrString("R_VerifySignature"), null); - } - } } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java index 29fc21e8e..f7c722e6b 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSpatialDatatype.java @@ -94,31 +94,19 @@ abstract class SQLServerSpatialDatatype { /** * Serializes the Geogemetry/Geography instance to WKB. * - * @param excludeZMFromWKB - * flag to indicate if Z and M coordinates should be excluded from the WKB representation + * @param noZM + * flag to indicate if Z and M coordinates should be included * @param type * Type of Spatial Datatype (Geometry/Geography) */ - protected void serializeToWkb(boolean excludeZMFromWKB, SQLServerSpatialDatatype type) { - ByteBuffer buf = ByteBuffer.allocate(determineWkbCapacity(excludeZMFromWKB)); + protected void serializeToWkb(boolean noZM, SQLServerSpatialDatatype type) { + ByteBuffer buf = ByteBuffer.allocate(determineWkbCapacity()); createSerializationProperties(); buf.order(ByteOrder.LITTLE_ENDIAN); buf.putInt(srid); buf.put(version); - if (excludeZMFromWKB) { - byte serializationPropertiesNoZM = serializationProperties; - if (hasZvalues) { - serializationPropertiesNoZM -= hasZvaluesMask; - } - - if (hasMvalues) { - serializationPropertiesNoZM -= hasMvaluesMask; - } - buf.put(serializationPropertiesNoZM); - } else { - buf.put(serializationProperties); - } + buf.put(serializationProperties); if (!isSinglePoint && !isSingleLineSegment) { buf.putInt(numberOfPoints); @@ -136,7 +124,7 @@ protected void serializeToWkb(boolean excludeZMFromWKB, SQLServerSpatialDatatype } } - if (!excludeZMFromWKB) { + if (!noZM) { if (hasZvalues) { for (int i = 0; i < numberOfPoints; i++) { buf.putDouble(zValues[i]); @@ -151,11 +139,7 @@ protected void serializeToWkb(boolean excludeZMFromWKB, SQLServerSpatialDatatype } if (isSinglePoint || isSingleLineSegment) { - if (excludeZMFromWKB) { - wkbNoZM = buf.array(); - } else { - wkb = buf.array(); - } + wkb = buf.array(); return; } @@ -179,7 +163,7 @@ protected void serializeToWkb(boolean excludeZMFromWKB, SQLServerSpatialDatatype } } - if (excludeZMFromWKB) { + if (noZM) { wkbNoZM = buf.array(); } else { wkb = buf.array(); @@ -1298,7 +1282,7 @@ protected void createSerializationProperties() { } } - protected int determineWkbCapacity(boolean excludeZMFromWKB) { + protected int determineWkbCapacity() { int totalSize = 0; totalSize += 6; // SRID + version + SerializationPropertiesByte @@ -1306,28 +1290,24 @@ protected int determineWkbCapacity(boolean excludeZMFromWKB) { if (isSinglePoint || isSingleLineSegment) { totalSize += 16 * numberOfPoints; - if (!excludeZMFromWKB) { - if (hasZvalues) { - totalSize += 8 * numberOfPoints; - } + if (hasZvalues) { + totalSize += 8 * numberOfPoints; + } - if (hasMvalues) { - totalSize += 8 * numberOfPoints; - } + if (hasMvalues) { + totalSize += 8 * numberOfPoints; } return totalSize; } int pointSize = 16; - if (!excludeZMFromWKB) { - if (hasZvalues) { - pointSize += 8; - } + if (hasZvalues) { + pointSize += 8; + } - if (hasMvalues) { - pointSize += 8; - } + if (hasMvalues) { + pointSize += 8; } totalSize += 12; // 4 bytes for 3 ints, each representing the number of points, shapes and figures diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java index 9c01b7f78..afd0a3e94 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerStatement.java @@ -16,6 +16,7 @@ import java.sql.Statement; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.ListIterator; import java.util.Stack; import java.util.StringTokenizer; import java.util.Vector; @@ -820,9 +821,6 @@ final void doExecuteStatement(StmtExecCmd execCmd) throws SQLServerException { // through regular Statement objects. We need to ensure that any such JDBC // call syntax is rewritten here as SQL exec syntax. String sql = ensureSQLSyntax(execCmd.sql); - if (!isInternalEncryptionQuery && connection.isAEv2()) { - execCmd.enclaveCEKs = connection.initEnclaveParameters(sql, null, null, null); - } // If this request might be a query (as opposed to an update) then make // sure we set the max number of rows and max field size for any ResultSet @@ -851,8 +849,6 @@ final void doExecuteStatement(StmtExecCmd execCmd) throws SQLServerException { TDSWriter tdsWriter = execCmd.startRequest(TDS.PKT_QUERY); - tdsWriter.sendEnclavePackage(sql, execCmd.enclaveCEKs); - tdsWriter.writeString(sql); // If this is an INSERT statement and generated keys were requested @@ -918,11 +914,6 @@ private void doExecuteStatementBatch(StmtBatchExecCmd execCmd) throws SQLServerE // Make sure any previous maxRows limitation on the connection is removed. connection.setMaxRows(0); - String batchStatementString = String.join(";", batchStatementBuffer); - if (connection.isAEv2()) { - execCmd.enclaveCEKs = connection.initEnclaveParameters(batchStatementString, null, null, null); - } - if (loggerExternal.isLoggable(Level.FINER) && Util.isActivityTraceOn()) { loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString()); } @@ -935,8 +926,12 @@ private void doExecuteStatementBatch(StmtBatchExecCmd execCmd) throws SQLServerE TDSWriter tdsWriter = execCmd.startRequest(TDS.PKT_QUERY); // Write the concatenated batch of statements, delimited by semicolons - tdsWriter.sendEnclavePackage(batchStatementString, execCmd.enclaveCEKs); - tdsWriter.writeString(batchStatementString); + ListIterator batchIter = batchStatementBuffer.listIterator(); + tdsWriter.writeString(batchIter.next()); + while (batchIter.hasNext()) { + tdsWriter.writeString(" ; "); + tdsWriter.writeString(batchIter.next()); + } // Start the response ensureExecuteResultsReader(execCmd.startResponse(isResponseBufferingAdaptive)); @@ -1210,9 +1205,6 @@ public final void cancel() throws SQLServerException { Vector sqlWarnings; // the SQL warnings chain - /** Flag to indicate that it is an internal query to retrieve encryption metadata. */ - boolean isInternalEncryptionQuery; - @Override public final SQLWarning getWarnings() throws SQLServerException { loggerExternal.entering(getClassNameLogging(), "getWarnings"); @@ -2008,7 +2000,6 @@ private void doExecuteCursored(StmtExecCmd execCmd, String sql) throws SQLServer tdsWriter.writeShort(TDS.PROCID_SP_CURSOROPEN); tdsWriter.writeByte((byte) 0); // RPC procedure option 1 tdsWriter.writeByte((byte) 0); // RPC procedure option 2 - tdsWriter.sendEnclavePackage(sql, execCmd.enclaveCEKs); // OUT tdsWriter.writeRPCInt(null, 0, true); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKeyCache.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKeyCache.java index c16c0aec7..ab839d20f 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKeyCache.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerSymmetricKeyCache.java @@ -125,9 +125,37 @@ SQLServerSymmetricKey getKey(EncryptionKeyInfo keyInfo, SQLServerConnection conn // if ColumnEncryptionKeyCacheTtl is 0 no caching at all if (!cache.containsKey(keyLookupValue)) { + + // Check for the connection provider first. + SQLServerColumnEncryptionKeyStoreProvider provider = connection + .getSystemColumnEncryptionKeyStoreProvider(keyInfo.keyStoreName); + + // There is no connection provider of this name, check for the global system providers. + if (null == provider) { + provider = SQLServerConnection + .getGlobalSystemColumnEncryptionKeyStoreProvider(keyInfo.keyStoreName); + } + + // There is no global system provider of this name, check for the global custom providers. + if (null == provider) { + provider = SQLServerConnection + .getGlobalCustomColumnEncryptionKeyStoreProvider(keyInfo.keyStoreName); + } + + // No provider was found of this name. + if (null == provider) { + String systemProviders = connection.getAllSystemColumnEncryptionKeyStoreProviders(); + String customProviders = SQLServerConnection + .getAllGlobalCustomSystemColumnEncryptionKeyStoreProviders(); + MessageFormat form = new MessageFormat( + SQLServerException.getErrString("R_UnrecognizedKeyStoreProviderName")); + Object[] msgArgs = {keyInfo.keyStoreName, systemProviders, customProviders}; + throw new SQLServerException(this, form.format(msgArgs), null, 0, false); + } + byte[] plaintextKey; - plaintextKey = connection.getColumnEncryptionKeyStoreProvider(keyInfo.keyStoreName) - .decryptColumnEncryptionKey(keyInfo.keyPath, keyInfo.algorithmName, keyInfo.encryptedKey); + plaintextKey = provider.decryptColumnEncryptionKey(keyInfo.keyPath, keyInfo.algorithmName, + keyInfo.encryptedKey); encryptionKey = new SQLServerSymmetricKey(plaintextKey); /* diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerVSMEnclaveProvider.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerVSMEnclaveProvider.java deleted file mode 100644 index 9ad90e981..000000000 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerVSMEnclaveProvider.java +++ /dev/null @@ -1,589 +0,0 @@ -/* - * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made - * available under the terms of the MIT License. See the LICENSE file in the project root for more information. - */ - -package com.microsoft.sqlserver.jdbc; - -import static java.nio.charset.StandardCharsets.UTF_16LE; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.security.GeneralSecurityException; -import java.security.KeyFactory; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.MessageDigest; -import java.security.PublicKey; -import java.security.SecureRandom; -import java.security.Signature; -import java.security.SignatureException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; -import java.security.spec.ECGenParameterSpec; -import java.security.spec.ECPoint; -import java.security.spec.ECPublicKeySpec; -import java.security.spec.MGF1ParameterSpec; -import java.security.spec.PSSParameterSpec; -import java.security.spec.RSAPublicKeySpec; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.crypto.KeyAgreement; - - -/** - * - * Provides the implementation of the VSM Enclave Provider. The enclave provider encapsulates the client-side - * implementation details of the enclave attestation protocol. - * - */ -public class SQLServerVSMEnclaveProvider implements ISQLServerEnclaveProvider { - - private VSMAttestationParameters vsmParams = null; - private AttestationResponse hgsResponse = null; - private String attestationURL = null; - private EnclaveSession enclaveSession = null; - - @Override - public void getAttestationParameters(boolean createNewParameters, String url) throws SQLServerException { - if (null == vsmParams || createNewParameters) { - attestationURL = url; - vsmParams = new VSMAttestationParameters(); - } - } - - @Override - public ArrayList createEnclaveSession(SQLServerConnection connection, String userSql, - String preparedTypeDefinitions, Parameter[] params, - ArrayList parameterNames) throws SQLServerException { - ArrayList b = describeParameterEncryption(connection, userSql, preparedTypeDefinitions, params, - parameterNames); - if (null != hgsResponse && !connection.enclaveEstablished()) { - try { - enclaveSession = new EnclaveSession(hgsResponse.getSessionID(), - vsmParams.createSessionSecret(hgsResponse.getDHpublicKey())); - } catch (GeneralSecurityException e) { - SQLServerException.makeFromDriverError(connection, this, e.getLocalizedMessage(), "0", false); - } - } - return b; - } - - @Override - public void invalidateEnclaveSession() { - enclaveSession = null; - vsmParams = null; - attestationURL = null; - } - - @Override - public EnclaveSession getEnclaveSession() { - return enclaveSession; - } - - @Override - public byte[] getEnclavePackage(String userSQL, ArrayList enclaveCEKs) throws SQLServerException { - if (null != enclaveSession) { - try { - ByteArrayOutputStream enclavePackage = new ByteArrayOutputStream(); - enclavePackage.writeBytes(enclaveSession.getSessionID()); - ByteArrayOutputStream keys = new ByteArrayOutputStream(); - byte[] randomGUID = new byte[16]; - SecureRandom.getInstanceStrong().nextBytes(randomGUID); - keys.writeBytes(randomGUID); - keys.writeBytes(ByteBuffer.allocate(8).putLong(enclaveSession.getCounter()).array()); - keys.writeBytes(MessageDigest.getInstance("SHA-256").digest((userSQL).getBytes(UTF_16LE))); - for (byte[] b : enclaveCEKs) { - keys.writeBytes(b); - } - enclaveCEKs.clear(); - SQLServerAeadAes256CbcHmac256EncryptionKey encryptedKey = new SQLServerAeadAes256CbcHmac256EncryptionKey( - enclaveSession.getSessionSecret(), SQLServerAeadAes256CbcHmac256Algorithm.algorithmName); - SQLServerAeadAes256CbcHmac256Algorithm algo = new SQLServerAeadAes256CbcHmac256Algorithm(encryptedKey, - SQLServerEncryptionType.Randomized, (byte) 0x1); - enclavePackage.writeBytes(algo.encryptData(keys.toByteArray())); - return enclavePackage.toByteArray(); - } catch (GeneralSecurityException | SQLServerException e) { - SQLServerException.makeFromDriverError(null, this, e.getLocalizedMessage(), "0", false); - } - } - return null; - } - - private AttestationResponse validateAttestationResponse(AttestationResponse ar) throws SQLServerException { - try { - byte[] attestationCerts = getAttestationCertificates(); - ar.validateCert(attestationCerts); - ar.validateStatementSignature(); - ar.validateDHPublicKey(); - } catch (IOException | GeneralSecurityException e) { - SQLServerException.makeFromDriverError(null, this, e.getLocalizedMessage(), "0", false); - } - return ar; - } - - private byte[] getAttestationCertificates() throws IOException { - java.net.URL url = new java.net.URL(attestationURL + "/attestationservice.svc/v2.0/signingCertificates/"); - java.net.URLConnection con = url.openConnection(); - String s = new String(con.getInputStream().readAllBytes()); - // omit the square brackets that come with the JSON - String[] bytesString = s.substring(1, s.length() - 1).split(","); - byte[] certData = new byte[bytesString.length]; - for (int i = 0; i < certData.length; i++) { - certData[i] = (byte) (Integer.parseInt(bytesString[i])); - } - return certData; - } - - private ArrayList describeParameterEncryption(SQLServerConnection connection, String userSql, - String preparedTypeDefinitions, Parameter[] params, - ArrayList parameterNames) throws SQLServerException { - ArrayList enclaveRequestedCEKs = new ArrayList<>(); - ResultSet rs = null; - try (PreparedStatement stmt = connection.prepareStatement("EXEC sp_describe_parameter_encryption ?,?,?")) { - ((SQLServerPreparedStatement) stmt).isInternalEncryptionQuery = true; - stmt.setNString(1, userSql); - if (preparedTypeDefinitions != null && preparedTypeDefinitions.length() != 0) { - stmt.setNString(2, preparedTypeDefinitions); - } else { - stmt.setNString(2, ""); - } - stmt.setBytes(3, vsmParams.getBytes()); - rs = ((SQLServerPreparedStatement) stmt).executeQueryInternal(); - - if (null == rs) { - // No results. Meaning no parameter. - // Should never happen. - return enclaveRequestedCEKs; - } - - Map cekList = new HashMap<>(); - CekTableEntry cekEntry = null; - boolean isRequestedByEnclave = false; - try { - while (rs.next()) { - int currentOrdinal = rs.getInt(DescribeParameterEncryptionResultSet1.KeyOrdinal.value()); - if (!cekList.containsKey(currentOrdinal)) { - cekEntry = new CekTableEntry(currentOrdinal); - cekList.put(cekEntry.ordinal, cekEntry); - } else { - cekEntry = cekList.get(currentOrdinal); - } - - String keyStoreName = rs.getString(DescribeParameterEncryptionResultSet1.ProviderName.value()); - String algo = rs.getString(DescribeParameterEncryptionResultSet1.KeyEncryptionAlgorithm.value()); - String keyPath = rs.getString(DescribeParameterEncryptionResultSet1.KeyPath.value()); - - int dbID = rs.getInt(DescribeParameterEncryptionResultSet1.DbId.value()); - byte[] mdVer = rs.getBytes(DescribeParameterEncryptionResultSet1.KeyMdVersion.value()); - int keyID = rs.getInt(DescribeParameterEncryptionResultSet1.KeyId.value()); - byte[] encryptedKey = rs.getBytes(DescribeParameterEncryptionResultSet1.EncryptedKey.value()); - - cekEntry.add(encryptedKey, dbID, keyID, - rs.getInt(DescribeParameterEncryptionResultSet1.KeyVersion.value()), mdVer, keyPath, - keyStoreName, algo); - - // servers supporting enclave computations should always return a boolean indicating whether the key - // is - // required by enclave or not. - if (ColumnEncryptionVersion.AE_v2.value() <= connection.getServerColumnEncryptionVersion() - .value()) { - isRequestedByEnclave = rs - .getBoolean(DescribeParameterEncryptionResultSet1.IsRequestedByEnclave.value()); - } - - if (isRequestedByEnclave) { - byte[] keySignature = rs - .getBytes(DescribeParameterEncryptionResultSet1.EnclaveCMKSignature.value()); - String serverName = connection.getTrustedServerNameAE(); - SQLServerSecurityUtility.verifyColumnMasterKeyMetadata(connection, keyStoreName, keyPath, - serverName, isRequestedByEnclave, keySignature); - - // DBID(4) + MDVER(8) + KEYID(2) + CEK(32) = 46 - ByteBuffer aev2CekEntry = ByteBuffer.allocate(46); - aev2CekEntry.order(ByteOrder.LITTLE_ENDIAN).putInt(dbID); - aev2CekEntry.put(mdVer); - aev2CekEntry.putShort((short) keyID); - aev2CekEntry.put(connection.getColumnEncryptionKeyStoreProvider(keyStoreName) - .decryptColumnEncryptionKey(keyPath, algo, encryptedKey)); - enclaveRequestedCEKs.add(aev2CekEntry.array()); - } - } - } catch (SQLException e) { - if (e instanceof SQLServerException) { - throw (SQLServerException) e; - } else { - throw new SQLServerException(SQLServerException.getErrString("R_UnableRetrieveParameterMetadata"), - null, 0, e); - } - } - - // Process the second resultset. - if (!stmt.getMoreResults()) { - throw new SQLServerException(this, SQLServerException.getErrString("R_UnexpectedDescribeParamFormat"), - null, 0, false); - } - - try { - rs = (SQLServerResultSet) stmt.getResultSet(); - while (rs.next() && null != params) { - String paramName = rs.getString(DescribeParameterEncryptionResultSet2.ParameterName.value()); - int paramIndex = parameterNames.indexOf(paramName); - int cekOrdinal = rs - .getInt(DescribeParameterEncryptionResultSet2.ColumnEncryptionKeyOrdinal.value()); - cekEntry = cekList.get(cekOrdinal); - - // cekEntry will be null if none of the parameters are encrypted. - if ((null != cekEntry) && (cekList.size() < cekOrdinal)) { - MessageFormat form = new MessageFormat( - SQLServerException.getErrString("R_InvalidEncryptionKeyOridnal")); - Object[] msgArgs = {cekOrdinal, cekEntry.getSize()}; - throw new SQLServerException(this, form.format(msgArgs), null, 0, false); - } - SQLServerEncryptionType encType = SQLServerEncryptionType - .of((byte) rs.getInt(DescribeParameterEncryptionResultSet2.ColumnEncrytionType.value())); - if (SQLServerEncryptionType.PlainText != encType) { - params[paramIndex].cryptoMeta = new CryptoMetadata(cekEntry, (short) cekOrdinal, - (byte) rs.getInt( - DescribeParameterEncryptionResultSet2.ColumnEncryptionAlgorithm.value()), - null, encType.value, (byte) rs.getInt( - DescribeParameterEncryptionResultSet2.NormalizationRuleVersion.value())); - // Decrypt the symmetric key.(This will also validate and throw if needed). - SQLServerSecurityUtility.decryptSymmetricKey(params[paramIndex].cryptoMeta, connection); - } else { - if (params[paramIndex].getForceEncryption()) { - MessageFormat form = new MessageFormat(SQLServerException - .getErrString("R_ForceEncryptionTrue_HonorAETrue_UnencryptedColumn")); - Object[] msgArgs = {userSql, paramIndex + 1}; - SQLServerException.makeFromDriverError(connection, this, form.format(msgArgs), "0", true); - } - } - } - } catch (SQLException e) { - if (e instanceof SQLServerException) { - throw (SQLServerException) e; - } else { - throw new SQLServerException(SQLServerException.getErrString("R_UnableRetrieveParameterMetadata"), - null, 0, e); - } - } - - // Process the third resultset. - if (connection.isAEv2() && stmt.getMoreResults()) { - rs = (SQLServerResultSet) stmt.getResultSet(); - while (rs.next()) { - hgsResponse = new AttestationResponse(rs.getBytes(1)); - // This validates and establishes the enclave session if valid - if (!connection.enclaveEstablished()) { - hgsResponse = validateAttestationResponse(hgsResponse); - } - } - } - - // Null check for rs is done already. - rs.close(); - } catch (SQLException e) { - if (e instanceof SQLServerException) { - throw (SQLServerException) e; - } else { - throw new SQLServerException(SQLServerException.getErrString("R_UnableRetrieveParameterMetadata"), null, - 0, e); - } - } - return enclaveRequestedCEKs; - } -} - - -class VSMAttestationParameters extends BaseAttestationRequest { - - // Static byte[] for VSM ECDH - private static byte ECDH_MAGIC[] = {0x45, 0x43, 0x4b, 0x33, 0x30, 0x00, 0x00, 0x00}; - // Type 3 is VSM, sent as Little Endian 0x30000000 - private static byte ENCLAVE_TYPE[] = new byte[] {0x3, 0x0, 0x0, 0x0}; - // VSM doesn't have a challenge - private static byte ENCLAVE_CHALLENGE[] = new byte[] {0x0, 0x0, 0x0, 0x0}; - private static int ENCLAVE_LENGTH = 104; - private byte[] x; - private byte[] y; - - VSMAttestationParameters() throws SQLServerException { - KeyPairGenerator kpg = null; - try { - kpg = KeyPairGenerator.getInstance("EC"); - kpg.initialize(new ECGenParameterSpec("secp384r1")); - } catch (GeneralSecurityException e) { - SQLServerException.makeFromDriverError(null, kpg, e.getLocalizedMessage(), "0", false); - } - KeyPair kp = kpg.generateKeyPair(); - ECPublicKey publicKey = (ECPublicKey) kp.getPublic(); - privateKey = kp.getPrivate(); - ECPoint w = publicKey.getW(); - x = w.getAffineX().toByteArray(); - y = w.getAffineY().toByteArray(); - - /* - * For some reason toByteArray doesn't have an Signum option like the constructor. Manually remove leading 00 - * byte if it exists. - */ - if (x[0] == 0 && x.length != 48) { - x = Arrays.copyOfRange(x, 1, x.length); - } - if (y[0] == 0 && y.length != 48) { - y = Arrays.copyOfRange(y, 1, y.length); - } - } - - @Override - byte[] getBytes() { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - os.writeBytes(ENCLAVE_TYPE); - os.writeBytes(ENCLAVE_CHALLENGE); - os.writeBytes(ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(ENCLAVE_LENGTH).array()); - os.writeBytes(ECDH_MAGIC); - os.writeBytes(x); - os.writeBytes(y); - return os.toByteArray(); - } - - byte[] createSessionSecret(byte[] serverResponse) throws GeneralSecurityException, SQLServerException { - if (serverResponse.length != ENCLAVE_LENGTH) { - SQLServerException.makeFromDriverError(null, this, - SQLServerResource.getResource("R_MalformedECDHPublicKey"), "0", false); - } - ByteBuffer sr = ByteBuffer.wrap(serverResponse); - byte[] magic = new byte[8]; - sr.get(magic); - if (!Arrays.equals(magic, ECDH_MAGIC)) { - SQLServerException.makeFromDriverError(null, this, SQLServerResource.getResource("R_MalformedECDHHeader"), - "0", false); - } - byte[] x = new byte[48]; - byte[] y = new byte[48]; - sr.get(x); - sr.get(y); - /* - * Server returns X and Y coordinates, create a key using the point of the server and our key parameters. - * Public/Private key parameters are the same. - */ - ECPublicKeySpec keySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(1, x), new BigInteger(1, y)), - ((ECPrivateKey) privateKey).getParams()); - KeyAgreement ka = KeyAgreement.getInstance("ECDH"); - ka.init(privateKey); - // Generate a PublicKey from the above key specifications and do an agreement with our PrivateKey - ka.doPhase(KeyFactory.getInstance("EC").generatePublic(keySpec), true); - // Generate a Secret from the agreement and hash with SHA-256 to create Session Secret - return MessageDigest.getInstance("SHA-256").digest(ka.generateSecret()); - } -} - - -@SuppressWarnings("unused") -class AttestationResponse { - private int totalSize; - private int identitySize; - private int healthReportSize; - private int enclaveReportSize; - - private byte[] enclavePK; - private byte[] healthReportCertificate; - private byte[] enclaveReportPackage; - - private int sessionInfoSize; - private byte[] sessionID = new byte[8]; - private int DHPKsize; - private int DHPKSsize; - private byte[] DHpublicKey; - private byte[] publicKeySig; - - private X509Certificate healthCert; - - AttestationResponse(byte[] b) throws SQLServerException { - /*- - * Parse the attestation response. - * - * Total Size of the response - 4B - * Size of the Identity - 4B - * Size of the HealthCert - 4B - * Size of the EnclaveReport - 4B - * Enclave PK - identitySize bytes - * Health Certificate - healthReportSize bytes - * Enclave Report Package - enclaveReportSize bytes - * Session Info Size - 4B - * Session ID - 8B - * DH Public Key Size - 4B - * DH Public Key Signature Size - 4B - * DH Public Key - DHPKsize bytes - * DH Public Key Signature - DHPKSsize bytes - */ - ByteBuffer response = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN); - this.totalSize = response.getInt(); - this.identitySize = response.getInt(); - this.healthReportSize = response.getInt(); - this.enclaveReportSize = response.getInt(); - - enclavePK = new byte[identitySize]; - healthReportCertificate = new byte[healthReportSize]; - enclaveReportPackage = new byte[enclaveReportSize]; - - response.get(enclavePK, 0, identitySize); - response.get(healthReportCertificate, 0, healthReportSize); - response.get(enclaveReportPackage, 0, enclaveReportSize); - - this.sessionInfoSize = response.getInt(); - response.get(sessionID, 0, 8); - this.DHPKsize = response.getInt(); - this.DHPKSsize = response.getInt(); - - DHpublicKey = new byte[DHPKsize]; - publicKeySig = new byte[DHPKSsize]; - - response.get(DHpublicKey, 0, DHPKsize); - response.get(publicKeySig, 0, DHPKSsize); - - if (0 != response.remaining()) { - SQLServerException.makeFromDriverError(null, this, - SQLServerResource.getResource("R_EnclaveResponseLengthError"), "0", false); - } - // Create a X.509 certificate from the bytes - try { - CertificateFactory cf = CertificateFactory.getInstance("X.509"); - healthCert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(healthReportCertificate)); - } catch (CertificateException ce) { - SQLServerException.makeFromDriverError(null, this, ce.getLocalizedMessage(), "0", false); - } - } - - @SuppressWarnings("unchecked") - void validateCert(byte[] b) throws SQLServerException { - try { - CertificateFactory cf = CertificateFactory.getInstance("X.509"); - Collection certs = (Collection) cf - .generateCertificates(new ByteArrayInputStream(b)); - for (X509Certificate cert : certs) { - try { - healthCert.verify(cert.getPublicKey()); - return; - } catch (SignatureException e) { - // Doesn't match, but continue looping through the rest of the certificates - } - } - } catch (GeneralSecurityException e) { - SQLServerException.makeFromDriverError(null, this, e.getLocalizedMessage(), "0", false); - } - SQLServerException.makeFromDriverError(null, this, SQLServerResource.getResource("R_InvalidHealthCert"), "0", - false); - } - - void validateStatementSignature() throws SQLServerException, GeneralSecurityException { - /*- - * Parse the Enclave Report Package fields. - * - * Package Size - 4B - * Version - 4B - * Signature Scheme - 4B - * Signed Statement Bytes Size - 4B - * Signature Size - 4B - * Reserved - 4B - * Signed Statement - signedStatementSize bytes contains: - * Report Size - 4B - * Report Version - 4B - * Enclave Data - 64B - * Enclave Identity - 152B - * ??? - 720B - * Signature Blob - signatureSize bytes - */ - ByteBuffer enclaveReportPackageBuffer = ByteBuffer.wrap(enclaveReportPackage).order(ByteOrder.LITTLE_ENDIAN); - int packageSize = enclaveReportPackageBuffer.getInt(); - int version = enclaveReportPackageBuffer.getInt(); - int signatureScheme = enclaveReportPackageBuffer.getInt(); - int signedStatementSize = enclaveReportPackageBuffer.getInt(); - int signatureSize = enclaveReportPackageBuffer.getInt(); - int reserved = enclaveReportPackageBuffer.getInt(); - - byte[] signedStatement = new byte[signedStatementSize]; - enclaveReportPackageBuffer.get(signedStatement, 0, signedStatementSize); - byte[] signatureBlob = new byte[signatureSize]; - enclaveReportPackageBuffer.get(signatureBlob, 0, signatureSize); - - if (enclaveReportPackageBuffer.remaining() != 0) { - SQLServerException.makeFromDriverError(null, this, - SQLServerResource.getResource("R_EnclavePackageLengthError"), "0", false); - } - - Signature sig = Signature.getInstance("RSASSA-PSS"); - PSSParameterSpec pss = new PSSParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256, 32, 1); - sig.setParameter(pss); - sig.initVerify(healthCert); - sig.update(signedStatement); - if (!sig.verify(signatureBlob)) { - SQLServerException.makeFromDriverError(null, this, - SQLServerResource.getResource("R_InvalidSignedStatement"), "0", false); - } - } - - void validateDHPublicKey() throws SQLServerException, GeneralSecurityException { - /*- - * Java doesn't directly support PKCS1 padding for RSA keys. Parse the key bytes and create a RSAPublicKeySpec - * with the exponent and modulus. - * - * Static string "RSA1" - 4B (Unused) - * Bit count - 4B (Unused) - * Public Exponent Length - 4B - * Public Modulus Length - 4B - * Prime 1 - 4B (Unused) - * Prime 2 - 4B (Unused) - * Exponent - publicExponentLength bytes - * Modulus - publicModulusLength bytes - */ - ByteBuffer enclavePKBuffer = ByteBuffer.wrap(enclavePK).order(ByteOrder.LITTLE_ENDIAN); - byte[] rsa1 = new byte[4]; - enclavePKBuffer.get(rsa1); - int bitCount = enclavePKBuffer.getInt(); - int publicExponentLength = enclavePKBuffer.getInt(); - int publicModulusLength = enclavePKBuffer.getInt(); - int prime1 = enclavePKBuffer.getInt(); - int prime2 = enclavePKBuffer.getInt(); - byte[] exponent = new byte[publicExponentLength]; - enclavePKBuffer.get(exponent); - byte[] modulus = new byte[publicModulusLength]; - enclavePKBuffer.get(modulus); - if (enclavePKBuffer.remaining() != 0) { - SQLServerException.makeFromDriverError(null, this, SQLServerResource.getResource("R_EnclavePKLengthError"), - "0", false); - } - RSAPublicKeySpec spec = new RSAPublicKeySpec(new BigInteger(1, modulus), new BigInteger(1, exponent)); - KeyFactory factory = KeyFactory.getInstance("RSA"); - PublicKey pub = factory.generatePublic(spec); - Signature sig = Signature.getInstance("SHA256withRSA"); - sig.initVerify(pub); - sig.update(DHpublicKey); - if (!sig.verify(publicKeySig)) { - SQLServerException.makeFromDriverError(null, this, SQLServerResource.getResource("R_InvalidDHKeySignature"), - "0", false); - } - } - - byte[] getDHpublicKey() { - return DHpublicKey; - } - - byte[] getSessionID() { - return sessionID; - } -} diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerXAConnection.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerXAConnection.java index fe1067775..958ffa365 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerXAConnection.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerXAConnection.java @@ -52,22 +52,6 @@ public final class SQLServerXAConnection extends SQLServerPooledConnection imple controlConnectionProperties.setProperty(SQLServerDriverStringProperty.PASSWORD.toString(), pwd); } - // Add truststore password property for creating the control connection. This will be removed again - String trustStorePassword = ds.getTrustStorePassword(); - if (null == trustStorePassword) { - // trustStorePassword can either come from the connection string or added via - // SQLServerXADataSource::setTrustStorePassword. - // if trustStorePassword is null at this point, then check the connection string. - Properties urlProps = Util.parseUrl(ds.getURL(), xaLogger); - trustStorePassword = urlProps.getProperty(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString()); - } - - // if trustStorePassword is still null, it wasn't provided. Do not set the property as null to avoid NPE. - if (null != trustStorePassword) { - controlConnectionProperties.setProperty(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString(), - trustStorePassword); - } - if (xaLogger.isLoggable(Level.FINER)) xaLogger.finer("Creating an internal control connection for" + toString()); physicalControlConnection = null; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java index 2fb946725..ec7fefb12 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/AESetup.java @@ -18,9 +18,7 @@ import java.sql.Statement; import java.sql.Time; import java.sql.Timestamp; -import java.util.HashMap; import java.util.LinkedList; -import java.util.Map; import java.util.Properties; import org.junit.jupiter.api.AfterAll; @@ -30,12 +28,9 @@ import org.opentest4j.TestAbortedException; import com.microsoft.sqlserver.jdbc.RandomData; -import com.microsoft.sqlserver.jdbc.RandomUtil; -import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider; import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionJavaKeyStoreProvider; import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionKeyStoreProvider; import com.microsoft.sqlserver.jdbc.SQLServerConnection; -import com.microsoft.sqlserver.jdbc.SQLServerException; import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement; import com.microsoft.sqlserver.jdbc.SQLServerStatement; import com.microsoft.sqlserver.jdbc.SQLServerStatementColumnEncryptionSetting; @@ -59,76 +54,14 @@ public class AESetup extends AbstractTest { static String filePath = null; static String thumbprint = null; - static String javaKeyPath = null; + static String keyPath = null; static String javaKeyAliases = null; - static String windowsKeyPath = null; - static String applicationClientID = null; - static String applicationKey = null; - static String[] keyIDs = null; - static String cmkJks = null; - static String cmkWin = null; - static String cmkAkv = null; - static String cekJks = null; - static String cekWin = null; - static String cekAkv = null; - - static boolean kspRegistered = false; - static SQLServerColumnEncryptionKeyStoreProvider jksProvider = null; - static SQLServerColumnEncryptionAzureKeyVaultProvider akvProvider = null; + + static SQLServerColumnEncryptionKeyStoreProvider storeProvider = null; static SQLServerStatementColumnEncryptionSetting stmtColEncSetting = null; static String AETestConnectionString; - static Properties AEInfo; - static boolean isAEv2Supported = false; - - public static final String tableName = RandomUtil.getIdentifier("AETest_"); - - public static final String CHAR_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedChar"); - public static final String BINARY_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedBinary"); - public static final String DATE_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedDate"); - public static final String NUMERIC_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedNumeric"); - public static final String SCALE_DATE_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedScaleDate"); - enum ColumnType { - PLAIN, - RANDOMIZED, - DETERMINISTIC - } - - /* - * tables used in the tests {columnName, columnType} - */ - static String binaryTable[][] = {{"Binary", "binary(20)"}, {"Varbinary", "varbinary(50)"}, - {"VarbinaryMax", "varbinary(max)"}, {"Binary512", "binary(512)"}, {"Binary8000", "varbinary(8000)"},}; - - static String charTable[][] = {{"Char", "char(20) COLLATE Latin1_General_BIN2", "CHAR"}, - {"Varchar", "varchar(50) COLLATE Latin1_General_BIN2", "CHAR"}, - {"VarcharMax", "varchar(max) COLLATE Latin1_General_BIN2", "LONGVARCHAR"}, - {"Nchar", "nchar(30) COLLATE Latin1_General_BIN2", "NCHAR"}, - {"Nvarchar", "nvarchar(60) COLLATE Latin1_General_BIN2", "NCHAR"}, - {"NvarcharMax", "nvarchar(max) COLLATE Latin1_General_BIN2", "LONGNVARCHAR"}, - {"Uniqueidentifier", "uniqueidentifier", "GUID"}, - {"Varchar8000", "varchar(8000) COLLATE Latin1_General_BIN2", "CHAR"}, - {"Nvarchar4000", "nvarchar(4000) COLLATE Latin1_General_BIN2", "NCHAR"},}; - - static String dateTable[][] = {{"Date", "date"}, {"Datetime2Default", "datetime2"}, - {"DatetimeoffsetDefault", "datetimeoffset"}, {"TimeDefault", "time"}, {"Datetime", "datetime"}, - {"Smalldatetime", "smalldatetime"},}; - - static String dateScaleTable[][] = {{"Datetime2", "datetime2(2)"}, {"Time", "time(2)"}, - {"Datetimeoffset", "datetimeoffset(2)"},}; - - static String numericTable[][] = {{"Bit", "bit"}, {"Tinyint", "tinyint"}, {"Smallint", "smallint"}, {"Int", "int"}, - {"Bigint", "bigint"}, {"FloatDefault", "float"}, {"Float", "float(30)"}, {"Real", "real"}, - {"DecimalDefault", "decimal"}, {"Decimal", "decimal(10,5)"}, {"NumericDefault", "numeric"}, - {"Numeric", "numeric(8,2)"}, {"SmallMoney", "smallmoney"}, {"Money", "money"}, - {"Decimal2", "decimal(28,4)"}, {"Numeric2", "numeric(28,4)"},}; - - // CREATE TABLE tableName (columns) NULL" - static String createSql = "CREATE TABLE %s (%s)"; - - // ENCRYPTED WITH (ENCRYPTION_TYPE = encryptionType, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', - // COLUMN_ENCRYPTION_KEY = cekName - static String encryptSql = " ENCRYPTED WITH (ENCRYPTION_TYPE = %s, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = %s"; + static Properties AEInfo; /** * Create connection, statement and generate path of resource file @@ -139,92 +72,24 @@ enum ColumnType { @BeforeAll public static void setUpConnection() throws TestAbortedException, Exception { AETestConnectionString = connectionString + ";sendTimeAsDateTime=false"; - String tmpConnectionString = AETestConnectionString; - String enclaveAttestationUrl = TestUtils.getConfiguredProperty("enclaveAttestationUrl"); - if (null != enclaveAttestationUrl) { - tmpConnectionString = TestUtils.addOrOverrideProperty(tmpConnectionString, "enclaveAttestationUrl", - enclaveAttestationUrl); - } - String enclaveAttestationProtocol = TestUtils.getConfiguredProperty("enclaveAttestationProtocol"); - if (null != enclaveAttestationProtocol) { - tmpConnectionString = TestUtils.addOrOverrideProperty(tmpConnectionString, "enclaveAttestationProtocol", - enclaveAttestationProtocol); - } - - // add enclave properties if AEv2 supported - try (Connection con = PrepUtil.getConnection(tmpConnectionString)) { - if (TestUtils.isAEv2(con)) { - isAEv2Supported = true; - AETestConnectionString = tmpConnectionString; - } - } catch (SQLServerException e) { - if (!e.getMessage().matches(TestUtils.formatErrorMsg("R_enclaveNotSupported"))) { - // ignore AEv2 not supported errors - fail(e.getMessage()); - } - } - - cmkJks = Constants.CMK_NAME + "_JKS"; - cekJks = Constants.CEK_NAME + "_JKS"; - readFromFile(Constants.JAVA_KEY_STORE_FILENAME, "Alias name"); - - javaKeyPath = TestUtils.getCurrentClassPath() + Constants.JKS_NAME; - applicationClientID = TestUtils.getConfiguredProperty("applicationClientID"); - applicationKey = TestUtils.getConfiguredProperty("applicationKey"); - String keyID = TestUtils.getConfiguredProperty("keyID"); - if (null != keyID) { - keyIDs = keyID.split(";"); - } - - Map map = new HashMap(); - if (null == jksProvider) { - jksProvider = new SQLServerColumnEncryptionJavaKeyStoreProvider(javaKeyPath, - Constants.JKS_SECRET.toCharArray()); - map.put("My_KEYSTORE", jksProvider); - } - - if (null == akvProvider && null != applicationClientID && null != applicationKey) { - akvProvider = new SQLServerColumnEncryptionAzureKeyVaultProvider(applicationClientID, applicationKey); - map.put(Constants.AZURE_KEY_VAULT_NAME, akvProvider); - } - - if (!kspRegistered && (null != jksProvider || null != akvProvider)) { - SQLServerConnection.registerColumnEncryptionKeyStoreProviders(map); - kspRegistered = true; - } - - dropAll(); - - // always test JKS - createCMK(cmkJks, Constants.JAVA_KEY_STORE_NAME, javaKeyAliases, Constants.CMK_SIGNATURE); - createCEK(cmkJks, cekJks, jksProvider); - - if (null != akvProvider) { - cmkAkv = Constants.CMK_NAME + "_AKV"; - cekAkv = Constants.CEK_NAME + "_AKV"; - - createCMK(cmkAkv, Constants.AZURE_KEY_VAULT_NAME, keyIDs[0], Constants.CMK_SIGNATURE_AKV); - createCEK(cmkAkv, cekAkv, akvProvider); - } - - windowsKeyPath = TestUtils.getConfiguredProperty("windowsKeyPath"); - if (null != windowsKeyPath) { - AETestConnectionString = TestUtils.addOrOverrideProperty(AETestConnectionString, "windowsKeyPath", - windowsKeyPath); - cmkWin = Constants.CMK_NAME + "_WIN"; - cekWin = Constants.CEK_NAME + "_WIN"; - createCMK(cmkWin, Constants.WINDOWS_KEY_STORE_NAME, windowsKeyPath, Constants.CMK_SIGNATURE); - createCEK(cmkWin, cekWin, null); + try (Connection con = PrepUtil.getConnection(AETestConnectionString); Statement stmt = con.createStatement()) { + dropCEK(stmt); + dropCMK(stmt); } + keyPath = TestUtils.getCurrentClassPath() + Constants.JKS_NAME; + storeProvider = new SQLServerColumnEncryptionJavaKeyStoreProvider(keyPath, Constants.JKS_SECRET.toCharArray()); stmtColEncSetting = SQLServerStatementColumnEncryptionSetting.Enabled; AEInfo = new Properties(); AEInfo.setProperty("ColumnEncryptionSetting", Constants.ENABLED); AEInfo.setProperty("keyStoreAuthentication", Constants.JAVA_KEY_STORE_SECRET); - AEInfo.setProperty("keyStoreLocation", javaKeyPath); + AEInfo.setProperty("keyStoreLocation", keyPath); AEInfo.setProperty("keyStoreSecret", Constants.JKS_SECRET); + + createCMK(Constants.JAVA_KEY_STORE_NAME, javaKeyAliases); + createCEK(storeProvider); } /** @@ -237,19 +102,8 @@ public static void setUpConnection() throws TestAbortedException, Exception { public static void dropAll() throws Exception { try (Statement stmt = connection.createStatement()) { dropTables(stmt); - - dropCEK(cekJks, stmt); - dropCMK(cmkJks, stmt); - - if (null != cekWin) { - dropCEK(cekWin, stmt); - dropCMK(cmkWin, stmt); - } - - if (null != cekAkv) { - dropCEK(cekAkv, stmt); - dropCMK(cmkAkv, stmt); - } + dropCEK(stmt); + dropCMK(stmt); } } @@ -283,26 +137,46 @@ private static void readFromFile(String inputFile, String lookupValue) throws IO } /** - * Create AE test tables + * Create encrypted table for Binary * - * @param tableName - * name of test table - * @param table - * 2d array containing table column definitions * @throws SQLException */ - protected static void createTable(String tableName, String cekName, String table[][]) throws SQLException { + protected static void createBinaryTable() throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(Constants.BINARY_TABLE_AE) + " (" + + "PlainBinary binary(20) null," + + "RandomizedBinary binary(20) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicBinary binary(20) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainVarbinary varbinary(50) null," + + "RandomizedVarbinary varbinary(50) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicVarbinary varbinary(50) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainVarbinaryMax varbinary(max) null," + + "RandomizedVarbinaryMax varbinary(max) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicVarbinaryMax varbinary(max) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainBinary512 binary(512) null," + + "RandomizedBinary512 binary(512) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicBinary512 binary(512) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainBinary8000 varbinary(8000) null," + + "RandomizedBinary8000 varbinary(8000) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicBinary8000 varbinary(8000) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + ");"; + try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String sql = ""; - for (int i = 0; i < table.length; i++) { - sql += ColumnType.PLAIN.name() + table[i][0] + " " + table[i][1] + " NULL,"; - sql += ColumnType.DETERMINISTIC.name() + table[i][0] + " " + table[i][1] - + String.format(encryptSql, ColumnType.DETERMINISTIC.name(), cekName) + ") NULL,"; - sql += ColumnType.RANDOMIZED.name() + table[i][0] + " " + table[i][1] - + String.format(encryptSql, ColumnType.RANDOMIZED.name(), cekName) + ") NULL,"; - } - sql = String.format(createSql, AbstractSQLGenerator.escapeIdentifier(tableName), sql); stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { @@ -310,33 +184,71 @@ protected static void createTable(String tableName, String cekName, String table } } - protected static void createPrecisionTable(String tableName, String table[][], String cekName, int floatPrecision, - int precision, int scale) throws SQLException { + /** + * Create encrypted table for Char + * + * @throws SQLException + */ + protected static void createCharTable() throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE) + " (" + + "PlainChar char(20) null," + + "RandomizedChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainVarchar varchar(50) null," + + "RandomizedVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainVarcharMax varchar(max) null," + + "RandomizedVarcharMax varchar(max) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicVarcharMax varchar(max) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainNchar nchar(30) null," + + "RandomizedNchar nchar(30) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicNchar nchar(30) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainNvarchar nvarchar(60) null," + + "RandomizedNvarchar nvarchar(60) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicNvarchar nvarchar(60) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainNvarcharMax nvarchar(max) null," + + "RandomizedNvarcharMax nvarchar(max) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicNvarcharMax nvarchar(max) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainUniqueidentifier uniqueidentifier null," + + "RandomizedUniqueidentifier uniqueidentifier ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicUniqueidentifier uniqueidentifier ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainVarchar8000 varchar(8000) null," + + "RandomizedVarchar8000 varchar(8000) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicVarchar8000 varchar(8000) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainNvarchar4000 nvarchar(4000) null," + + "RandomizedNvarchar4000 nvarchar(4000) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicNvarchar4000 nvarchar(4000) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + ");"; + try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String sql = ""; - for (int i = 0; i < table.length; i++) { - if ("float" == table[i][1]) { - sql += ColumnType.PLAIN.name() + table[i][0] + "Precision " + table[i][1] + "(" + floatPrecision - + ") NULL,"; - sql += ColumnType.RANDOMIZED.name() + table[i][0] + "Precision " + table[i][1] + "(" - + floatPrecision + ") " + String.format(encryptSql, ColumnType.RANDOMIZED.name(), cekName) - + ") NULL,"; - sql += ColumnType.DETERMINISTIC.name() + table[i][0] + "Precision " + table[i][1] + "(" - + floatPrecision + ") " - + String.format(encryptSql, ColumnType.DETERMINISTIC.name(), cekName) + ") NULL,"; - } else { - sql += ColumnType.PLAIN.name() + table[i][0] + "Precision " + table[i][1] + "(" + precision + "," - + scale + ") NULL,"; - sql += ColumnType.RANDOMIZED.name() + table[i][0] + "Precision " + table[i][1] + "(" + precision - + "," + scale + ") " + String.format(encryptSql, ColumnType.RANDOMIZED.name(), cekName) - + ") NULL,"; - sql += ColumnType.DETERMINISTIC.name() + table[i][0] + "Precision " + table[i][1] + "(" + precision - + "," + scale + ") " + String.format(encryptSql, ColumnType.DETERMINISTIC.name(), cekName) - + ") NULL,"; - } - } - sql = String.format(createSql, AbstractSQLGenerator.escapeIdentifier(tableName), sql); stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { @@ -344,27 +256,303 @@ protected static void createPrecisionTable(String tableName, String table[][], S } } - protected static void createScaleTable(String tableName, String table[][], String cekName, - int scale) throws SQLException { + /** + * Create encrypted table for Date + * + * @throws SQLException + */ + protected void createDateTable() throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " (" + + "PlainDate date null," + + "RandomizedDate date ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDate date ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainDatetime2Default datetime2 null," + + "RandomizedDatetime2Default datetime2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDatetime2Default datetime2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainDatetimeoffsetDefault datetimeoffset null," + + "RandomizedDatetimeoffsetDefault datetimeoffset ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDatetimeoffsetDefault datetimeoffset ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainTimeDefault time null," + + "RandomizedTimeDefault time ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicTimeDefault time ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainDatetime datetime null," + + "RandomizedDatetime datetime ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDatetime datetime ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainSmalldatetime smalldatetime null," + + "RandomizedSmalldatetime smalldatetime ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicSmalldatetime smalldatetime ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + ");"; + try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String sql = ""; - for (int i = 0; i < table.length; i++) { + stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); + } catch (SQLException e) { + fail(e.getMessage()); + } + } - sql += ColumnType.PLAIN.name() + table[i][0] + "Scale " + table[i][1] + "(" + scale + ") NULL,"; - sql += ColumnType.RANDOMIZED.name() + table[i][0] + "Scale " + table[i][1] + "(" + scale + ") " - + String.format(encryptSql, ColumnType.RANDOMIZED.name(), cekName) + ") NULL,"; - sql += ColumnType.DETERMINISTIC.name() + table[i][0] + "Scale " + table[i][1] + "(" + scale + ") " - + String.format(encryptSql, ColumnType.DETERMINISTIC.name(), cekName) + ") NULL,"; + /** + * Create encrypted table for Date with precision + * + * @throws SQLException + */ + protected void createDatePrecisionTable(int scale) throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " (" + // 1 + + "PlainDatetime2 datetime2(" + scale + ") null," + "RandomizedDatetime2 datetime2(" + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + "DeterministicDatetime2 datetime2(" + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + // 4 + + "PlainDatetime2Default datetime2 null," + + "RandomizedDatetime2Default datetime2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDatetime2Default datetime2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + // 7 + + "PlainDatetimeoffsetDefault datetimeoffset null," + + "RandomizedDatetimeoffsetDefault datetimeoffset ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDatetimeoffsetDefault datetimeoffset ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + // 10 + + "PlainTimeDefault time null," + + "RandomizedTimeDefault time ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicTimeDefault time ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + // 13 + + "PlainTime time(" + scale + ") null," + "RandomizedTime time(" + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + "DeterministicTime time(" + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + // 16 + + "PlainDatetimeoffset datetimeoffset(" + scale + ") null," + "RandomizedDatetimeoffset datetimeoffset(" + + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + "DeterministicDatetimeoffset datetimeoffset(" + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + ");"; - sql += ColumnType.PLAIN.name() + table[i][0] + " " + table[i][1] + " NULL,"; - sql += ColumnType.RANDOMIZED.name() + table[i][0] + " " + table[i][1] - + String.format(encryptSql, ColumnType.RANDOMIZED.name(), cekName) + ") NULL,"; - sql += ColumnType.DETERMINISTIC.name() + table[i][0] + " " + table[i][1] - + String.format(encryptSql, ColumnType.DETERMINISTIC.name(), cekName) + ") NULL,"; - } + try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); + } catch (SQLException e) { + fail(e.getMessage()); + } + } + + /** + * Create encrypted table for Date with scale + * + * @throws SQLException + */ + protected static void createDateScaleTable() throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(Constants.SCALE_DATE_TABLE_AE) + " (" + + + "PlainDatetime2 datetime2(2) null," + + "RandomizedDatetime2 datetime2(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDatetime2 datetime2(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainTime time(2) null," + + "RandomizedTime time(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicTime time(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainDatetimeoffset datetimeoffset(2) null," + + "RandomizedDatetimeoffset datetimeoffset(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDatetimeoffset datetimeoffset(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + ");"; + + try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); + } catch (SQLException e) { + fail(e.getMessage()); + } + } + + /** + * Create encrypted table for Numeric + * + * @throws SQLException + */ + protected static void createNumericTable() throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " (" + + "PlainBit bit null," + + "RandomizedBit bit ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicBit bit ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainTinyint tinyint null," + + "RandomizedTinyint tinyint ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicTinyint tinyint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainSmallint smallint null," + + "RandomizedSmallint smallint ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicSmallint smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainInt int null," + + "RandomizedInt int ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicInt int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainBigint bigint null," + + "RandomizedBigint bigint ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicBigint bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainFloatDefault float null," + + "RandomizedFloatDefault float ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicFloatDefault float ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainFloat float(30) null," + + "RandomizedFloat float(30) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicFloat float(30) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainReal real null," + + "RandomizedReal real ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicReal real ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainDecimalDefault decimal null," + + "RandomizedDecimalDefault decimal ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDecimalDefault decimal ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainDecimal decimal(10,5) null," + + "RandomizedDecimal decimal(10,5) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDecimal decimal(10,5) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainNumericDefault numeric null," + + "RandomizedNumericDefault numeric ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicNumericDefault numeric ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainNumeric numeric(8,2) null," + + "RandomizedNumeric numeric(8,2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicNumeric numeric(8,2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainSmallMoney smallmoney null," + + "RandomizedSmallMoney smallmoney ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicSmallMoney smallmoney ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainMoney money null," + + "RandomizedMoney money ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicMoney money ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainDecimal2 decimal(28,4) null," + + "RandomizedDecimal2 decimal(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDecimal2 decimal(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainNumeric2 numeric(28,4) null," + + "RandomizedNumeric2 numeric(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicNumeric2 numeric(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + ");"; + + try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { + stmt.execute(sql); + stmt.execute("DBCC FREEPROCCACHE"); + } catch (SQLException e) { + fail(e.getMessage()); + } + } + + /** + * Create encrypted table for Numeric with precision + * + * @throws SQLException + */ + protected void createNumericPrecisionTable(int floatPrecision, int precision, int scale) throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " (" + + "PlainFloat float(" + floatPrecision + ") null," + "RandomizedFloat float(" + floatPrecision + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + "DeterministicFloat float(" + floatPrecision + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainDecimal decimal(" + precision + "," + scale + ") null," + "RandomizedDecimal decimal(" + + precision + "," + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + "DeterministicDecimal decimal(" + precision + "," + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainNumeric numeric(" + precision + "," + scale + ") null," + "RandomizedNumeric numeric(" + + precision + "," + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + "DeterministicNumeric numeric(" + precision + "," + scale + + ") ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL" + + + ");"; - sql = String.format(createSql, AbstractSQLGenerator.escapeIdentifier(tableName), sql); + try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); + SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { stmt.execute(sql); stmt.execute("DBCC FREEPROCCACHE"); } catch (SQLException e) { @@ -485,15 +673,13 @@ protected static LinkedList createTemporalTypes(boolean nullable) { * @param keyPath * @throws SQLException */ - private static void createCMK(String cmkName, String keyStoreName, String keyPath, - String signature) throws SQLException { + private static void createCMK(String keyStoreName, String keyPath) throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil - .getConnection(AETestConnectionString + ";sendTimeAsDateTime=false", AEInfo); + .getConnection(connectionString + ";sendTimeAsDateTime=false", AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String sql = " if not exists (SELECT name from sys.column_master_keys where name='" + cmkName + "')" - + " begin" + " CREATE COLUMN MASTER KEY " + cmkName + " WITH (KEY_STORE_PROVIDER_NAME = '" - + keyStoreName + "', KEY_PATH = '" + keyPath + "'" - + (TestUtils.isAEv2(con) ? ",ENCLAVE_COMPUTATIONS (SIGNATURE = " + signature + ")) end" : ") end"); + String sql = " if not exists (SELECT name from sys.column_master_keys where name='" + Constants.CMK_NAME + + "')" + " begin" + " CREATE COLUMN MASTER KEY " + Constants.CMK_NAME + + " WITH (KEY_STORE_PROVIDER_NAME = '" + keyStoreName + "', KEY_PATH = '" + keyPath + "')" + " end"; stmt.execute(sql); } } @@ -505,29 +691,17 @@ private static void createCMK(String cmkName, String keyStoreName, String keyPat * @param certStore * @throws SQLException */ - private static void createCEK(String cmkName, String cekName, - SQLServerColumnEncryptionKeyStoreProvider storeProvider) throws SQLException { + private static void createCEK(SQLServerColumnEncryptionKeyStoreProvider storeProvider) throws SQLException { try (SQLServerConnection con = (SQLServerConnection) PrepUtil - .getConnection(AETestConnectionString + ";sendTimeAsDateTime=false", AEInfo); + .getConnection(connectionString + ";sendTimeAsDateTime=false", AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { byte[] valuesDefault = Constants.CEK_STRING.getBytes(); - String encryptedValue; - - if (storeProvider instanceof SQLServerColumnEncryptionJavaKeyStoreProvider) { - byte[] key = storeProvider.encryptColumnEncryptionKey(javaKeyAliases, Constants.CEK_ALGORITHM, - valuesDefault); - encryptedValue = "0x" + TestUtils.bytesToHexString(key, key.length); - } else if (storeProvider instanceof SQLServerColumnEncryptionAzureKeyVaultProvider) { - byte[] key = storeProvider.encryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, - valuesDefault); - encryptedValue = "0x" + TestUtils.bytesToHexString(key, key.length); - } else { - encryptedValue = Constants.CEK_ENCRYPTED_VALUE; - } - - String cekSql = "CREATE COLUMN ENCRYPTION KEY " + cekName + " WITH VALUES " + "(COLUMN_MASTER_KEY = " - + cmkName + ", ALGORITHM = '" + Constants.CEK_ALGORITHM + "', ENCRYPTED_VALUE = " + encryptedValue - + ");"; + String cekSql = null; + byte[] key = storeProvider.encryptColumnEncryptionKey(javaKeyAliases, Constants.CEK_ALGORITHM, + valuesDefault); + cekSql = "CREATE COLUMN ENCRYPTION KEY " + Constants.CEK_NAME + " WITH VALUES " + "(COLUMN_MASTER_KEY = " + + Constants.CMK_NAME + ", ALGORITHM = '" + Constants.CEK_ALGORITHM + "', ENCRYPTED_VALUE = 0x" + + TestUtils.bytesToHexString(key, key.length) + ");"; stmt.execute(cekSql); } } @@ -538,10 +712,10 @@ private static void createCEK(String cmkName, String cekName, * @throws SQLException */ protected static void dropTables(Statement stmt) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.BINARY_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE), stmt); } /** @@ -551,8 +725,8 @@ protected static void dropTables(Statement stmt) throws SQLException { * @throws SQLException */ protected static void populateBinaryNormalCase(LinkedList byteValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.BINARY_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil .getConnection(connectionString + ";sendTimeAsDateTime=false", AEInfo); @@ -615,8 +789,8 @@ protected static void populateBinaryNormalCase(LinkedList byteValues) th * @throws SQLException */ protected static void populateBinarySetObject(LinkedList byteValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.BINARY_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { @@ -677,8 +851,8 @@ protected static void populateBinarySetObject(LinkedList byteValues) thr * @throws SQLException */ protected static void populateBinarySetObjectWithJDBCType(LinkedList byteValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.BINARY_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -739,8 +913,8 @@ protected static void populateBinarySetObjectWithJDBCType(LinkedList byt * @throws SQLException */ protected static void populateBinaryNullCase() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.BINARY_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -777,8 +951,8 @@ protected static void populateBinaryNullCase() throws SQLException { * @throws SQLException */ protected static void populateCharNormalCase(String[] charValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -844,8 +1018,8 @@ protected static void populateCharNormalCase(String[] charValues) throws SQLExce * @throws SQLException */ protected static void populateCharSetObject(String[] charValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -907,8 +1081,8 @@ protected static void populateCharSetObject(String[] charValues) throws SQLExcep * @throws SQLException */ protected static void populateCharSetObjectWithJDBCTypes(String[] charValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -969,8 +1143,8 @@ protected static void populateCharSetObjectWithJDBCTypes(String[] charValues) th * @throws SQLException */ protected static void populateCharNullCase() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1023,12 +1197,13 @@ protected static void populateCharNullCase() throws SQLException { * @throws SQLException */ protected static void populateDateNormalCase(LinkedList dateValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { + // date for (int i = 1; i <= 3; i++) { pstmt.setDate(i, (Date) dateValues.get(0)); @@ -1070,7 +1245,7 @@ protected static void populateDateNormalCase(LinkedList dateValues) thro * @throws SQLException */ protected static void populateDateScaleNormalCase(LinkedList dateValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(SCALE_DATE_TABLE_AE) + " values( " + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.SCALE_DATE_TABLE_AE) + " values( " + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); @@ -1105,8 +1280,8 @@ protected static void populateDateScaleNormalCase(LinkedList dateValues) */ protected static void populateDateSetObject(LinkedList dateValues, String setter) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1172,8 +1347,8 @@ else if (setter.equalsIgnoreCase("setwithJDBCType")) * @throws SQLException */ protected void populateDateSetObjectNull() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1219,8 +1394,8 @@ protected void populateDateSetObjectNull() throws SQLException { * @throws SQLException */ protected static void populateDateNullCase() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1267,9 +1442,9 @@ protected static void populateDateNullCase() throws SQLException { * @throws SQLException */ protected static void populateNumeric(String[] values) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1376,9 +1551,9 @@ protected static void populateNumeric(String[] values) throws SQLException { * @throws SQLException */ protected static void populateNumericSetObject(String[] values) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1485,9 +1660,9 @@ protected static void populateNumericSetObject(String[] values) throws SQLExcept * @throws SQLException */ protected static void populateNumericSetObjectWithJDBCTypes(String[] values) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1593,9 +1768,9 @@ protected static void populateNumericSetObjectWithJDBCTypes(String[] values) thr * @throws SQLException */ protected static void populateNumericSetObjectNull() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1692,9 +1867,9 @@ protected static void populateNumericSetObjectNull() throws SQLException { * @throws SQLException */ protected static void populateNumericNullCase(String[] values) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; @@ -1792,9 +1967,9 @@ protected static void populateNumericNullCase(String[] values) throws SQLExcepti * @throws SQLException */ protected static void populateNumericNormalCase(String[] numericValues) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; @@ -1903,9 +2078,9 @@ protected static void populateNumericNormalCase(String[] numericValues) throws S * * @throws SQLException */ - private static void dropCEK(String cekName, Statement stmt) throws SQLException { - String cekSql = " if exists (SELECT name from sys.column_encryption_keys where name='" + cekName + "')" - + " begin" + " drop column encryption key " + cekName + " end"; + private static void dropCEK(Statement stmt) throws SQLException { + String cekSql = " if exists (SELECT name from sys.column_encryption_keys where name='" + Constants.CEK_NAME + + "')" + " begin" + " drop column encryption key " + Constants.CEK_NAME + " end"; stmt.execute(cekSql); } @@ -1914,9 +2089,10 @@ private static void dropCEK(String cekName, Statement stmt) throws SQLException * * @throws SQLException */ - private static void dropCMK(String cmkName, Statement stmt) throws SQLException { - String cekSql = " if exists (SELECT name from sys.column_master_keys where name='" + cmkName + "')" + " begin" - + " drop column master key " + cmkName + " end"; + private static void dropCMK(Statement stmt) throws SQLException { + String cekSql = " if exists (SELECT name from sys.column_master_keys where name='" + Constants.CMK_NAME + "')" + + " begin" + " drop column master key " + Constants.CMK_NAME + " end"; stmt.execute(cekSql); } + } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java index 75ab29256..f52cc3704 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/CallableStatementTest.java @@ -84,17 +84,6 @@ public class CallableStatementTest extends AESetup { private static LinkedList dateValues; private static boolean nullable = false; - static String SP_table1[][] = {{"Char", "char(20) COLLATE Latin1_General_BIN2"}, - {"Varchar", "varchar(50) COLLATE Latin1_General_BIN2"},}; - static String SP_table2[][] = {{"Char", "char(20) COLLATE Latin1_General_BIN2"}, - {"Varchar", "varchar(50) COLLATE Latin1_General_BIN2"},}; - static String SP_table3[][] = {{"Bit", "bit"}, {"Tinyint", "tinyint"}, {"Smallint", "smallint"}, {"Int", "int"}, - {"BigInt", "bigint"}, {"FloatDefault", "float"}, {"Float", "float(30)"}, {"Real", "real"}, - {"DecimalDefault", "decimal(18,0)"}, {"Decimal", "decimal(10,5)"}, {"NumericDefault", "numeric(18,0)"}, - {"Numeric", "numeric(8,2)"}, {"Int2", "int"}, {"SmallMoney", "smallmoney"}, {"Money", "money"}, - {"Decimal2", "decimal(28,4)"}, {"Numeric2", "numeric(28,4)"},}; - static String SP_table4[][] = {{"Int", "int"},}; - /** * Initialize the tables for this class. This method will execute AFTER the parent class (AESetup) finishes * initializing. @@ -110,21 +99,20 @@ public static void initCallableStatementTest() throws Exception { dateValues = createTemporalTypesCallableStatement(nullable); charValues = createCharValues(nullable); - createTables(cekJks); + createTables(); populateTable3(); populateTable4(); - createTable(CHAR_TABLE_AE, cekJks, charTable); - createTable(NUMERIC_TABLE_AE, cekJks, numericTable); - createTable(BINARY_TABLE_AE, cekJks, binaryTable); - - createDateTableCallableStatement(cekJks); + createCharTable(); + createNumericTable(); + createBinaryTable(); + createDateTableCallableStatement(); populateCharNormalCase(charValues); populateNumericSetObject(numericValues); populateBinaryNormalCase(byteValues); populateDateNormalCase(); - createTable(SCALE_DATE_TABLE_AE, cekJks, dateScaleTable); + createDateScaleTable(); populateDateScaleNormalCase(dateValues); } @@ -320,29 +308,188 @@ private static void dropTables() throws SQLException { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table3), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table4), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.BINARY_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table5), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table6), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(SCALE_DATE_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.SCALE_DATE_TABLE_AE), stmt); } } - private static void createTables(String cekName) throws SQLException { - createTable(table1, cekJks, SP_table1); - createTable(table2, cekJks, SP_table2); - createTable(table3, cekJks, SP_table3); - createTable(table4, cekJks, SP_table4); + private static void createTables() throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(table1) + " (" + "PlainChar char(20) null," + + "RandomizedChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainVarchar varchar(50) null," + + "RandomizedVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL" + ");"; + + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { + stmt.execute(sql); + } catch (SQLException e) { + fail(e.getMessage()); + } + + sql = "create table " + AbstractSQLGenerator.escapeIdentifier(table2) + " (" + "PlainChar char(20) null," + + "RandomizedChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainVarchar varchar(50) null," + + "RandomizedVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL" + + + ");"; + + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { + stmt.execute(sql); + } catch (SQLException e) { + fail(e.getMessage()); + } + + sql = "create table " + AbstractSQLGenerator.escapeIdentifier(table3) + " (" + "PlainBit bit null," + + "RandomizedBit bit ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicBit bit ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainTinyint tinyint null," + + "RandomizedTinyint tinyint ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicTinyint tinyint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainSmallint smallint null," + + "RandomizedSmallint smallint ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicSmallint smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainInt int null," + + "RandomizedInt int ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicInt int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainBigint bigint null," + + "RandomizedBigint bigint ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicBigint bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainFloatDefault float null," + + "RandomizedFloatDefault float ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicFloatDefault float ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainFloat float(30) null," + + "RandomizedFloat float(30) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicFloat float(30) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainReal real null," + + "RandomizedReal real ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicReal real ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainDecimalDefault decimal(18,0) null," + + "RandomizedDecimalDefault decimal(18,0) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDecimalDefault decimal(18,0) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainDecimal decimal(10,5) null," + + "RandomizedDecimal decimal(10,5) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDecimal decimal(10,5) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainNumericDefault numeric(18,0) null," + + "RandomizedNumericDefault numeric(18,0) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicNumericDefault numeric(18,0) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainNumeric numeric(8,2) null," + + "RandomizedNumeric numeric(8,2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicNumeric numeric(8,2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainInt2 int null," + + "RandomizedInt2 int ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicInt2 int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainSmallMoney smallmoney null," + + "RandomizedSmallMoney smallmoney ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicSmallMoney smallmoney ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainMoney money null," + + "RandomizedMoney money ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicMoney money ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainDecimal2 decimal(28,4) null," + + "RandomizedDecimal2 decimal(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicDecimal2 decimal(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + "PlainNumeric2 numeric(28,4) null," + + "RandomizedNumeric2 numeric(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicNumeric2 numeric(28,4) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + + ");"; + + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { + stmt.execute(sql); + } catch (SQLException e) { + fail(e.getMessage()); + } + + sql = "create table " + AbstractSQLGenerator.escapeIdentifier(table4) + " (" + "PlainInt int null," + + "RandomizedInt int ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicInt int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + ");"; + + try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); + Statement stmt = con.createStatement()) { + stmt.execute(sql); + } catch (SQLException e) { + fail(e.getMessage()); + } - String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(table5) + " (" + sql = "create table " + AbstractSQLGenerator.escapeIdentifier(table5) + " (" + "c1 int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekJks + ") NULL," + + Constants.CEK_NAME + ") NULL," + "c2 smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekJks + ") NULL," + + Constants.CEK_NAME + ") NULL," + "c3 bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekJks + ") NULL," + ");"; + + Constants.CEK_NAME + ") NULL," + ");"; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); Statement stmt = con.createStatement()) { @@ -353,11 +500,11 @@ private static void createTables(String cekName) throws SQLException { sql = "create table " + AbstractSQLGenerator.escapeIdentifier(table6) + " (" + "c1 int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "c2 smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "c3 bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + ");"; + + Constants.CEK_NAME + ") NULL," + ");"; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); Statement stmt = con.createStatement()) { @@ -577,7 +724,7 @@ private void createInputProcedure() throws SQLException { + "@p2 float, @p3 real, @p4 numeric(18, 0), @p5 smallmoney, @p6 money," + "@p7 bit, @p8 smallint, @p9 bigint, @p10 float(30), @p11 decimal(10,5), @p12 numeric(8,2), " + "@p13 decimal(28,4), @p14 numeric(28,4) " + " AS" + " SELECT top 1 RandomizedInt FROM " - + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " where DeterministicInt=@p0 and DeterministicDecimalDefault=@p1 and " + " DeterministicFloatDefault=@p2 and DeterministicReal=@p3 and DeterministicNumericDefault=@p4 and" + " DeterministicSmallMoney=@p5 and DeterministicMoney=@p6 and DeterministicBit=@p7 and" @@ -642,7 +789,7 @@ private void createInputProcedure2() throws SQLException { + " @p6 varchar(8000), @p7 nvarchar(4000)" + " AS" + " SELECT top 1 RandomizedVarchar, DeterministicUniqueidentifier, DeterministicVarcharMax, RandomizedNchar, " + " DeterministicNvarchar, DeterministicNvarcharMax, DeterministicVarchar8000, RandomizedNvarchar4000 FROM " - + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) + + AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE) + " where DeterministicVarchar = @p0 and DeterministicUniqueidentifier =@p1"; stmt.execute(sql); @@ -1457,7 +1604,7 @@ private void createOutputProcedureChar() throws SQLException { + " AS" + " SELECT top 1 @p0=DeterministicChar,@p1=RandomizedVarChar,@p2=RandomizedNChar," + " @p3=DeterministicNVarChar, @p4=DeterministicUniqueidentifier, @p5=DeterministicVarcharMax," + " @p6=DeterministicNvarcharMax, @p7=DeterministicVarchar8000, @p8=RandomizedNvarchar4000 FROM " - + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE); + + AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE); stmt.execute(sql); } @@ -1585,7 +1732,7 @@ private void createOutputProcedureNumeric() throws SQLException { + " @p7=RandomizedReal, @p8=DeterministicDecimalDefault, @p9=RandomizedDecimal," + " @p10=DeterministicNumericDefault, @p11=RandomizedNumeric, @p12=RandomizedSmallMoney, @p13=DeterministicMoney," + " @p14=DeterministicDecimal2, @p15=DeterministicNumeric2 FROM " - + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE); + + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE); stmt.execute(sql); } @@ -1977,7 +2124,7 @@ private void createOutputProcedureBinary() throws SQLException { + " @p3 binary(512) OUTPUT,@p4 varbinary(8000) OUTPUT " + " AS" + " SELECT top 1 @p0=RandomizedBinary,@p1=DeterministicVarbinary,@p2=DeterministicVarbinaryMax," + " @p3=DeterministicBinary512,@p4=DeterministicBinary8000 FROM " - + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE); + + AbstractSQLGenerator.escapeIdentifier(Constants.BINARY_TABLE_AE); stmt.execute(sql); } @@ -2112,61 +2259,61 @@ private void testOutputProcedureBinaryInorderString(String sql) throws SQLExcept } } - protected static void createDateTableCallableStatement(String cekName) throws SQLException { - String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " (" + protected static void createDateTableCallableStatement() throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " (" + "PlainDate date null," + "RandomizedDate date ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "DeterministicDate date ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "PlainDatetime2Default datetime2 null," + "RandomizedDatetime2Default datetime2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "DeterministicDatetime2Default datetime2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "PlainDatetimeoffsetDefault datetimeoffset null," + "RandomizedDatetimeoffsetDefault datetimeoffset ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "DeterministicDatetimeoffsetDefault datetimeoffset ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "PlainTimeDefault time null," + "RandomizedTimeDefault time ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "DeterministicTimeDefault time ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "PlainDatetime2 datetime2(2) null," + "RandomizedDatetime2 datetime2(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "DeterministicDatetime2 datetime2(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "PlainTime time(2) null," + "RandomizedTime time(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "DeterministicTime time(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "PlainDatetimeoffset datetimeoffset(2) null," + "RandomizedDatetimeoffset datetimeoffset(2) ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "DeterministicDatetimeoffset datetimeoffset(2) ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "PlainDateTime DateTime null," + "RandomizedDateTime DateTime ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "DeterministicDateTime DateTime ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "PlainSmallDatetime smalldatetime null," + "RandomizedSmallDatetime smalldatetime ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + "DeterministicSmallDatetime smalldatetime ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " - + cekName + ") NULL," + + Constants.CEK_NAME + ") NULL," + ");"; @@ -2206,8 +2353,8 @@ private static LinkedList createTemporalTypesCallableStatement(boolean n } private static void populateDateNormalCase() throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement sqlPstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -2281,7 +2428,7 @@ private void createOutputProcedureDate() throws SQLException { + " @p4=PlainDateTime,@p41=DeterministicDateTime, @p5=PlainSmallDateTime,@p51=RandomizedSmallDateTime, " + " @p6=PlainDatetime2,@p61=RandomizedDatetime2, @p7=PlainTime,@p71=Deterministictime, " + " @p8=PlainDatetimeoffset, @p81=RandomizedDatetimeoffset" + " FROM " - + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE); + + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE); stmt.execute(sql); } @@ -2478,7 +2625,7 @@ private void createMixedProcedureDateScale() throws SQLException { + " AS" + " SELECT top 1 @p1=DeterministicDatetime2,@p2=RandomizedDatetime2,@p3=DeterministicTime,@p4=RandomizedTime," + " @p5=DeterministicDatetimeoffset,@p6=RandomizedDatetimeoffset " + " FROM " - + AbstractSQLGenerator.escapeIdentifier(SCALE_DATE_TABLE_AE) + + AbstractSQLGenerator.escapeIdentifier(Constants.SCALE_DATE_TABLE_AE) + " where DeterministicDatetime2 = @p1 and DeterministicTime = @p3 and DeterministicDatetimeoffset=@p5"; stmt.execute(sql); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java index b2be22d5e..06fb0e4a1 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/JDBCEncryptionDecryptionTest.java @@ -43,15 +43,16 @@ public class JDBCEncryptionDecryptionTest extends AESetup { private boolean nullable = false; + private String[] numericValues = null; + private String[] numericValues2 = null; + private String[] numericValuesNull = null; + private String[] numericValuesNull2 = null; + private String[] charValues = null; - enum TestCase { - NORMAL, - SETOBJECT, - SETOBJECT_WITH_JDBCTYPES, - SETOBJECT_WITH_JAVATYPES, - SETOBJECT_NULL, - NULL - } + private LinkedList byteValuesSetObject = null; + private LinkedList byteValuesNull = null; + + private LinkedList dateValues = null; /** * Junit test case for char set string for string values @@ -59,30 +60,15 @@ enum TestCase { * @throws SQLException */ @Test - public void testCharSpecificSetter_aev1() throws SQLException { - testCharSpecificSetter(false); - } - - @Tag(Constants.xSQLv15) - @Test - public void testCharSpecificSetter_aev2() throws SQLException { - testCharSpecificSetter(isAEv2Supported); - } - - private void testCharSpecificSetter(boolean isTestEnclave) throws SQLException { + public void testCharSpecificSetter() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values = createCharValues(nullable); - - testChars(stmt, cekJks, charTable, values, TestCase.NORMAL, isTestEnclave); - - if (null != cekWin) { - testChars(stmt, cekWin, charTable, values, TestCase.NORMAL, isTestEnclave); - } - - if (null != cekAkv) { - testChars(stmt, cekAkv, charTable, values, TestCase.NORMAL, isTestEnclave); - } + charValues = createCharValues(nullable); + dropTables(stmt); + createCharTable(); + populateCharNormalCase(charValues); + testChar(stmt, charValues); + testChar(null, charValues); } } @@ -92,31 +78,15 @@ private void testCharSpecificSetter(boolean isTestEnclave) throws SQLException { * @throws SQLException */ @Test - public void testCharSetObject_aev1() throws SQLException { - testCharSetObject(false); - } - - @Tag(Constants.xSQLv15) - @Test - public void testCharSetObject_aev2() throws SQLException { - testCharSetObject(isAEv2Supported); - } - - private void testCharSetObject(boolean isTestEnclave) throws SQLException { + public void testCharSetObject() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values = createCharValues(nullable); - - testChars(stmt, cekJks, charTable, values, TestCase.SETOBJECT, isTestEnclave); - - if (null != cekWin) { - testChars(stmt, cekWin, charTable, values, TestCase.SETOBJECT, isTestEnclave); - } - - if (null != cekAkv) { - testChars(stmt, cekAkv, charTable, values, TestCase.SETOBJECT, isTestEnclave); - } - + charValues = createCharValues(nullable); + dropTables(stmt); + createCharTable(); + populateCharSetObject(charValues); + testChar(stmt, charValues); + testChar(null, charValues); } } @@ -126,31 +96,16 @@ private void testCharSetObject(boolean isTestEnclave) throws SQLException { * @throws SQLException */ @Test - public void testCharSetObjectWithJDBCTypes_aev1() throws SQLException { - testCharSetObjectWithJDBCTypes(false); - } - - @Tag(Constants.xSQLv15) - @Test - public void testCharSetObjectWithJDBCTypes_aev2() throws SQLException { - testCharSetObjectWithJDBCTypes(isAEv2Supported); - } - - private void testCharSetObjectWithJDBCTypes(boolean isTestEnclave) throws SQLException { + public void testCharSetObjectWithJDBCTypes() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values = createCharValues(nullable); - - testChars(stmt, cekJks, charTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, isTestEnclave); - - if (null != cekWin) { - testChars(stmt, cekWin, charTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, isTestEnclave); - } - - if (null != cekAkv) { - testChars(stmt, cekAkv, charTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES, isTestEnclave); - } + charValues = createCharValues(nullable); + dropTables(stmt); + createCharTable(); + populateCharSetObjectWithJDBCTypes(charValues); + testChar(stmt, charValues); + testChar(null, charValues); } } @@ -161,29 +116,14 @@ private void testCharSetObjectWithJDBCTypes(boolean isTestEnclave) throws SQLExc */ @Test public void testCharSpecificSetterNull() throws SQLException { - testCharSpecificSetterNull(false); - } - - @Tag(Constants.xSQLv15) - @Test - public void testCharSpecificSetterNull_aev2() throws SQLException { - testCharSpecificSetterNull(isAEv2Supported); - } - - private void testCharSpecificSetterNull(boolean isTestEnclave) throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values = {null, null, null, null, null, null, null, null, null}; - - testChars(stmt, cekJks, charTable, values, TestCase.NORMAL, isTestEnclave); - - if (null != cekWin) { - testChars(stmt, cekWin, charTable, values, TestCase.NORMAL, isTestEnclave); - } - - if (null != cekAkv) { - testChars(stmt, cekAkv, charTable, values, TestCase.NORMAL, isTestEnclave); - } + String[] charValuesNull = {null, null, null, null, null, null, null, null, null}; + dropTables(stmt); + createCharTable(); + populateCharNormalCase(charValuesNull); + testChar(stmt, charValuesNull); + testChar(null, charValuesNull); } } @@ -193,30 +133,15 @@ private void testCharSpecificSetterNull(boolean isTestEnclave) throws SQLExcepti * @throws SQLException */ @Test - public void testCharSetObjectNull_aev1() throws SQLException { - testCharSetObjectNull(false); - } - - @Tag(Constants.xSQLv15) - @Test - public void testCharSetObjectNull_aev2() throws SQLException { - testCharSetObjectNull(isAEv2Supported); - } - - private void testCharSetObjectNull(boolean isTestEnclave) throws SQLException { + public void testCharSetObjectNull() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values = {null, null, null, null, null, null, null, null, null}; - - testChars(stmt, cekJks, charTable, values, TestCase.SETOBJECT, isTestEnclave); - - if (null != cekWin) { - testChars(stmt, cekWin, charTable, values, TestCase.SETOBJECT, isTestEnclave); - } - - if (null != cekAkv) { - testChars(stmt, cekAkv, charTable, values, TestCase.SETOBJECT, isTestEnclave); - } + String[] charValuesNull = {null, null, null, null, null, null, null, null, null}; + dropTables(stmt); + createCharTable(); + populateCharSetObject(charValuesNull); + testChar(stmt, charValuesNull); + testChar(null, charValuesNull); } } @@ -226,30 +151,15 @@ private void testCharSetObjectNull(boolean isTestEnclave) throws SQLException { * @throws SQLException */ @Test - public void testCharSetNull_aev1() throws SQLException { - testCharSetNull(false); - } - - @Tag(Constants.xSQLv15) - @Test - public void testCharSetNull_aev2() throws SQLException { - testCharSetNull(isAEv2Supported); - } - - private void testCharSetNull(boolean isTestEnclave) throws SQLException { + public void testCharSetNull() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values = {null, null, null, null, null, null, null, null, null}; - - testChars(stmt, cekJks, charTable, values, TestCase.NULL, isTestEnclave); - - if (null != cekWin) { - testChars(stmt, cekWin, charTable, values, TestCase.NULL, isTestEnclave); - } - - if (null != cekAkv) { - testChars(stmt, cekAkv, charTable, values, TestCase.NULL, isTestEnclave); - } + String[] charValuesNull = {null, null, null, null, null, null, null, null, null}; + dropTables(stmt); + createCharTable(); + populateCharNullCase(); + testChar(stmt, charValuesNull); + testChar(null, charValuesNull); } } @@ -262,17 +172,12 @@ private void testCharSetNull(boolean isTestEnclave) throws SQLException { public void testBinarySpecificSetter() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createbinaryValues(false); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.NORMAL); - - if (null != cekWin) { - testBinaries(stmt, cekWin, binaryTable, values, TestCase.NORMAL); - } - - if (null != cekAkv) { - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.NORMAL); - } + LinkedList byteValues = createbinaryValues(false); + dropTables(stmt); + createBinaryTable(); + populateBinaryNormalCase(byteValues); + testBinary(stmt, byteValues); + testBinary(null, byteValues); } } @@ -285,17 +190,12 @@ public void testBinarySpecificSetter() throws SQLException { public void testBinarySetobject() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createbinaryValues(false); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT); - - if (null != cekWin) { - testBinaries(stmt, cekWin, binaryTable, values, TestCase.SETOBJECT); - } - - if (null != cekAkv) { - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT); - } + byteValuesSetObject = createbinaryValues(false); + dropTables(stmt); + createBinaryTable(); + populateBinarySetObject(byteValuesSetObject); + testBinary(stmt, byteValuesSetObject); + testBinary(null, byteValuesSetObject); } } @@ -308,17 +208,12 @@ public void testBinarySetobject() throws SQLException { public void testBinarySetNull() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createbinaryValues(true); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.NULL); - - if (null != cekWin) { - testBinaries(stmt, cekWin, binaryTable, values, TestCase.NULL); - } - - if (null != cekAkv) { - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.NULL); - } + byteValuesNull = createbinaryValues(true); + dropTables(stmt); + createBinaryTable(); + populateBinaryNullCase(); + testBinary(stmt, byteValuesNull); + testBinary(null, byteValuesNull); } } @@ -331,17 +226,12 @@ public void testBinarySetNull() throws SQLException { public void testBinarySpecificSetterNull() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createbinaryValues(true); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.NORMAL); - - if (null != cekWin) { - testBinaries(stmt, cekWin, binaryTable, values, TestCase.NORMAL); - } - - if (null != cekAkv) { - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.NORMAL); - } + byteValuesNull = createbinaryValues(true); + dropTables(stmt); + createBinaryTable(); + populateBinaryNormalCase(null); + testBinary(stmt, byteValuesNull); + testBinary(null, byteValuesNull); } } @@ -354,17 +244,12 @@ public void testBinarySpecificSetterNull() throws SQLException { public void testBinarysetObjectNull() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createbinaryValues(true); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT_NULL); - - if (null != cekWin) { - testBinaries(stmt, cekWin, binaryTable, values, TestCase.SETOBJECT_NULL); - } - - if (null != cekAkv) { - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT_NULL); - } + byteValuesNull = createbinaryValues(true); + dropTables(stmt); + createBinaryTable(); + populateBinarySetObject(null); + testBinary(stmt, byteValuesNull); + testBinary(null, byteValuesNull); } } @@ -378,17 +263,12 @@ public void testBinarySetObjectWithJDBCTypes() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createbinaryValues(false); - - testBinaries(stmt, cekJks, binaryTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES); - - if (null != cekWin) { - testBinaries(stmt, cekWin, binaryTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES); - } - - if (null != cekAkv) { - testBinaries(stmt, cekAkv, binaryTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES); - } + byteValuesSetObject = createbinaryValues(false); + dropTables(stmt); + createBinaryTable(); + populateBinarySetObjectWithJDBCType(byteValuesSetObject); + testBinary(stmt, byteValuesSetObject); + testBinary(null, byteValuesSetObject); } } @@ -401,17 +281,12 @@ public void testBinarySetObjectWithJDBCTypes() throws SQLException { public void testDateSpecificSetter() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); - - testDates(stmt, cekJks, dateTable, values, TestCase.NORMAL); - - if (null != cekWin) { - testDates(stmt, cekWin, dateTable, values, TestCase.NORMAL); - } - - if (null != cekAkv) { - testDates(stmt, cekAkv, dateTable, values, TestCase.NORMAL); - } + dateValues = createTemporalTypes(nullable); + dropTables(stmt); + createDateTable(); + populateDateNormalCase(dateValues); + testDate(stmt, dateValues); + testDate(null, dateValues); } } @@ -424,17 +299,12 @@ public void testDateSpecificSetter() throws SQLException { public void testDateSetObject() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); - - testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT); - - if (null != cekWin) { - testDates(stmt, cekWin, dateTable, values, TestCase.SETOBJECT); - } - - if (null != cekAkv) { - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT); - } + dateValues = createTemporalTypes(nullable); + dropTables(stmt); + createDateTable(); + populateDateSetObject(dateValues, ""); + testDate(stmt, dateValues); + testDate(null, dateValues); } } @@ -447,17 +317,12 @@ public void testDateSetObject() throws SQLException { public void testDateSetObjectWithJavaType() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); - - testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT_WITH_JAVATYPES); - - if (null != cekWin) { - testDates(stmt, cekWin, dateTable, values, TestCase.SETOBJECT_WITH_JAVATYPES); - } - - if (null != cekAkv) { - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_WITH_JAVATYPES); - } + dateValues = createTemporalTypes(nullable); + dropTables(stmt); + createDateTable(); + populateDateSetObject(dateValues, "setwithJavaType"); + testDate(stmt, dateValues); + testDate(null, dateValues); } } @@ -470,17 +335,12 @@ public void testDateSetObjectWithJavaType() throws SQLException { public void testDateSetObjectWithJDBCType() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); - - testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES); - - if (null != cekWin) { - testDates(stmt, cekWin, dateTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES); - } - - if (null != cekAkv) { - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_WITH_JDBCTYPES); - } + dateValues = createTemporalTypes(nullable); + dropTables(stmt); + createDateTable(); + populateDateSetObject(dateValues, "setwithJDBCType"); + testDate(stmt, dateValues); + testDate(null, dateValues); } } @@ -494,17 +354,12 @@ public void testDateSpecificSetterMinMaxValue() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { RandomData.returnMinMax = true; - LinkedList values = createTemporalTypes(nullable); - - testDates(stmt, cekJks, dateTable, values, TestCase.NORMAL); - - if (null != cekWin) { - testDates(stmt, cekWin, dateTable, values, TestCase.NORMAL); - } - - if (null != cekAkv) { - testDates(stmt, cekAkv, dateTable, values, TestCase.NORMAL); - } + dateValues = createTemporalTypes(nullable); + dropTables(stmt); + createDateTable(); + populateDateNormalCase(dateValues); + testDate(stmt, dateValues); + testDate(null, dateValues); } } @@ -519,17 +374,13 @@ public void testDateSetNull() throws SQLException { SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { RandomData.returnNull = true; nullable = true; - LinkedList values = createTemporalTypes(nullable); - testDates(stmt, cekJks, dateTable, values, TestCase.NULL); - - if (null != cekWin) { - testDates(stmt, cekWin, dateTable, values, TestCase.NULL); - } - - if (null != cekAkv) { - testDates(stmt, cekAkv, dateTable, values, TestCase.NULL); - } + dateValues = createTemporalTypes(nullable); + dropTables(stmt); + createDateTable(); + populateDateNullCase(); + testDate(stmt, dateValues); + testDate(null, dateValues); } nullable = false; @@ -548,17 +399,12 @@ public void testDateSetObjectNull() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - LinkedList values = createTemporalTypes(nullable); - - testDates(stmt, cekJks, dateTable, values, TestCase.SETOBJECT_NULL); - - if (null != cekWin) { - testDates(stmt, cekWin, dateTable, values, TestCase.SETOBJECT_NULL); - } - - if (null != cekAkv) { - testDates(stmt, cekAkv, dateTable, values, TestCase.SETOBJECT_NULL); - } + dateValues = createTemporalTypes(nullable); + dropTables(stmt); + createDateTable(); + populateDateSetObjectNull(); + testDate(stmt, dateValues); + testDate(null, dateValues); } nullable = false; @@ -572,22 +418,17 @@ public void testDateSetObjectNull() throws SQLException { */ @Test public void testNumericSpecificSetter() throws TestAbortedException, Exception { + numericValues = createNumericValues(nullable); + numericValues2 = new String[numericValues.length]; + System.arraycopy(numericValues, 0, numericValues2, 0, numericValues.length); + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - - String[] values1 = createNumericValues(nullable); - String[] values2 = new String[values1.length]; - System.arraycopy(values1, 0, values2, 0, values1.length); - - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NORMAL); - - if (null != cekWin) { - testNumerics(stmt, cekWin, numericTable, values1, values2, TestCase.NORMAL); - } - - if (null != cekAkv) { - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL); - } + dropTables(stmt); + createNumericTable(); + populateNumeric(numericValues); + testNumeric(stmt, numericValues, false); + testNumeric(null, numericValues2, false); } } @@ -598,21 +439,17 @@ public void testNumericSpecificSetter() throws TestAbortedException, Exception { */ @Test public void testNumericSetObject() throws SQLException { + numericValues = createNumericValues(nullable); + numericValues2 = new String[numericValues.length]; + System.arraycopy(numericValues, 0, numericValues2, 0, numericValues.length); + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values1 = createNumericValues(nullable); - String[] values2 = new String[values1.length]; - System.arraycopy(values1, 0, values2, 0, values1.length); - - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.SETOBJECT); - - if (null != cekWin) { - testNumerics(stmt, cekWin, numericTable, values1, values2, TestCase.SETOBJECT); - } - - if (null != cekAkv) { - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.SETOBJECT); - } + dropTables(stmt); + createNumericTable(); + populateNumericSetObject(numericValues); + testNumeric(null, numericValues, false); + testNumeric(stmt, numericValues2, false); } } @@ -626,19 +463,15 @@ public void testNumericSetObjectWithJDBCTypes() throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values1 = createNumericValues(nullable); - String[] values2 = new String[values1.length]; - System.arraycopy(values1, 0, values2, 0, values1.length); - - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.SETOBJECT_WITH_JDBCTYPES); - - if (null != cekWin) { - testNumerics(stmt, cekWin, numericTable, values1, values2, TestCase.SETOBJECT_WITH_JDBCTYPES); - } - - if (null != cekAkv) { - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.SETOBJECT_WITH_JDBCTYPES); - } + numericValues = createNumericValues(nullable); + numericValues2 = new String[numericValues.length]; + System.arraycopy(numericValues, 0, numericValues2, 0, numericValues.length); + + dropTables(stmt); + createNumericTable(); + populateNumericSetObjectWithJDBCTypes(numericValues); + testNumeric(stmt, numericValues, false); + testNumeric(null, numericValues2, false); } } @@ -649,27 +482,22 @@ public void testNumericSetObjectWithJDBCTypes() throws SQLException { */ @Test public void testNumericSpecificSetterMaxValue() throws SQLException { + String[] numericValuesBoundaryPositive = {Boolean.TRUE.toString(), "255", "32767", "2147483647", + "9223372036854775807", "1.79E308", "1.123", "3.4E38", "999999999999999999", "12345.12345", + "999999999999999999", "567812.78", "214748.3647", "922337203685477.5807", + "999999999999999999999999.9999", "999999999999999999999999.9999"}; + String[] numericValuesBoundaryPositive2 = {Boolean.TRUE.toString(), "255", "32767", "2147483647", + "9223372036854775807", "1.79E308", "1.123", "3.4E38", "999999999999999999", "12345.12345", + "999999999999999999", "567812.78", "214748.3647", "922337203685477.5807", + "999999999999999999999999.9999", "999999999999999999999999.9999"}; + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - - String[] values1 = {Boolean.TRUE.toString(), "255", "32767", "2147483647", "9223372036854775807", - "1.79E308", "1.123", "3.4E38", "999999999999999999", "12345.12345", "999999999999999999", - "567812.78", "214748.3647", "922337203685477.5807", "999999999999999999999999.9999", - "999999999999999999999999.9999"}; - String[] values2 = {Boolean.TRUE.toString(), "255", "32767", "2147483647", "9223372036854775807", - "1.79E308", "1.123", "3.4E38", "999999999999999999", "12345.12345", "999999999999999999", - "567812.78", "214748.3647", "922337203685477.5807", "999999999999999999999999.9999", - "999999999999999999999999.9999"}; - - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NORMAL); - - if (null != cekWin) { - testNumerics(stmt, cekWin, numericTable, values1, values2, TestCase.NORMAL); - } - - if (null != cekAkv) { - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL); - } + dropTables(stmt); + createNumericTable(); + populateNumeric(numericValuesBoundaryPositive); + testNumeric(stmt, numericValuesBoundaryPositive, false); + testNumeric(null, numericValuesBoundaryPositive2, false); } } @@ -680,26 +508,22 @@ public void testNumericSpecificSetterMaxValue() throws SQLException { */ @Test public void testNumericSpecificSetterMinValue() throws SQLException { + String[] numericValuesBoundaryNegtive = {Boolean.FALSE.toString(), "0", "-32768", "-2147483648", + "-9223372036854775808", "-1.79E308", "1.123", "-3.4E38", "999999999999999999", "12345.12345", + "999999999999999999", "567812.78", "-214748.3648", "-922337203685477.5808", + "999999999999999999999999.9999", "999999999999999999999999.9999"}; + String[] numericValuesBoundaryNegtive2 = {Boolean.FALSE.toString(), "0", "-32768", "-2147483648", + "-9223372036854775808", "-1.79E308", "1.123", "-3.4E38", "999999999999999999", "12345.12345", + "999999999999999999", "567812.78", "-214748.3648", "-922337203685477.5808", + "999999999999999999999999.9999", "999999999999999999999999.9999"}; + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values1 = {Boolean.FALSE.toString(), "0", "-32768", "-2147483648", "-9223372036854775808", - "-1.79E308", "1.123", "-3.4E38", "999999999999999999", "12345.12345", "999999999999999999", - "567812.78", "-214748.3648", "-922337203685477.5808", "999999999999999999999999.9999", - "999999999999999999999999.9999"}; - String[] values2 = {Boolean.FALSE.toString(), "0", "-32768", "-2147483648", "-9223372036854775808", - "-1.79E308", "1.123", "-3.4E38", "999999999999999999", "12345.12345", "999999999999999999", - "567812.78", "-214748.3648", "-922337203685477.5808", "999999999999999999999999.9999", - "999999999999999999999999.9999"}; - - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NORMAL); - - if (null != cekWin) { - testNumerics(stmt, cekWin, numericTable, values1, values2, TestCase.NORMAL); - } - - if (null != cekAkv) { - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL); - } + dropTables(stmt); + createNumericTable(); + populateNumeric(numericValuesBoundaryNegtive); + testNumeric(stmt, numericValuesBoundaryNegtive, false); + testNumeric(null, numericValuesBoundaryNegtive2, false); } } @@ -710,23 +534,19 @@ public void testNumericSpecificSetterMinValue() throws SQLException { */ @Test public void testNumericSpecificSetterNull() throws SQLException { + nullable = true; + RandomData.returnNull = true; + numericValuesNull = createNumericValues(nullable); + numericValuesNull2 = new String[numericValuesNull.length]; + System.arraycopy(numericValuesNull, 0, numericValuesNull2, 0, numericValuesNull.length); + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - nullable = true; - RandomData.returnNull = true; - String[] values1 = createNumericValues(nullable); - String[] values2 = new String[values1.length]; - System.arraycopy(values1, 0, values2, 0, values1.length); - - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NULL); - - if (null != cekWin) { - testNumerics(stmt, cekWin, numericTable, values1, values2, TestCase.NULL); - } - - if (null != cekAkv) { - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NULL); - } + dropTables(stmt); + createNumericTable(); + populateNumericNullCase(numericValuesNull); + testNumeric(stmt, numericValuesNull, true); + testNumeric(null, numericValuesNull2, true); } nullable = false; @@ -740,23 +560,19 @@ public void testNumericSpecificSetterNull() throws SQLException { */ @Test public void testNumericSpecificSetterSetObjectNull() throws SQLException { + nullable = true; + RandomData.returnNull = true; + numericValuesNull = createNumericValues(nullable); + numericValuesNull2 = new String[numericValuesNull.length]; + System.arraycopy(numericValuesNull, 0, numericValuesNull2, 0, numericValuesNull.length); + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - nullable = true; - RandomData.returnNull = true; - String[] values1 = createNumericValues(nullable); - String[] values2 = new String[values1.length]; - System.arraycopy(values1, 0, values2, 0, values1.length); - - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NULL); - - if (null != cekWin) { - testNumerics(stmt, cekWin, numericTable, values1, values2, TestCase.NULL); - } - - if (null != cekAkv) { - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NULL); - } + dropTables(stmt); + createNumericTable(); + populateNumericSetObjectNull(); + testNumeric(stmt, numericValuesNull, true); + testNumeric(null, numericValuesNull2, true); } nullable = false; @@ -770,24 +586,20 @@ public void testNumericSpecificSetterSetObjectNull() throws SQLException { */ @Test public void testNumericNormalization() throws SQLException { + String[] numericValuesNormalization = {Boolean.TRUE.toString(), "1", "127", "100", "100", "1.123", "1.123", + "1.123", "123456789123456789", "12345.12345", "987654321123456789", "567812.78", "7812.7812", + "7812.7812", "999999999999999999999999.9999", "999999999999999999999999.9999"}; + String[] numericValuesNormalization2 = {Boolean.TRUE.toString(), "1", "127", "100", "100", "1.123", "1.123", + "1.123", "123456789123456789", "12345.12345", "987654321123456789", "567812.78", "7812.7812", + "7812.7812", "999999999999999999999999.9999", "999999999999999999999999.9999"}; + try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { - String[] values1 = {Boolean.TRUE.toString(), "1", "127", "100", "100", "1.123", "1.123", "1.123", - "123456789123456789", "12345.12345", "987654321123456789", "567812.78", "7812.7812", "7812.7812", - "999999999999999999999999.9999", "999999999999999999999999.9999"}; - String[] values2 = {Boolean.TRUE.toString(), "1", "127", "100", "100", "1.123", "1.123", "1.123", - "123456789123456789", "12345.12345", "987654321123456789", "567812.78", "7812.7812", "7812.7812", - "999999999999999999999999.9999", "999999999999999999999999.9999"}; - - testNumerics(stmt, cekJks, numericTable, values1, values2, TestCase.NORMAL); - - if (null != cekWin) { - testNumerics(stmt, cekWin, numericTable, values1, values2, TestCase.NORMAL); - } - - if (null != cekAkv) { - testNumerics(stmt, cekAkv, numericTable, values1, values2, TestCase.NORMAL); - } + dropTables(stmt); + createNumericTable(); + populateNumericNormalCase(numericValuesNormalization); + testNumeric(stmt, numericValuesNormalization, false); + testNumeric(null, numericValuesNormalization2, false); } } @@ -796,10 +608,11 @@ public void testAEFMTOnly() throws SQLException { try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";useFmtOnly=true", AEInfo); Statement s = c.createStatement()) { dropTables(s); - createTable(NUMERIC_TABLE_AE, cekJks, numericTable); - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + createNumericTable(); + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + + ")"; try (PreparedStatement p = c.prepareStatement(sql)) { ParameterMetaData pmd = p.getParameterMetaData(); assertTrue(pmd.getParameterCount() == 48); @@ -808,7 +621,7 @@ public void testAEFMTOnly() throws SQLException { } private void testChar(SQLServerStatement stmt, String[] values) throws SQLException { - String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE); + String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { @@ -824,7 +637,7 @@ private void testChar(SQLServerStatement stmt, String[] values) throws SQLExcept } private void testBinary(SQLServerStatement stmt, LinkedList values) throws SQLException { - String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE.toString()); + String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(Constants.BINARY_TABLE_AE); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -841,7 +654,7 @@ private void testBinary(SQLServerStatement stmt, LinkedList values) thro } private void testDate(SQLServerStatement stmt, LinkedList values1) throws SQLException { - String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE); + String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -954,41 +767,41 @@ private void testGetBigDecimal(ResultSet rs, int numberOfColumns, String[] value String decimalValue1 = "" + rs.getBigDecimal(i); String decimalValue2 = "" + rs.getBigDecimal(i + 1); String decimalValue3 = "" + rs.getBigDecimal(i + 2); - String value = values[index]; - if (decimalValue1.equalsIgnoreCase("0") && (value.equalsIgnoreCase(Boolean.TRUE.toString()) - || value.equalsIgnoreCase(Boolean.FALSE.toString()))) { + if (decimalValue1.equalsIgnoreCase("0") && (values[index].equalsIgnoreCase(Boolean.TRUE.toString()) + || values[index].equalsIgnoreCase(Boolean.FALSE.toString()))) { decimalValue1 = Boolean.FALSE.toString(); decimalValue2 = Boolean.FALSE.toString(); decimalValue3 = Boolean.FALSE.toString(); - } else if (decimalValue1.equalsIgnoreCase("1") && (value.equalsIgnoreCase(Boolean.TRUE.toString()) - || value.equalsIgnoreCase(Boolean.FALSE.toString()))) { + } else if (decimalValue1.equalsIgnoreCase("1") && (values[index].equalsIgnoreCase(Boolean.TRUE.toString()) + || values[index].equalsIgnoreCase(Boolean.FALSE.toString()))) { decimalValue1 = Boolean.TRUE.toString(); decimalValue2 = Boolean.TRUE.toString(); decimalValue3 = Boolean.TRUE.toString(); } - if (null != value) { - if (value.equalsIgnoreCase("1.79E308")) { - value = "1.79E+308"; - } else if (value.equalsIgnoreCase("3.4E38")) { - value = "3.4E+38"; + if (null != values[index]) { + if (values[index].equalsIgnoreCase("1.79E308")) { + values[index] = "1.79E+308"; + } else if (values[index].equalsIgnoreCase("3.4E38")) { + values[index] = "3.4E+38"; } - if (value.equalsIgnoreCase("-1.79E308")) { - value = "-1.79E+308"; - } else if (value.equalsIgnoreCase("-3.4E38")) { - value = "-3.4E+38"; + if (values[index].equalsIgnoreCase("-1.79E308")) { + values[index] = "-1.79E+308"; + } else if (values[index].equalsIgnoreCase("-3.4E38")) { + values[index] = "-3.4E+38"; } } try { assertTrue( - decimalValue1.equalsIgnoreCase("" + value) && decimalValue2.equalsIgnoreCase("" + value) - && decimalValue3.equalsIgnoreCase("" + value), + decimalValue1.equalsIgnoreCase("" + values[index]) + && decimalValue2.equalsIgnoreCase("" + values[index]) + && decimalValue3.equalsIgnoreCase("" + values[index]), TestResource.getResource("R_decryptionFailed") + "getBigDecimal(): " + decimalValue1 + ", " + decimalValue2 + ", " + decimalValue3 + ".\n" - + TestResource.getResource("R_expectedValue") + value); + + TestResource.getResource("R_expectedValue") + values[index]); } finally { index++; } @@ -1021,11 +834,11 @@ private void testGetString(ResultSet rs, int numberOfColumns, String[] values) t && stringValue3.equalsIgnoreCase("" + values[index]); if (("" + values[index]).length() >= 1000) { - assertTrue(matches, TestResource.getResource("R_decryptionFailed") + " getString():" + i + ", " + assertTrue(matches, TestResource.getResource("R_decryptionFailed") + "getString():" + i + ", " + (i + 1) + ", " + (i + 2) + ".\n" + TestResource.getResource("R_expectedValue") + index); } else { assertTrue(matches, - TestResource.getResource("R_decryptionFailed") + " getString(): " + stringValue1 + ", " + TestResource.getResource("R_decryptionFailed") + "getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3 + ".\n" + TestResource.getResource("R_expectedValue") + values[index]); } @@ -1224,7 +1037,7 @@ private void testGetDate(ResultSet rs, int numberOfColumns, LinkedList v } private void testNumeric(Statement stmt, String[] numericValues, boolean isNull) throws SQLException { - String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE); + String sql = "select * from " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE); try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -1399,91 +1212,6 @@ private void testWithSpecifiedtype(SQLServerResultSet rs, int numberOfColumns, index++; } - /** - * Alter Column encryption on deterministic columns to randomized - this will trigger enclave to re-encrypt - * - * @param stmt - * @param tableName - * @param table - * @param values - * @throws SQLException - */ - private void testAlterColumnEncryption(SQLServerStatement stmt, String tableName, String table[][], String cekName, - String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { - for (int i = 0; i < table.length; i++) { - // alter deterministic to randomized - String sql = "ALTER TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) + " ALTER COLUMN " - + ColumnType.DETERMINISTIC.name() + table[i][0] + " " + table[i][1] - + String.format(encryptSql, ColumnType.RANDOMIZED.name(), cekName) + ")"; - try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, - stmtColEncSetting)) { - stmt.execute(sql); - if (!TestUtils.isAEv2(con)) { - fail(TestResource.getResource("R_expectedExceptionNotThrown")); - } - } catch (SQLException e) { - if (!TestUtils.isAEv2(con)) { - fail(TestResource.getResource("R_expectedExceptionNotThrown")); - } else { - fail(TestResource.getResource("R_AlterAEv2Error") + e.getMessage() + "Query: " + sql); - } - } - } - } - } - - private void testRichQuery(SQLServerStatement stmt, String tableName, String table[][], - String[] values) throws SQLException { - try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo)) { - for (int i = 0; i < table.length; i++) { - String sql = "SELECT * FROM " + AbstractSQLGenerator.escapeIdentifier(tableName) + " WHERE " - + ColumnType.PLAIN.name() + table[i][0] + "= ?"; - try (SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, - stmtColEncSetting)) { - switch (table[i][2]) { - case "CHAR": - case "LONGVARCHAR": - pstmt.setString(1, values[i / 3]); - break; - case "NCHAR": - case "LONGNVARCHAR": - pstmt.setNString(1, values[i / 3]); - break; - case "GUID": - pstmt.setUniqueIdentifier(1, null); - pstmt.setUniqueIdentifier(1, Constants.UID); - break; - default: - System.out.println("die"); - - } - try (ResultSet rs = (pstmt.executeQuery())) { - if (!TestUtils.isAEv2(con)) { - fail(TestResource.getResource("R_expectedExceptionNotThrown")); - } - - int numberOfColumns = rs.getMetaData().getColumnCount(); - while (rs.next()) { - testGetString(rs, numberOfColumns, values); - testGetObject(rs, numberOfColumns, values); - } - } catch (SQLException e) { - if (!TestUtils.isAEv2(con)) { - fail(TestResource.getResource("R_expectedExceptionNotThrown")); - } else { - fail(TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); - } - } - } catch (Exception e) { - fail(TestResource.getResource("R_RichQueryError") + e.getMessage() + "Query: " + sql); - } - - } - } - - } - private void Compare(String expectedValue, String value1, String value2, String value3) { if (null != expectedValue) { @@ -1507,115 +1235,4 @@ private void Compare(String expectedValue, String value1, String value2, String + value3 + ".\n" + TestResource.getResource("R_expectedValue")); } - private void testChars(SQLServerStatement stmt, String cekName, String[][] table, String[] values, - TestCase testcase, boolean isTestEnclave) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE), stmt); - createTable(CHAR_TABLE_AE, cekName, table); - - switch (testcase) { - case NORMAL: - populateCharNormalCase(values); - break; - case SETOBJECT: - populateCharSetObject(values); - break; - case SETOBJECT_NULL: - populateDateSetObjectNull(); - break; - case SETOBJECT_WITH_JDBCTYPES: - populateCharSetObjectWithJDBCTypes(values); - break; - case NULL: - populateCharNullCase(); - break; - } - - testChar(stmt, values); - testChar(null, values); - - if (isTestEnclave && null != getConfiguredProperty(Constants.ENCLAVE_ATTESTATIONURL)) { - testAlterColumnEncryption(stmt, CHAR_TABLE_AE, table, cekName, values); - testRichQuery(stmt, CHAR_TABLE_AE, table, values); - } - } - - private void testBinaries(SQLServerStatement stmt, String cekName, String[][] table, LinkedList values, - TestCase testcase) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(BINARY_TABLE_AE), stmt); - createTable(BINARY_TABLE_AE, cekName, table); - - switch (testcase) { - case NORMAL: - populateBinaryNormalCase(values); - break; - case SETOBJECT: - populateBinarySetObject(values); - case SETOBJECT_WITH_JDBCTYPES: - populateBinarySetObjectWithJDBCType(values); - break; - case SETOBJECT_NULL: - populateBinarySetObject(null); - break; - - case NULL: - populateBinaryNullCase(); - break; - } - - testBinary(stmt, values); - testBinary(null, values); - } - - private void testDates(SQLServerStatement stmt, String cekName, String[][] table, LinkedList values, - TestCase testcase) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE), stmt); - createTable(DATE_TABLE_AE, cekName, table); - - switch (testcase) { - case NORMAL: - populateDateNormalCase(values); - break; - case SETOBJECT: - populateDateSetObject(values, ""); - break; - case SETOBJECT_WITH_JDBCTYPES: - populateDateSetObject(values, "setwithJDBCType"); - break; - case SETOBJECT_WITH_JAVATYPES: - populateDateSetObject(values, "setwithJavaType"); - break; - case NULL: - populateDateNullCase(); - break; - } - - testDate(stmt, values); - testDate(null, values); - } - - private void testNumerics(SQLServerStatement stmt, String cekName, String[][] table, String[] values1, - String[] values2, TestCase testcase) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE), stmt); - createTable(NUMERIC_TABLE_AE, cekName, table); - - boolean isNull = false; - switch (testcase) { - case NORMAL: - populateNumeric(values1); - break; - case SETOBJECT: - populateNumericSetObject(values1); - break; - case SETOBJECT_WITH_JDBCTYPES: - populateNumericSetObjectWithJDBCTypes(values1); - break; - case NULL: - populateNumericNullCase(values1); - isNull = true; - break; - } - - testNumeric(stmt, values1, isNull); - testNumeric(null, values2, isNull); - } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java index 44bc5f841..735029d27 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/PrecisionScaleTest.java @@ -50,11 +50,6 @@ public class PrecisionScaleTest extends AESetup { private static String GMTDateWithoutDate = ""; private static String dateTimeOffsetExpectedValue = ""; - static String datePrecisionTable[][] = {{"Datetime2", "datetime2",}, {"Datetimeoffset", "datetimeoffset"}, - {"Time", "time"},}; - - static String numericPrecisionTable[][] = {{"Float", "float"}, {"Decimal", "decimal"}, {"Numeric", "numeric"}}; - static { TimeZone tz = TimeZone.getDefault(); offsetFromGMT = tz.getOffset(1450812362177L); @@ -82,8 +77,7 @@ public void testNumericPrecision8Scale2() throws Exception { String[] numeric = {"1.12345", "12345.12", "567.70"}; - createPrecisionTable(NUMERIC_TABLE_AE, numericPrecisionTable, cekJks, 30, 8, 2); - + createNumericPrecisionTable(30, 8, 2); populateNumericNormalCase(numeric, 8, 2); populateNumericSetObject(numeric, 8, 2); @@ -98,12 +92,12 @@ public void testDateScale2() throws Exception { dropTables(stmt); String[] dateNormalCase = {GMTDate + ".18", GMTDate + ".1770000", - dateTimeOffsetExpectedValue + ".18 +00:01", dateTimeOffsetExpectedValue + ".1770000 +00:01", - GMTDateWithoutDate + ".18", GMTDateWithoutDate + ".1770000",}; - String[] dateSetObject = {GMTDate + ".18", GMTDate + ".177", dateTimeOffsetExpectedValue + ".18 +00:01", - dateTimeOffsetExpectedValue + ".177 +00:01", GMTDateWithoutDate, GMTDateWithoutDate,}; + dateTimeOffsetExpectedValue + ".1770000 +00:01", GMTDateWithoutDate + ".1770000", + GMTDateWithoutDate + ".18", dateTimeOffsetExpectedValue + ".18 +00:01"}; + String[] dateSetObject = {GMTDate + ".18", GMTDate + ".177", dateTimeOffsetExpectedValue + ".177 +00:01", + GMTDateWithoutDate, GMTDateWithoutDate, dateTimeOffsetExpectedValue + ".18 +00:01"}; - createScaleTable(DATE_TABLE_AE, datePrecisionTable, cekJks, 2); + createDatePrecisionTable(2); populateDateNormalCase(2); populateDateSetObject(2); @@ -119,8 +113,7 @@ public void testNumericPrecision8Scale0() throws Exception { String[] numeric2 = {"1.12345", "12345", "567"}; - createPrecisionTable(NUMERIC_TABLE_AE, numericPrecisionTable, cekJks, 30, 8, 0); - + createNumericPrecisionTable(30, 8, 0); populateNumericNormalCase(numeric2, 8, 0); populateNumericSetObject(numeric2, 8, 0); @@ -134,14 +127,12 @@ public void testDateScale0() throws Exception { SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) { dropTables(stmt); - String[] dateNormalCase2 = {GMTDate, GMTDate + ".1770000", dateTimeOffsetExpectedValue + " +00:01", - dateTimeOffsetExpectedValue + ".1770000 +00:01", GMTDateWithoutDate, - GMTDateWithoutDate + ".1770000",}; - String[] dateSetObject2 = {GMTDate + ".0", GMTDate + ".177", dateTimeOffsetExpectedValue + " +00:01", - dateTimeOffsetExpectedValue + ".177 +00:01", GMTDateWithoutDate, GMTDateWithoutDate,}; - - createScaleTable(DATE_TABLE_AE, datePrecisionTable, cekJks, 0); + String[] dateNormalCase2 = {GMTDate, GMTDate + ".1770000", dateTimeOffsetExpectedValue + ".1770000 +00:01", + GMTDateWithoutDate + ".1770000", GMTDateWithoutDate, dateTimeOffsetExpectedValue + " +00:01"}; + String[] dateSetObject2 = {GMTDate + ".0", GMTDate + ".177", dateTimeOffsetExpectedValue + ".177 +00:01", + GMTDateWithoutDate, GMTDateWithoutDate, dateTimeOffsetExpectedValue + " +00:01"}; + createDatePrecisionTable(0); populateDateNormalCase(0); populateDateSetObject(0); @@ -157,8 +148,7 @@ public void testNumericPrecision8Scale2Null() throws Exception { String[] numericNull = {"null", "null", "null"}; - createPrecisionTable(NUMERIC_TABLE_AE, numericPrecisionTable, cekJks, 30, 8, 2); - + createNumericPrecisionTable(30, 8, 2); populateNumericSetObjectNull(8, 2); testNumeric(numericNull); @@ -173,8 +163,7 @@ public void testDateScale2Null() throws Exception { String[] dateSetObjectNull = {"null", "null", "null", "null", "null", "null"}; - createScaleTable(DATE_TABLE_AE, datePrecisionTable, cekJks, 2); - + createDatePrecisionTable(2); populateDateSetObjectNull(2); testDate(dateSetObjectNull, dateSetObjectNull); @@ -189,8 +178,7 @@ public void testDateScale5Null() throws Exception { String[] dateSetObjectNull = {"null", "null", "null", "null", "null", "null"}; - createScaleTable(DATE_TABLE_AE, datePrecisionTable, cekJks, 5); - + createDatePrecisionTable(5); populateDateNormalCaseNull(5); testDate(dateSetObjectNull, dateSetObjectNull); } @@ -199,8 +187,8 @@ public void testDateScale5Null() throws Exception { private void testNumeric(String[] numeric) throws SQLException { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement(); ResultSet rs = stmt - .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE))) { + SQLServerStatement stmt = (SQLServerStatement) con.createStatement(); ResultSet rs = stmt.executeQuery( + "select * from " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE))) { int numberOfColumns = rs.getMetaData().getColumnCount(); ArrayList skipMax = new ArrayList<>(); @@ -216,8 +204,8 @@ private void testNumeric(String[] numeric) throws SQLException { private void testDate(String[] dateNormalCase, String[] dateSetObject) throws Exception { try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); - SQLServerStatement stmt = (SQLServerStatement) con.createStatement(); ResultSet rs = stmt - .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE))) { + SQLServerStatement stmt = (SQLServerStatement) con.createStatement(); ResultSet rs = stmt.executeQuery( + "select * from " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE))) { int numberOfColumns = rs.getMetaData().getColumnCount(); ArrayList skipMax = new ArrayList<>(); @@ -343,9 +331,9 @@ private void testGetDate(ResultSet rs, int numberOfColumns, String[] dates) thro break; case 10: - stringValue1 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i); - stringValue2 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i + 1); - stringValue3 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i + 2); + stringValue1 = "" + ((SQLServerResultSet) rs).getTime(i); + stringValue2 = "" + ((SQLServerResultSet) rs).getTime(i + 1); + stringValue3 = "" + ((SQLServerResultSet) rs).getTime(i + 2); break; case 13: @@ -355,9 +343,9 @@ private void testGetDate(ResultSet rs, int numberOfColumns, String[] dates) thro break; case 16: - stringValue1 = "" + ((SQLServerResultSet) rs).getTime(i); - stringValue2 = "" + ((SQLServerResultSet) rs).getTime(i + 1); - stringValue3 = "" + ((SQLServerResultSet) rs).getTime(i + 2); + stringValue1 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i); + stringValue2 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i + 1); + stringValue3 = "" + ((SQLServerResultSet) rs).getDateTimeOffset(i + 2); break; default: @@ -382,14 +370,14 @@ private void testGetDate(ResultSet rs, int numberOfColumns, String[] dates) thro } private void populateDateNormalCase(int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { - // datetime2 scale + // datetime2(5) for (int i = 1; i <= 3; i++) { pstmt.setTimestamp(i, new Timestamp(date.getTime()), scale); } @@ -399,25 +387,25 @@ private void populateDateNormalCase(int scale) throws SQLException { pstmt.setTimestamp(i, new Timestamp(date.getTime())); } - // datetimeoffset scale + // datetimeoffset default for (int i = 7; i <= 9; i++) { - pstmt.setDateTimeOffset(i, microsoft.sql.DateTimeOffset.valueOf(new Timestamp(date.getTime()), 1), - scale); + pstmt.setDateTimeOffset(i, microsoft.sql.DateTimeOffset.valueOf(new Timestamp(date.getTime()), 1)); } - // datetimeoffset default + // time default for (int i = 10; i <= 12; i++) { - pstmt.setDateTimeOffset(i, microsoft.sql.DateTimeOffset.valueOf(new Timestamp(date.getTime()), 1)); + pstmt.setTime(i, new Time(date.getTime())); } - // time scale + // time(3) for (int i = 13; i <= 15; i++) { pstmt.setTime(i, new Time(date.getTime()), scale); } - // time default + // datetimeoffset(2) for (int i = 16; i <= 18; i++) { - pstmt.setTime(i, new Time(date.getTime())); + pstmt.setDateTimeOffset(i, microsoft.sql.DateTimeOffset.valueOf(new Timestamp(date.getTime()), 1), + scale); } pstmt.execute(); @@ -425,14 +413,14 @@ private void populateDateNormalCase(int scale) throws SQLException { } private void populateDateNormalCaseNull(int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { - // datetime2 scale + // datetime2(5) for (int i = 1; i <= 3; i++) { pstmt.setTimestamp(i, null, scale); } @@ -442,24 +430,24 @@ private void populateDateNormalCaseNull(int scale) throws SQLException { pstmt.setTimestamp(i, null); } - // datetimeoffset scale + // datetimeoffset default for (int i = 7; i <= 9; i++) { - pstmt.setDateTimeOffset(i, null, scale); + pstmt.setDateTimeOffset(i, null); } - // datetimeoffset default + // time default for (int i = 10; i <= 12; i++) { - pstmt.setDateTimeOffset(i, null); + pstmt.setTime(i, null); } - // time scale + // time(3) for (int i = 13; i <= 15; i++) { pstmt.setTime(i, null, scale); } - // time default + // datetimeoffset(2) for (int i = 16; i <= 18; i++) { - pstmt.setTime(i, null); + pstmt.setDateTimeOffset(i, null, scale); } pstmt.execute(); @@ -467,8 +455,8 @@ private void populateDateNormalCaseNull(int scale) throws SQLException { } private void populateNumericNormalCase(String[] numeric, int precision, int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -494,8 +482,8 @@ private void populateNumericNormalCase(String[] numeric, int precision, int scal } private void populateNumericSetObject(String[] numeric, int precision, int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -522,8 +510,8 @@ private void populateNumericSetObject(String[] numeric, int precision, int scale } private void populateNumericSetObjectNull(int precision, int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, @@ -550,14 +538,14 @@ private void populateNumericSetObjectNull(int precision, int scale) throws SQLEx } private void populateDateSetObject(int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { - // datetime2 scale + // datetime2(5) for (int i = 1; i <= 3; i++) { pstmt.setObject(i, new Timestamp(date.getTime()), java.sql.Types.TIMESTAMP, scale); } @@ -567,26 +555,26 @@ private void populateDateSetObject(int scale) throws SQLException { pstmt.setObject(i, new Timestamp(date.getTime()), java.sql.Types.TIMESTAMP); } - // datetimeoffset scale + // datetimeoffset default for (int i = 7; i <= 9; i++) { pstmt.setObject(i, microsoft.sql.DateTimeOffset.valueOf(new Timestamp(date.getTime()), 1), - microsoft.sql.Types.DATETIMEOFFSET, scale); + microsoft.sql.Types.DATETIMEOFFSET); } - // datetimeoffset default + // time default for (int i = 10; i <= 12; i++) { - pstmt.setObject(i, microsoft.sql.DateTimeOffset.valueOf(new Timestamp(date.getTime()), 1), - microsoft.sql.Types.DATETIMEOFFSET); + pstmt.setObject(i, new Time(date.getTime()), java.sql.Types.TIME); } - // time scale + // time(3) for (int i = 13; i <= 15; i++) { pstmt.setObject(i, new Time(date.getTime()), java.sql.Types.TIME, scale); } - // time default + // datetimeoffset(2) for (int i = 16; i <= 18; i++) { - pstmt.setObject(i, new Time(date.getTime()), java.sql.Types.TIME); + pstmt.setObject(i, microsoft.sql.DateTimeOffset.valueOf(new Timestamp(date.getTime()), 1), + microsoft.sql.Types.DATETIMEOFFSET, scale); } pstmt.execute(); @@ -594,14 +582,14 @@ private void populateDateSetObject(int scale) throws SQLException { } private void populateDateSetObjectNull(int scale) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?," - + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")"; try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo); SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) { - // datetime2 set + // datetime2(5) for (int i = 1; i <= 3; i++) { pstmt.setObject(i, null, java.sql.Types.TIMESTAMP, scale); } @@ -611,24 +599,24 @@ private void populateDateSetObjectNull(int scale) throws SQLException { pstmt.setObject(i, null, java.sql.Types.TIMESTAMP); } - // datetimeoffset scale + // datetimeoffset default for (int i = 7; i <= 9; i++) { - pstmt.setObject(i, null, microsoft.sql.Types.DATETIMEOFFSET, scale); + pstmt.setObject(i, null, microsoft.sql.Types.DATETIMEOFFSET); } - // datetimeoffset default + // time default for (int i = 10; i <= 12; i++) { - pstmt.setObject(i, null, microsoft.sql.Types.DATETIMEOFFSET); + pstmt.setObject(i, null, java.sql.Types.TIME); } - // time scale + // time(3) for (int i = 13; i <= 15; i++) { pstmt.setObject(i, null, java.sql.Types.TIME, scale); } - // time default + // datetimeoffset(2) for (int i = 16; i <= 18; i++) { - pstmt.setObject(i, null, java.sql.Types.TIME); + pstmt.setObject(i, null, microsoft.sql.Types.DATETIMEOFFSET, scale); } pstmt.execute(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java index 8e8d1100c..1f8a97115 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/AlwaysEncrypted/RegressionAlwaysEncryptedTest.java @@ -30,15 +30,6 @@ @Tag(Constants.xAzureSQLDB) public class RegressionAlwaysEncryptedTest extends AESetup { - static String numericTable[][] = {{"Bit", "bit"}, {"Tinyint", "tinyint"}, {"Smallint", "smallint"},}; - - static String dateTable[][] = {{"Date", "date"}, - - }; - - static String charTable[][] = {{"Char", "char(20) COLLATE Latin1_General_BIN2"}, - {"Varchar", "varchar(50) COLLATE Latin1_General_BIN2"},}; - @Test public void alwaysEncrypted1() throws SQLException { try (Connection connection = PrepUtil.getConnection( @@ -46,20 +37,17 @@ public void alwaysEncrypted1() throws SQLException { Statement stmt = connection.createStatement()) { dropTables(stmt); - createTable(NUMERIC_TABLE_AE, cekJks, numericTable); - + createNumericTable(stmt); populateNumericTable(connection); verifyNumericTable(connection, false); dropTables(stmt); - createTable(DATE_TABLE_AE, cekJks, dateTable); - + createDateTable(stmt); populateDateTable(connection); verifyDateTable(connection); dropTables(stmt); - createTable(NUMERIC_TABLE_AE, cekJks, numericTable); - + createNumericTable(stmt); populateNumericTableWithNull(connection); verifyNumericTable(connection, true); @@ -74,17 +62,17 @@ public void alwaysEncrypted2() throws SQLException { Statement stmt = connection.createStatement()) { dropTables(stmt); - createTable(CHAR_TABLE_AE, cekJks, charTable); + createCharTable(stmt); populateCharTable(connection); verifyCharTable(connection); dropTables(stmt); - createTable(DATE_TABLE_AE, cekJks, dateTable); + createDateTable(stmt); populateDateTable(connection); verifyDateTable(connection); dropTables(stmt); - createTable(NUMERIC_TABLE_AE, cekJks, numericTable); + createNumericTable(stmt); populateNumericTableSpecificSetter(connection); verifyNumericTable(connection, false); @@ -93,20 +81,18 @@ public void alwaysEncrypted2() throws SQLException { } private void populateDateTable(Connection connection) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE) + " values( " + "?,?,?" + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " values( " + "?" + ")"; try (PreparedStatement sqlPstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability())) { sqlPstmt.setObject(1, Constants.DATE); - sqlPstmt.setObject(2, Constants.DATE); - sqlPstmt.setObject(3, Constants.DATE); sqlPstmt.executeUpdate(); } } private void populateCharTable(Connection connection) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE) + " values( " + "?,?,?,?,?,?" - + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE) + " values( " + + "?,?,?,?,?,?" + ")"; try (PreparedStatement sqlPstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability())) { sqlPstmt.setObject(1, "hi"); @@ -120,7 +106,7 @@ private void populateCharTable(Connection connection) throws SQLException { } private void populateNumericTable(Connection connection) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values(?,?,?,?,?,?,?,?,?)"; try (PreparedStatement sqlPstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability())) { @@ -139,7 +125,7 @@ private void populateNumericTable(Connection connection) throws SQLException { } private void populateNumericTableSpecificSetter(Connection connection) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( " + "?,?,?,?,?,?,?,?,?" + ")"; try (PreparedStatement sqlPstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability())) { @@ -158,8 +144,8 @@ private void populateNumericTableSpecificSetter(Connection connection) throws SQ } private void populateNumericTableWithNull(Connection connection) throws SQLException { - String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE) + " values( " + "?,?,?" - + ",?,?,?" + ",?,?,?" + ")"; + String sql = "insert into " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " values( " + + "?,?,?" + ",?,?,?" + ",?,?,?" + ")"; try (PreparedStatement sqlPstmt = connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, connection.getHoldability())) { sqlPstmt.setObject(1, null, java.sql.Types.BIT); @@ -177,8 +163,8 @@ private void populateNumericTableWithNull(Connection connection) throws SQLExcep private void verifyDateTable(Connection connection) throws SQLException { try (Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); - ResultSet rs = stmt - .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE))) { + ResultSet rs = stmt.executeQuery( + "select * from " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE))) { while (rs.next()) { // VSTS BUG 5268 // assertEquals(date.getTime(), ((Date) rs.getObject(1)).getTime()); @@ -188,8 +174,8 @@ private void verifyDateTable(Connection connection) throws SQLException { private void verifyCharTable(Connection connection) throws SQLException { try (Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); - ResultSet rs = stmt - .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE))) { + ResultSet rs = stmt.executeQuery( + "select * from " + AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE))) { while (rs.next()) { assertEquals("hi ", rs.getObject(1)); assertEquals("sample ", rs.getObject(2)); @@ -203,8 +189,8 @@ private void verifyCharTable(Connection connection) throws SQLException { private void verifyNumericTable(Connection connection, boolean isNull) throws SQLException { try (Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); - ResultSet rs = stmt - .executeQuery("select * from " + AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE))) { + ResultSet rs = stmt.executeQuery( + "select * from " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE))) { while (rs.next()) { if (isNull) { assertEquals(null, rs.getObject(1)); @@ -231,9 +217,48 @@ private void verifyNumericTable(Connection connection, boolean isNull) throws SQ } } + private void createDateTable(Statement stmt) throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE) + " (" + + "RandomizedDate date ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + ");"; + stmt.execute(sql); + } + + private void createCharTable(Statement stmt) throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE) + " (" + + "PlainChar char(20) null," + + "RandomizedChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicChar char(20) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + "PlainVarchar varchar(50) null," + + "RandomizedVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicVarchar varchar(50) COLLATE Latin1_General_BIN2 ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + ");"; + stmt.execute(sql); + } + + private void createNumericTable(Statement stmt) throws SQLException { + String sql = "create table " + AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE) + " (" + + "PlainBit bit null," + + "RandomizedBit bit ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicBit bit ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + "PlainTinyint tinyint null," + + "RandomizedTinyint tinyint ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicTinyint tinyint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + "PlainSmallint smallint null," + + "RandomizedSmallint smallint ENCRYPTED WITH (ENCRYPTION_TYPE = RANDOMIZED, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + + "DeterministicSmallint smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = " + + Constants.CEK_NAME + ") NULL," + ");"; + stmt.execute(sql); + } + public static void dropTables(Statement stmt) throws SQLException { - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(DATE_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(CHAR_TABLE_AE), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(NUMERIC_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.DATE_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.CHAR_TABLE_AE), stmt); + TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(Constants.NUMERIC_TABLE_AE), stmt); } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/ComparisonUtil.java b/src/test/java/com/microsoft/sqlserver/jdbc/ComparisonUtil.java index f440ce2d6..e73650b97 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/ComparisonUtil.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/ComparisonUtil.java @@ -103,46 +103,56 @@ public static void compareExpectedAndActual(int dataType, Object expectedValue, } else switch (dataType) { case java.sql.Types.BIGINT: - assertEquals((Long) expectedValue, (Long) actualValue, "Unexpected bigint value."); + assertTrue((((Long) expectedValue).longValue() == ((Long) actualValue).longValue()), + "Unexpected bigint value. Expected:" + ((Long) expectedValue).longValue() + " Actual:" + + ((Long) actualValue).longValue()); break; case java.sql.Types.INTEGER: - assertEquals((Integer) expectedValue, (Integer) actualValue, "Unexpected int value."); + assertTrue((((Integer) expectedValue).intValue() == ((Integer) actualValue).intValue()), + "Unexpected int value. Expected:" + ((Integer) expectedValue).intValue() + " Actual:" + + ((Integer) actualValue).intValue()); break; case java.sql.Types.SMALLINT: case java.sql.Types.TINYINT: - assertEquals((Short) expectedValue, (Short) actualValue, "Unexpected smallint/tinyint value."); + assertTrue((((Short) expectedValue).shortValue() == ((Short) actualValue).shortValue()), + "Unexpected smallint/tinyint value. Expected:" + ((Short) expectedValue).shortValue() + + " Actual:" + ((Short) actualValue).shortValue()); break; case java.sql.Types.BIT: - assertEquals((Boolean) expectedValue, (Boolean) actualValue, "Unexpected bit value"); + assertTrue((((Boolean) expectedValue).booleanValue() == ((Boolean) actualValue).booleanValue()), + "Unexpected bit value"); break; case java.sql.Types.DECIMAL: case java.sql.Types.NUMERIC: - assertTrue(((BigDecimal) expectedValue).compareTo((BigDecimal) actualValue) == 0, - "Unexpected decimal/numeric/money/smallmoney value. Expected:" + expectedValue + " Actual:" - + actualValue); + assertTrue(0 == (((BigDecimal) expectedValue).compareTo((BigDecimal) actualValue)), + "Unexpected decimal/numeric/money/smallmoney value"); break; case java.sql.Types.DOUBLE: - assertEquals((Double) expectedValue, (Double) actualValue, "Unexpected double value."); + assertTrue((((Double) expectedValue).doubleValue() == ((Double) actualValue).doubleValue()), + "Unexpected double value. Expected:" + ((Double) expectedValue).doubleValue() + " Actual:" + + ((Double) actualValue).doubleValue()); break; case java.sql.Types.REAL: - assertEquals((Float) expectedValue, (Float) actualValue, "Unexpected real/float value."); + assertTrue((((Float) expectedValue).floatValue() == ((Float) actualValue).floatValue()), + "Unexpected real/float value. Expected:" + ((Float) expectedValue).floatValue() + " Actual:" + + ((Float) actualValue).floatValue()); break; case java.sql.Types.VARCHAR: case java.sql.Types.NVARCHAR: - assertEquals(((String) expectedValue).trim(), ((String) actualValue).trim(), + assertTrue(((((String) expectedValue).trim()).equals(((String) actualValue).trim())), "Unexpected varchar/nvarchar value "); break; case java.sql.Types.CHAR: case java.sql.Types.NCHAR: - assertEquals(((String) expectedValue).trim(), ((String) actualValue).trim(), + assertTrue(((((String) expectedValue).trim()).equals(((String) actualValue).trim())), "Unexpected char/nchar value "); break; @@ -153,7 +163,7 @@ public static void compareExpectedAndActual(int dataType, Object expectedValue, break; case java.sql.Types.TIMESTAMP: - assertEquals((Timestamp) expectedValue, (Timestamp) actualValue, + assertTrue((((Timestamp) expectedValue).getTime() == (((Timestamp) actualValue).getTime())), "Unexpected datetime/smalldatetime/datetime2 value"); break; @@ -162,19 +172,18 @@ public static void compareExpectedAndActual(int dataType, Object expectedValue, expC.setTime((Date) expectedValue); Calendar actC = Calendar.getInstance(); actC.setTime((Date) actualValue); - assertEquals(expC.get(Calendar.DAY_OF_MONTH), actC.get(Calendar.DAY_OF_MONTH), - "Unexpected date value. Expected:" + expectedValue + " Actual:" + actualValue); + assertTrue(expC.get(Calendar.DAY_OF_MONTH) == actC.get(Calendar.DAY_OF_MONTH), + "Unexpected datetime value"); break; case java.sql.Types.TIME: - assertEquals((Time) expectedValue, (Time) actualValue, "Unexpected time value "); + assertTrue(((Time) expectedValue).getTime() == ((Time) actualValue).getTime(), + "Unexpected time value "); break; case microsoft.sql.Types.DATETIMEOFFSET: - assertTrue( - 0 == ((microsoft.sql.DateTimeOffset) expectedValue) - .compareTo((microsoft.sql.DateTimeOffset) actualValue), - "Unexpected datetimeoffset value. Expected:" + expectedValue + " Actual:" + actualValue); + assertTrue(0 == ((microsoft.sql.DateTimeOffset) expectedValue) + .compareTo((microsoft.sql.DateTimeOffset) actualValue), "Unexpected time value "); break; default: diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java index ed421060f..b5cd04128 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestResource.java @@ -179,8 +179,5 @@ protected Object[][] getContents() { {"R_incorrectSyntaxTableDW", "Incorrect syntax near 'table'."}, {"R_ConnectionStringNull", "Connection String should not be null"}, {"R_OperandTypeClash", "Operand type clash"}, - {"R_NoPrivilege", "The EXECUTE permission was denied on the object {0}"}, - {"R_resultSetEmpty", "Result set is empty."}, - {"R_AlterAEv2Error", "Alter Column Encryption failed."}, - {"R_RichQueryError", "Rich query failed."}}; + {"R_NoPrivilege", "The EXECUTE permission was denied on the object {0}"}}; } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java b/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java index dab9a33e6..1e257dec3 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/TestUtils.java @@ -10,12 +10,7 @@ import java.io.ByteArrayInputStream; import java.io.CharArrayReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.net.URI; -import java.security.KeyStore; -import java.security.cert.CertificateFactory; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.PreparedStatement; @@ -26,7 +21,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; -import java.util.List; import java.util.Locale; import java.util.ResourceBundle; @@ -110,15 +104,6 @@ public static boolean isAzureMI(Connection con) { return isAzureMI; } - /** - * Checks if connection is established to server that supports AEv2. - * - * @see com.microsoft.sqlserver.jdbc.SQLServerConnection#isAEv2() - */ - public static boolean isAEv2(Connection con) { - return ((SQLServerConnection) con).isAEv2(); - } - /** * Read variable from property files if found null try to read from env. * @@ -842,53 +827,4 @@ public static String formatErrorMsg(String s) { public static String addOrOverrideProperty(String connectionString, String property, String value) { return connectionString + ";" + property + "=" + value + ";"; } - - /** - * Creates a truststore and returns the path of it. - * - * @param certificates - * String list of certificates - * @param tsName - * name of truststore to create - * @param tsPwd - * password of truststore to set - * @param ksType - * type of Keystore e.g PKCS12 or JKS - * @return Path of truststore that was created - * @throws Exception - */ - public static String createTrustStore(List certificates, String tsName, String tsPwd, - String ksType) throws Exception { - return (new TrustStore(certificates, tsName, tsPwd, ksType)).getFileName(); - } - - private static class TrustStore { - private File trustStoreFile; - - TrustStore(List certificateNames, String tsName, String tsPwd, String ksType) throws Exception { - trustStoreFile = File.createTempFile(tsName, null, new File(".")); - trustStoreFile.deleteOnExit(); - KeyStore ks = KeyStore.getInstance(ksType); - ks.load(null, null); - - for (String certificateName : certificateNames) { - ks.setCertificateEntry(certificateName, getCertificate(certificateName)); - } - - FileOutputStream os = new FileOutputStream(trustStoreFile); - ks.store(os, tsPwd.toCharArray()); - os.flush(); - os.close(); - } - - final String getFileName() throws Exception { - return trustStoreFile.getCanonicalPath(); - } - - private static java.security.cert.Certificate getCertificate(String certname) throws Exception { - FileInputStream is = new FileInputStream(certname); - CertificateFactory cf = CertificateFactory.getInstance("X.509"); - return cf.generateCertificate(is); - } - } } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java index 720d43c29..953f3ac91 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyCSVTest.java @@ -166,7 +166,7 @@ private void testBulkCopyCSV(SQLServerBulkCSVFileRecord fileRecord, boolean firs (-1 == precision) ? 0 : precision, (-1 == scale) ? 0 : scale); } stmt.createTable(destTable); - bulkCopy.writeToServer(fileRecord); + bulkCopy.writeToServer((ISQLServerBulkRecord) fileRecord); } if (firstLineIsColumnNames) validateValuesFromCSV(destTable, inputFile); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestUtil.java b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestUtil.java index 57c8bdf50..48b98279b 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestUtil.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTestUtil.java @@ -13,7 +13,7 @@ import java.sql.SQLException; import com.microsoft.sqlserver.jdbc.ComparisonUtil; -import com.microsoft.sqlserver.jdbc.ISQLServerBulkData; +import com.microsoft.sqlserver.jdbc.ISQLServerBulkRecord; import com.microsoft.sqlserver.jdbc.SQLServerBulkCopy; import com.microsoft.sqlserver.jdbc.TestResource; import com.microsoft.sqlserver.jdbc.bulkCopy.BulkCopyTestWrapper.ColumnMap; @@ -314,7 +314,7 @@ static void validateValues(DBConnection con, DBTable sourceTable, DBTable destin * @param srcData * @param dstTable */ - static void performBulkCopy(BulkCopyTestWrapper bulkWrapper, ISQLServerBulkData srcData, DBTable dstTable) { + static void performBulkCopy(BulkCopyTestWrapper bulkWrapper, ISQLServerBulkRecord srcData, DBTable dstTable) { try (DBConnection con = new DBConnection(bulkWrapper.getConnectionString()); DBStatement stmt = con.createStatement(); SQLServerBulkCopy bc = new SQLServerBulkCopy(bulkWrapper.getConnectionString())) { @@ -333,7 +333,7 @@ static void performBulkCopy(BulkCopyTestWrapper bulkWrapper, ISQLServerBulkData * @param destinationTable * @throws Exception */ - static void validateValues(DBConnection con, ISQLServerBulkData srcData, + static void validateValues(DBConnection con, ISQLServerBulkRecord srcData, DBTable destinationTable) throws Exception { try (DBStatement dstStmt = con.createStatement(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/connection/XADataSourceTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/connection/XADataSourceTest.java deleted file mode 100644 index 9d5958a0c..000000000 --- a/src/test/java/com/microsoft/sqlserver/jdbc/connection/XADataSourceTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made - * available under the terms of the MIT License. See the LICENSE file in the project root for more information. - */ - -package com.microsoft.sqlserver.jdbc.connection; - -import javax.sql.XAConnection; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; - -import com.microsoft.sqlserver.jdbc.SQLServerXADataSource; -import com.microsoft.sqlserver.testframework.AbstractTest; -import com.microsoft.sqlserver.testframework.Constants; - - -@RunWith(JUnitPlatform.class) -@Tag(Constants.reqExternalSetup) -public class XADataSourceTest extends AbstractTest { - private static String connectionUrlSSL = connectionString + ";encrypt=true;trustServerCertificate=false;"; - - /** - * Tests XA connection with PKCS12 truststore that is password protected. - * - * Only re-populate the truststore if need arises in the future. - * TestUtils.createTrustStore() can be used to create the truststore. - * - * @throws Exception - */ - @Test - public void testPKCS12() throws Exception { - SQLServerXADataSource ds = new SQLServerXADataSource(); - - String trustStore = System.getProperty("pkcs12_truststore"); - String url = connectionUrlSSL + "trustStore=" + trustStore + ";"; - ds.setURL(url); - ds.setTrustStorePassword(System.getProperty("pkcs12_truststore_password")); - XAConnection connection = ds.getXAConnection(); - connection.close(); - } -} diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java index 1c5f48bb3..fbe3f195f 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataForeignKeyTest.java @@ -42,13 +42,8 @@ public class DatabaseMetaDataForeignKeyTest extends AbstractTest { private static String table3 = RandomUtil.getIdentifier("DatabaseMetaDataForeignKeyTest_table_3"); private static String table4 = RandomUtil.getIdentifier("DatabaseMetaDataForeignKeyTest_table_4"); private static String table5 = RandomUtil.getIdentifier("DatabaseMetaDataForeignKeyTest_table_5"); - private static String PKTable1 = RandomUtil.getIdentifier("DatabaseMetaDataForeignKeyTest_PKTable1"); - private static String FKTable1 = RandomUtil.getIdentifier("DatabaseMetaDataForeignKeyTest_FKTable1"); - private static String PKTable2 = RandomUtil.getIdentifier("DatabaseMetaDataForeignKeyTest_PKTable2"); - private static String FKTable2 = RandomUtil.getIdentifier("DatabaseMetaDataForeignKeyTest_FKTable2"); private static String schema = null; - private static String anotherSchema = RandomUtil.getIdentifier("anotherSchema"); private static String catalog = null; @BeforeAll @@ -57,24 +52,30 @@ public static void setupVariation() throws SQLException { catalog = conn.getCatalog(); schema = conn.getSchema(); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table1), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table2), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table3), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table4), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table5), stmt); - + stmt.executeUpdate("if object_id('" + TestUtils.escapeSingleQuotes(table1) + + "','U') is not null drop table " + AbstractSQLGenerator.escapeIdentifier(table1)); + stmt.executeUpdate("if object_id('" + TestUtils.escapeSingleQuotes(table2) + + "','U') is not null drop table " + AbstractSQLGenerator.escapeIdentifier(table2)); stmt.execute("Create table " + AbstractSQLGenerator.escapeIdentifier(table2) + " (c21 int NOT NULL PRIMARY KEY)"); + stmt.executeUpdate("if object_id('" + TestUtils.escapeSingleQuotes(table3) + + "','U') is not null drop table " + AbstractSQLGenerator.escapeIdentifier(table3)); stmt.execute("Create table " + AbstractSQLGenerator.escapeIdentifier(table3) + " (c31 int NOT NULL PRIMARY KEY)"); + stmt.executeUpdate("if object_id('" + TestUtils.escapeSingleQuotes(table4) + + "','U') is not null drop table " + AbstractSQLGenerator.escapeIdentifier(table4)); stmt.execute("Create table " + AbstractSQLGenerator.escapeIdentifier(table4) + " (c41 int NOT NULL PRIMARY KEY)"); + stmt.executeUpdate("if object_id('" + TestUtils.escapeSingleQuotes(table5) + + "','U') is not null drop table " + AbstractSQLGenerator.escapeIdentifier(table5)); stmt.execute("Create table " + AbstractSQLGenerator.escapeIdentifier(table5) + " (c51 int NOT NULL PRIMARY KEY)"); + stmt.executeUpdate("if object_id('" + TestUtils.escapeSingleQuotes(table1) + + "','U') is not null drop table " + AbstractSQLGenerator.escapeIdentifier(table1)); stmt.execute("Create table " + AbstractSQLGenerator.escapeIdentifier(table1) + " (c11 int primary key," + " c12 int FOREIGN KEY REFERENCES " + AbstractSQLGenerator.escapeIdentifier(table2) + "(c21) ON DELETE no action ON UPDATE set default," + " c13 int FOREIGN KEY REFERENCES " @@ -83,27 +84,6 @@ public static void setupVariation() throws SQLException { + "(c41) ON DELETE set null ON UPDATE cascade," + " c15 int FOREIGN KEY REFERENCES " + AbstractSQLGenerator.escapeIdentifier(table5) + "(c51) ON DELETE set default ON UPDATE no action," + ")"); - - stmt.execute("CREATE SCHEMA " + AbstractSQLGenerator.escapeIdentifier(anotherSchema)); - - stmt.execute("Create table " + AbstractSQLGenerator.escapeIdentifier(PKTable1) - + " (col int NOT NULL PRIMARY KEY)"); - - stmt.execute("Create table " + AbstractSQLGenerator.escapeIdentifier(anotherSchema) + "." - + AbstractSQLGenerator.escapeIdentifier(PKTable2) + " (col int NOT NULL PRIMARY KEY)"); - - stmt.execute("Create table " + AbstractSQLGenerator.escapeIdentifier(schema) + "." - + AbstractSQLGenerator.escapeIdentifier(FKTable1) - + " (col int, CONSTRAINT fk_DuplicateName FOREIGN KEY ([col]) REFERENCES " - + AbstractSQLGenerator.escapeIdentifier(schema) + "." - + AbstractSQLGenerator.escapeIdentifier(PKTable1) + "([col])" + ")"); - - stmt.execute("Create table " + AbstractSQLGenerator.escapeIdentifier(anotherSchema) + "." - + AbstractSQLGenerator.escapeIdentifier(FKTable2) - + " (col int, CONSTRAINT fk_DuplicateName FOREIGN KEY ([col]) REFERENCES " - + AbstractSQLGenerator.escapeIdentifier(anotherSchema) + "." - + AbstractSQLGenerator.escapeIdentifier(PKTable2) + "([col])" + ")"); - } catch (Exception e) { fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage()); } @@ -117,16 +97,6 @@ public static void terminateVariation() throws SQLException { TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table3), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table4), stmt); TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(table5), stmt); - - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(FKTable1), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(anotherSchema) + "." - + AbstractSQLGenerator.escapeIdentifier(FKTable2), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(anotherSchema) + "." - + AbstractSQLGenerator.escapeIdentifier(PKTable2), stmt); - TestUtils.dropTableIfExists(AbstractSQLGenerator.escapeIdentifier(PKTable1), stmt); - - TestUtils.dropSchemaIfExists(anotherSchema, stmt); - } catch (Exception e) { fail(TestResource.getResource("R_unexpectedErrorMessage") + e.getMessage()); } @@ -163,31 +133,6 @@ public void testGetImportedKeys() throws SQLException { } } - @Test - /** - * test getImportedKeys does not return duplicate row if multiple FKs have same name - * - * @throws SQLException - * @throws SQLTimeoutException - */ - public void validateDuplicateForeignKeys() throws SQLException { - int expectedRowCount = 1; - int rowCount = 0; - - try (Connection conn = getConnection()) { - DatabaseMetaData dmd = conn.getMetaData(); - - try (ResultSet rs = dmd.getImportedKeys(null, null, FKTable1)) { - while (rs.next()) { - rowCount++; - } - } - if (expectedRowCount != rowCount) { - assertEquals(expectedRowCount, rowCount, TestResource.getResource("R_numKeysIncorrect")); - } - } - } - private void validateGetImportedKeysResults(ResultSet rs) throws SQLException { int expectedRowCount = 4; int rowCount = 0; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java index a6a5f9ac9..d3a7e2a98 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/databasemetadata/DatabaseMetaDataTest.java @@ -353,19 +353,22 @@ public void testGetDBColumn() throws SQLException { fail(form1.format(msgArgs1)); } else { try (ResultSet rs1 = databaseMetaData.getColumns(null, null, tableName, "%")) { - testGetDBColumnInternal(rs1, databaseMetaData); - } - - try (ResultSet rs1 = databaseMetaData.getColumns(null, null, tableName, "col\\_1")) { - testGetDBColumnInternal(rs1, databaseMetaData); - } - - try (ResultSet rs1 = databaseMetaData.getColumns(null, null, tableName, "col\\%2")) { - testGetDBColumnInternal(rs1, databaseMetaData); - } - - try (ResultSet rs1 = databaseMetaData.getColumns(null, null, tableName, "col\\[3")) { - testGetDBColumnInternal(rs1, databaseMetaData); + MessageFormat form2 = new MessageFormat(TestResource.getResource("R_nameEmpty")); + Object[][] msgArgs2 = {{"Category"}, {"SCHEMA"}, {"Table"}, {"COLUMN"}, {"Data Type"}, {"Type"}, + {"Column Size"}, {"Nullable value"}, {"IS_NULLABLE"}, {"IS_AUTOINCREMENT"}}; + while (rs1.next()) { + assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_CAT")), form2.format(msgArgs2[0])); + assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_SCHEM")), form2.format(msgArgs2[1])); + assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_NAME")), form2.format(msgArgs2[2])); + assertTrue(!StringUtils.isEmpty(rs1.getString("COLUMN_NAME")), form2.format(msgArgs2[3])); + assertTrue(!StringUtils.isEmpty(rs1.getString("DATA_TYPE")), form2.format(msgArgs2[4])); + assertTrue(!StringUtils.isEmpty(rs1.getString("TYPE_NAME")), form2.format(msgArgs2[5])); + assertTrue(!StringUtils.isEmpty(rs1.getString("COLUMN_SIZE")), form2.format(msgArgs2[6])); + assertTrue(!StringUtils.isEmpty(rs1.getString("NULLABLE")), form2.format(msgArgs2[7])); // 11 + assertTrue(!StringUtils.isEmpty(rs1.getString("IS_NULLABLE")), form2.format(msgArgs2[8])); // 18 + assertTrue(!StringUtils.isEmpty(rs1.getString("IS_AUTOINCREMENT")), + form2.format(msgArgs2[9])); // 22 + } } } } @@ -374,29 +377,6 @@ public void testGetDBColumn() throws SQLException { } } - private void testGetDBColumnInternal(ResultSet rs1, DatabaseMetaData databaseMetaData) throws SQLException { - MessageFormat form2 = new MessageFormat(TestResource.getResource("R_nameEmpty")); - Object[][] msgArgs2 = {{"Category"}, {"SCHEMA"}, {"Table"}, {"COLUMN"}, {"Data Type"}, {"Type"}, - {"Column Size"}, {"Nullable value"}, {"IS_NULLABLE"}, {"IS_AUTOINCREMENT"}}; - if (!rs1.next()) { - fail(TestResource.getResource("R_resultSetEmpty")); - } else { - do { - assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_CAT")), form2.format(msgArgs2[0])); - assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_SCHEM")), form2.format(msgArgs2[1])); - assertTrue(!StringUtils.isEmpty(rs1.getString("TABLE_NAME")), form2.format(msgArgs2[2])); - assertTrue(!StringUtils.isEmpty(rs1.getString("COLUMN_NAME")), form2.format(msgArgs2[3])); - assertTrue(!StringUtils.isEmpty(rs1.getString("DATA_TYPE")), form2.format(msgArgs2[4])); - assertTrue(!StringUtils.isEmpty(rs1.getString("TYPE_NAME")), form2.format(msgArgs2[5])); - assertTrue(!StringUtils.isEmpty(rs1.getString("COLUMN_SIZE")), form2.format(msgArgs2[6])); - assertTrue(!StringUtils.isEmpty(rs1.getString("NULLABLE")), form2.format(msgArgs2[7])); // 11 - assertTrue(!StringUtils.isEmpty(rs1.getString("IS_NULLABLE")), form2.format(msgArgs2[8])); // 18 - assertTrue(!StringUtils.isEmpty(rs1.getString("IS_AUTOINCREMENT")), - form2.format(msgArgs2[9])); // 22 - } while (rs1.next()); - } - } - /** * We can improve this test case by following manner: *
    @@ -612,7 +592,7 @@ public void testGetMaxConnections() throws SQLException { public static void setupTable() throws SQLException { try (Statement stmt = connection.createStatement()) { stmt.execute("CREATE TABLE " + AbstractSQLGenerator.escapeIdentifier(tableName) - + " ([col_1] int NOT NULL, [col%2] varchar(200), [col[3] decimal(15,2))"); + + " (col1 int NOT NULL, col2 varchar(200), col3 decimal(15,2))"); stmt.execute("CREATE FUNCTION " + AbstractSQLGenerator.escapeIdentifier(functionName) + " (@p1 INT, @p2 INT) RETURNS INT AS BEGIN DECLARE @result INT; SET @result = @p1 + @p2; RETURN @result; END"); } diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java index af7b42d81..d17b5a17d 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/datatypes/SQLServerSpatialDatatypeTest.java @@ -5,7 +5,6 @@ package com.microsoft.sqlserver.jdbc.datatypes; import static org.junit.Assert.fail; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; @@ -958,8 +957,8 @@ public void testSTAsBinary() throws SQLException { byte[] geomWKB2 = geomWKT2.STAsBinary(); byte[] geogWKB2 = geogWKT2.STAsBinary(); - assertArrayEquals(geomWKB, geomWKB2); - assertArrayEquals(geogWKB, geogWKB2); + assertEquals(geomWKB, geomWKB2); + assertEquals(geogWKB, geogWKB2); } @Test diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/SQLServerDataTableTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/tvp/SQLServerDataTableTest.java deleted file mode 100644 index cea36fcbd..000000000 --- a/src/test/java/com/microsoft/sqlserver/jdbc/tvp/SQLServerDataTableTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made - * available under the terms of the MIT License. See the LICENSE file in the project root for more information. - */ - -package com.microsoft.sqlserver.jdbc.tvp; - -import static org.junit.Assert.assertEquals; - -import java.math.BigDecimal; -import java.sql.Types; -import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; - -import com.microsoft.sqlserver.jdbc.SQLServerDataColumn; -import com.microsoft.sqlserver.jdbc.SQLServerDataTable; -import com.microsoft.sqlserver.jdbc.SQLServerException; - - -@RunWith(JUnitPlatform.class) -public class SQLServerDataTableTest { - - @Test - public void testClear() throws SQLServerException { - SQLServerDataTable table = new SQLServerDataTable(); - SQLServerDataColumn a = new SQLServerDataColumn("foo", Types.VARCHAR); - SQLServerDataColumn b = new SQLServerDataColumn("bar", Types.INTEGER); - - table.addColumnMetadata(a); - table.addColumnMetadata(b); - assertEquals(2, table.getColumnMetadata().size()); - - table.clear(); - assertEquals(0, table.getColumnMetadata().size()); - - table.addColumnMetadata(a); - table.addColumnMetadata(b); - assertEquals(2, table.getColumnMetadata().size()); - } - - @Test - public void testHashCodes() throws SQLServerException { - // Test Null field values for SQLServerDataColumn - SQLServerDataColumn nullDataColumn1 = new SQLServerDataColumn(null, 0); - SQLServerDataColumn nullDataColumn2 = new SQLServerDataColumn(null, 0); - assert (nullDataColumn1.hashCode() == nullDataColumn2.hashCode()); - assert (nullDataColumn1.equals(nullDataColumn2)); - - // Test Null field values for SQLServerDataTable - SQLServerDataTable nullDataTable1 = new SQLServerDataTable(); - SQLServerDataTable nullDataTable2 = new SQLServerDataTable(); - assert (nullDataTable1.hashCode() == nullDataTable2.hashCode()); - assert (nullDataTable1.equals(nullDataTable2)); - - SQLServerDataColumn a = new SQLServerDataColumn("foo", Types.VARCHAR); - - // Test consistent generation of hashCode - assert (a.hashCode() == a.hashCode()); - assert (a.equals(a)); - - SQLServerDataColumn aClone = new SQLServerDataColumn("foo", Types.VARCHAR); - - // Test for different instances generating same hashCode for same data - assert (a.hashCode() == aClone.hashCode()); - assert (a.equals(aClone)); - - SQLServerDataColumn b = new SQLServerDataColumn("bar", Types.DECIMAL); - SQLServerDataTable table = createTable(a, b); - - // Test consistent generation of hashCode - assert (table.hashCode() == table.hashCode()); - assert (table.equals(table)); - - SQLServerDataTable tableClone = createTable(aClone, b); - - // Test for different instances generating same hashCode for same data - assert (table.hashCode() == tableClone.hashCode()); - assert (table.equals(tableClone)); - - // Test for non equal hashCodes - assert (a.hashCode() != b.hashCode()); - assert (!a.equals(b)); - - SQLServerDataColumn c = new SQLServerDataColumn("bar", Types.FLOAT); - table.clear(); - table = createTable(a, c); - - // Test for non equal hashCodes - assert (table.hashCode() != tableClone.hashCode()); - assert (!table.equals(tableClone)); - } - - private SQLServerDataTable createTable(SQLServerDataColumn a, SQLServerDataColumn b) throws SQLServerException { - SQLServerDataTable table = new SQLServerDataTable(); - table.addColumnMetadata(a); - table.addColumnMetadata(b); - table.addRow("Hello", new BigDecimal(1.5)); - table.addRow("World", new BigDecimal(5.5)); - table.setTvpName("TVP_HashCode"); - return table; - } -} diff --git a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java index 8bb32524d..1d46a075a 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/AbstractTest.java @@ -74,8 +74,7 @@ public abstract class AbstractTest { /** * This will take care of all initialization before running the Test Suite. * - * @throws Exception - * when an error occurs + * @throws Exception when an error occurs */ @BeforeAll public static void setup() throws Exception { @@ -243,8 +242,7 @@ protected static SQLServerConnection getConnection() throws SQLException { /** * This will take care of all clean ups after running the Test Suite. * - * @throws Exception - * when an error occurs + * @throws Exception when an error occurs */ @AfterAll public static void teardown() throws Exception { diff --git a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java index beecd8fed..b1ff0d894 100644 --- a/src/test/java/com/microsoft/sqlserver/testframework/Constants.java +++ b/src/test/java/com/microsoft/sqlserver/testframework/Constants.java @@ -6,6 +6,8 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.logging.Logger; +import com.microsoft.sqlserver.jdbc.RandomUtil; + public final class Constants { private Constants() {} @@ -23,7 +25,6 @@ private Constants() {} * xAzureSQLDW - - - - For tests not compatible with Azure Data Warehouse * xAzureSQLMI - - - - For tests not compatible with Azure SQL Managed Instance * NTLM - - - - - - - For NTLM tests - * reqExternalSetup - For tests requiring external setup * */ public static final String xJDBC42 = "xJDBC42"; @@ -35,7 +36,6 @@ private Constants() {} public static final String xAzureSQLDW = "xAzureSQLDW"; public static final String xAzureSQLMI = "xAzureSQLMI"; public static final String NTLM = "NTLM"; - public static final String reqExternalSetup = "reqExternalSetup"; public static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current(); public static final Logger LOGGER = Logger.getLogger("AbstractTest"); @@ -87,10 +87,8 @@ private Constants() {} + "Ǥ⚌c♮ƺåYèĢù⚏Ȓ★njäõpƸŃōoƝĤßuÙőƆE♹gLJÜŬȺDZ!Û☵ŦãǁĸNQŰǚǻTÖC]ǶýåÉbɉ☩=\\ȍáźŗǃĻýű☓☄¸T☑ö^k☏I:x☑⚀läiȉ☱☚⚅ǸǎãÂ"; // AE Constants - public static final String WINDOWS_KEY_STORE_NAME = "MSSQL_CERTIFICATE_STORE"; - public static final String AZURE_KEY_VAULT_NAME = "AZURE_KEY_VAULT"; - public static final String JAVA_KEY_STORE_NAME = "MSSQL_JAVA_KEYSTORE"; public static final String JAVA_KEY_STORE_FILENAME = "JavaKeyStore.txt"; + public static final String JAVA_KEY_STORE_NAME = "MSSQL_JAVA_KEYSTORE"; public static final String JAVA_KEY_STORE_SECRET = "JavaKeyStorePassword"; public static final String JKS = "JKS"; public static final String JKS_NAME = "clientcert.jks"; @@ -100,12 +98,15 @@ private Constants() {} public static final String UID = UUID.randomUUID().toString(); public static final Long RANDOM_LONG = Long.valueOf((long) (RANDOM.nextDouble() * Math.pow(10, 10))); public static final String CMK_NAME = "JDBC_CMK_" + RANDOM_LONG; - public static final String CMK_SIGNATURE = "0x5859A75C4F8C05C9865DAE46CA70F34B94EF1DF25D185DE8AB67918E5CF02953F2C787EFDC57ACAD5AEC2634C24B0A4C98B3A659220E980D948F91238A5D98CD898EF76CCA4AED9A6D51EBF4EABDEAA28CF975A7C8083E188AA4677303DAC9D6F49C81CB42E4BF14365B56BFEDD6E4B0DF0BC69E9FE313A7001613822D724A97055FA110C495A98EE37BE137293DF9E569D0845B96C4A6DD8554D42E83E784E3DCAFFDDD2CB3A7352920C3AAC43EA79BE5B8C7203B0E2F9B7C317C542E632C529BC46D792D9C85E16B5B3EE50D6D5E53103CC27B60175F79ECA1F2B28995FD1C12FA109E53810192BDD38A3B9A5D2CCC2BCBF16F936FE211A55FD999689C8CC4"; - public static final String CMK_SIGNATURE_AKV = "0x0474EC516A93B3EBCBD58E3AC35699E125F937AE6A56E96EC4FC37ACD09284CC99702B4762E56E8518A23A4D7EBF62FF735C8EEF4B61326CB8300ED09076D69008ACEB4156D9F2E1F95A8373335C33FCDD7DD7DF69CDD23544AB0D63B6D93379593E15C24D31EC0020F62BA23A19165C8A58AFAE8304DAC2996470919EBAB97587D685AEF4FFA3666E65DA673F41B2204410AFA69B9E05402853AB2AF0D22F4CF498394EB9DA8CA55814601DE6E004B12886C069010F911AE1F0EDA5DA3F1A09A211C7C30D21A567D47A8F133DF20A44E694900344FF3E189A8D6069CB86AA63D168B90CE4150F09A78DC09EF20FC239EA299E964762AE1FF711E407936FA9C9"; public static final String CEK_NAME = "JDBC_CEK_" + RANDOM_LONG; public static final String CEK_ALGORITHM = "RSA_OAEP"; public static final String CEK_STRING = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - public static final String CEK_ENCRYPTED_VALUE = "0x016E000001630075007200720065006E00740075007300650072002F006D0079002F0030003600640036003400630062003800320033003700320064003600350062003200330039003500610066003300370037006500630039006600330061003900380034003800300038003400360035004E087F31F14C340BB976498C67FB79C7B64B48029320176DCEF0E6F8F3B47178B67EF6804C9A7F914E961F4789EBEA1E8A4DB529E5E2289ABBB722DEB3D08EEC79749A9AAB2C9397FCA549E00CC60C8733AA6DFCDE078C45717F8A022B0BA4418D3B00A37454ACB32CEB40D9B23980EFEE4C7A7FD2D329B144044EE7447A99B69A90A504C4490A82B62D17E2E325FF6DF72EA76618CEDAB67CFA9D2F2C9DF7719F538EF915E086ACA8C2A21A753335C898A0E444B2C7772946203C7C1510B576F1F7F0BDCF8181F26FDAF1FBB5ECC3F348E49A62F677D08D26A40E6DCDB6682AEDAA20A416D31DA666DC07266AE7D06E6415A2CD0793A896047E619CA411997DC38457C3CF79AEBCAF021B7E68C21D2477B7CB1AFE45CF77E4137D838EE2F1C8178B83EED6EADCFB668D07D356F61DF2C39C8A00DA2AD91882649C90D413B391B284F37BDAC59766669FAC4BF177B8BC3DB93C258EC5801252B0BD91FDB09C9C2F19715F3DC7029B2E7F374D34B8C7D7F4A7DB58C897D651B52F8EC0C071C9442A4923688DB080613865E21B34EB2745BA9B99ADC6A95B41AF9B8F793078CFCFF684BC00326CEE43323D426F1DE9F89CC373B05A363341A91B24BCD320AACF678D032161C2E142C9C011691AEC5826C6CF2135AD86BD28E1FD51B7C7CEFDA5EBA56A87DACE7DED948E0338E3AFBEA9736AE5CBB2D9690EFA45402965462581A7"; + + public static final String CHAR_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedChar"); + public static final String BINARY_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedBinary"); + public static final String DATE_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedDate"); + public static final String NUMERIC_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedNumeric"); + public static final String SCALE_DATE_TABLE_AE = RandomUtil.getIdentifier("JDBCEncryptedScaleDate"); // Start: Connection Properties parsed in AbstractTest class for creating DataSource. public static final String INTEGRATED_SECURITY = "INTEGRATEDSECURITY"; @@ -135,8 +136,6 @@ private Constants() {} public static final String TRUST_STORE_SECRET_PROPERTY = "TRUSTSTOREPASSWORD"; public static final String TRUST_STORE = "TRUSTSTORE"; - public static final String ENCLAVE_ATTESTATIONURL = "enclaveAttestationUrl"; - public enum LOB { CLOB, NCLOB,