Skip to content
Snippets Groups Projects
Commit fd4db9b9 authored by Rob Adams's avatar Rob Adams
Browse files

Add AuthTool command-line tool to create shared secret for challenge/response authentication

parent d3fa485a
No related branches found
No related tags found
No related merge requests found
package org.sdnplatform.sync.client;
import java.io.Console;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.sdnplatform.sync.internal.config.AuthScheme;
import org.sdnplatform.sync.internal.util.CryptoUtil;
/**
* Command-line tool for setting up authentication credentials
* @author readams
*/
public class AuthTool {
protected static class AuthToolSettings {
@Option(name="--help",
usage="Show help")
protected boolean help;
@Option(name="--keyStorePath",
usage="Path to JCEKS key store where credentials should " +
"be stored",
required=true)
protected String keyStorePath;
@Option(name="--keyStorePassword",
usage="Password for key store")
protected String keyStorePassword;
@Option(name="--authScheme",
usage="Auth scheme for which we should set up credentials",
required=true)
protected AuthScheme authScheme;
}
public static void main(String[] args) throws Exception {
AuthToolSettings settings = new AuthToolSettings();
CmdLineParser parser = new CmdLineParser(settings);
try {
parser.parseArgument(args);
} catch (CmdLineException e) {
System.err.println(e.getMessage());
parser.printUsage(System.err);
System.exit(1);
}
if (settings.help) {
parser.printUsage(System.err);
System.exit(1);
}
if (settings.keyStorePassword == null) {
Console con = System.console();
char[] password = con.readPassword("Enter key store password: ");
settings.keyStorePassword = new String(password);
}
switch (settings.authScheme) {
case NO_AUTH:
System.err.println("No credentials required for NO_AUTH");
break;
case CHALLENGE_RESPONSE:
CryptoUtil.writeSharedSecret(settings.keyStorePath,
settings.keyStorePassword,
CryptoUtil.secureRandom(16));
System.out.println("Wrote random 128-bit secret to " +
settings.keyStorePath);
break;
}
}
}
......@@ -436,7 +436,7 @@ public class SyncClient {
protected static class SyncClientSettings {
@Option(name="--help",
usage="Server hostname")
usage="Show help")
protected boolean help;
@Option(name="--hostname", aliases="-h",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment