ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
policy.c
Go to the documentation of this file.
3
5 if (!policy || !mode)
6 return SET_ERRNO(ERROR_INVALID_PARAM, "Missing crypto policy or result");
7 if (policy->encrypt && policy->no_encrypt)
8 return SET_ERRNO(ERROR_INVALID_PARAM, "--encrypt and --no-encrypt are mutually exclusive");
9 bool authentication = policy->has_password || policy->has_identity || policy->has_verification_key;
10 if (policy->no_auth && authentication)
11 return SET_ERRNO(ERROR_INVALID_PARAM, "Authentication material cannot be used with --no-auth");
12 bool encryption = !policy->no_encrypt && (policy->encrypt || policy->has_password || !policy->transport_secure);
13 *mode = (encryption ? ACIP_CRYPTO_ENCRYPT : 0) | (authentication ? ACIP_CRYPTO_AUTH : 0);
14 return ASCIICHAT_OK;
15}
16
17asciichat_error_t crypto_policy_check_mode(bool transport_secure, bool encrypt, bool no_encrypt, bool require_auth,
18 uint8_t mode) {
19 if (mode > ACIP_CRYPTO_FULL || (encrypt && no_encrypt))
20 return SET_ERRNO(ERROR_CRYPTO, "Invalid security policy");
21 if (require_auth && !ACIP_CRYPTO_HAS_AUTH(mode))
22 return SET_ERRNO(ERROR_CRYPTO_AUTH, "Server requires authentication");
23 if ((encrypt || (!transport_secure && !no_encrypt)) && !ACIP_CRYPTO_HAS_ENCRYPT(mode))
24 return SET_ERRNO(ERROR_CRYPTO, "Server requires ACIP encryption");
25 if (no_encrypt && ACIP_CRYPTO_HAS_ENCRYPT(mode))
26 return SET_ERRNO(ERROR_CRYPTO, "Server disabled ACIP encryption");
27 return ASCIICHAT_OK;
28}
#define SET_ERRNO(code,...)
unsigned char uint8_t
Definition common.h:60
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
@ ASCIICHAT_OK
Definition error_codes.h:46
@ ERROR_CRYPTO_AUTH
Definition error_codes.h:95
@ ERROR_CRYPTO
Definition error_codes.h:93
@ ERROR_INVALID_PARAM
#define ACIP_CRYPTO_HAS_AUTH(mode)
Check if crypto mode includes authentication.
Definition packet.h:1155
#define ACIP_CRYPTO_HAS_ENCRYPT(mode)
Check if crypto mode includes payload encryption.
Definition packet.h:1148
#define ACIP_CRYPTO_ENCRYPT
Encryption only (no identity verification).
Definition packet.h:1139
#define ACIP_CRYPTO_AUTH
Authentication only (no payload encryption).
Definition packet.h:1140
#define ACIP_CRYPTO_FULL
Full crypto: encryption + authentication.
Definition packet.h:1141
asciichat_error_t crypto_policy_check_mode(bool transport_secure, bool encrypt, bool no_encrypt, bool require_auth, uint8_t mode)
Definition policy.c:17
asciichat_error_t crypto_policy_resolve(const crypto_policy_t *policy, uint8_t *mode)
Definition policy.c:4
The useful part of crypto policy is in transport_secure, encrypt, no_encrypt, no_auth: together they ...
Definition policy.h:12
bool no_encrypt
Definition policy.h:15
bool transport_secure
Definition policy.h:13
bool has_password
Definition policy.h:17
bool has_identity
Definition policy.h:18
bool has_verification_key
Definition policy.h:19