web stats
Mirth Appliance accessing MSSQL with Windows authentication - Page 2 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #11  
Old 04-28-2014, 12:59 PM
caarnold caarnold is offline
OBX.1 Kenobi
 
Join Date: Apr 2014
Posts: 33
caarnold is on a distinguished road
Default

I do not have it quite right


function getEncryptedDBProperties(fname) {

var sFilename = globalMap.get('globalPath') + "/conf/db/" + fname + ".properties";

// Get LastADTCheck date/time
var properties = new Packages.java.util.Properties();
try {
var encryptor = Donkey.getInstance().getEncryptor();
properties.raw_data = encryptor.decrypt(properties.raw_data.load(new Packages.java.io.FileInputStream(new Packages.java.io.File(sFilename))));
globalMap.put(fname +'.driver', properties.getProperty('driver'));
globalMap.put(fname +'.db', properties.getProperty('db'));
globalMap.put(fname +'.user', properties.getProperty('user'));
globalMap.put(fname +'.pswd', properties.getProperty('pswd'));
} catch (err) {
logger.error('ERROR getEncryptedDBProperties: ' + sFilename + ' not found.' + err.message);
}

}
Reply With Quote
  #12  
Old 04-29-2014, 07:19 AM
caarnold caarnold is offline
OBX.1 Kenobi
 
Join Date: Apr 2014
Posts: 33
caarnold is on a distinguished road
Default

What is the full path of Donkey.getInstance().getEncryptor() ?
Reply With Quote
  #13  
Old 04-29-2014, 08:20 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

Quote:
Originally Posted by caarnold View Post
What is the full path of Donkey.getInstance().getEncryptor() ?
You can view the source here: http://www.mirthcorp.com/community/f...ey.java?r=6901
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #14  
Old 04-29-2014, 09:10 AM
caarnold caarnold is offline
OBX.1 Kenobi
 
Join Date: Apr 2014
Posts: 33
caarnold is on a distinguished road
Default

I tried this:
var encryptor = com.mirth.connect.donkey.server.getInstance().getE ncryptor();

I keep getting this error:
Cannot find function getEncryptor in object {}.

Full code:

function getEncryptedDBProperties(fname) {

var sFilename = globalMap.get('globalPath') + "/conf/db/" + fname + ".properties";
// Get LastADTCheck date/time
var encryptor = com.mirth.connect.donkey.server.getInstance().getE ncryptor();

var properties = new Packages.java.util.Properties();
try {
globalMap.put(fname +'.driver', properties.getProperty('driver'));
globalMap.put(fname +'.db', properties.getProperty('db'));
globalMap.put(fname +'.user', properties.getProperty('user'));
globalMap.put(fname +'.pswd', encryptor.decrypt(properties.getProperty('pswd'))) ;

} catch (err) {
logger.error('ERROR getEncryptedDBProperties: ' + sFilename + ' not found.' + err.message);
}

}
Reply With Quote
  #15  
Old 04-29-2014, 09:14 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

Looks like you forgot to include the class name in there ("Donkey")
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #16  
Old 04-29-2014, 12:57 PM
caarnold caarnold is offline
OBX.1 Kenobi
 
Join Date: Apr 2014
Posts: 33
caarnold is on a distinguished road
Default

I think I am ready to use .Net lol.

function getEncryptedDBProperties(fname) {
var Donkey = new Packages.com.mirth.connect.donkey.server.Donkey.ge tInstance();
var sFilename = globalMap.get('globalPath') + "/conf/db/" + fname + ".properties";
// Get LastADTCheck date/time
var encryptor = Donkey.getEncryptor();
var properties = new Packages.java.util.Properties();

try {
globalMap.put(fname +'.driver', properties.getProperty('driver'));
globalMap.put(fname +'.db', properties.getProperty('db'));
globalMap.put(fname +'.user', properties.getProperty('user'));
globalMap.put(fname +'.pswd', encryptor.decrypt(properties.getProperty('pswd'))) ;

} catch (err) {
logger.error('ERROR getEncryptedDBProperties: ' + sFilename + ' not found.' + err.message);
}

}
Reply With Quote
  #17  
Old 05-01-2014, 05:48 AM
caarnold caarnold is offline
OBX.1 Kenobi
 
Join Date: Apr 2014
Posts: 33
caarnold is on a distinguished road
Default

Naruply can you look at that code and possibly correct it?
Reply With Quote
  #18  
Old 05-01-2014, 06:37 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,123
narupley is on a distinguished road
Default

First, create a config file with your plaintext password. For example:

Code:
driver = org.postgresql.Driver
db = postgres
user = postgres
pswd = postgres
Then you need to encrypt it. This can be a one-off deploy script:

Code:
var props = org.apache.commons.configuration.PropertiesConfiguration(new java.io.File('appdata/dbconfig.properties'));
var encryptor = com.mirth.connect.donkey.server.Donkey.getInstance().getEncryptor();
props.setProperty('pswd', encryptor.encrypt(props.getProperty('pswd')));
props.save();
Now the file looks like:

Code:
driver = org.postgresql.Driver
db = postgres
user = postgres
pswd = a24m7kKlLI3/4nWRSVnepA==\r\n
At this point you can get rid of the deploy script and/or channel, since you only needed it to encrypt that password. Now you can load the properties into the global map in the global deploy script:

Code:
var props = org.apache.commons.configuration.PropertiesConfiguration(new java.io.File('appdata/dbconfig.properties'));
var encryptor = com.mirth.connect.donkey.server.Donkey.getInstance().getEncryptor();

for (var it = props.getKeys(); it.hasNext();) {
	var key = it.next();
	var value = props.getProperty(key);

	if (key == 'pswd') {
		value = encryptor.decrypt(value);
	}

	$g(key, value);
}
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #19  
Old 05-01-2014, 09:57 AM
caarnold caarnold is offline
OBX.1 Kenobi
 
Join Date: Apr 2014
Posts: 33
caarnold is on a distinguished road
Default

Works great!! you are the man. Thank you.
Reply With Quote
  #20  
Old 07-31-2014, 07:59 AM
caarnold caarnold is offline
OBX.1 Kenobi
 
Join Date: Apr 2014
Posts: 33
caarnold is on a distinguished road
Default com.mirth.commons.encryption.EncryptionException: javax.crypto.BadPaddingException: p

I am getting these errors now. What can cause this using that same code?

com.mirth.commons.encryption.EncryptionException: javax.crypto.BadPaddingException: pad block corrupted
Reply With Quote
Reply

Tags
mirth appliance, mssql, windows authentication

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 12:43 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation