PQS: Post Quantum Shell Protocol 1.1.0.0a (A2)
A quantum secure secure shell protocol
pqspolicy.h
Go to the documentation of this file.
1/* 2025-2026 Quantum Resistant Cryptographic Solutions Corporation
2 * All Rights Reserved.
3 *
4 * NOTICE:
5 * This software and all accompanying materials are the exclusive property of
6 * Quantum Resistant Cryptographic Solutions Corporation (QRCS). The intellectual
7 * and technical concepts contained herein are proprietary to QRCS and are
8 * protected under applicable Canadian, U.S., and international copyright,
9 * patent, and trade secret laws.
10 *
11 * CRYPTOGRAPHIC ALGORITHMS AND IMPLEMENTATIONS:
12 * - This software includes implementations of cryptographic primitives and
13 * algorithms that are standardized or in the public domain, such as AES
14 * and SHA-3, which are not proprietary to QRCS.
15 * - This software also includes cryptographic primitives, constructions, and
16 * algorithms designed by QRCS, including but not limited to RCS, SCB, CSX, QMAC, and
17 * related components, which are proprietary to QRCS.
18 * - All source code, implementations, protocol compositions, optimizations,
19 * parameter selections, and engineering work contained in this software are
20 * original works of QRCS and are protected under this license.
21 *
22 * LICENSE AND USE RESTRICTIONS:
23 * - This software is licensed under the Quantum Resistant Cryptographic Solutions
24 * Public Research and Evaluation License (QRCS-PREL), 2025-2026.
25 * - Permission is granted solely for non-commercial evaluation, academic research,
26 * cryptographic analysis, interoperability testing, and feasibility assessment.
27 * - Commercial use, production deployment, commercial redistribution, or
28 * integration into products or services is strictly prohibited without a
29 * separate written license agreement executed with QRCS.
30 * - Licensing and authorized distribution are solely at the discretion of QRCS.
31 *
32 * EXPERIMENTAL CRYPTOGRAPHY NOTICE:
33 * Portions of this software may include experimental, novel, or evolving
34 * cryptographic designs. Use of this software is entirely at the user's risk.
35 *
36 * DISCLAIMER:
37 * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 * IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS
39 * FOR A PARTICULAR PURPOSE, SECURITY, OR NON-INFRINGEMENT. QRCS DISCLAIMS ALL
40 * LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
41 * ARISING FROM THE USE OR MISUSE OF THIS SOFTWARE.
42 *
43 * FULL LICENSE:
44 * This software is subject to the Quantum Resistant Cryptographic Solutions
45 * Public Research and Evaluation License (QRCS-PREL), 2025-2026. The complete license terms
46 * are provided in the accompanying LICENSE file or at https://www.qrcscorp.ca.
47 *
48 * Written by: John G. Underhill
49 * Contact: contact@qrcscorp.ca
50 */
51
52#ifndef PQS_POLICY_H
53#define PQS_POLICY_H
54
55#include "pqs.h"
56
61
65#define PQS_POLICY_DATABASE_MAGIC "PQSPOLICYDB1"
66
70#define PQS_POLICY_DEFAULT_GUEST "guest"
71
75#define PQS_POLICY_DEFAULT_USER "user"
76
80#define PQS_POLICY_DEFAULT_ADMIN "admin"
81
92
96PQS_EXPORT_API typedef struct pqs_policy_record
97{
98 char name[PQS_POLICY_NAME_MAX];
99 char allowlist[PQS_POLICY_COMMAND_LIST_MAX];
100 char denylist[PQS_POLICY_COMMAND_LIST_MAX];
101 char forced[PQS_POLICY_COMMAND_MAX];
102 uint32_t privilege_mask;
104 bool enabled;
106
110PQS_EXPORT_API typedef struct pqs_policy_store
111{
112 pqs_policy_record records[PQS_POLICY_DATABASE_MAX];
113 char path[QSC_SYSTEM_MAX_PATH];
114 char guest_policy[PQS_POLICY_NAME_MAX];
115 char user_policy[PQS_POLICY_NAME_MAX];
116 char admin_policy[PQS_POLICY_NAME_MAX];
117 size_t count;
120
132PQS_EXPORT_API bool pqs_policy_store_add(pqs_policy_store* store, const char* name, pqs_policy_modes mode, uint32_t privilege_mask, bool enabled);
133
144PQS_EXPORT_API bool pqs_policy_store_add_command(pqs_policy_store* store, const char* name, const char* command, bool allowed);
145
155PQS_EXPORT_API bool pqs_policy_store_assign_privilege(pqs_policy_store* store, pqs_user_privileges privilege, const char* policy);
156
167
175PQS_EXPORT_API bool pqs_policy_command_is_safe(const char* command);
176
209PQS_EXPORT_API bool pqs_policy_store_authorize(const pqs_policy_store* store, pqs_user_privileges privilege, const char* command, const pqs_policy_record** matched);
210
220PQS_EXPORT_API bool pqs_policy_store_enable(pqs_policy_store* store, const char* name, bool enabled);
221
230PQS_EXPORT_API const pqs_policy_record* pqs_policy_store_find(const pqs_policy_store* store, const char* name);
231
240PQS_EXPORT_API pqs_policy_record* pqs_policy_store_find_mutable(pqs_policy_store* store, const char* name);
241
250PQS_EXPORT_API bool pqs_policy_store_initialize(pqs_policy_store* store, const char* path);
251
260PQS_EXPORT_API bool pqs_policy_store_remove(pqs_policy_store* store, const char* name);
261
272PQS_EXPORT_API bool pqs_policy_store_remove_command(pqs_policy_store* store, const char* name, const char* command, bool allowed);
273
281PQS_EXPORT_API bool pqs_policy_store_save(const pqs_policy_store* store);
282
292PQS_EXPORT_API bool pqs_policy_store_set_forced(pqs_policy_store* store, const char* name, const char* command);
293
303PQS_EXPORT_API bool pqs_policy_store_set_mode(pqs_policy_store* store, const char* name, pqs_policy_modes mode);
304
312PQS_EXPORT_API const char* pqs_policy_mode_to_string(pqs_policy_modes mode);
313
321PQS_EXPORT_API pqs_policy_modes pqs_policy_mode_from_string(const char* value);
322
330PQS_EXPORT_API uint32_t pqs_policy_privilege_to_mask(pqs_user_privileges privilege);
331
332#endif
PQS_EXPORT_API bool pqs_policy_store_assign_privilege(pqs_policy_store *store, pqs_user_privileges privilege, const char *policy)
Assign a named policy to a privilege level.
Definition pqspolicy.c:566
PQS_EXPORT_API bool pqs_policy_store_set_mode(pqs_policy_store *store, const char *name, pqs_policy_modes mode)
Set the enforcement mode of a command policy.
Definition pqspolicy.c:973
PQS_EXPORT_API bool pqs_policy_store_remove(pqs_policy_store *store, const char *name)
Remove a command policy record from a policy store.
Definition pqspolicy.c:828
PQS_EXPORT_API bool pqs_policy_store_remove_command(pqs_policy_store *store, const char *name, const char *command, bool allowed)
Remove a command verb from a policy allow-list or deny-list.
Definition pqspolicy.c:864
PQS_EXPORT_API bool pqs_policy_store_save(const pqs_policy_store *store)
Save a command policy store to persistent storage.
Definition pqspolicy.c:894
PQS_EXPORT_API bool pqs_policy_store_add_command(pqs_policy_store *store, const char *name, const char *command, bool allowed)
Add a command verb to a policy allow-list or deny-list.
Definition pqspolicy.c:538
PQS_EXPORT_API bool pqs_policy_store_set_forced(pqs_policy_store *store, const char *name, const char *command)
Set the forced command associated with a command policy.
Definition pqspolicy.c:953
PQS_EXPORT_API bool pqs_policy_store_initialize(pqs_policy_store *store, const char *path)
Initialize a command policy store from persistent storage.
Definition pqspolicy.c:758
PQS_EXPORT_API const pqs_policy_record * pqs_policy_store_find(const pqs_policy_store *store, const char *name)
Find a command policy record by name.
Definition pqspolicy.c:710
PQS_EXPORT_API uint32_t pqs_policy_privilege_to_mask(pqs_user_privileges privilege)
Convert a PQS user privilege level to a policy privilege mask.
Definition pqspolicy.c:1047
PQS_EXPORT_API const char * pqs_policy_mode_to_string(pqs_policy_modes mode)
Convert a policy mode enumeration value to a string.
Definition pqspolicy.c:992
PQS_EXPORT_API bool pqs_policy_store_add(pqs_policy_store *store, const char *name, pqs_policy_modes mode, uint32_t privilege_mask, bool enabled)
Add a command policy record to a policy store.
Definition pqspolicy.c:515
PQS_EXPORT_API bool pqs_policy_command_is_safe(const char *command)
Authorize a command for a privilege level using the active policy assignment.
Definition pqspolicy.c:601
pqs_policy_modes
Command policy execution modes.
Definition pqspolicy.h:86
@ pqs_policy_mode_none
Definition pqspolicy.h:87
@ pqs_policy_mode_raw
Definition pqspolicy.h:90
@ pqs_policy_mode_restricted
Definition pqspolicy.h:88
@ pqs_policy_mode_forced
Definition pqspolicy.h:89
PQS_EXPORT_API bool pqs_policy_store_authorize(const pqs_policy_store *store, pqs_user_privileges privilege, const char *command, const pqs_policy_record **matched)
Authorizes a command request against the policy assigned to a privilege class.
Definition pqspolicy.c:641
PQS_EXPORT_API pqs_policy_modes pqs_policy_mode_from_string(const char *value)
Convert a policy mode string to a policy mode enumeration value.
Definition pqspolicy.c:1018
PQS_EXPORT_API bool pqs_policy_store_enable(pqs_policy_store *store, const char *name, bool enabled)
Enable or disable a command policy record.
Definition pqspolicy.c:691
PQS_EXPORT_API pqs_policy_record * pqs_policy_store_find_mutable(pqs_policy_store *store, const char *name)
Find a mutable command policy record by name.
Definition pqspolicy.c:734
A PQS server command policy record.
Definition pqspolicy.h:97
pqs_policy_modes mode
Definition pqspolicy.h:103
char forced[PQS_POLICY_COMMAND_MAX]
Definition pqspolicy.h:101
char denylist[PQS_POLICY_COMMAND_LIST_MAX]
Definition pqspolicy.h:100
uint32_t privilege_mask
Definition pqspolicy.h:102
bool enabled
Definition pqspolicy.h:104
char allowlist[PQS_POLICY_COMMAND_LIST_MAX]
Definition pqspolicy.h:99
char name[PQS_POLICY_NAME_MAX]
Definition pqspolicy.h:98
The fixed-size PQS command policy database.
Definition pqspolicy.h:111
char user_policy[PQS_POLICY_NAME_MAX]
Definition pqspolicy.h:115
char guest_policy[PQS_POLICY_NAME_MAX]
Definition pqspolicy.h:114
size_t count
Definition pqspolicy.h:117
char path[QSC_SYSTEM_MAX_PATH]
Definition pqspolicy.h:113
char admin_policy[PQS_POLICY_NAME_MAX]
Definition pqspolicy.h:116
pqs_policy_record records[PQS_POLICY_DATABASE_MAX]
Definition pqspolicy.h:112
bool initialized
Definition pqspolicy.h:118