Add aliases defined in RFC 5155 (NSEC3); formatting.

git-svn-id: https://svn.verisignlabs.com/jdnssec/tools/trunk@113 4cbd57fe-54e5-0310-bd9a-f30fe5ea5e6e
This commit is contained in:
David Blacka 2009-02-02 04:51:15 +00:00
parent e5270de8ee
commit 4073e6a576

View File

@ -41,13 +41,13 @@ import java.util.logging.Logger;
import org.xbill.DNS.DNSSEC; import org.xbill.DNS.DNSSEC;
/** /**
* This class handles translated DNS signing algorithm identifiers into * This class handles translated DNS signing algorithm identifiers into various
* various usable java implementations. * usable java implementations.
* *
* Besides centralizing the logic surrounding matching a DNSKEY algorithm * Besides centralizing the logic surrounding matching a DNSKEY algorithm
* identifier with various crypto implementations, it also handles algorithm * identifier with various crypto implementations, it also handles algorithm
* aliasing -- that is, defining a new algorithm identifier to be equivalent * aliasing -- that is, defining a new algorithm identifier to be equivalent to
* to an existing identifier. * an existing identifier.
* *
* @author David Blacka (orig) * @author David Blacka (orig)
* @author $Author: davidb $ (latest) * @author $Author: davidb $ (latest)
@ -74,9 +74,8 @@ public class DnsKeyAlgorithm
} }
/** /**
* This is a mapping of algorithm identifier to Entry. The Entry contains * This is a mapping of algorithm identifier to Entry. The Entry contains the
* the data needed to map the algorithm to the various crypto * data needed to map the algorithm to the various crypto implementations.
* implementations.
*/ */
private HashMap mAlgorithmMap; private HashMap mAlgorithmMap;
/** /**
@ -84,8 +83,8 @@ public class DnsKeyAlgorithm
*/ */
private HashMap mMnemonicToIdMap; private HashMap mMnemonicToIdMap;
/** /**
* This is a mapping of identifiers to preferred mnemonic -- the preferred * This is a mapping of identifiers to preferred mnemonic -- the preferred one
* one is the first defined one * is the first defined one
*/ */
private HashMap mIdToMnemonicMap; private HashMap mIdToMnemonicMap;
@ -119,6 +118,10 @@ public class DnsKeyAlgorithm
addAlgorithm(DNSSEC.RSASHA1, new Entry("SHA1withRSA", RSA)); addAlgorithm(DNSSEC.RSASHA1, new Entry("SHA1withRSA", RSA));
addMnemonic("RSASHA1", DNSSEC.RSASHA1); addMnemonic("RSASHA1", DNSSEC.RSASHA1);
addMnemonic("RSA", DNSSEC.RSASHA1); addMnemonic("RSA", DNSSEC.RSASHA1);
// Load the (now) standard aliases
addAlias(6, "DSA-NSEC3-SHA1", DNSSEC.DSA);
addAlias(7, "RSA-NSEC3-SHA1", DNSSEC.RSASHA1);
} }
private void addAlgorithm(int algorithm, Entry entry) private void addAlgorithm(int algorithm, Entry entry)
@ -131,7 +134,7 @@ public class DnsKeyAlgorithm
{ {
Integer a = new Integer(alg); Integer a = new Integer(alg);
mMnemonicToIdMap.put(m.toUpperCase(), a); mMnemonicToIdMap.put(m.toUpperCase(), a);
if (! mIdToMnemonicMap.containsKey(a)) if (!mIdToMnemonicMap.containsKey(a))
{ {
mIdToMnemonicMap.put(a, m); mIdToMnemonicMap.put(a, m);
} }
@ -212,14 +215,14 @@ public class DnsKeyAlgorithm
{ {
switch (baseType(algorithm)) switch (baseType(algorithm))
{ {
case RSA : case RSA:
return DNSSEC.RSASHA1; return DNSSEC.RSASHA1;
case DSA : case DSA:
return DNSSEC.DSA; return DNSSEC.DSA;
case DH : case DH:
return DNSSEC.DH; return DNSSEC.DH;
default : default:
return UNKNOWN; return UNKNOWN;
} }
} }
@ -234,44 +237,46 @@ public class DnsKeyAlgorithm
KeyPair pair = null; KeyPair pair = null;
switch (baseType(algorithm)) switch (baseType(algorithm))
{ {
case RSA : case RSA:
if (mRSAKeyGenerator == null) if (mRSAKeyGenerator == null)
{ {
mRSAKeyGenerator = KeyPairGenerator.getInstance("RSA"); mRSAKeyGenerator = KeyPairGenerator.getInstance("RSA");
} }
RSAKeyGenParameterSpec rsa_spec; RSAKeyGenParameterSpec rsa_spec;
if (useLargeExp) if (useLargeExp)
{ {
rsa_spec = new RSAKeyGenParameterSpec(keysize, RSAKeyGenParameterSpec.F4); rsa_spec = new RSAKeyGenParameterSpec(keysize,
} RSAKeyGenParameterSpec.F4);
else }
{ else
rsa_spec = new RSAKeyGenParameterSpec(keysize, RSAKeyGenParameterSpec.F0); {
} rsa_spec = new RSAKeyGenParameterSpec(keysize,
try RSAKeyGenParameterSpec.F0);
{ }
mRSAKeyGenerator.initialize(rsa_spec); try
} {
catch (InvalidAlgorithmParameterException e) mRSAKeyGenerator.initialize(rsa_spec);
{ }
// Fold the InvalidAlgorithmParameterException into our existing catch (InvalidAlgorithmParameterException e)
// thrown exception. Ugly, but requires less code change. {
throw new NoSuchAlgorithmException("invalid key parameter spec"); // Fold the InvalidAlgorithmParameterException into our existing
} // thrown exception. Ugly, but requires less code change.
throw new NoSuchAlgorithmException("invalid key parameter spec");
}
pair = mRSAKeyGenerator.generateKeyPair(); pair = mRSAKeyGenerator.generateKeyPair();
break; break;
case DSA : case DSA:
if (mDSAKeyGenerator == null) if (mDSAKeyGenerator == null)
{ {
mDSAKeyGenerator = KeyPairGenerator.getInstance("DSA"); mDSAKeyGenerator = KeyPairGenerator.getInstance("DSA");
} }
mDSAKeyGenerator.initialize(keysize); mDSAKeyGenerator.initialize(keysize);
pair = mDSAKeyGenerator.generateKeyPair(); pair = mDSAKeyGenerator.generateKeyPair();
break; break;
default : default:
throw new NoSuchAlgorithmException("Alg " + algorithm); throw new NoSuchAlgorithmException("Alg " + algorithm);
} }
return pair; return pair;