From 558592a87f331d90d3692593c21caa9fd4bf8fcc Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 8 May 2019 13:50:26 +0000 Subject: [PATCH] Utils: Auto-generate su3 output file for extract if not specified --- core/java/src/net/i2p/crypto/SU3File.java | 39 +++++++++++++++++-- .../src/net/i2p/router/RouterVersion.java | 2 +- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/core/java/src/net/i2p/crypto/SU3File.java b/core/java/src/net/i2p/crypto/SU3File.java index 70da7e9c4..91167f282 100644 --- a/core/java/src/net/i2p/crypto/SU3File.java +++ b/core/java/src/net/i2p/crypto/SU3File.java @@ -615,7 +615,7 @@ public class SU3File { } int idx = g.getOptind(); - String cmd = args[idx]; + String cmd = args[idx].toLowerCase(Locale.US); List a = new ArrayList(Arrays.asList(args).subList(idx + 1, args.length)); if (error) { @@ -641,7 +641,8 @@ public class SU3File { new I2PAppContext(props); ok = genKeysCLI(stype, a.get(0), a.get(1), crlfile, a.get(2), kspass); } else if ("extract".equals(cmd)) { - ok = extractCLI(a.get(0), a.get(1), shouldVerify, kfile); + String outfile = (a.size() > 1) ? a.get(1) : null; + ok = extractCLI(a.get(0), outfile, shouldVerify, kfile); } else { showUsageCLI(); } @@ -661,7 +662,7 @@ public class SU3File { " (signs all .zip, .xml, and .xml.gz files in the directory)\n" + " SU3File showversion signedFile.su3\n" + " SU3File verifysig [-k file.crt] signedFile.su3 ## -k use this pubkey cert for verification\n" + - " SU3File extract [-x] [-k file.crt] signedFile.su3 outFile ## -x don't check sig"); + " SU3File extract [-x] [-k file.crt] signedFile.su3 [outFile] ## -x don't check sig"); System.err.println("Default keystore password: \"" + KeyStoreUtil.DEFAULT_KEYSTORE_PASSWORD + '"'); System.err.println(dumpTypes()); } @@ -928,6 +929,7 @@ public class SU3File { } /** + * @param outFile if null, will use a name derived from signedFile * @return success * @since 0.9.9 */ @@ -938,10 +940,39 @@ public class SU3File { if (pkFile != null) file.setPublicKeyCertificate(new File(pkFile)); file.setVerifySignature(verifySig); + if (outFile == null) { + outFile = signedFile; + if (outFile.endsWith(".su3") && outFile.length() > 4) + outFile = outFile.substring(0, outFile.length() - 4); + String sfx; + switch (file.getFileType()) { + case TYPE_ZIP: + sfx = ".zip"; + break; + case TYPE_XML: + sfx = ".xml"; + break; + case TYPE_HTML: + sfx = ".html"; + break; + case TYPE_XML_GZ: + sfx = ".xml.gz"; + break; + case TYPE_TXT_GZ: + sfx = ".txt.gz"; + break; + default: + sfx = ".extracted"; + break; + } + outFile = outFile + sfx; + // above causes failure, quick fix + file = new SU3File(signedFile); + } File out = new File(outFile); boolean ok = file.verifyAndMigrate(out); if (ok) - System.out.println("File extracted (signed by " + file.getSignerString() + ' ' + file._sigType + ')'); + System.out.println("File extracted to " + outFile + " (signed by " + file.getSignerString() + ' ' + file._sigType + ')'); else System.out.println("Signature INVALID (signed by " + file.getSignerString() + ' ' + file._sigType +')'); return ok; diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index a411b0099..87e5bffca 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 0; + public final static long BUILD = 1; /** for example "-test" */ public final static String EXTRA = "";