Make the keyinfo tool slightly more useful: handle multiple keys at a time, print out DSA key information, etc.
git-svn-id: https://svn.verisignlabs.com/jdnssec/tools/trunk@141 4cbd57fe-54e5-0310-bd9a-f30fe5ea5e6e
This commit is contained in:
parent
f09eeaffaa
commit
b90877444d
@ -20,6 +20,7 @@
|
|||||||
package com.verisignlabs.dnssec.cl;
|
package com.verisignlabs.dnssec.cl;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.security.interfaces.DSAPublicKey;
|
||||||
import java.security.interfaces.RSAPublicKey;
|
import java.security.interfaces.RSAPublicKey;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -48,7 +49,7 @@ public class KeyInfoTool
|
|||||||
private static class CLIState
|
private static class CLIState
|
||||||
{
|
{
|
||||||
private Options opts;
|
private Options opts;
|
||||||
public String keyname = null;
|
public String[] keynames = null;
|
||||||
|
|
||||||
public CLIState()
|
public CLIState()
|
||||||
{
|
{
|
||||||
@ -118,15 +119,13 @@ public class KeyInfoTool
|
|||||||
addArgAlias(optstrs[i]);
|
addArgAlias(optstrs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String[] cl_args = cli.getArgs();
|
keynames = cli.getArgs();
|
||||||
|
|
||||||
if (cl_args.length < 1)
|
if (keynames.length < 1)
|
||||||
{
|
{
|
||||||
System.err.println("error: missing key file ");
|
System.err.println("error: missing key file ");
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
keyname = cl_args[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Print out the usage and help statements, then quit. */
|
/** Print out the usage and help statements, then quit. */
|
||||||
@ -190,25 +189,49 @@ public class KeyInfoTool
|
|||||||
public static void execute(CLIState state) throws Exception
|
public static void execute(CLIState state) throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
DnsKeyPair key = BINDKeyUtils.loadKey(state.keyname, null);
|
for (int i = 0; i < state.keynames.length; ++i)
|
||||||
DNSKEYRecord dnskey = key.getDNSKEYRecord();
|
|
||||||
DnsKeyAlgorithm dnskeyalg = DnsKeyAlgorithm.getInstance();
|
|
||||||
|
|
||||||
boolean isSEP = (dnskey.getFlags() & DNSKEYRecord.Flags.SEP_KEY) != 0;
|
|
||||||
|
|
||||||
System.out.println("Name: " + dnskey.getName());
|
|
||||||
System.out.println("SEP: " + isSEP);
|
|
||||||
|
|
||||||
System.out.println("Algorithm: "
|
|
||||||
+ dnskeyalg.algToString(dnskey.getAlgorithm()));
|
|
||||||
System.out.println("ID: " + dnskey.getFootprint());
|
|
||||||
if (dnskeyalg.baseType(dnskey.getAlgorithm()) == DnsKeyAlgorithm.RSA)
|
|
||||||
{
|
{
|
||||||
RSAPublicKey pub = (RSAPublicKey) key.getPublic();
|
String keyname = state.keynames[i];
|
||||||
System.out.println("RSA Public Exponent: " + pub.getPublicExponent());
|
DnsKeyPair key = BINDKeyUtils.loadKey(keyname, null);
|
||||||
System.out.println("RSA Modulus: " + pub.getModulus());
|
DNSKEYRecord dnskey = key.getDNSKEYRecord();
|
||||||
}
|
DnsKeyAlgorithm dnskeyalg = DnsKeyAlgorithm.getInstance();
|
||||||
|
|
||||||
|
boolean isSEP = (dnskey.getFlags() & DNSKEYRecord.Flags.SEP_KEY) != 0;
|
||||||
|
|
||||||
|
System.out.println(keyname + ":");
|
||||||
|
System.out.println("Name: " + dnskey.getName());
|
||||||
|
System.out.println("SEP: " + isSEP);
|
||||||
|
|
||||||
|
System.out.println("Algorithm: "
|
||||||
|
+ dnskeyalg.algToString(dnskey.getAlgorithm()) + " ("
|
||||||
|
+ dnskey.getAlgorithm() + ")");
|
||||||
|
System.out.println("ID: " + dnskey.getFootprint());
|
||||||
|
System.out.println("KeyFileBase: " + BINDKeyUtils.keyFileBase(key));
|
||||||
|
int basetype = dnskeyalg.baseType(dnskey.getAlgorithm());
|
||||||
|
switch (basetype)
|
||||||
|
{
|
||||||
|
case DnsKeyAlgorithm.RSA:
|
||||||
|
{
|
||||||
|
RSAPublicKey pub = (RSAPublicKey) key.getPublic();
|
||||||
|
System.out.println("RSA Public Exponent: " + pub.getPublicExponent());
|
||||||
|
System.out.println("RSA Modulus: " + pub.getModulus());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case DnsKeyAlgorithm.DSA:
|
||||||
|
{
|
||||||
|
DSAPublicKey pub = (DSAPublicKey) key.getPublic();
|
||||||
|
System.out.println("DSA base (G): " + pub.getParams().getG());
|
||||||
|
System.out.println("DSA prime (P): " + pub.getParams().getP());
|
||||||
|
System.out.println("DSA subprime (Q): " + pub.getParams().getQ());
|
||||||
|
System.out.println("DSA public (Y): " + pub.getY());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (state.keynames.length - i > 1)
|
||||||
|
{
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
|
Loading…
Reference in New Issue
Block a user