1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <set> 20 #include <string> 21 #include <vector> 22 23 #include <netinet/in.h> 24 25 #include <params.h> 26 27 #include "IPrivateDnsServer.h" 28 29 namespace android { 30 namespace net { 31 32 // DnsTlsServer represents a recursive resolver that supports, or may support, a 33 // secure protocol. 34 struct DnsTlsServer : public IPrivateDnsServer { 35 // Default constructor. DnsTlsServerDnsTlsServer36 DnsTlsServer() {} 37 38 // Allow sockaddr_storage to be promoted to DnsTlsServer automatically. DnsTlsServerDnsTlsServer39 DnsTlsServer(const sockaddr_storage& ss) : ss(ss) {} 40 41 // The server location, including IP and port. 42 // TODO: make it const. 43 sockaddr_storage ss = {}; 44 45 // The server's hostname. If this string is nonempty, the server must present a 46 // certificate that indicates this name and has a valid chain to a trusted root CA. 47 // TODO: make it const. 48 std::string name; 49 50 // The certificate of the CA that signed the server's certificate. 51 // It is used to store temporary test CA certificate for internal tests. 52 // TODO: make it const. 53 std::string certificate; 54 55 // Placeholder. More protocols might be defined in the future. 56 // TODO: make it const. 57 int protocol = IPPROTO_TCP; 58 59 // Exact comparison of DnsTlsServer objects 60 bool operator<(const DnsTlsServer& other) const; 61 bool operator==(const DnsTlsServer& other) const; 62 63 bool wasExplicitlyConfigured() const; 64 std::string toIpString() const; 65 transportDnsTlsServer66 PrivateDnsTransport transport() const override { return PrivateDnsTransport::kDot; } providerDnsTlsServer67 std::string provider() const override { return name; } addrDnsTlsServer68 netdutils::IPSockAddr addr() const override { return netdutils::IPSockAddr::toIPSockAddr(ss); } validationMarkDnsTlsServer69 uint32_t validationMark() const override { return mark; } 70 validationStateDnsTlsServer71 Validation validationState() const override { return mValidation; } setValidationStateDnsTlsServer72 void setValidationState(Validation val) override { mValidation = val; } probeDnsTlsServer73 bool probe() override { 74 // TODO: implement it. 75 return false; 76 } 77 78 // The socket mark used for validation. 79 // Note that the mark of a connection to which the DnsResolver sends app's DNS requests can 80 // be different. 81 // TODO: make it const. 82 uint32_t mark = 0; 83 84 // Return whether or not the server can be used for a network. It depends on 85 // the resolver configuration. activeDnsTlsServer86 bool active() const override { return mActive; } setActiveDnsTlsServer87 void setActive(bool val) override { mActive = val; } 88 89 private: 90 // State, unrelated to the comparison of DnsTlsServer objects. 91 Validation mValidation = Validation::unknown_server; 92 bool mActive = false; 93 }; 94 95 // This comparison only checks the IP address. It ignores ports, names, and fingerprints. 96 struct AddressComparator { 97 bool operator()(const DnsTlsServer& x, const DnsTlsServer& y) const; 98 }; 99 100 } // namespace net 101 } // namespace android 102