本文整理汇总了Java中org.xbill.DNS.DNSSEC.Algorithm类的典型用法代码示例。如果您正苦于以下问题:Java Algorithm类的具体用法?Java Algorithm怎么用?Java Algorithm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Algorithm类属于org.xbill.DNS.DNSSEC包,在下文中一共展示了Algorithm类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSIG0
import org.xbill.DNS.DNSSEC.Algorithm; //导入依赖的package包/类
public void testSIG0() throws Exception {
Name sig0zoneName = new Name("sig0.invalid.");
Name sig0hostName = new Name("sometext.sig0.invalid.");
KeyPairGenerator rsagen = KeyPairGenerator.getInstance("RSA");
KeyPair rsapair = rsagen.generateKeyPair();
PrivateKey privKey = rsapair.getPrivate();
PublicKey pubKey = rsapair.getPublic();
KEYRecord keyRecord = new KEYRecord(sig0zoneName, DClass.IN,
0, KEYRecord.Flags.HOST,
KEYRecord.Protocol.DNSSEC,
DNSSEC.Algorithm.RSASHA1,
pubKey);
TXTRecord txtRecord = new TXTRecord(sig0hostName, DClass.IN, 0, "Hello World!");
Update updateMessage = new Update(sig0zoneName);
updateMessage.add(txtRecord);
SIG0.signMessage(updateMessage, keyRecord, privKey, null);
Message message = new Message(updateMessage.toWire());
SIG0.verifyMessage(message, message.toWire(), keyRecord, null);
}
示例2: isAlgorithmSupported
import org.xbill.DNS.DNSSEC.Algorithm; //导入依赖的package包/类
/**
* Determines if the algorithm is supported.
*
* @param alg The algorithm to check.
* @return True when the algorithm is supported, false otherwise.
*/
static boolean isAlgorithmSupported(int alg) {
switch (alg) {
case Algorithm.RSAMD5:
return false; // obsoleted by rfc6944
case Algorithm.DSA:
case Algorithm.DSA_NSEC3_SHA1:
case Algorithm.RSASHA1:
case Algorithm.RSA_NSEC3_SHA1:
case Algorithm.RSASHA256:
case Algorithm.RSASHA512:
case Algorithm.ECDSAP256SHA256:
case Algorithm.ECDSAP384SHA384:
return true;
default:
return false;
}
}
示例3: testModifiedSignature
import org.xbill.DNS.DNSSEC.Algorithm; //导入依赖的package包/类
@Test
public void testModifiedSignature() throws IOException {
Name query = Name.fromString("www.ingotronic.ch.");
// prepare a faked, unsigned response message that must have a signature
// to be valid
Message message = new Message();
message.addRecord(Record.newRecord(query, Type.A, DClass.IN), Section.QUESTION);
message.addRecord(new ARecord(query, Type.A, DClass.IN, InetAddress.getByName(localhost)), Section.ANSWER);
message.addRecord(new RRSIGRecord(query, DClass.IN, 0, Type.A, Algorithm.RSASHA256, 5, new Date(System.currentTimeMillis() + 5000), new Date(System.currentTimeMillis() - 5000), 1234, Name.fromString("ingotronic.ch."), new byte[] { 1, 2, 3 }), Section.ANSWER);
add("www.ingotronic.ch./A", message);
Message response = resolver.send(createMessage("www.ingotronic.ch./A"));
assertFalse("AD flag must not be set", response.getHeader().getFlag(Flags.AD));
assertEquals(Rcode.SERVFAIL, response.getRcode());
assertTrue(getReason(response).startsWith("failed.answer.positive:{ www.ingotronic.ch."));
}
示例4: testFavoriteDigestNotInRRset
import org.xbill.DNS.DNSSEC.Algorithm; //导入依赖的package包/类
@AlwaysOffline
@Test
public void testFavoriteDigestNotInRRset() throws Exception {
Properties config = new Properties();
config.put("org.jitsi.dnssec.digest_preference", "4");
ValUtils v = new ValUtils();
v.init(config);
SRRset set = new SRRset();
set.addRR(new DSRecord(Name.root, DClass.IN, 120, 1234, Algorithm.DSA, Digest.SHA1, new byte[] { 1, 2, 3 }));
set.addRR(new DSRecord(Name.root, DClass.IN, 120, 1234, Algorithm.DSA, Digest.SHA256, new byte[] { 1, 2, 3 }));
int digestId = Whitebox.invokeMethod(v, "favoriteDSDigestID", set);
assertEquals(0, digestId);
}
示例5: testOnlyUnsupportedDigestInRRset
import org.xbill.DNS.DNSSEC.Algorithm; //导入依赖的package包/类
@AlwaysOffline
@Test
public void testOnlyUnsupportedDigestInRRset() throws Exception {
ValUtils v = new ValUtils();
SRRset set = new SRRset();
set.addRR(new DSRecord(Name.root, DClass.IN, 120, 1234, Algorithm.DSA, 3 /*GOST*/, new byte[] { 1, 2, 3 }));
int digestId = Whitebox.invokeMethod(v, "favoriteDSDigestID", set);
assertEquals(0, digestId);
}
示例6: validIterations
import org.xbill.DNS.DNSSEC.Algorithm; //导入依赖的package包/类
private boolean validIterations(SRRset nsec, KeyCache keyCache) {
SRRset dnskeyRrset = keyCache.find(nsec.getSignerName(), nsec.getDClass()).getRRset();
// for now, we return the maximum iterations based simply on the key
// algorithms that may have been used to sign the NSEC3 RRsets.
try {
for (Iterator<?> i = dnskeyRrset.rrs(); i.hasNext();) {
DNSKEYRecord dnskey = (DNSKEYRecord)i.next();
int keysize;
switch (dnskey.getAlgorithm()) {
case Algorithm.RSAMD5:
return false; // obsoleted by rfc6944
case Algorithm.RSASHA1:
case Algorithm.RSASHA256:
case Algorithm.RSASHA512:
case Algorithm.RSA_NSEC3_SHA1:
keysize = ((RSAPublicKey)dnskey.getPublicKey()).getModulus().bitLength();
break;
case Algorithm.DSA:
case Algorithm.DSA_NSEC3_SHA1:
keysize = ((DSAPublicKey)dnskey.getPublicKey()).getParams().getP().bitLength();
break;
case Algorithm.ECDSAP256SHA256:
case Algorithm.ECDSAP384SHA384:
keysize = ((ECPublicKey)dnskey.getPublicKey()).getParams().getCurve().getField().getFieldSize();
break;
default:
return false;
}
Integer keyIters = this.maxIterations.floorKey(keysize);
if (keyIters == null) {
keyIters = this.maxIterations.firstKey();
}
keyIters = this.maxIterations.get(keyIters);
if (((NSEC3Record)nsec.first()).getIterations() > keyIters) {
return false;
}
}
return true;
}
catch (DNSSECException e) {
logger.error("Could not get public key from NSEC3 record", e);
return false;
}
}
示例7: RplParser
import org.xbill.DNS.DNSSEC.Algorithm; //导入依赖的package包/类
public RplParser(InputStream data) {
this.data = data;
for (Field f : Algorithm.class.getFields()) {
this.algoStrings.add(f.getName());
}
}
示例8: parseRecord
import org.xbill.DNS.DNSSEC.Algorithm; //导入依赖的package包/类
private Record parseRecord(String line) throws IOException {
try {
Master ma = new Master(new ByteArrayInputStream(line.getBytes()), null, 3600);
Record r = ma.nextRecord();
if (r.getType() == Type.RRSIG) {
RRSIGRecord rr = (RRSIGRecord)r;
// unbound directly uses the DER format for DSA signatures
// instead of the format specified in rfc2536#section-3
if (rr.getAlgorithm() == Algorithm.DSA && rr.getSignature().length > 41) {
Method DSASignaturetoDNS = DNSSEC.class.getDeclaredMethod("DSASignaturetoDNS", byte[].class, int.class);
DSASignaturetoDNS.setAccessible(true);
byte[] signature = (byte[])DSASignaturetoDNS.invoke(null, rr.getSignature(), 0);
RRSIGRecord fixed = new RRSIGRecord(rr.getName(), rr.getDClass(), rr.getTTL(), rr.getTypeCovered(), rr.getAlgorithm(), rr.getOrigTTL(),
rr.getExpire(), rr.getTimeSigned(), rr.getFootprint(), rr.getSigner(), signature);
Field f = getField(RRSIGRecord.class, "labels");
f.setAccessible(true);
f.set(fixed, rr.getLabels());
r = fixed;
}
}
return r;
}
catch (Exception ex) {
if (ex.getMessage() != null && ex.getMessage().contains("expected an integer")) {
String[] data = line.split("\\s");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.length; i++) {
if (this.algoStrings.contains(data[i])) {
sb.append(Algorithm.value(data[i]));
}
else {
sb.append(data[i]);
}
sb.append(' ');
}
return parseRecord(sb.toString());
}
else {
throw new IOException(line, ex);
}
}
}