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

Feature | Introduce NTLM authentication mode #998

Merged
merged 118 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from 113 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
ede9d96
added domain connection property
lilgreenbird Dec 11, 2018
9d2576f
Merge remote-tracking branch 'upstream/dev' into ntlm2
lilgreenbird Dec 25, 2018
c15a114
save work
lilgreenbird Dec 28, 2018
df3ff26
Merge remote-tracking branch 'upstream/dev' into ntlm2
lilgreenbird Feb 2, 2019
1f45f4c
added missed files
lilgreenbird Feb 2, 2019
9d5a814
Merge remote-tracking branch 'upstream/dev' into ntlm2
lilgreenbird Feb 21, 2019
b0e6c53
updated negotiate flags names to match spec
lilgreenbird Feb 21, 2019
35efcbf
initial implementation of NTLM auth
lilgreenbird Mar 6, 2019
19ecf42
cleanup
lilgreenbird Mar 6, 2019
cb90257
connection property changes
lilgreenbird Mar 6, 2019
2eeb79b
added workstation field
lilgreenbird Mar 7, 2019
5b934b4
add ntlm context
lilgreenbird Mar 7, 2019
2b25cd4
review updates
lilgreenbird Mar 7, 2019
c891cec
fixed review changes
lilgreenbird Mar 8, 2019
85eb03e
Add | Adding NTLM JUnit tests
ulvii Mar 8, 2019
b6b9257
Merge remote-tracking branch 'upstream/dev' into ntlmv2
ulvii Mar 8, 2019
081793c
Merge remote-tracking branch 'lilgreenbird/newntlm' into ntlmv2
ulvii Mar 8, 2019
9441813
Fix | Add new line
ulvii Mar 8, 2019
e46e1a3
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Mar 11, 2019
53d05fe
added some validation
lilgreenbird Mar 12, 2019
2c59755
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Mar 12, 2019
5932c25
Merge remote-tracking branch 'upstream/dev' into ntlm
lilgreenbird Mar 12, 2019
2e4ecbc
Merge branch 'ntlm' into newntlm
lilgreenbird Mar 12, 2019
3284cce
Fix | Merge conflict
ulvii Mar 13, 2019
819fe74
connection property changes and md4 package name
lilgreenbird Mar 13, 2019
3808036
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Mar 13, 2019
dbae1fa
Merge remote-tracking branch 'lilgreenbird/newntlm' into ntlmv2
ulvii Mar 13, 2019
4569f7e
Fix | Update tests to use the new connection properties
ulvii Mar 13, 2019
fd57e65
Merge pull request #3 from ulvii/ntlmv2
lilgreenbird Mar 13, 2019
b0999d9
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Mar 15, 2019
bf9a6da
fixed merge issues
lilgreenbird Mar 18, 2019
d0c9869
merged
lilgreenbird Mar 18, 2019
23719d0
added MIC
lilgreenbird Mar 18, 2019
3b1e71f
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Mar 18, 2019
ce1f600
Update changes from dev (#992)
lilgreenbird Mar 18, 2019
1f82528
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Mar 18, 2019
4213849
Merge branch 'newntlm' of https://github.com/lilgreenbird/mssql-jdbc …
lilgreenbird Mar 19, 2019
9bb9804
initial implementation
lilgreenbird Mar 19, 2019
002b083
current timestamp to windows epoch in client challenge
lilgreenbird Mar 20, 2019
d739c3e
review updates and removed LmChallengeResponse code
lilgreenbird Mar 20, 2019
c74b98c
added reference to spec in comments and use MAC api to calculate hash
lilgreenbird Mar 21, 2019
3bf1788
updates
lilgreenbird Mar 22, 2019
8197a11
fixes from unit testing
lilgreenbird Mar 26, 2019
acc687c
add unit tests
lilgreenbird Mar 26, 2019
b118bb8
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Mar 28, 2019
5c4de43
fixed MIC and cleanup
lilgreenbird Mar 28, 2019
fe19dd2
updates ntlm test
lilgreenbird Mar 29, 2019
dd5ccfc
add NTLM connetion property vars to azure pipeline
lilgreenbird Mar 29, 2019
868dd1e
added more info to NTLM error msgs
lilgreenbird Mar 30, 2019
6087ccf
added more info to NTLM error msgs
lilgreenbird Mar 30, 2019
b3bdf67
added ntlm domain var to azure pipeline
lilgreenbird Mar 30, 2019
5593394
get fqdn for servername
lilgreenbird Apr 2, 2019
8d71095
separate challenge message tests
lilgreenbird Apr 2, 2019
89523b9
added check for NTLM properties
lilgreenbird Apr 3, 2019
3ff75b3
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Apr 3, 2019
9a3378c
added logging and check for timestamp before sending MIC
lilgreenbird Apr 3, 2019
8748a62
updated to use java.util.Random instead of SecureRandom as it could h…
lilgreenbird Apr 3, 2019
fe9fec0
remove debug printfs
lilgreenbird Apr 3, 2019
b5c401d
do not fail on domain/computer namev verification and added more tests
lilgreenbird Apr 4, 2019
8e17178
removed localhost test as it can't be run in test lab
lilgreenbird Apr 4, 2019
4835d46
updates test to check for warning log
lilgreenbird Apr 5, 2019
b4082c8
code coverage, cleanup, and javadocs
lilgreenbird Apr 5, 2019
023a4e8
minor changes from checkstyle on CI build
lilgreenbird Apr 5, 2019
dff1160
merged with dev
lilgreenbird Apr 9, 2019
1d05fee
review updates
lilgreenbird Apr 9, 2019
36027eb
add @tags
Apr 10, 2019
257f84d
add import tags
lilgreenbird Apr 10, 2019
81d7ad1
more review updates
lilgreenbird Apr 10, 2019
428dde3
more review updates
lilgreenbird Apr 11, 2019
0127466
more review updates
lilgreenbird Apr 11, 2019
3956d9c
typo
lilgreenbird Apr 11, 2019
2cf07a3
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Apr 11, 2019
5dc31e7
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Apr 12, 2019
3a253ef
more review updates
lilgreenbird Apr 13, 2019
1052ffb
merged with dev
lilgreenbird Apr 16, 2019
e1af8a2
udpated to use master db for grant permission
lilgreenbird Apr 17, 2019
15dded1
fixed stupid typo
lilgreenbird Apr 17, 2019
1c9bddc
added NTLM to excludedgroups
lilgreenbird Apr 17, 2019
a2078dd
Update NTLMConnectionTest.java
lilgreenbird Apr 17, 2019
5b348ec
exclude NTLM from Travis
lilgreenbird Apr 17, 2019
8824b0b
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Apr 17, 2019
f931a80
merged with dev
lilgreenbird Apr 17, 2019
b65a59a
fixed excludeGroups
lilgreenbird Apr 17, 2019
646d990
review updates
lilgreenbird Apr 18, 2019
3d9aa2d
merged with dev
lilgreenbird Apr 24, 2019
d6b3f96
updated to add spn and channel binding
lilgreenbird May 1, 2019
766d447
fixed workstation
lilgreenbird May 1, 2019
92a560c
updated kerb to use Util spn code
lilgreenbird May 1, 2019
19d1a4a
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird May 8, 2019
d4901e3
service binding
lilgreenbird May 8, 2019
6b8c8ad
fixed build failure
lilgreenbird May 8, 2019
41c3b7b
resolved conflicts and moved spn code to sspi
lilgreenbird May 9, 2019
fc3c96a
more updates
lilgreenbird May 9, 2019
721551d
fixed jre8 build
lilgreenbird May 9, 2019
cf66114
static analysis updates
lilgreenbird May 9, 2019
6eab595
trigger build
lilgreenbird May 9, 2019
7b064b8
Downgrade surefire plugin to be able to run a single test
ulvii May 10, 2019
44450bc
Downgrade surefire plugin
ulvii May 10, 2019
2832b12
updated test to fix grant permission issue
lilgreenbird May 10, 2019
ddeda42
Merge branch 'newntlm' of https://github.com/lilgreenbird/mssql-jdbc …
lilgreenbird May 10, 2019
01cf51a
updated test to fix grant permission issue
lilgreenbird May 10, 2019
ad66e38
Update testNTLMNonDefaultDatabase to use tempdb
ulvii May 10, 2019
07161df
Update surefire version
ulvii May 11, 2019
b8ae487
Update AbstractTest.java
ulvii May 14, 2019
d35d445
Merge branch 'dev' into newntlm
cheenamalhotra May 19, 2019
8d7519c
Merge Conflict resolved
cheenamalhotra May 19, 2019
327745c
Update property name to domainNTLM
cheenamalhotra May 22, 2019
3f4be4a
Update SQL Server being tested with
cheenamalhotra May 22, 2019
aa6cd1b
Minor update
cheenamalhotra May 22, 2019
4279afa
Merge branch 'ms-dev' into newntlm
cheenamalhotra May 23, 2019
e163a84
Exclude NTLM Tag in Gradle Script
cheenamalhotra May 23, 2019
ba6297d
Static Code changes
cheenamalhotra May 24, 2019
912e7e8
Update SQL 2019
cheenamalhotra May 24, 2019
5d4eeab
Review and apply review comments.
cheenamalhotra May 30, 2019
f3ee2c7
Merge branch 'ms-dev' into newntlm
cheenamalhotra May 30, 2019
5423d9e
Apply review comments
cheenamalhotra May 30, 2019
cc44603
Merge remote-tracking branch 'upstream/dev' into newntlm
lilgreenbird Jun 3, 2019
1fa9143
removed unused code
lilgreenbird Jun 10, 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
14 changes: 7 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Microsoft JDBC Driver for SQL Server CI Build triggers tests against below SQL Servers:
# - SQL Server 2017
# - SQL Server 2019
# - SQL Server 2008 R2
jobs:
- job: "CI_Build"
Expand All @@ -8,9 +8,9 @@ jobs:
demands: maven
strategy:
matrix:
SQL-2017:
Target_SQL: 'SQL-2k17-03'
Ex_Groups: 'xSQLv14'
SQL-2019:
Target_SQL: 'SQL-2k19-01'
Ex_Groups: 'xSQLv15'
SQL-2008R2:
Target_SQL: 'SQL-2k8R2-SP3-1'
Ex_Groups: 'xSQLv12'
Expand All @@ -33,7 +33,7 @@ jobs:
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 -Pjre12 -DexcludedGroups=$(Ex_Groups)'
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 jre12'
javaHomeOption: Path
Expand All @@ -42,7 +42,7 @@ jobs:
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 -DexcludedGroups=$(Ex_Groups)'
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
Expand All @@ -51,7 +51,7 @@ jobs:
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 -DexcludedGroups=$(Ex_Groups)'
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
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ allprojects {

test {
useJUnitPlatform {
excludeTags (hasProperty('excludedGroups') ? excludedGroups : 'xSQLv15','xGradle')
excludeTags (hasProperty('excludedGroups') ? excludedGroups : 'xSQLv15','xGradle','NTLM')
}
}

Expand Down Expand Up @@ -70,7 +70,7 @@ if(hasProperty('buildProfile') && buildProfile == "jre8") {
targetCompatibility = 1.8
test {
useJUnitPlatform {
excludeTags (hasProperty('excludedGroups') ? excludedGroups : 'xSQLv15','xGradle','xJDBC42')
excludeTags (hasProperty('excludedGroups') ? excludedGroups : 'xSQLv15','xGradle','NTLM','xJDBC42')
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +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)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Default testing enabled with SQL Server 2019 (SQLv14) -->
<excludedGroups>xSQLv15</excludedGroups>
<excludedGroups>xSQLv15, NTLM</excludedGroups>

<!-- Driver Dependencies -->
<azure.keyvault.version>1.2.1</azure.keyvault.version>
Expand Down Expand Up @@ -414,7 +415,7 @@
<version>3.0.0</version>
<configuration>
<failOnError>true</failOnError>
<excludePackageNames>mssql.googlecode.*</excludePackageNames>
<excludePackageNames>mssql.googlecode.*:mssql.security.provider.MD4</excludePackageNames>
</configuration>
<executions>
<execution>
Expand Down
59 changes: 30 additions & 29 deletions src/main/java/com/microsoft/sqlserver/jdbc/AuthenticationJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ class FedAuthDllInfo {
* Encapsulation of the JNI native calls for trusted authentication.
*/
final class AuthenticationJNI extends SSPIAuthentication {
private final static int maximumpointersize = 128; // we keep the SNI_Sec pointer
private static final int maximumpointersize = 128; // we keep the SNI_Sec pointer
private static boolean enabled = false;
private static java.util.logging.Logger authLogger = java.util.logging.Logger
.getLogger("com.microsoft.sqlserver.jdbc.internals.AuthenticationJNI");
private static int sspiBlobMaxlen = 0;
private byte[] sniSec = new byte[maximumpointersize];
private int sniSecLen[] = {0};
private final String DNSName;
private int[] sniSecLen = {0};
private final String dnsName;
private final int port;
private SQLServerConnection con;

private static final UnsatisfiedLinkError linkError;

static int GetMaxSSPIBlobSize() {
static int getMaxSSPIBlobSize() {
return sspiBlobMaxlen;
}

Expand All @@ -54,8 +54,9 @@ static boolean isDllLoaded() {
pkg[0] = 0;
if (0 == SNISecInitPackage(pkg, authLogger)) {
sspiBlobMaxlen = pkg[0];
} else
} else {
throw new UnsatisfiedLinkError();
}
enabled = true;
} catch (UnsatisfiedLinkError e) {
temp = e;
Expand All @@ -68,12 +69,13 @@ static boolean isDllLoaded() {
}

AuthenticationJNI(SQLServerConnection con, String address, int serverport) throws SQLServerException {
if (!enabled)
if (!enabled) {
con.terminate(SQLServerException.DRIVER_ERROR_NONE,
SQLServerException.getErrString("R_notConfiguredForIntegrated"), linkError);
}

this.con = con;
DNSName = GetDNSName(address);
dnsName = getDNSName(address);
port = serverport;
}

Expand All @@ -85,17 +87,17 @@ static FedAuthDllInfo getAccessTokenForWindowsIntegrated(String stsURL, String s
}

// InitDNSName should be called to initialize the DNSName before calling this function
byte[] GenerateClientContext(byte[] pin, boolean[] done) throws SQLServerException {
byte[] generateClientContext(byte[] pin, boolean[] done) throws SQLServerException {
byte[] pOut;
int[] outsize; // This is where the size of the filled data returned
outsize = new int[1];
outsize[0] = GetMaxSSPIBlobSize();
outsize[0] = getMaxSSPIBlobSize();
pOut = new byte[outsize[0]];

// assert DNSName cant be null
assert DNSName != null;
assert dnsName != null;

int failure = SNISecGenClientContext(sniSec, sniSecLen, pin, pin.length, pOut, outsize, done, DNSName, port,
int failure = SNISecGenClientContext(sniSec, sniSecLen, pin, pin.length, pOut, outsize, done, dnsName, port,
null, null, authLogger);

if (failure != 0) {
Expand All @@ -106,12 +108,12 @@ byte[] GenerateClientContext(byte[] pin, boolean[] done) throws SQLServerExcepti
SQLServerException.getErrString("R_integratedAuthenticationFailed"), linkError);
}
// allocate space based on the size returned
byte output[] = new byte[outsize[0]];
byte[] output = new byte[outsize[0]];
System.arraycopy(pOut, 0, output, 0, outsize[0]);
return output;
}

/* L0 */ int ReleaseClientContext() {
int releaseClientContext() {
int success = 0;
if (sniSecLen[0] > 0) {
success = SNISecReleaseClientContext(sniSec, sniSecLen[0], authLogger);
Expand All @@ -122,39 +124,38 @@ byte[] GenerateClientContext(byte[] pin, boolean[] done) throws SQLServerExcepti

// note we handle the failures of the GetDNSName in this function, this function will return an empty string if the
// underlying call fails.
private static String GetDNSName(String address) {
String DNS[] = new String[1];
if (GetDNSName(address, DNS, authLogger) != 0) {
private static String getDNSName(String address) {
String[] dns = new String[1];
if (GetDNSName(address, dns, authLogger) != 0) {
// Simply initialize the DNS to address
DNS[0] = address;
dns[0] = address;
}
return DNS[0];
return dns[0];
}

// we use arrays of size one in many places to retrieve output values
// Java Integer objects are immutable so we cant use them to get the output sizes.
// Same for String
/* L0 */private native static int SNISecGenClientContext(byte[] psec, int[] secptrsize, byte[] pin, int insize,
byte[] pOut, int[] outsize, boolean[] done, String servername, int port, String username, String password,
private static native int SNISecGenClientContext(byte[] psec, int[] secptrsize, byte[] pin, int insize, byte[] pOut,
int[] outsize, boolean[] done, String servername, int port, String username, String password,
java.util.logging.Logger log);

/* L0 */ private native static int SNISecReleaseClientContext(byte[] psec, int secptrsize,
java.util.logging.Logger log);
private static native int SNISecReleaseClientContext(byte[] psec, int secptrsize, java.util.logging.Logger log);

private native static int SNISecInitPackage(int[] pcbMaxToken, java.util.logging.Logger log);
private static native int SNISecInitPackage(int[] pcbMaxToken, java.util.logging.Logger log);

private native static int SNISecTerminatePackage(java.util.logging.Logger log);
private static native int SNISecTerminatePackage(java.util.logging.Logger log);

private native static int SNIGetSID(byte[] SID, java.util.logging.Logger log);
private static native int SNIGetSID(byte[] SID, java.util.logging.Logger log);

private native static boolean SNIIsEqualToCurrentSID(byte[] SID, java.util.logging.Logger log);
private static native boolean SNIIsEqualToCurrentSID(byte[] SID, java.util.logging.Logger log);

private native static int GetDNSName(String address, String[] DNSName, java.util.logging.Logger log);
private static native int GetDNSName(String address, String[] DNSName, java.util.logging.Logger log);

private native static FedAuthDllInfo ADALGetAccessTokenForWindowsIntegrated(String stsURL,
private static native FedAuthDllInfo ADALGetAccessTokenForWindowsIntegrated(String stsURL,
String servicePrincipalName, String clientConnectionId, String clientId, long expirationFileTime,
java.util.logging.Logger log);

native static byte[] DecryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
static native byte[] DecryptColumnEncryptionKey(String masterKeyPath, String encryptionAlgorithm,
byte[] encryptedColumnEncryptionKey) throws DLLException;
}
Loading