Ben Schwartz | 66810f6 | 2017-10-16 19:27:46 -0400 | [diff] [blame] | 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 | #ifndef _DNS_DNSTLSSERVER_H |
| 18 | #define _DNS_DNSTLSSERVER_H |
| 19 | |
| 20 | #include <set> |
| 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <netinet/in.h> |
| 25 | |
Bernie Innocenti | ad4e26e | 2019-01-30 11:16:36 +0900 | [diff] [blame] | 26 | #include <netd_resolv/params.h> |
Mike Yu | 5ae6154 | 2018-10-19 22:11:43 +0800 | [diff] [blame] | 27 | |
Ben Schwartz | 66810f6 | 2017-10-16 19:27:46 -0400 | [diff] [blame] | 28 | namespace android { |
| 29 | namespace net { |
| 30 | |
| 31 | // DnsTlsServer represents a recursive resolver that supports, or may support, a |
| 32 | // secure protocol. |
Mike Yu | a46fae7 | 2018-11-01 20:07:00 +0800 | [diff] [blame] | 33 | struct DnsTlsServer { |
Ben Schwartz | 66810f6 | 2017-10-16 19:27:46 -0400 | [diff] [blame] | 34 | // Default constructor. |
| 35 | DnsTlsServer() {} |
| 36 | |
| 37 | // Allow sockaddr_storage to be promoted to DnsTlsServer automatically. |
| 38 | DnsTlsServer(const sockaddr_storage& ss) : ss(ss) {} |
| 39 | |
Ben Schwartz | ded1b70 | 2017-10-25 14:41:02 -0400 | [diff] [blame] | 40 | enum class Response : uint8_t { success, network_error, limit_error, internal_error }; |
| 41 | |
| 42 | struct Result { |
| 43 | Response code; |
| 44 | std::vector<uint8_t> response; |
| 45 | }; |
| 46 | |
Ben Schwartz | 66810f6 | 2017-10-16 19:27:46 -0400 | [diff] [blame] | 47 | // The server location, including IP and port. |
Ben Schwartz | ded1b70 | 2017-10-25 14:41:02 -0400 | [diff] [blame] | 48 | sockaddr_storage ss = {}; |
Ben Schwartz | 66810f6 | 2017-10-16 19:27:46 -0400 | [diff] [blame] | 49 | |
| 50 | // A set of SHA256 public key fingerprints. If this set is nonempty, the server |
| 51 | // must present a self-consistent certificate chain that contains a certificate |
| 52 | // whose public key matches one of these fingerprints. Otherwise, the client will |
| 53 | // terminate the connection. |
| 54 | std::set<std::vector<uint8_t>> fingerprints; |
| 55 | |
| 56 | // The server's hostname. If this string is nonempty, the server must present a |
| 57 | // certificate that indicates this name and has a valid chain to a trusted root CA. |
| 58 | std::string name; |
| 59 | |
| 60 | // Placeholder. More protocols might be defined in the future. |
| 61 | int protocol = IPPROTO_TCP; |
| 62 | |
| 63 | // Exact comparison of DnsTlsServer objects |
Bernie Innocenti | ad4e26e | 2019-01-30 11:16:36 +0900 | [diff] [blame] | 64 | bool operator<(const DnsTlsServer& other) const; |
| 65 | bool operator==(const DnsTlsServer& other) const; |
Erik Kline | 1564d48 | 2018-03-07 17:09:35 +0900 | [diff] [blame] | 66 | |
| 67 | bool wasExplicitlyConfigured() const; |
Ben Schwartz | 66810f6 | 2017-10-16 19:27:46 -0400 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | // This comparison only checks the IP address. It ignores ports, names, and fingerprints. |
Mike Yu | a46fae7 | 2018-11-01 20:07:00 +0800 | [diff] [blame] | 71 | struct AddressComparator { |
Bernie Innocenti | ad4e26e | 2019-01-30 11:16:36 +0900 | [diff] [blame] | 72 | bool operator()(const DnsTlsServer& x, const DnsTlsServer& y) const; |
Ben Schwartz | 66810f6 | 2017-10-16 19:27:46 -0400 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | } // namespace net |
| 76 | } // namespace android |
| 77 | |
| 78 | #endif // _DNS_DNSTLSSERVER_H |