use of org.xbill.DNS.Name in project ecf by eclipse.
the class DnsSdDiscoveryContainerAdapter method isFinal.
private boolean isFinal(PTRRecord record) {
Name name = record.getName();
Name target = record.getTarget();
return name.subdomain(target);
}
use of org.xbill.DNS.Name in project ecf by eclipse.
the class DnsSdDiscoveryLocator method getServiceInfos.
private List getServiceInfos(Collection srvQueryResult) {
List infos = new ArrayList();
for (Iterator iterator = srvQueryResult.iterator(); iterator.hasNext(); ) {
SRVRecord srvRecord = (SRVRecord) iterator.next();
long ttl = srvRecord.getTTL();
int priority = srvRecord.getPriority();
int weight = srvRecord.getWeight();
int port = srvRecord.getPort();
Name target = srvRecord.getTarget();
String host = target.toString();
host = host.substring(0, host.length() - 1);
IServiceTypeID aServiceTypeID = new DnsSdServiceTypeID(getConnectNamespace(), srvRecord.getName());
// query for txt records (attributes)
Properties props = new Properties();
Lookup txtQuery = new Lookup(srvRecord.getName(), Type.TXT);
txtQuery.setResolver(resolver);
Record[] txtQueryResults = txtQuery.run();
int length = txtQueryResults == null ? 0 : txtQueryResults.length;
for (int l = 0; l < length; l++) {
TXTRecord txtResult = (TXTRecord) txtQueryResults[l];
List strings = txtResult.getStrings();
for (Iterator itr = strings.iterator(); itr.hasNext(); ) {
String str = (String) itr.next();
// $NON-NLS-1$
String[] split = str.split("=");
props.put(split[0], split[1]);
}
}
String path = props.getProperty(DNS_SD_PATH);
String proto = props.getProperty(DNS_SD_PTCL) == null ? aServiceTypeID.getProtocols()[0] : props.getProperty(DNS_SD_PTCL);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
URI uri = URI.create(proto + "://" + host + ":" + port + (path == null ? "" : path));
IServiceInfo info = new ServiceInfo(uri, host, aServiceTypeID, priority, weight, new ServiceProperties(props), ttl);
infos.add(info);
}
return infos;
}
use of org.xbill.DNS.Name in project dim by 1and1.
the class DNSJavaNameService method lookupAllHostAddr.
/**
* Performs a forward DNS lookup for the host name.
* @param host The host name to resolve.
* @return All the ip addresses found for the host name.
*/
public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException {
Name name = null;
try {
name = new Name(host);
} catch (TextParseException e) {
throw new UnknownHostException(host);
}
Record[] records = null;
if (preferV6)
records = new Lookup(name, Type.AAAA).run();
if (records == null)
records = new Lookup(name, Type.A).run();
if (records == null && !preferV6)
records = new Lookup(name, Type.AAAA).run();
if (records == null)
throw new UnknownHostException(host);
InetAddress[] array = new InetAddress[records.length];
for (int i = 0; i < records.length; i++) {
Record record = records[i];
if (records[i] instanceof ARecord) {
ARecord a = (ARecord) records[i];
array[i] = a.getAddress();
} else {
AAAARecord aaaa = (AAAARecord) records[i];
array[i] = aaaa.getAddress();
}
}
return array;
}
use of org.xbill.DNS.Name in project dim by 1and1.
the class DNSJavaNameService method getHostByAddr.
/**
* Performs a reverse DNS lookup.
* @param addr The ip address to lookup.
* @return The host name found for the ip address.
*/
public String getHostByAddr(byte[] addr) throws UnknownHostException {
Name name = ReverseMap.fromAddress(InetAddress.getByAddress(addr));
Record[] records = new Lookup(name, Type.PTR).run();
if (records == null)
throw new UnknownHostException();
return ((PTRRecord) records[0]).getTarget().toString();
}
use of org.xbill.DNS.Name in project dim by 1and1.
the class SignZone method execute.
public void execute() throws Exception {
// Read in the zone
List<Record> records = ZoneUtils.readZoneFile(state.zonefile, null);
if (records == null || records.size() == 0) {
System.err.println("error: empty zone file");
state.usage();
}
// calculate the zone name.
Name zonename = ZoneUtils.findZoneName(records);
if (zonename == null) {
System.err.println("error: invalid zone file - no SOA");
state.usage();
}
// Load the key pairs.
List<DnsKeyPair> keypairs = getKeys(state.keyFiles, 0, state.keyDirectory);
List<DnsKeyPair> kskpairs = getKeys(state.kskFiles, 0, state.keyDirectory);
// any public keys.
if (keypairs == null && kskpairs == null) {
List<Record> dnskeys = ZoneUtils.findRRs(records, zonename, Type.DNSKEY);
keypairs = getKeys(dnskeys, state.keyDirectory);
}
// that match
if (keypairs == null && kskpairs == null) {
keypairs = findZoneKeys(state.keyDirectory, zonename);
}
// are actually ksks by looking at the SEP flag.
if ((kskpairs == null || kskpairs.size() == 0) && keypairs != null && keypairs.size() > 1) {
for (Iterator<DnsKeyPair> i = keypairs.iterator(); i.hasNext(); ) {
DnsKeyPair pair = i.next();
DNSKEYRecord kr = pair.getDNSKEYRecord();
if ((kr.getFlags() & DNSKEYRecord.Flags.SEP_KEY) != 0) {
if (kskpairs == null)
kskpairs = new ArrayList<DnsKeyPair>();
kskpairs.add(pair);
i.remove();
}
}
}
// provided), all KSKs will be treated as ZSKs, as well.
if (keypairs == null || keypairs.size() == 0) {
keypairs = kskpairs;
}
// If there *still* aren't any ZSKs defined, bail.
if (keypairs == null || keypairs.size() == 0) {
System.err.println("No zone signing keys could be determined.");
state.usage();
}
// default the output file, if not set.
if (state.outputfile == null && !state.zonefile.equals("-")) {
if (zonename.isAbsolute()) {
state.outputfile = zonename + "signed";
} else {
state.outputfile = zonename + ".signed";
}
}
// Verify that the keys can be in the zone.
if (!keyPairsValidForZone(zonename, keypairs) || !keyPairsValidForZone(zonename, kskpairs)) {
System.err.println("error: specified keypairs are not valid for the zone.");
state.usage();
}
// removes duplicate records.
if (kskpairs != null) {
for (DnsKeyPair pair : kskpairs) {
records.add(pair.getDNSKEYRecord());
}
}
if (keypairs != null) {
for (DnsKeyPair pair : keypairs) {
records.add(pair.getDNSKEYRecord());
}
}
// read in the keysets, if any.
List<Record> keysetrecs = getKeysets(state.keysetDirectory, zonename);
if (keysetrecs != null) {
records.addAll(keysetrecs);
}
DnsSecSigner signer;
if (state.parallel)
signer = new JCEDnsSecParallelSigner(state.verboseSigning);
else
signer = new JCEDnsSecSigner(state.verboseSigning);
// Sign the zone.
List<Record> signed_records;
if (state.useNsec3) {
signed_records = signer.signZoneNSEC3(zonename, records, kskpairs, keypairs, state.start, state.expire, state.fullySignKeyset, state.useOptOut, state.includeNames, state.salt, state.iterations, state.digest_id, state.nsec3paramttl);
} else {
signed_records = signer.signZone(zonename, records, kskpairs, keypairs, state.start, state.expire, state.fullySignKeyset, state.digest_id);
}
// write out the signed zone
ZoneUtils.writeZoneFile(signed_records, state.outputfile);
if (state.verifySigs) {
// FIXME: ugh.
if (kskpairs != null) {
keypairs.addAll(kskpairs);
}
log.fine("verifying generated signatures");
boolean res = verifyZoneSigs(zonename, signed_records, keypairs);
if (res) {
System.out.println("Generated signatures verified");
// log.info("Generated signatures verified");
} else {
System.out.println("Generated signatures did not verify.");
// log.warn("Generated signatures did not verify.");
}
}
}
Aggregations