Skip to content

Commit

Permalink
Merge branch 'master' into j21tc9
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanrdoherty committed Aug 12, 2024
2 parents f413d5a + 33c15fa commit b197a24
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Model/bin/readSecretKey
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

fgpJava org.gusdb.wdk.model.config.SecretKeyReader $@
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <path-to-secret-key-file>");
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<Path> secretKeyFile) throws IOException {
try (FileReader in = new FileReader(secretKeyFile.get().toFile())) {
return EncryptionUtil.md5(IoUtil.readAllChars(in).strip());
}
}

}

0 comments on commit b197a24

Please sign in to comment.