AERN: Authenticated Encrypted Relay Network 1.0.0.0a (A1)
A post quantum authenticated and encrypted proxy chain network
topology.h
Go to the documentation of this file.
1/* 2025 Quantum Resistant Cryptographic Solutions Corporation
2 * All Rights Reserved.
3 *
4 * NOTICE: This software and all accompanying materials are the exclusive
5 * property of Quantum Resistant Cryptographic Solutions Corporation (QRCS).
6 * The intellectual and technical concepts contained within this implementation
7 * are proprietary to QRCS and its authorized licensors and are protected under
8 * applicable U.S. and international copyright, patent, and trade secret laws.
9 *
10 * CRYPTOGRAPHIC STANDAARS:
11 * - This software includes implementations of cryptographic algorithms such as
12 * SHA3, AES, and others. These algorithms are public domain or standardized
13 * by organizations such as NIST and are NOT the property of QRCS.
14 * - However, all source code, optimizations, and implementations in this library
15 * are original works of QRCS and are protected under this license.
16 *
17 * RESTRICTIONS:
18 * - Redistribution, modification, or unauthorized distribution of this software,
19 * in whole or in part, is strictly prohibited.
20 * - This software is provided for non-commercial, educational, and research
21 * purposes only. Commercial use in any form is expressly forbidden.
22 * - Licensing and authorized distribution are solely at the discretion of QRCS.
23 * - Any use of this software implies acceptance of these restrictions.
24 *
25 * DISCLAIMER:
26 * This software is provided "as is," without warranty of any kind, express or
27 * implied, including but not limited to warranties of merchantability or fitness
28 * for a particular purpose. QRCS disclaims all liability for any direct, indirect,
29 * incidental, or consequential damages resulting from the use or misuse of this software.
30 *
31 * FULL LICENSE:
32 * This software is subject to the **Quantum Resistant Cryptographic Solutions
33 * Proprietary License (QRCS-PL)**. The complete license terms are included
34 * in the LICENSE.txt file distributed with this software.
35 *
36 * Written by: John G. Underhill
37 * Contact: contact@qrcscorp.ca
38 */
39
40#ifndef AERN_TOPOLOGY_H
41#define AERN_TOPOLOGY_H
42
43#include "aern.h"
44#include "certificate.h"
45#include "ipinfo.h"
46#include "list.h"
47#include "timestamp.h"
48
80
81/*---------------------------------------------------------------------------
82 MACRO DEFINITIONS
83---------------------------------------------------------------------------*/
84
92#if defined(AERN_NETWORK_PROTOCOL_IPV6)
93# define AERN_TOPOLOGY_NODE_ENCODED_SIZE (AERN_CHILD_CERTIFICATE_ISSUER_PREFIX_SIZE + AERN_CERTIFICATE_ISSUER_SIZE + AERN_CERTIFICATE_SEPERATOR_SIZE + \
94 AERN_CHILD_CERTIFICATE_ADDRESS_PREFIX_SIZE + QSC_IPINFO_IPV6_STRNLEN + AERN_CERTIFICATE_SEPERATOR_SIZE + \
95 AERN_ROOT_CERTIFICATE_HASH_PREFIX_SIZE + (AERN_CERTIFICATE_HASH_SIZE * 2U) + AERN_CERTIFICATE_SEPERATOR_SIZE + \
96 AERN_CHILD_CERTIFICATE_SERIAL_PREFIX_SIZE + (AERN_CERTIFICATE_SERIAL_SIZE * 2U) + AERN_CERTIFICATE_SEPERATOR_SIZE + \
97 AERN_CHILD_CERTIFICATE_DESIGNATION_PREFIX_SIZE + AERN_NETWORK_DESIGNATION_SIZE + AERN_CERTIFICATE_SEPERATOR_SIZE + \
98 AERN_CHILD_CERTIFICATE_VALID_FROM_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + AERN_CERTIFICATE_SEPERATOR_SIZE + \
99 AERN_CHILD_CERTIFICATE_EXPIRATION_TO_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + AERN_CERTIFICATE_SEPERATOR_SIZE)
100#else
101# define AERN_TOPOLOGY_NODE_ENCODED_SIZE (AERN_CHILD_CERTIFICATE_ISSUER_PREFIX_SIZE + AERN_CERTIFICATE_ISSUER_SIZE + AERN_CERTIFICATE_SEPERATOR_SIZE + \
102 AERN_CHILD_CERTIFICATE_ADDRESS_PREFIX_SIZE + QSC_IPINFO_IPV4_STRNLEN + AERN_CERTIFICATE_SEPERATOR_SIZE + \
103 AERN_ROOT_CERTIFICATE_HASH_PREFIX_SIZE + (AERN_CERTIFICATE_HASH_SIZE * 2U) + AERN_CERTIFICATE_SEPERATOR_SIZE + \
104 AERN_CHILD_CERTIFICATE_SERIAL_PREFIX_SIZE + (AERN_CERTIFICATE_SERIAL_SIZE * 2U) + AERN_CERTIFICATE_SEPERATOR_SIZE + \
105 AERN_CHILD_CERTIFICATE_DESIGNATION_PREFIX_SIZE + AERN_NETWORK_DESIGNATION_SIZE + AERN_CERTIFICATE_SEPERATOR_SIZE + \
106 AERN_CHILD_CERTIFICATE_VALID_FROM_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + AERN_CERTIFICATE_SEPERATOR_SIZE + \
107 AERN_CHILD_CERTIFICATE_EXPIRATION_TO_PREFIX_SIZE + QSC_TIMESTAMP_STRING_SIZE + AERN_CERTIFICATE_SEPERATOR_SIZE)
108#endif
109
114#define AERN_TOPOLOGY_NODE_MINIMUM_ISSUER_SIZE 3U
115
120#define AERN_TOPOLOGY_NODE_NOT_FOUND -1
121
126#define AERN_NETWORK_TOPOLOGY_MAX_SIZE 1024U
127
132#define AERN_NETWORK_TOPOLOGY_NODE_SIZE (AERN_CERTIFICATE_ADDRESS_SIZE + \
133 AERN_CERTIFICATE_HASH_SIZE + \
134 AERN_CERTIFICATE_SERIAL_SIZE + \
135 AERN_CERTIFICATE_ISSUER_SIZE + \
136 AERN_CERTIFICATE_EXPIRATION_SIZE + \
137 AERN_CERTIFICATE_DESIGNATION_SIZE)
138
139/*---------------------------------------------------------------------------
140 STATIC CONSTANTS
141---------------------------------------------------------------------------*/
142
146static const char AERN_TOPOLOGY_NETWORK_DELIMITER[] = "/";
147
151static const char AERN_TOPOLOGY_CTYPE_DELIMITER[] = ".";
152
156static const char AERN_TOPOLOGY_ALIAS_DELIMITER[] = ":";
157
158/*---------------------------------------------------------------------------
159 DATA STRUCTURES
160---------------------------------------------------------------------------*/
161
177
184AERN_EXPORT_API typedef struct aern_topology_list_state
185{
186 uint8_t* topology;
187 uint32_t count;
189
190/*---------------------------------------------------------------------------
191 FUNCTION PROTOTYPES
192---------------------------------------------------------------------------*/
193
204AERN_EXPORT_API void aern_topology_address_from_issuer(char* address, const char* issuer, const aern_topology_list_state* list);
205
214AERN_EXPORT_API void aern_topology_node_add_alias(aern_topology_node_state* node, const char* alias);
215
226
237
247
259AERN_EXPORT_API bool aern_topology_canonical_to_issuer_name(char* issuer, size_t isslen, const char* domain, const char* cname);
260
271AERN_EXPORT_API bool aern_topology_issuer_to_canonical_name(char* cname, size_t namelen, const char* issuer);
272
282AERN_EXPORT_API void aern_topology_child_register(aern_topology_list_state* list, const aern_child_certificate* ccert, const char* address);
283
292AERN_EXPORT_API void aern_topology_list_clone(const aern_topology_list_state* tlist, aern_topology_list_state* tcopy);
293
303AERN_EXPORT_API void aern_topology_list_deserialize(aern_topology_list_state* list, const uint8_t* input, size_t inplen);
304
312AERN_EXPORT_API void aern_topology_list_dispose(aern_topology_list_state* list);
313
322
333AERN_EXPORT_API bool aern_topology_list_item(const aern_topology_list_state* list, aern_topology_node_state* node, size_t index);
334
344
355
365AERN_EXPORT_API size_t aern_topology_list_serialize(uint8_t* output, const aern_topology_list_state* list);
366
375AERN_EXPORT_API size_t aern_topology_list_size(const aern_topology_list_state* list);
376
387AERN_EXPORT_API size_t aern_topology_list_to_string(const aern_topology_list_state* list, char* output, size_t outlen);
388
399AERN_EXPORT_API size_t aern_topology_list_update_pack(uint8_t* output, const aern_topology_list_state* list, aern_network_designations ntype);
400
411AERN_EXPORT_API size_t aern_topology_list_update_unpack(aern_topology_list_state* list, const uint8_t* input, size_t inplen);
412
425
433AERN_EXPORT_API void aern_topology_node_clear(aern_topology_node_state* node);
434
443AERN_EXPORT_API void aern_topology_node_copy(const aern_topology_node_state* source, aern_topology_node_state* destination);
444
453AERN_EXPORT_API void aern_topology_node_deserialize(aern_topology_node_state* node, const uint8_t* input);
454
464AERN_EXPORT_API size_t aern_topology_node_encode(const aern_topology_node_state* node, char output[AERN_TOPOLOGY_NODE_ENCODED_SIZE]);
465
475AERN_EXPORT_API bool aern_topology_node_exists(const aern_topology_list_state* list, const uint8_t* serial);
476
486AERN_EXPORT_API int32_t aern_topology_node_get_index(const aern_topology_list_state* list, const uint8_t* serial);
487
498AERN_EXPORT_API bool aern_topology_node_find(const aern_topology_list_state* list, aern_topology_node_state* node, const uint8_t* serial);
499
510AERN_EXPORT_API bool aern_topology_node_find_address(const aern_topology_list_state* list, aern_topology_node_state* node, const char* address);
511
522AERN_EXPORT_API bool aern_topology_node_find_alias(const aern_topology_list_state* list, aern_topology_node_state* node, const char* alias);
523
534
545AERN_EXPORT_API bool aern_topology_node_find_issuer(const aern_topology_list_state* list, aern_topology_node_state* node, const char* issuer);
546
557
566AERN_EXPORT_API void aern_topology_node_remove(aern_topology_list_state* list, const uint8_t* serial);
567
576AERN_EXPORT_API void aern_topology_node_remove_duplicate(aern_topology_list_state* list, const char* issuer);
577
587AERN_EXPORT_API bool aern_topology_node_verify_ads(const aern_topology_list_state* list, const aern_child_certificate* ccert);
588
599AERN_EXPORT_API bool aern_topology_node_verify_issuer(const aern_topology_list_state* list, const aern_child_certificate* ccert, const char* issuer);
600
610AERN_EXPORT_API bool aern_topology_node_verify_root(const aern_topology_list_state* list, const aern_root_certificate* rcert);
611
621AERN_EXPORT_API size_t aern_topology_node_serialize(uint8_t* output, const aern_topology_node_state* node);
622
632AERN_EXPORT_API void aern_topology_root_register(aern_topology_list_state* list, const aern_root_certificate* rcert, const char* address);
633
642AERN_EXPORT_API void aern_topology_from_file(const char* fpath, aern_topology_list_state* list);
643
652AERN_EXPORT_API void aern_topology_to_file(const aern_topology_list_state* list, const char* fpath);
653
654#if defined(AERN_DEBUG_MODE)
662AERN_EXPORT_API bool aern_topology_functions_test();
663#endif
664
665#endif
AERN Common Definitions and Protocol Configuration.
#define AERN_CERTIFICATE_ISSUER_SIZE
The maximum certificate issuer string length. The last character must be a string terminator.
Definition aern.h:813
#define AERN_CERTIFICATE_ADDRESS_SIZE
The maximum IP address length.
Definition aern.h:776
aern_network_designations
The AERN device designation.
Definition aern.h:1140
#define AERN_CERTIFICATE_HASH_SIZE
The size of the certificate hash in bytes.
Definition aern.h:806
#define AERN_CERTIFICATE_SERIAL_SIZE
The certificate serial number field length.
Definition aern.h:837
AERN Certificate Handling Functions.
The certificate expiration time structure.
Definition aern.h:1308
The child certificate structure.
Definition aern.h:1318
The root certificate structure.
Definition aern.h:1436
The AERN topology list structure.
Definition topology.h:185
uint8_t * topology
Definition topology.h:186
uint32_t count
Definition topology.h:187
The AERN topology node structure.
Definition topology.h:169
char issuer[AERN_CERTIFICATE_ISSUER_SIZE]
Definition topology.h:173
char address[AERN_CERTIFICATE_ADDRESS_SIZE]
Definition topology.h:170
aern_certificate_expiration expiration
Definition topology.h:174
uint8_t serial[AERN_CERTIFICATE_SERIAL_SIZE]
Definition topology.h:172
aern_network_designations designation
Definition topology.h:175
uint8_t chash[AERN_CERTIFICATE_HASH_SIZE]
Definition topology.h:171
AERN_EXPORT_API void aern_topology_node_remove_duplicate(aern_topology_list_state *list, const char *issuer)
Remove a node from the topology with the same issuer name.
Definition topology.c:1035
AERN_EXPORT_API bool aern_topology_node_find_ads(const aern_topology_list_state *list, aern_topology_node_state *node)
Return the ADC node from the list.
Definition topology.c:822
AERN_EXPORT_API size_t aern_topology_list_update_pack(uint8_t *output, const aern_topology_list_state *list, aern_network_designations ntype)
Pack a node update set to an array.
Definition topology.c:468
AERN_EXPORT_API bool aern_topology_node_find_address(const aern_topology_list_state *list, aern_topology_node_state *node, const char *address)
Return the node pointer in the list matching the address string.
Definition topology.c:748
AERN_EXPORT_API bool aern_topology_node_find_issuer(const aern_topology_list_state *list, aern_topology_node_state *node, const char *issuer)
Return the node pointer in the list matching the name string.
Definition topology.c:858
AERN_EXPORT_API void aern_topology_list_deserialize(aern_topology_list_state *list, const uint8_t *input, size_t inplen)
Deserialize a topology list.
Definition topology.c:235
AERN_EXPORT_API size_t aern_topology_list_serialize(uint8_t *output, const aern_topology_list_state *list)
Serialize a topology list.
Definition topology.c:420
AERN_EXPORT_API size_t aern_topology_list_size(const aern_topology_list_state *list)
Get the byte size of the serialized list.
Definition topology.c:449
AERN_EXPORT_API void aern_topology_from_file(const char *fpath, aern_topology_list_state *list)
Copy a topology list from a file.
Definition topology.c:1299
AERN_EXPORT_API size_t aern_topology_list_server_count(const aern_topology_list_state *list, aern_network_designations ntype)
Get the count of a type of node in the database.
Definition topology.c:393
AERN_EXPORT_API size_t aern_topology_list_update_unpack(aern_topology_list_state *list, const uint8_t *input, size_t inplen)
Unpack a node update set to the topology list.
Definition topology.c:497
AERN_EXPORT_API int32_t aern_topology_node_get_index(const aern_topology_list_state *list, const uint8_t *serial)
Find the index number of a node in an array.
Definition topology.c:958
AERN_EXPORT_API void aern_topology_child_register(aern_topology_list_state *list, const aern_child_certificate *ccert, const char *address)
Register a child to a topology list.
Definition topology.c:187
AERN_EXPORT_API bool aern_topology_node_verify_root(const aern_topology_list_state *list, const aern_root_certificate *rcert)
Verify that the root certificate matches the hash stored in the topology.
Definition topology.c:1133
AERN_EXPORT_API size_t aern_topology_node_encode(const aern_topology_node_state *node, char output[AERN_TOPOLOGY_NODE_ENCODED_SIZE])
Encode a topological node into a printable string.
Definition topology.c:1210
AERN_EXPORT_API bool aern_topology_node_verify_issuer(const aern_topology_list_state *list, const aern_child_certificate *ccert, const char *issuer)
Verify that an issuing node's certificate matches the hash stored in the topology.
Definition topology.c:1107
AERN_EXPORT_API uint8_t * aern_topology_child_add_empty_node(aern_topology_list_state *list)
Get an empty node pointer from the topology list.
Definition topology.c:43
AERN_EXPORT_API void aern_topology_node_copy(const aern_topology_node_state *source, aern_topology_node_state *destination)
Copy a source node to a destination node structure.
Definition topology.c:669
AERN_EXPORT_API bool aern_topology_node_verify_ads(const aern_topology_list_state *list, const aern_child_certificate *ccert)
Verify that the ADC certificate matches the hash stored in the topology.
Definition topology.c:1082
AERN_EXPORT_API bool aern_topology_canonical_to_issuer_name(char *issuer, size_t isslen, const char *domain, const char *cname)
Translate a canonical name to an issuer name.
Definition topology.c:109
AERN_EXPORT_API bool aern_topology_node_find_alias(const aern_topology_list_state *list, aern_topology_node_state *node, const char *alias)
Return the node pointer in the list matching the alias string.
Definition topology.c:785
#define AERN_TOPOLOGY_NODE_ENCODED_SIZE
The size of an encoded node string.
Definition topology.h:101
AERN_EXPORT_API bool aern_topology_nodes_are_equal(const aern_topology_node_state *a, const aern_topology_node_state *b)
Compare two topological nodes for equality.
Definition topology.c:618
AERN_EXPORT_API bool aern_topology_node_find_root(const aern_topology_list_state *list, aern_topology_node_state *node)
Return the ARS server node from the list.
Definition topology.c:905
AERN_EXPORT_API void aern_topology_list_initialize(aern_topology_list_state *list)
Initialize the topology list.
Definition topology.c:283
AERN_EXPORT_API void aern_topology_to_file(const aern_topology_list_state *list, const char *fpath)
Copy a topology list to a file.
Definition topology.c:1328
AERN_EXPORT_API size_t aern_topology_node_serialize(uint8_t *output, const aern_topology_node_state *node)
Serialize a topological node structure, including the mfk.
Definition topology.c:1052
AERN_EXPORT_API bool aern_topology_issuer_to_canonical_name(char *cname, size_t namelen, const char *issuer)
Translate an issuer name to a canonical name.
Definition topology.c:147
AERN_EXPORT_API void aern_topology_list_dispose(aern_topology_list_state *list)
Dispose of the topology list and release memory.
Definition topology.c:267
AERN_EXPORT_API void aern_topology_root_register(aern_topology_list_state *list, const aern_root_certificate *rcert, const char *address)
Register a root to a topology list.
Definition topology.c:1158
AERN_EXPORT_API size_t aern_topology_ordered_server_list(aern_topology_list_state *olist, const aern_topology_list_state *tlist, aern_network_designations ntype)
Return a list of nodes of a type, sorted by serial number.
Definition topology.c:527
AERN_EXPORT_API void aern_topology_node_add_alias(aern_topology_node_state *node, const char *alias)
Add an alias string to an issuer path.
Definition topology.c:585
AERN_EXPORT_API void aern_topology_node_remove(aern_topology_list_state *list, const uint8_t *serial)
Find and remove a node from the topology.
Definition topology.c:987
AERN_EXPORT_API void aern_topology_node_deserialize(aern_topology_node_state *node, const uint8_t *input)
Deserialize a topological node.
Definition topology.c:686
AERN_EXPORT_API void aern_topology_node_clear(aern_topology_node_state *node)
Erase a node structure.
Definition topology.c:653
AERN_EXPORT_API bool aern_topology_list_item(const aern_topology_list_state *list, aern_topology_node_state *node, size_t index)
Get a node from the index.
Definition topology.c:294
AERN_EXPORT_API void aern_topology_child_add_item(aern_topology_list_state *list, const aern_topology_node_state *node)
Add a node to the topology list.
Definition topology.c:87
AERN_EXPORT_API size_t aern_topology_list_to_string(const aern_topology_list_state *list, char *output, size_t outlen)
Convert the topology list to a printable string.
Definition topology.c:1181
AERN_EXPORT_API size_t aern_topology_list_remove_duplicates(aern_topology_list_state *list)
Remove duplicate nodes from the topology.
Definition topology.c:320
AERN_EXPORT_API bool aern_topology_node_find(const aern_topology_list_state *list, aern_topology_node_state *node, const uint8_t *serial)
Return the node pointer in the list matching the serial number.
Definition topology.c:711
AERN_EXPORT_API void aern_topology_address_from_issuer(char *address, const char *issuer, const aern_topology_list_state *list)
Returns an IP address from an issuer string.
Definition topology.c:12
AERN_EXPORT_API bool aern_topology_node_exists(const aern_topology_list_state *list, const uint8_t *serial)
Queries on the serial number if the node is in the database.
Definition topology.c:941
AERN_EXPORT_API void aern_topology_list_clone(const aern_topology_list_state *tlist, aern_topology_list_state *tcopy)
Clone a topology list.
Definition topology.c:220