GNUnet 0.26.2-114-g7c6b613e3
 
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_common.h"
30#include "gnunet_util_lib.h"
31
32#include "gnunet_pils_service.h"
34
35#define GNUNET_MESSENGER_SALT_ANNOUNCEMENT_KEY \
36 "gnunet-messenger-announcement-key-k*d-p!80"
37#define GNUNET_MESSENGER_SALT_EPOCH_KEY \
38 "gnunet-messenger-epoch-key-ePGN3bGR-}*i$<2"
39#define GNUNET_MESSENGER_SALT_GROUP_KEY \
40 "gnunet-messenger-group-key-L)&7{4i(WSEPpR-"
41#define GNUNET_MESSENGER_SALT_SECRET_KEY \
42 "gnunet-messenger-secret-key-}xJ(eTuk[+xu{S"
43#define GNUNET_MESSENGER_SALT_ENCRYPTION_KEY \
44 "gnunet-messenger-encryption-key-9*Qaj7A+zv"
45
46#define GNUNET_MESSENGER_SALT_EPOCH_IV "gnunet-messenger-epoch-iv"
47#define GNUNET_MESSENGER_SALT_ENCRYPTION_IV "gnunet-messenger-encryption-iv"
48#define GNUNET_MESSENGER_SALT_SECRET_IV "gnunet-messenger-secret-iv"
49
50#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE (GNUNET_MAX_MESSAGE_SIZE \
51 - GNUNET_MIN_MESSAGE_SIZE)
52
53#define GNUNET_MESSENGER_PADDING_MIN (sizeof(uint16_t) + sizeof(char))
54#define GNUNET_MESSENGER_PADDING_LEVEL0 (512)
55#define GNUNET_MESSENGER_PADDING_LEVEL1 (4096)
56#define GNUNET_MESSENGER_PADDING_LEVEL2 (32768)
57
63
72
80copy_message (const struct GNUNET_MESSENGER_Message *message);
81
89void
92
98void
100
106void
108
117
125uint16_t
127 enum GNUNET_GenericReturnValue include_header);
128
136uint16_t
137get_message_size (const struct GNUNET_MESSENGER_Message *message,
138 enum GNUNET_GenericReturnValue include_header);
139
148void
150 uint16_t length,
151 char *buffer);
152
161void
162encode_message (const struct GNUNET_MESSENGER_Message *message,
163 uint16_t length,
164 char *buffer,
165 enum GNUNET_GenericReturnValue include_header);
166
184 uint16_t length,
185 const char *buffer,
186 enum GNUNET_GenericReturnValue include_header,
187 uint16_t *padding);
188
198void
199hash_message (const struct GNUNET_MESSENGER_Message *message,
200 uint16_t length,
201 const char *buffer,
202 struct GNUNET_HashCode *hash);
203
211void
213 const struct GNUNET_HashCode *hash,
215
229 const struct GNUNET_HashCode *hash,
230 struct GNUNET_PILS_Handle *pils,
232 void *cls);
233
248
260verify_message (const struct GNUNET_MESSENGER_Message *message,
261 const struct GNUNET_HashCode *hash,
263
276 const struct GNUNET_HashCode *hash,
277 const struct GNUNET_PeerIdentity *identity);
278
290
302 const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key);
303
315 const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key);
316
326transcribe_message (const struct GNUNET_MESSENGER_Message *message,
328
341 const union GNUNET_MESSENGER_EpochIdentifier *identifier
342 ,
344
357
368
382 const struct GNUNET_CRYPTO_HpkePrivateKey *key,
384 shared_key);
385
399 const struct
402 shared_key);
403
413get_message_timeout (const struct GNUNET_MESSENGER_Message *message);
414
425struct GNUNET_MQ_Envelope*
427 struct GNUNET_HashCode *hash,
429
439is_peer_message (const struct GNUNET_MESSENGER_Message *message);
440
453is_service_message (const struct GNUNET_MESSENGER_Message *message);
454
465is_epoch_message (const struct GNUNET_MESSENGER_Message *message);
466
477
485const struct GNUNET_ShortHashCode*
486get_message_discourse (const struct GNUNET_MESSENGER_Message *message);
487
488#endif // GNUNET_MESSENGER_API_MESSAGE_H
static void sign_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
Definition gnunet-abd.c:675
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_PILS_Handle * pils
Handle to PILS.
Definition gnunet-pils.c:44
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
static enum @52 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
void(* GNUNET_PILS_SignResultCallback)(void *cls, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig)
A handler/callback to be called for signatures.
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...
void encode_message_signature(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer)
Encodes the signature of a given message into a buffer of a maximum length in bytes.
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 maximum 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_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_PackMode mode)
Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_P...
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
struct GNUNET_PILS_Operation * sign_message_by_peer(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, struct GNUNET_PILS_Handle *pils, const GNUNET_PILS_SignResultCallback sign_cb, void *cls)
Signs the hash of a message with the peer identity of a given pils service going into a callback with...
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.
void sign_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
Signs the hash of a message with a given private 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...
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.
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.
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.
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 maximum 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.
A handle for the PILS service.
Definition pils_api.c:82
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.