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 | client certificate authentication #1284

Merged
merged 61 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c97b863
Fix AEv2 tests exclude for reqExternalSetup and cleanup (#1247)
lilgreenbird Feb 5, 2020
54b5a19
Fix | Add null check for getObject() with LocalTime and LocalDate (#1…
peterbae Feb 8, 2020
672b7d6
added all AKV tests to use reqExternalSetup tag so they will be skipp…
lilgreenbird Feb 10, 2020
f006c4e
Added new Azure endpoints to the list of trusted endpoints (#1264)
ulvii Feb 24, 2020
5f33c57
Release | Changes for 8.2.1 HotFix release (#1260)
peterbae Feb 24, 2020
10f9737
Sync master with dev for 8.2.1 Release
ulvii Feb 27, 2020
77d25cb
Release | 8.3.0-SNAPSHOT
ulvii Feb 27, 2020
166add5
Sync dev with master for 8.2.1 Release
ulvii Feb 27, 2020
3346b3a
Release | Add snapshot to pom file
ulvii Feb 27, 2020
bef72c5
Release | Update version to 8.3.0-SNAPSHOT
ulvii Feb 28, 2020
560be4c
initial stuff
peterbae Mar 4, 2020
bcc4a03
Merge branch 'dev' of https://github.com/Microsoft/mssql-jdbc into cl…
peterbae Mar 9, 2020
2508f53
Add support for PKCS8 and PKCS1 private keys
rene-ye Mar 10, 2020
15293af
Remove imports
rene-ye Mar 10, 2020
e1e7c42
Remove imports from iobuffer
rene-ye Mar 10, 2020
9d20136
more import cleanup
rene-ye Mar 10, 2020
e2d5f88
Merge pull request #11 from rene-ye/clientcertauth
peterbae Mar 10, 2020
fa15950
change logic for decryptprovider
rene-ye Mar 10, 2020
45a7a25
Add PVK support
rene-ye Mar 10, 2020
b51d9b9
changes
peterbae Mar 10, 2020
a743065
Merge branch 'clientcertauth' of https://github.com/peterbae/mssql-jd…
rene-ye Mar 10, 2020
13db002
Merge pull request #12 from rene-ye/clientcertauth
peterbae Mar 10, 2020
fb19534
hw
rene-ye Mar 12, 2020
f94a3da
Merge pull request #13 from rene-ye/clientcertauth
peterbae Mar 12, 2020
3f5a958
initial changes
peterbae Mar 16, 2020
58fb495
update
peterbae Mar 16, 2020
e521b60
try
peterbae Mar 16, 2020
e36be2b
statically load BC
peterbae Mar 16, 2020
32ed914
update test
peterbae Mar 16, 2020
fd35331
format
peterbae Mar 16, 2020
ceca02b
update test
peterbae Mar 17, 2020
e4621c8
add null check
peterbae Mar 18, 2020
565c16d
logic change
peterbae Mar 18, 2020
db3d040
test change
peterbae Mar 18, 2020
e802213
test update
peterbae Mar 20, 2020
bae1e04
Fix some issues
rene-ye Mar 20, 2020
bee991c
Add resources
rene-ye Mar 20, 2020
a791523
Merge branch 'clientcertauth' of https://github.com/peterbae/mssql-jd…
rene-ye Mar 20, 2020
887fbdf
Merge branch 'dev' of https://github.com/Microsoft/mssql-jdbc into cl…
peterbae Mar 20, 2020
f64828f
Merge pull request #14 from rene-ye/clientcertauth
peterbae Mar 25, 2020
a426136
test update
peterbae Mar 25, 2020
6b42090
disable clientcertauth on CI
peterbae Mar 25, 2020
de3f175
make it optional
peterbae Mar 25, 2020
c03a69f
add null check
peterbae Mar 26, 2020
898feca
Fix pkcs8 and add tests
rene-ye Mar 26, 2020
85a8ad8
Remove uneeded import
rene-ye Mar 26, 2020
ee8f08b
Merge pull request #15 from rene-ye/clientcertauth
peterbae Mar 26, 2020
7482c8e
changes
peterbae Mar 26, 2020
198b97d
Make some changes
rene-ye Mar 26, 2020
13b27a4
Merge branch 'clientcertauth' of https://github.com/peterbae/mssql-jd…
rene-ye Mar 26, 2020
b7a6f9b
Add file not found catching
rene-ye Mar 26, 2020
15ada35
Merge pull request #16 from rene-ye/clientcertauth
peterbae Mar 26, 2020
a4868fe
test changes
peterbae Mar 26, 2020
30b989d
revert
peterbae Mar 26, 2020
6a2978f
handle exception
peterbae Mar 27, 2020
b6d6b19
comments
peterbae Mar 27, 2020
5159647
comments
peterbae Mar 27, 2020
5d223e0
dont need statements
peterbae Mar 27, 2020
49ed487
use datasoure api
peterbae Mar 27, 2020
0533b48
String match provider name
rene-ye Mar 27, 2020
c347a29
Merge pull request #17 from rene-ye/clientcertauth
peterbae Mar 27, 2020
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
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
matrix:
SQL-2019:
Target_SQL: 'HGS-2k19-01'
Ex_Groups: 'xSQLv15'
Ex_Groups: 'xSQLv15, clientCertAuth'
SQL-2012:
Target_SQL: 'SQL-2K12-SP3-1'
Ex_Groups: 'xSQLv12'
Expand Down
15 changes: 13 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
xAzureSQLMI - - - - For tests not compatible with Azure SQL Managed Instance
NTLM - - - - - - - For tests using NTLM Authentication mode (excluded by default)
reqExternalSetup - For tests requiring external setup (excluded by default)
clientCertAuth - - For tests requiring client certificate authentication setup (excluded by default)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Default testing enabled with SQL Server 2019 (SQLv15) -->
<excludedGroups>xSQLv15, NTLM, reqExternalSetup</excludedGroups>
<excludedGroups>xSQLv15, NTLM, reqExternalSetup, clientCertAuth</excludedGroups>

<!-- Use -preview for preview release, leave empty for official release.-->
<releaseExt></releaseExt>
Expand All @@ -66,6 +67,8 @@
<osgi.comp.version>5.0.0</osgi.comp.version>
<antlr.runtime.version>4.7.2</antlr.runtime.version>
<google.gson.version>2.8.6</google.gson.version>
<bouncycastle.bcprov.version>1.64</bouncycastle.bcprov.version>
<bouncycastle.bcpkix.version>1.64</bouncycastle.bcpkix.version>

<!-- JUnit Test Dependencies -->
<junit.platform.version>[1.3.2, 1.5.2]</junit.platform.version>
Expand Down Expand Up @@ -119,7 +122,15 @@
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.64</version>
<version>${bouncycastle.bcprov.version}</version>
<optional>true</optional>
</dependency>

<!-- dependencies for Client Certificate Authentication -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>${bouncycastle.bcpkix.version}</version>
<optional>true</optional>
</dependency>

Expand Down
19 changes: 16 additions & 3 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.TrustManager;
Expand Down Expand Up @@ -364,6 +365,7 @@ static final String getTokenName(int tdsTokenType) {
static final byte ENCRYPT_ON = 0x01;
static final byte ENCRYPT_NOT_SUP = 0x02;
static final byte ENCRYPT_REQ = 0x03;
static final byte ENCRYPT_CLIENT_CERT = (byte) 0x80;
static final byte ENCRYPT_INVALID = (byte) 0xFF;

static final String getEncryptionLevel(int level) {
Expand Down Expand Up @@ -1597,9 +1599,16 @@ enum SSLHandhsakeState {
* Server Host Name for SSL Handshake
* @param port
* Server Port for SSL Handshake
* @param clientCertificate
* Client certificate path
* @param clientKey
* Private key file path
* @param clientKeyPassword
* Private key file's password
* @throws SQLServerException
*/
void enableSSL(String host, int port) throws SQLServerException {
void enableSSL(String host, int port, String clientCertificate, String clientKey,
String clientKeyPassword) throws SQLServerException {
// If enabling SSL fails, which it can for a number of reasons, the following items
// are used in logging information to the TDS channel logger to help diagnose the problem.
Provider tmfProvider = null; // TrustManagerFactory provider
Expand Down Expand Up @@ -1774,13 +1783,16 @@ else if (con.getTrustManagerClass() != null) {
if (logger.isLoggable(Level.FINEST))
logger.finest(toString() + " Getting TLS or better SSL context");

KeyManager[] km = (null != clientCertificate && clientCertificate.length() > 0) ? SQLServerCertificateUtils
.getKeyManagerFromFile(clientCertificate, clientKey, clientKeyPassword) : null;

sslContext = SSLContext.getInstance(sslProtocol);
sslContextProvider = sslContext.getProvider();

if (logger.isLoggable(Level.FINEST))
logger.finest(toString() + " Initializing SSL context");

sslContext.init(null, tm, null);
sslContext.init(km, tm, null);

// Got the SSL context. Now create an SSL socket over our own proxy socket
// which we can toggle between TDS-encapsulated and raw communications.
Expand Down Expand Up @@ -6202,7 +6214,8 @@ void writeRPCReaderUnicode(String sName, Reader re, long reLength, boolean bOut,

void sendEnclavePackage(String sql, ArrayList<byte[]> enclaveCEKs) throws SQLServerException {
if (null != con && con.isAEv2()) {
if (null != sql && !sql.isEmpty() && null != enclaveCEKs && 0 < enclaveCEKs.size() && con.enclaveEstablished()) {
if (null != sql && !sql.isEmpty() && null != enclaveCEKs && 0 < enclaveCEKs.size()
&& con.enclaveEstablished()) {
byte[] b = con.generateEnclavePackage(sql, enclaveCEKs);
if (null != b && 0 != b.length) {
this.writeShort((short) b.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -903,5 +903,43 @@ public interface ISQLServerDataSource extends javax.sql.CommonDataSource {
* Enclave attestation protocol.
*/
void setEnclaveAttestationProtocol(String protocol);

/**
* Returns client certificate path for client certificate authentication.
*
* @return Client certificate path.
*/
String getClientCertificate();

/**
* Sets client certificate path for client certificate authentication.
*
* @param certPath
* Client certificate path.
*/
void setClientCertificate(String certPath);

/**
* Returns Private key file path for client certificate authentication.
*
* @return Private key file path.
*/
String getClientKey();

/**
* Sets Private key file path for client certificate authentication.
*
* @param keyPath
* Private key file path.
*/
void setClientKey(String keyPath);

/**
* Sets the password to be used for Private key provided by the user for client certificate authentication.
*
* @param password
* Private key password.
*/
void setClientKeyPassword(String password);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/*
* Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
* available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/

package com.microsoft.sqlserver.jdbc;

import java.security.Security;

/*
* Class that is meant to statically load the BouncyCastle Provider for JDK 8. Hides the call so JDK 11/13 don't have to include the dependency.
* Also loads BouncyCastle provider for PKCS1 private key parsing.
*/
class SQLServerBouncyCastleLoader {
static void loadBouncyCastle() {
Expand Down
Loading