GNUnet 0.21.1
gnunet-service-core_kx.c File Reference

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

#include "platform.h"
#include "gnunet-service-core_kx.h"
#include "gnunet_transport_core_service.h"
#include "gnunet-service-core_sessions.h"
#include "gnunet-service-core.h"
#include "gnunet_constants.h"
#include "gnunet_signatures.h"
#include "gnunet_protocols.h"
Include dependency graph for gnunet-service-core_kx.c:

Go to the source code of this file.

Data Structures

struct  EncryptedMessage
 Encapsulation for encrypted messages exchanged between peers. More...
 
struct  GSC_KeyExchangeInfo
 Information about the status of a key exchange with another peer. More...
 

Macros

#define DEBUG_KX   0
 Enable expensive (and possibly problematic for privacy!) logging of KX. More...
 
#define INITIAL_SET_KEY_RETRY_FREQUENCY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
 How long do we wait for SET_KEY confirmation initially? More...
 
#define MIN_PING_FREQUENCY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 What is the minimum frequency for a PING message? More...
 
#define REKEY_FREQUENCY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12)
 How often do we rekey? More...
 
#define REKEY_TOLERANCE    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
 What time difference do we tolerate? More...
 
#define MAX_MESSAGE_AGE   GNUNET_TIME_UNIT_DAYS
 What is the maximum age of a message for us to consider processing it? Note that this looks at the timestamp used by the other peer, so clock skew between machines does come into play here. More...
 
#define ENCRYPTED_HEADER_SIZE    (offsetof (struct EncryptedMessage, sequence_number))
 Number of bytes (at the beginning) of struct EncryptedMessage that are NOT encrypted. More...
 

Functions

static uint32_t calculate_seed (struct GSC_KeyExchangeInfo *kx)
 Calculate seed value we should use for a message. More...
 
static void monitor_notify_all (struct GSC_KeyExchangeInfo *kx)
 Inform all monitors about the KX state of the given peer. More...
 
static void derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed)
 Derive an authentication key from "set key" information. More...
 
static void derive_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed, const struct GNUNET_PeerIdentity *identity)
 Derive an IV from packet information. More...
 
static void derive_pong_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed, uint32_t challenge, const struct GNUNET_PeerIdentity *identity)
 Derive an IV from pong packet information. More...
 
static void derive_aes_key (const struct GNUNET_PeerIdentity *sender, const struct GNUNET_PeerIdentity *receiver, const struct GNUNET_HashCode *key_material, struct GNUNET_CRYPTO_SymmetricSessionKey *skey)
 Derive an AES key from key material. More...
 
static int do_encrypt (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const void *in, void *out, size_t size)
 Encrypt size bytes from in and write the result to out. More...
 
static int do_decrypt (struct GSC_KeyExchangeInfo *kx, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const void *in, void *out, size_t size)
 Decrypt size bytes from in and write the result to out. More...
 
static void send_key (struct GSC_KeyExchangeInfo *kx)
 Send our key (and encrypted PING) to the other peer. More...
 
static void set_key_retry_task (void *cls)
 Task that will retry send_key() if our previous attempt failed. More...
 
static void setup_fresh_ping (struct GSC_KeyExchangeInfo *kx)
 Create a fresh PING message for transmission to the other peer. More...
 
static int deliver_message (void *cls, const struct GNUNET_MessageHeader *m)
 Deliver P2P message to interested clients. More...
 
static void * handle_transport_notify_connect (void *cls, const struct GNUNET_PeerIdentity *pid, struct GNUNET_MQ_Handle *mq)
 Function called by transport to notify us that a peer connected to us (on the network level). More...
 
static void handle_transport_notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
 Function called by transport telling us that a peer disconnected. More...
 
static void send_ping (struct GSC_KeyExchangeInfo *kx)
 Send our PING to the other peer. More...
 
static void derive_session_keys (struct GSC_KeyExchangeInfo *kx)
 Derive fresh session keys from the current ephemeral keys. More...
 
static void handle_ephemeral_key (void *cls, const struct EphemeralKeyMessage *m)
 We received a GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY message. More...
 
static void send_keep_alive (void *cls)
 Task triggered when a neighbour entry is about to time out (and we should prevent this by sending a PING). More...
 
static void handle_ping (void *cls, const struct PingMessage *m)
 We received a PING message. More...
 
static void update_timeout (struct GSC_KeyExchangeInfo *kx)
 We've seen a valid message from the other peer. More...
 
static void handle_pong (void *cls, const struct PongMessage *m)
 We received a PONG message. More...
 
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. More...
 
static int check_encrypted (void *cls, const struct EncryptedMessage *m)
 We received an encrypted message. More...
 
static void handle_encrypted (void *cls, const struct EncryptedMessage *m)
 We received an encrypted message. More...
 
static void sign_ephemeral_key ()
 Setup the message that links the ephemeral key to our persistent public key and generate the appropriate signature. More...
 
static void do_rekey (void *cls)
 Task run to trigger rekeying. More...
 
int GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
 Initialize KX subsystem. More...
 
void GSC_KX_done ()
 Shutdown KX subsystem. More...
 
unsigned int GSC_NEIGHBOURS_get_queue_length (const struct GSC_KeyExchangeInfo *kxinfo)
 Check how many messages are queued for the given neighbour. More...
 
int GSC_NEIGHBOURS_check_excess_bandwidth (const struct GSC_KeyExchangeInfo *kxinfo)
 Check if the given neighbour has excess bandwidth available. More...
 
void GSC_KX_handle_client_monitor_peers (struct GNUNET_MQ_Handle *mq)
 Handle GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS request. More...
 

Variables

static struct GNUNET_TRANSPORT_CoreHandletransport
 Transport service. More...
 
static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
 Our private key. More...
 
static struct GNUNET_CRYPTO_EcdhePrivateKey my_ephemeral_key
 Our ephemeral private key. More...
 
static struct EphemeralKeyMessage current_ekm
 Current message we send for a key exchange. More...
 
static struct GSC_KeyExchangeInfokx_head
 DLL head. More...
 
static struct GSC_KeyExchangeInfokx_tail
 DLL tail. More...
 
static struct GNUNET_SCHEDULER_Taskrekey_task
 Task scheduled for periodic re-generation (and thus rekeying) of our ephemeral key. More...
 
static struct GNUNET_NotificationContextnc
 Notification context for broadcasting to monitors. More...
 

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.c.

Macro Definition Documentation

◆ DEBUG_KX

#define DEBUG_KX   0

Enable expensive (and possibly problematic for privacy!) logging of KX.

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

◆ INITIAL_SET_KEY_RETRY_FREQUENCY

#define INITIAL_SET_KEY_RETRY_FREQUENCY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)

How long do we wait for SET_KEY confirmation initially?

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

◆ MIN_PING_FREQUENCY

#define MIN_PING_FREQUENCY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)

What is the minimum frequency for a PING message?

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

◆ REKEY_FREQUENCY

#define REKEY_FREQUENCY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12)

How often do we rekey?

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

◆ REKEY_TOLERANCE

#define REKEY_TOLERANCE    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)

What time difference do we tolerate?

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

◆ MAX_MESSAGE_AGE

#define MAX_MESSAGE_AGE   GNUNET_TIME_UNIT_DAYS

What is the maximum age of a message for us to consider processing it? Note that this looks at the timestamp used by the other peer, so clock skew between machines does come into play here.

So this should be picked high enough so that a little bit of clock skew does not prevent peers from connecting to us.

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

◆ ENCRYPTED_HEADER_SIZE

#define ENCRYPTED_HEADER_SIZE    (offsetof (struct EncryptedMessage, sequence_number))

Number of bytes (at the beginning) of struct EncryptedMessage that are NOT encrypted.

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

Function Documentation

◆ calculate_seed()

static uint32_t calculate_seed ( struct GSC_KeyExchangeInfo kx)
static

Calculate seed value we should use for a message.

Parameters
kxkey exchange context

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

295{
296 /* Note: may want to make this non-random and instead
297 derive from key material to avoid having an undetectable
298 side-channel */
299 return htonl (
301}
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.

References GNUNET_CRYPTO_QUALITY_NONCE, and GNUNET_CRYPTO_random_u32().

Referenced by GSC_KX_encrypt_and_transmit(), handle_ping(), and setup_fresh_ping().

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

◆ monitor_notify_all()

static void monitor_notify_all ( struct GSC_KeyExchangeInfo kx)
static

Inform all monitors about the KX state of the given peer.

Parameters
kxkey exchange state to inform about

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

311{
313
315 msg.header.size = htons (sizeof(msg));
316 msg.state = htonl ((uint32_t) kx->status);
317 msg.peer = *kx->peer;
318 msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout);
321}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct GNUNET_NotificationContext * nc
Notification context for broadcasting to monitors.
@ GNUNET_NO
void GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, const struct GNUNET_MessageHeader *msg, int can_drop)
Send a message to all subscribers of this context.
Definition: nc.c:190
#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:638
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
struct GNUNET_TIME_Absolute last_notify_timeout
What was the last timeout we informed our monitors about?
const struct GNUNET_PeerIdentity * peer
Identity of the peer.
struct GNUNET_TIME_Absolute timeout
When should the session time out (if there are no PONGs)?
enum GNUNET_CORE_KxState status
What is our connection status?
Message sent by the service to monitor clients to notify them about a peer changing status.
Definition: core.h:301

References GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY, GNUNET_NO, GNUNET_notification_context_broadcast(), GNUNET_TIME_absolute_hton(), GSC_KeyExchangeInfo::last_notify_timeout, msg, nc, GSC_KeyExchangeInfo::peer, GNUNET_MessageHeader::size, GSC_KeyExchangeInfo::status, GSC_KeyExchangeInfo::timeout, and GNUNET_MessageHeader::type.

