Some DNSKeyAlgorithm class cleanup

This commit is contained in:
David Blacka 2018-11-16 13:57:16 +00:00
parent 62b5b0ad23
commit 7d27694d9a

View File

@ -200,7 +200,7 @@ public class DnsKeyAlgorithm
addMnemonic("RSASHA512", DNSSEC.Algorithm.RSASHA512); addMnemonic("RSASHA512", DNSSEC.Algorithm.RSASHA512);
// ECC-GOST is not supported by Java 1.8's Sun crypto provider. The // ECC-GOST is not supported by Java 1.8's Sun crypto provider. The
// bouncycastle.org provider, however, does. // bouncycastle.org provider, however, does support it.
// GostR3410-2001-CryptoPro-A is the named curve in the BC provider, but we // GostR3410-2001-CryptoPro-A is the named curve in the BC provider, but we
// will get the parameters directly. // will get the parameters directly.
addAlgorithm(DNSSEC.Algorithm.ECC_GOST, "GOST3411withECGOST3410", ECC_GOST, null); addAlgorithm(DNSSEC.Algorithm.ECC_GOST, "GOST3411withECGOST3410", ECC_GOST, null);
@ -217,8 +217,8 @@ public class DnsKeyAlgorithm
// EdDSA is not supported by either the Java 1.8 Sun crypto // EdDSA is not supported by either the Java 1.8 Sun crypto
// provider or bouncycastle. It is added by the Ed25519-Java // provider or bouncycastle. It is added by the Ed25519-Java
// library. // library. We don't have a corresponding constant in
// FIXME: add constant for the EdDSA algs to DNSJava. // org.xbill.DNS.DNSSEC yet, though.
addAlgorithm(15, "NONEwithEdDSA", EDDSA, "Ed25519"); addAlgorithm(15, "NONEwithEdDSA", EDDSA, "Ed25519");
addMnemonic("ED25519", 15); addMnemonic("ED25519", 15);
} }
@ -250,8 +250,7 @@ public class DnsKeyAlgorithm
} }
else if (baseType == EDDSA) else if (baseType == EDDSA)
{ {
EdDSAParameterSpec ed_spec = EdDSASpecFromAlgorithm(algorithm); EdDSAParameterSpec ed_spec = EdDSASpecFromName(curveName);
if (ed_spec == null) ed_spec = EdDSASpecFromName(curveName);
if (ed_spec == null) return; if (ed_spec == null) return;
// Check to see if we can get a Signature object for this algorithm. // Check to see if we can get a Signature object for this algorithm.
@ -335,7 +334,7 @@ public class DnsKeyAlgorithm
} }
} }
// Fetch the curve parameters from a named curve. // Fetch the curve parameters from a named ECDSA curve.
private ECParameterSpec ECSpecFromName(String stdName) private ECParameterSpec ECSpecFromName(String stdName)
{ {
try try
@ -354,14 +353,7 @@ public class DnsKeyAlgorithm
return null; return null;
} }
// Fetch the curve parameters from a named EdDSA curve.
// For curves where we don't (or can't) get the parameters from a standard
// name, we can construct the parameters here.
private EdDSAParameterSpec EdDSASpecFromAlgorithm(int algorithm)
{
return null;
}
private EdDSAParameterSpec EdDSASpecFromName(String stdName) private EdDSAParameterSpec EdDSASpecFromName(String stdName)
{ {
try try
@ -393,6 +385,7 @@ public class DnsKeyAlgorithm
return result; return result;
} }
/** /**
* Return a Signature object for the specified DNSSEC algorithm. * Return a Signature object for the specified DNSSEC algorithm.
* @param algorithm The DNSSEC algorithm (by number). * @param algorithm The DNSSEC algorithm (by number).
@ -437,6 +430,14 @@ public class DnsKeyAlgorithm
return ec_entry.ec_spec; return ec_entry.ec_spec;
} }
/** Given one of the EdDSA algorithms (Ed25519, Ed448) return the
* elliptic curve parameters.
*
* @param algorithm
* The DNSSEC algorithm number.
* @return The stored EdDSAParameterSpec for that algorithm, or
* null if not a recognized/supported EdDSA algorithm.
*/
public EdDSAParameterSpec getEdwardsCurveParams(int algorithm) public EdDSAParameterSpec getEdwardsCurveParams(int algorithm)
{ {
AlgEntry entry = getEntry(algorithm); AlgEntry entry = getEntry(algorithm);