aiodnsprox package¶
Subpackages¶
aiodnsprox.coap module¶
DNS over CoAP serving side of the proxy.
- class aiodnsprox.coap.DNSOverCoAPServerFactory(dns_upstream: DNSUpstream)[source]¶
Bases:
BaseServerFactoryFactory to create DNS over CoAP servers
- class ClosableContext(loop=None, serversite=None, loggername='coap', client_credentials=None, server_credentials=None)[source]¶
Bases:
Context,BaseDNSServeraiocoap.Contextthat also serves as an extension ofdns_server.BaseDNSServerso it can be returned byDNSOverCoAPServerFactory.create_server()
- class DNSQueryResource(factory)[source]¶
Bases:
ResourceThe DNS over CoAP resource of the DNS over CoAP server.
- Parameters:
factory (
DNSOverCoAPServerFactory) – The factory that created the DNS over CoAP server.
- async render_fetch(request)[source]¶
aiocoap.resource.Resourcemethod to serve a FETCH request- Parameters:
request – The FETCH request
- Returns:
The response for the FETCH request.
- async create_server(loop, *args, local_addr=None, **kwargs)[source]¶
Creates an
aiocoapserver context.- Parameters:
loop (
asyncio.AbstractEventLoop) – the asyncio event loop the server should run inlocal_addr (
typing.Tuple[str, int]) – A tuple for the created server to bind to. The first element is the host part, the second element the port.
- Returns:
An
ClosableContextobject representing anaiocoapserver context.- Return type:
aiodnsprox.config module¶
Proxy configuration
- class aiodnsprox.config.Config(*args, **kwargs)[source]¶
Bases:
objectSingleton Config mapping class to represent both config file and CLI argument congfiguration.
- add_args_config(args) NoReturn[source]¶
Adds configuration from CLI arguments
- Parameters:
args (
argparse.Namespace) – parsed CLI arguments.
- add_config(config: Mapping) NoReturn[source]¶
Adds configuration from a mapping
- Parameters:
config (
typing.Mapping.) – A mapping that contains the new configuration sections.
aiodnsprox.dns_server module¶
Base definitions for the serving side of the DNS proxy
- class aiodnsprox.dns_server.BaseServerFactory(dns_upstream: DNSUpstream)[source]¶
Bases:
ABCAbstract
BaseDNSServerfactory.- Parameters:
dns_upstream – The proxied DNS server for
dns_upstream.DNSUpstreamServerMixin.
- abstract async create_server(loop: AbstractEventLoop, *args, local_addr: Tuple[str, int] | None = None, **kwargs) BaseDNSServer[source]¶
Creates a
BaseDNSServerobject.- Parameters:
loop (
asyncio.AbstractEventLoop) – the asyncio event loop the server should run inlocal_addr (
typing.Tuple[str, int]) – A tuple for the created server to bind to. The first element is the host part, the second element the port. Iflocal_addrisNoneor any of its elements arelocal_addrareNone, a sensible default is selected by the implementation.
- Returns:
An object based on the
BaseDNSServerclass.- Return type:
aiodnsprox.dns_upstream module¶
Implementation of the proxying side of the DNS proxy.
- class aiodnsprox.dns_upstream.DNSTransport(value)[source]¶
Bases:
EnumType to identify the server proxied via
DNSUpstream.TCPfor DNS over TCPUDPfor DNS over UDPUDP_TCP_FALLBACKfor DNS over UDP with a fallback to DNS over TCP in case the DNS over UDP response is truncated
- TCP = 2¶
- UDP = 0¶
- UDP_TCP_FALLBACK = 1¶
- class aiodnsprox.dns_upstream.DNSUpstream(host: str, port: int | None = None, transport: DNSTransport | None = DNSTransport.UDP)[source]¶
Bases:
objectImplementation of the DNS client towards the proxied DNS server
- Parameters:
host (str) – Host of the proxied DNS server
port (int) – (Optional) port of the proxied DNS server. If no port is provided, the default of the selected
transportwill be used (e.g. 53 forDNSTransport.TCPorDNSTransport.UDP).transport (DNSTransport) – (Optional) transport used to communicate with the proxied DNS server. If no transport is provided,
DNSTransport.UDPwill be used.
- DEFAULT_LIFETIME = 5.0¶
- DEFAULT_TIMEOUT = 2.0¶
- property port¶
Port of the proxied DNS server
- Type:
int
- async query(query: bytes, timeout: float | None = None) bytes[source]¶
Query proxied DNS server.
- Parameters:
query (bytes) – DNS query in the on-the-wire format
timeout (float) – (Optional) timeout for the DNS query operation. If not provided and the transport to the server is
DNSTransport.UDP,DNSUpstream.DEFAULT_LIFETIMEwill be used.
- class aiodnsprox.dns_upstream.DNSUpstreamServerMixin(dns_upstream: DNSUpstream, timeout: float | None = None)[source]¶
Bases:
ABCMixin for the serving side of the proxy for easy access towards the proxied side.
- Parameters:
dns_upstream (
DNSUpstream) – The proxied DNS server.timeout (float) – (Optional) timeout for queries towards
dns_upstream.
- dns_query_received(query: bytes, requester) NoReturn[source]¶
The serving end of the proxy notifies that it received a DNS query and sends it to the proxied DNS server. When a response is received asynchronously,
send_response_to_requester()is called to notify the serving end about the received response.- Parameters:
query (bytes) – The DNS query in on-the-wire format to send to the proxied DNS server.
requester – Identifier for the endpoint that originally requested the query.
- logger = <Logger aiodnsprox.dns_upstream.aiodnsprox.dns_upstream (WARNING)>¶
- abstract send_response_to_requester(response: bytes, requester) NoReturn[source]¶
Called when proxied DNS server responded to a DNS query send by
dns_query_received().- Parameters:
response – The DNS response in on-the-wire format received from the proxied DNS server.
requester – Identifier for the endpoint that originally requested the query. This will have the same value as the
requesterparameter ofdns_query_received()for thequerythatresponseis the response to.
- class aiodnsprox.dns_upstream.MockDNSUpstream(*args, IN=None, **kwargs)[source]¶
Bases:
DNSUpstreamMocks an upstream by statically responding with a preconfigured set of records.
- Parameters:
IN (dict) – Records for the RDATA class IN. A mapping that maps the name of the record to its data. Currently supported are
AandAAAArecords.
- async query(query: bytes, timeout: float | None = None) bytes[source]¶
Query proxied DNS server.
- Parameters:
query (bytes) – DNS query in the on-the-wire format
timeout (float) – (Optional) timeout for the DNS query operation. If not provided and the transport to the server is
DNSTransport.UDP,DNSUpstream.DEFAULT_LIFETIMEwill be used.
aiodnsprox.dtls module¶
DNS over DTLS serving side of the proxy.
- class aiodnsprox.dtls.BaseDTLSWrapper(transport: DatagramTransport)[source]¶
Bases:
ABCAn abstract wrapper for a DTLS implementation
- Parameters:
transport (
asyncio.DatagramTransport) – The datagram transport the datagrams should be encrypted and decrypted for.
- abstract close(addr: Any) NoReturn[source]¶
Closes a session with
addr.- Parameters:
addr – An (implementation-specific) remote endpoint
- abstract connect(addr: Any) NoReturn[source]¶
Establish a session with
addr.- Parameters:
addr – An (implementation-specific) remote endpoint
- abstract handle_message(msg: bytes, addr: Any) Tuple[bytes, Any, bool][source]¶
Handles a DTLS message that came over the datagram transport.
- Parameters:
msg (bytes) – An incoming DTLS message.
addr – The remote endpoint as served by the datagram transport.
- Returns:
A 3-tuple, containing
The unencrypted message,
The (implementation-specific) remote endpoint the message was received from, an
A boolean, indicating if the last message established a session with the remote endpoint.
If
msgwas a control message, the first and second elements will beNone.
- abstract is_connected(addr: Any) bool[source]¶
Check if a session with
addrwas established.- Parameters:
addr – A remote endpoint (implementation-specific)
- Returns:
True, when a session withaddris established,Falseif not.
- class aiodnsprox.dtls.DNSOverDTLSServerFactory(dns_upstream: DNSUpstream)[source]¶
Bases:
BaseServerFactoryFactory to create DNS over DLTS servers
- class DNSOverDTLSServer(factory)[source]¶
Bases:
BaseDNSServer,DNSUpstreamServerMixinDNS over DTLS server implementation.
- Parameters:
factory (
DNSOverDTLSServerFactory) – The factory that created the DNS over DTLS server.
- error_received(exc)[source]¶
See error_received()
- send_response_to_requester(response, requester)[source]¶
Called when proxied DNS server responded to a DNS query send by
dns_query_received().- Parameters:
response – The DNS response in on-the-wire format received from the proxied DNS server.
requester – Identifier for the endpoint that originally requested the query. This will have the same value as the
requesterparameter ofdns_query_received()for thequerythatresponseis the response to.
- DODTLS_PORT = 853¶
- async create_server(loop, *args, local_addr=None, **kwargs)[source]¶
Creates an
DNSOverDTLSServerobject.- Parameters:
loop (
asyncio.AbstractEventLoop) – the asyncio event loop the server should run inlocal_addr (
typing.Tuple[str, int]) – A tuple for the created server to bind to. The first element is the host part, the second element the port.
- Returns:
An
DNSOverDTLSServerobject representing an DNS over DTLS server.- Return type:
- dtls_class¶
alias of
TinyDTLSWrapper
- class aiodnsprox.dtls.TinyDTLSWrapper(transport)[source]¶
Bases:
BaseDTLSWrapperA wrapper for tinydtls.
- EVENT_CONNECTED = 478¶
- LOG_LEVEL = {10: 6, 20: 5, 30: 3, 40: 2, 50: 0}¶
- close(addr)[source]¶
Closes a session with
addr.- Parameters:
addr – An (implementation-specific) remote endpoint
- connect(addr)[source]¶
Establish a session with
addr.- Parameters:
addr – An (implementation-specific) remote endpoint
- handle_message(msg, addr)[source]¶
Handles a DTLS message that came over the datagram transport.
- Parameters:
msg (bytes) – An incoming DTLS message.
addr – The remote endpoint as served by the datagram transport.
- Returns:
A 3-tuple, containing
The unencrypted message,
The (implementation-specific) remote endpoint the message was received from, an
A boolean, indicating if the last message established a session with the remote endpoint.
If
msgwas a control message, the first and second elements will beNone.
- is_connected(addr)[source]¶
Check if a session with
addrwas established.- Parameters:
addr – A remote endpoint (implementation-specific)
- Returns:
True, when a session withaddris established,Falseif not.
aiodnsprox.udp module¶
DNS over UDP serving side of the proxy.
- class aiodnsprox.udp.DNSOverUDPServerFactory(dns_upstream: DNSUpstream)[source]¶
Bases:
BaseServerFactoryFactory to create DNS over UDP servers
- class DNSOverUDPServer(factory)[source]¶
Bases:
BaseDNSServer,DNSUpstreamServerMixinDNS over UDP server implementation
- Parameters:
factory (
DNSOverUDPServerFactory) – The factory that created the DNS over DTLS server.
- error_received(exc)[source]¶
See error_received()
- send_response_to_requester(response, requester)[source]¶
Called when proxied DNS server responded to a DNS query send by
dns_query_received().- Parameters:
response – The DNS response in on-the-wire format received from the proxied DNS server.
requester – Identifier for the endpoint that originally requested the query. This will have the same value as the
requesterparameter ofdns_query_received()for thequerythatresponseis the response to.
- DNS_PORT = 53¶
- async create_server(loop, *args, local_addr=None, **kwargs)[source]¶
Creates an
DNSOverUDPServerobject.- Parameters:
loop (
asyncio.AbstractEventLoop) – the asyncio event loop the server should run inlocal_addr (
typing.Tuple[str, int]) – A tuple for the created server to bind to. The first element is the host part, the second element the port.
- Returns:
An
DNSOverUDPServerobject representing an DNS over DTLS server.- Return type: