mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-24 01:32:17 -05:00
lower case incoming dns records
This commit is contained in:
parent
00b3d5ee35
commit
1a57599da2
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user