GNUnet 0.28.1-dev.4-8-g14b9efcb0
 
Loading...
Searching...
No Matches
gnunet-service-core_kx.h File Reference

code for managing the key exchange (SET_KEY, PING, PONG) with other peers More...

Include dependency graph for gnunet-service-core_kx.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  InitiatorHelloPayload
 
struct  InitiatorHello
 TODO. More...
 
struct  ConfirmationAck
 The ACK. More...
 
struct  ResponderHello
 ResponderHello. More...
 
struct  ResponderHelloPayload
 
struct  InitiatorDone
 InitiatorDone. More...
 
struct  EncryptedMessage
 EncryptedMessage. More...
 
struct  Heartbeat
 KeyUpdate. More...
 

Enumerations

enum  HeartbeatFlags { GSC_HEARTBEAT_KEY_UPDATE_REQUESTED = 1 }
 Heartbeat flags. More...
 

Functions

void GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, const void *payload, size_t payload_size)
 Encrypt and transmit a message with the given payload.
 
int GSC_KX_init (void)
 Initialize KX subsystem.
 
void GSC_KX_done (void)
 Shutdown KX subsystem.
 
int GSC_NEIGHBOURS_check_excess_bandwidth (const struct GSC_KeyExchangeInfo *target)
 Check if the given neighbour has excess bandwidth available.
 
unsigned int GSC_NEIGHBOURS_get_queue_length (const struct GSC_KeyExchangeInfo *target)
 Check how many messages are queued for the given neighbour.
 
void GSC_KX_handle_client_monitor_peers (struct GNUNET_MQ_Handle *mq)
 Handle GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS request.
 

Detailed Description

code for managing the key exchange (SET_KEY, PING, PONG) with other peers

Author
Christian Grothoff

Definition in file gnunet-service-core_kx.h.

Enumeration Type Documentation

◆ HeartbeatFlags

Heartbeat flags.

Enumerator
GSC_HEARTBEAT_KEY_UPDATE_REQUESTED 

A key update is requested.

Definition at line 225 of file gnunet-service-core_kx.h.

226{
231
232};
@ GSC_HEARTBEAT_KEY_UPDATE_REQUESTED
A key update is requested.

Function Documentation

◆ GSC_KX_encrypt_and_transmit()

void GSC_KX_encrypt_and_transmit ( struct GSC_KeyExchangeInfo kx,
const void *  payload,
size_t  payload_size 
)

Encrypt and transmit a message with the given payload.

Parameters
kxkey exchange context
payloadpayload of the message
payload_sizenumber of bytes in 'payload'

Encrypt and transmit a message with the given payload.

Parameters
kxkey exchange info
payloadthe payload
payload_sizesize of the payload

Definition at line 3439 of file gnunet-service-core_kx.c.

