libwebsockets
Lightweight C library for HTML5 websockets
Toggle main menu visibility
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
28
struct
lws_context;
29
30
struct
lws_dht_dnssec_keygen_args
{
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
38
struct
lws_dht_dnssec_dsfromkey_args
{
39
const
char
*
domain
;
40
const
char
*
workdir
;
41
const
char
*
hash
;
/* E.g., "SHA256" */
42
};
43
44
struct
lws_dht_dnssec_signzone_args
{
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
53
struct
lws_dht_dnssec_importnsd_args
{
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
*/
62
enum
lws_dht_dnssec_fetch_status
{
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
*/
74
typedef
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
*/
99
struct
lws_dht_dnssec_fetch_zone_args
{
100
struct
lws_vhost *
vhost
;
101
const
char
*
domain
;
102
const
char
*
cache_dir
;
103
lws_dht_dnssec_fetch_cb_t
cb
;
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
*/
117
enum
lws_dht_dnssec_serial_state
{
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
*/
128
struct
lws_dht_dnssec_serial_report
{
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
*/
140
typedef
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
160
struct
lws_dht_dnssec_query_serials_args
{
161
struct
lws_vhost *
vhost
;
162
const
char
*
domain
;
/* not used for a cancel */
163
lws_dht_dnssec_serial_cb_t
cb
;
164
void
*
opaque
;
165
int
is_cancel
;
166
};
167
168
struct
lws_dht_dnssec_ops
{
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,
206
struct
lws_dht_dnssec_query_serials_args
*args);
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
lws_dht_hash_t
struct lws_dht_hash lws_dht_hash_t
lws_sockaddr46
Definition
lws-adopt.h:91
uint32_t
unsigned int uint32_t
Definition
libwebsockets.h:744
uint8_t
unsigned char uint8_t
Definition
libwebsockets.h:746
lws_dht_dnssec_importnsd_args::domain
const char * domain
Definition
lws-dht-dnssec.h:54
lws_dht_dnssec_serial_report::sa
const struct sockaddr * sa
Definition
lws-dht-dnssec.h:129
lws_dht_dnssec_dsfromkey_args::hash
const char * hash
Definition
lws-dht-dnssec.h:41
lws_dht_dnssec_dsfromkey_args::domain
const char * domain
Definition
lws-dht-dnssec.h:39
lws_dht_dnssec_fetch_status
lws_dht_dnssec_fetch_status
Definition
lws-dht-dnssec.h:62
LWS_DHT_DNSSEC_FETCH_TIMEOUT
@ LWS_DHT_DNSSEC_FETCH_TIMEOUT
Definition
lws-dht-dnssec.h:67
LWS_DHT_DNSSEC_FETCH_OK
@ LWS_DHT_DNSSEC_FETCH_OK
Definition
lws-dht-dnssec.h:68
LWS_DHT_DNSSEC_FETCH_ABORTED
@ LWS_DHT_DNSSEC_FETCH_ABORTED
Definition
lws-dht-dnssec.h:63
LWS_DHT_DNSSEC_FETCH_INVALID
@ LWS_DHT_DNSSEC_FETCH_INVALID
Definition
lws-dht-dnssec.h:66
lws_dht_dnssec_serial_state
lws_dht_dnssec_serial_state
Definition
lws-dht-dnssec.h:117
LWS_DHT_DNSSEC_SERIAL_NO_ANSWER
@ LWS_DHT_DNSSEC_SERIAL_NO_ANSWER
Definition
lws-dht-dnssec.h:120
LWS_DHT_DNSSEC_SERIAL_NONE
@ LWS_DHT_DNSSEC_SERIAL_NONE
Definition
lws-dht-dnssec.h:119
LWS_DHT_DNSSEC_SERIAL_HELD
@ LWS_DHT_DNSSEC_SERIAL_HELD
Definition
lws-dht-dnssec.h:118
lws_dht_dnssec_dsfromkey_args::workdir
const char * workdir
Definition
lws-dht-dnssec.h:40
lws_dht_dnssec_signzone_args::domain
const char * domain
Definition
lws-dht-dnssec.h:45
lws_dht_dnssec_serial_report::serial
uint32_t serial
Definition
lws-dht-dnssec.h:132
lws_dht_dnssec_serial_report::salen
size_t salen
Definition
lws-dht-dnssec.h:130
lws_dht_dnssec_signzone_args::ipv6
char ipv6[64]
Definition
lws-dht-dnssec.h:50
lws_dht_dnssec_serial_report::state
uint8_t state
Definition
lws-dht-dnssec.h:133
lws_dht_dnssec_fetch_zone_args::force_network
int force_network
Definition
lws-dht-dnssec.h:108
lws_dht_dnssec_keygen_args::workdir
const char * workdir
Definition
lws-dht-dnssec.h:32
lws_dht_dnssec_query_serials_args::cb
lws_dht_dnssec_serial_cb_t cb
Definition
lws-dht-dnssec.h:163
lws_dht_dnssec_fetch_zone_args::is_cancel
int is_cancel
Definition
lws-dht-dnssec.h:105
lws_dht_dnssec_keygen_args::curve
const char * curve
Definition
lws-dht-dnssec.h:34
lws_dht_dnssec_serial_report::good
uint8_t good
Definition
lws-dht-dnssec.h:134
lws_dht_dnssec_signzone_args::sign_validity_duration
uint32_t sign_validity_duration
Definition
lws-dht-dnssec.h:48
lws_dht_dnssec_serial_cb_t
void(* lws_dht_dnssec_serial_cb_t)(void *opaque, const char *domain, const struct lws_dht_dnssec_serial_report *r)
Definition
lws-dht-dnssec.h:140
lws_dht_dnssec_query_serials_args::domain
const char * domain
Definition
lws-dht-dnssec.h:162
lws_dht_dnssec_query_serials_args::is_cancel
int is_cancel
Definition
lws-dht-dnssec.h:165
lws_dht_dnssec_keygen_args::bits
int bits
Definition
lws-dht-dnssec.h:35
lws_dht_dnssec_signzone_args::certs_dir
const char * certs_dir
Definition
lws-dht-dnssec.h:47
lws_dht_dnssec_query_serials_args::vhost
struct lws_vhost * vhost
Definition
lws-dht-dnssec.h:161
lws_dht_dnssec_keygen_args::type
const char * type
Definition
lws-dht-dnssec.h:33
lws_dht_dnssec_signzone_args::workdir
const char * workdir
Definition
lws-dht-dnssec.h:46
lws_dht_dnssec_fetch_zone_args::cb
lws_dht_dnssec_fetch_cb_t cb
Definition
lws-dht-dnssec.h:103
lws_dht_dnssec_keygen_args::domain
const char * domain
Definition
lws-dht-dnssec.h:31
lws_dht_dnssec_importnsd_args::key2_prefix
const char * key2_prefix
Definition
lws-dht-dnssec.h:56
lws_dht_dnssec_fetch_zone_args::opaque
void * opaque
Definition
lws-dht-dnssec.h:104
lws_dht_dnssec_fetch_zone_args::domain
const char * domain
Definition
lws-dht-dnssec.h:101
lws_dht_dnssec_serial_report::id
const lws_dht_hash_t * id
Definition
lws-dht-dnssec.h:131
lws_dht_dnssec_importnsd_args::key1_prefix
const char * key1_prefix
Definition
lws-dht-dnssec.h:55
lws_dht_dnssec_fetch_zone_args::is_fail
int is_fail
Definition
lws-dht-dnssec.h:109
lws_dht_dnssec_fetch_cb_t
void(* lws_dht_dnssec_fetch_cb_t)(void *opaque, const char *domain, int status)
Definition
lws-dht-dnssec.h:74
lws_dht_dnssec_signzone_args::ipv4
char ipv4[64]
Definition
lws-dht-dnssec.h:49
lws_dht_dnssec_fetch_zone_args::cache_dir
const char * cache_dir
Definition
lws-dht-dnssec.h:102
lws_dht_dnssec_query_serials_args::opaque
void * opaque
Definition
lws-dht-dnssec.h:164
lws_dht_dnssec_fetch_zone_args::vhost
struct lws_vhost * vhost
Definition
lws-dht-dnssec.h:100
lws_dht_dnssec_dsfromkey_args
Definition
lws-dht-dnssec.h:38
lws_dht_dnssec_fetch_zone_args
Definition
lws-dht-dnssec.h:99
lws_dht_dnssec_importnsd_args
Definition
lws-dht-dnssec.h:53
lws_dht_dnssec_keygen_args
Definition
lws-dht-dnssec.h:30
lws_dht_dnssec_query_serials_args
Definition
lws-dht-dnssec.h:160
lws_dht_dnssec_serial_report
Definition
lws-dht-dnssec.h:128
lws_dht_dnssec_signzone_args
Definition
lws-dht-dnssec.h:44
sockaddr
Definition
lws-optee.h:52
lws_dht_dnssec_ops
Definition
lws-dht-dnssec.h:168
lws_dht_dnssec_ops::bump_zone_serial
int(* bump_zone_serial)(struct lws_context *context, const char *zone_filepath)
Definition
lws-dht-dnssec.h:173
lws_dht_dnssec_ops::importnsd
int(* importnsd)(struct lws_context *context, struct lws_dht_dnssec_importnsd_args *args)
Definition
lws-dht-dnssec.h:172
lws_dht_dnssec_ops::notify_peer_outdated
int(* notify_peer_outdated)(struct lws_vhost *vhost, const char *domain, const lws_sockaddr46 *sa46_peer, uint64_t newer_soa_serial)
Definition
lws-dht-dnssec.h:190
lws_dht_dnssec_ops::add_temp_zone
int(* add_temp_zone)(struct lws_context *context, const char *domain, const char *zone_str, int ttl_secs)
Definition
lws-dht-dnssec.h:175
lws_dht_dnssec_ops::subscribe_zone
int(* subscribe_zone)(struct lws_vhost *vhost, const char *domain)
Definition
lws-dht-dnssec.h:184
lws_dht_dnssec_ops::fetch_zone
int(* fetch_zone)(struct lws_context *cx, struct lws_dht_dnssec_fetch_zone_args *args)
Definition
lws-dht-dnssec.h:177
lws_dht_dnssec_ops::query_serials
int(* query_serials)(struct lws_context *cx, struct lws_dht_dnssec_query_serials_args *args)
Definition
lws-dht-dnssec.h:205
lws_dht_dnssec_ops::publish_jws
int(* publish_jws)(struct lws_vhost *vhost, const char *jws_filepath)
Definition
lws-dht-dnssec.h:176
lws_dht_dnssec_ops::keygen
int(* keygen)(struct lws_context *context, struct lws_dht_dnssec_keygen_args *args)
Definition
lws-dht-dnssec.h:169
lws_dht_dnssec_ops::register_auth_cb
int(* register_auth_cb)(struct lws_vhost *vh, void(*cb)(void *opaque, const char *domain, const char *payload_path), void *opaque)
Definition
lws-dht-dnssec.h:200
lws_dht_dnssec_ops::zone_file_serial
int(* zone_file_serial)(const char *filepath, uint32_t *serial)
Definition
lws-dht-dnssec.h:212
lws_dht_dnssec_ops::signzone
int(* signzone)(struct lws_context *context, struct lws_dht_dnssec_signzone_args *args)
Definition
lws-dht-dnssec.h:171
lws_dht_dnssec_ops::dsfromkey
int(* dsfromkey)(struct lws_context *context, struct lws_dht_dnssec_dsfromkey_args *args)
Definition
lws-dht-dnssec.h:170
include
libwebsockets
lws-dht-dnssec.h
Generated on
for libwebsockets by
1.18.0