Referenced by do_rekey(), handle_encrypted(), handle_ephemeral_key(), handle_pong(), handle_transport_notify_connect(), handle_transport_notify_disconnect(), send_keep_alive(), and update_timeout().

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

◆ derive_auth_key()

static void derive_auth_key ( struct GNUNET_CRYPTO_AuthKey akey,
const struct GNUNET_CRYPTO_SymmetricSessionKey skey,
uint32_t  seed 
)
static

Derive an authentication key from "set key" information.

Parameters
akeyauthentication key to derive
skeysession key to use
seedseed to use

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

335{
336 static const char ctx[] = "authentication key";
337
338#if DEBUG_KX
339 struct GNUNET_HashCode sh;
340
341 GNUNET_CRYPTO_hash (skey, sizeof(*skey), &sh);
343 "Deriving Auth key from SKEY %s and seed %u\n",
344 GNUNET_h2s (&sh),
345 (unsigned int) seed);
346#endif
348 skey,
349 &seed,
350 sizeof(seed),
351 skey,
352 sizeof(
354 ctx,
355 sizeof(ctx),
356 NULL);
357}
static struct GNUNET_FS_Handle * ctx
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
void GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len,...)
Derive an authentication key.
Definition: crypto_hash.c:267
#define GNUNET_log(kind,...)
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
A 512-bit hashcode.

References ctx, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hmac_derive_key(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, and sh.

Referenced by GSC_KX_encrypt_and_transmit(), and handle_encrypted().

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

◆ derive_iv()

static void derive_iv ( struct GNUNET_CRYPTO_SymmetricInitializationVector iv,
const struct GNUNET_CRYPTO_SymmetricSessionKey skey,
uint32_t  seed,
const struct GNUNET_PeerIdentity identity 
)
static

Derive an IV from packet information.

Parameters
ivinitialization vector to initialize
skeysession key to use
seedseed to use
identityidentity of the other peer to use

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

373{
374 static const char ctx[] = "initialization vector";
375
376#if DEBUG_KX
377 struct GNUNET_HashCode sh;
378
379 GNUNET_CRYPTO_hash (skey, sizeof(*skey), &sh);
381 "Deriving IV from SKEY %s and seed %u for peer %s\n",
382 GNUNET_h2s (&sh),
383 (unsigned int) seed,
385#endif
387 skey,
388 &seed,
389 sizeof(seed),
390 identity,
391 sizeof(struct GNUNET_PeerIdentity),
392 ctx,
393 sizeof(ctx),
394 NULL);
395}
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
void GNUNET_CRYPTO_symmetric_derive_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const void *salt, size_t salt_len,...)
Derive an IV.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
The identity of the host (wraps the signing key of the peer).

References ctx, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_symmetric_derive_iv(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, identity, and sh.

Referenced by GSC_KX_encrypt_and_transmit(), handle_encrypted(), handle_ping(), and setup_fresh_ping().

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

◆ derive_pong_iv()

static void derive_pong_iv ( struct GNUNET_CRYPTO_SymmetricInitializationVector iv,
const struct GNUNET_CRYPTO_SymmetricSessionKey skey,
uint32_t  seed,
uint32_t  challenge,
const struct GNUNET_PeerIdentity identity 
)
static

Derive an IV from pong packet information.

Parameters
ivinitialization vector to initialize
skeysession key to use
seedseed to use
challengenonce to use
identityidentity of the other peer to use

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

413{
414 static const char ctx[] = "pong initialization vector";
415
416#if DEBUG_KX
417 struct GNUNET_HashCode sh;
418
419 GNUNET_CRYPTO_hash (skey, sizeof(*skey), &sh);
421 "Deriving PONG IV from SKEY %s and seed %u/%u for %s\n",
422 GNUNET_h2s (&sh),
423 (unsigned int) seed,
424 (unsigned int) challenge,
426#endif
428 skey,
429 &seed,
430 sizeof(seed),
431 identity,
432 sizeof(struct GNUNET_PeerIdentity),
433 &challenge,
434 sizeof(challenge),
435 ctx,
436 sizeof(ctx),
437 NULL);
438}

References ctx, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_symmetric_derive_iv(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, identity, and sh.

Referenced by handle_ping(), and handle_pong().

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

◆ derive_aes_key()

static void derive_aes_key ( const struct GNUNET_PeerIdentity sender,
const struct GNUNET_PeerIdentity receiver,
const struct GNUNET_HashCode key_material,
struct GNUNET_CRYPTO_SymmetricSessionKey skey 
)
static

Derive an AES key from key material.

Parameters
senderpeer identity of the sender
receiverpeer identity of the sender
key_materialhigh entropy key material to use
skeyset to derived session key

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

454{
455 static const char ctx[] = "aes key generation vector";
456
457#if DEBUG_KX
458 struct GNUNET_HashCode sh;
459
460 GNUNET_CRYPTO_hash (skey, sizeof(*skey), &sh);
462 "Deriving AES Keys for %s to %s from %s\n",
463 GNUNET_i2s (sender),
465 GNUNET_h2s (key_material));
466#endif
467 GNUNET_CRYPTO_kdf (skey,
469 ctx,
470 sizeof(ctx),
471 key_material,
472 sizeof(struct GNUNET_HashCode),
473 sender,
474 sizeof(struct GNUNET_PeerIdentity),
475 receiver,
476 sizeof(struct GNUNET_PeerIdentity),
477 NULL);
478}
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:70
const char * GNUNET_i2s2(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void receiver(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback to read from the SOCKS5 proxy.
Definition: socks.c:330

References ctx, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_kdf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_i2s2(), GNUNET_log, receiver(), and sh.

Referenced by derive_session_keys().

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

◆ do_encrypt()

static int do_encrypt ( struct GSC_KeyExchangeInfo kx,
const struct GNUNET_CRYPTO_SymmetricInitializationVector iv,
const void *  in,
void *  out,
size_t  size 
)
static

Encrypt size bytes from in and write the result to out.

Use the kx key for outbound traffic of the given neighbour.

Parameters
kxkey information context
ivinitialization vector to use
inciphertext
outplaintext
sizesize of in / out
Returns
GNUNET_OK on success

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

499{
500 if (size != (uint16_t) size)
501 {
502 GNUNET_break (0);
503 return GNUNET_NO;
504 }
506 (uint16_t) size,
507 &kx->encrypt_key,
508 iv,
509 out));
511 gettext_noop ("# bytes encrypted"),
512 size,
513 GNUNET_NO);
514 /* the following is too sensitive to write to log files by accident,
515 so we require manual intervention to get this one... */
516#if DEBUG_KX
518 "Encrypted %u bytes for `%s' using key %s, IV %u\n",
519 (unsigned int) size,
520 GNUNET_i2s (kx->peer),
522 GNUNET_CRYPTO_crc32_n (iv, sizeof(iv)));
523#endif
524 return GNUNET_OK;
525}
#define gettext_noop(String)
Definition: gettext.h:70
struct GNUNET_STATISTICS_Handle * GSC_stats
For creating statistics.
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
int32_t GNUNET_CRYPTO_crc32_n(const void *buf, size_t len)
Compute the CRC32 checksum for the first len bytes of the buffer.
Definition: crypto_crc.c:99
@ GNUNET_OK
#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.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static unsigned int size
Size of the "table".
Definition: peer.c:68
unsigned char aes_key[(256/8)]
Actual key for AES.
struct GNUNET_CRYPTO_SymmetricSessionKey encrypt_key
Key we use to encrypt our messages for the other peer (initialized by us when we do the handshake).

References GNUNET_CRYPTO_SymmetricSessionKey::aes_key, GSC_KeyExchangeInfo::encrypt_key, gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_crc32_n(), GNUNET_CRYPTO_symmetric_encrypt(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GSC_stats, GSC_KeyExchangeInfo::peer, and size.

Referenced by GSC_KX_encrypt_and_transmit(), handle_ping(), and setup_fresh_ping().

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

◆ do_decrypt()

static int do_decrypt ( struct GSC_KeyExchangeInfo kx,
const struct GNUNET_CRYPTO_SymmetricInitializationVector iv,
const void *  in,
void *  out,
size_t  size 
)
static

Decrypt size bytes from in and write the result to out.

Use the kx key for inbound traffic of the given neighbour. This function does NOT do any integrity-checks on the result.

Parameters
kxkey information context
ivinitialization vector to use
inciphertext
outplaintext
sizesize of in / out
Returns
GNUNET_OK on success

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

546{
547 if (size != (uint16_t) size)
548 {
549 GNUNET_break (0);
550 return GNUNET_NO;
551 }
555 {
556 GNUNET_break_op (0);
557 return GNUNET_SYSERR;
558 }
560 (uint16_t) size,
561 &kx->decrypt_key,
562 iv,
563 out))
564 {
565 GNUNET_break (0);
566 return GNUNET_SYSERR;
567 }
569 gettext_noop ("# bytes decrypted"),
570 size,
571 GNUNET_NO);
572 /* the following is too sensitive to write to log files by accident,
573 so we require manual intervention to get this one... */
574#if DEBUG_KX
576 "Decrypted %u bytes from `%s' using key %s, IV %u\n",
577 (unsigned int) size,
578 GNUNET_i2s (kx->peer),
580 GNUNET_CRYPTO_crc32_n (iv, sizeof(*iv)));
581#endif
582 return GNUNET_OK;
583}
@ GNUNET_CORE_KX_STATE_UP
The other peer has confirmed our session key + PING with a PONG message encrypted with their session ...
@ GNUNET_CORE_KX_STATE_KEY_RECEIVED
We've received the other peers session key.
@ GNUNET_CORE_KX_STATE_REKEY_SENT
We're rekeying (or had a timeout), so we have sent the other peer our new ephemeral key,...
ssize_t GNUNET_CRYPTO_symmetric_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Decrypt a given block using a symmetric sessionkey.
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_CRYPTO_SymmetricSessionKey decrypt_key
Key we use to decrypt messages from the other peer (given to us by the other peer during the handshak...

References GNUNET_CRYPTO_SymmetricSessionKey::aes_key, GSC_KeyExchangeInfo::decrypt_key, gettext_noop, GNUNET_break, GNUNET_break_op, GNUNET_CORE_KX_STATE_KEY_RECEIVED, GNUNET_CORE_KX_STATE_REKEY_SENT, GNUNET_CORE_KX_STATE_UP, GNUNET_CRYPTO_crc32_n(), GNUNET_CRYPTO_symmetric_decrypt(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GSC_stats, GSC_KeyExchangeInfo::peer, size, and GSC_KeyExchangeInfo::status.

Referenced by handle_encrypted(), handle_ping(), and handle_pong().

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

◆ send_key()

static void send_key ( struct GSC_KeyExchangeInfo kx)
static

Send our key (and encrypted PING) to the other peer.

Send our key to the other peer.

Parameters
kxkey exchange context

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

1386{
1387 struct GNUNET_MQ_Envelope *env;
1388
1390 if (NULL != kx->retry_set_key_task)
1391 {
1393 kx->retry_set_key_task = NULL;
1394 }
1395 /* always update sender status in SET KEY message */
1396#if DEBUG_KX
1397 {
1398 struct GNUNET_HashCode hc;
1399
1401 sizeof(current_ekm.ephemeral_key),
1402 &hc);
1404 "Sending EPHEMERAL_KEY %s to `%s' (my status: %d)\n",
1405 GNUNET_h2s (&hc),
1406 GNUNET_i2s (kx->peer),
1407 kx->status);
1408 }
1409#endif
1410 current_ekm.sender_status = htonl ((int32_t) (kx->status));
1412 GNUNET_MQ_send (kx->mq, env);
1414 send_ping (kx);
1415 kx->retry_set_key_task =
1418 kx);
1419}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void set_key_retry_task(void *cls)
Task that will retry send_key() if our previous attempt failed.
static struct EphemeralKeyMessage current_ekm
Current message we send for a key exchange.
static void send_ping(struct GSC_KeyExchangeInfo *kx)
Send our PING to the other peer.
@ GNUNET_CORE_KX_STATE_DOWN
No handshake yet.
@ GNUNET_CORE_KX_STATE_KEY_SENT
We've sent our session key.
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:533
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:304
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1278
struct GNUNET_MessageHeader header
Message type is GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY.
int32_t sender_status
Status of the sender (should be in enum PeerStateMachine), nbo.
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key
Ephemeral public ECC key.
struct GNUNET_SCHEDULER_Task * retry_set_key_task
ID of task used for re-trying SET_KEY and PING message.
struct GNUNET_TIME_Relative set_key_retry_frequency
At what frequency are we currently re-trying SET_KEY messages?
struct GNUNET_MQ_Handle * mq
Message queue for sending messages to peer.

References current_ekm, env, EphemeralKeyMessage::ephemeral_key, GNUNET_assert, GNUNET_CORE_KX_STATE_DOWN, GNUNET_CORE_KX_STATE_KEY_SENT, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MQ_msg_copy(), GNUNET_MQ_send(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), EphemeralKeyMessage::header, GSC_KeyExchangeInfo::mq, GSC_KeyExchangeInfo::peer, GSC_KeyExchangeInfo::retry_set_key_task, send_ping(), EphemeralKeyMessage::sender_status, GSC_KeyExchangeInfo::set_key_retry_frequency, set_key_retry_task(), and GSC_KeyExchangeInfo::status.

Referenced by do_rekey(), handle_encrypted(), handle_ephemeral_key(), handle_transport_notify_connect(), send_keep_alive(), and set_key_retry_task().

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

◆ set_key_retry_task()

static void set_key_retry_task ( void *  cls)
static

Task that will retry send_key() if our previous attempt failed.

Parameters
clsour struct GSC_KeyExchangeInfo

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

602{
603 struct GSC_KeyExchangeInfo *kx = cls;
604
605 kx->retry_set_key_task = NULL;
609 send_key (kx);
610}
static void send_key(struct GSC_KeyExchangeInfo *kx)
Send our key (and encrypted PING) to the other peer.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Information about the status of a key exchange with another peer.

References GNUNET_assert, GNUNET_CORE_KX_STATE_DOWN, GNUNET_TIME_STD_BACKOFF, GSC_KeyExchangeInfo::retry_set_key_task, send_key(), GSC_KeyExchangeInfo::set_key_retry_frequency, and GSC_KeyExchangeInfo::status.

Referenced by handle_transport_notify_connect(), and send_key().

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

◆ setup_fresh_ping()

static void setup_fresh_ping ( struct GSC_KeyExchangeInfo kx)
static

Create a fresh PING message for transmission to the other peer.

Parameters
kxkey exchange context to create PING for

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

620{
621 struct PingMessage pp;
622 struct PingMessage *pm;
624
625 pm = &kx->ping;
626 kx->ping_challenge =
628 pm->header.size = htons (sizeof(struct PingMessage));
629 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
630 pm->iv_seed = calculate_seed (kx);
631 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, kx->peer);
632 pp.challenge = kx->ping_challenge;
633 pp.target = *kx->peer;
634 do_encrypt (kx,
635 &iv,
636 &pp.target,
637 &pm->target,
638 sizeof(struct PingMessage)
639 - ((void *) &pm->target - (void *) pm));
640}
static uint32_t calculate_seed(struct GSC_KeyExchangeInfo *kx)
Calculate seed value we should use for a message.
static void derive_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed, const struct GNUNET_PeerIdentity *identity)
Derive an IV from packet information.
static int do_encrypt(struct GSC_KeyExchangeInfo *kx, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const void *in, void *out, size_t size)
Encrypt size bytes from in and write the result to out.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_MESSAGE_TYPE_CORE_PING
Check that other peer is alive (challenge).
uint32_t ping_challenge
What was our PING challenge number (for this peer)?
struct PingMessage ping
PING message we transmit to the other peer.
We're sending an (encrypted) PING to the other peer to check if it can decrypt.

References calculate_seed(), PingMessage::challenge, derive_iv(), do_encrypt(), GSC_KeyExchangeInfo::encrypt_key, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_MESSAGE_TYPE_CORE_PING, GSC_KeyExchangeInfo::peer, GSC_KeyExchangeInfo::ping, GSC_KeyExchangeInfo::ping_challenge, pm, and PingMessage::target.

Referenced by derive_session_keys(), and send_keep_alive().

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

◆ deliver_message()

static int deliver_message ( void *  cls,
const struct GNUNET_MessageHeader m 
)
static

Deliver P2P message to interested clients.

Invokes send twice, once for clients that want the full message, and once for clients that only want the header

Parameters
clsthe struct GSC_KeyExchangeInfo
mthe message
Returns
GNUNET_OK on success, GNUNET_NO to stop further processing (no error) GNUNET_SYSERR to stop further processing with error

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

656{
657 struct GSC_KeyExchangeInfo *kx = cls;
658
660 "Decrypted message of type %d from %s\n",
661 ntohs (m->type),
662 GNUNET_i2s (kx->peer));
664 {
666 gettext_noop ("# PAYLOAD dropped (out of order)"),
667 1,
668 GNUNET_NO);
669 return GNUNET_OK;
670 }
671 switch (ntohs (m->type))
672 {
676 return GNUNET_OK;
677
680 return GNUNET_OK;
681
682 default:
684 m,
685 ntohs (m->size),
688 m,
689 sizeof(struct GNUNET_MessageHeader),
691 }
692 return GNUNET_OK;
693}
#define GNUNET_CORE_OPTION_SEND_FULL_INBOUND
Client wants all inbound messages in full.
Definition: core.h:53
#define GNUNET_CORE_OPTION_SEND_HDR_INBOUND
Client just wants the 4-byte message headers of all inbound messages.
Definition: core.h:59
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
void GSC_CLIENTS_deliver_message(const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, uint16_t msize, uint32_t options)
Deliver P2P message to interested clients.
void GSC_SESSIONS_confirm_typemap(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *msg)
The other peer has confirmed receiving our type map, check if it is current and if so,...
void GSC_SESSIONS_set_typemap(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *msg)
We've received a typemap message from a peer, update ours.
#define GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP
uncompressed type map of the sender
#define GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP
gzip-compressed type map of the sender
#define GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP
Other peer confirms having received the type map.
Header for all communications.

References gettext_noop, GNUNET_CORE_KX_STATE_UP, GNUNET_CORE_OPTION_SEND_FULL_INBOUND, GNUNET_CORE_OPTION_SEND_HDR_INBOUND, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP, GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP, GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GSC_CLIENTS_deliver_message(), GSC_SESSIONS_confirm_typemap(), GSC_SESSIONS_set_typemap(), GSC_stats, m, GSC_KeyExchangeInfo::peer, and GSC_KeyExchangeInfo::status.

Referenced by handle_transport_notify_connect().

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

◆ handle_transport_notify_connect()

static void * handle_transport_notify_connect ( void *  cls,
const struct GNUNET_PeerIdentity pid,
struct GNUNET_MQ_Handle mq 
)
static

Function called by transport to notify us that a peer connected to us (on the network level).

Starts the key exchange with the given peer.

Parameters
clsclosure (NULL)
pididentity of the peer to do a key exchange with
Returns
key exchange information context

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

709{
710 struct GSC_KeyExchangeInfo *kx;
711 struct GNUNET_HashCode h1;
712 struct GNUNET_HashCode h2;
713
715 "Initiating key exchange with `%s'\n",
716 GNUNET_i2s (pid));
718 gettext_noop ("# key exchanges initiated"),
719 1,
720 GNUNET_NO);
721
722 kx = GNUNET_new (struct GSC_KeyExchangeInfo);
724 kx->mq = mq;
725 kx->peer = pid;
730 GNUNET_CRYPTO_hash (pid, sizeof(struct GNUNET_PeerIdentity), &h1);
732 sizeof(struct GNUNET_PeerIdentity),
733 &h2);
734 if (0 < GNUNET_CRYPTO_hash_cmp (&h1, &h2))
735 {
736 /* peer with "lower" identity starts KX, otherwise we typically end up
737 with both peers starting the exchange and transmit the 'set key'
738 message twice */
739 send_key (kx);
740 }
741 else
742 {
743 /* peer with "higher" identity starts a delayed KX, if the "lower" peer
744 * does not start a KX since it sees no reasons to do so */
748 kx);
749 }
750 return kx;
751}
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_PeerIdentity GSC_my_identity
Our identity.
static struct GSC_KeyExchangeInfo * kx_tail
DLL tail.
static struct GSC_KeyExchangeInfo * kx_head
DLL head.
#define INITIAL_SET_KEY_RETRY_FREQUENCY
How long do we wait for SET_KEY confirmation initially?
static int deliver_message(void *cls, const struct GNUNET_MessageHeader *m)
Deliver P2P message to interested clients.
static void monitor_notify_all(struct GSC_KeyExchangeInfo *kx)
Inform all monitors about the KX state of the given peer.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
Definition: crypto_hash.c:221
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:86
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_MessageStreamTokenizer * mst
Our message stream tokenizer (for encrypted payload).

References deliver_message(), gettext_noop, GNUNET_CONTAINER_DLL_insert, GNUNET_CORE_KX_STATE_KEY_SENT, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_cmp(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MST_create(), GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_TIME_UNIT_SECONDS, GSC_my_identity, GSC_stats, INITIAL_SET_KEY_RETRY_FREQUENCY, kx_head, kx_tail, monitor_notify_all(), mq, GSC_KeyExchangeInfo::mq, GSC_KeyExchangeInfo::mst, GSC_KeyExchangeInfo::peer, pid, GSC_KeyExchangeInfo::retry_set_key_task, send_key(), GSC_KeyExchangeInfo::set_key_retry_frequency, set_key_retry_task(), and GSC_KeyExchangeInfo::status.

Referenced by GSC_KX_init().

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

◆ handle_transport_notify_disconnect()

static void handle_transport_notify_disconnect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  handler_cls 
)
static

Function called by transport telling us that a peer disconnected.

Stop key exchange with the given peer. Clean up key material.

Parameters
clsclosure
peerthe peer that disconnected
handler_clsthe struct GSC_KeyExchangeInfo of the peer

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

767{
768 struct GSC_KeyExchangeInfo *kx = handler_cls;
769
771 "Peer `%s' disconnected from us.\n",
772 GNUNET_i2s (peer));
775 gettext_noop ("# key exchanges stopped"),
776 1,
777 GNUNET_NO);
778 if (NULL != kx->retry_set_key_task)
779 {
781 kx->retry_set_key_task = NULL;
782 }
783 if (NULL != kx->keep_alive_task)
784 {
786 kx->keep_alive_task = NULL;
787 }
792 GNUNET_free (kx);
793}
void GSC_SESSIONS_end(const struct GNUNET_PeerIdentity *pid)
End the session with the given peer (we are no longer connected).
@ GNUNET_CORE_KX_PEER_DISCONNECT
Last state of a KX (when it is being terminated).
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:404
struct GNUNET_SCHEDULER_Task * keep_alive_task
ID of task used for sending keep-alive pings.

References gettext_noop, GNUNET_CONTAINER_DLL_remove, GNUNET_CORE_KX_PEER_DISCONNECT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_MST_destroy(), GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GSC_SESSIONS_end(), GSC_stats, GSC_KeyExchangeInfo::keep_alive_task, kx_head, kx_tail, monitor_notify_all(), GSC_KeyExchangeInfo::mst, GSC_KeyExchangeInfo::peer, GSC_KeyExchangeInfo::retry_set_key_task, and GSC_KeyExchangeInfo::status.

Referenced by GSC_KX_init().

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

◆ send_ping()

static void send_ping ( struct GSC_KeyExchangeInfo kx)
static

Send our PING to the other peer.

Parameters
kxkey exchange context

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

803{
804 struct GNUNET_MQ_Envelope *env;
805
807 gettext_noop ("# PING messages transmitted"),
808 1,
809 GNUNET_NO);
811 GNUNET_MQ_send (kx->mq, env);
812}
struct GNUNET_MessageHeader header
Message type is GNUNET_MESSAGE_TYPE_CORE_PING.

References env, gettext_noop, GNUNET_MQ_msg_copy(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_STATISTICS_update(), GSC_stats, PingMessage::header, GSC_KeyExchangeInfo::mq, and GSC_KeyExchangeInfo::ping.

Referenced by handle_ephemeral_key(), send_keep_alive(), and send_key().

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

◆ derive_session_keys()

static void derive_session_keys ( struct GSC_KeyExchangeInfo kx)
static

Derive fresh session keys from the current ephemeral keys.

Parameters
kxsession to derive keys for

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

822{
823 struct GNUNET_HashCode key_material;
824
825 if (GNUNET_OK !=
828 &key_material))
829 {
830 GNUNET_break (0);
831 return;
832 }
833 derive_aes_key (&GSC_my_identity, kx->peer, &key_material, &kx->encrypt_key);
834 derive_aes_key (kx->peer, &GSC_my_identity, &key_material, &kx->decrypt_key);
835 memset (&key_material, 0, sizeof(key_material));
836 /* fresh key, reset sequence numbers */
838 kx->last_packets_bitmap = 0;
839 setup_fresh_ping (kx);
840}
static struct GNUNET_CRYPTO_EcdhePrivateKey my_ephemeral_key
Our ephemeral private key.
static void derive_aes_key(const struct GNUNET_PeerIdentity *sender, const struct GNUNET_PeerIdentity *receiver, const struct GNUNET_HashCode *key_material, struct GNUNET_CRYPTO_SymmetricSessionKey *skey)
Derive an AES key from key material.
static void setup_fresh_ping(struct GSC_KeyExchangeInfo *kx)
Create a fresh PING message for transmission to the other peer.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_ecdh(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a public and a private ECC key.
Definition: crypto_ecc.c:714
uint32_t last_sequence_number_received
last sequence number received on this connection (highest)
struct GNUNET_CRYPTO_EcdhePublicKey other_ephemeral_key
Ephemeral public ECC key of the other peer.
uint32_t last_packets_bitmap
Bit map indicating which of the 32 sequence numbers before the last were received (good for accepting...

References GSC_KeyExchangeInfo::decrypt_key, derive_aes_key(), GSC_KeyExchangeInfo::encrypt_key, GNUNET_break, GNUNET_CRYPTO_ecc_ecdh(), GNUNET_OK, GSC_my_identity, GSC_KeyExchangeInfo::last_packets_bitmap, GSC_KeyExchangeInfo::last_sequence_number_received, my_ephemeral_key, GSC_KeyExchangeInfo::other_ephemeral_key, GSC_KeyExchangeInfo::peer, and setup_fresh_ping().

Referenced by do_rekey(), and handle_ephemeral_key().

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

◆ handle_ephemeral_key()

static void handle_ephemeral_key ( void *  cls,
const struct EphemeralKeyMessage m 
)
static

We received a GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY message.

Validate and update our key material and status.

Parameters
clskey exchange status for the corresponding peer
mthe set key message we received

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

852{
853 struct GSC_KeyExchangeInfo *kx = cls;
854 struct GNUNET_TIME_Absolute start_t;
855 struct GNUNET_TIME_Absolute end_t;
856 struct GNUNET_TIME_Absolute now;
857 enum GNUNET_CORE_KxState sender_status;
858 enum GNUNET_GenericReturnValue do_verify = GNUNET_YES;
859
860 end_t = GNUNET_TIME_absolute_ntoh (m->expiration_time);
864 (end_t.abs_value_us < kx->foreign_key_expires.abs_value_us))
865 {
867 gettext_noop ("# old ephemeral keys ignored"),
868 1,
869 GNUNET_NO);
871 "Received expired EPHEMERAL_KEY from %s\n",
872 GNUNET_i2s (&m->origin_identity));
873 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
874 return;
875 }
876 if (0 == memcmp (&m->ephemeral_key,
878 sizeof(m->ephemeral_key)))
879 {
882 "# duplicate ephemeral keys. Not verifying."),
883 1,
884 GNUNET_NO);
886 "Duplicate EPHEMERAL_KEY from %s, do not verify\n",
887 GNUNET_i2s (&m->origin_identity));
888 do_verify = GNUNET_NO;
889 }
890 if (0 != memcmp (&m->origin_identity,
891 kx->peer,
892 sizeof(struct GNUNET_PeerIdentity)))
893 {
895 "Received EPHEMERAL_KEY from %s, but expected %s\n",
896 GNUNET_i2s (&m->origin_identity),
897 GNUNET_i2s_full (kx->peer));
898 GNUNET_break_op (0);
899 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
900 return;
901 }
902 if (do_verify && ((ntohl (m->purpose.size) !=
904 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
905 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
906 + sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)
907 + sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) ||
908 (GNUNET_OK !=
910 &m->purpose,
911 &m->signature,
912 &m->origin_identity.public_key))))
913 {
914 /* invalid signature */
915 GNUNET_break_op (0);
918 "# EPHEMERAL_KEYs rejected (bad signature)"),
919 1,
920 GNUNET_NO);
922 "Received EPHEMERAL_KEY from %s with bad signature\n",
923 GNUNET_i2s (&m->origin_identity));
924 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
925 return;
926 }
928 start_t = GNUNET_TIME_absolute_ntoh (m->creation_time);
929 if ((end_t.abs_value_us <
931 (start_t.abs_value_us >
933 {
934 GNUNET_log (
936 _ (
937 "EPHEMERAL_KEY from peer `%s' rejected as its validity range does not match our system time (%llu not in [%llu,%llu]).\n"),
938 GNUNET_i2s (kx->peer),
939 (unsigned long long) now.abs_value_us,
940 (unsigned long long) start_t.abs_value_us,
941 (unsigned long long) end_t.abs_value_us);
944 "# EPHEMERAL_KEY messages rejected due to time"),
945 1,
946 GNUNET_NO);
947 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
948 return;
949 }
950#if DEBUG_KX
951 {
952 struct GNUNET_HashCode eh;
953
954 GNUNET_CRYPTO_hash (&m->ephemeral_key, sizeof(m->ephemeral_key), &eh);
956 "Received valid EPHEMERAL_KEY `%s' from `%s' in state %d.\n",
957 GNUNET_h2s (&eh),
958 GNUNET_i2s (kx->peer),
959 kx->status);
960 }
961#endif
963 gettext_noop ("# valid ephemeral keys received"),
964 1,
965 GNUNET_NO);
966 kx->other_ephemeral_key = m->ephemeral_key;
967 kx->foreign_key_expires = end_t;
969
970 /* check if we still need to send the sender our key */
971 sender_status = (enum GNUNET_CORE_KxState) ntohl (m->sender_status);
972 switch (sender_status)
973 {
975 GNUNET_break_op (0);
976 break;
977
979 /* fine, need to send our key after updating our status, see below */
981 break;
982
984 /* other peer already got our key, but typemap did go down */
986 break;
987
989 /* other peer already got our key, typemap NOT down */
990 break;
991
993 /* other peer already got our key, typemap NOT down */
994 break;
995
996 default:
997 GNUNET_break (0);
998 break;
999 }
1000 /* check if we need to confirm everything is fine via PING + PONG */
1001 switch (kx->status)
1002 {
1004 GNUNET_assert (NULL == kx->keep_alive_task);
1006 monitor_notify_all (kx);
1007 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1008 send_key (kx);
1009 else
1010 send_ping (kx);
1011 break;
1012
1014 GNUNET_assert (NULL == kx->keep_alive_task);
1016 monitor_notify_all (kx);
1017 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1018 send_key (kx);
1019 else
1020 send_ping (kx);
1021 break;
1022
1024 GNUNET_assert (NULL == kx->keep_alive_task);
1025 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1026 send_key (kx);
1027 else
1028 send_ping (kx);
1029 break;
1030
1033 monitor_notify_all (kx);
1034 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1035 send_key (kx);
1036 else
1037 send_ping (kx);
1038 break;
1039
1041 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1042 send_key (kx);
1043 else
1044 send_ping (kx);
1045 break;
1046
1047 default:
1048 GNUNET_break (0);
1049 break;
1050 }
1051 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1052}
#define REKEY_TOLERANCE
What time difference do we tolerate?
static void derive_session_keys(struct GSC_KeyExchangeInfo *kx)
Derive fresh session keys from the current ephemeral keys.
static struct GNUNET_TRANSPORT_CoreHandle * transport
Transport service.
void GSC_SESSIONS_reinit(const struct GNUNET_PeerIdentity *peer)
The other peer has indicated that it 'lost' the session (KX down), reinitialize the session on our en...
GNUNET_CORE_KxState
State machine for our P2P encryption handshake.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:690
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_YES
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:737
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Subtract a given relative duration from the given start time.
Definition: time.c:469
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:450
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY
Purpose is to set a session key.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
struct GNUNET_TIME_Absolute foreign_key_expires
At what time did the other peer generate the decryption key?

