javasybasebouncycastlesap-aseanypoint-studio

Anypoint Studio how to configure BouncyCastle


Our goal is to connect to Sybase ASE DB from Anypoint Studio. This DB Server expects encrypted password. So we wrote the java code and able to make connection. In the java project added external BouncyCastle jar (bcprov-jdk15on-170.jar) and the jConnecter (jconn.jar) the JDBC Driver. And it works.

        Class.forName(DRIVER_CLASS); //DRIVER_CLASS = "com.sybase.jdbc4.jdbc.SybDriver";
    prop.put("ENCRYPT_PASSWORD", "true"); // by default this is false.
    prop.put("java.security.Provider", "org.bouncycastle.jce.BouncyCastleProvider");
    
    prop.put("user", UID);
    prop.put("password", PWD);
    
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); 
            
    System.out.println("Trying to connect");
    Connection con = DriverManager.getConnection(JDBC_URL, prop);
    System.out.println("Connection success!");

The next thing, same we want to achieve in Anypoint Studio 7.11. The Database Config I give below parameters:

Connection: Generic
JDBC Driver: jconn4
URL: jdbc:sybase:Tds:<host>:<port>/<DB>?ENCRYPT_PASSWORD=true&java.security.Provider=org.bouncycastle.jce.provider.BouncyCastleProvider
Driver Class: com.sybase.jdbc4.jdbc.SybDriver
Followed by User: and Password.

Then added the bcprov-jdk15on-170.jar as project/external jar in Referenced Libraries.

But when I do test connection it gives error:

org.mule.runtime.api.connection.ConnectionException: Could not obtain connection from data source
Caused by: org.mule.db.commons.shaded.api.exception.connection.ConnectionCreationException: Could not obtain connection from data source
Caused by: java.sql.SQLException: Cannot get connection for URL jdbc:sybase:Tds:<host>:<port>/<DB>?ENCRYPT_PASSWORD=true&java.security.Provider=org.bouncycastle.jce.provider.BouncyCastleProvider : JZ0LA: Failed to instantiate Cipher object. Transformation RSA/NONE/OAEPWithSHA1AndMGF1Padding is not implemented by any of the loaded JCE providers.

This error had happened while testing with Java project, but then I have solved by adding below line of code:

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

But in Anypoint Studio how to do it? Or how to solve it? The Anypoint Studio Database Config is not getting this class file. I checked internet it says to specify the provider in java.security file. the other post on SOF. I have done that also. Still it does not work from Anypoint Studio. If anyone of you have successfully done it in past kindly share idea.

[Update 1] I added Invoke-Static Moulde in Anypoint Studio flow, that is working. So next trying to give same setting in the Database Config (global element) but it is giving now new error on TestConnection. Provider I have changed and it works from Invoke-Static flow.

The Invoke-Static Java code which makes connection (and is okay):

 Security.addProvider(new org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider()); // new provider
//Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

Also in the jdk/conf/java.security which this Anypoint is using made the addition of BouncyCastle at top:

security.provider.1=org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider

But when I make corresponding settings in Database Config as below url:

url="jdbc:sybase:Tds:<host>:<port>/<DB>?ENCRYPT_PASSWORD=true&java.security.Provider=org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider"
user and password same.

it gives new error on clicking TestConnection from Database Config:

ToolingException{message='Got status code: 500 when trying to resolve a Mule Runtime operation. Reason: 'Server Error. {"errorType":null,"errorMessage":null,"errorDetail":null,"additionalProperties":{servlet=org.glassfish.jersey.servlet.ServletContainer-29fe8bdb, message=Request failed., url=/mule/tooling/applications/70c8b7ab-8bbc-4863-a0aa-718be6d803b9/components/Database_Sybase/connection, status=500}}''

Now investigating, why this error?

[Update 2] The above mentioned new error of Tooling exception is gone by appending the &RETRY_WITH_NO_ENCRYPTION=true in the URL, but the original error still coming. JZ0LA: Failed to instantiate Cipher object. Transformation RSA/NONE/OAEPWithSHA1AndMGF1Padding is not implemented


Solution

  • Finally got it to work! Since the flow was working in Anypoint Studio, so it means jars were correct, but Test Connection of Database Config was not getting in its classpath. May be some classloader issue. So, I searched on the internet about where to put this jar into a path so that the Database Config can load and use it. Found that in the file %MULE_HOME%/conf/wrapper.conf.template there are properties to set the classpath for jars. I put this BouncyCastle jar in the library path and then it worked. The librbary path in my case was at %MULE_HOME%/lib/boot, so I kept here also apart from keeping at %MULE_HOME%/lib/usr. Then it worked