Add env var support to CLI.
[ADDED] The Java CLI client can now take values for the username and master password from the environment.
This commit is contained in:
parent
647235616e
commit
f2fdca6a03
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Wed Jul 04 23:49:38 CEST 2012
|
#Mon Jul 30 10:06:47 CEST 2012
|
||||||
version=GIT-SNAPSHOT
|
version=GIT-SNAPSHOT
|
||||||
groupId=com.lyndir.lhunath.masterpassword
|
groupId=com.lyndir.lhunath.masterpassword
|
||||||
artifactId=masterpassword-algorithm
|
artifactId=masterpassword-algorithm
|
||||||
|
@ -18,7 +18,8 @@ package com.lyndir.lhunath.masterpassword;
|
|||||||
import com.google.common.io.LineReader;
|
import com.google.common.io.LineReader;
|
||||||
import com.lyndir.lhunath.opal.system.logging.Logger;
|
import com.lyndir.lhunath.opal.system.logging.Logger;
|
||||||
import com.lyndir.lhunath.opal.system.util.ConversionUtils;
|
import com.lyndir.lhunath.opal.system.util.ConversionUtils;
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
||||||
@ -30,14 +31,19 @@ import java.util.Arrays;
|
|||||||
public class CLI {
|
public class CLI {
|
||||||
|
|
||||||
static final Logger logger = Logger.get( CLI.class );
|
static final Logger logger = Logger.get( CLI.class );
|
||||||
|
private static final String ENV_USERNAME = "MP_USERNAME";
|
||||||
|
private static final String ENV_PASSWORD = "MP_PASSWORD";
|
||||||
|
|
||||||
public static void main(final String[] args)
|
public static void main(final String[] args)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
InputStream in = System.in;
|
String userName, masterPassword, siteName = null;
|
||||||
|
|
||||||
|
/* Environment. */
|
||||||
|
userName = System.getenv().get( ENV_USERNAME );
|
||||||
|
masterPassword = System.getenv().get( ENV_PASSWORD );
|
||||||
|
|
||||||
/* Arguments. */
|
/* Arguments. */
|
||||||
String userName = null, siteName = null;
|
|
||||||
int counter = 1;
|
int counter = 1;
|
||||||
MPElementType type = MPElementType.GeneratedLong;
|
MPElementType type = MPElementType.GeneratedLong;
|
||||||
boolean typeArg = false, counterArg = false, userNameArg = false;
|
boolean typeArg = false, counterArg = false, userNameArg = false;
|
||||||
@ -72,6 +78,7 @@ public class CLI {
|
|||||||
System.out.println( "[options] [site name]" );
|
System.out.println( "[options] [site name]" );
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println( "Available options:" );
|
System.out.println( "Available options:" );
|
||||||
|
|
||||||
System.out.println( "\t-t | --type [site password type]" );
|
System.out.println( "\t-t | --type [site password type]" );
|
||||||
System.out.format( "\t\tDefault: %s. The password type to use for this site.\n", type.getName() );
|
System.out.format( "\t\tDefault: %s. The password type to use for this site.\n", type.getName() );
|
||||||
System.out.println( "\t\tUse 'list' to see the available types." );
|
System.out.println( "\t\tUse 'list' to see the available types." );
|
||||||
@ -83,26 +90,44 @@ public class CLI {
|
|||||||
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println( "\t-u | --username [user's name]" );
|
System.out.println( "\t-u | --username [user's name]" );
|
||||||
System.out.println( "\t\tDefault: asked. The name of the current user." );
|
System.out.println( "\t\tDefault: asked. The name of the user." );
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
System.out.println( "Available environment variables:" );
|
||||||
|
|
||||||
|
System.out.format( "\t%s\n", ENV_USERNAME );
|
||||||
|
System.out.println( "\t\tThe name of the user." );
|
||||||
|
|
||||||
|
System.out.format( "\t%s\n", ENV_PASSWORD );
|
||||||
|
System.out.println( "\t\tThe master password of the user." );
|
||||||
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
return;
|
return;
|
||||||
} else
|
} else
|
||||||
siteName = arg;
|
siteName = arg;
|
||||||
LineReader lineReader = new LineReader( new InputStreamReader( System.in ) );
|
|
||||||
|
InputStreamReader inReader = new InputStreamReader( System.in );
|
||||||
|
try {
|
||||||
|
LineReader lineReader = new LineReader( inReader );
|
||||||
if (siteName == null) {
|
if (siteName == null) {
|
||||||
System.out.print( "Site name: " );
|
System.err.format( "Site name: " );
|
||||||
siteName = lineReader.readLine();
|
siteName = lineReader.readLine();
|
||||||
}
|
}
|
||||||
if (userName == null) {
|
if (userName == null) {
|
||||||
System.out.print( "User's name: " );
|
System.err.format( "User's name: " );
|
||||||
userName = lineReader.readLine();
|
userName = lineReader.readLine();
|
||||||
}
|
}
|
||||||
System.out.print( "User's master password: " );
|
if (masterPassword == null) {
|
||||||
String masterPassword = lineReader.readLine();
|
System.err.format( "%s's master password: ", userName );
|
||||||
|
masterPassword = lineReader.readLine();
|
||||||
|
}
|
||||||
|
|
||||||
String sitePassword = MasterPassword.generateContent( type, siteName, MasterPassword.keyForPassword( masterPassword, userName ),
|
byte[] masterKey = MasterPassword.keyForPassword( masterPassword, userName );
|
||||||
counter );
|
String sitePassword = MasterPassword.generateContent( type, siteName, masterKey, counter );
|
||||||
System.out.println( sitePassword );
|
System.out.println( sitePassword );
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
inReader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
#Generated by Maven
|
#Generated by Maven
|
||||||
#Wed Jul 04 23:49:39 CEST 2012
|
#Mon Jul 30 10:06:48 CEST 2012
|
||||||
version=GIT-SNAPSHOT
|
version=GIT-SNAPSHOT
|
||||||
groupId=com.lyndir.lhunath.masterpassword
|
groupId=com.lyndir.lhunath.masterpassword
|
||||||
artifactId=masterpassword-cli
|
artifactId=masterpassword-cli
|
||||||
|
Loading…
Reference in New Issue
Block a user