Utils: Add RKG command line tool

This commit is contained in:
zzz
2016-12-24 13:46:51 +00:00
parent f902a63144
commit 074c630ac6
2 changed files with 24 additions and 15 deletions

View File

@@ -22,6 +22,7 @@ import net.i2p.crypto.SHA256Generator;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.data.Hash; import net.i2p.data.Hash;
import net.i2p.data.RoutingKeyGenerator; import net.i2p.data.RoutingKeyGenerator;
import net.i2p.util.ConvertToHash;
import net.i2p.util.HexDump; import net.i2p.util.HexDump;
import net.i2p.util.Log; import net.i2p.util.Log;
@@ -216,23 +217,30 @@ public class RouterKeyGenerator extends RoutingKeyGenerator {
return SHA256Generator.getInstance().calculateHash(modVal); return SHA256Generator.getInstance().calculateHash(modVal);
} }
/**** /**
* @since 0.9.29
*/
public static void main(String args[]) { public static void main(String args[]) {
Hash k1 = new Hash(); if (args.length <= 0) {
byte k1d[] = new byte[Hash.HASH_LENGTH]; System.err.println("Usage: RouterKeyGenerator [-days] [+days] hash|hostname|destination");
RandomSource.getInstance().nextBytes(k1d); System.exit(1);
k1.setData(k1d);
for (int i = 0; i < 10; i++) {
System.out.println("K1: " + k1);
Hash k1m = RoutingKeyGenerator.getInstance().getRoutingKey(k1);
System.out.println("MOD: " + new String(RoutingKeyGenerator.getInstance().getModData()));
System.out.println("K1M: " + k1m);
} }
try { long now = System.currentTimeMillis();
Thread.sleep(2000); Hash h;
} catch (Throwable t) { // nop if (args.length > 1 && (args[0].startsWith("+") || args[0].startsWith("-"))) {
now += Integer.parseInt(args[0]) * 24*60*60*1000L;
h = ConvertToHash.getHash(args[1]);
} else {
h = ConvertToHash.getHash(args[0]);
} }
if (h == null) {
System.err.println("Bad hash");
System.exit(1);
}
RouterKeyGenerator rkg = new RouterKeyGenerator(I2PAppContext.getGlobalContext());
Hash rkey = rkg.getRoutingKey(h, now);
System.out.println("Date: " + rkg._fmt.format(now));
System.out.println("Original key: " + h.toBase64());
System.out.println("Routing key: " + rkey.toBase64());
} }
****/
} }

View File

@@ -15,6 +15,7 @@ public class CommandLine extends net.i2p.util.CommandLine {
protected static final List<String> RCLASSES = Arrays.asList(new String[] { protected static final List<String> RCLASSES = Arrays.asList(new String[] {
"net.i2p.data.router.RouterInfo", "net.i2p.data.router.RouterInfo",
"net.i2p.data.router.RouterKeyGenerator",
"net.i2p.router.MultiRouter", "net.i2p.router.MultiRouter",
"net.i2p.router.Router", "net.i2p.router.Router",
"net.i2p.router.RouterLaunch", "net.i2p.router.RouterLaunch",