Hobione's Weblog

Living & Breathing in Web 2.0 Era

RSA premaster secret error

I wrote how to use SSL connection string using JDBC driver in my previous blog. I deployed the code on the Unix server from Windows 7 pc and I got RSA premaster secret error.

Caused by: java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyGenerator not available

I figured it out after banging my head on the wall for couple of days. I had to explicitly use sunjce_provider.jar file name on the class path.

$JAVA_HOME/bin/java -Xms64m -Xmx256m -Djava.ext.dirs=.:$SURVEY_LIB -cp .:$JAVA_HOME/jre/lib/ext/sunjce_provider.jar:$CLASSPATH:$SURVEY_BIN/surveys.jar com.hobi.survey.SurveyMainClass getAllSurveys

August 29, 2014 Posted by | SSL | Leave a comment

SSL connection from Java to MSSQL Database Server using JDBC driver

First of all, need to get the self-signed certificate from database administrator and install/import to the following path.
C:\Program Files\Java\jdk1.7.0_17\jre\lib\security\cacerts

How to install ssl certificate?
Step 1: Get the certificate from certificate owner, it is usually .cer file (SQLcert.cer)
Step 2: Make a dir under c drive (c:\certificate)
Step 3: Copy the cacerts from C:\Program Files\Java\jdk1.7.0_17\jre\lib\security\cacerts to c:\certificate
Step4: Copy SQLcert.cer to c:\certificate
Step5: Open up a command prompt and change directory to c:\certificate
Step6: Execute this command
keytool -import -keystore cacerts -file SQLcert.cer

How to import SSL certificate

Step8: Copy cacerts file back to the original path –> *C:\Program Files\Java\jdk1.7.0_17\jre\lib\security

How to install jdbc4 driver to local maven repository?

Missing artifact com.microsoft.sqlserver:sqljdbc4:jar:4.0
To add the jar file in pom.xml since Microsoft don’t make this available via any maven repository.

Download the jar from the Microsoft website, and then manually install it into local maven repository using following command.
mvn install:install-file -Dfile=sqljdbc4.jar –DgroupId=com.microsoft.sqlserver –DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar

How to install jdbc4 driver to local maven repository


How to setup jdbc ssl connection string for MSSQL server 2012?

Pay attentions on slashes (forward slash vs backward slash: before server name, it has forward slash but after the server name there are two back slashes). I also had to use full server name instead of an ip address.

I was able to connect to the SQL server after few days of hard work.


How to list all certificates in cacerts file?
c:\Program Files\Java\jdk1.7.0_17\jre\lib\security>keytool -list -v -keystore cacerts

August 18, 2014 Posted by | SSL | , | Leave a comment