3442{
3443 struct GNUNET_MQ_Envelope *env;
3444 struct EncryptedMessage *encrypted_msg;
3445 unsigned char enc_key[AEAD_KEY_BYTES];
3446 unsigned char enc_nonce[AEAD_NONCE_BYTES];
3447 unsigned char seq_enc_k[crypto_stream_chacha20_ietf_KEYBYTES];
3448 uint64_t sqn;
3449 uint64_t epoch;
3450 int8_t ret;
3451
3452 encrypted_msg = NULL;
3453
3454 if (GNUNET_YES != kx->association_up)
3455 {
3456 /* No application traffic keys installed -- there is nothing to protect
3457 this with. Callers reach this through a session, which only exists
3458 while the association does, so this is a should-not-happen. */
3459 GNUNET_break (0);
3460 return;
3461 }
3462 if (GNUNET_OK != check_rekey (kx))
3463 return; /* association was torn down, @e current_ats is gone */
3464 sqn = kx->current_sqn;
3465 epoch = kx->current_epoch;
3466 /* We are the sender and as we are going to send,
3467 * we are using the initiator key material */
3469 sqn,
3470 enc_key,
3471 enc_nonce);
3472 kx->current_sqn++;
3473 derive_sn (&kx->current_ats,
3474 seq_enc_k,
3475 sizeof seq_enc_k);
3476 env = GNUNET_MQ_msg_extra (encrypted_msg,
3477 payload_size,
3479 // only encrypt the payload for now
3480 // TODO encrypt other fields as well
3481 ret = crypto_aead_xchacha20poly1305_ietf_encrypt_detached (
3482 (unsigned char*) &encrypted_msg[1], // c - resulting ciphertext
3483 (unsigned char*) &encrypted_msg->tag, // mac - resulting mac/tag
3484 NULL, // maclen
3485 (unsigned char*) payload, // m - plain message
3486 payload_size, // mlen
3487 NULL, // ad - additional data TODO also cover the unencrypted part (epoch)
3488 0, // adlen
3489 NULL, // nsec - unused
3490 enc_nonce, // npub nonce
3491 enc_key // k - key
3492 );
3493 if (0 != ret)
3494 {
3496 "Something went wrong encrypting message\n");
3497 GNUNET_assert (0);
3498 }
3499 {
3500 /* compute the sequence number */
3501 unsigned char *seq_enc_nonce;
3502 uint64_t seq_nbo;
3503 uint32_t seq_enc_ctr;
3504
3505 seq_nbo = GNUNET_htonll (sqn);
3506 seq_enc_ctr = *((uint32_t*) encrypted_msg->tag);
3507 seq_enc_nonce = &encrypted_msg->tag[sizeof (uint32_t)];
3508 crypto_stream_chacha20_ietf_xor_ic (
3509 (unsigned char*) &encrypted_msg->sequence_number,
3510 (unsigned char*) &seq_nbo,
3511 sizeof seq_nbo,
3512 seq_enc_nonce,
3513 ntohl (seq_enc_ctr),
3514 seq_enc_k);
3515#if DEBUG_KX
3516 GNUNET_print_bytes (seq_enc_k,
3517 sizeof seq_enc_k,
3518 8,
3519 GNUNET_NO);
3520 GNUNET_print_bytes ((char*) &seq_enc_ctr,
3521 sizeof seq_enc_ctr,
3522 8,
3523 GNUNET_NO);
3524#endif
3526 "Sending encrypted message with E(SQN=%" PRIu64 ")=%" PRIu64
3527 "\n",
3528 sqn,
3529 encrypted_msg->sequence_number);
3530 }
3531 encrypted_msg->epoch = GNUNET_htonll (epoch);
3532
3533 // TODO actually copy payload
3534 GNUNET_MQ_send (kx->mq, env);
3535}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static int ret
Final status code.
Definition gnunet-arm.c:93
#define AEAD_NONCE_BYTES
libsodium has very long symbol names
static void derive_per_message_secrets(const struct GNUNET_ShortHashCode *ts, uint64_t seq, unsigned char key[crypto_aead_xchacha20poly1305_ietf_KEYBYTES], unsigned char nonce[crypto_aead_xchacha20poly1305_ietf_NPUBBYTES])
key = HKDF-Expand [I,R][A,H]TS, "key", 32) nonce = HKDF-Expand ([I,R][A,H]TS, "iv",...
#define AEAD_KEY_BYTES
libsodium has very long symbol names
static void derive_sn(const struct GNUNET_ShortHashCode *secret, unsigned char *sn, size_t sn_len)
static enum GNUNET_GenericReturnValue check_rekey(struct GSC_KeyExchangeInfo *kx)
Move to the next epoch if the current one is exhausted.
static unsigned long long payload
How much data are we currently storing in the database?
#define GNUNET_log(kind,...)
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
void GNUNET_print_bytes(const void *buf, size_t buf_len, int fold, int in_be)
Print a byte string in hexadecimal ascii notation.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition mq.c:337
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE_CAKE
Encrypted message.
uint64_t current_sqn
Our current sequence number.
struct GNUNET_MQ_Handle * mq
Message queue for sending messages to peer.
int association_up
GNUNET_YES once application traffic keys are installed for this peer, i.e.
uint64_t current_epoch
Our currently used epoch for sending.
struct GNUNET_ShortHashCode current_ats
*ATS - our current application traffic secret by epoch

References AEAD_KEY_BYTES, AEAD_NONCE_BYTES, GSC_KeyExchangeInfo::association_up, check_rekey(), GSC_KeyExchangeInfo::current_ats, GSC_KeyExchangeInfo::current_epoch, GSC_KeyExchangeInfo::current_sqn, derive_per_message_secrets(), derive_sn(), env, EncryptedMessage::epoch, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_htonll(), GNUNET_log, GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE_CAKE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_print_bytes(), GNUNET_YES, GSC_KeyExchangeInfo::mq, payload, ret, EncryptedMessage::sequence_number, and EncryptedMessage::tag.

Referenced by handle_heartbeat(), handle_initiator_done(), send_heartbeat(), and try_transmission().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_KX_init()

int GSC_KX_init ( void  )

Initialize KX subsystem.

Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 3627 of file gnunet-service-core_kx.c.

3628{
3631 NULL);
3632 if (NULL == GSC_pils)
3633 {
3634 GSC_KX_done ();
3635 return GNUNET_SYSERR;
3636 }
3637
3638 return GNUNET_OK;
3639}
const struct GNUNET_CONFIGURATION_Handle * GSC_cfg
Our configuration.
struct GNUNET_PILS_Handle * GSC_pils
For peer identity access.
void GSC_KX_done()
Shutdown KX subsystem.
void pid_change_cb(void *cls, const struct GNUNET_HELLO_Parser *parser, const struct GNUNET_HashCode *hash)
struct GNUNET_PILS_Handle * GNUNET_PILS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
Connect to the PILS service.
Definition pils_api.c:624
@ GNUNET_SYSERR

References GNUNET_OK, GNUNET_PILS_connect(), GNUNET_SYSERR, GSC_cfg, GSC_KX_done(), GSC_pils, and pid_change_cb().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_KX_done()

void GSC_KX_done ( void  )

Shutdown KX subsystem.

Definition at line 3646 of file gnunet-service-core_kx.c.