References _, GNUNET_TIME_Absolute::abs_value_us, derive_session_keys(), GSC_KeyExchangeInfo::foreign_key_expires, gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_CORE_KX_STATE_DOWN, GNUNET_CORE_KX_STATE_KEY_RECEIVED, GNUNET_CORE_KX_STATE_KEY_SENT, GNUNET_CORE_KX_STATE_REKEY_SENT, GNUNET_CORE_KX_STATE_UP, GNUNET_CRYPTO_eddsa_verify_(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_i2s(), GNUNET_i2s_full(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_absolute_subtract(), GNUNET_YES, GSC_SESSIONS_reinit(), GSC_stats, GSC_KeyExchangeInfo::keep_alive_task, m, monitor_notify_all(), GSC_KeyExchangeInfo::other_ephemeral_key, GSC_KeyExchangeInfo::peer, REKEY_TOLERANCE, send_key(), send_ping(), GSC_KeyExchangeInfo::status, and transport.

Here is the call graph for this function:

◆ send_keep_alive()

static void send_keep_alive ( void *  cls)
static

Task triggered when a neighbour entry is about to time out (and we should prevent this by sending a PING).

Parameters
clsthe struct GSC_KeyExchangeInfo

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

1160{
1161 struct GSC_KeyExchangeInfo *kx = cls;
1162 struct GNUNET_TIME_Relative retry;
1163 struct GNUNET_TIME_Relative left;
1164
1165 kx->keep_alive_task = NULL;
1167 if (0 == left.rel_value_us)
1168 {
1170 gettext_noop ("# sessions terminated by timeout"),
1171 1,
1172 GNUNET_NO);
1173 GSC_SESSIONS_end (kx->peer);
1175 monitor_notify_all (kx);
1176 send_key (kx);
1177 return;
1178 }
1180 "Sending KEEPALIVE to `%s'\n",
1181 GNUNET_i2s (kx->peer));
1183 gettext_noop ("# keepalive messages sent"),
1184 1,
1185 GNUNET_NO);
1186 setup_fresh_ping (kx);
1187 send_ping (kx);
1190 kx->keep_alive_task =
1192}
#define MIN_PING_FREQUENCY
What is the minimum frequency for a PING message?
static void send_keep_alive(void *cls)
Task triggered when a neighbour entry is about to time out (and we should prevent this by sending a P...
struct GNUNET_TIME_Relative GNUNET_TIME_relative_max(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the maximum of two relative time values.
Definition: time.c:351
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:405
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition: time.c:550
Time for relative time used by GNUnet, in microseconds.

References gettext_noop, GNUNET_CORE_KX_STATE_KEY_SENT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_divide(), GNUNET_TIME_relative_max(), GSC_SESSIONS_end(), GSC_stats, GSC_KeyExchangeInfo::keep_alive_task, MIN_PING_FREQUENCY, monitor_notify_all(), GSC_KeyExchangeInfo::peer, GNUNET_TIME_Relative::rel_value_us, send_keep_alive(), send_key(), send_ping(), setup_fresh_ping(), GSC_KeyExchangeInfo::status, and GSC_KeyExchangeInfo::timeout.

Referenced by handle_ping(), send_keep_alive(), and update_timeout().

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

◆ handle_ping()

static void handle_ping ( void *  cls,
const struct PingMessage m 
)
static

We received a PING message.

Validate and transmit a PONG message.

Parameters
clskey exchange status for the corresponding peer
mthe encrypted PING message itself

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

1068{
1069 struct GSC_KeyExchangeInfo *kx = cls;
1070 struct PingMessage t;
1071 struct PongMessage tx;
1072 struct PongMessage *tp;
1073 struct GNUNET_MQ_Envelope *env;
1075
1077 gettext_noop ("# PING messages received"),
1078 1,
1079 GNUNET_NO);
1083 {
1084 /* ignore */
1086 gettext_noop (
1087 "# PING messages dropped (out of order)"),
1088 1,
1089 GNUNET_NO);
1090 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1091 return;
1092 }
1094 "Core service receives PING request from `%s'.\n",
1095 GNUNET_i2s (kx->peer));
1096 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
1097 if (GNUNET_OK != do_decrypt (kx,
1098 &iv,
1099 &m->target,
1100 &t.target,
1101 sizeof(struct PingMessage)
1102 - ((void *) &m->target - (void *) m)))
1103 {
1104 GNUNET_break_op (0);
1105 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1106 return;
1107 }
1108 if (0 !=
1109 memcmp (&t.target, &GSC_my_identity, sizeof(struct GNUNET_PeerIdentity)))
1110 {
1113 "Decryption of PING from peer `%s' failed, PING for `%s'?\n",
1114 GNUNET_i2s (kx->peer),
1115 GNUNET_i2s2 (&t.target));
1116 else
1117 GNUNET_log (
1119 "Decryption of PING from peer `%s' failed after rekey (harmless)\n",
1120 GNUNET_i2s (kx->peer));
1121 GNUNET_break_op (0);
1122 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1123 return;
1124 }
1125 /* construct PONG */
1126 tx.reserved = 0;
1127 tx.challenge = t.challenge;
1128 tx.target = t.target;
1130 tp->iv_seed = calculate_seed (kx);
1131 derive_pong_iv (&iv, &kx->encrypt_key, tp->iv_seed, t.challenge, kx->peer);
1132 do_encrypt (kx,
1133 &iv,
1134 &tx.challenge,
1135 &tp->challenge,
1136 sizeof(struct PongMessage)
1137 - ((void *) &tp->challenge - (void *) tp));
1139 gettext_noop ("# PONG messages created"),
1140 1,
1141 GNUNET_NO);
1142 GNUNET_MQ_send (kx->mq, env);
1143 if (NULL != kx->keep_alive_task)
1144 {
1147 }
1148 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1149}
static int do_decrypt(struct GSC_KeyExchangeInfo *kx, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const void *in, void *out, size_t size)
Decrypt size bytes from in and write the result to out.
static void derive_pong_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed, uint32_t challenge, const struct GNUNET_PeerIdentity *identity)
Derive an IV from pong packet information.
static struct GNUNET_SCHEDULER_Task * t
Main task.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MESSAGE_TYPE_CORE_PONG
Confirmation that other peer is alive.
Response to a PING.
uint32_t challenge
Random number to make replay attacks harder.
uint32_t iv_seed
Seed for the IV.

