Changed the default auth-file encryption algorithm to and the encoding to hex.
@@ -27,13 +27,16 @@ import com.thinkbiganalytics.auth.jaas.LoginConfiguration;
import com.thinkbiganalytics.auth.jaas.LoginConfigurationBuilder;
import com.thinkbiganalytics.auth.jaas.config.JaasAuthConfig;
-import org.jboss.security.auth.spi.UsersRolesLoginModule;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
import javax.security.auth.login.AppConfigurationEntry;
+import javax.xml.bind.DatatypeConverter;
/**
* Configures a file-based login module.
@@ -57,10 +60,10 @@ public class FileAuthConfig {
@Value("${security.auth.file.password.hash.enabled:false}")
private boolean passwordHashEnabled;
- @Value("${security.auth.file.password.hash.algorithm:MD5}")
+ @Value("${security.auth.file.password.hash.algorithm:SHA-256}")
private String hashAlgorithm;
- @Value("${security.auth.file.password.hash.encoding:base64}")
+ @Value("${security.auth.file.password.hash.encoding:hex}")
private String hashEncoding;
@Bean(name = "servicesFileLoginConfiguration")
@@ -124,4 +127,29 @@ public class FileAuthConfig {
module.initialize(null, null, null, entry.getOptions());
}
+
+ public static void main(String... args) {
+ if (args.length < 2) {
+ System.out.println("Usage: <password text> <hash algorithm> [<encoding>]");
+ System.exit(1);
+ }
+
+ String value = args[0];
+ String alg = args[1];
+ String encoding = args.length >= 3 ? args[2].toLowerCase() : "hex";
+
+ if (! encoding.equals("base64") && ! encoding.equals("hex")) {
+ System.err.println("Only supported encodings for this tool are \"base64\" or \"hex\"");
+ System.exit(2);
+ }
+
+ try {
+ MessageDigest md = MessageDigest.getInstance(alg);
+ byte[] bytes = md.digest(value.getBytes());
+ System.out.println(encoding.equals("hex") ? DatatypeConverter.printHexBinary(bytes).toLowerCase() : DatatypeConverter.printBase64Binary(bytes));
+ } catch (NoSuchAlgorithmException e) {
+ System.err.println("Unknown hash algorithm: " + e.getMessage());
+ System.exit(3);
+ }
+ }
}
