ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
policy.c
Go to the documentation of this file.
3
5 uint8_t *mode) {
6 if (!policy || !mode)
7 return SET_ERRNO(ERROR_INVALID_PARAM, "Missing crypto policy or result");
8 if (policy->encrypt && policy->no_encrypt)
10 "--encrypt and --no-encrypt are mutually exclusive");
11 bool authentication = policy->has_password || policy->has_identity ||
13 if (policy->no_auth && authentication)
15 "Authentication material cannot be used with --no-auth");
16 bool encryption =
17 !policy->no_encrypt &&
18 (policy->encrypt || policy->has_password || !policy->transport_secure);
19 *mode = (encryption ? ACIP_CRYPTO_ENCRYPT : 0) |
20 (authentication ? ACIP_CRYPTO_AUTH : 0);
21 return ASCIICHAT_OK;
22}
23
24asciichat_error_t crypto_policy_check_mode(bool transport_secure, bool encrypt,
25 bool no_encrypt, bool require_auth,
26 uint8_t mode) {
27 if (mode > ACIP_CRYPTO_FULL || (encrypt && no_encrypt))
28 return SET_ERRNO(ERROR_CRYPTO, "Invalid security policy");
29 if (require_auth && !ACIP_CRYPTO_HAS_AUTH(mode))
30 return SET_ERRNO(ERROR_CRYPTO_AUTH, "Server requires authentication");
31 if ((encrypt || (!transport_secure && !no_encrypt)) &&
33 return SET_ERRNO(ERROR_CRYPTO, "Server requires ACIP encryption");
34 if (no_encrypt && ACIP_CRYPTO_HAS_ENCRYPT(mode))
35 return SET_ERRNO(ERROR_CRYPTO, "Server disabled ACIP encryption");
36 return ASCIICHAT_OK;
37}
#define SET_ERRNO(code,...)
unsigned char uint8_t
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_CRYPTO_AUTH
@ ERROR_CRYPTO
@ ERROR_INVALID_PARAM
#define ACIP_CRYPTO_HAS_AUTH(mode)
Check if crypto mode includes authentication.
Definition packet.h:1178
#define ACIP_CRYPTO_HAS_ENCRYPT(mode)
Check if crypto mode includes payload encryption.
Definition packet.h:1171
#define ACIP_CRYPTO_ENCRYPT
Encryption only (no identity verification).
Definition packet.h:1162
#define ACIP_CRYPTO_AUTH
Authentication only (no payload encryption).
Definition packet.h:1163
#define ACIP_CRYPTO_FULL
Full crypto: encryption + authentication.
Definition packet.h:1164
asciichat_error_t crypto_policy_check_mode(bool transport_secure, bool encrypt, bool no_encrypt, bool require_auth, uint8_t mode)
Definition policy.c:24
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:19
bool no_encrypt
Definition policy.h:22
bool transport_secure
Definition policy.h:20
bool has_password
Definition policy.h:24
bool has_identity
Definition policy.h:25
bool has_verification_key
Definition policy.h:26