Search in sources :

Example 81 with Name

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);
}
Also used : Name(org.xbill.DNS.Name)

Example 82 with Name

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;
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) URI(java.net.URI) Name(org.xbill.DNS.Name) IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) ServiceInfo(org.eclipse.ecf.discovery.ServiceInfo) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) TXTRecord(org.xbill.DNS.TXTRecord) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Lookup(org.xbill.DNS.Lookup) PTRRecord(org.xbill.DNS.PTRRecord) Record(org.xbill.DNS.Record) SRVRecord(org.xbill.DNS.SRVRecord) TXTRecord(org.xbill.DNS.TXTRecord) SRVRecord(org.xbill.DNS.SRVRecord)

Example 83 with Name

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;
}
Also used : ARecord(org.xbill.DNS.ARecord) AAAARecord(org.xbill.DNS.AAAARecord) AAAARecord(org.xbill.DNS.AAAARecord) UnknownHostException(java.net.UnknownHostException) ARecord(org.xbill.DNS.ARecord) PTRRecord(org.xbill.DNS.PTRRecord) AAAARecord(org.xbill.DNS.AAAARecord) Record(org.xbill.DNS.Record) Lookup(org.xbill.DNS.Lookup) InetAddress(java.net.InetAddress) Name(org.xbill.DNS.Name) TextParseException(org.xbill.DNS.TextParseException)

Example 84 with Name

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();
}
Also used : UnknownHostException(java.net.UnknownHostException) ARecord(org.xbill.DNS.ARecord) PTRRecord(org.xbill.DNS.PTRRecord) AAAARecord(org.xbill.DNS.AAAARecord) Record(org.xbill.DNS.Record) Lookup(org.xbill.DNS.Lookup) Name(org.xbill.DNS.Name)

Example 85 with Name

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.");
        }
    }
}
Also used : DNSKEYRecord(org.xbill.DNS.DNSKEYRecord) ArrayList(java.util.ArrayList) DSRecord(org.xbill.DNS.DSRecord) Record(org.xbill.DNS.Record) DNSKEYRecord(org.xbill.DNS.DNSKEYRecord) JCEDnsSecSigner(com.verisignlabs.dnssec.security.JCEDnsSecSigner) DnsKeyPair(com.verisignlabs.dnssec.security.DnsKeyPair) JCEDnsSecParallelSigner(com.verisignlabs.dnssec.security.JCEDnsSecParallelSigner) DnsSecSigner(com.verisignlabs.dnssec.security.DnsSecSigner) JCEDnsSecSigner(com.verisignlabs.dnssec.security.JCEDnsSecSigner) Name(org.xbill.DNS.Name)

Aggregations

Name (org.xbill.DNS.Name)101 Record (org.xbill.DNS.Record)36 Message (org.xbill.DNS.Message)18 SRVRecord (org.xbill.DNS.SRVRecord)18 IOException (java.io.IOException)11 UnknownHostException (java.net.UnknownHostException)11 ArrayList (java.util.ArrayList)11 Lookup (org.xbill.DNS.Lookup)10 ARecord (org.xbill.DNS.ARecord)9 ExtendedResolver (org.xbill.DNS.ExtendedResolver)9 SimpleResolver (org.xbill.DNS.SimpleResolver)9 RRset (org.xbill.DNS.RRset)8 NSRecord (org.xbill.DNS.NSRecord)7 TXTRecord (org.xbill.DNS.TXTRecord)7 HashSet (java.util.HashSet)6 Iterator (java.util.Iterator)6 CNAMERecord (org.xbill.DNS.CNAMERecord)6 TextParseException (org.xbill.DNS.TextParseException)6 Update (org.xbill.DNS.Update)6 ZoneTransferIn (org.xbill.DNS.ZoneTransferIn)6