References calculate_seed(), PongMessage::challenge, GSC_KeyExchangeInfo::decrypt_key, derive_iv(), derive_pong_iv(), do_decrypt(), do_encrypt(), GSC_KeyExchangeInfo::encrypt_key, env, gettext_noop, GNUNET_break_op, GNUNET_CORE_KX_STATE_KEY_RECEIVED, GNUNET_CORE_KX_STATE_REKEY_SENT, GNUNET_CORE_KX_STATE_UP, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s(), GNUNET_i2s2(), GNUNET_log, GNUNET_MESSAGE_TYPE_CORE_PONG, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GSC_my_identity, GSC_stats, PongMessage::iv_seed, GSC_KeyExchangeInfo::keep_alive_task, m, MIN_PING_FREQUENCY, GSC_KeyExchangeInfo::mq, GSC_KeyExchangeInfo::peer, PongMessage::reserved, send_keep_alive(), GSC_KeyExchangeInfo::status, t, PongMessage::target, and transport.

Here is the call graph for this function:

◆ update_timeout()

static void update_timeout ( struct GSC_KeyExchangeInfo kx)
static

We've seen a valid message from the other peer.

Update the time when the session would time out and delay sending our keep alive message further.

Parameters
kxkey exchange where we saw activity

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

1204{
1206
1207 kx->timeout =
1209 delta =
1211 if (delta.rel_value_us > 5LL * 1000LL * 1000LL)
1212 {
1213 /* we only notify monitors about timeout changes if those
1214 are bigger than the threshold (5s) */
1215 monitor_notify_all (kx);
1216 }
1217 if (NULL != kx->keep_alive_task)
1222 kx);
1223}
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer?
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:421
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:36
uint64_t rel_value_us
The actual value.

References delta, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_absolute_get_difference(), GNUNET_TIME_relative_divide(), GNUNET_TIME_relative_to_absolute(), GSC_KeyExchangeInfo::keep_alive_task, GSC_KeyExchangeInfo::last_notify_timeout, monitor_notify_all(), GNUNET_TIME_Relative::rel_value_us, send_keep_alive(), and GSC_KeyExchangeInfo::timeout.

Referenced by handle_encrypted(), and handle_pong().

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

◆ handle_pong()

static void handle_pong ( void *  cls,
const struct PongMessage m 
)
static

We received a PONG message.

Validate and update our status.

Parameters
kxkey exchange context for the the PONG
mthe encrypted PONG message itself

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

1234{
1235 struct GSC_KeyExchangeInfo *kx = cls;
1236 struct PongMessage t;
1238
1240 gettext_noop ("# PONG messages received"),
1241 1,
1242 GNUNET_NO);
1243 switch (kx->status)
1244 {
1247 gettext_noop (
1248 "# PONG messages dropped (connection down)"),
1249 1,
1250 GNUNET_NO);
1251 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1252 return;
1253
1256 gettext_noop (
1257 "# PONG messages dropped (out of order)"),
1258 1,
1259 GNUNET_NO);
1260 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1261 return;
1262
1264 break;
1265
1267 break;
1268
1270 break;
1271
1272 default:
1273 GNUNET_break (0);
1274 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1275 return;
1276 }
1278 "Core service receives PONG response from `%s'.\n",
1279 GNUNET_i2s (kx->peer));
1280 /* mark as garbage, just to be sure */
1281 memset (&t, 255, sizeof(t));
1282 derive_pong_iv (&iv,
1283 &kx->decrypt_key,
1284 m->iv_seed,
1285 kx->ping_challenge,
1287 if (GNUNET_OK != do_decrypt (kx,
1288 &iv,
1289 &m->challenge,
1290 &t.challenge,
1291 sizeof(struct PongMessage)
1292 - ((void *) &m->challenge - (void *) m)))
1293 {
1294 GNUNET_break_op (0);
1295 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1296 return;
1297 }
1299 gettext_noop ("# PONG messages decrypted"),
1300 1,
1301 GNUNET_NO);
1302 if ((0 !=
1303 memcmp (&t.target, kx->peer, sizeof(struct GNUNET_PeerIdentity))) ||
1304 (kx->ping_challenge != t.challenge))
1305 {
1306 /* PONG malformed */
1308 "Received malformed PONG wanted sender `%s' with challenge %u\n",
1309 GNUNET_i2s (kx->peer),
1310 (unsigned int) kx->ping_challenge);
1312 "Received malformed PONG received from `%s' with challenge %u\n",
1313 GNUNET_i2s (&t.target),
1314 (unsigned int) t.challenge);
1315 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1316 return;
1317 }
1319 "Received valid PONG from `%s'\n",
1320 GNUNET_i2s (kx->peer));
1321 /* no need to resend key any longer */
1322 if (NULL != kx->retry_set_key_task)
1323 {
1325 kx->retry_set_key_task = NULL;
1326 }
1327 switch (kx->status)
1328 {
1330 GNUNET_assert (0); /* should be impossible */
1331 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1332 return;
1333
1335 GNUNET_assert (0); /* should be impossible */
1336 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1337 return;
1338
1341 gettext_noop (
1342 "# session keys confirmed via PONG"),
1343 1,
1344 GNUNET_NO);
1346 monitor_notify_all (kx);
1347 GSC_SESSIONS_create (kx->peer, kx);
1348 GNUNET_assert (NULL == kx->keep_alive_task);
1349 update_timeout (kx);
1350 break;
1351
1354 gettext_noop ("# timeouts prevented via PONG"),
1355 1,
1356 GNUNET_NO);
1357 update_timeout (kx);
1358 break;
1359
1362 gettext_noop (
1363 "# rekey operations confirmed via PONG"),
1364 1,
1365 GNUNET_NO);
1367 monitor_notify_all (kx);
1368 update_timeout (kx);
1369 break;
1370
1371 default:
1372 GNUNET_break (0);
1373 break;
1374 }
1375 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1376}
static void update_timeout(struct GSC_KeyExchangeInfo *kx)
We've seen a valid message from the other peer.
void GSC_SESSIONS_create(const struct GNUNET_PeerIdentity *peer, struct GSC_KeyExchangeInfo *kx)
Create a session, a key exchange was just completed.

References GSC_KeyExchangeInfo::decrypt_key, derive_pong_iv(), do_decrypt(), gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_CORE_KX_STATE_DOWN, GNUNET_CORE_KX_STATE_KEY_RECEIVED, GNUNET_CORE_KX_STATE_KEY_SENT, GNUNET_CORE_KX_STATE_REKEY_SENT, GNUNET_CORE_KX_STATE_UP, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GSC_my_identity, GSC_SESSIONS_create(), GSC_stats, GSC_KeyExchangeInfo::keep_alive_task, m, monitor_notify_all(), GSC_KeyExchangeInfo::peer, GSC_KeyExchangeInfo::ping_challenge, GSC_KeyExchangeInfo::retry_set_key_task, GSC_KeyExchangeInfo::status, t, transport, and update_timeout().

Here is the call graph for this function:

◆ 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'

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

