Skip to content
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

more AE tests and updated AE properties to not read from env variable #1186

Merged
merged 65 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
55d0840
add enclaveAttestationUrl property
lilgreenbird Sep 4, 2019
6f543bf
Merge pull request #1140 from lilgreenbird/aev2
rene-ye Sep 5, 2019
bd214ad
enclaveType
lilgreenbird Sep 6, 2019
0557d1a
enclaveType (#1141)
lilgreenbird Sep 6, 2019
5b0fee0
added some junit tests and attestationProtocol property
lilgreenbird Sep 6, 2019
22fa9bb
resovled conflicts
lilgreenbird Sep 6, 2019
6cb3994
Add | Enclave STuff
rene-ye Sep 12, 2019
ae19d23
Merge branch 'aev2' of https://github.com/rene-ye/mssql-jdbc into aev2
lilgreenbird Sep 12, 2019
4bc018f
asdf
rene-ye Sep 12, 2019
7aceb50
Merge branch 'aev2' of https://github.com/rene-ye/mssql-jdbc into aev2
lilgreenbird Sep 12, 2019
0898459
merged with Rene
lilgreenbird Sep 12, 2019
ca3b4ed
asd
rene-ye Sep 13, 2019
793eb38
Merge branch 'aev2' of https://github.com/rene-ye/mssql-jdbc into aev2
lilgreenbird Sep 13, 2019
72e4daa
asdf
rene-ye Sep 13, 2019
7a81056
merged
lilgreenbird Sep 13, 2019
bd5ddca
fix server stuff
rene-ye Sep 13, 2019
0816100
save work
lilgreenbird Sep 23, 2019
256aae7
parse json
rene-ye Sep 23, 2019
d619849
Fix ECDH Key
rene-ye Sep 24, 2019
6333f79
fixed akv verify
lilgreenbird Sep 24, 2019
b78470f
merged with rene
lilgreenbird Sep 24, 2019
aa11348
Add | generate session key
rene-ye Sep 26, 2019
f37606f
merged with Rene
lilgreenbird Sep 26, 2019
e2869d5
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Sep 26, 2019
4d9b2eb
Merge branch 'aev2' of https://github.com/lilgreenbird/mssql-jdbc int…
Sep 27, 2019
c203a2f
merged dev
lilgreenbird Oct 4, 2019
af25a94
merged
lilgreenbird Oct 16, 2019
1a70872
Merge remote-tracking branch 'upstream/dev' into dev
lilgreenbird Oct 16, 2019
b86eef3
merged
lilgreenbird Oct 16, 2019
c4acfb8
updated to use reqExternalSetup tag
lilgreenbird Oct 17, 2019
20aa27d
refactored tests to use reqExternalSetup and added tests for more dat…
lilgreenbird Oct 21, 2019
2634835
Merge remote-tracking branch 'upstream/dev' into aetests
Oct 22, 2019
541da60
added properties to run AE tests
lilgreenbird Oct 22, 2019
74e23af
fixed typo
lilgreenbird Oct 23, 2019
4e243b3
fixed typo
lilgreenbird Oct 23, 2019
aa9f25e
add dll
lilgreenbird Oct 23, 2019
79363c7
copy dll to default classpath
lilgreenbird Oct 23, 2019
41fa8bd
fixed
lilgreenbird Oct 23, 2019
6019e95
fix
lilgreenbird Oct 23, 2019
8020b61
added debug
lilgreenbird Oct 23, 2019
91552df
changed to HGS server
lilgreenbird Oct 23, 2019
16dd417
removed debug line
lilgreenbird Oct 23, 2019
f672758
assumeTrue
lilgreenbird Oct 24, 2019
d7644eb
removed reqExternalSetup for AE tests
lilgreenbird Oct 24, 2019
65f0fcd
fixed typo for jre11
lilgreenbird Oct 24, 2019
30726b1
removed reqExternalSetup from reg AE tests
lilgreenbird Oct 24, 2019
7790d4f
windows check
lilgreenbird Oct 24, 2019
b9ac82b
added comment to trigger build
lilgreenbird Oct 24, 2019
a8ce69a
added more tests and fixed some stuff
lilgreenbird Oct 26, 2019
d1cd647
added aev2 check
lilgreenbird Oct 26, 2019
560b02d
update jacoco version and add code coverage
lilgreenbird Oct 29, 2019
7603161
added more tests and fix executeBatch issue
lilgreenbird Oct 30, 2019
12bceac
more tests
lilgreenbird Oct 31, 2019
b131be5
tag
lilgreenbird Oct 31, 2019
fb460c6
more tests
lilgreenbird Oct 31, 2019
ea1f5c1
fix
lilgreenbird Nov 1, 2019
ef1b364
review updates and added more negative test
lilgreenbird Nov 8, 2019
960243f
Merge remote-tracking branch 'upstream/dev' into aetests
lilgreenbird Nov 13, 2019
cb88339
merged
lilgreenbird Nov 13, 2019
75e6475
more AE tests
lilgreenbird Nov 17, 2019
21b394d
removed reading env vars for properties
lilgreenbird Nov 18, 2019
625fb70
only read connection string and logging string from env var
lilgreenbird Nov 19, 2019
549c6ac
more tests
lilgreenbird Nov 19, 2019
cdaa085
added support for config.properties file
lilgreenbird Nov 22, 2019
05c2fe3
review updates
lilgreenbird Nov 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ public static void setUpConnection() throws TestAbortedException, Exception {

readFromFile(Constants.JAVA_KEY_STORE_FILENAME, "Alias name");

String enclaveAttestationUrl = TestUtils.getConfiguredProperty("enclaveAttestationUrl");
String enclaveAttestationUrl = System.getProperty("enclaveAttestationUrl");
lilgreenbird marked this conversation as resolved.
Show resolved Hide resolved
if (null != enclaveAttestationUrl) {
AETestConnectionString = TestUtils.addOrOverrideProperty(AETestConnectionString, "enclaveAttestationUrl",
enclaveAttestationUrl);
}
String enclaveAttestationProtocol = TestUtils.getConfiguredProperty("enclaveAttestationProtocol");
String enclaveAttestationProtocol = System.getProperty("enclaveAttestationProtocol");
lilgreenbird marked this conversation as resolved.
Show resolved Hide resolved
if (null != enclaveAttestationProtocol) {
AETestConnectionString = TestUtils.addOrOverrideProperty(AETestConnectionString,
"enclaveAttestationProtocol", enclaveAttestationProtocol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,25 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.util.LinkedList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.opentest4j.TestAbortedException;

import com.microsoft.aad.adal4j.AuthenticationContext;
import com.microsoft.aad.adal4j.AuthenticationResult;
import com.microsoft.aad.adal4j.ClientCredential;
import com.microsoft.sqlserver.jdbc.RandomData;
import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider;
import com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionJavaKeyStoreProvider;
import com.microsoft.sqlserver.jdbc.SQLServerConnection;
import com.microsoft.sqlserver.jdbc.SQLServerException;
import com.microsoft.sqlserver.jdbc.SQLServerKeyVaultAuthenticationCallback;
import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement;
import com.microsoft.sqlserver.jdbc.SQLServerResultSet;
import com.microsoft.sqlserver.jdbc.SQLServerStatement;
Expand Down Expand Up @@ -59,6 +69,247 @@ enum TestCase {
NULL
}

/*
* Test getting/setting JKS name
*/
@Test
public void testJksName() {
try {
SQLServerColumnEncryptionJavaKeyStoreProvider jksp = new SQLServerColumnEncryptionJavaKeyStoreProvider(
javaKeyPath, new char[1]);
String keystoreName = "keystoreName";
jksp.setName(keystoreName);
assertTrue(jksp.getName().equals(keystoreName));
} catch (SQLServerException e) {
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}
}

/*
* Test getting/setting AKV name
*/
@Test
public void testAkvName() {
try {
SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(
authenticationCallback);
String keystoreName = "keystoreName";
akv.setName(keystoreName);
assertTrue(akv.getName().equals(keystoreName));
} catch (SQLServerException e) {
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}
}

/*
* Test bad Java Key Store
*/
@SuppressWarnings("unused")
@Test
public void testBadJks() {
try {
SQLServerColumnEncryptionJavaKeyStoreProvider jksp = new SQLServerColumnEncryptionJavaKeyStoreProvider(null,
null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidConnectionSetting")));
}
}

/*
* Test bad Azure Key Vault
*/
@SuppressWarnings("unused")
@Test
public void testBadAkv() {
try {
SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(
null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_NullValue")));
}
}

/*
* Test bad encryptColumnEncryptionKey for JKS
*/
@Test
public void testJksBadEncryptColumnEncryptionKey() {
SQLServerColumnEncryptionJavaKeyStoreProvider jksp = null;
char[] secret = new char[1];
try {
jksp = new SQLServerColumnEncryptionJavaKeyStoreProvider(javaKeyPath, secret);
} catch (SQLServerException e) {
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

// null masterKeyPath
try {
jksp.encryptColumnEncryptionKey(null, null, null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidMasterKeyDetails")));
}

// empty cek
try {
byte[] emptyCek = new byte[0];
jksp.encryptColumnEncryptionKey(javaKeyPath, Constants.CEK_ALGORITHM, emptyCek);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_EmptyColumnEncryptionKey")));
}
}

/*
* Test bad encryptColumnEncryptionKey for AKV
*/
@Test
public void testAkvBadEncryptColumnEncryptionKey() {
SQLServerColumnEncryptionAzureKeyVaultProvider akv = null;
try {
akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(authenticationCallback);
} catch (SQLServerException e) {
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

// null encryptedColumnEncryptionKey
try {
akv.encryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_NullColumnEncryptionKey")));
}

// empty encryptedColumnEncryptionKey
try {
byte[] emptyCek = new byte[0];
akv.encryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, emptyCek);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_EmptyCEK")));
}
}

/*
* Test decryptColumnEncryptionKey for JKS
*/
@Test
public void testJksDecryptColumnEncryptionKey() {
SQLServerColumnEncryptionJavaKeyStoreProvider jksp = null;
char[] secret = new char[1];
try {
jksp = new SQLServerColumnEncryptionJavaKeyStoreProvider("badkeypath", secret);
} catch (SQLServerException e) {
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

// null masterKeyPath
try {
jksp.decryptColumnEncryptionKey(null, null, null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidMasterKeyDetails")));
}

// bad keystore
try {
byte[] emptyCek = new byte[0];
jksp.decryptColumnEncryptionKey("keypath", "algorithm", emptyCek);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_KeyStoreNotFound")));
}

try {
jksp = new SQLServerColumnEncryptionJavaKeyStoreProvider(javaKeyPath, secret);
} catch (SQLServerException e) {
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

// bad cert
try {
byte[] badCek = new byte[1];
jksp.decryptColumnEncryptionKey(javaKeyAliases, "RSA_OAEP", badCek);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_invalidKeyStoreFile")));
}
}

/*
* Test decryptColumnEncryptionKey for AKV
*/
@Test
public void testAkvDecryptColumnEncryptionKey() {
SQLServerColumnEncryptionAzureKeyVaultProvider akv = null;
try {
akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(authenticationCallback);
} catch (SQLServerException e) {
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}

// null akvpath
try {
akv.decryptColumnEncryptionKey(null, "", null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AKVPathNull")));
}

// invalid akvpath
try {
akv.decryptColumnEncryptionKey("keypath", "", null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AKVMasterKeyPathInvalid")));
}

// invalid akvpath url
try {
akv.decryptColumnEncryptionKey("http:///^[!#$&-;=?-[]_a-", "", null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_AKVURLInvalid")));
}

// null encryptedColumnEncryptionKey
try {
akv.decryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, null);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_NullEncryptedColumnEncryptionKey")));
}

// empty encryptedColumnEncryptionKey
try {
byte[] emptyCek = new byte[0];
akv.decryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, emptyCek);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_EmptyEncryptedColumnEncryptionKey")));
}

// invalid algorithm
try {
byte[] badCek = new byte[1];
akv.decryptColumnEncryptionKey(keyIDs[0], "invalidAlgo", badCek);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidKeyEncryptionAlgorithm")));
}

// bad encryptedColumnEncryptionKey
try {
byte[] badCek = new byte[1];
akv.decryptColumnEncryptionKey(keyIDs[0], Constants.CEK_ALGORITHM, badCek);
fail(TestResource.getResource("R_expectedExceptionNotThrown"));
} catch (SQLServerException e) {
assertTrue(e.getMessage().matches(TestUtils.formatErrorMsg("R_InvalidEcryptionAlgorithmVersion")));
}
}

/**
* Junit test case for char set string for string values
*
Expand Down Expand Up @@ -1525,8 +1776,8 @@ void testChars(SQLServerStatement stmt, String cekName, String[][] table, String
testChar(null, values);

if (isTestEnclave) {
if (null == getConfiguredProperty(Constants.ENCLAVE_ATTESTATIONURL)
|| null == getConfiguredProperty(Constants.ENCLAVE_ATTESTATIONPROTOCOL)) {
if (null == System.getProperty(Constants.ENCLAVE_ATTESTATIONURL)
lilgreenbird marked this conversation as resolved.
Show resolved Hide resolved
|| null == System.getProperty(Constants.ENCLAVE_ATTESTATIONPROTOCOL)) {
fail(TestResource.getResource("R_reqExternalSetup"));
}

Expand Down Expand Up @@ -1564,8 +1815,8 @@ void testBinaries(SQLServerStatement stmt, String cekName, String[][] table, Lin
testBinary(null, values);

if (isTestEnclave) {
if (null == getConfiguredProperty(Constants.ENCLAVE_ATTESTATIONURL)
|| null == getConfiguredProperty(Constants.ENCLAVE_ATTESTATIONPROTOCOL)) {
if (null == System.getProperty(Constants.ENCLAVE_ATTESTATIONURL)
|| null == System.getProperty(Constants.ENCLAVE_ATTESTATIONPROTOCOL)) {
fail(TestResource.getResource("R_reqExternalSetup"));
}

Expand Down Expand Up @@ -1607,8 +1858,8 @@ void testDates(SQLServerStatement stmt, String cekName, String[][] table, Linked
testDate(null, values);

if (isTestEnclave) {
if (null == getConfiguredProperty(Constants.ENCLAVE_ATTESTATIONURL)
|| null == getConfiguredProperty(Constants.ENCLAVE_ATTESTATIONPROTOCOL)) {
if (null == System.getProperty(Constants.ENCLAVE_ATTESTATIONURL)
|| null == System.getProperty(Constants.ENCLAVE_ATTESTATIONPROTOCOL)) {
fail(TestResource.getResource("R_reqExternalSetup"));
}

Expand Down Expand Up @@ -1646,8 +1897,8 @@ void testNumerics(SQLServerStatement stmt, String cekName, String[][] table, Str
testNumeric(null, values2, isNull);

if (isTestEnclave) {
if (null == getConfiguredProperty(Constants.ENCLAVE_ATTESTATIONURL)
|| null == getConfiguredProperty(Constants.ENCLAVE_ATTESTATIONPROTOCOL)) {
if (null == System.getProperty(Constants.ENCLAVE_ATTESTATIONURL)
|| null == System.getProperty(Constants.ENCLAVE_ATTESTATIONPROTOCOL)) {
fail(TestResource.getResource("R_reqExternalSetup"));
}

Expand All @@ -1656,4 +1907,27 @@ void testNumerics(SQLServerStatement stmt, String cekName, String[][] table, Str
testRichQuery(stmt, NUMERIC_TABLE_AE, table, values2);
}
}

SQLServerKeyVaultAuthenticationCallback authenticationCallback = new SQLServerKeyVaultAuthenticationCallback() {
// @Override
ExecutorService service = Executors.newFixedThreadPool(2);

public String getAccessToken(String authority, String resource, String scope) {

AuthenticationResult result = null;
try {
AuthenticationContext context = new AuthenticationContext(authority, false, service);
ClientCredential cred = new ClientCredential(applicationClientID, applicationKey);
Future<AuthenticationResult> future = context.acquireToken(resource, cred, null);
result = future.get();
return result.getAccessToken();
} catch (Exception e) {
e.printStackTrace();
lilgreenbird marked this conversation as resolved.
Show resolved Hide resolved
return null;
}

lilgreenbird marked this conversation as resolved.
Show resolved Hide resolved
// return null;
}
};

}
Loading