3647{
3648 if (NULL != GSC_pils)
3649 {
3651 GSC_pils = NULL;
3652 }
3653 if (NULL != transport)
3654 {
3656 transport = NULL;
3657 }
3658 if (NULL != rekey_task)
3659 {
3661 rekey_task = NULL;
3662 }
3663 if (NULL != nc)
3664 {
3666 nc = NULL;
3667 }
3668}
static struct GNUNET_NotificationContext * nc
Notification context for broadcasting to monitors.
static struct GNUNET_SCHEDULER_Task * rekey_task
Task scheduled for periodic re-generation (and thus rekeying) of our ephemeral key.
static struct GNUNET_TRANSPORT_CoreHandle * transport
Transport service.
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition pils_api.c:647
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
Definition nc.c:138
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986

References GNUNET_notification_context_destroy(), GNUNET_PILS_disconnect(), GNUNET_SCHEDULER_cancel(), GNUNET_TRANSPORT_core_disconnect(), GSC_pils, nc, rekey_task, and transport.

Referenced by GSC_KX_init(), GSC_KX_start(), and shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_NEIGHBOURS_check_excess_bandwidth()

int GSC_NEIGHBOURS_check_excess_bandwidth ( const struct GSC_KeyExchangeInfo target)

Check if the given neighbour has excess bandwidth available.

Parameters
targetneighbour to check
Returns
GNUNET_YES if excess bandwidth is available, GNUNET_NO if not

Definition at line 3685 of file gnunet-service-core_kx.c.

3686{
3687 return kxinfo->has_excess_bandwidth;
3688}

References GSC_KeyExchangeInfo::has_excess_bandwidth.

Referenced by try_transmission().

Here is the caller graph for this function:

◆ GSC_NEIGHBOURS_get_queue_length()

unsigned int GSC_NEIGHBOURS_get_queue_length ( const struct GSC_KeyExchangeInfo kxinfo)

Check how many messages are queued for the given neighbour.

Parameters
targetneighbour to check
Returns
number of items in the message queue
Parameters
kxinfodata about neighbour to check
Returns
number of items in the message queue

Definition at line 3678 of file gnunet-service-core_kx.c.

3679{
3680 return GNUNET_MQ_get_length (kxinfo->mq);
3681}
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition mq.c:325

References GNUNET_MQ_get_length(), and GSC_KeyExchangeInfo::mq.

Referenced by try_transmission().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_KX_handle_client_monitor_peers()

void GSC_KX_handle_client_monitor_peers ( struct GNUNET_MQ_Handle mq)

Handle GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS request.

For this request type, the client does not have to have transmitted an INIT request. All current peers are returned, regardless of which message types they accept.

Parameters
mqmessage queue to add for monitoring

Definition at line 3700 of file gnunet-service-core_kx.c.

3701{
3702 struct GNUNET_MQ_Envelope *env;
3703 struct MonitorNotifyMessage *done_msg;
3704 struct GSC_KeyExchangeInfo *kx;
3705
3707 for (kx = kx_head; NULL != kx; kx = kx->next)
3708 {
3709 struct GNUNET_MQ_Envelope *env_notify;
3710 struct MonitorNotifyMessage *msg;
3711
3713 msg->state = htonl ((uint32_t) kx->status);
3714 msg->peer = kx->peer;
3715 msg->timeout = GNUNET_TIME_absolute_hton (kx->timeout);
3716 GNUNET_MQ_send (mq, env_notify);
3717 }
3719 done_msg->state = htonl ((uint32_t) GNUNET_CORE_KX_ITERATION_FINISHED);
3722}
struct GNUNET_MessageHeader * msg
Definition 005.c:2
static struct GSC_KeyExchangeInfo * kx_head
DLL head.
@ GNUNET_CORE_KX_ITERATION_FINISHED
This is not a state in a peer's state machine, but a special value used with the GNUNET_CORE_MonitorC...
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
Definition nc.c:161
#define GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY
Reply for monitor by CORE service.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
Information about the status of a key exchange with another peer.
struct GSC_KeyExchangeInfo * next
DLL.
struct GNUNET_PeerIdentity peer
Identity of the peer.
struct GNUNET_TIME_Absolute timeout
When should the session time out (if there are no Acks to HEARTBEATs)?
enum GNUNET_CORE_KxState status
What is our connection state?
Message sent by the service to monitor clients to notify them about a peer changing status.
Definition core.h:313
uint32_t state
New peer state, an enum GNUNET_CORE_KxState in NBO.
Definition core.h:322
struct GNUNET_TIME_AbsoluteNBO timeout
How long will we stay in this state (if nothing else happens)?
Definition core.h:332

References env, GNUNET_CORE_KX_ITERATION_FINISHED, GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_notification_context_add(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_UNIT_FOREVER_ABS, kx_head, mq, msg, nc, GSC_KeyExchangeInfo::next, GSC_KeyExchangeInfo::peer, MonitorNotifyMessage::state, GSC_KeyExchangeInfo::status, MonitorNotifyMessage::timeout, and GSC_KeyExchangeInfo::timeout.

Referenced by handle_client_monitor_peers().

Here is the call graph for this function:
Here is the caller graph for this function: