GNUnet debian-0.24.3-29-g453fda2cf
 
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--2025 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_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE \
34 - GNUNET_MIN_MESSAGE_SIZE)
35
36#define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char))
37#define GNUNET_MESSENGER_PADDING_LEVEL0 (512)
38#define GNUNET_MESSENGER_PADDING_LEVEL1 (4096)
39#define GNUNET_MESSENGER_PADDING_LEVEL2 (32768)
40
49
57copy_message (const struct GNUNET_MESSENGER_Message *message);
58
66void
69
75void
77
83void
85
94
102uint16_t
104 enum GNUNET_GenericReturnValue include_header);
105
113uint16_t
114get_message_size (const struct GNUNET_MESSENGER_Message *message,
115 enum GNUNET_GenericReturnValue include_header);
116
125void
126encode_message (const struct GNUNET_MESSENGER_Message *message,
127 uint16_t length,
128 char *buffer,
129 enum GNUNET_GenericReturnValue include_header);
130
148 uint16_t length,
149 const char *buffer,
150 enum GNUNET_GenericReturnValue include_header,
151 uint16_t *padding);
152
162void
163hash_message (const struct GNUNET_MESSENGER_Message *message,
164 uint16_t length,
165 const char *buffer,
166 struct GNUNET_HashCode *hash);
167
178void
180 uint16_t length,
181 char *buffer,
182 const struct GNUNET_HashCode *hash,
183 const struct GNUNET_CRYPTO_PrivateKey *key);
184
195void
197 uint16_t length,
198 char *buffer,
199 const struct GNUNET_HashCode *hash,
200 const struct GNUNET_CONFIGURATION_Handle *cfg);
201
212void
215
227verify_message (const struct GNUNET_MESSENGER_Message *message,
228 const struct GNUNET_HashCode *hash,
229 const struct GNUNET_CRYPTO_PublicKey *key);
230
243 const struct GNUNET_HashCode *hash,
244 const struct GNUNET_PeerIdentity *identity);
245
257
269 const struct GNUNET_CRYPTO_PublicKey *key);
270
282 const struct GNUNET_CRYPTO_PrivateKey *key);
283
293transcribe_message (const struct GNUNET_MESSENGER_Message *message,
294 const struct GNUNET_CRYPTO_PublicKey *key);
295
308 const union GNUNET_MESSENGER_EpochIdentifier *identifier
309 ,
311
324
335
351 shared_key);
352
366 const struct
369 shared_key);
370
380get_message_timeout (const struct GNUNET_MESSENGER_Message *message);
381
383 const void *cls,
384 struct GNUNET_MESSENGER_Message *message,
385 uint16_t length,
386 char *buffer,
387 const struct GNUNET_HashCode *hash);
388
394
408struct GNUNET_MQ_Envelope*
410 struct GNUNET_HashCode *hash,
413 const void *cls);
414
424is_peer_message (const struct GNUNET_MESSENGER_Message *message);
425
438is_service_message (const struct GNUNET_MESSENGER_Message *message);
439
450is_epoch_message (const struct GNUNET_MESSENGER_Message *message);
451
462
470const struct GNUNET_ShortHashCode*
471get_message_discourse (const struct GNUNET_MESSENGER_Message *message);
472
473#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 @44 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 verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PublicKey *key)
Verifies the signature of a given message and its hash with a specific public key.
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...
void sign_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PrivateKey *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_service_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message contains service critical information.
enum GNUNET_GenericReturnValue encrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
Encrypts a message using a given public key and replaces its body and kind with the now private encry...
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 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 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 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_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PrivateKey *key)
Decrypts a private message using a given private key and replaces its body and kind with the inner en...
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 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 extract_access_message_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_EcdhePrivateKey *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 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.
struct GNUNET_MESSENGER_Message * transcribe_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
Transcribes a message as a new transcript message using a given public key from the recipient of the ...
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.
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.
Private ECC key encoded for transmission.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
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.