Open muskaan62 opened 1 month ago
hi @muskaan62
I don't see the code you used to connect but the url you included above doesn't look correct. Please see this doc for an example on how to connect using ActiveDirectoryServicePrincipalCertificate authentication mode.
hi @muskaan62
I don't see the code you used to connect but the url you included above doesn't look correct. Please see this doc for an example on how to connect using ActiveDirectoryServicePrincipalCertificate authentication mode.
@lilgreenbird The code
try (Connection connection = DriverManager.getConnection(jdbcUrl);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT* from TestTable")) {
if (rs.next()) {
System.out.println("Id: " + rs.getString(1));
System.out.println("Name: " + rs.getString(2));
}
}
can u please mention whats the wrong in the url if it is trustServerCertificate and encrypt one then keeping both true also give same error...also the attach doc is not showing anything its pointing to github repo only.I am kinda block on this.
@lilgreenbird I think the bug is in this method https://github.com/microsoft/mssql-jdbc/blob/main/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCertificateUtils.java#L397 which use to decrypt the encrypted private key . I clone the driver code and replace the above method with the below logic https://stackoverflow.com/questions/69027323/reading-pem-encoded-encrypted-private-key-from-file-in-java . its working as expected. can u please fix this issue ASAP. as it is blocking our enhancement feature.
I'm sorry it looks like there was a c&p issue the link in my prev post was wrong, I've now fixed it. The example uses SQLServerDataSource but it's the same idea in URL form, you can see in the sample what properties is needed for ActiveDirectoryServicePrincipalCertificate auth.
We also have junit test which tests ActiveDirectoryServicePrincipalCertificate fyi.
@lilgreenbird I am using the correct properties in URL form. And the test you provide is only for testing certificate auth without any password. let me tell you in details As per this doc https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentication?view=sql-server-ver16#connect-using-activedirectoryserviceprincipalcertificate-authentication-mode we can authenticate via ActiveDirectoryServicePrincipal certificate in this four ways.(jdbc url prop allowed https://learn.microsoft.com/en-us/sql/connect/jdbc/setting-the-connection-properties?view=sql-server-ver16 )
@lilgreenbird I try to raise the PR for this issue but looks like i dont have perms to create PR. though i have created a patch for the fix below.. I tried to upload patch file here for the fix somehow its not uploading so put that in the text file you rename it to .patch if you are considering the fix. fixissue2530.txt
hi @muskaan62
Thanks, what errors are you getting whehn you tried to create a PR? this is open source so anyone should be able to create a PR and we've had contributions from various users in the past. You should be able to create a PR here
@lilgreenbird facing this error
I try to fork the repo and raise PR https://github.com/microsoft/mssql-jdbc/pull/2532
Question
ActiveDirectoryServicePrincipalCertificate Authentication with client certifiicate private key and private key associated with password is not working.
I am trying to connect with azuresql db with the above url using (clientcert,private key,password) for authentication Note(clientcert with private key is working) client cert with password also working. only the above combination is giving the below error..I have verified the private key as well it contains valid header
-----BEGIN ENCRYPTED PRIVATE KEY-----
tested with latest driver also 12.8.0.jre11 Is it a bug in driver?
use below steps to create certificate with private key and privatekey password
Relevant Issues and Pull Requests