use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.
the class PbeCrypto method decode.
@Override
@SuppressWarnings({ "lgtm [java/weak-cryptographic-algorithm]" })
public String decode(String encrypted, String charset) throws PasswordException {
String encryptedString = encrypted;
String result = null;
if (encrypted.startsWith(NON_PORTABLE_PASSWORD)) {
encryptedString = encrypted.substring(NON_PORTABLE_PASSWORD.length());
}
try {
PBEParameterSpec pbeParamSpec = new PBEParameterSpec(SALT, ITERATIONS);
PBEKeySpec pbeKeySpec = new PBEKeySpec(hostname.toCharArray());
SecretKeyFactory keyFac = SecretKeyFactory.getInstance(ALGORITHM);
SecretKey pbeKey = keyFac.generateSecret(pbeKeySpec);
Cipher pbeCipher = Cipher.getInstance(ALGORITHM);
pbeCipher.init(Cipher.DECRYPT_MODE, pbeKey, pbeParamSpec);
byte[] decrypted = pbeCipher.doFinal(base64.translate(encryptedString));
result = unseed(decrypted, charset);
} catch (Exception e) {
throw new PasswordException(e);
}
return result;
}
use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.
the class LegacyPrivateKeyPasswordProvider method retrievePrivateKeyPassword.
/**
* Return the private key password as a char[] array.
*
* @return the private key password sourced from 'security.properties' and decoded using {@link com.adaptris.security.password.Password#decode(String)}
*/
@Override
public char[] retrievePrivateKeyPassword() throws PasswordException {
if (pkPassword == null) {
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(PKEY_PW_FILE)) {
Properties p = new Properties();
p.load(is);
pkPassword = Password.decode(p.getProperty(PKEY_PW_KEY)).toCharArray();
} catch (IOException e) {
throw new PasswordException(e);
}
}
return pkPassword;
}
use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.
the class HttpLegacyPrivateKeyPasswordProvider method retrievePrivateKeyPassword.
/**
* Return the private key password as a char[] array.
*
* @return the private key sourced from 'adp-http.properties' and decoded using {@link com.adaptris.security.password.Password#decode(String)}
*/
@Override
public char[] retrievePrivateKeyPassword() throws PasswordException {
if (pkPassword == null) {
InputStream is = this.getClass().getClassLoader().getResourceAsStream(Https.CONFIG_PROPERTY_FILE);
try {
if (is != null) {
Properties p = new Properties();
p.load(is);
pkPassword = Password.decode(p.getProperty(Https.CONFIG_PRIVATE_KEY_PW)).toCharArray();
}
} catch (IOException e) {
throw new PasswordException(e);
} finally {
IOUtils.closeQuietly(is);
}
}
return pkPassword;
}
use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.
the class JdbcConnection method validateConnection.
/**
* <p>
* Validate the underlying connection.
* </p>
*
* @throws SQLException if we could not validate the connection.
*/
private void validateConnection() throws SQLException {
boolean connectionNeedsRefresh = false;
connectionNeedsRefresh = (sqlConnection == null);
if (connectionNeedsRefresh) {
try {
Properties p = connectionProperties();
sqlConnection = new ProxyNonClosingSqlConnection(DriverManager.getConnection(getConnectUrl(), p));
} catch (PasswordException e) {
sqlConnection = null;
log.error("Couldn't decode password for database");
throw new SQLException(e);
}
}
try {
// If the driver throws an AbstractMethodError because it's too old
// We're running in J11 which means it must have been compiled against
// J8 or higher... How the hell is it getting away with that?
JdbcUtil.testConnection(sqlConnection, alwaysValidateConnection());
} catch (SQLException e) {
sqlConnection = null;
throw e;
}
}
use of com.adaptris.security.exc.PasswordException in project interlok by adaptris.
the class StandardSftpConnectionTest method testConnectOnly_Composite_Fails.
@Test
public void testConnectOnly_Composite_Fails() throws Exception {
Assume.assumeTrue(areTestsEnabled());
StandardSftpConnection conn = createConnection();
SftpAuthenticationWrapper auth = new SftpAuthenticationWrapper(new SftpKeyAuthentication(PROPERTIES.getProperty(CFG_PRIVATE_KEY_FILE), "PW:abde"), new SftpKeyAuthentication("/some/path/that/does/not/exist", PROPERTIES.getProperty(CFG_PRIVATE_KEY_PW)));
conn.setAuthentication(auth);
try {
start(conn);
FileTransferClient c = conn.connect(getDestinationString());
fail();
} catch (IOException | PasswordException expected) {
} finally {
stop(conn);
}
}
Aggregations