libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-dht-dnssec.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2026 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25#if !defined(__LWS_DHT_DNSSEC_H__)
26#define __LWS_DHT_DNSSEC_H__
27
28struct lws_context;
29
31 const char *domain;
32 const char *workdir;
33 const char *type; /* e.g. "EC" or "RSA" */
34 const char *curve;
35 int bits;
36};
37
39 const char *domain;
40 const char *workdir;
41 const char *hash; /* E.g., "SHA256" */
42};
43
45 const char *domain;
46 const char *workdir;
47 const char *certs_dir;
48 uint32_t sign_validity_duration; /* secs, 0 = LWS_AUTH_DNS_SIGN_VALIDITY_DEFAULT_SECS */
49 char ipv4[64];
50 char ipv6[64];
51};
52
54 const char *domain;
55 const char *key1_prefix;
56 const char *key2_prefix; /* optional if only importing 1 key */
57};
58
59/*
60 * The status a zone fetch completes with
61 */
63 LWS_DHT_DNSSEC_FETCH_ABORTED = -2, /* refused or dropped unfinished,
64 * eg, vhost destroyed: no result
65 * and nothing more will come */
66 LWS_DHT_DNSSEC_FETCH_INVALID = -1, /* what came failed validation */
67 LWS_DHT_DNSSEC_FETCH_TIMEOUT = 0, /* nobody answered in time */
68 LWS_DHT_DNSSEC_FETCH_OK = 1, /* the zone is in DHT storage */
69};
70
71/*
72 * status is one of enum lws_dht_dnssec_fetch_status
73 */
74typedef void (*lws_dht_dnssec_fetch_cb_t)(void *opaque, const char *domain, int status);
75
76/*
77 * Ownership of opaque: a fetch_zone() call that is not a cancel calls cb
78 * exactly once with opaque, whatever happens to the fetch, so cb is the one
79 * place that needs to release it. That may happen before fetch_zone()
80 * returns: when the zone is already in storage (FETCH_OK), and when the
81 * fetch is refused (FETCH_ABORTED, and fetch_zone() returns nonzero).
82 *
83 * A request with the same domain, cb and opaque as one still pending is
84 * merged into it, and cb is called once for both.
85 *
86 * A cancel (is_cancel = 1) drops the pending requests for that domain and
87 * opaque without calling their cb: opaque is the caller's again. A cancel
88 * with domain NULL drops every pending request with that opaque, so a caller
89 * going away can take back everything it handed out at once. A cancel must
90 * not be made from inside cb.
91 *
92 * A fail (is_fail = 1) gives up the pending requests for that domain and
93 * opaque (every domain with that opaque if domain is NULL) now, as a caller
94 * does when whatever wanted the zone stopped waiting for it: each is
95 * completed as it would be had nobody answered, its cb called once with
96 * LWS_DHT_DNSSEC_FETCH_TIMEOUT before fetch_zone() returns, and then forgotten.
97 * cb may start a new fetch.
98 */
100 struct lws_vhost *vhost;
101 const char *domain;
102 const char *cache_dir;
104 void *opaque;
105 int is_cancel; /* If 1, cancel an ongoing fetch for this domain/opaque
106 * pair, or for every domain with opaque if domain is
107 * NULL */
108 int force_network; /* If 1, bypass local cache and query network directly */
109 int is_fail; /* If 1, complete the pending requests for this domain /
110 * opaque pair, or for every domain with opaque if domain
111 * is NULL, now, as timed out */
112};
113
114/*
115 * What a DHT node says of its copy of a zone, in answer to query_serials()
116 */
118 LWS_DHT_DNSSEC_SERIAL_HELD, /* it holds the zone, at serial */
119 LWS_DHT_DNSSEC_SERIAL_NONE, /* it holds no copy of the zone */
120 LWS_DHT_DNSSEC_SERIAL_NO_ANSWER, /* it didn't answer in time: it may be
121 * down, or too old to know the query */
122};
123
124/*
125 * One node's answer. sa is NULL for this node's own copy. Everything
126 * pointed to is only valid during the callback.
127 */
129 const struct sockaddr *sa;
130 size_t salen;
131 const lws_dht_hash_t *id; /* its DHT node id, NULL for ours */
132 uint32_t serial; /* when state is ..._HELD */
133 uint8_t state; /* enum lws_dht_dnssec_serial_state */
134 uint8_t good; /* the routing table holds it as good */
135};
136
137/*
138 * r is NULL once every node asked has been reported: the query is over
139 */
140typedef void (*lws_dht_dnssec_serial_cb_t)(void *opaque, const char *domain,
141 const struct lws_dht_dnssec_serial_report *r);
142
143/*
144 * Ask every node in the DHT routing table which serial of domain's zone it
145 * holds, eg, to watch a new serial propagate. cb is called once for each
146 * node, as its answer arrives or as NO_ANSWER when the query times out after
147 * LWS_DHT_DNSSEC_SERIAL_QUERY_SECS, and then once with a NULL report. This
148 * node's own copy is reported first, from inside query_serials(), and so is
149 * the end of the query if the routing table is empty.
150 *
151 * There is one query per opaque: a new one replaces any still in progress for
152 * that opaque, with no further cb for the old one. A cancel (is_cancel = 1)
153 * drops it the same way, and must be made before opaque goes away. cb must
154 * not start or cancel a query itself.
155 *
156 * Returns nonzero if the query was refused, and then cb is not called.
157 */
158#define LWS_DHT_DNSSEC_SERIAL_QUERY_SECS 5
159
161 struct lws_vhost *vhost;
162 const char *domain; /* not used for a cancel */
164 void *opaque;
166};
167
169 int (*keygen)(struct lws_context *context, struct lws_dht_dnssec_keygen_args *args);
170 int (*dsfromkey)(struct lws_context *context, struct lws_dht_dnssec_dsfromkey_args *args);
171 int (*signzone)(struct lws_context *context, struct lws_dht_dnssec_signzone_args *args);
172 int (*importnsd)(struct lws_context *context, struct lws_dht_dnssec_importnsd_args *args);
173 int (*bump_zone_serial)(struct lws_context *context, const char *zone_filepath);
174
175 int (*add_temp_zone)(struct lws_context *context, const char *domain, const char *zone_str, int ttl_secs);
176 int (*publish_jws)(struct lws_vhost *vhost, const char *jws_filepath);
177 int (*fetch_zone)(struct lws_context *cx,
178 struct lws_dht_dnssec_fetch_zone_args *args);
179
180 /*
181 * Tell DHT plugin to actively subscribe to the network for changes
182 * to this domain using LWS_DHT_EVENT_NOTIFY pub/sub.
183 */
184 int (*subscribe_zone)(struct lws_vhost *vhost, const char *domain);
185
186 /*
187 * Actively repair an outdated peer we encountered by firing a targeted
188 * EVENT_NOTIFY packet at them containing the fresh SOA Serial.
189 */
190 int (*notify_peer_outdated)(struct lws_vhost *vhost, const char *domain,
191 const lws_sockaddr46 *sa46_peer, uint64_t newer_soa_serial);
192
193 /*
194 * Have cb told of each zone verified and stored here, with the path
195 * of its payload, eg, so the authoritative dns on vh serves it.
196 * Returns 0 if it is registered, or nonzero if lws-dht-dnssec isn't
197 * started on vh (yet): the protocols on a vhost start in no fixed
198 * order, so try again later.
199 */
200 int (*register_auth_cb)(struct lws_vhost *vh, void (*cb)(void *opaque, const char *domain, const char *payload_path), void *opaque);
201
202 /*
203 * See struct lws_dht_dnssec_query_serials_args
204 */
205 int (*query_serials)(struct lws_context *cx,
207
208 /*
209 * The SOA serial of a zone file, or of a signed zone as
210 * lws_auth_dns_sign_zone() writes it. Returns nonzero if it has none.
211 */
212 int (*zone_file_serial)(const char *filepath, uint32_t *serial);
213};
214
215
216#endif
struct lws_dht_hash lws_dht_hash_t
unsigned int uint32_t
unsigned char uint8_t
const struct sockaddr * sa
lws_dht_dnssec_fetch_status
@ LWS_DHT_DNSSEC_FETCH_TIMEOUT
@ LWS_DHT_DNSSEC_FETCH_OK
@ LWS_DHT_DNSSEC_FETCH_ABORTED
@ LWS_DHT_DNSSEC_FETCH_INVALID
lws_dht_dnssec_serial_state
@ LWS_DHT_DNSSEC_SERIAL_NO_ANSWER
@ LWS_DHT_DNSSEC_SERIAL_NONE
@ LWS_DHT_DNSSEC_SERIAL_HELD
lws_dht_dnssec_serial_cb_t cb
void(* lws_dht_dnssec_serial_cb_t)(void *opaque, const char *domain, const struct lws_dht_dnssec_serial_report *r)
lws_dht_dnssec_fetch_cb_t cb
const lws_dht_hash_t * id
void(* lws_dht_dnssec_fetch_cb_t)(void *opaque, const char *domain, int status)
int(* bump_zone_serial)(struct lws_context *context, const char *zone_filepath)
int(* importnsd)(struct lws_context *context, struct lws_dht_dnssec_importnsd_args *args)
int(* notify_peer_outdated)(struct lws_vhost *vhost, const char *domain, const lws_sockaddr46 *sa46_peer, uint64_t newer_soa_serial)
int(* add_temp_zone)(struct lws_context *context, const char *domain, const char *zone_str, int ttl_secs)
int(* subscribe_zone)(struct lws_vhost *vhost, const char *domain)
int(* fetch_zone)(struct lws_context *cx, struct lws_dht_dnssec_fetch_zone_args *args)
int(* query_serials)(struct lws_context *cx, struct lws_dht_dnssec_query_serials_args *args)
int(* publish_jws)(struct lws_vhost *vhost, const char *jws_filepath)
int(* keygen)(struct lws_context *context, struct lws_dht_dnssec_keygen_args *args)
int(* register_auth_cb)(struct lws_vhost *vh, void(*cb)(void *opaque, const char *domain, const char *payload_path), void *opaque)
int(* zone_file_serial)(const char *filepath, uint32_t *serial)
int(* signzone)(struct lws_context *context, struct lws_dht_dnssec_signzone_args *args)
int(* dsfromkey)(struct lws_context *context, struct lws_dht_dnssec_dsfromkey_args *args)