1426{
1427 size_t used = payload_size + sizeof(struct EncryptedMessage);
1428 char pbuf[used]; /* plaintext */
1429 struct EncryptedMessage *em; /* encrypted message */
1430 struct EncryptedMessage *ph; /* plaintext header */
1431 struct GNUNET_MQ_Envelope *env;
1433 struct GNUNET_CRYPTO_AuthKey auth_key;
1434
1435 ph = (struct EncryptedMessage *) pbuf;
1436 ph->sequence_number = htonl (++kx->last_sequence_number_sent);
1437 ph->iv_seed = calculate_seed (kx);
1438 ph->reserved = 0;
1440 GNUNET_memcpy (&ph[1], payload, payload_size);
1442 payload_size,
1444 em->iv_seed = ph->iv_seed;
1445 derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, kx->peer);
1447 &iv,
1448 &ph->sequence_number,
1449 &em->sequence_number,
1450 used - ENCRYPTED_HEADER_SIZE));
1451#if DEBUG_KX
1452 {
1453 struct GNUNET_HashCode hc;
1454
1456 used - ENCRYPTED_HEADER_SIZE,
1457 &hc);
1459 "Encrypted payload `%s' of %u bytes for %s\n",
1460 GNUNET_h2s (&hc),
1461 (unsigned int) (used - ENCRYPTED_HEADER_SIZE),
1462 GNUNET_i2s (kx->peer));
1463 }
1464#endif
1465 derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed);
1466 GNUNET_CRYPTO_hmac (&auth_key,
1467 &em->sequence_number,
1468 used - ENCRYPTED_HEADER_SIZE,
1469 &em->hmac);
1470#if DEBUG_KX
1471 {
1472 struct GNUNET_HashCode hc;
1473
1474 GNUNET_CRYPTO_hash (&auth_key, sizeof(auth_key), &hc);
1476 "For peer %s, used AC %s to create hmac %s\n",
1477 GNUNET_i2s (kx->peer),
1478 GNUNET_h2s (&hc),
1479 GNUNET_h2s2 (&em->hmac));
1480 }
1481#endif
1483 GNUNET_MQ_send (kx->mq, env);
1484}
#define ENCRYPTED_HEADER_SIZE
Number of bytes (at the beginning) of struct EncryptedMessage that are NOT encrypted.
static void derive_auth_key(struct GNUNET_CRYPTO_AuthKey *akey, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed)
Derive an authentication key from "set key" information.
static unsigned long long payload
How much data are we currently storing in the database?
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
Definition: crypto_hash.c:330
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * GNUNET_h2s2(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE
Encapsulation for an encrypted message between peers.
Encapsulation for encrypted messages exchanged between peers.
uint32_t iv_seed
Random value used for IV generation.
struct GNUNET_TIME_AbsoluteNBO timestamp
Timestamp.
uint32_t sequence_number
Sequence number, in network byte order.
struct GNUNET_HashCode hmac
MAC of the encrypted message (starting at sequence_number), used to verify message integrity.
uint32_t reserved
Reserved, always zero.
type for (message) authentication keys
uint32_t last_sequence_number_sent
last sequence number transmitted
int has_excess_bandwidth
GNUNET_YES if this peer currently has excess bandwidth.

References calculate_seed(), derive_auth_key(), derive_iv(), do_encrypt(), GSC_KeyExchangeInfo::encrypt_key, ENCRYPTED_HEADER_SIZE, env, GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hmac(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_h2s2(), GNUNET_i2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_hton(), GSC_KeyExchangeInfo::has_excess_bandwidth, EncryptedMessage::hmac, EncryptedMessage::iv_seed, GSC_KeyExchangeInfo::last_sequence_number_sent, GSC_KeyExchangeInfo::mq, payload, GSC_KeyExchangeInfo::peer, EncryptedMessage::reserved, EncryptedMessage::sequence_number, and EncryptedMessage::timestamp.

Referenced by transmit_typemap_task(), and try_transmission().

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

◆ check_encrypted()

static int check_encrypted ( void *  cls,
const struct EncryptedMessage m 
)
static

We received an encrypted message.

Check that it is well-formed (size-wise).

Parameters
clskey exchange context for encrypting the message
mencrypted message
Returns
GNUNET_OK if msg is well-formed (size-wise)

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

1497{
1498 uint16_t size = ntohs (m->header.size) - sizeof(*m);
1499
1500 if (size < sizeof(struct GNUNET_MessageHeader))
1501 {
1502 GNUNET_break_op (0);
1503 return GNUNET_SYSERR;
1504 }
1505 return GNUNET_OK;
1506}

References GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, m, and size.

◆ handle_encrypted()

static void handle_encrypted ( void *  cls,
const struct EncryptedMessage m 
)
static

We received an encrypted message.

Decrypt, validate and pass on to the appropriate clients.

Parameters
clskey exchange context for encrypting the message
mencrypted message

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

1518{
1519 struct GSC_KeyExchangeInfo *kx = cls;
1520 struct EncryptedMessage *pt; /* plaintext */
1521 struct GNUNET_HashCode ph;
1522 uint32_t snum;
1523 struct GNUNET_TIME_Absolute t;
1525 struct GNUNET_CRYPTO_AuthKey auth_key;
1526 uint16_t size = ntohs (m->header.size);
1527 char buf[size] GNUNET_ALIGN;
1528
1530 {
1532 gettext_noop (
1533 "# DATA message dropped (out of order)"),
1534 1,
1535 GNUNET_NO);
1536 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1537 return;
1538 }
1539 if (0 ==
1541 {
1542 GNUNET_log (
1544 _ (
1545 "Session to peer `%s' went down due to key expiration (should not happen)\n"),
1546 GNUNET_i2s (kx->peer));
1548 gettext_noop (
1549 "# sessions terminated by key expiration"),
1550 1,
1551 GNUNET_NO);
1552 GSC_SESSIONS_end (kx->peer);
1553 if (NULL != kx->keep_alive_task)
1554 {
1556 kx->keep_alive_task = NULL;
1557 }
1559 monitor_notify_all (kx);
1560 send_key (kx);
1561 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1562 return;
1563 }
1564
1565 /* validate hash */
1566#if DEBUG_KX
1567 {
1568 struct GNUNET_HashCode hc;
1569
1570 GNUNET_CRYPTO_hash (&m->sequence_number, size - ENCRYPTED_HEADER_SIZE, &hc);
1572 "Received encrypted payload `%s' of %u bytes from %s\n",
1573 GNUNET_h2s (&hc),
1574 (unsigned int) (size - ENCRYPTED_HEADER_SIZE),
1575 GNUNET_i2s (kx->peer));
1576 }
1577#endif
1578 derive_auth_key (&auth_key, &kx->decrypt_key, m->iv_seed);
1579 GNUNET_CRYPTO_hmac (&auth_key,
1580 &m->sequence_number,
1582 &ph);
1583#if DEBUG_KX
1584 {
1585 struct GNUNET_HashCode hc;
1586
1587 GNUNET_CRYPTO_hash (&auth_key, sizeof(auth_key), &hc);
1589 "For peer %s, used AC %s to verify hmac %s\n",
1590 GNUNET_i2s (kx->peer),
1591 GNUNET_h2s (&hc),
1592 GNUNET_h2s2 (&m->hmac));
1593 }
1594#endif
1595 if (0 != memcmp (&ph, &m->hmac, sizeof(struct GNUNET_HashCode)))
1596 {
1597 /* checksum failed */
1599 "Failed checksum validation for a message from `%s'\n",
1600 GNUNET_i2s (kx->peer));
1601 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1602 return;
1603 }
1604 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
1605 /* decrypt */
1606 if (GNUNET_OK != do_decrypt (kx,
1607 &iv,
1608 &m->sequence_number,
1611 {
1612 GNUNET_break_op (0);
1613 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1614 return;
1615 }
1617 "Decrypted %u bytes from %s\n",
1618 (unsigned int) (size - ENCRYPTED_HEADER_SIZE),
1619 GNUNET_i2s (kx->peer));
1620 pt = (struct EncryptedMessage *) buf;
1621
1622 /* validate sequence number */
1623 snum = ntohl (pt->sequence_number);
1624 if (kx->last_sequence_number_received == snum)
1625 {
1627 "Received duplicate message, ignoring.\n");
1628 /* duplicate, ignore */
1630 gettext_noop ("# bytes dropped (duplicates)"),
1631 size,
1632 GNUNET_NO);
1633 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1634 return;
1635 }
1636 if ((kx->last_sequence_number_received > snum) &&
1637 (kx->last_sequence_number_received - snum > 32))
1638 {
1640 "Received ancient out of sequence message, ignoring.\n");
1641 /* ancient out of sequence, ignore */
1643 gettext_noop (
1644 "# bytes dropped (out of sequence)"),
1645 size,
1646 GNUNET_NO);
1647 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1648 return;
1649 }
1650 if (kx->last_sequence_number_received > snum)
1651 {
1652 uint32_t rotbit = 1U << (kx->last_sequence_number_received - snum - 1);
1653
1654 if ((kx->last_packets_bitmap & rotbit) != 0)
1655 {
1657 "Received duplicate message, ignoring.\n");
1659 gettext_noop ("# bytes dropped (duplicates)"),
1660 size,
1661 GNUNET_NO);
1662 /* duplicate, ignore */
1663 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1664 return;
1665 }
1666 kx->last_packets_bitmap |= rotbit;
1667 }
1668 if (kx->last_sequence_number_received < snum)
1669 {
1670 unsigned int shift = (snum - kx->last_sequence_number_received);
1671
1672 if (shift >= 8 * sizeof(kx->last_packets_bitmap))
1673 kx->last_packets_bitmap = 0;
1674 else
1675 kx->last_packets_bitmap <<= shift;
1677 }
1678
1679 /* check timestamp */
1681 if (GNUNET_TIME_absolute_get_duration (t).rel_value_us >
1682 MAX_MESSAGE_AGE.rel_value_us)
1683 {
1685 "Message received far too old (%s). Content ignored.\n",
1688 GNUNET_YES));
1690 gettext_noop (
1691 "# bytes dropped (ancient message)"),
1692 size,
1693 GNUNET_NO);
1694 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1695 return;
1696 }
1697
1698 /* process decrypted message(s) */
1699 update_timeout (kx);
1701 gettext_noop ("# bytes of payload decrypted"),
1702 size - sizeof(struct EncryptedMessage),
1703 GNUNET_NO);
1704 if (GNUNET_OK !=
1706 &buf[sizeof(struct EncryptedMessage)],
1707 size - sizeof(struct EncryptedMessage),
1708 GNUNET_YES,
1709 GNUNET_NO))
1710 GNUNET_break_op (0);
1711
1712 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1713}
#define MAX_MESSAGE_AGE
What is the maximum age of a message for us to consider processing it? Note that this looks at the ti...
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
enum GNUNET_GenericReturnValue GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
Definition: mst.c:101
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:436
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570

References _, GSC_KeyExchangeInfo::decrypt_key, derive_auth_key(), derive_iv(), do_decrypt(), ENCRYPTED_HEADER_SIZE, GSC_KeyExchangeInfo::foreign_key_expires, gettext_noop, GNUNET_ALIGN, GNUNET_break_op, GNUNET_CORE_KX_STATE_KEY_SENT, GNUNET_CORE_KX_STATE_UP, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hmac(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_h2s2(), GNUNET_i2s(), GNUNET_log, GNUNET_MST_from_buffer(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_absolute_ntoh(), GNUNET_YES, GSC_my_identity, GSC_SESSIONS_end(), GSC_stats, GSC_KeyExchangeInfo::keep_alive_task, GSC_KeyExchangeInfo::last_packets_bitmap, GSC_KeyExchangeInfo::last_sequence_number_received, m, MAX_MESSAGE_AGE, monitor_notify_all(), GSC_KeyExchangeInfo::mst, GSC_KeyExchangeInfo::peer, GNUNET_TIME_Relative::rel_value_us, send_key(), EncryptedMessage::sequence_number, size, GSC_KeyExchangeInfo::status, t, EncryptedMessage::timestamp, transport, and update_timeout().

Here is the call graph for this function:

◆ sign_ephemeral_key()

static void sign_ephemeral_key ( )
static

Setup the message that links the ephemeral key to our persistent public key and generate the appropriate signature.

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

1722{
1723 current_ekm.header.size = htons (sizeof(struct EphemeralKeyMessage));
1725 current_ekm.sender_status = 0; /* to be set later */
1728 htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
1729 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
1730 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
1731 + sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)
1732 + sizeof(struct GNUNET_PeerIdentity));
1736 "core",
1737 "USE_EPHEMERAL_KEYS"))
1738 {
1742 REKEY_TOLERANCE)));
1743 }
1744 else
1745 {
1748 }
1756}
const struct GNUNET_CONFIGURATION_Handle * GSC_cfg
Our configuration.
static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
Our private key.
#define REKEY_FREQUENCY
How often do we rekey?
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:607
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:214
#define GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY
Session key exchange between peers.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
Definition: time.c:585
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
Message transmitted with the signed ephemeral key of a peer.
struct GNUNET_PeerIdentity origin_identity
Public key of the signing peer (persistent version, not the ephemeral public key).
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the given ephemeral key expire (end of validity).
struct GNUNET_CRYPTO_EddsaSignature signature
An ECC signature of the origin_identity asserting the validity of the given ephemeral key.
struct GNUNET_TIME_AbsoluteNBO creation_time
At what time was this key created (beginning of validity).
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Information about what is being signed.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...

References EphemeralKeyMessage::creation_time, current_ekm, EphemeralKeyMessage::ephemeral_key, EphemeralKeyMessage::expiration_time, GNUNET_assert, GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_eddsa_sign_(), GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_relative_add(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_YES, GSC_cfg, GSC_my_identity, EphemeralKeyMessage::header, my_ephemeral_key, my_private_key, EphemeralKeyMessage::origin_identity, EphemeralKeyMessage::purpose, GNUNET_CRYPTO_EccSignaturePurpose::purpose, REKEY_FREQUENCY, REKEY_TOLERANCE, EphemeralKeyMessage::sender_status, EphemeralKeyMessage::signature, GNUNET_MessageHeader::size, GNUNET_CRYPTO_EccSignaturePurpose::size, and GNUNET_MessageHeader::type.

Referenced by do_rekey(), and GSC_KX_init().

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

◆ do_rekey()

static void do_rekey ( void *  cls)
static

Task run to trigger rekeying.

Parameters
clsclosure, NULL

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

1766{
1767 struct GSC_KeyExchangeInfo *pos;
1768
1769 (void) cls;
1773 {
1774 struct GNUNET_HashCode eh;
1775
1777 sizeof(current_ekm.ephemeral_key),
1778 &eh);
1779 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Rekeying to %s\n", GNUNET_h2s (&eh));
1780 }
1781 for (pos = kx_head; NULL != pos; pos = pos->next)
1782 {
1783 if (GNUNET_CORE_KX_STATE_UP == pos->status)
1784 {
1786 derive_session_keys (pos);
1787 }
1788 else if (GNUNET_CORE_KX_STATE_DOWN == pos->status)
1789 {
1791 }
1792 monitor_notify_all (pos);
1793 send_key (pos);
1794 }
1795}
static void sign_ephemeral_key()
Setup the message that links the ephemeral key to our persistent public key and generate the appropri...
static void do_rekey(void *cls)
Task run to trigger rekeying.
static struct GNUNET_SCHEDULER_Task * rekey_task
Task scheduled for periodic re-generation (and thus rekeying) of our ephemeral key.
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:436
@ GNUNET_ERROR_TYPE_INFO
struct GSC_KeyExchangeInfo * next
DLL.

References current_ekm, derive_session_keys(), do_rekey(), EphemeralKeyMessage::ephemeral_key, GNUNET_CORE_KX_STATE_DOWN, GNUNET_CORE_KX_STATE_KEY_SENT, GNUNET_CORE_KX_STATE_REKEY_SENT, GNUNET_CORE_KX_STATE_UP, GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_INFO, GNUNET_h2s(), GNUNET_log, GNUNET_SCHEDULER_add_delayed(), kx_head, monitor_notify_all(), my_ephemeral_key, GSC_KeyExchangeInfo::next, REKEY_FREQUENCY, rekey_task, send_key(), sign_ephemeral_key(), and GSC_KeyExchangeInfo::status.

Referenced by do_rekey(), and GSC_KX_init().

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

◆ GSC_KX_init()

int GSC_KX_init ( struct GNUNET_CRYPTO_EddsaPrivateKey pk)

Initialize KX subsystem.

Parameters
pkprivate key to use for the peer
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

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

1806{
1808 GNUNET_MQ_hd_fixed_size (ephemeral_key,
1810 struct EphemeralKeyMessage,
1811 NULL),
1814 struct PingMessage,
1815 NULL),
1818 struct PongMessage,
1819 NULL),
1820 GNUNET_MQ_hd_var_size (encrypted,
1822 struct EncryptedMessage,
1823 NULL),
1825 };
1826
1827 my_private_key = *pk;
1832 {
1833 struct GNUNET_HashCode eh;
1834
1836 sizeof(current_ekm.ephemeral_key),
1837 &eh);
1839 "Starting with ephemeral key %s\n",
1840 GNUNET_h2s (&eh));
1841 }
1842
1845 transport =
1848 handlers,
1849 NULL,
1852 if (NULL == transport)
1853 {
1854 GSC_KX_done ();
1855 return GNUNET_SYSERR;
1856 }
1857 return GNUNET_OK;
1858}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static void handle_transport_notify_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
Function called by transport telling us that a peer disconnected.
void GSC_KX_done()
Shutdown KX subsystem.
static void * handle_transport_notify_connect(void *cls, const struct GNUNET_PeerIdentity *pid, struct GNUNET_MQ_Handle *mq)
Function called by transport to notify us that a peer connected to us (on the network level).
struct GNUNET_TRANSPORT_CoreHandle * GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd)
Connect to the transport service.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:198
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
Definition: nc.c:122
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
Message handler for a specific message type.
struct GNUNET_CRYPTO_EddsaPublicKey public_key

References current_ekm, do_rekey(), EphemeralKeyMessage::ephemeral_key, GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_INFO, GNUNET_h2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE, GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY, GNUNET_MESSAGE_TYPE_CORE_PING, GNUNET_MESSAGE_TYPE_CORE_PONG, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_notification_context_create(), GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SYSERR, GNUNET_TRANSPORT_core_connect(), GSC_cfg, GSC_KX_done(), GSC_my_identity, handle_transport_notify_connect(), handle_transport_notify_disconnect(), handlers, my_ephemeral_key, my_private_key, nc, pk, GNUNET_PeerIdentity::public_key, REKEY_FREQUENCY, rekey_task, sign_ephemeral_key(), and transport.

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 1865 of file gnunet-service-core_kx.c.

1866{
1867 if (NULL != transport)
1868 {
1870 transport = NULL;
1871 }
1872 if (NULL != rekey_task)
1873 {
1875 rekey_task = NULL;
1876 }
1877 memset (&my_ephemeral_key,
1878 0,
1879 sizeof (my_ephemeral_key));
1880 memset (&my_private_key,
1881 0,
1882 sizeof (my_private_key));
1883 if (NULL != nc)
1884 {
1886 nc = NULL;
1887 }
1888}
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

References GNUNET_notification_context_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_TRANSPORT_core_disconnect(), my_ephemeral_key, my_private_key, nc, rekey_task, and transport.

Referenced by GSC_KX_init(), and shutdown_task().

Here is the call graph for this function:
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
kxinfodata about neighbour to check
Returns
number of items in the message queue

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

1899{
1900 return GNUNET_MQ_get_length (kxinfo->mq);
1901}
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:293

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_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 1905 of file gnunet-service-core_kx.c.

1906{
1907 return kxinfo->has_excess_bandwidth;
1908}

References GSC_KeyExchangeInfo::has_excess_bandwidth.

Referenced by try_transmission().

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 1920 of file gnunet-service-core_kx.c.

1921{
1922 struct GNUNET_MQ_Envelope *env;
1923 struct MonitorNotifyMessage *done_msg;
1924 struct GSC_KeyExchangeInfo *kx;
1925
1927 for (kx = kx_head; NULL != kx; kx = kx->next)
1928 {
1929 struct GNUNET_MQ_Envelope *env;
1930 struct MonitorNotifyMessage *msg;
1931
1933 msg->state = htonl ((uint32_t) kx->status);
1934 msg->peer = *kx->peer;
1935 msg->timeout = GNUNET_TIME_absolute_hton (kx->timeout);
1937 }
1939 done_msg->state = htonl ((uint32_t) GNUNET_CORE_KX_ITERATION_FINISHED);
1942}
@ 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...
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
uint32_t state
New peer state, an enum GNUNET_CORE_KxState in NBO.
Definition: core.h:310
struct GNUNET_TIME_AbsoluteNBO timeout
How long will we stay in this state (if nothing else happens)?
Definition: core.h:320

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:

Variable Documentation

◆ transport

struct GNUNET_TRANSPORT_CoreHandle* transport
static

Transport service.

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

Referenced by GSC_KX_done(), GSC_KX_init(), handle_encrypted(), handle_ephemeral_key(), handle_ping(), and handle_pong().

◆ my_private_key

struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
static

Our private key.

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

Referenced by GSC_KX_done(), GSC_KX_init(), and sign_ephemeral_key().

◆ my_ephemeral_key

struct GNUNET_CRYPTO_EcdhePrivateKey my_ephemeral_key
static

Our ephemeral private key.

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

Referenced by derive_session_keys(), do_rekey(), GSC_KX_done(), GSC_KX_init(), and sign_ephemeral_key().

◆ current_ekm

struct EphemeralKeyMessage current_ekm
static

Current message we send for a key exchange.

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

Referenced by do_rekey(), GSC_KX_init(), send_key(), and sign_ephemeral_key().

◆ kx_head

◆ kx_tail

struct GSC_KeyExchangeInfo* kx_tail
static

◆ rekey_task

struct GNUNET_SCHEDULER_Task* rekey_task
static

Task scheduled for periodic re-generation (and thus rekeying) of our ephemeral key.

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

Referenced by do_rekey(), GSC_KX_done(), and GSC_KX_init().

◆ nc