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

Change | Enclave caching key #1388

Merged
merged 2 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -426,8 +426,10 @@ final class EnclaveSessionCache {
sessionCache = new Hashtable<>(0);
}

void addEntry(String servername, String attestationUrl, BaseAttestationRequest b, EnclaveSession e) {
sessionCache.put(servername + attestationUrl, new EnclaveCacheEntry(b, e));
void addEntry(String servername, String catalog, String attestationUrl, BaseAttestationRequest b,
EnclaveSession e) {
StringBuilder sb = new StringBuilder(servername).append(catalog).append(attestationUrl);
sessionCache.put(sb.toString(), new EnclaveCacheEntry(b, e));
}

void removeEntry(EnclaveSession e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public class SQLServerAASEnclaveProvider implements ISQLServerEnclaveProvider {

private AASAttestationParameters aasParams = null;
private AASAttestationResponse hgsResponse = null;
private String attestationURL = null;
private String attestationUrl = null;
private EnclaveSession enclaveSession = null;

@Override
public void getAttestationParameters(String url) throws SQLServerException {
if (null == aasParams) {
attestationURL = url;
attestationUrl = url;
try {
aasParams = new AASAttestationParameters(attestationURL);
aasParams = new AASAttestationParameters(attestationUrl);
} catch (IOException e) {
SQLServerException.makeFromDriverError(null, this, e.getLocalizedMessage(), "0", false);
}
Expand All @@ -65,21 +65,24 @@ public void getAttestationParameters(String url) throws SQLServerException {
public ArrayList<byte[]> createEnclaveSession(SQLServerConnection connection, String userSql,
String preparedTypeDefinitions, Parameter[] params,
ArrayList<String> parameterNames) throws SQLServerException {
// Check if the session exists in our cache
ulvii marked this conversation as resolved.
Show resolved Hide resolved
StringBuilder keyLookup = new StringBuilder(connection.getServerName()).append(connection.getCatalog())
.append(attestationUrl);
EnclaveCacheEntry entry = enclaveCache.getSession(keyLookup.toString());
if (null != entry) {
this.enclaveSession = entry.getEnclaveSession();
this.aasParams = (AASAttestationParameters) entry.getBaseAttestationRequest();
}
ArrayList<byte[]> b = describeParameterEncryption(connection, userSql, preparedTypeDefinitions, params,
parameterNames);
if (null != hgsResponse && !connection.enclaveEstablished()) {
// Check if the session exists in our cache
EnclaveCacheEntry entry = enclaveCache.getSession(connection.getServerName() + attestationURL);
if (null != entry) {
this.enclaveSession = entry.getEnclaveSession();
this.aasParams = (AASAttestationParameters) entry.getBaseAttestationRequest();
return b;
}
if (connection.enclaveEstablished()) {
return b;
} else if (null != hgsResponse && !connection.enclaveEstablished()) {
try {
enclaveSession = new EnclaveSession(hgsResponse.getSessionID(),
aasParams.createSessionSecret(hgsResponse.getDHpublicKey()));
enclaveCache.addEntry(connection.getServerName(), connection.enclaveAttestationUrl, aasParams,
enclaveSession);
enclaveCache.addEntry(connection.getServerName(), connection.getCatalog(),
connection.enclaveAttestationUrl, aasParams, enclaveSession);
} catch (GeneralSecurityException e) {
SQLServerException.makeFromDriverError(connection, this, e.getLocalizedMessage(), "0", false);
}
Expand All @@ -94,7 +97,7 @@ public void invalidateEnclaveSession() {
}
enclaveSession = null;
aasParams = null;
attestationURL = null;
attestationUrl = null;
}

@Override
Expand All @@ -105,7 +108,7 @@ public EnclaveSession getEnclaveSession() {
private void validateAttestationResponse() throws SQLServerException {
if (null != hgsResponse) {
try {
hgsResponse.validateToken(attestationURL, aasParams.getNonce());
hgsResponse.validateToken(attestationUrl, aasParams.getNonce());
hgsResponse.validateDHPublicKey(aasParams.getNonce());
} catch (GeneralSecurityException e) {
SQLServerException.makeFromDriverError(null, this, e.getLocalizedMessage(), "0", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3609,10 +3609,6 @@ public String getCatalog() throws SQLServerException {
return sCatalog;
}

String getSCatalog() throws SQLServerException {
return sCatalog;
}

@Override
public void setTransactionIsolation(int level) throws SQLServerException {
if (loggerExternal.isLoggable(Level.FINER)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,26 @@ public void getAttestationParameters(String url) throws SQLServerException {
public ArrayList<byte[]> createEnclaveSession(SQLServerConnection connection, String userSql,
String preparedTypeDefinitions, Parameter[] params,
ArrayList<String> parameterNames) throws SQLServerException {
// Check if the session exists in our cache
StringBuilder keyLookup = new StringBuilder(connection.getServerName()).append(connection.getCatalog())
.append(attestationUrl);
EnclaveCacheEntry entry = enclaveCache.getSession(keyLookup.toString());
if (null != entry) {
this.enclaveSession = entry.getEnclaveSession();
this.vsmParams = (VSMAttestationParameters) entry.getBaseAttestationRequest();
}
ArrayList<byte[]> b = describeParameterEncryption(connection, userSql, preparedTypeDefinitions, params,
parameterNames);
if (null != hgsResponse && !connection.enclaveEstablished()) {
// Check if the session exists in our cache
EnclaveCacheEntry entry = enclaveCache.getSession(connection.getServerName() + attestationUrl);
if (null != entry) {
this.enclaveSession = entry.getEnclaveSession();
this.vsmParams = (VSMAttestationParameters) entry.getBaseAttestationRequest();
return b;
}
if (connection.enclaveEstablished()) {
return b;
} else if (null != hgsResponse && !connection.enclaveEstablished()) {

// If not, set it up
try {
enclaveSession = new EnclaveSession(hgsResponse.getSessionID(),
vsmParams.createSessionSecret(hgsResponse.getDHpublicKey()));
enclaveCache.addEntry(connection.getServerName(), connection.enclaveAttestationUrl, vsmParams,
enclaveSession);
enclaveCache.addEntry(connection.getServerName(), connection.getCatalog(),
connection.enclaveAttestationUrl, vsmParams, enclaveSession);
} catch (GeneralSecurityException e) {
SQLServerException.makeFromDriverError(connection, this, e.getLocalizedMessage(), "0", false);
}
Expand Down