2 This file is part of GNUnet
3 Copyright (C) 2012, 2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @author Christian Grothoff
25 * API that can be used to manipulate GNS record data
27 * @defgroup gnsrecord GNS Record library
28 * Manipulate GNS record data
30 * @see [Documentation](https://gnunet.org/gns-plugins)
34 #ifndef GNUNET_GNSRECORD_LIB_H
35 #define GNUNET_GNSRECORD_LIB_H
39 #if 0 /* keep Emacsens' auto-indent happy */
45 * Maximum size of a value that can be stored in a GNS block.
47 #define GNUNET_GNSRECORD_MAX_BLOCK_SIZE (63 * 1024)
51 * Record type indicating any record/'*'
53 #define GNUNET_GNSRECORD_TYPE_ANY 0
56 * Record type for GNS zone transfer ("PKEY").
58 #define GNUNET_GNSRECORD_TYPE_PKEY 65536
61 * Record type for GNS nick names ("NICK").
63 #define GNUNET_GNSRECORD_TYPE_NICK 65537
66 * Record type for GNS legacy hostnames ("LEHO").
68 #define GNUNET_GNSRECORD_TYPE_LEHO 65538
71 * Record type for VPN resolution
73 #define GNUNET_GNSRECORD_TYPE_VPN 65539
76 * Record type for delegation to DNS.
78 #define GNUNET_GNSRECORD_TYPE_GNS2DNS 65540
81 * Record type for a boxed record (see TLSA/SRV handling in GNS).
83 #define GNUNET_GNSRECORD_TYPE_BOX 65541
86 * Record type for a social place.
88 #define GNUNET_GNSRECORD_TYPE_PLACE 65542
91 * Record type for a phone (of CONVERSATION).
93 #define GNUNET_GNSRECORD_TYPE_PHONE 65543
96 * Record type for identity attributes (of RECLAIM).
98 #define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE 65544
101 * Record type for local ticket references
103 #define GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET 65545
110 * 65547 deleted, free to use
114 * Record type for policies
116 #define GNUNET_GNSRECORD_TYPE_DELEGATE 65548
119 * Record type for reverse lookups
121 #define GNUNET_GNSRECORD_TYPE_ATTRIBUTE 65549
124 * Record type for reclaim records
126 #define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE_REF 65550
129 * Record type for RECLAIM master
131 #define GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER 65551
134 * Record type for reclaim OIDC clients
136 #define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT 65552
139 * Record type for reclaim OIDC redirect URIs
141 #define GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT 65553
144 * Record type for an attribute attestation
146 #define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION 65554
149 * Record type for an attestation reference in a ticket
151 #define GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION_REF 65555
155 * Flags that can be set for a record.
157 enum GNUNET_GNSRECORD_Flags
160 * No special options.
162 GNUNET_GNSRECORD_RF_NONE = 0,
165 * This is a private record of this peer and it should
166 * thus not be handed out to other peers.
168 GNUNET_GNSRECORD_RF_PRIVATE = 2,
171 * This is a supplemental record.
173 GNUNET_GNSRECORD_RF_SUPPLEMENTAL = 4,
176 * This expiration time of the record is a relative
177 * time (not an absolute time).
179 GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION = 8,
182 * This record should not be used unless all (other) records with an absolute
183 * expiration time have expired.
185 GNUNET_GNSRECORD_RF_SHADOW_RECORD = 16
188 * When comparing flags for record equality for removal,
189 * which flags should must match (in addition to the type,
190 * name, expiration value and data of the record)? All flags
191 * that are not listed here will be ignored for this purpose.
192 * (for example, we don't expect that users will remember to
193 * pass the '--private' option when removing a record from
194 * the namestore, hence we don't require this particular option
195 * to match upon removal). See also
196 * #GNUNET_GNSRECORD_records_cmp.
198 #define GNUNET_GNSRECORD_RF_RCMP_FLAGS (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)
205 struct GNUNET_GNSRECORD_Data
208 * Binary value stored in the DNS record. Note: "data" must never
209 * be individually 'malloc'ed, but instead always points into some
210 * existing data area.
215 * Expiration time for the DNS record. Can be relative
216 * or absolute, depending on @e flags. Measured in the same
217 * unit as GNUnet time (microseconds).
219 uint64_t expiration_time;
222 * Number of bytes in @e data.
227 * Type of the GNS/DNS record.
229 uint32_t record_type;
232 * Flags for the record.
234 enum GNUNET_GNSRECORD_Flags flags;
238 GNUNET_NETWORK_STRUCT_BEGIN
241 * Data stored in a PLACE record.
243 struct GNUNET_GNSRECORD_PlaceData
246 * Public key of the place.
248 struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key;
251 * Peer identity of the origin.
253 struct GNUNET_PeerIdentity origin;
256 * Number of relays that follow.
258 uint32_t relay_count GNUNET_PACKED;
260 /* Followed by struct GNUNET_PeerIdentity relays[relay_count] */
265 * Information we have in an encrypted block with record data (i.e. in the DHT).
267 struct GNUNET_GNSRECORD_Block
270 * Signature of the block.
272 struct GNUNET_CRYPTO_EcdsaSignature signature;
275 * Derived key used for signing; hash of this is the query.
277 struct GNUNET_CRYPTO_EcdsaPublicKey derived_key;
280 * Number of bytes signed; also specifies the number of bytes
281 * of encrypted data that follow.
283 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
286 * Expiration time of the block.
288 struct GNUNET_TIME_AbsoluteNBO expiration_time;
290 /* followed by encrypted data */
295 * Record type used to box up SRV and TLSA records. For example, a
296 * TLSA record for "_https._tcp.foo.gnu" will be stored under
297 * "foo.gnu" as a BOX record with service 443 (https) and protocol 6
298 * (tcp) and record_type "TLSA". When a BOX record is received, GNS
299 * unboxes it if the name contained "_SERVICE._PROTO", otherwise GNS
300 * leaves it untouched. This is done to ensure that TLSA (and SRV)
301 * records do not require a separate network request, thus making TLSA
302 * records inseparable from the "main" A/AAAA/VPN/etc. records.
304 struct GNUNET_GNSRECORD_BoxRecord
307 * Protocol of the boxed record (6 = TCP, 17 = UDP, etc.).
308 * Yes, in IP protocols are usually limited to 8 bits. In NBO.
310 uint16_t protocol GNUNET_PACKED;
313 * Service of the boxed record (aka port number), in NBO.
315 uint16_t service GNUNET_PACKED;
318 * GNS record type of the boxed record. In NBO.
320 uint32_t record_type GNUNET_PACKED;
322 /* followed by the 'original' record */
326 * Record type used internally to keep track of reverse mappings into a
328 * The record contains data related to PKEY delegations from other namespaces to
329 * the namespace the record belongs to.
330 * It is exclusively found under the label ``+''.
332 struct GNUNET_GNSRECORD_ReverseRecord
335 * The public key of the namespace the is delegating to our namespace
337 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
340 * The expiration time of the delegation
342 struct GNUNET_TIME_Absolute expiration;
344 /* followed by the name the delegator uses to refer to our namespace */
347 GNUNET_NETWORK_STRUCT_END
351 * Process a records that were decrypted from a block.
354 * @param rd_count number of entries in @a rd array
355 * @param rd array of records with data to store
357 typedef void (*GNUNET_GNSRECORD_RecordCallback) (
358 void *cls, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd);
361 /* ***************** API related to GNSRECORD plugins ************** */
364 * Convert the binary value @a data of a record of
365 * type @a type to a human-readable string.
367 * @param type type of the record
368 * @param data value in binary encoding
369 * @param data_size number of bytes in @a data
370 * @return NULL on error, otherwise human-readable representation of the value
373 GNUNET_GNSRECORD_value_to_string (uint32_t type, const void *data,
378 * Convert human-readable version of the value @a s of a record
379 * of type @a type to the respective binary representation.
381 * @param type type of the record
382 * @param s human-readable string
383 * @param data set to value in binary encoding (will be allocated)
384 * @param data_size set to number of bytes in @a data
385 * @return #GNUNET_OK on success
388 GNUNET_GNSRECORD_string_to_value (uint32_t type, const char *s, void **data,
393 * Convert a type name (i.e. "AAAA") to the corresponding number.
395 * @param dns_typename name to convert
396 * @return corresponding number, UINT32_MAX on error
399 GNUNET_GNSRECORD_typename_to_number (const char *dns_typename);
403 * Convert a type number (i.e. 1) to the corresponding type string (i.e. "A")
405 * @param type number of a type to convert
406 * @return corresponding typestring, NULL on error
409 GNUNET_GNSRECORD_number_to_typename (uint32_t type);
412 /* convenience APIs for serializing / deserializing GNS records */
415 * Calculate how many bytes we will need to serialize the given
418 * @param rd_count number of records in the @a rd array
419 * @param rd array of #GNUNET_GNSRECORD_Data with @a rd_count elements
420 * @return the required size to serialize, -1 on error
423 GNUNET_GNSRECORD_records_get_size (unsigned int rd_count,
424 const struct GNUNET_GNSRECORD_Data *rd);
428 * Serialize the given records to the given destination buffer.
430 * @param rd_count number of records in the @a rd array
431 * @param rd array of #GNUNET_GNSRECORD_Data with @a rd_count elements
432 * @param dest_size size of the destination array @a dst
433 * @param dest where to write the result
434 * @return the size of serialized records, -1 if records do not fit
437 GNUNET_GNSRECORD_records_serialize (unsigned int rd_count,
438 const struct GNUNET_GNSRECORD_Data *rd,
439 size_t dest_size, char *dest);
443 * Deserialize the given records to the given destination.
445 * @param len size of the serialized record data
446 * @param src the serialized record data
447 * @param rd_count number of records in the @a dest array
448 * @param dest where to put the data
449 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
452 GNUNET_GNSRECORD_records_deserialize (size_t len, const char *src,
453 unsigned int rd_count,
454 struct GNUNET_GNSRECORD_Data *dest);
457 /* ******* general APIs relating to blocks, records and labels ******** */
461 * Test if a given record is expired.
463 * @param rd record to test
464 * @return #GNUNET_YES if the record is expired,
468 GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd);
472 * Convert a UTF-8 string to UTF-8 lowercase
473 * @param src source string
474 * @return converted result
477 GNUNET_GNSRECORD_string_to_lowercase (const char *src);
481 * Convert a zone to a string (for printing debug messages).
482 * This is one of the very few calls in the entire API that is
485 * @param z public key of a zone
486 * @return string form; will be overwritten by next call to
487 * #GNUNET_GNSRECORD_z2s.
490 GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z);
494 * Convert public key to the respective absolute domain name in the
496 * This is one of the very few calls in the entire API that is
499 * @param pkey a public key with a point on the eliptic curve
500 * @return string "X.zkey" where X is the coordinates of the public
501 * key in an encoding suitable for DNS labels.
504 GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey);
508 * Convert an absolute domain name to the
509 * respective public key.
511 * @param zkey string "X" where X is the public
512 * key in an encoding suitable for DNS labels.
513 * @param pkey set to a public key on the eliptic curve
514 * @return #GNUNET_SYSERR if @a zkey has the wrong syntax
517 GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey,
518 struct GNUNET_CRYPTO_EcdsaPublicKey *pkey);
522 * Calculate the DHT query for a given @a label in a given @a zone.
524 * @param zone private key of the zone
525 * @param label label of the record
526 * @param query hash to use for the query
529 GNUNET_GNSRECORD_query_from_private_key (
530 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label,
531 struct GNUNET_HashCode *query);
535 * Calculate the DHT query for a given @a label in a given @a zone.
537 * @param pub public key of the zone
538 * @param label label of the record
539 * @param query hash to use for the query
542 GNUNET_GNSRECORD_query_from_public_key (
543 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, const char *label,
544 struct GNUNET_HashCode *query);
548 * Sign name and records
550 * @param key the private key
551 * @param expire block expiration
552 * @param label the name for the records
553 * @param rd record data
554 * @param rd_count number of records in @a rd
556 struct GNUNET_GNSRECORD_Block *
557 GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
558 struct GNUNET_TIME_Absolute expire,
560 const struct GNUNET_GNSRECORD_Data *rd,
561 unsigned int rd_count);
565 * Sign name and records, cache derived public key (also keeps the
566 * private key in static memory, so do not use this function if
567 * keeping the private key in the process'es RAM is a major issue).
569 * @param key the private key
570 * @param expire block expiration
571 * @param label the name for the records
572 * @param rd record data
573 * @param rd_count number of records in @a rd
575 struct GNUNET_GNSRECORD_Block *
576 GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
577 struct GNUNET_TIME_Absolute expire,
579 const struct GNUNET_GNSRECORD_Data *rd,
580 unsigned int rd_count);
584 * Check if a signature is valid. This API is used by the GNS Block
585 * to validate signatures received from the network.
587 * @param block block to verify
588 * @return #GNUNET_OK if the signature is valid
591 GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block);
597 * @param block block to decrypt
598 * @param zone_key public key of the zone
599 * @param label the name for the records
600 * @param proc function to call with the result
601 * @param proc_cls closure for @a proc
602 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was
606 GNUNET_GNSRECORD_block_decrypt (
607 const struct GNUNET_GNSRECORD_Block *block,
608 const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, const char *label,
609 GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls);
613 * Compares if two records are equal
616 * @param b another record
617 * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not.
620 GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
621 const struct GNUNET_GNSRECORD_Data *b);
625 * Returns the expiration time of the given block of records. The block
626 * expiration time is the expiration time of the record with smallest
629 * @param rd_count number of records given in @a rd
630 * @param rd array of records
631 * @return absolute expiration time
633 struct GNUNET_TIME_Absolute
634 GNUNET_GNSRECORD_record_get_expiration_time (
635 unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd);
638 #if 0 /* keep Emacsens' auto-indent happy */
647 /** @} */ /* end of group */