diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-11-08 10:14:34 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-11-08 10:14:34 +0100 |
commit | 1a57599da2b99f37d8d5ca611a4c4f83f7fd2e00 (patch) | |
tree | 2593e410c50f7fcaf069caf6d159662995b4624c /src/main/java/eu/siacs | |
parent | 00b3d5ee350e8b2a91817c84552ee37bfd3ecc45 (diff) |
lower case incoming dns records
Diffstat (limited to 'src/main/java/eu/siacs')
-rw-r--r-- | src/main/java/eu/siacs/conversations/utils/DNSHelper.java | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java index ac64cf2e..a8aba6db 100644 --- a/src/main/java/eu/siacs/conversations/utils/DNSHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/DNSHelper.java @@ -19,6 +19,7 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Random; import java.util.TreeMap; import java.util.Map; @@ -148,26 +149,29 @@ public class DNSHelper { for (Record[] rrset : new Record[][] { message.getAnswers(), message.getAdditionalResourceRecords() }) { for (Record rr : rrset) { Data d = rr.getPayload(); - if (d instanceof SRV && NameUtil.idnEquals(qname, rr.getName())) { + final String name = rr.getName() != null ? rr.getName().toLowerCase(Locale.US) : null; + if (d instanceof SRV && NameUtil.idnEquals(qname, name)) { SRV srv = (SRV) d; if (!priorities.containsKey(srv.getPriority())) { priorities.put(srv.getPriority(),new ArrayList<TlsSrv>()); } priorities.get(srv.getPriority()).add(new TlsSrv(srv, tls)); + } else if (d instanceof SRV) { + Log.d(Config.LOGTAG,"found unrecognized SRV record with name: "+name); } if (d instanceof A) { A a = (A) d; - if (!ips4.containsKey(rr.getName())) { - ips4.put(rr.getName(), new ArrayList<String>()); + if (!ips4.containsKey(name)) { + ips4.put(name, new ArrayList<String>()); } - ips4.get(rr.getName()).add(a.toString()); + ips4.get(name).add(a.toString()); } if (d instanceof AAAA) { AAAA aaaa = (AAAA) d; - if (!ips6.containsKey(rr.getName())) { - ips6.put(rr.getName(), new ArrayList<String>()); + if (!ips6.containsKey(name)) { + ips6.put(name, new ArrayList<String>()); } - ips6.get(rr.getName()).add("[" + aaaa.toString() + "]"); + ips6.get(name).add("[" + aaaa.toString() + "]"); } } } @@ -177,8 +181,8 @@ public class DNSHelper { Bundle bundle = new Bundle(); try { client.setTimeout(Config.SOCKET_TIMEOUT * 1000); - final String qname = "_xmpp-client._tcp." + host; - final String tlsQname = "_xmpps-client._tcp." + host; + final String qname = "_xmpp-client._tcp." + host.toLowerCase(Locale.US); + final String tlsQname = "_xmpps-client._tcp." + host.toLowerCase(Locale.US); Log.d(Config.LOGTAG, "using dns server: " + dnsServer.getHostAddress() + " to look up " + host); final Map<Integer, List<TlsSrv>> priorities = new TreeMap<>(); @@ -218,27 +222,28 @@ public class DNSHelper { } for (final TlsSrv tlsSrv : result) { final SRV srv = tlsSrv.srv; - if (ips6.containsKey(srv.getName())) { - values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips6, tlsSrv.tls)); + final String name = srv.getName() != null ? srv.getName().toLowerCase(Locale.US) : null; + if (ips6.containsKey(name)) { + values.add(createNamePortBundle(name,srv.getPort(),ips6, tlsSrv.tls)); } else { try { - DNSMessage response = client.query(srv.getName(), TYPE.AAAA, CLASS.IN, dnsServer.getHostAddress()); + DNSMessage response = client.query(name, TYPE.AAAA, CLASS.IN, dnsServer.getHostAddress()); for (int i = 0; i < response.getAnswers().length; ++i) { - values.add(createNamePortBundle(srv.getName(), srv.getPort(), response.getAnswers()[i].getPayload(), tlsSrv.tls)); + values.add(createNamePortBundle(name, srv.getPort(), response.getAnswers()[i].getPayload(), tlsSrv.tls)); } } catch (SocketTimeoutException e) { Log.d(Config.LOGTAG,"ignoring timeout exception when querying AAAA record on "+dnsServer.getHostAddress()); } } - if (ips4.containsKey(srv.getName())) { - values.add(createNamePortBundle(srv.getName(),srv.getPort(),ips4, tlsSrv.tls)); + if (ips4.containsKey(name)) { + values.add(createNamePortBundle(name,srv.getPort(),ips4, tlsSrv.tls)); } else { - DNSMessage response = client.query(srv.getName(), TYPE.A, CLASS.IN, dnsServer.getHostAddress()); + DNSMessage response = client.query(name, TYPE.A, CLASS.IN, dnsServer.getHostAddress()); for(int i = 0; i < response.getAnswers().length; ++i) { - values.add(createNamePortBundle(srv.getName(),srv.getPort(),response.getAnswers()[i].getPayload(), tlsSrv.tls)); + values.add(createNamePortBundle(name,srv.getPort(),response.getAnswers()[i].getPayload(), tlsSrv.tls)); } } - values.add(createNamePortBundle(srv.getName(), srv.getPort(), tlsSrv.tls)); + values.add(createNamePortBundle(name, srv.getPort(), tlsSrv.tls)); } bundle.putParcelableArrayList("values", values); } catch (SocketTimeoutException e) { |