forked from I2P_Developers/i2p.i2p
Util: Add KeyStore and SHA256 to CLI
This commit is contained in:
@ -1280,7 +1280,6 @@ public final class KeyStoreUtil {
|
|||||||
* KeyStoreUtil keygen file.ks alias keypw (create keypair in keystore)
|
* KeyStoreUtil keygen file.ks alias keypw (create keypair in keystore)
|
||||||
* KeyStoreUtil keygen2 file.ks alias keypw (create keypair using I2PProvider)
|
* KeyStoreUtil keygen2 file.ks alias keypw (create keypair using I2PProvider)
|
||||||
*/
|
*/
|
||||||
/****
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
if (args.length > 0 && "import".equals(args[0])) {
|
if (args.length > 0 && "import".equals(args[0])) {
|
||||||
@ -1299,6 +1298,10 @@ public final class KeyStoreUtil {
|
|||||||
testKeygen2(args);
|
testKeygen2(args);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (args.length > 0 && "list".equals(args[0])) {
|
||||||
|
listKeys(args);
|
||||||
|
return;
|
||||||
|
}
|
||||||
File ksf = (args.length > 0) ? new File(args[0]) : null;
|
File ksf = (args.length > 0) ? new File(args[0]) : null;
|
||||||
if (ksf != null && !ksf.exists()) {
|
if (ksf != null && !ksf.exists()) {
|
||||||
createKeyStore(ksf, DEFAULT_KEYSTORE_PASSWORD);
|
createKeyStore(ksf, DEFAULT_KEYSTORE_PASSWORD);
|
||||||
@ -1339,6 +1342,10 @@ public final class KeyStoreUtil {
|
|||||||
|
|
||||||
|
|
||||||
private static void testExport(String[] args) throws Exception {
|
private static void testExport(String[] args) throws Exception {
|
||||||
|
if (args.length != 4) {
|
||||||
|
System.err.println("Usage: KeyStoreUtil export keystore.ks keyalias keypassword");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
File ksf = new File(args[1]);
|
File ksf = new File(args[1]);
|
||||||
String alias = args[2];
|
String alias = args[2];
|
||||||
String pw = args[3];
|
String pw = args[3];
|
||||||
@ -1386,5 +1393,40 @@ public final class KeyStoreUtil {
|
|||||||
net.i2p.data.Signature sig = SigUtil.fromJavaSig(bsig, type);
|
net.i2p.data.Signature sig = SigUtil.fromJavaSig(bsig, type);
|
||||||
System.out.println("Signature test: " + sig);
|
System.out.println("Signature test: " + sig);
|
||||||
}
|
}
|
||||||
****/
|
|
||||||
|
private static void listKeys(String[] args) {
|
||||||
|
if (args.length != 2) {
|
||||||
|
System.err.println("Usage: KeyStoreUtil list keystore.ks");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
File ksf = new File(args[1]);
|
||||||
|
if (ksf.exists()) {
|
||||||
|
InputStream fis = null;
|
||||||
|
try {
|
||||||
|
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||||
|
fis = new FileInputStream(ksf);
|
||||||
|
ks.load(fis, DEFAULT_KEYSTORE_PASSWORD.toCharArray());
|
||||||
|
System.out.println("Certificates:");
|
||||||
|
for(Enumeration<String> e = ks.aliases(); e.hasMoreElements();) {
|
||||||
|
String alias = e.nextElement();
|
||||||
|
if (ks.isCertificateEntry(alias))
|
||||||
|
System.out.println(alias);
|
||||||
|
}
|
||||||
|
System.out.println("\nPrivate keys:");
|
||||||
|
for(Enumeration<String> e = ks.aliases(); e.hasMoreElements();) {
|
||||||
|
String alias = e.nextElement();
|
||||||
|
if (ks.isKeyEntry(alias))
|
||||||
|
System.out.println(alias);
|
||||||
|
}
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
error("Unable to get certificates in key store " + ksf, ioe);
|
||||||
|
} catch (GeneralSecurityException gse) {
|
||||||
|
error("Unable to get certificates in key store " + ksf, gse);
|
||||||
|
} finally {
|
||||||
|
try { if (fis != null) fis.close(); } catch (IOException foo) {}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.err.println("Keystore file not found: " + ksf);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,4 +92,12 @@ public final class SHA256Generator {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
if (args.length != 1) {
|
||||||
|
System.err.println("Usage: SHA256Generator 'text to hash'");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
System.out.println(net.i2p.data.Base64.encode(getInstance().calculateHash(net.i2p.data.DataHelper.getUTF8(args[0])).getData()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,9 @@ public class CommandLine {
|
|||||||
"net.i2p.crypto.CertUtil",
|
"net.i2p.crypto.CertUtil",
|
||||||
"net.i2p.crypto.CryptoCheck",
|
"net.i2p.crypto.CryptoCheck",
|
||||||
"net.i2p.crypto.KeyGenerator",
|
"net.i2p.crypto.KeyGenerator",
|
||||||
|
"net.i2p.crypto.KeyStoreUtil",
|
||||||
"net.i2p.crypto.SelfSignedGenerator",
|
"net.i2p.crypto.SelfSignedGenerator",
|
||||||
|
"net.i2p.crypto.SHA256Generator",
|
||||||
"net.i2p.crypto.SU3File",
|
"net.i2p.crypto.SU3File",
|
||||||
"net.i2p.crypto.TrustedUpdate",
|
"net.i2p.crypto.TrustedUpdate",
|
||||||
"net.i2p.data.Base32",
|
"net.i2p.data.Base32",
|
||||||
|
Reference in New Issue
Block a user