MPDC: Multi Party Domain Cryptosystem 1.0.0.0b (A0)
MPDC Interior protocol
server.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 STANDARDS:
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: john.underhill@protonmail.com
38 */
39
40#ifndef MPDC_SERVER_H
41#define MPDC_SERVER_H
42
43#include "common.h"
44#include "certificate.h"
45#include "commands.h"
46#include "logger.h"
47#include "mpdc.h"
48#include "topology.h"
49#include "../../QSC/QSC/collection.h"
50
61
62/*---------------------------------------------------------------------------
63 MACRO DEFINITIONS
64---------------------------------------------------------------------------*/
65
70#define MPDC_SERVER_MINIMUM_COMMAND_LENGTH 4
71
79#define MPDC_SERVER_APPLICATION_STATE_SIZE (MPDC_STORAGE_DOMAINNAME_MAX + MPDC_STORAGE_HOSTNAME_MAX + \
80 MPDC_STORAGE_ADDRESS_MAX + MPDC_STORAGE_PATH_MAX + MPDC_STORAGE_USERNAME_MAX + MPDC_CERTIFICATE_ISSUER_SIZE + \
81 sizeof(uint16_t) + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint16_t) + sizeof(bool) + sizeof(bool) + \
82 MPDC_ASYMMETRIC_SIGNING_KEY_SIZE)
83
84/*---------------------------------------------------------------------------
85 ENUMERATIONS
86---------------------------------------------------------------------------*/
87
100
101/*---------------------------------------------------------------------------
102 DATA STRUCTURES
103---------------------------------------------------------------------------*/
104
115MPDC_EXPORT_API typedef struct mpdc_server_application_state
116{
117 char cmdprompt[MPDC_STORAGE_PROMPT_MAX];
118 char domain[MPDC_STORAGE_DOMAINNAME_MAX];
119 char hostname[MPDC_STORAGE_HOSTNAME_MAX];
121 char localip[MPDC_STORAGE_ADDRESS_MAX];
122 char logpath[MPDC_STORAGE_PATH_MAX];
123 char username[MPDC_STORAGE_USERNAME_MAX];
124 uint8_t* kchain;
125 uint8_t* sigkey;
126 const char* aplpath;
127 const char* banner;
128 const char* cfgname;
129 const char* prikeyname;
130 const char* promptdef;
131 const char* pubkeyname;
132 const char* srvname;
133 const char* topname;
134 const char* wtitle;
140 uint16_t port;
142 uint16_t timeout;
143 uint8_t retries;
144 bool joined;
145 bool loghost;
147
148/*---------------------------------------------------------------------------
149 FUNCTION PROTOTYPES
150---------------------------------------------------------------------------*/
151
162MPDC_EXPORT_API void mpdc_server_certificate_directory(const mpdc_server_application_state* state, char* dpath, size_t pathlen);
163
174MPDC_EXPORT_API void mpdc_server_certificate_path(const mpdc_server_application_state* state, char* fpath, size_t pathlen, const char* issuer);
175
186MPDC_EXPORT_API bool mpdc_server_child_certificate_export(const mpdc_server_application_state* state, const char* dpath);
187
199MPDC_EXPORT_API bool mpdc_server_child_certificate_from_issuer(mpdc_child_certificate* ccert, const mpdc_server_application_state* state, const char* issuer);
200
212MPDC_EXPORT_API bool mpdc_server_child_certificate_from_serial(mpdc_child_certificate* ccert, const mpdc_server_application_state* state, const uint8_t* serial);
213
224MPDC_EXPORT_API void mpdc_server_child_certificate_generate(mpdc_server_application_state* state, mpdc_child_certificate* ccert, uint64_t period);
225
237MPDC_EXPORT_API bool mpdc_server_child_certificate_import(mpdc_child_certificate* lcert, mpdc_server_application_state* state, const char* fpath);
238
248MPDC_EXPORT_API void mpdc_server_child_certificate_path(const mpdc_server_application_state* state, char* fpath, size_t pathlen);
249
260MPDC_EXPORT_API void mpdc_server_child_certificate_path_from_issuer(const mpdc_server_application_state* state, char* fpath, size_t pathlen, const char* issuer);
261
272MPDC_EXPORT_API bool mpdc_server_child_certificate_print(const char* fpath, size_t pathlen);
273
283MPDC_EXPORT_API void mpdc_server_local_certificate_store(mpdc_server_application_state* state, const mpdc_child_certificate* ccert, const char* address);
284
293
301MPDC_EXPORT_API void mpdc_server_clear_log(mpdc_server_application_state* state);
302
310MPDC_EXPORT_API void mpdc_server_erase_all(mpdc_server_application_state* state);
311
319MPDC_EXPORT_API void mpdc_server_log_host(mpdc_server_application_state* state);
320
328MPDC_EXPORT_API void mpdc_server_log_print(mpdc_server_application_state* state);
329
342MPDC_EXPORT_API bool mpdc_server_log_write_message(mpdc_server_application_state* state, mpdc_application_messages msgtype, const char* message, size_t msglen);
343
353MPDC_EXPORT_API void mpdc_server_mfkcol_path(const mpdc_server_application_state* state, char* fpath, size_t pathlen);
354
365MPDC_EXPORT_API bool mpdc_server_mfkcol_from_file(qsc_collection_state* mfkcol, const mpdc_server_application_state* state);
366
375MPDC_EXPORT_API void mpdc_server_mfkcol_to_file(const qsc_collection_state* mfkcol, const mpdc_server_application_state* state);
376
384MPDC_EXPORT_API void mpdc_server_print_banner(const mpdc_server_application_state* state);
385
396MPDC_EXPORT_API void mpdc_server_print_error(const mpdc_server_application_state* state, mpdc_application_messages appmsg, const char* message, mpdc_protocol_errors error);
397
405MPDC_EXPORT_API void mpdc_server_print_configuration(const mpdc_server_application_state* state);
406
417MPDC_EXPORT_API bool mpdc_server_root_certificate_export(const mpdc_server_application_state* state, const char* dpath);
418
429
440MPDC_EXPORT_API void mpdc_server_root_certificate_generate(mpdc_server_application_state* state, mpdc_root_certificate* rcert, uint64_t period);
441
454
465MPDC_EXPORT_API bool mpdc_server_root_certificate_print(const char* fpath, size_t pathlen);
466
477
486
498MPDC_EXPORT_API bool mpdc_server_set_console_timeout(mpdc_server_application_state* state, const char* snum, size_t numlen);
499
511MPDC_EXPORT_API bool mpdc_server_set_domain_name(mpdc_server_application_state* state, const char* name, size_t namelen);
512
524MPDC_EXPORT_API bool mpdc_server_set_host_name(mpdc_server_application_state* state, const char* name, size_t namelen);
525
537MPDC_EXPORT_API bool mpdc_server_set_ip_address(mpdc_server_application_state* state, const char* address, size_t addlen);
538
550MPDC_EXPORT_API bool mpdc_server_set_password_retries(mpdc_server_application_state* state, const char* snum, size_t numlen);
551
560
568MPDC_EXPORT_API void mpdc_server_state_backup_restore(const mpdc_server_application_state* state);
569
577MPDC_EXPORT_API void mpdc_server_state_backup_save(const mpdc_server_application_state* state);
578
588
598MPDC_EXPORT_API bool mpdc_server_state_store(mpdc_server_application_state* state);
599
608
620
631
640
649
658MPDC_EXPORT_API void mpdc_server_topology_remove_certificate(mpdc_server_application_state* state, const char* issuer);
659
668MPDC_EXPORT_API void mpdc_server_topology_remove_node(mpdc_server_application_state* state, const char* issuer);
669
678
690
700MPDC_EXPORT_API bool mpdc_server_topology_root_exists(const mpdc_server_application_state* state);
701
713
722
732MPDC_EXPORT_API bool mpdc_server_user_login(mpdc_server_application_state* state);
733
741MPDC_EXPORT_API void mpdc_server_user_logout(mpdc_server_application_state* state);
742
743#endif
MPDC Certificate Handling Functions.
The MPDC command enumerations.
mpdc_application_messages
The RDS application messages.
Definition commands.h:73
mpdc_console_modes
The RDS console modes.
Definition commands.h:331
mpdc_command_actions
The RDS command actions.
Definition commands.h:248
MPDC Logging Functions.
MPDC Common Definitions and Protocol Configuration.
#define MPDC_CERTIFICATE_ISSUER_SIZE
The maximum certificate issuer string length. The last character must be a string terminator.
Definition mpdc.h:795
mpdc_network_designations
The MPDC device designation.
Definition mpdc.h:1114
mpdc_protocol_errors
The MPDC protocol error values.
Definition mpdc.h:1219
MPDC_EXPORT_API void mpdc_server_set_command_prompt(mpdc_server_application_state *state)
Set the command prompt to the current state mode.
Definition server.c:1546
MPDC_EXPORT_API bool mpdc_server_child_certificate_from_issuer(mpdc_child_certificate *ccert, const mpdc_server_application_state *state, const char *issuer)
Get the certificate instance from file using the issuer string.
Definition server.c:703
MPDC_EXPORT_API bool mpdc_server_set_console_timeout(mpdc_server_application_state *state, const char *snum, size_t numlen)
Set the number of idle minutes before the user is logged out.
Definition server.c:1598
MPDC_EXPORT_API void mpdc_server_erase_signature_key(mpdc_server_application_state *state)
Erase the signature-scheme signing key.
Definition server.c:1827
MPDC_EXPORT_API void mpdc_server_topology_to_file(mpdc_server_application_state *state)
Copy the topology to an encrypted file.
Definition server.c:2399
MPDC_EXPORT_API bool mpdc_server_mfkcol_from_file(qsc_collection_state *mfkcol, const mpdc_server_application_state *state)
Convert an encrypted mfk collection file to a collection state.
Definition server.c:1074
MPDC_EXPORT_API void mpdc_server_mfkcol_path(const mpdc_server_application_state *state, char *fpath, size_t pathlen)
Get the path to the mfk collection file.
Definition server.c:1060
mpdc_server_server_loop_status
The MPDC server loop status.
Definition server.h:95
@ mpdc_server_loop_status_paused
Definition server.h:98
@ mpdc_server_loop_status_started
Definition server.h:97
@ mpdc_server_loop_status_stopped
Definition server.h:96
MPDC_EXPORT_API void mpdc_server_print_error(const mpdc_server_application_state *state, mpdc_application_messages appmsg, const char *message, mpdc_protocol_errors error)
Print a network error to the console.
Definition server.c:1195
MPDC_EXPORT_API void mpdc_server_print_configuration(const mpdc_server_application_state *state)
Print the server configuration.
Definition server.c:1210
MPDC_EXPORT_API bool mpdc_server_topology_dla_fetch(const mpdc_server_application_state *state, mpdc_child_certificate *dcert)
Load the DLA certificate from state.
Definition server.c:2110
MPDC_EXPORT_API void mpdc_server_certificate_path(const mpdc_server_application_state *state, char *fpath, size_t pathlen, const char *issuer)
Get the full path to a certificate.
Definition server.c:651
MPDC_EXPORT_API bool mpdc_server_topology_root_exists(const mpdc_server_application_state *state)
Check if the root certificate exists on file.
Definition server.c:2351
MPDC_EXPORT_API bool mpdc_server_topology_root_fetch(const mpdc_server_application_state *state, mpdc_root_certificate *rcert)
Load the root certificate from state.
Definition server.c:2369
MPDC_EXPORT_API void mpdc_server_topology_print_list(mpdc_server_application_state *state)
Print the topological list to the console.
Definition server.c:2235
MPDC_EXPORT_API void mpdc_server_user_logout(mpdc_server_application_state *state)
Log out of the server.
Definition server.c:2735
MPDC_EXPORT_API bool mpdc_server_topology_load(mpdc_server_application_state *state)
Load the topology from an encrypted file to state.
Definition server.c:2140
MPDC_EXPORT_API bool mpdc_server_child_certificate_import(mpdc_child_certificate *lcert, mpdc_server_application_state *state, const char *fpath)
Import the local certificate signed by the root.
Definition server.c:770
MPDC_EXPORT_API bool mpdc_server_root_certificate_print(const char *fpath, size_t pathlen)
Print a formatted root certificate to console.
Definition server.c:1449
MPDC_EXPORT_API void mpdc_server_state_unload(mpdc_server_application_state *state)
Unload the server state from memory.
Definition server.c:2098
MPDC_EXPORT_API void mpdc_server_clear_log(mpdc_server_application_state *state)
Erase the log file.
Definition server.c:932
MPDC_EXPORT_API void mpdc_server_topology_reset(mpdc_server_application_state *state)
Delete all nodes and certificates except for the root.
Definition server.c:2333
MPDC_EXPORT_API bool mpdc_server_set_domain_name(mpdc_server_application_state *state, const char *name, size_t namelen)
Rename the network domain.
Definition server.c:1635
MPDC_EXPORT_API void mpdc_server_topology_remove_certificate(mpdc_server_application_state *state, const char *issuer)
Delete the certificate.
Definition server.c:2292
MPDC_EXPORT_API void mpdc_server_erase_all(mpdc_server_application_state *state)
Erase all state, including log files, and reset configuration.
Definition server.c:946
MPDC_EXPORT_API void mpdc_server_clear_config(mpdc_server_application_state *state)
Erase and reset the configuration file.
Definition server.c:921
MPDC_EXPORT_API void mpdc_server_print_banner(const mpdc_server_application_state *state)
Print the server banner.
Definition server.c:1184
MPDC_EXPORT_API bool mpdc_server_state_store(mpdc_server_application_state *state)
Write the server state to file.
Definition server.c:2066
MPDC_EXPORT_API bool mpdc_server_root_certificate_load(const mpdc_server_application_state *state, mpdc_root_certificate *root, const mpdc_topology_list_state *tlist)
Load a root certificate using the issuer name.
Definition server.c:1391
MPDC_EXPORT_API bool mpdc_server_child_certificate_from_serial(mpdc_child_certificate *ccert, const mpdc_server_application_state *state, const uint8_t *serial)
Get the certificate instance from file using the serial number.
Definition server.c:720
MPDC_EXPORT_API void mpdc_server_certificate_directory(const mpdc_server_application_state *state, char *dpath, size_t pathlen)
Get the full delimited path to the certificate storage directory.
Definition server.c:631
MPDC_EXPORT_API void mpdc_server_state_initialize(mpdc_server_application_state *state, mpdc_network_designations srvtype)
Initialize the internal state.
Definition server.c:1941
MPDC_EXPORT_API bool mpdc_server_child_certificate_print(const char *fpath, size_t pathlen)
Print the local child certificate to console.
Definition server.c:854
MPDC_EXPORT_API void mpdc_server_log_print(mpdc_server_application_state *state)
Print the log file to the console.
Definition server.c:986
MPDC_EXPORT_API bool mpdc_server_child_certificate_export(const mpdc_server_application_state *state, const char *dpath)
Export the local certificate to a file.
Definition server.c:665
MPDC_EXPORT_API bool mpdc_server_root_import_dialogue(mpdc_server_application_state *state)
Import the root certificate.
Definition server.c:1316
MPDC_EXPORT_API void mpdc_server_state_backup_restore(const mpdc_server_application_state *state)
Restore the state from backup.
Definition server.c:1837
MPDC_EXPORT_API void mpdc_server_root_certificate_store(mpdc_server_application_state *state, const mpdc_root_certificate *rcert)
Store a root certificate to a file.
Definition server.c:1484
MPDC_EXPORT_API bool mpdc_server_log_write_message(mpdc_server_application_state *state, mpdc_application_messages msgtype, const char *message, size_t msglen)
Write a message to the log.
Definition server.c:1030
MPDC_EXPORT_API bool mpdc_server_user_login(mpdc_server_application_state *state)
Start the user login dialogue.
Definition server.c:2449
MPDC_EXPORT_API void mpdc_server_local_certificate_store(mpdc_server_application_state *state, const mpdc_child_certificate *ccert, const char *address)
Store a child certificate.
Definition server.c:889
MPDC_EXPORT_API void mpdc_server_topology_remove_node(mpdc_server_application_state *state, const char *issuer)
Remove a node from the topology.
Definition server.c:2316
MPDC_EXPORT_API bool mpdc_server_root_certificate_export(const mpdc_server_application_state *state, const char *dpath)
Export the root certificate to a directory.
Definition server.c:1278
MPDC_EXPORT_API void mpdc_server_child_certificate_path_from_issuer(const mpdc_server_application_state *state, char *fpath, size_t pathlen, const char *issuer)
Get the certificate file path from the certificate issuer name.
Definition server.c:840
MPDC_EXPORT_API void mpdc_server_root_certificate_generate(mpdc_server_application_state *state, mpdc_root_certificate *rcert, uint64_t period)
Generate a new root certificate.
Definition server.c:1363
MPDC_EXPORT_API void mpdc_server_log_host(mpdc_server_application_state *state)
Enable logging on the server.
Definition server.c:958
MPDC_EXPORT_API void mpdc_server_state_backup_save(const mpdc_server_application_state *state)
Backup the state.
Definition server.c:1895
MPDC_EXPORT_API bool mpdc_server_set_host_name(mpdc_server_application_state *state, const char *name, size_t namelen)
Rename the server host.
Definition server.c:1693
MPDC_EXPORT_API bool mpdc_server_set_ip_address(mpdc_server_application_state *state, const char *address, size_t addlen)
Set the IP address of the server.
Definition server.c:1750
MPDC_EXPORT_API void mpdc_server_topology_purge_externals(mpdc_server_application_state *state)
Clear the topology list except for the root and local nodes.
Definition server.c:2267
MPDC_EXPORT_API bool mpdc_server_topology_local_fetch(const mpdc_server_application_state *state, mpdc_child_certificate *ccert)
Load the local certificate from state.
Definition server.c:2205
MPDC_EXPORT_API bool mpdc_server_set_password_retries(mpdc_server_application_state *state, const char *snum, size_t numlen)
Set the number of failed password retries.
Definition server.c:1791
MPDC_EXPORT_API void mpdc_server_child_certificate_path(const mpdc_server_application_state *state, char *fpath, size_t pathlen)
Get the full path to the child certificate.
Definition server.c:827
MPDC_EXPORT_API void mpdc_server_child_certificate_generate(mpdc_server_application_state *state, mpdc_child_certificate *ccert, uint64_t period)
Generate a new child certificate.
Definition server.c:742
MPDC_EXPORT_API void mpdc_server_mfkcol_to_file(const qsc_collection_state *mfkcol, const mpdc_server_application_state *state)
Convert an mfk collection to an encrypted file.
Definition server.c:1140
The child certificate structure.
Definition mpdc.h:1293
The root certificate structure.
Definition mpdc.h:1411
The MPDC server state.
Definition server.h:116
uint8_t * kchain
Definition server.h:124
char hostname[MPDC_STORAGE_HOSTNAME_MAX]
Definition server.h:119
const char * aplpath
Definition server.h:126
const char * pubkeyname
Definition server.h:131
const char * srvname
Definition server.h:132
const char * promptdef
Definition server.h:130
uint8_t retries
Definition server.h:143
mpdc_root_certificate root
Definition server.h:136
const char * prikeyname
Definition server.h:129
char logpath[MPDC_STORAGE_PATH_MAX]
Definition server.h:122
char issuer[MPDC_CERTIFICATE_ISSUER_SIZE]
Definition server.h:120
mpdc_topology_list_state tlist
Definition server.h:137
mpdc_console_modes mode
Definition server.h:139
bool loghost
Definition server.h:145
uint16_t timeout
Definition server.h:142
const char * banner
Definition server.h:127
uint8_t * sigkey
Definition server.h:125
mpdc_command_actions action
Definition server.h:138
uint16_t port
Definition server.h:140
const char * topname
Definition server.h:133
char localip[MPDC_STORAGE_ADDRESS_MAX]
Definition server.h:121
bool joined
Definition server.h:144
mpdc_network_designations srvtype
Definition server.h:141
mpdc_child_certificate dla
Definition server.h:135
char username[MPDC_STORAGE_USERNAME_MAX]
Definition server.h:123
char cmdprompt[MPDC_STORAGE_PROMPT_MAX]
Definition server.h:117
char domain[MPDC_STORAGE_DOMAINNAME_MAX]
Definition server.h:118
const char * wtitle
Definition server.h:134
const char * cfgname
Definition server.h:128
The MPDC topology list structure.
Definition topology.h:185
The MPDC topology functions.