[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [oonib/master] Add test helper that can be used to discover the resolver being used by a probe.
commit df43691bedae4e5024aa39d6b10d47b99dc946e4
Author: Arturo Filastò <art@xxxxxxxxx>
Date: Wed Jun 25 15:43:28 2014 +0200
Add test helper that can be used to discover the resolver being used by a probe.
---
oonib.conf.example | 6 ++++++
oonib/oonibackend.py | 37 +++++++++++++++++++++++++------------
oonib/testhelpers/dns_helpers.py | 29 ++++++++++++++++++++++++++++-
3 files changed, 59 insertions(+), 13 deletions(-)
diff --git a/oonib.conf.example b/oonib.conf.example
index c25d405..6b07414 100644
--- a/oonib.conf.example
+++ b/oonib.conf.example
@@ -52,6 +52,12 @@ helpers:
tcp_port: 57005
resolver_address: '8.8.8.8:53'
+ dns_discovery:
+ address: null
+ udp_port: 53
+ tcp_port: 53
+ resolver_address: null
+
ssl:
address: null
private_key: 'private.key'
diff --git a/oonib/oonibackend.py b/oonib/oonibackend.py
index 3e6598c..2a9fa7d 100644
--- a/oonib/oonibackend.py
+++ b/oonib/oonibackend.py
@@ -10,13 +10,9 @@
from twisted.application import internet, service
from twisted.names import dns
-from cyclone import web
-
from oonib.testhelpers import dns_helpers, ssl_helpers
from oonib.testhelpers import http_helpers, tcp_helpers
-from oonib import log
-
from oonib.config import config
if config.main.uid and config.main.gid:
@@ -30,42 +26,59 @@ serviceCollection = service.IServiceCollection(application)
if config.helpers['ssl'].port:
print "Starting SSL helper on %s" % config.helpers['ssl'].port
ssl_helper = internet.SSLServer(int(config.helpers['ssl'].port),
- http_helpers.HTTPReturnJSONHeadersHelper(),
- ssl_helpers.SSLContext(config))
+ http_helpers.HTTPReturnJSONHeadersHelper(),
+ ssl_helpers.SSLContext(config))
ssl_helper.setServiceParent(serviceCollection)
# Start the DNS Server related services
if config.helpers['dns'].tcp_port:
print "Starting TCP DNS Helper on %s" % config.helpers['dns'].tcp_port
tcp_dns_helper = internet.TCPServer(int(config.helpers['dns'].tcp_port),
- dns_helpers.DNSTestHelper())
+ dns_helpers.DNSTestHelper())
tcp_dns_helper.setServiceParent(serviceCollection)
if config.helpers['dns'].udp_port:
print "Starting UDP DNS Helper on %s" % config.helpers['dns'].udp_port
udp_dns_factory = dns.DNSDatagramProtocol(dns_helpers.DNSTestHelper())
udp_dns_helper = internet.UDPServer(int(config.helpers['dns'].udp_port),
- udp_dns_factory)
+ udp_dns_factory)
udp_dns_helper.setServiceParent(serviceCollection)
+if config.helpers['dns_discovery'].udp_port:
+ print ("Starting UDP DNS Discovery Helper on %s" %
+ config.helpers['dns_discovery'].udp_port)
+ udp_dns_discovery = internet.UDPServer(int(config.helpers['dns_discovery'].udp_port),
+ dns.DNSDatagramProtocol(
+ dns_helpers.DNSResolverDiscovery()
+ ))
+ udp_dns_discovery.setServiceParent(serviceCollection)
+
+if config.helpers['dns_discovery'].tcp_port:
+ print ("Starting TCP DNS Discovery Helper on %s" %
+ config.helpers['dns_discovery'].tcp_port)
+ tcp_dns_discovery = internet.TCPServer(int(config.helpers['dns_discovery'].tcp_port),
+ dns_helpers.DNSResolverDiscovery())
+ tcp_dns_discovery.setServiceParent(serviceCollection)
+
+
# XXX this needs to be ported
# Start the OONI daphn3 backend
if config.helpers['daphn3'].port:
print "Starting Daphn3 helper on %s" % config.helpers['daphn3'].port
daphn3_helper = internet.TCPServer(int(config.helpers['daphn3'].port),
- tcp_helpers.Daphn3Server())
+ tcp_helpers.Daphn3Server())
daphn3_helper.setServiceParent(serviceCollection)
if config.helpers['tcp-echo'].port:
print "Starting TCP echo helper on %s" % config.helpers['tcp-echo'].port
tcp_echo_helper = internet.TCPServer(int(config.helpers['tcp-echo'].port),
- tcp_helpers.TCPEchoHelper())
+ tcp_helpers.TCPEchoHelper())
tcp_echo_helper.setServiceParent(serviceCollection)
if config.helpers['http-return-json-headers'].port:
print "Starting HTTP return request helper on %s" % config.helpers['http-return-json-headers'].port
http_return_request_helper = internet.TCPServer(
- int(config.helpers['http-return-json-headers'].port),
- http_helpers.HTTPReturnJSONHeadersHelper())
+ int(config.helpers['http-return-json-headers'].port),
+ http_helpers.HTTPReturnJSONHeadersHelper())
http_return_request_helper.setServiceParent(serviceCollection)
diff --git a/oonib/testhelpers/dns_helpers.py b/oonib/testhelpers/dns_helpers.py
index fbf932b..ff31dde 100644
--- a/oonib/testhelpers/dns_helpers.py
+++ b/oonib/testhelpers/dns_helpers.py
@@ -1,4 +1,4 @@
-from twisted.names import client, server
+from twisted.names import client, server, dns
from oonib.config import config
@@ -21,3 +21,30 @@ class DNSTestHelper(server.DNSServerFactory):
def handleQuery(self, message, protocol, address):
server.DNSServerFactory.handleQuery(self, message, protocol, address)
+
+
+class DNSResolverDiscovery(server.DNSServerFactory):
+ """
+ This test helper is used to discover the IP address of the resolver being
+ used by a ooniprobe client.
+ To use it you should set it up on a machine that has been delegated as the
+ authoritative name server for a specific subdomain.
+ You can do so by adding the following to your zone file:
+
+ mysubdomain IN NS ns.mysubdomain.example.org.
+ ns.mysubdomain.example.org IN A 10.42.42.42
+
+ Replace 10.42.42.42 with the IP address of the machine running oonib.
+
+ You will then be able to perform A lookups on subdomains of
+ mysubdomain.example.org and retrieve in the query answer section the IP
+ address of the resolver that was used for performing the request.
+ """
+ def handleQuery(self, message, protocol, address):
+ query = message.queries[0]
+ if query.type == dns.A:
+ ans = dns.RRHeader(bytes(query.name),
+ payload=dns.Record_A(bytes(address[0]), 0))
+ message.answers = [ans]
+ message.answer = 1
+ self.sendReply(protocol, message, address)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits