GNUnet 0.26.2-24-g10badbb4a
 
Loading...
Searching...
No Matches
messenger_api_message.h
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2026 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
26#ifndef GNUNET_MESSENGER_API_MESSAGE_H
27#define GNUNET_MESSENGER_API_MESSAGE_H
28
29#include "gnunet_util_lib.h"
30
32
33#define GNUNET_MESSENGER_SALT_ANNOUNCEMENT_KEY "gnunet-messenger-announcement-key-k*d-p!80"
34#define GNUNET_MESSENGER_SALT_EPOCH_KEY "gnunet-messenger-epoch-key-ePGN3bGR-}*i$<2"
35#define GNUNET_MESSENGER_SALT_GROUP_KEY "gnunet-messenger-group-key-L)&7{4i(WSEPpR-"
36#define GNUNET_MESSENGER_SALT_SECRET_KEY "gnunet-messenger-secret-key-}xJ(eTuk[+xu{S"
37#define GNUNET_MESSENGER_SALT_ENCRYPTION_KEY "gnunet-messenger-encryption-key-9*Qaj7A+zv"
38
39#define GNUNET_MESSENGER_SALT_EPOCH_IV "gnunet-messenger-epoch-iv"
40#define GNUNET_MESSENGER_SALT_ENCRYPTION_IV "gnunet-messenger-encryption-iv"
41#define GNUNET_MESSENGER_SALT_SECRET_IV "gnunet-messenger-secret-iv"
42
43#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE \
44 - GNUNET_MIN_MESSAGE_SIZE)
45
46#define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char))
47#define GNUNET_MESSENGER_PADDING_LEVEL0 (512)
48#define GNUNET_MESSENGER_PADDING_LEVEL1 (4096)
49#define GNUNET_MESSENGER_PADDING_LEVEL2 (32768)
50
59
67copy_message (const struct GNUNET_MESSENGER_Message *message);
68
76void
79
85void
87
93void
95
104
112uint16_t
114 enum GNUNET_GenericReturnValue include_header);
115
123uint16_t
124get_message_size (const struct GNUNET_MESSENGER_Message *message,
125 enum GNUNET_GenericReturnValue include_header);
126
135void
136encode_message (const struct GNUNET_MESSENGER_Message *message,
137 uint16_t length,
138 char *buffer,
139 enum GNUNET_GenericReturnValue include_header);
140
158 uint16_t length,
159 const char *buffer,
160 enum GNUNET_GenericReturnValue include_header,
161 uint16_t *padding);
162
172void
173hash_message (const struct GNUNET_MESSENGER_Message *message,
174 uint16_t length,
175 const char *buffer,
176 struct GNUNET_HashCode *hash);
177
188void
190 uint16_t length,
191 char *buffer,
192 const struct GNUNET_HashCode *hash,
194
205void
207 uint16_t length,
208 char *buffer,
209 const struct GNUNET_HashCode *hash,
210 const struct GNUNET_CONFIGURATION_Handle *cfg);
211
226
238verify_message (const struct GNUNET_MESSENGER_Message *message,
239 const struct GNUNET_HashCode *hash,
241
254 const struct GNUNET_HashCode *hash,
255 const struct GNUNET_PeerIdentity *identity);
256
268
280 const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key);
281
293 const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key);
294
304transcribe_message (const struct GNUNET_MESSENGER_Message *message,
306
319 const union GNUNET_MESSENGER_EpochIdentifier *identifier
320 ,
322
335
346
360 const struct GNUNET_CRYPTO_HpkePrivateKey *key,
362 shared_key);
363
377 const struct
380 shared_key);
381
391get_message_timeout (const struct GNUNET_MESSENGER_Message *message);
392
394 const void *cls,
395 struct GNUNET_MESSENGER_Message *message,
396 uint16_t length,
397 char *buffer,
398 const struct GNUNET_HashCode *hash);
399
405
419struct GNUNET_MQ_Envelope*
421 struct GNUNET_HashCode *hash,
424 const void *cls);
425
435is_peer_message (const struct GNUNET_MESSENGER_Message *message);
436
449is_service_message (const struct GNUNET_MESSENGER_Message *message);
450
461is_epoch_message (const struct GNUNET_MESSENGER_Message *message);
462
473
481const struct GNUNET_ShortHashCode*
482get_message_discourse (const struct GNUNET_MESSENGER_Message *message);
483
484#endif // GNUNET_MESSENGER_API_MESSAGE_H
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
static enum @49 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
GNUNET_GenericReturnValue
Named constants for return values.
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
enum GNUNET_GenericReturnValue encrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
Encrypts a message using a given public key and replaces its body and kind with the now private encry...
enum GNUNET_GenericReturnValue extract_access_message_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
Extracts the shared epoch or group key from an access message using the private ephemeral key from an...
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
Encodes a given message into a buffer of a maximal length in bytes.
struct GNUNET_TIME_Relative get_message_timeout(const struct GNUNET_MESSENGER_Message *message)
Return the relative timeout of the content from a given message that controls when a delayed handling...
enum GNUNET_GenericReturnValue is_service_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message contains service critical information.
enum GNUNET_GenericReturnValue verify_message_by_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Verifies the hmac of a given message body with a specific shared key.
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
GNUNET_MESSENGER_PackMode
@ GNUNET_MESSENGER_PACK_MODE_UNKNOWN
@ GNUNET_MESSENGER_PACK_MODE_ENVELOPE
enum GNUNET_GenericReturnValue filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message should be sent by a client.
enum GNUNET_GenericReturnValue verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Verifies the signature of a given message and its hash with a specific public key.
enum GNUNET_GenericReturnValue extract_authorization_message_key(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
Extracts the shared epoch or group key from an authorization message using a previously exchanged sha...
enum GNUNET_GenericReturnValue decrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key)
Decrypts a private message using a given private key and replaces its body and kind with the inner en...
void sign_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
Signs the hash of a message with a given private key and writes the signature into the buffer as well...
enum GNUNET_GenericReturnValue is_peer_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message can be sent by the service without usage of a clients priv...
const struct GNUNET_ShortHashCode * get_message_discourse(const struct GNUNET_MESSENGER_Message *message)
Returns the discourse hash of a message depending on its kind.
enum GNUNET_GenericReturnValue sign_message_by_key(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Signs the message body via it's own hmac with a specific shared key.
enum GNUNET_GenericReturnValue is_epoch_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a certain kind of message from storage contains some specific details that might be r...
enum GNUNET_GenericReturnValue verify_message_by_peer(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_PeerIdentity *identity)
Verifies the signature of a given message and its hash with a specific peer's identity.
void hash_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer with a length in bytes from a message.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, const GNUNET_MESSENGER_SignFunction sign, enum GNUNET_MESSENGER_PackMode mode, const void *cls)
Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_P...
enum GNUNET_GenericReturnValue decrypt_secret_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Decrypts a secret message using a given shared key and replaces its body and kind with the inner encr...
void copy_message_header(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_MessageHeader *header)
Copy message header details from another message to a given message.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
void(* GNUNET_MESSENGER_SignFunction)(const void *cls, struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash)
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind, enum GNUNET_GenericReturnValue include_header)
Returns the minimal size in bytes to encode a message of a specific kind.
void sign_message_by_peer(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CONFIGURATION_Handle *cfg)
Signs the hash of a message with the peer identity of a given config and writes the signature into th...
enum GNUNET_GenericReturnValue read_transcript_message(struct GNUNET_MESSENGER_Message *message)
Read the original message from a transcript message and replaces its body and kind with the inner enc...
enum GNUNET_GenericReturnValue is_message_session_bound(const struct GNUNET_MESSENGER_Message *message)
Returns if the message should be bound to a member session.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, enum GNUNET_GenericReturnValue include_header)
Returns the exact size in bytes to encode a given message.
enum GNUNET_GenericReturnValue decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, enum GNUNET_GenericReturnValue include_header, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
struct GNUNET_MESSENGER_Message * transcribe_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Transcribes a message as a new transcript message using a given public key from the recipient of the ...
enum GNUNET_GenericReturnValue encrypt_secret_message(struct GNUNET_MESSENGER_Message *message, const union GNUNET_MESSENGER_EpochIdentifier *identifier, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Encrypts a message using a given shared key from an announcement of an epoch and replaces its body an...
void cleanup_message(struct GNUNET_MESSENGER_Message *message)
Frees the messages body memory.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
A public key used for decryption.
A public key used for encryption.
A 512-bit hashcode.
The header of a GNUNET_MESSENGER_Message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
Time for relative time used by GNUnet, in microseconds.
An epoch identifier unifies an epoch identifier code and its 256bit hash representation.