Skip to content

Commit

Permalink
Merge pull request #4 from lilgreenbird/msal
Browse files Browse the repository at this point in the history
Msal
  • Loading branch information
srnagar authored Sep 23, 2020
2 parents 7d4274f + a711913 commit 122e408
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 31 deletions.
14 changes: 7 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ jobs:
inputs:
secureFile: 'mssql-jdbc_auth-9.1.0.x64-preview.dll'
- task: Maven@3
displayName: 'Maven build jre14'
displayName: 'Maven build jre15'
inputs:
mavenPomFile: 'pom.xml'
goals: 'clean dependency:purge-local-repository -DdllPath=$(Agent.TempDirectory) -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pjre14 -DuserNTLM=$(userNTLM) -DpasswordNTLM=$(passwordNTLM) -DdomainNTLM=$(domainNTLM) -DexcludedGroups=$(Ex_Groups) -Dpkcs12_truststore_password=$(pkcs12_truststore_password) -Dpkcs12_truststore=$(pkcs12_truststore.secureFilePath)
goals: 'clean dependency:purge-local-repository -DdllPath=$(Agent.TempDirectory) -Dmssql_jdbc_test_connection_properties=jdbc:sqlserver://$(Target_SQL)$(server_domain);$(database);$(user);$(password); install -Pjre15 -DuserNTLM=$(userNTLM) -DpasswordNTLM=$(passwordNTLM) -DdomainNTLM=$(domainNTLM) -DexcludedGroups=$(Ex_Groups) -Dpkcs12_truststore_password=$(pkcs12_truststore_password) -Dpkcs12_truststore=$(pkcs12_truststore.secureFilePath)
-DapplicationClientID=$(applicationClientID) -DapplicationKey=$(applicationKey) -DkeyID=$(keyID) -DwindowsKeyPath=$(windowsKeyPath) -DenclaveAttestationUrl=$(enclaveAttestationUrl) -DenclaveAttestationProtocol=$(enclaveAttestationProtocol) -DenclaveServer=$(enclaveServer)'
testResultsFiles: '**/TEST-*.xml'
testRunTitle: 'Maven build jre14'
testRunTitle: 'Maven build jre15'
javaHomeOption: Path
jdkDirectory: $(JDK14)
jdkDirectory: $(JDK15)
- task: Maven@3
displayName: 'Maven build jre11'
inputs:
Expand All @@ -58,14 +58,14 @@ jobs:
testResultsFiles: '**/TEST-*.xml'
testRunTitle: 'Maven build jre11'
javaHomeOption: Path
jdkDirectory: $(JDK14)
jdkDirectory: $(JDK15)
- task: Maven@3
displayName: 'Maven build jre8'
inputs:
mavenPomFile: 'pom.xml'
goals: 'clean dependency:purge-local-repository -DdllPath=$(Agent.TempDirectory) -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 dependency:purge-local-repository -DdllPath=$(Agent.TempDirectory) -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)
-DapplicationClientID=$(applicationClientID) -DapplicationKey=$(applicationKey) -DkeyID=$(keyID) -DwindowsKeyPath=$(windowsKeyPath) -DenclaveAttestationUrl=$(enclaveAttestationUrl) -DenclaveAttestationProtocol=$(enclaveAttestationProtocol) -DenclaveServer=$(enclaveServer)'
testResultsFiles: '**/TEST-*.xml'
testRunTitle: 'Maven build jre8'
javaHomeOption: Path
jdkDirectory: $(JDK14)
jdkDirectory: $(JDK15)
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
****************************************************************
* Instruction for Building JDBC Driver:
* For building particular version of the driver, use commands:
* jre14 - - PS> gradle build
PS> gradle build -PbuildProfile=jre14
* jre15 - - PS> gradle build
PS> gradle build -PbuildProfile=jre15
* jre11 - - PS> gradle build -PbuildProfile=jre11
* jre8 - - PS> gradle build -PbuildProfile=jre8
*
Expand Down Expand Up @@ -35,17 +35,17 @@ test {
}
}

if (!hasProperty('buildProfile') || (hasProperty('buildProfile') && buildProfile == "jre14")){
if (!hasProperty('buildProfile') || (hasProperty('buildProfile') && buildProfile == "jre15")){

jreVersion = "jre14"
jreVersion = "jre15"
excludedFile = 'com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java'
jar {
manifest {
attributes 'Automatic-Module-Name': 'com.microsoft.sqlserver.jdbc'
}
}
sourceCompatibility = 14
targetCompatibility = 14
sourceCompatibility = 15
targetCompatibility = 15
}

if (hasProperty('buildProfile') && buildProfile == "jre11"){
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,12 @@
</build>
</profile>
<profile>
<id>jre14</id>
<id>jre15</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<finalName>${project.artifactId}-${project.version}.jre14${releaseExt}</finalName>
<finalName>${project.artifactId}-${project.version}.jre15${releaseExt}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -322,8 +322,8 @@
<excludes>
<exclude>**/com/microsoft/sqlserver/jdbc/SQLServerJdbc42.java</exclude>
</excludes>
<source>14</source>
<target>14</target>
<source>15</source>
<target>15</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -430,7 +430,7 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>4.2.0</version>
<version>5.1.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
Expand Down Expand Up @@ -484,7 +484,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<version>0.8.6</version>
<executions>
<execution>
<id>pre-test</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.CompletableFuture;
import reactor.core.publisher.Mono;


/**
* An AAD credential that acquires a token with a client secret for an AAD application.
*/
Expand Down Expand Up @@ -73,7 +74,7 @@ class KeyVaultTokenCredential implements TokenCredential {

@Override
public Mono<AccessToken> getToken(TokenRequestContext request) {
if (null == authenticationCallback) {
if (null != authenticationCallback) {
String accessToken = authenticationCallback.getAccessToken(this.authorization, this.resource, this.scope);
return Mono.just(new AccessToken(accessToken, OffsetDateTime.MIN));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.azure.security.keyvault.keys.models.KeyType;
import com.azure.security.keyvault.keys.models.KeyVaultKey;


/**
* Provides implementation similar to certificate store provider. A CEK encrypted with certificate store provider should
* be decryptable by this provider and vice versa.
Expand Down Expand Up @@ -170,8 +171,6 @@ public SQLServerColumnEncryptionAzureKeyVaultProvider(TokenCredential tokenCrede
createKeyvaultClients(tokenCredential);
}



/**
* Constructs a SQLServerColumnEncryptionAzureKeyVaultProvider with a callback function to authenticate to AAD and
* an executor service.. This is used by KeyVaultClient at runtime to authenticate to Azure Key Vault.
Expand Down Expand Up @@ -253,7 +252,7 @@ public byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryption
}

// Validate encryptionAlgorithm
KeyWrapAlgorithm _encryptionAlgorithm = this.validateEncryptionAlgorithm(encryptionAlgorithm);
KeyWrapAlgorithm keyWrapAlgorithm = this.validateEncryptionAlgorithm(encryptionAlgorithm);

// Validate whether the key is RSA one or not and then get the key size
int keySizeInBytes = getAKVKeySize(masterKeyPath);
Expand Down Expand Up @@ -341,7 +340,7 @@ public byte[] decryptColumnEncryptionKey(String masterKeyPath, String encryption
}

// Decrypt the CEK
byte[] decryptedCEK = this.AzureKeyVaultUnWrap(masterKeyPath, _encryptionAlgorithm, cipherText);
byte[] decryptedCEK = this.AzureKeyVaultUnWrap(masterKeyPath, keyWrapAlgorithm, cipherText);

return decryptedCEK;
}
Expand Down Expand Up @@ -389,7 +388,7 @@ public byte[] encryptColumnEncryptionKey(String masterKeyPath, String encryption
}

// Validate encryptionAlgorithm
KeyWrapAlgorithm _encryptionAlgorithm = this.validateEncryptionAlgorithm(encryptionAlgorithm);
KeyWrapAlgorithm keyWrapAlgorithm = this.validateEncryptionAlgorithm(encryptionAlgorithm);

// Validate whether the key is RSA one or not and then get the key size
int keySizeInBytes = getAKVKeySize(masterKeyPath);
Expand All @@ -409,7 +408,7 @@ public byte[] encryptColumnEncryptionKey(String masterKeyPath, String encryption
keyPathLength[1] = (byte) (((short) masterKeyPathBytes.length) >> 8 & 0xff);

// Encrypt the plain text
byte[] cipherText = this.AzureKeyVaultWrap(masterKeyPath, _encryptionAlgorithm, columnEncryptionKey);
byte[] cipherText = this.AzureKeyVaultWrap(masterKeyPath, keyWrapAlgorithm, columnEncryptionKey);

byte[] cipherTextLength = new byte[2];
cipherTextLength[0] = (byte) (((short) cipherText.length) & 0xff);
Expand Down Expand Up @@ -698,7 +697,6 @@ private KeyVaultKey getKeyVaultKey(String masterKeyPath) throws SQLServerExcepti
retrievedKey = keyClient.getKey(keyName);
}


if (null == retrievedKey) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_AKVKeyNotFound"));
Object[] msgArgs = {keyTokens[keyTokens.length - 1]};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
*/
package com.microsoft.sqlserver.jdbc.AlwaysEncrypted;

import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import com.microsoft.aad.msal4j.ClientCredentialFactory;
import com.microsoft.aad.msal4j.ClientCredentialParameters;
import com.microsoft.aad.msal4j.ConfidentialClientApplication;
import com.microsoft.aad.msal4j.IClientCredential;
import com.microsoft.aad.msal4j.PublicClientApplication;
import com.microsoft.sqlserver.jdbc.SQLServerKeyVaultAuthenticationCallback;
import java.math.BigDecimal;
import java.sql.Date;
Expand All @@ -28,8 +26,6 @@

import com.azure.core.credential.TokenCredential;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down

0 comments on commit 122e408

Please sign in to comment.