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.h File Reference

Go to the source code of this file.

Data Structures

struct  crypto_policy_t
 The useful part of crypto policy is in transport_secure, encrypt, no_encrypt, no_auth: together they describe what is pending, who owns it, and how much data is valid. Keep the object with its parent operation and use the parent cleanup path. TLS/DTLS protect the transport. Keys request authentication, not encryption. Explicit no-encrypt wins over the password default, enabling auth-only. More...

Functions

asciichat_error_t crypto_policy_check_mode (bool transport_secure, bool encrypt, bool no_encrypt, bool require_auth, uint8_t mode)
asciichat_error_t crypto_policy_resolve (const crypto_policy_t *policy, uint8_t *mode)

Function Documentation

◆ crypto_policy_check_mode()

asciichat_error_t crypto_policy_check_mode ( bool transport_secure,
bool encrypt,
bool no_encrypt,
bool require_auth,
uint8_t mode )

Validate a peer proposal against server transport and explicit encryption settings.

Definition at line 17 of file policy.c.

18 {
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,...)
@ ASCIICHAT_OK
Definition error_codes.h:46
@ ERROR_CRYPTO_AUTH
Definition error_codes.h:95
@ ERROR_CRYPTO
Definition error_codes.h:93
#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_FULL
Full crypto: encryption + authentication.
Definition packet.h:1141

References ACIP_CRYPTO_FULL, ACIP_CRYPTO_HAS_AUTH, ACIP_CRYPTO_HAS_ENCRYPT, ASCIICHAT_OK, ERROR_CRYPTO, ERROR_CRYPTO_AUTH, and SET_ERRNO.

Referenced by network_negotiation_receive().

◆ crypto_policy_resolve()

asciichat_error_t crypto_policy_resolve ( const crypto_policy_t * policy,
uint8_t * mode )

Resolve to the ACIP_CRYPTO_* wire bitmask; reject contradictory requests.

Definition at line 4 of file policy.c.

4 {
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}
@ ERROR_INVALID_PARAM
#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
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

References ACIP_CRYPTO_AUTH, ACIP_CRYPTO_ENCRYPT, ASCIICHAT_OK, crypto_policy_t::encrypt, ERROR_INVALID_PARAM, crypto_policy_t::has_identity, crypto_policy_t::has_password, crypto_policy_t::has_verification_key, crypto_policy_t::no_auth, crypto_policy_t::no_encrypt, SET_ERRNO, and crypto_policy_t::transport_secure.

Referenced by acip_security_init_options(), client_resolve_crypto_policy(), discovery_session_start(), and peer_crypto_create().