Some UI fixes for Https server

This commit is contained in:
PeratX 2018-06-22 01:51:35 +08:00
parent fdd28b6b6d
commit c4d53d6c77
6 changed files with 43 additions and 36 deletions

View File

@ -121,7 +121,7 @@ public class DNSServersFragment extends ToolbarFragment {
CustomDNSServer server = Daedalus.configurations.getCustomDNSServers().get(position);
holder.setIndex(position);
holder.textViewName.setText(server.getName());
holder.textViewAddress.setText(server.getAddress() + ":" + server.getPort());
holder.textViewAddress.setText(server.getRealName());
}
@Override

View File

@ -153,38 +153,41 @@ public class DNSTestFragment extends ToolbarFragment {
private StringBuilder testServer(DnsQuery dnsQuery, Record.TYPE type, AbstractDNSServer server, String domain, StringBuilder testText) {
Logger.debug("Testing DNS server " + server.getAddress() + ":" + server.getPort());
testText.append(getString(R.string.test_domain)).append(" ").append(domain).append("\n").append(getString(R.string.test_dns_server)).append(" ").append(server.getAddress()).append(":").append(server.getPort());
Logger.debug("Testing DNS server " + server.getRealName());
testText.append(getString(R.string.test_domain)).append(" ").append(domain).append("\n")
.append(getString(R.string.test_dns_server)).append(" ").append(server.getRealName());
mHandler.obtainMessage(DnsTestHandler.MSG_DISPLAY_STATUS, testText.toString()).sendToTarget();
boolean succ = false;
try {
DnsMessage.Builder message = DnsMessage.builder()
.addQuestion(new Question(domain, type))
.setId((new Random()).nextInt())
.setRecursionDesired(true)
.setOpcode(DnsMessage.OPCODE.QUERY)
.setResponseCode(DnsMessage.RESPONSE_CODE.NO_ERROR)
.setQrFlag(false);
if (!server.isHttpsServer()) {//TODO: DoH Server Test
try {
DnsMessage.Builder message = DnsMessage.builder()
.addQuestion(new Question(domain, type))
.setId((new Random()).nextInt())
.setRecursionDesired(true)
.setOpcode(DnsMessage.OPCODE.QUERY)
.setResponseCode(DnsMessage.RESPONSE_CODE.NO_ERROR)
.setQrFlag(false);
long startTime = System.currentTimeMillis();
DnsMessage response = dnsQuery.query(message.build(), InetAddress.getByName(server.getAddress()), server.getPort());
long endTime = System.currentTimeMillis();
long startTime = System.currentTimeMillis();
DnsMessage response = dnsQuery.query(message.build(), InetAddress.getByName(server.getAddress()), server.getPort());
long endTime = System.currentTimeMillis();
if (response.answerSection.size() > 0) {
for (Record record : response.answerSection) {
if (record.getPayload().getType() == type) {
testText.append("\n").append(getString(R.string.test_result_resolved)).append(" ").append(record.getPayload().toString());
if (response.answerSection.size() > 0) {
for (Record record : response.answerSection) {
if (record.getPayload().getType() == type) {
testText.append("\n").append(getString(R.string.test_result_resolved)).append(" ").append(record.getPayload().toString());
}
}
testText.append("\n").append(getString(R.string.test_time_used)).append(" ").
append(String.valueOf(endTime - startTime)).append(" ms");
succ = true;
}
testText.append("\n").append(getString(R.string.test_time_used)).append(" ").
append(String.valueOf(endTime - startTime)).append(" ms");
succ = true;
} catch (SocketTimeoutException ignored) {
} catch (Exception e) {
Logger.logException(e);
}
} catch (SocketTimeoutException ignored){
} catch (Exception e) {
Logger.logException(e);
}
if (!succ){

View File

@ -48,10 +48,12 @@ public class HttpsIetfProvider extends HttpsProvider {
whqList.add(new WaitingHttpsRequest(parsedPacket) {
@Override
public void doRequest() {
final int id = message.id;
final byte[] rawRequest = message.toArray();
Request request = new Request.Builder()
.url(HttpUrl.parse(HTTPS_SUFFIX + uri).newBuilder()
.addQueryParameter("dns", Base64.encodeToString(rawRequest, Base64.DEFAULT))
.addQueryParameter("dns", Base64.encodeToString(
message.asBuilder().setId(0).build().toArray(), Base64.DEFAULT))
.build())
.get()
.build();
@ -65,7 +67,8 @@ public class HttpsIetfProvider extends HttpsProvider {
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
result = response.body().bytes();
result = new DnsMessage(response.body().bytes()).asBuilder()
.setId(id).build().toArray();
completed = true;
}
}

View File

@ -128,7 +128,7 @@ public class HttpsJsonProvider extends HttpsProvider {
}
}
}
result = msg.build().toArray();
result = msg.setQrFlag(true).build().toArray();
completed = true;
}
}

View File

@ -77,18 +77,16 @@ abstract public class HttpsProvider extends Provider {
return;
}
boolean writeToDevice = false;
Iterator<WaitingHttpsRequest> iterator = whqList.iterator();
while (iterator.hasNext()) {
WaitingHttpsRequest request = iterator.next();
if (request.completed) {
writeToDevice = true;
handleDnsResponse(request.packet, request.result);
iterator.remove();
}
}
if (writeToDevice) {
if ((deviceFd.revents & OsConstants.POLLOUT) != 0) {
Log.d(TAG, "Write to device");
writeToDevice(outputStream);
}
@ -149,7 +147,7 @@ abstract public class HttpsProvider extends Provider {
}
if (!resolve(parsedPacket, dnsMsg) && uri != null) {
sendRequestToServer(parsedPacket, dnsMsg.asBuilder().setId(0).build(), uri);
sendRequestToServer(parsedPacket, dnsMsg, uri);
//SHOULD use a DNS ID of 0 in every DNS request (according to draft-ietf-doh-dns-over-https-11)
}
}
@ -181,10 +179,5 @@ abstract public class HttpsProvider extends Provider {
public Iterator<WaitingHttpsRequest> iterator() {
return list.iterator();
}
int size() {
return list.size();
}
}
}

View File

@ -46,4 +46,12 @@ public class AbstractDNSServer {
public String toString() {
return getName();
}
public String getRealName() {
return isHttpsServer() ? address : address + ":" + port;
}
public boolean isHttpsServer() {
return address.contains("/");
}
}