diff --git a/Model/bin/readSecretKey b/Model/bin/readSecretKey new file mode 100755 index 000000000..9e786af42 --- /dev/null +++ b/Model/bin/readSecretKey @@ -0,0 +1,3 @@ +#!/bin/bash + +fgpJava org.gusdb.wdk.model.config.SecretKeyReader $@ diff --git a/Model/src/main/java/org/gusdb/wdk/model/config/ModelConfig.java b/Model/src/main/java/org/gusdb/wdk/model/config/ModelConfig.java index 3a27c24d8..0f03d8488 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/config/ModelConfig.java +++ b/Model/src/main/java/org/gusdb/wdk/model/config/ModelConfig.java @@ -1,15 +1,12 @@ package org.gusdb.wdk.model.config; -import java.io.FileReader; import java.io.IOException; import java.nio.file.Path; import java.util.List; import java.util.Optional; import org.apache.log4j.Logger; -import org.gusdb.fgputil.EncryptionUtil; import org.gusdb.fgputil.FormatUtil; -import org.gusdb.fgputil.IoUtil; import org.gusdb.fgputil.Named.NamedObject; import org.gusdb.oauth2.client.KeyStoreTrustManager.KeyStoreConfig; import org.gusdb.oauth2.client.OAuthConfig; @@ -304,8 +301,8 @@ public ModelConfigAppDB getAppDB() { */ public String getSecretKey() { if (_secretKey == null && _secretKeyFile.isPresent()) { - try (FileReader in = new FileReader(_secretKeyFile.get().toFile())) { - _secretKey = EncryptionUtil.md5(IoUtil.readAllChars(in).strip()); + try { + _secretKey = SecretKeyReader.readSecretKey(_secretKeyFile); } catch (IOException e) { // log error but otherwise ignore so null is returned; problem may be remedied in the future diff --git a/Model/src/main/java/org/gusdb/wdk/model/config/SecretKeyReader.java b/Model/src/main/java/org/gusdb/wdk/model/config/SecretKeyReader.java new file mode 100644 index 000000000..30af7de87 --- /dev/null +++ b/Model/src/main/java/org/gusdb/wdk/model/config/SecretKeyReader.java @@ -0,0 +1,35 @@ +package org.gusdb.wdk.model.config; + +import java.io.FileReader; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Optional; + +import org.gusdb.fgputil.EncryptionUtil; +import org.gusdb.fgputil.IoUtil; + +public class SecretKeyReader { + + public static void main(String[] args) { + if (args.length != 1) { + System.err.println("USAGE: readSecretKey "); + System.exit(1); + } + Path path = Paths.get(args[0]); + try { + System.out.print(readSecretKey(Optional.of(path))); + } + catch (Exception e) { + e.printStackTrace(System.err); + System.exit(2); + } + } + + public static String readSecretKey(Optional secretKeyFile) throws IOException { + try (FileReader in = new FileReader(secretKeyFile.get().toFile())) { + return EncryptionUtil.md5(IoUtil.readAllChars(in).strip()); + } + } + +}