Is there support for password files in the Plain Java Client API?
Hi,
We are running automated builds (Maven) through the Jazz Build Engine, which uses a password file, which is fine for CLI and Ant scripts, however there does not seem to be OOTB support for password files through the RTC Plain Java Client API (4.0.3). Am I stuck having to write a custom LoginHandler that decrypts the password? Or is there an easier way around this?
Thanks
Accepted answer
There is an ObfuscationHelper class in the Plain Java api. A couple of lines is all you'd need
e.g.
import com.ibm.team.repository.common.ObfuscationHelper;
props = this.getProperties(path);
String pw=props.getProperty("password");
String ctpw=new String(ObfuscationHelper.decrypt(pw.getBytes()));
teamRepository = login(repositoryID, props.getProperty("userID"),ctpw );
And you'd need some way to do the encrypt ( ObfuscationHelper.encrypt or ObfuscationHelper.encryptString )
Or as the SCM and build tool kits likely use, you can just use the hashed password from one of those and decrypt it as I've shown.
e.g.
import com.ibm.team.repository.common.ObfuscationHelper;
props = this.getProperties(path);
String pw=props.getProperty("password");
String ctpw=new String(ObfuscationHelper.decrypt(pw.getBytes()));
teamRepository = login(repositoryID, props.getProperty("userID"),ctpw );
And you'd need some way to do the encrypt ( ObfuscationHelper.encrypt or ObfuscationHelper.encryptString )
Or as the SCM and build tool kits likely use, you can just use the hashed password from one of those and decrypt it as I've shown.
2 other answers
see above,
here is a sample pgm to encryt and decrypt the string..
package com.sd.tools;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import com.ibm.team.repository.common.util.ObfuscationHelper;
public class EncodePassword
{
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
if(args.length==1)
{
String enpw = ObfuscationHelper.encryptString(args[0]);
// you would use this output in any password file
System.out.println(enpw);
// here is how you would decrypt it for use in your application.
// you could get this string from the commandline, or a file,
// or a properties file (pw= string)
String userpw=enpw; (the encrypted or plain text password)
try
{
// try to decrypt
userpw=ObfuscationHelper.decryptString(userpw);
}
catch(Exception ex)
{
// nothing to do, target variable not overwritten on error
}
System.out.println("pw="+userpw);
}
}
else
System.out.println("need password string");
}
}
here is a sample pgm to encryt and decrypt the string..
package com.sd.tools;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import com.ibm.team.repository.common.util.ObfuscationHelper;
public class EncodePassword
{
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
if(args.length==1)
{
String enpw = ObfuscationHelper.encryptString(args[0]);
// you would use this output in any password file
System.out.println(enpw);
// here is how you would decrypt it for use in your application.
// you could get this string from the commandline, or a file,
// or a properties file (pw= string)
String userpw=enpw; (the encrypted or plain text password)
try
{
// try to decrypt
userpw=ObfuscationHelper.decryptString(userpw);
}
catch(Exception ex)
{
// nothing to do, target variable not overwritten on error
}
System.out.println("pw="+userpw);
}
}
else
System.out.println("need password string");
}
}
An implementation of a decryption of a password file inside an ANT task extending the AbstractTeamBuildTask from RTC would look like:
if (getPasswordFile() != null) { logger.info("Detected password file. Decrypting password"); logger.info(String.format("password file is [%s]", getPasswordFile().toString())); final Properties properties = new Properties(); final FileInputStream in = new FileInputStream(getPasswordFile()); properties.loadFromXML(in); in.close(); for (Object key : properties.keySet()) { logger.info(String.format("Key = [%s]", key.toString())); } setPassword(ObfuscationHelper.decryptString(properties.getProperty("password"))); }