Skip to content

Always encrypted unicode data corruption guard #2289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Additional test updates for SSPAU=false
  • Loading branch information
tkyc committed Jan 10, 2024
commit 663846dd14207bf37f0ae7f3b0f96903c8cad8f4
Original file line number Diff line number Diff line change
@@ -1082,7 +1082,7 @@ protected static void populateCharSetObjectWithJDBCTypes(String[] charValues) th
String sql = "insert into " + CHAR_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?,"
+ "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")";

try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {

@@ -1144,7 +1144,7 @@ protected static void populateCharNullCase() throws SQLException {
String sql = "insert into " + CHAR_TABLE_AE + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?,"
+ "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?" + ")";

try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (SQLServerConnection con = (SQLServerConnection) PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {

Original file line number Diff line number Diff line change
@@ -540,7 +540,7 @@ private void createMultiInsertionSelection() throws SQLException {
+ TestUtils.escapeSingleQuotes(multiStatementsProcedure)
+ "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + multiStatementsProcedure;

try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (Connection con = PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
stmt.execute(sql);

@@ -556,7 +556,7 @@ private void createMultiInsertionSelection() throws SQLException {
private void MultiInsertionSelection() throws SQLException {

String sql = "{call " + multiStatementsProcedure + " (?,?,?,?,?,?)}";
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (Connection con = PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {

@@ -673,7 +673,7 @@ private void createInputProcedure2() throws SQLException {
+ TestUtils.escapeSingleQuotes(inputProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)"
+ " DROP PROCEDURE " + inputProcedure2;

try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (Connection con = PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
stmt.execute(sql);

@@ -690,7 +690,7 @@ private void createInputProcedure2() throws SQLException {

private void testInputProcedure2(String sql) throws SQLException {

try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (Connection con = PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {

Original file line number Diff line number Diff line change
@@ -210,7 +210,7 @@ public void testVerifyBadJksSignature(String serverName, String url, String prot
String badTable = TestUtils.escapeSingleQuotes(
AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("testVerifyBadJksSignature")));

try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
Statement s = c.createStatement()) {
createCMK(AETestConnectionString, badCmk, Constants.JAVA_KEY_STORE_NAME, javaKeyAliases, "0x666");
createCEK(AETestConnectionString, badCmk, badCek, jksProvider);
@@ -256,7 +256,7 @@ public void testVerifyBadAkvSignature(String serverName, String url, String prot
String badTable = TestUtils.escapeSingleQuotes(
AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("testVerifyBadAkvSignature")));

try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
Statement s = c.createStatement()) {
createCMK(AETestConnectionString, badCmk, Constants.AZURE_KEY_VAULT_NAME, keyIDs[0], "0x666");
createCEK(AETestConnectionString, badCmk, badCek, akvProvider);
@@ -301,7 +301,7 @@ public void testVerifyBadWinSignature(String serverName, String url, String prot
String badTable = TestUtils.escapeSingleQuotes(
AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("testVerifyBadWinSignature")));

try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
Statement s = c.createStatement()) {
// create CMK with a bad signature
createCMK(AETestConnectionString, badCmk, Constants.WINDOWS_KEY_STORE_NAME, windowsKeyPath, "0x666");
@@ -397,7 +397,7 @@ public void testAEFMTOnly(String serverName, String url, String protocol) throws
@MethodSource("enclaveParams")
public void testAlter(String serverName, String url, String protocol) throws Exception {
setAEConnectionString(serverName, url, protocol);
try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
Statement s = c.createStatement()) {
createTable(CHAR_TABLE_AE, cekJks, varcharTableSimple);
PreparedStatement pstmt = c.prepareStatement("INSERT INTO " + CHAR_TABLE_AE + " VALUES (?,?,?)");
@@ -445,7 +445,7 @@ public void testNumericRichQuery(String serverName, String url, String protocol)
@MethodSource("enclaveParams")
public void testStringRichQuery(String serverName, String url, String protocol) throws Exception {
setAEConnectionString(serverName, url, protocol);
try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
Statement s = c.createStatement()) {
createTable(CHAR_TABLE_AE, cekJks, varcharTableSimple);

@@ -473,7 +473,7 @@ public void testStringRichQuery(String serverName, String url, String protocol)
@MethodSource("enclaveParams")
public void testAlterNoEncrypt(String serverName, String url, String protocol) throws Exception {
setAEConnectionString(serverName, url, protocol);
try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (SQLServerConnection c = PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
Statement s = c.createStatement()) {
createTable(CHAR_TABLE_AE, cekJks, varcharTableSimple);
PreparedStatement pstmt = c.prepareStatement("INSERT INTO " + CHAR_TABLE_AE + " VALUES (?,?,?)");
Original file line number Diff line number Diff line change
@@ -526,7 +526,7 @@ public void testStatementCustomKeyStoreProviderDuringAeQuery() throws Exception
private void insertData(String tableName, int customId, String customName) {
String sqlQuery = "INSERT INTO " + tableName + " VALUES ( ?, ? )";

try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
try (SQLServerConnection con = PrepUtil.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;", AEInfo);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sqlQuery,
SQLServerStatementColumnEncryptionSetting.ENABLED)) {
pstmt.setInt(1, customId);
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ public void alwaysEncrypted1(String serverName, String url, String protocol) thr
public void alwaysEncrypted2(String serverName, String url, String protocol) throws Exception {
setAEConnectionString(serverName, url, protocol);
try (Connection connection = PrepUtil
.getConnection(AETestConnectionString + ";columnEncryptionSetting=enabled;", AEInfo);
.getConnection(AETestConnectionString + ";sendStringParametersAsUnicode=false;columnEncryptionSetting=enabled;", AEInfo);
Statement stmt = connection.createStatement()) {
dropTables(stmt);