GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
gnunet-communicator-udp.c File Reference

Transport plugin using UDP. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_constants.h"
#include "gnunet_nt_lib.h"
#include "gnunet_nat_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_application_service.h"
#include "gnunet_transport_communication_service.h"
Include dependency graph for gnunet-communicator-udp.c:

Go to the source code of this file.

Data Structures

struct  UdpHandshakeSignature
 Signature we use to verify that the ephemeral key was really chosen by the specified sender. More...
 
struct  InitialKX
 "Plaintext" header at beginning of KX message. More...
 
struct  UDPConfirmation
 Encrypted continuation of UDP initial handshake, followed by message header with payload. More...
 
struct  UDPAck
 UDP key acknowledgement. More...
 
struct  UdpBroadcastSignature
 Signature we use to verify that the broadcast was really made by the peer that claims to have made it. More...
 
struct  UDPBroadcast
 Broadcast by peer in LAN announcing its presence. More...
 
struct  UDPBox
 UDP message box. More...
 
struct  UDPRekey
 UDP message box. More...
 
struct  KeyCacheEntry
 Pre-generated "kid" code (key and IV identification code) to quickly derive master key for a struct UDPBox. More...
 
struct  SharedSecret
 Shared secret we generated for a particular sender or receiver. More...
 
struct  SenderAddress
 Information we track per sender address we have recently been in contact with (we decrypt messages from the sender). More...
 
struct  ReceiverAddress
 Information we track per receiving address we have recently been in contact with (encryption to receiver). More...
 
struct  BroadcastInterface
 Interface we broadcast our presence on. More...
 
struct  SearchContext
 Context information to be used while searching for operation contexts. More...
 

Macros

#define DEFAULT_REKEY_TIME_INTERVAL   GNUNET_TIME_UNIT_DAYS
 How often do we rekey based on time (at least) More...
 
#define PROTO_QUEUE_TIMEOUT   GNUNET_TIME_UNIT_MINUTES
 How long do we wait until we must have received the initial KX? More...
 
#define BROADCAST_FREQUENCY   GNUNET_TIME_UNIT_MINUTES
 How often do we broadcast our presence on the LAN? More...
 
#define INTERFACE_SCAN_FREQUENCY   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
 How often do we scan for changes to our network interfaces? More...
 
#define ADDRESS_VALIDITY_PERIOD   GNUNET_TIME_UNIT_HOURS
 How long do we believe our addresses to remain up (before the other peer should revalidate). More...
 
#define WORKING_QUEUE_INTERVALL   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS,1)
 
#define AES_KEY_SIZE   (256 / 8)
 AES key size. More...
 
#define AES_IV_SIZE   (96 / 8)
 AES (GCM) IV size. More...
 
#define GCM_TAG_SIZE   (128 / 8)
 Size of the GCM tag. More...
 
#define GENERATE_AT_ONCE   2
 
#define KCN_THRESHOLD   92
 If we fall below this number of available KCNs, we generate additional ACKs until we reach KCN_TARGET. More...
 
#define KCN_TARGET   128
 How many KCNs do we keep around after we hit the KCN_THRESHOLD? Should be larger than KCN_THRESHOLD so we do not generate just one ACK at the time. More...
 
#define MAX_SQN_DELTA   160
 What is the maximum delta between KCN sequence numbers that we allow. More...
 
#define MAX_SECRETS   128000
 How many shared master secrets do we keep around at most per sender? Should be large enough so that we generally have a chance of sending an ACK before the sender already rotated out the master secret. More...
 
#define DEFAULT_REKEY_MAX_BYTES   (1024LLU * 1024 * 1024 * 4LLU)
 Default value for how often we do rekey based on number of bytes transmitted? (additionally randomized). More...
 
#define COMMUNICATOR_ADDRESS_PREFIX   "udp"
 Address prefix used by the communicator. More...
 
#define COMMUNICATOR_CONFIG_SECTION   "communicator-udp"
 Configuration section used by the communicator. More...
 

Functions

static void bi_destroy (struct BroadcastInterface *bi)
 An interface went away, stop broadcasting on it. More...
 
static void receiver_destroy (struct ReceiverAddress *receiver)
 Destroys a receiving state due to timeout or shutdown. More...
 
static void kce_destroy (struct KeyCacheEntry *kce)
 Free memory used by key cache entry. More...
 
static void get_kid (const struct GNUNET_HashCode *msec, uint32_t serial, struct GNUNET_ShortHashCode *kid)
 Compute kid. More...
 
static void kce_generate (struct SharedSecret *ss, uint32_t seq)
 Setup key cache entry for sequence number seq and shared secret ss. More...
 
static int secret_destroy (struct SharedSecret *ss, int withoutKce)
 Destroy ss and associated key cache entries. More...
 
static void sender_destroy (struct SenderAddress *sender)
 Functions with this signature are called whenever we need to close a sender's state due to timeout. More...
 
static void get_iv_key (const struct GNUNET_HashCode *msec, uint32_t serial, char key[(256/8)], char iv[(96/8)])
 Compute key and iv. More...
 
static void reschedule_sender_timeout (struct SenderAddress *sender)
 Increment sender timeout due to activity. More...
 
static void reschedule_receiver_timeout (struct ReceiverAddress *receiver)
 Increment receiver timeout due to activity. More...
 
static void check_timeouts (void *cls)
 Task run to check #receiver_heap and #sender_heap for timeouts. More...
 
static void calculate_cmac (struct SharedSecret *ss)
 Calcualte cmac from master in ss. More...
 
static void pass_plaintext_to_core (struct SenderAddress *sender, const void *plaintext, size_t plaintext_len)
 We received plaintext_len bytes of plaintext from a sender. More...
 
static void setup_cipher (const struct GNUNET_HashCode *msec, uint32_t serial, gcry_cipher_hd_t *cipher)
 Setup cipher based on shared secret msec and serial number serial. More...
 
static int try_decrypt (const struct SharedSecret *ss, const char tag[(128/8)], uint32_t serial, const char *in_buf, size_t in_buf_size, char *out_buf)
 Try to decrypt buf using shared secret ss and key/iv derived using serial. More...
 
static struct SharedSecretsetup_shared_secret_dec (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
 Setup shared secret for decryption. More...
 
static struct SharedSecretsetup_shared_secret_enc (const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, struct ReceiverAddress *receiver, int add_to_receiver)
 Setup shared secret for encryption. More...
 
static void setup_receiver_mq (struct ReceiverAddress *receiver)
 Setup the MQ for the receiver. More...
 
static void destroy_all_secrets (struct SharedSecret *ss, int withoutKce)
 Destroying all secrets. More...
 
static void add_acks (struct SharedSecret *ss, int acks_to_add)
 
static uint32_t reset_rekey_kces (struct ReceiverAddress *receiver, uint32_t acks_to_add)
 
static void add_acks_rekey (struct ReceiverAddress *receiver)
 
static int handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 We received an ACK for pid. More...
 
static void try_handle_plaintext (struct SenderAddress *sender, const void *buf, size_t buf_size)
 Test if we have received a valid message in plaintext. More...
 
static void kce_generate_cb (void *cls)
 
static void kce_generate_rekey_cb (void *cls)
 
static void consider_ss_ack (struct SharedSecret *ss, int initial)
 We established a shared secret with a sender. More...
 
static void decrypt_box (const struct UDPBox *box, size_t box_len, struct KeyCacheEntry *kce)
 We received a box with matching kce. More...
 
static void decrypt_rekey (const struct UDPRekey *rekey, size_t rekey_len, struct KeyCacheEntry *kce, struct SenderAddress *sender)
 We received a rekey with matching kce. More...
 
static int find_sender_by_address (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Find existing struct SenderAddress by matching addresses. More...
 
static struct SenderAddresssetup_sender (const struct GNUNET_PeerIdentity *target, const struct sockaddr *address, socklen_t address_len)
 Create sender address for target. More...
 
static int verify_confirmation (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, const struct UDPConfirmation *uc)
 Check signature from uc against ephemeral. More...
 
static char * sockaddr_to_udpaddr_string (const struct sockaddr *address, socklen_t address_len)
 Converts address to the address string format used by this communicator in HELLOs. More...
 
static void sock_read (void *cls)
 Socket read task. More...
 
static struct sockaddr * udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
 Convert UDP bind specification to a struct sockaddr * More...
 
static void do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
 Pad dgram by pad_size using out_cipher. More...
 
static void mq_send_kx (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
 Signature of functions implementing the sending functionality of a message queue. More...
 
static void check_for_rekeying (struct ReceiverAddress *receiver, struct UDPBox *box)
 
static void send_UDPRekey (struct ReceiverAddress *receiver, struct SharedSecret *ss)
 
static void mq_send_d (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
 Signature of functions implementing the sending functionality of a message queue. More...
 
static void mq_destroy_d (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Signature of functions implementing the destruction of a message queue. More...
 
static void mq_destroy_kx (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Signature of functions implementing the destruction of a message queue. More...
 
static void mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Implementation function that cancels the currently sent message. More...
 
static void mq_error (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
static int mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
 Function called by the transport service to initialize a message queue given address information about another peer. More...
 
static int get_receiver_delete_it (void *cls, const struct GNUNET_PeerIdentity *target, void *value)
 Iterator over all receivers to clean up. More...
 
static int get_sender_delete_it (void *cls, const struct GNUNET_PeerIdentity *target, void *value)
 Iterator over all senders to clean up. More...
 
static void do_shutdown (void *cls)
 Shutdown the UNIX communicator. More...
 
static void enc_notify_cb (void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg)
 Function called when the transport service has received a backchannel message for this communicator (!) via a different return path. More...
 
static void nat_address_cb (void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
 Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of 'valid' addresses changes. More...
 
static void ifc_broadcast (void *cls)
 Broadcast our presence on one of our interfaces. More...
 
static int iface_proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen)
 Callback function invoked for each interface found. More...
 
static void do_broadcast (void *cls)
 Scan interfaces to broadcast our presence on the LAN. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Setup communicator and launch network interactions. More...
 
int main (int argc, char *const *argv)
 The main function for the UNIX communicator. More...
 

Variables

static struct GNUNET_TIME_Relative rekey_interval
 The rekey interval. More...
 
static unsigned long long rekey_max_bytes
 How often we do rekey based on number of bytes transmitted. More...
 
struct SharedSecretss_finished
 Shared secret we finished the last kce working queue for. More...
 
static struct GNUNET_CONTAINER_MultiShortmapkey_cache
 Cache of pre-generated key IDs. More...
 
static struct GNUNET_SCHEDULER_Taskread_task
 ID of read task. More...
 
static struct GNUNET_SCHEDULER_Tasktimeout_task
 ID of timeout task. More...
 
static struct GNUNET_SCHEDULER_Taskbroadcast_task
 ID of master broadcast task. More...
 
static struct GNUNET_STATISTICS_Handlestats
 For logging statistics. More...
 
static struct GNUNET_TRANSPORT_CommunicatorHandlech
 Our environment. More...
 
static struct GNUNET_CONTAINER_MultiPeerMapreceivers
 Receivers (map from peer identity to struct ReceiverAddress) More...
 
static struct GNUNET_CONTAINER_MultiPeerMapsenders
 Senders (map from peer identity to struct SenderAddress) More...
 
static struct GNUNET_CONTAINER_Heapsenders_heap
 Expiration heap for senders (contains struct SenderAddress) More...
 
static struct GNUNET_CONTAINER_Heapreceivers_heap
 Expiration heap for receivers (contains struct ReceiverAddress) More...
 
static struct BroadcastInterfacebi_head
 Broadcast interface tasks. More...
 
static struct BroadcastInterfacebi_tail
 Broadcast interface tasks. More...
 
static struct GNUNET_NETWORK_Handleudp_sock
 Our socket. More...
 
static int have_v6_socket
 GNUNET_YES if udp_sock supports IPv6. More...
 
static struct GNUNET_PeerIdentity my_identity
 Our public key. More...
 
static struct GNUNET_CRYPTO_EddsaPrivateKeymy_private_key
 Our private key. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration. More...
 
static struct GNUNET_TRANSPORT_ApplicationHandleah
 Our handle to report addresses for validation to TRANSPORT. More...
 
static struct GNUNET_NT_InterfaceScanneris
 Network scanner to determine network types. More...
 
static struct GNUNET_NAT_Handlenat
 Connection to NAT service. More...
 
static uint16_t my_port
 Port number to which we are actually bound. More...
 

Detailed Description

Transport plugin using UDP.

Author
Christian Grothoff

TODO:

Definition in file gnunet-communicator-udp.c.

Macro Definition Documentation

◆ DEFAULT_REKEY_TIME_INTERVAL

#define DEFAULT_REKEY_TIME_INTERVAL   GNUNET_TIME_UNIT_DAYS

How often do we rekey based on time (at least)

Definition at line 54 of file gnunet-communicator-udp.c.

Referenced by run().

◆ PROTO_QUEUE_TIMEOUT

#define PROTO_QUEUE_TIMEOUT   GNUNET_TIME_UNIT_MINUTES

How long do we wait until we must have received the initial KX?

Definition at line 59 of file gnunet-communicator-udp.c.

◆ BROADCAST_FREQUENCY

#define BROADCAST_FREQUENCY   GNUNET_TIME_UNIT_MINUTES

How often do we broadcast our presence on the LAN?

Definition at line 64 of file gnunet-communicator-udp.c.

Referenced by ifc_broadcast().

◆ INTERFACE_SCAN_FREQUENCY

#define INTERFACE_SCAN_FREQUENCY   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)

How often do we scan for changes to our network interfaces?

Definition at line 69 of file gnunet-communicator-udp.c.

Referenced by do_broadcast(), and ifc_broadcast().

◆ ADDRESS_VALIDITY_PERIOD

#define ADDRESS_VALIDITY_PERIOD   GNUNET_TIME_UNIT_HOURS

How long do we believe our addresses to remain up (before the other peer should revalidate).

Definition at line 76 of file gnunet-communicator-udp.c.

Referenced by pass_plaintext_to_core().

◆ WORKING_QUEUE_INTERVALL

#define WORKING_QUEUE_INTERVALL   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS,1)

◆ AES_KEY_SIZE

#define AES_KEY_SIZE   (256 / 8)

AES key size.

Definition at line 84 of file gnunet-communicator-udp.c.

Referenced by setup_cipher().

◆ AES_IV_SIZE

#define AES_IV_SIZE   (96 / 8)

AES (GCM) IV size.

Definition at line 89 of file gnunet-communicator-udp.c.

Referenced by get_iv_key(), and setup_cipher().

◆ GCM_TAG_SIZE

#define GCM_TAG_SIZE   (128 / 8)

Size of the GCM tag.

Definition at line 94 of file gnunet-communicator-udp.c.

◆ GENERATE_AT_ONCE

#define GENERATE_AT_ONCE   2

Definition at line 96 of file gnunet-communicator-udp.c.

Referenced by kce_generate_cb(), and kce_generate_rekey_cb().

◆ KCN_THRESHOLD

#define KCN_THRESHOLD   92

If we fall below this number of available KCNs, we generate additional ACKs until we reach KCN_TARGET.

Should be large enough that we don't generate ACKs all the time and still have enough time for the ACK to arrive before the sender runs out. So really this should ideally be based on the RTT.

Definition at line 107 of file gnunet-communicator-udp.c.

Referenced by consider_ss_ack().

◆ KCN_TARGET

#define KCN_TARGET   128

How many KCNs do we keep around after we hit the KCN_THRESHOLD? Should be larger than KCN_THRESHOLD so we do not generate just one ACK at the time.

Definition at line 115 of file gnunet-communicator-udp.c.

Referenced by kce_generate_cb().

◆ MAX_SQN_DELTA

#define MAX_SQN_DELTA   160

What is the maximum delta between KCN sequence numbers that we allow.

Used to expire 'ancient' KCNs that likely were dropped by the network. Must be larger than KCN_TARGET (otherwise we generate new KCNs all the time), but not too large (otherwise packet loss may cause sender to fall back to KX needlessly when sender runs out of ACK'ed KCNs due to losses).

Definition at line 126 of file gnunet-communicator-udp.c.

Referenced by consider_ss_ack().

◆ MAX_SECRETS

#define MAX_SECRETS   128000

How many shared master secrets do we keep around at most per sender? Should be large enough so that we generally have a chance of sending an ACK before the sender already rotated out the master secret.

Generally values around KCN_TARGET make sense. Might make sense to adapt to RTT if we had a good measurement...

Definition at line 137 of file gnunet-communicator-udp.c.

Referenced by consider_ss_ack(), and mq_send_kx().

◆ DEFAULT_REKEY_MAX_BYTES

#define DEFAULT_REKEY_MAX_BYTES   (1024LLU * 1024 * 1024 * 4LLU)

Default value for how often we do rekey based on number of bytes transmitted? (additionally randomized).

Definition at line 143 of file gnunet-communicator-udp.c.

Referenced by run().

◆ COMMUNICATOR_ADDRESS_PREFIX

#define COMMUNICATOR_ADDRESS_PREFIX   "udp"

Address prefix used by the communicator.

Definition at line 149 of file gnunet-communicator-udp.c.

Referenced by consider_ss_ack(), mq_init(), nat_address_cb(), run(), and sockaddr_to_udpaddr_string().

◆ COMMUNICATOR_CONFIG_SECTION

#define COMMUNICATOR_CONFIG_SECTION   "communicator-udp"

Configuration section used by the communicator.

Definition at line 154 of file gnunet-communicator-udp.c.

Referenced by run(), and udp_address_to_sockaddr().

Function Documentation

◆ bi_destroy()

static void bi_destroy ( struct BroadcastInterface bi)
static

An interface went away, stop broadcasting on it.

Parameters
bientity to close down

Definition at line 904 of file gnunet-communicator-udp.c.

References BroadcastInterface::ba, BroadcastInterface::broadcast_task, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_strerror, GNUNET_NETWORK_socket_setsockopt(), GNUNET_OK, GNUNET_SCHEDULER_cancel(), BroadcastInterface::mcreq, and BroadcastInterface::sa.

Referenced by do_broadcast(), and do_shutdown().

905 {
906  if (AF_INET6 == bi->sa->sa_family)
907  {
908  /* Leave the multicast group */
910  IPPROTO_IPV6,
911  IPV6_LEAVE_GROUP,
912  &bi->mcreq,
913  sizeof(bi->mcreq)))
914  {
916  }
917  }
920  GNUNET_free (bi->sa);
921  GNUNET_free (bi->ba);
922  GNUNET_free (bi);
923 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
Definition: network.c:880
static struct BroadcastInterface * bi_tail
Broadcast interface tasks.
static struct BroadcastInterface * bi_head
Broadcast interface tasks.
struct sockaddr * ba
Broadcast address to use on the interface.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
struct sockaddr * sa
Sender's address of the interface.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
struct ipv6_mreq mcreq
If this is an IPv6 interface, this is the request we use to join/leave the group. ...
struct GNUNET_SCHEDULER_Task * broadcast_task
Task for this broadcast interface.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
Here is the call graph for this function:
Here is the caller graph for this function:

◆ receiver_destroy()

static void receiver_destroy ( struct ReceiverAddress receiver)
static

Destroys a receiving state due to timeout or shutdown.

Parameters
receiverentity to close down

Definition at line 932 of file gnunet-communicator-udp.c.

References ReceiverAddress::address, ReceiverAddress::d_qh, ReceiverAddress::foreign_addr, GNUNET_assert, GNUNET_CONTAINER_heap_remove_node(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_TRANSPORT_communicator_mq_del(), GNUNET_YES, ReceiverAddress::hn, ReceiverAddress::kx_mq, ReceiverAddress::kx_qh, ReceiverAddress::receiver_destroy_called, and ReceiverAddress::target.

Referenced by check_timeouts(), get_receiver_delete_it(), mq_destroy_d(), mq_destroy_kx(), mq_error(), mq_send_d(), and mq_send_kx().

933 {
934 
936 
938  "Disconnecting receiver for peer `%s'\n",
939  GNUNET_i2s (&receiver->target));
940  /*if (NULL != (mq = receiver->kx_mq))
941  {
942  receiver->kx_mq = NULL;
943  GNUNET_MQ_destroy (mq);
944  }*/
945  if (NULL != receiver->kx_qh)
946  {
948  receiver->kx_qh = NULL;
949  receiver->kx_mq = NULL;
950  }
951  /*if (NULL != (mq = receiver->d_mq))
952  {
953  receiver->d_mq = NULL;
954  GNUNET_MQ_destroy (mq);
955  }*/
956  if (NULL != receiver->d_qh)
957  {
959  receiver->d_qh = NULL;
960  }
963  &receiver->target,
964  receiver));
965  GNUNET_assert (receiver == GNUNET_CONTAINER_heap_remove_node (receiver->hn));
967  "# receivers active",
969  GNUNET_NO);
970  GNUNET_free (receiver->address);
971  GNUNET_free (receiver->foreign_addr);
972  GNUNET_free (receiver);
973 }
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct sockaddr * address
Address of the other peer.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
void GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
Notify transport service that an MQ became unavailable due to a disconnect or timeout.
struct GNUNET_TRANSPORT_QueueHandle * d_qh
handle for default queue with the ch.
char * foreign_addr
Address of the receiver in the human-readable format with the COMMUNICATOR_ADDRESS_PREFIX.
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
struct GNUNET_MQ_Handle * kx_mq
KX message queue we are providing for the ch.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
int receiver_destroy_called
receiver_destroy already called on receiver.
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct GNUNET_PeerIdentity target
To whom are we talking to.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.
struct GNUNET_TRANSPORT_QueueHandle * kx_qh
handle for KX queue with the ch.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kce_destroy()

static void kce_destroy ( struct KeyCacheEntry kce)
static

Free memory used by key cache entry.

Parameters
kcethe key cache entry

Definition at line 982 of file gnunet-communicator-udp.c.

References SenderAddress::acks_available, SharedSecret::active_kce_count, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multishortmap_remove(), GNUNET_free, GNUNET_YES, SharedSecret::kce_head, SharedSecret::kce_tail, KeyCacheEntry::kid, SharedSecret::sender, and KeyCacheEntry::ss.

Referenced by consider_ss_ack(), decrypt_box(), decrypt_rekey(), and secret_destroy().

983 {
984  struct SharedSecret *ss = kce->ss;
985 
986  ss->active_kce_count--;
987  ss->sender->acks_available--;
990  &kce->kid,
991  kce));
992  GNUNET_free (kce);
993 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct KeyCacheEntry * kce_head
Kept in a DLL, sorted by sequence number.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.
struct SharedSecret * ss
Corresponding shared secret.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
struct KeyCacheEntry * kce_tail
Kept in a DLL, sorted by sequence number.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this sender.
Shared secret we generated for a particular sender or receiver.
unsigned int active_kce_count
Number of active KCN entries.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_kid()

static void get_kid ( const struct GNUNET_HashCode msec,
uint32_t  serial,
struct GNUNET_ShortHashCode kid 
)
static

Compute kid.

Parameters
msecmaster secret for HMAC calculation
serialnumber for the smac calculation
kid[out]where to write the key ID

Definition at line 1004 of file gnunet-communicator-udp.c.

References GNUNET_CRYPTO_hkdf().

Referenced by kce_generate(), mq_send_d(), and send_UDPRekey().

1007 {
1008  uint32_t sid = htonl (serial);
1009 
1010  GNUNET_CRYPTO_hkdf (kid,
1011  sizeof(*kid),
1012  GCRY_MD_SHA512,
1013  GCRY_MD_SHA256,
1014  &sid,
1015  sizeof(sid),
1016  msec,
1017  sizeof(*msec),
1018  "UDP-KID",
1019  strlen ("UDP-KID"),
1020  NULL,
1021  0);
1022 }
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf(void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_hkdf.c:320
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kce_generate()

static void kce_generate ( struct SharedSecret ss,
uint32_t  seq 
)
static

Setup key cache entry for sequence number seq and shared secret ss.

Parameters
ssshared secret
seqsequence number for the key cache entry

Definition at line 1032 of file gnunet-communicator-udp.c.

References SenderAddress::acks_available, SharedSecret::active_kce_count, get_kid(), GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multishortmap_put(), GNUNET_CONTAINER_multishortmap_size(), GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_set(), SharedSecret::kce_head, SharedSecret::kce_tail, KeyCacheEntry::kid, SharedSecret::master, SharedSecret::sender, KeyCacheEntry::sequence_number, and KeyCacheEntry::ss.

Referenced by consider_ss_ack(), kce_generate_cb(), and kce_generate_rekey_cb().

1033 {
1034  struct KeyCacheEntry *kce;
1035 
1036  GNUNET_assert (0 < seq);
1037  kce = GNUNET_new (struct KeyCacheEntry);
1038  kce->ss = ss;
1039  kce->sequence_number = seq;
1040  get_kid (&ss->master, seq, &kce->kid);
1042  ss->active_kce_count++;
1043  ss->sender->acks_available++;
1045  key_cache,
1046  &kce->kid,
1047  kce,
1050  "# KIDs active",
1052  GNUNET_NO);
1053 }
struct KeyCacheEntry * kce_head
Kept in a DLL, sorted by sequence number.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
struct SharedSecret * ss
Corresponding shared secret.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
uint32_t sequence_number
Sequence number used to derive this entry from master key.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
Pre-generated "kid" code (key and IV identification code) to quickly derive master key for a struct U...
struct GNUNET_HashCode master
Master shared secret.
struct KeyCacheEntry * kce_tail
Kept in a DLL, sorted by sequence number.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this sender.
int GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static void get_kid(const struct GNUNET_HashCode *msec, uint32_t serial, struct GNUNET_ShortHashCode *kid)
Compute kid.
unsigned int active_kce_count
Number of active KCN entries.
Allow multiple values with the same key.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ secret_destroy()

static int secret_destroy ( struct SharedSecret ss,
int  withoutKce 
)
static

Destroy ss and associated key cache entries.

Parameters
ssshared secret to destroy
withoutKceIf GNUNET_YES shared secrets with kce will not be destroyed.

Definition at line 1063 of file gnunet-communicator-udp.c.

References ReceiverAddress::acks_available, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multishortmap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_STATISTICS_update(), GNUNET_YES, kce_destroy(), SharedSecret::kce_head, SharedSecret::master, SenderAddress::num_secrets, ReceiverAddress::num_secrets, SharedSecret::receiver, UdpHandshakeSignature::receiver, SharedSecret::sender, UdpHandshakeSignature::sender, SharedSecret::sequence_allowed, SharedSecret::sequence_used, SenderAddress::ss_head, ReceiverAddress::ss_head, SenderAddress::ss_tail, and ReceiverAddress::ss_tail.

Referenced by destroy_all_secrets().

1064 {
1065  struct SenderAddress *sender;
1066  struct ReceiverAddress *receiver;
1067  struct KeyCacheEntry *kce;
1068 
1069  if (withoutKce && (ss->sequence_allowed > 0))
1070  return GNUNET_NO;
1071 
1073  "secret %s destroy %u %u\n",
1074  GNUNET_h2s (&ss->master),
1075  withoutKce,
1076  ss->sequence_allowed);
1077  if (NULL != (sender = ss->sender))
1078  {
1079  GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss);
1080  sender->num_secrets--;
1081  }
1082  if (NULL != (receiver = ss->receiver))
1083  {
1084  GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
1085  receiver->num_secrets--;
1086  // Uncomment this for alternativ 1 of backchannel functionality
1087  receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used);
1089  "%u receiver->acks_available 3\n",
1090  receiver->acks_available);
1091  // Until here for alternativ 1
1092  }
1093  while (NULL != (kce = ss->kce_head))
1094  kce_destroy (kce);
1095  GNUNET_STATISTICS_update (stats, "# Secrets active", -1, GNUNET_NO);
1097  "# KIDs active",
1099  GNUNET_NO);
1100  GNUNET_free (ss);
1101  return GNUNET_YES;
1102 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct SharedSecret * ss_tail
Shared secrets we used with target, last used is tail.
struct KeyCacheEntry * kce_head
Kept in a DLL, sorted by sequence number.
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
uint32_t sequence_allowed
Up to which sequence number did the other peer allow us to use this key, or up to which number did we...
unsigned int num_secrets
Length of the DLL at ss_head.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static void kce_destroy(struct KeyCacheEntry *kce)
Free memory used by key cache entry.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct SharedSecret * ss_head
Shared secrets we used with target, first used is head.
Pre-generated "kid" code (key and IV identification code) to quickly derive master key for a struct U...
uint32_t sequence_used
Up to which sequence number did we use this master already? (for encrypting only) ...
struct GNUNET_HashCode master
Master shared secret.
struct SharedSecret * ss_tail
Shared secrets we received with target, last used is tail.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
Information we track per receiving address we have recently been in contact with (encryption to recei...
unsigned int num_secrets
Length of the DLL at ss_head.
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:329
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
struct ReceiverAddress * receiver
Receiver we use this shared secret with, or NULL.
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
#define GNUNET_free(ptr)
Wrapper around free.
struct SharedSecret * ss_head
Shared secrets we received from target, first used is head.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sender_destroy()

static void sender_destroy ( struct SenderAddress sender)
static

Functions with this signature are called whenever we need to close a sender's state due to timeout.

Parameters
senderentity to close down

Definition at line 1112 of file gnunet-communicator-udp.c.

References SenderAddress::address, GNUNET_assert, GNUNET_CONTAINER_heap_remove_node(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_free, GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_YES, SenderAddress::hn, SenderAddress::sender_destroy_called, and SenderAddress::target.

Referenced by check_timeouts(), and get_sender_delete_it().

1113 {
1115  GNUNET_assert (
1116  GNUNET_YES ==
1118  GNUNET_assert (sender == GNUNET_CONTAINER_heap_remove_node (sender->hn));
1120  "# senders active",
1122  GNUNET_NO);
1123  GNUNET_free (sender->address);
1124  GNUNET_free (sender);
1125 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int sender_destroy_called
sender_destroy already called on sender.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct sockaddr * address
Address of the other peer.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_CONTAINER_MultiPeerMap * senders
Senders (map from peer identity to struct SenderAddress)
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_iv_key()

static void get_iv_key ( const struct GNUNET_HashCode msec,
uint32_t  serial,
char  key[(256/8)],
char  iv[(96/8)] 
)
static

Compute key and iv.

Parameters
msecmaster secret for calculation
serialnumber for the smac calculation
key[out]where to write the decrption key
iv[out]where to write the IV

Definition at line 1137 of file gnunet-communicator-udp.c.

References AES_IV_SIZE, GNUNET_CRYPTO_hkdf(), key, and res.

Referenced by setup_cipher().

1141 {
1142  uint32_t sid = htonl (serial);
1143  char res[AES_KEY_SIZE + AES_IV_SIZE];
1144 
1145  GNUNET_CRYPTO_hkdf (res,
1146  sizeof(res),
1147  GCRY_MD_SHA512,
1148  GCRY_MD_SHA256,
1149  &sid,
1150  sizeof(sid),
1151  msec,
1152  sizeof(*msec),
1153  "UDP-IV-KEY",
1154  strlen ("UDP-IV-KEY"),
1155  NULL,
1156  0);
1157  memcpy (key, res, AES_KEY_SIZE);
1158  memcpy (iv, &res[AES_KEY_SIZE], AES_IV_SIZE);
1159 }
#define AES_IV_SIZE
AES (GCM) IV size.
static int res
struct GNUNET_HashCode key
The key used in the DHT.
#define AES_KEY_SIZE
AES key size.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf(void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_hkdf.c:320
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reschedule_sender_timeout()

static void reschedule_sender_timeout ( struct SenderAddress sender)
static

Increment sender timeout due to activity.

Parameters
senderaddress for which the timeout should be rescheduled

Definition at line 1168 of file gnunet-communicator-udp.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_heap_update_cost(), GNUNET_TIME_relative_to_absolute(), SenderAddress::hn, and SenderAddress::timeout.

Referenced by setup_sender().

1169 {
1170  sender->timeout =
1173 }
void GNUNET_CONTAINER_heap_update_cost(struct GNUNET_CONTAINER_HeapNode *node, GNUNET_CONTAINER_HeapCostType new_cost)
Updates the cost of any node in the tree.
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:246
struct GNUNET_TIME_Absolute timeout
Timeout for this sender.
uint64_t abs_value_us
The actual value.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reschedule_receiver_timeout()

static void reschedule_receiver_timeout ( struct ReceiverAddress receiver)
static

Increment receiver timeout due to activity.

Parameters
receiveraddress for which the timeout should be rescheduled

Definition at line 1182 of file gnunet-communicator-udp.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_heap_update_cost(), GNUNET_TIME_relative_to_absolute(), ReceiverAddress::hn, and ReceiverAddress::timeout.

Referenced by mq_send_d(), and mq_send_kx().

1183 {
1184  receiver->timeout =
1187  receiver->timeout.abs_value_us);
1188 }
void GNUNET_CONTAINER_heap_update_cost(struct GNUNET_CONTAINER_HeapNode *node, GNUNET_CONTAINER_HeapCostType new_cost)
Updates the cost of any node in the tree.
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
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:246
uint64_t abs_value_us
The actual value.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
struct GNUNET_TIME_Absolute timeout
Timeout for this receiver address.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_timeouts()

static void check_timeouts ( void *  cls)
static

Task run to check #receiver_heap and #sender_heap for timeouts.

Parameters
clsunused, NULL

Definition at line 1197 of file gnunet-communicator-udp.c.

References GNUNET_CONTAINER_heap_peek(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_min(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, UdpHandshakeSignature::receiver, receiver_destroy(), GNUNET_TIME_Relative::rel_value_us, UdpHandshakeSignature::sender, sender_destroy(), SenderAddress::sender_destroy_called, SenderAddress::timeout, and ReceiverAddress::timeout.

Referenced by mq_init(), and setup_sender().

1198 {
1199  struct GNUNET_TIME_Relative st;
1200  struct GNUNET_TIME_Relative rt;
1201  struct GNUNET_TIME_Relative delay;
1202  struct ReceiverAddress *receiver;
1203  struct SenderAddress *sender;
1204 
1205  (void) cls;
1206  timeout_task = NULL;
1208  while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap)))
1209  {
1210  /* if (GNUNET_YES != receiver->receiver_destroy_called) */
1211  /* { */
1213  if (0 != rt.rel_value_us)
1214  break;
1216  "Receiver timed out\n");
1217  receiver_destroy (receiver);
1218  // }
1219  }
1221  while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap)))
1222  {
1223  if (GNUNET_YES != sender->sender_destroy_called)
1224  {
1226  if (0 != st.rel_value_us)
1227  break;
1228  sender_destroy (sender);
1229  }
1230  }
1232  if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
1234 }
uint64_t rel_value_us
The actual value.
int sender_destroy_called
sender_destroy already called on sender.
struct GNUNET_TIME_Absolute timeout
Timeout for this sender.
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:1269
void * GNUNET_CONTAINER_heap_peek(const struct GNUNET_CONTAINER_Heap *heap)
Get element stored at the root of heap.
static void check_timeouts(void *cls)
Task run to check #receiver_heap and #sender_heap for timeouts.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Information we track per receiving address we have recently been in contact with (encryption to recei...
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:272
static struct GNUNET_CONTAINER_Heap * senders_heap
Expiration heap for senders (contains struct SenderAddress)
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
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:329
static struct GNUNET_CONTAINER_Heap * receivers_heap
Expiration heap for receivers (contains struct ReceiverAddress)
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
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:331
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
struct GNUNET_TIME_Absolute timeout
Timeout for this receiver address.
static void sender_destroy(struct SenderAddress *sender)
Functions with this signature are called whenever we need to close a sender&#39;s state due to timeout...
Time for relative time used by GNUnet, in microseconds.
static struct GNUNET_SCHEDULER_Task * timeout_task
ID of timeout task.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_cmac()

static void calculate_cmac ( struct SharedSecret ss)
static

Calcualte cmac from master in ss.

Parameters
ss[in,out]data structure to complete

Definition at line 1243 of file gnunet-communicator-udp.c.

References SharedSecret::cmac, GNUNET_CRYPTO_hkdf(), and SharedSecret::master.

Referenced by decrypt_rekey(), setup_shared_secret_enc(), and sock_read().

1244 {
1245  GNUNET_CRYPTO_hkdf (&ss->cmac,
1246  sizeof(ss->cmac),
1247  GCRY_MD_SHA512,
1248  GCRY_MD_SHA256,
1249  "CMAC",
1250  strlen ("CMAC"),
1251  &ss->master,
1252  sizeof(ss->master),
1253  "UDP-CMAC",
1254  strlen ("UDP-CMAC"),
1255  NULL,
1256  0);
1257 }
struct GNUNET_HashCode cmac
CMAC is used to identify master in ACKs.
struct GNUNET_HashCode master
Master shared secret.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf(void *result, size_t out_len, int xtr_algo, int prf_algo, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_hkdf.c:320
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pass_plaintext_to_core()

static void pass_plaintext_to_core ( struct SenderAddress sender,
const void *  plaintext,
size_t  plaintext_len 
)
static

We received plaintext_len bytes of plaintext from a sender.

Pass it on to CORE.

Parameters
queuethe queue that received the plaintext
plaintextthe plaintext that was received
plaintext_lennumber of bytes of plaintext received

Definition at line 1269 of file gnunet-communicator-udp.c.

References ADDRESS_VALIDITY_PERIOD, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TRANSPORT_communicator_receive(), GNUNET_MessageHeader::size, and SenderAddress::target.

Referenced by try_handle_plaintext().

1272 {
1273  const struct GNUNET_MessageHeader *hdr = plaintext;
1274  const char *pos = plaintext;
1275 
1276  while (ntohs (hdr->size) < plaintext_len)
1277  {
1279  "# bytes given to core",
1280  ntohs (hdr->size),
1281  GNUNET_NO);
1283  "Giving %u bytes to TNG\n", ntohs (hdr->size));
1286  &sender->target,
1287  hdr,
1289  NULL /* no flow control possible */
1290  ,
1291  NULL));
1292  /* move on to next message, if any */
1293  plaintext_len -= ntohs (hdr->size);
1294  if (plaintext_len < sizeof(*hdr))
1295  break;
1296  pos += ntohs (hdr->size);
1297  hdr = (const struct GNUNET_MessageHeader *) pos;
1298  // TODO for now..., we do not actually sen >1msg or have a way of telling
1299  // if we are done
1300  break;
1301  }
1303  "# bytes padding discarded",
1304  plaintext_len,
1305  GNUNET_NO);
1306 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_PeerIdentity target
To whom are we talking to.
int GNUNET_TRANSPORT_communicator_receive(struct GNUNET_TRANSPORT_CommunicatorHandle *handle, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
Notify transport service that the communicator has received a message.
#define ADDRESS_VALIDITY_PERIOD
How long do we believe our addresses to remain up (before the other peer should revalidate).
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
Header for all communications.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_cipher()

static void setup_cipher ( const struct GNUNET_HashCode msec,
uint32_t  serial,
gcry_cipher_hd_t *  cipher 
)
static

Setup cipher based on shared secret msec and serial number serial.

Parameters
msecmaster shared secret
serialserial number of cipher to set up
cipher[out]cipher to initialize

Definition at line 1318 of file gnunet-communicator-udp.c.

References AES_IV_SIZE, AES_KEY_SIZE, get_iv_key(), GNUNET_assert, and key.

Referenced by mq_send_d(), mq_send_kx(), send_UDPRekey(), and try_decrypt().

1321 {
1322  char key[AES_KEY_SIZE];
1323  char iv[AES_IV_SIZE];
1324  int rc;
1325 
1326  GNUNET_assert (0 ==
1327  gcry_cipher_open (cipher,
1328  GCRY_CIPHER_AES256 /* low level: go for speed */,
1329  GCRY_CIPHER_MODE_GCM,
1330  0 /* flags */));
1331  get_iv_key (msec, serial, key, iv);
1332  rc = gcry_cipher_setkey (*cipher, key, sizeof(key));
1333  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
1334  rc = gcry_cipher_setiv (*cipher, iv, sizeof(iv));
1335  GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY));
1336 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define AES_IV_SIZE
AES (GCM) IV size.
struct GNUNET_HashCode key
The key used in the DHT.
#define AES_KEY_SIZE
AES key size.
static void get_iv_key(const struct GNUNET_HashCode *msec, uint32_t serial, char key[(256/8)], char iv[(96/8)])
Compute key and iv.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_decrypt()

static int try_decrypt ( const struct SharedSecret ss,
const char  tag[(128/8)],
uint32_t  serial,
const char *  in_buf,
size_t  in_buf_size,
char *  out_buf 
)
static

Try to decrypt buf using shared secret ss and key/iv derived using serial.

Parameters
ssshared secret
tagGCM authentication tag
serialserial number to use
in_bufinput buffer to decrypt
in_buf_sizenumber of bytes in in_buf and available in out_buf
out_bufwhere to write the result
Returns
GNUNET_OK on success

Definition at line 1352 of file gnunet-communicator-udp.c.

References GNUNET_assert, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, SharedSecret::master, and setup_cipher().

Referenced by decrypt_box(), decrypt_rekey(), and sock_read().

1358 {
1359  gcry_cipher_hd_t cipher;
1360 
1361  setup_cipher (&ss->master, serial, &cipher);
1362  GNUNET_assert (
1363  0 ==
1364  gcry_cipher_decrypt (cipher, out_buf, in_buf_size, in_buf, in_buf_size));
1365  if (0 != gcry_cipher_checktag (cipher, tag, GCM_TAG_SIZE))
1366  {
1367  gcry_cipher_close (cipher);
1369  "# AEAD authentication failures",
1370  1,
1371  GNUNET_NO);
1372  return GNUNET_SYSERR;
1373  }
1374  gcry_cipher_close (cipher);
1375  return GNUNET_OK;
1376 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GCM_TAG_SIZE
Size of the GCM tag.
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 void setup_cipher(const struct GNUNET_HashCode *msec, uint32_t serial, gcry_cipher_hd_t *cipher)
Setup cipher based on shared secret msec and serial number serial.
struct GNUNET_HashCode master
Master shared secret.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_shared_secret_dec()

static struct SharedSecret* setup_shared_secret_dec ( const struct GNUNET_CRYPTO_EcdhePublicKey ephemeral)
static

Setup shared secret for decryption.

Parameters
ephemeralephemeral key we received from the other peer
Returns
new shared secret

Definition at line 1386 of file gnunet-communicator-udp.c.

References GNUNET_CRYPTO_eddsa_ecdh(), GNUNET_new, and SharedSecret::master.

Referenced by sock_read().

1387 {
1388  struct SharedSecret *ss;
1389 
1390  ss = GNUNET_new (struct SharedSecret);
1391  GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &ss->master);
1392  return ss;
1393 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_HashCode master
Master shared secret.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
Shared secret we generated for a particular sender or receiver.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_ecdh(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a ECDH public key and a private EdDSA key.
Definition: crypto_ecc.c:827
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_shared_secret_enc()

static struct SharedSecret* setup_shared_secret_enc ( const struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral,
struct ReceiverAddress receiver,
int  add_to_receiver 
)
static

Setup shared secret for encryption.

Parameters
ephemeralephemeral key we are sending to the other peer
receiver[in,out]queue to initialize encryption key for
Returns
new shared secret

Definition at line 1404 of file gnunet-communicator-udp.c.

References calculate_cmac(), GNUNET_CONTAINER_DLL_insert, GNUNET_CRYPTO_ecdh_eddsa(), GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_update(), SharedSecret::master, ReceiverAddress::num_secrets, GNUNET_PeerIdentity::public_key, SharedSecret::receiver, UdpHandshakeSignature::receiver, setup_receiver_mq(), ReceiverAddress::ss_head, ReceiverAddress::ss_tail, and ReceiverAddress::target.

Referenced by mq_send_kx(), and send_UDPRekey().

1406 {
1407  struct SharedSecret *ss;
1408 
1409  ss = GNUNET_new (struct SharedSecret);
1410  GNUNET_CRYPTO_ecdh_eddsa (ephemeral,
1411  &receiver->target.public_key,
1412  &ss->master);
1413  calculate_cmac (ss);
1414  ss->receiver = receiver;
1415  GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1416  receiver->num_secrets++;
1417  GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
1418  return ss;
1419 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
unsigned int num_secrets
Length of the DLL at ss_head.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_eddsa(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a EdDSA public key and a private ECDH key.
Definition: crypto_ecc.c:867
struct GNUNET_HashCode master
Master shared secret.
struct SharedSecret * ss_tail
Shared secrets we received with target, last used is tail.
Shared secret we generated for a particular sender or receiver.
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:329
struct ReceiverAddress * receiver
Receiver we use this shared secret with, or NULL.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static void calculate_cmac(struct SharedSecret *ss)
Calcualte cmac from master in ss.
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
struct SharedSecret * ss_head
Shared secrets we received from target, first used is head.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_receiver_mq()

static void setup_receiver_mq ( struct ReceiverAddress receiver)
static

Setup the MQ for the receiver.

If a queue exists, the existing one is destroyed. Then the MTU is recalculated and a fresh queue is initialized.

Parameters
receiverreceiver to setup MQ for

Definition at line 3075 of file gnunet-communicator-udp.c.

References ReceiverAddress::address, ReceiverAddress::d_mq, ReceiverAddress::d_mtu, ReceiverAddress::d_qh, ReceiverAddress::foreign_addr, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MQ_queue_for_callbacks(), GNUNET_TRANSPORT_communicator_mq_add(), GNUNET_TRANSPORT_CS_OUTBOUND, GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, ReceiverAddress::kx_mq, ReceiverAddress::kx_mtu, ReceiverAddress::kx_qh, mq_cancel(), mq_destroy_d(), mq_destroy_kx(), mq_error(), mq_send_d(), mq_send_kx(), ReceiverAddress::nt, and ReceiverAddress::target.

Referenced by mq_init(), and setup_shared_secret_enc().

3076 {
3077  size_t base_mtu;
3078 
3079  /*if (NULL != receiver->kx_qh)
3080  {
3081  GNUNET_TRANSPORT_communicator_mq_del (receiver->kx_qh);
3082  receiver->kx_qh = NULL;
3083  }
3084  if (NULL != receiver->d_qh)
3085  {
3086  GNUNET_TRANSPORT_communicator_mq_del (receiver->d_qh);
3087  receiver->d_qh = NULL;
3088  }*/
3089  // GNUNET_assert (NULL == receiver->mq);
3090  switch (receiver->address->sa_family)
3091  {
3092  case AF_INET:
3093  base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */
3094  - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */
3095  - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
3096  break;
3097 
3098  case AF_INET6:
3099  base_mtu = 1280 /* Minimum MTU required by IPv6 */
3100  - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */
3101  - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
3102  break;
3103 
3104  default:
3105  GNUNET_assert (0);
3106  break;
3107  }
3108  /* MTU based on full KX messages */
3109  receiver->kx_mtu = base_mtu - sizeof(struct InitialKX) /* 48 */
3110  - sizeof(struct UDPConfirmation); /* 104 */
3111  /* MTU based on BOXed messages */
3112  receiver->d_mtu = base_mtu - sizeof(struct UDPBox);
3113 
3115  "Setting up MQs and QHs\n");
3116  /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to
3117  1404 (IPv4 + Box) bytes, depending on circumstances... */
3118  if (NULL == receiver->kx_mq)
3120  &mq_destroy_kx,
3121  &mq_cancel,
3122  receiver,
3123  NULL,
3124  &mq_error,
3125  receiver);
3126  if (NULL == receiver->d_mq)
3128  &mq_destroy_d,
3129  &mq_cancel,
3130  receiver,
3131  NULL,
3132  &mq_error,
3133  receiver);
3134 
3135  receiver->kx_qh =
3137  &receiver->target,
3138  receiver->foreign_addr,
3139  receiver->kx_mtu,
3141  0, /* Priority */
3142  receiver->nt,
3144  receiver->kx_mq);
3145  receiver->d_qh =
3147  &receiver->target,
3148  receiver->foreign_addr,
3149  receiver->d_mtu,
3150  0, /* Initialize with 0 acks */
3151  1, /* Priority */
3152  receiver->nt,
3154  receiver->d_mq);
3155 
3156 }
static void mq_send_d(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue. ...
static void mq_destroy_d(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct sockaddr * address
Address of the other peer.
UDP packet header.
Standard IPv4 header.
Encrypted continuation of UDP initial handshake, followed by message header with payload.
"Plaintext" header at beginning of KX message.
struct GNUNET_TRANSPORT_QueueHandle * d_qh
handle for default queue with the ch.
char * foreign_addr
Address of the receiver in the human-readable format with the COMMUNICATOR_ADDRESS_PREFIX.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition: mq.c:565
enum GNUNET_NetworkType nt
Which network type does this queue use?
struct GNUNET_MQ_Handle * kx_mq
KX message queue we are providing for the ch.
size_t kx_mtu
MTU we allowed transport for this receiver&#39;s KX queue.
UDP message box.
static void mq_destroy_kx(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
size_t d_mtu
MTU we allowed transport for this receiver&#39;s default queue.
struct GNUNET_TRANSPORT_QueueHandle * GNUNET_TRANSPORT_communicator_mq_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
Notify transport service that a MQ became available due to an "inbound" connection or because the com...
Standard IPv6 header.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
this is an outbound connection (transport initiated)
#define GNUNET_log(kind,...)
static void mq_error(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
struct GNUNET_PeerIdentity target
To whom are we talking to.
static void mq_send_kx(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Signature of functions implementing the sending functionality of a message queue. ...
struct GNUNET_TRANSPORT_QueueHandle * kx_qh
handle for KX queue with the ch.
struct GNUNET_MQ_Handle * d_mq
Default message queue we are providing for the ch.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy_all_secrets()

static void destroy_all_secrets ( struct SharedSecret ss,
int  withoutKce 
)
static

Destroying all secrets.

Depending on parameter we keep those secrets having a kce.

Parameters
ssThe secret we will not destroy.
withoutKceIf GNUNET_YES shared secrets with kce will not be destroyed.

Definition at line 1439 of file gnunet-communicator-udp.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_NO, SharedSecret::next, SharedSecret::receiver, UdpHandshakeSignature::receiver, secret_destroy(), SharedSecret::sender, UdpHandshakeSignature::sender, SenderAddress::ss_head, and ReceiverAddress::ss_head.

Referenced by add_acks(), consider_ss_ack(), and mq_send_kx().

1440 {
1441  struct SenderAddress *sender;
1442  struct ReceiverAddress *receiver;
1443  struct SharedSecret *ss_to_destroy;
1444  struct SharedSecret *ss_start;
1445  struct SharedSecret *pos;
1446  int at_least_one_destroyed = GNUNET_NO;
1447 
1449  "Starting destroy all withoutKce: %u.\n",
1450  withoutKce);
1451 
1452  if (NULL != (sender = ss->sender))
1453  {
1454  ss_start = sender->ss_head;
1455  }
1456  else if (NULL != (receiver = ss->receiver))
1457  {
1458  ss_start = receiver->ss_head;
1459  }
1460  else
1461  {
1463  "Shared secret has no sender or receiver!\n");
1464  return;
1465  }
1466 
1467  pos = ss_start;
1468  while (NULL != pos)
1469  {
1470  ss_to_destroy = pos;
1471  pos = pos->next;
1472 
1473  if (ss != ss_to_destroy)
1474  at_least_one_destroyed = secret_destroy (ss_to_destroy, withoutKce);
1475  }
1476 
1477  if ((ss != ss_start) && ! at_least_one_destroyed)
1478  {
1480  "Really destroying all.\n");
1481  destroy_all_secrets (ss_start, GNUNET_NO);
1482  }
1483 
1485  "Finished destroy all.\n");
1486 }
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
struct SharedSecret * ss_head
Shared secrets we used with target, first used is head.
struct SharedSecret * next
Kept in a DLL.
Information we track per receiving address we have recently been in contact with (encryption to recei...
Shared secret we generated for a particular sender or receiver.
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:329
struct ReceiverAddress * receiver
Receiver we use this shared secret with, or NULL.
static int secret_destroy(struct SharedSecret *ss, int withoutKce)
Destroy ss and associated key cache entries.
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
#define GNUNET_log(kind,...)
static void destroy_all_secrets(struct SharedSecret *ss, int withoutKce)
Destroying all secrets.
struct SharedSecret * ss_head
Shared secrets we received from target, first used is head.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_acks()

static void add_acks ( struct SharedSecret ss,
int  acks_to_add 
)
static

Definition at line 1490 of file gnunet-communicator-udp.c.

References ReceiverAddress::d_qh, destroy_all_secrets(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_TRANSPORT_communicator_mq_update(), GNUNET_YES, ReceiverAddress::number_rekeying_kce, SharedSecret::receiver, ReceiverAddress::ss_head, and ReceiverAddress::ss_tail.

Referenced by add_acks_rekey(), and handle_ack().

1491 {
1492 
1493  struct ReceiverAddress *receiver = ss->receiver;
1494 
1495  if (NULL == ss)
1497  "secret NULL!\n");
1498 
1499  if (NULL == receiver)
1501  "Receiver NULL!\n");
1502  if (NULL == receiver->d_qh)
1504  "Queue NULL!\n");
1505 
1507  "Tell transport we have %u more acks!\n",
1508  acks_to_add);
1510  "%u kce for rekeying.\n",
1511  receiver->number_rekeying_kce);
1513  receiver->d_qh,
1514  acks_to_add,
1515  1);
1516  // Until here for alternativ 1
1517 
1518  /* move ss to head to avoid discarding it anytime soon! */
1519 
1520  GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
1521  GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1523 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_TRANSPORT_QueueHandle * d_qh
handle for default queue with the ch.
struct SharedSecret * ss_tail
Shared secrets we received with target, last used is tail.
Information we track per receiving address we have recently been in contact with (encryption to recei...
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:329
struct ReceiverAddress * receiver
Receiver we use this shared secret with, or NULL.
#define GNUNET_log(kind,...)
int number_rekeying_kce
Numer of kce we retain for sending the rekeying shared secret.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static void destroy_all_secrets(struct SharedSecret *ss, int withoutKce)
Destroying all secrets.
void GNUNET_TRANSPORT_communicator_mq_update(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_TRANSPORT_QueueHandle *u_qh, uint64_t q_len, uint32_t priority)
Notify transport service that an MQ was updated.
struct SharedSecret * ss_head
Shared secrets we received from target, first used is head.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_rekey_kces()

static uint32_t reset_rekey_kces ( struct ReceiverAddress receiver,
uint32_t  acks_to_add 
)
static

Definition at line 1527 of file gnunet-communicator-udp.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and ReceiverAddress::number_rekeying_kce.

Referenced by add_acks_rekey(), and handle_ack().

1529 {
1530  int needed_for_rekeying;
1531 
1533  "%u kce for rekeying and %u acks_to_add\n",
1534  receiver->number_rekeying_kce,
1535  acks_to_add);
1536 
1537  needed_for_rekeying = (3 - receiver->number_rekeying_kce);
1538  if (acks_to_add <= needed_for_rekeying)
1539  {
1540  receiver->number_rekeying_kce += acks_to_add;
1541  acks_to_add = 0;
1542  }
1543  else
1544  {
1545  acks_to_add -= (3 - receiver->number_rekeying_kce);
1546  receiver->number_rekeying_kce = 3;
1547  }
1548 
1550  "%u kce for rekeying and %u acks_to_add\n",
1551  receiver->number_rekeying_kce,
1552  acks_to_add);
1553  return acks_to_add;
1554 }
#define GNUNET_log(kind,...)
int number_rekeying_kce
Numer of kce we retain for sending the rekeying shared secret.
Here is the caller graph for this function:

◆ add_acks_rekey()

static void add_acks_rekey ( struct ReceiverAddress receiver)
static

Definition at line 1558 of file gnunet-communicator-udp.c.

References ReceiverAddress::acks_available, add_acks(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), ReceiverAddress::number_rekeying_kce, reset_rekey_kces(), SharedSecret::sequence_allowed, and ReceiverAddress::ss_rekey.

Referenced by handle_ack(), and mq_send_d().

1559 {
1560  uint32_t acks_to_add = receiver->ss_rekey->sequence_allowed;
1561 
1562  if (receiver->number_rekeying_kce < 3)
1563  acks_to_add = reset_rekey_kces (receiver, acks_to_add);
1564  receiver->acks_available = receiver->ss_rekey->sequence_allowed;
1566  "%u receiver->acks_available 4\n",
1567  receiver->acks_available);
1568  /* add_acks (receiver->ss_rekey, acks_to_add - 3); */
1569  if (0 != acks_to_add)
1570  {
1571  add_acks (receiver->ss_rekey, acks_to_add);
1572  }
1573  receiver->ss_rekey = NULL;
1575  "# rekeying successful\n");
1577  "# rekeying successful",
1578  1,
1579  GNUNET_NO);
1580 }
static void add_acks(struct SharedSecret *ss, int acks_to_add)
uint32_t sequence_allowed
Up to which sequence number did the other peer allow us to use this key, or up to which number did we...
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 uint32_t reset_rekey_kces(struct ReceiverAddress *receiver, uint32_t acks_to_add)
struct SharedSecret * ss_rekey
Shared secret we use with target for rekeying.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
int number_rekeying_kce
Numer of kce we retain for sending the rekeying shared secret.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_ack()

static int handle_ack ( void *  cls,
const struct GNUNET_PeerIdentity pid,
void *  value 
)
static

We received an ACK for pid.

Check if it is for the receiver in value and if so, handle it and return GNUNET_NO. Otherwise, return GNUNET_YES.

Parameters
clsa const struct UDPAck
pidpeer the ACK is from
valuea struct ReceiverAddress
Returns
GNUNET_YES to continue to iterate

Definition at line 1594 of file gnunet-communicator-udp.c.

References UDPAck::acks_available, ReceiverAddress::acks_available, add_acks(), add_acks_rekey(), UDPAck::cmac, SharedSecret::cmac, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_YES, SharedSecret::master, SharedSecret::next, ReceiverAddress::number_rekeying_kce, ReceiverAddress::rekeying, reset_rekey_kces(), SharedSecret::sequence_allowed, UDPAck::sequence_max, ReceiverAddress::ss_head, ReceiverAddress::ss_rekey, and value.

Referenced by enc_notify_cb(), and try_handle_plaintext().

1595 {
1596  const struct UDPAck *ack = cls;
1597  struct ReceiverAddress *receiver = value;
1598  uint32_t acks_to_add;
1599  uint32_t allowed;
1600  // int needed_for_rekeying;
1601 
1603  "in handle ack with cmac %s\n",
1604  GNUNET_h2s (&ack->cmac));
1605 
1606  if (NULL != receiver->ss_rekey)
1608  "We have rekey secret with cmac %s \n",
1609  GNUNET_h2s (&receiver->ss_rekey->cmac));
1610 
1611  if ((NULL != receiver->ss_rekey) && (0 == memcmp (&ack->cmac,
1612  &receiver->ss_rekey->cmac,
1613  sizeof(struct
1614  GNUNET_HashCode))) )
1615  {
1616  allowed = ntohl (ack->sequence_max);
1617 
1618  if (allowed > receiver->ss_rekey->sequence_allowed)
1619  {
1621  "%u > %u (%u %u) for rekey secrect %s\n", allowed,
1622  receiver->ss_rekey->sequence_allowed,
1623  receiver->acks_available,
1624  ack->acks_available,
1625  GNUNET_h2s (&receiver->ss_rekey->master));
1626 
1627  receiver->ss_rekey->sequence_allowed = allowed;
1628 
1629  if (GNUNET_NO == receiver->rekeying)
1630  add_acks_rekey (receiver);
1631 
1632  return GNUNET_NO;
1633  }
1634  }
1635 
1636  (void) pid;
1637  for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next)
1638  {
1639  if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode)))
1640  {
1641 
1643  "Found matching mac\n");
1644 
1645  allowed = ntohl (ack->sequence_max);
1646 
1647  if (allowed > ss->sequence_allowed)
1648  {
1650  "%u > %u (%u %u) for secrect %s\n", allowed,
1651  ss->sequence_allowed,
1652  receiver->acks_available,
1653  ack->acks_available,
1654  GNUNET_h2s (&ss->master));
1655  // Uncomment this for alternativ 1 of backchannel functionality
1656  acks_to_add = (allowed - ss->sequence_allowed);
1657  if ((GNUNET_NO == receiver->rekeying) &&
1658  (receiver->number_rekeying_kce < 3) )
1659  acks_to_add = reset_rekey_kces (receiver, acks_to_add);
1660  /* if ((GNUNET_NO == receiver->rekeying) && */
1661  /* (receiver->number_rekeying_kce < */
1662  /* 3) ) */
1663  /* { */
1664  /* needed_for_rekeying = (3 - receiver->number_rekeying_kce); */
1665  /* if (acks_to_add <= needed_for_rekeying) */
1666  /* { */
1667  /* receiver->number_rekeying_kce += acks_to_add; */
1668  /* acks_to_add = 0; */
1669  /* } */
1670  /* else */
1671  /* { */
1672  /* acks_to_add -= (3 - receiver->number_rekeying_kce); */
1673  /* receiver->number_rekeying_kce = 3; */
1674  /* } */
1675  /* } */
1676  /* GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, */
1677  /* "%u kce for rekeying\n", */
1678  /* receiver->number_rekeying_kce); */
1679 
1680  if ((0 != acks_to_add) && (GNUNET_NO == receiver->rekeying))
1681  {
1682  receiver->acks_available += (allowed - ss->sequence_allowed);
1683  ss->sequence_allowed = allowed;
1685  "%u receiver->acks_available 5\n",
1686  receiver->acks_available);
1687  add_acks (ss, acks_to_add);
1688  }
1689  }
1690  return GNUNET_NO;
1691  }
1692  }
1693  return GNUNET_YES;
1694 }
static void add_acks(struct SharedSecret *ss, int acks_to_add)
struct GNUNET_HashCode cmac
CMAC is used to identify master in ACKs.
uint32_t sequence_allowed
Up to which sequence number did the other peer allow us to use this key, or up to which number did we...
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static uint32_t reset_rekey_kces(struct ReceiverAddress *receiver, uint32_t acks_to_add)
struct SharedSecret * ss_rekey
Shared secret we use with target for rekeying.
static char * value
Value of the record to add/remove.
struct GNUNET_HashCode master
Master shared secret.
static void add_acks_rekey(struct ReceiverAddress *receiver)
A 512-bit hashcode.
struct SharedSecret * next
Kept in a DLL.
Information we track per receiving address we have recently been in contact with (encryption to recei...
struct GNUNET_HashCode cmac
CMAC of the base key being acknowledged.
Shared secret we generated for a particular sender or receiver.
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:329
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
uint32_t sequence_max
Sequence acknowledgement limit.
#define GNUNET_log(kind,...)
UDP key acknowledgement.
int number_rekeying_kce
Numer of kce we retain for sending the rekeying shared secret.
uint32_t acks_available
Sequence acknowledgement limit.
int rekeying
Flag indicating sender is initiated rekeying for this receiver.
struct SharedSecret * ss_head
Shared secrets we received from target, first used is head.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_handle_plaintext()

static void try_handle_plaintext ( struct SenderAddress sender,
const void *  buf,
size_t  buf_size 
)
static

Test if we have received a valid message in plaintext.

If so, handle it.

Parameters
senderpeer to process inbound plaintext for
bufbuffer we received
buf_sizenumber of bytes in buf

Definition at line 1706 of file gnunet-communicator-udp.c.

References GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK, GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD, handle_ack(), pass_plaintext_to_core(), GNUNET_MessageHeader::size, SenderAddress::target, type, and GNUNET_MessageHeader::type.

Referenced by decrypt_box(), and sock_read().

1709 {
1710  const struct GNUNET_MessageHeader *hdr =
1711  (const struct GNUNET_MessageHeader *) buf;
1712  const struct UDPAck *ack = (const struct UDPAck *) buf;
1713  uint16_t type;
1714 
1715  if (sizeof(*hdr) > buf_size)
1716  return; /* not even a header */
1717  if (ntohs (hdr->size) > buf_size)
1718  return; /* not even a header */
1719  type = ntohs (hdr->type);
1720  switch (type)
1721  {
1723  /* lookup master secret by 'cmac', then update sequence_max */
1725  &sender->target,
1726  &handle_ack,
1727  (void *) ack);
1728  /* There could be more messages after the ACK, handle those as well */
1729  buf += ntohs (hdr->size);
1730  buf_size -= ntohs (hdr->size);
1731  pass_plaintext_to_core (sender, buf, buf_size);
1732  break;
1733 
1735  /* skip padding */
1736  break;
1737 
1738  default:
1739  pass_plaintext_to_core (sender, buf, buf_size);
1740  }
1741 }
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD
UDP communicator padding.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK
UDP KX acknowledgement.
static int handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
We received an ACK for pid.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_PeerIdentity target
To whom are we talking to.
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
static void pass_plaintext_to_core(struct SenderAddress *sender, const void *plaintext, size_t plaintext_len)
We received plaintext_len bytes of plaintext from a sender.
static char buf[2048]
UDP key acknowledgement.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Header for all communications.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kce_generate_cb()

static void kce_generate_cb ( void *  cls)
static

Definition at line 1745 of file gnunet-communicator-udp.c.

References SenderAddress::acks_available, GENERATE_AT_ONCE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_YES, kce_generate(), SenderAddress::kce_task, SenderAddress::kce_task_finished, KCN_TARGET, SharedSecret::master, SenderAddress::rekeying, SharedSecret::sender, SharedSecret::sequence_allowed, SenderAddress::ss_rekey, and WORKING_QUEUE_INTERVALL.

Referenced by consider_ss_ack(), and kce_generate_rekey_cb().

1746 {
1747  struct SharedSecret *ss = cls;
1748 
1749  ss->sender->kce_task = NULL;
1750 
1751  if (((GNUNET_NO == ss->sender->rekeying) && (ss->sender->acks_available <
1752  KCN_TARGET) ) ||
1753  ((ss->sender->ss_rekey == ss) && (GNUNET_YES == ss->sender->rekeying) &&
1754  (ss->sender->acks_available < 128)))
1755  {
1756 
1758  "Precomputing keys for master %s\n",
1759  GNUNET_h2s (&(ss->master)));
1760 
1761  for (int i = 0; i < GENERATE_AT_ONCE; i++)
1762  kce_generate (ss, ++ss->sequence_allowed);
1763 
1767  ss);
1768  }
1769  else
1770  {
1772  "We have enough keys.\n");
1773  ss_finished = ss;
1775  }
1776 
1777 
1778 }
#define KCN_TARGET
How many KCNs do we keep around after we hit the KCN_THRESHOLD? Should be larger than KCN_THRESHOLD s...
int rekeying
Flag indicating sender is initiated rekeying for this receiver.
uint32_t sequence_allowed
Up to which sequence number did the other peer allow us to use this key, or up to which number did we...
#define WORKING_QUEUE_INTERVALL
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
struct GNUNET_SCHEDULER_Task * kce_task
ID of kce working queue task.
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:1269
struct GNUNET_HashCode master
Master shared secret.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this sender.
#define GENERATE_AT_ONCE
static void kce_generate_cb(void *cls)
Shared secret we generated for a particular sender or receiver.
int kce_task_finished
Is the kce_task finished?
struct SharedSecret * ss_finished
Shared secret we finished the last kce working queue for.
#define GNUNET_log(kind,...)
static void kce_generate(struct SharedSecret *ss, uint32_t seq)
Setup key cache entry for sequence number seq and shared secret ss.
struct SharedSecret * ss_rekey
Shared secret we use with target for rekeying.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kce_generate_rekey_cb()

static void kce_generate_rekey_cb ( void *  cls)
static

Definition at line 1782 of file gnunet-communicator-udp.c.

References GENERATE_AT_ONCE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_SCHEDULER_add_delayed(), kce_generate(), kce_generate_cb(), SenderAddress::kce_task, SenderAddress::kce_task_rekey, SharedSecret::master, SharedSecret::sender, SharedSecret::sequence_allowed, and WORKING_QUEUE_INTERVALL.

Referenced by consider_ss_ack().

1783 {
1784  struct SharedSecret *ss = cls;
1785 
1786  ss->sender->kce_task_rekey = NULL;
1787 
1788  if (NULL == ss->sender->kce_task)
1789  {
1790 
1792  "Precomputing keys for rekey master %s\n",
1793  GNUNET_h2s (&(ss->master)));
1794 
1795  for (int i = 0; i < GENERATE_AT_ONCE; i++)
1796  kce_generate (ss, ++ss->sequence_allowed);
1797 
1801  ss);
1802  ss->sender->kce_task_rekey = NULL;
1803  }
1804  else
1805  {
1809  ss);
1810  }
1811 }
uint32_t sequence_allowed
Up to which sequence number did the other peer allow us to use this key, or up to which number did we...
#define WORKING_QUEUE_INTERVALL
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
struct GNUNET_SCHEDULER_Task * kce_task
ID of kce working queue task.
struct GNUNET_SCHEDULER_Task * kce_task_rekey
ID of kce rekey working queue task.
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:1269
struct GNUNET_HashCode master
Master shared secret.
static void kce_generate_rekey_cb(void *cls)
#define GENERATE_AT_ONCE
static void kce_generate_cb(void *cls)
Shared secret we generated for a particular sender or receiver.
#define GNUNET_log(kind,...)
static void kce_generate(struct SharedSecret *ss, uint32_t seq)
Setup key cache entry for sequence number seq and shared secret ss.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ consider_ss_ack()

static void consider_ss_ack ( struct SharedSecret ss,
int  initial 
)
static

We established a shared secret with a sender.

We should try to send the sender an struct UDPAck at the next opportunity to allow the sender to use ss longer (assuming we did not yet already recently).

Parameters
ssshared secret to generate ACKs for
intialThe SharedSecret came with initial KX.

Definition at line 1824 of file gnunet-communicator-udp.c.

References UDPAck::acks_available, SenderAddress::acks_available, UDPAck::cmac, SharedSecret::cmac, COMMUNICATOR_ADDRESS_PREFIX, destroy_all_secrets(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s_full(), GNUNET_log, GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TRANSPORT_communicator_notify(), GNUNET_YES, UDPAck::header, kce_destroy(), kce_generate(), kce_generate_cb(), kce_generate_rekey_cb(), SharedSecret::kce_head, SharedSecret::kce_tail, SenderAddress::kce_task, SenderAddress::kce_task_finished, SenderAddress::kce_task_rekey, KCN_THRESHOLD, SharedSecret::master, MAX_SECRETS, MAX_SQN_DELTA, SenderAddress::num_secrets, SenderAddress::rekeying, SharedSecret::sender, SharedSecret::sequence_allowed, UDPAck::sequence_max, KeyCacheEntry::sequence_number, GNUNET_MessageHeader::size, ss_finished, SenderAddress::target, GNUNET_MessageHeader::type, and WORKING_QUEUE_INTERVALL.

Referenced by decrypt_box(), decrypt_rekey(), and sock_read().

1825 {
1826  struct GNUNET_SCHEDULER_Task *kce_task_rekey;
1827  struct GNUNET_SCHEDULER_Task *kce_task;
1828  int kce_task_finished;
1829 
1830  kce_task_rekey = ss->sender->kce_task_rekey;
1831  kce_task_finished = ss->sender->kce_task_finished;
1832  kce_task = ss->sender->kce_task;
1833 
1834  GNUNET_assert (NULL != ss->sender);
1836  "Considering SS UDPAck %s\n",
1837  GNUNET_i2s_full (&ss->sender->target));
1838 
1840  "We have %u acks available.\n",
1841  ss->sender->acks_available);
1842  /* drop ancient KeyCacheEntries */
1843  while ((NULL != ss->kce_head) &&
1844  (MAX_SQN_DELTA <
1846  kce_destroy (ss->kce_tail);
1847 
1848 
1849  if (GNUNET_NO == initial)
1850  kce_generate (ss, ++ss->sequence_allowed);
1851 
1852  /*if (0 == ss->sender->acks_available)
1853  {
1854  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1855  "Generating keys\n");
1856  while (ss->active_kce_count < KCN_TARGET)
1857  kce_generate (ss, ++ss->sequence_allowed);
1858  }*/
1859 
1860  if (((NULL != kce_task) && kce_task_finished) || (GNUNET_NO == initial))
1861  {
1862  struct UDPAck ack;
1863  struct SharedSecret *ss_tell;
1864 
1865  if (GNUNET_NO != initial)
1866  ss_tell = ss_finished;
1867  else
1868  ss_tell = ss;
1869 
1870  ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK);
1871  ack.header.size = htons (sizeof(ack));
1872  ack.sequence_max = htonl (ss_tell->sequence_allowed);
1873  ack.acks_available = ss->sender->acks_available;
1874  ack.cmac = ss_tell->cmac;
1876  "Notifying transport of UDPAck %s with intial %u and master %s\n",
1877  GNUNET_i2s_full (&ss_tell->sender->target),
1878  initial,
1879  GNUNET_h2s (&(ss_tell->master)));
1881  &ss_tell->sender->target,
1883  &ack.header);
1884  if (GNUNET_NO != initial)
1885  {
1887  kce_task = NULL;
1888  kce_task_finished = GNUNET_NO;
1889  }
1890  }
1891  else if ((NULL == kce_task) && ((KCN_THRESHOLD >
1892  ss->sender->acks_available) ||
1893  (GNUNET_YES == ss->sender->rekeying) ||
1894  (ss->sender->num_secrets > MAX_SECRETS) ))
1895  {
1896 
1897  // kce_generate (ss, ++ss->sequence_allowed);
1898  // kce_generate (ss, ++ss->sequence_allowed);
1899  // TODO This task must be per sender!
1902  ss);
1903  kce_task_finished = GNUNET_NO;
1904 
1905  }
1906  else if ((NULL == kce_task_rekey) && (GNUNET_YES ==
1907  ss->sender->rekeying) )
1908  {
1911  ss);
1912  }
1913 }
struct KeyCacheEntry * kce_head
Kept in a DLL, sorted by sequence number.
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK
UDP KX acknowledgement.
int rekeying
Flag indicating sender is initiated rekeying for this receiver.
struct GNUNET_HashCode cmac
CMAC is used to identify master in ACKs.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t sequence_allowed
Up to which sequence number did the other peer allow us to use this key, or up to which number did we...
#define WORKING_QUEUE_INTERVALL
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static void kce_destroy(struct KeyCacheEntry *kce)
Free memory used by key cache entry.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
uint32_t sequence_number
Sequence number used to derive this entry from master key.
struct GNUNET_SCHEDULER_Task * kce_task
ID of kce working queue task.
struct GNUNET_SCHEDULER_Task * kce_task_rekey
ID of kce rekey working queue task.
struct GNUNET_PeerIdentity target
To whom are we talking to.
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:1269
struct GNUNET_HashCode master
Master shared secret.
struct KeyCacheEntry * kce_tail
Kept in a DLL, sorted by sequence number.
#define MAX_SECRETS
How many shared master secrets do we keep around at most per sender? Should be large enough so that w...
static void kce_generate_rekey_cb(void *cls)
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this sender.
static void kce_generate_cb(void *cls)
Shared secret we generated for a particular sender or receiver.
unsigned int num_secrets
Length of the DLL at ss_head.
#define KCN_THRESHOLD
If we fall below this number of available KCNs, we generate additional ACKs until we reach KCN_TARGET...
int kce_task_finished
Is the kce_task finished?
struct SharedSecret * ss_finished
Shared secret we finished the last kce working queue for.
void GNUNET_TRANSPORT_communicator_notify(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *pid, const char *comm, const struct GNUNET_MessageHeader *header)
The communicator asks the transport service to route a message via a different path to another commun...
#define GNUNET_log(kind,...)
UDP key acknowledgement.
Entry in list of pending tasks.
Definition: scheduler.c:134
#define MAX_SQN_DELTA
What is the maximum delta between KCN sequence numbers that we allow.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static void kce_generate(struct SharedSecret *ss, uint32_t seq)
Setup key cache entry for sequence number seq and shared secret ss.
static void destroy_all_secrets(struct SharedSecret *ss, int withoutKce)
Destroying all secrets.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt_box()

static void decrypt_box ( const struct UDPBox box,
size_t  box_len,
struct KeyCacheEntry kce 
)
static

We received a box with matching kce.

Decrypt and process it.

Parameters
boxthe data we received
box_lennumber of bytes in box
kcekey index to decrypt box

Definition at line 1924 of file gnunet-communicator-udp.c.

References consider_ss_ack(), UDPBox::gcm_tag, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_sh2s(), GNUNET_STATISTICS_update(), GNUNET_YES, kce_destroy(), SenderAddress::rekeying, SharedSecret::sender, KeyCacheEntry::sequence_number, KeyCacheEntry::ss, SenderAddress::ss_rekey, try_decrypt(), and try_handle_plaintext().

Referenced by sock_read().

1927 {
1928  struct SharedSecret *ss = kce->ss;
1929  char out_buf[box_len - sizeof(*box)];
1930 
1931  GNUNET_assert (NULL != ss->sender);
1932  if (GNUNET_OK != try_decrypt (ss,
1933  box->gcm_tag,
1934  kce->sequence_number,
1935  (const char *) &box[1],
1936  sizeof(out_buf),
1937  out_buf))
1938  {
1940  "# Decryption failures with valid KCE",
1941  1,
1942  GNUNET_NO);
1943  kce_destroy (kce);
1944  return;
1945  }
1946  kce_destroy (kce);
1948  "# bytes decrypted with BOX",
1949  sizeof(out_buf),
1950  GNUNET_NO);
1952  "# messages decrypted with BOX",
1953  1,
1954  GNUNET_NO);
1956  "decrypted UDPBox with kid %s\n",
1957  GNUNET_sh2s (&box->kid));
1958  try_handle_plaintext (ss->sender, out_buf, sizeof(out_buf));
1959  if ((GNUNET_NO == box->rekeying) && (GNUNET_YES == ss->sender->rekeying))
1960  {
1961  ss->sender->rekeying = GNUNET_NO;
1962  ss->sender->ss_rekey = NULL;
1963  // destroy_all_secrets (ss, GNUNET_NO);
1965  "Receiver stopped rekeying.\n");
1966  }
1967  else if (GNUNET_NO == box->rekeying)
1968  consider_ss_ack (ss, GNUNET_NO);
1969  else
1970  {
1971  ss->sender->rekeying = GNUNET_YES;
1973  "Got Box: Receiver doing rekeying.\n");
1974  }
1975 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
static void consider_ss_ack(struct SharedSecret *ss, int initial)
We established a shared secret with a sender.
int rekeying
Flag indicating sender is initiated rekeying for this receiver.
char gcm_tag[(128/8)]
128-bit authentication tag for the following encrypted message, from GCM.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct SharedSecret * ss
Corresponding shared secret.
static void kce_destroy(struct KeyCacheEntry *kce)
Free memory used by key cache entry.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
uint32_t sequence_number
Sequence number used to derive this entry from master key.
static void try_handle_plaintext(struct SenderAddress *sender, const void *buf, size_t buf_size)
Test if we have received a valid message in plaintext.
Shared secret we generated for a particular sender or receiver.
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
struct SharedSecret * ss_rekey
Shared secret we use with target for rekeying.
static int try_decrypt(const struct SharedSecret *ss, const char tag[(128/8)], uint32_t serial, const char *in_buf, size_t in_buf_size, char *out_buf)
Try to decrypt buf using shared secret ss and key/iv derived using serial.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decrypt_rekey()

static void decrypt_rekey ( const struct UDPRekey rekey,
size_t  rekey_len,
struct KeyCacheEntry kce,
struct SenderAddress sender 
)
static

We received a rekey with matching kce.

Decrypt and process it.

Parameters
rekeythe data we received
rekey_lennumber of bytes in rekey
kcekey index to decrypt rekey

Definition at line 1986 of file gnunet-communicator-udp.c.

References SenderAddress::acks_available, calculate_cmac(), SharedSecret::cmac, consider_ss_ack(), UDPRekey::gcm_tag, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_sh2s(), GNUNET_STATISTICS_update(), GNUNET_YES, kce_destroy(), SharedSecret::master, SenderAddress::num_secrets, SharedSecret::sender, UdpHandshakeSignature::sender, SharedSecret::sequence_allowed, KeyCacheEntry::sequence_number, KeyCacheEntry::ss, SenderAddress::ss_head, SenderAddress::ss_rekey, SenderAddress::ss_tail, and try_decrypt().

Referenced by sock_read().

1990 {
1991  struct SharedSecret *ss = kce->ss;
1992  struct SharedSecret *ss_rekey;
1993  char out_buf[rekey_len - sizeof(*rekey)];
1994  struct GNUNET_HashCode *master;
1995 
1996 
1998  "decrypt_rekey.\n");
1999 
2000  GNUNET_assert (NULL != ss->sender);
2001  if (GNUNET_OK != try_decrypt (ss,
2002  rekey->gcm_tag,
2003  kce->sequence_number,
2004  (const char *) &rekey[1],
2005  sizeof(out_buf),
2006  out_buf))
2007  {
2009  "# Decryption failures with valid KCE",
2010  1,
2011  GNUNET_NO);
2013  "Decryption with kid %s failed\n",
2014  GNUNET_sh2s (&rekey->kid));
2015  kce_destroy (kce);
2016  return;
2017  }
2018  kce_destroy (kce);
2020  "# bytes decrypted with Rekey",
2021  sizeof(out_buf),
2022  GNUNET_NO);
2024  "decrypted UDPRekey with kid %s\n",
2025  GNUNET_sh2s (&rekey->kid));
2026  /*cmac = (struct GNUNET_HashCode *) out_buf;
2027  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2028  "Received secret with cmac %s \n",
2029  GNUNET_h2s (&cmac));*/
2030  // ss_rekey = (struct SharedSecret *) out_buf;
2031  master = (struct GNUNET_HashCode *) out_buf;
2032  ss_rekey = GNUNET_new (struct SharedSecret);
2033  ss_rekey->master = *master;
2034  calculate_cmac (ss_rekey);
2035  ss_rekey->sender = sender;
2036  // ss_rekey->sequence_used = 0;
2037  // ss_rekey->sequence_allowed = 0;
2038  /* ss_rekey->active_kce_count = 0; */
2039  /* ss_rekey->prev = NULL; */
2040  /* ss_rekey->next = NULL; */
2041  /* GNUNET_assert (ss_rekey->prev == NULL && sender->ss_head != ss_rekey); */
2042  /* GNUNET_assert (ss_rekey->next == NULL && sender->ss_tail != ss_rekey); */
2043  GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss_rekey);
2044  sender->ss_rekey = ss_rekey;
2045  sender->num_secrets++;
2047  "Received secret with cmac %s\n",
2048  GNUNET_h2s (&(ss_rekey->cmac)));
2050  "Received secret with master %s.\n",
2051  GNUNET_h2s (&(ss_rekey->master)));
2053  "We have %u sequence_allowed.\n",
2054  ss_rekey->sequence_allowed);
2056  "We have a sender %p\n",
2057  ss_rekey->sender);
2059  "We have %u acks available.\n",
2060  ss_rekey->sender->acks_available);
2061  consider_ss_ack (ss_rekey, GNUNET_YES);
2062 
2063 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
struct SharedSecret * ss_tail
Shared secrets we used with target, last used is tail.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
static void consider_ss_ack(struct SharedSecret *ss, int initial)
We established a shared secret with a sender.
struct GNUNET_HashCode cmac
CMAC is used to identify master in ACKs.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t sequence_allowed
Up to which sequence number did the other peer allow us to use this key, or up to which number did we...
struct SharedSecret * ss
Corresponding shared secret.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static void kce_destroy(struct KeyCacheEntry *kce)
Free memory used by key cache entry.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
uint32_t sequence_number
Sequence number used to derive this entry from master key.
struct SharedSecret * ss_head
Shared secrets we used with target, first used is head.
struct GNUNET_HashCode master
Master shared secret.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this sender.
A 512-bit hashcode.
Shared secret we generated for a particular sender or receiver.
unsigned int num_secrets
Length of the DLL at ss_head.
#define GNUNET_log(kind,...)
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
char gcm_tag[(128/8)]
128-bit authentication tag for the following encrypted message, from GCM.
static void calculate_cmac(struct SharedSecret *ss)
Calcualte cmac from master in ss.
struct SharedSecret * ss_rekey
Shared secret we use with target for rekeying.
static int try_decrypt(const struct SharedSecret *ss, const char tag[(128/8)], uint32_t serial, const char *in_buf, size_t in_buf_size, char *out_buf)
Try to decrypt buf using shared secret ss and key/iv derived using serial.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_sender_by_address()

static int find_sender_by_address ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Find existing struct SenderAddress by matching addresses.

Parameters
clsa struct SearchContext
keyignored, must match already
valuea struct SenderAddress
Returns
GNUNET_YES if not found (continue to search), GNUNET_NO if found

Definition at line 2097 of file gnunet-communicator-udp.c.

References SenderAddress::address, SearchContext::address, SenderAddress::address_len, SearchContext::address_len, GNUNET_NO, GNUNET_YES, sc, SearchContext::sender, UdpHandshakeSignature::sender, and value.

Referenced by setup_sender().

2100 {
2101  struct SearchContext *sc = cls;
2102  struct SenderAddress *sender = value;
2103 
2104  if ((sender->address_len == sc->address_len) &&
2105  (0 == memcmp (sender->address, sc->address, sender->address_len)))
2106  {
2107  sc->sender = sender;
2108  return GNUNET_NO; /* stop iterating! */
2109  }
2110  return GNUNET_YES;
2111 }
socklen_t address_len
Number of bytes in address.
socklen_t address_len
Length of the address.
static char * value
Value of the record to add/remove.
struct sockaddr * address
Address of the other peer.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Context information to be used while searching for operation contexts.
Definition: testbed_api.c:225
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
struct SenderAddress * sender
Return value to set if we found a match.
const struct sockaddr * address
Address we are looking for.
Here is the caller graph for this function:

◆ setup_sender()

static struct SenderAddress* setup_sender ( const struct GNUNET_PeerIdentity target,
const struct sockaddr *  address,
socklen_t  address_len 
)
static

Create sender address for target.

Note that we might already have one, so a fresh one is only allocated if one does not yet exist for address.

Parameters
targetpeer to generate address for
addresstarget address
address_lennumber of bytes in address
Returns
data structure to keep track of key material for decrypting data from target

Definition at line 2126 of file gnunet-communicator-udp.c.

References GNUNET_TIME_Absolute::abs_value_us, address, SenderAddress::address, SearchContext::address, SenderAddress::address_len, SearchContext::address_len, check_timeouts(), find_sender_by_address(), GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_memdup, GNUNET_new, GNUNET_NO, GNUNET_NT_scanner_get_type(), GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_set(), GNUNET_TIME_relative_to_absolute(), SenderAddress::hn, SenderAddress::nt, reschedule_sender_timeout(), SearchContext::sender, UdpHandshakeSignature::sender, SenderAddress::target, and SenderAddress::timeout.

Referenced by sock_read().

2129 {
2130  struct SenderAddress *sender;
2131  struct SearchContext sc = { .address = address,
2132  .address_len = address_len,
2133  .sender = NULL };
2134 
2136  target,
2138  &sc);
2139  if (NULL != sc.sender)
2140  {
2142  return sc.sender;
2143  }
2144  sender = GNUNET_new (struct SenderAddress);
2145  sender->target = *target;
2147  sender->address_len = address_len;
2149  senders,
2150  &sender->target,
2151  sender,
2154  "# senders active",
2156  GNUNET_NO);
2157  sender->timeout =
2160  sender,
2161  sender->timeout.abs_value_us);
2163  if (NULL == timeout_task)
2165  return sender;
2166 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WANT.
Definition: nt.c:314
struct GNUNET_CONTAINER_HeapNode * GNUNET_CONTAINER_heap_insert(struct GNUNET_CONTAINER_Heap *heap, void *element, GNUNET_CONTAINER_HeapCostType cost)
Inserts a new element into the heap.
socklen_t address_len
Number of bytes in address.
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:246
socklen_t address_len
Length of the address.
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TIME_Absolute timeout
Timeout for this sender.
uint64_t abs_value_us
The actual value.
static void reschedule_sender_timeout(struct SenderAddress *sender)
Increment sender timeout due to activity.
struct GNUNET_PeerIdentity target
To whom are we talking to.
static struct GNUNET_CONTAINER_MultiPeerMap * receivers
Receivers (map from peer identity to struct ReceiverAddress)
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
static void check_timeouts(void *cls)
Task run to check #receiver_heap and #sender_heap for timeouts.
struct sockaddr * address
Address of the other peer.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_CONTAINER_Heap * senders_heap
Expiration heap for senders (contains struct SenderAddress)
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
static struct GNUNET_CONTAINER_MultiPeerMap * senders
Senders (map from peer identity to struct SenderAddress)
Allow multiple values with the same key.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_CONTAINER_HeapNode * hn
Entry in sender expiration heap.
Context information to be used while searching for operation contexts.
Definition: testbed_api.c:225
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static int find_sender_by_address(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Find existing struct SenderAddress by matching addresses.
struct SenderAddress * sender
Return value to set if we found a match.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
static char * address
GNS address for this phone.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
static struct GNUNET_SCHEDULER_Task * timeout_task
ID of timeout task.
enum GNUNET_NetworkType nt
Which network type does this queue use?
Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_confirmation()

static int verify_confirmation ( const struct GNUNET_CRYPTO_EcdhePublicKey ephemeral,
const struct UDPConfirmation uc 
)
static

Check signature from uc against ephemeral.

Parameters
ephermalkey that is signed
ucsignature of claimant
Returns
GNUNET_OK if signature is valid

Definition at line 2177 of file gnunet-communicator-udp.c.

References UdpHandshakeSignature::ephemeral, GNUNET_CRYPTO_eddsa_verify, GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, UDPConfirmation::monotonic_time, UdpHandshakeSignature::monotonic_time, my_identity, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, UdpHandshakeSignature::purpose, UdpHandshakeSignature::receiver, UDPConfirmation::sender, UdpHandshakeSignature::sender, UDPConfirmation::sender_sig, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by sock_read().

2179 {
2180  struct UdpHandshakeSignature uhs;
2181 
2183  uhs.purpose.size = htonl (sizeof(uhs));
2184  uhs.sender = uc->sender;
2185  uhs.receiver = my_identity;
2186  uhs.ephemeral = *ephemeral;
2187  uhs.monotonic_time = uc->monotonic_time;
2190  &uhs,
2191  &uc->sender_sig,
2192  &uc->sender.public_key);
2193 }
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE
Signature used by UDP communicator handshake.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
struct GNUNET_CRYPTO_EddsaSignature sender_sig
Sender&#39;s signature of type GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE.
struct GNUNET_TIME_AbsoluteNBO monotonic_time
Monotonic time of sender, to possibly help detect replay attacks (if receiver persists times by sende...
struct GNUNET_PeerIdentity sender
Sender&#39;s identity.
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
Ephemeral key used by the sender.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the caller graph for this function:

◆ sockaddr_to_udpaddr_string()

static char* sockaddr_to_udpaddr_string ( const struct sockaddr *  address,
socklen_t  address_len 
)
static

Converts address to the address string format used by this communicator in HELLOs.

Parameters
addressthe address to convert, must be AF_INET or AF_INET6.
address_lennumber of bytes in address
Returns
string representation of address

Definition at line 2205 of file gnunet-communicator-udp.c.

References COMMUNICATOR_ADDRESS_PREFIX, GNUNET_a2s(), GNUNET_asprintf(), GNUNET_assert, and ret.

Referenced by mq_init(), and sock_read().

2207 {
2208  char *ret;
2209 
2210  switch (address->sa_family)
2211  {
2212  case AF_INET:
2213  GNUNET_asprintf (&ret,
2214  "%s-%s",
2216  GNUNET_a2s (address, address_len));
2217  break;
2218 
2219  case AF_INET6:
2220  GNUNET_asprintf (&ret,
2221  "%s-%s",
2223  GNUNET_a2s (address, address_len));
2224  break;
2225 
2226  default:
2227  GNUNET_assert (0);
2228  }
2229  return ret;
2230 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
static char * address
GNS address for this phone.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sock_read()

static void sock_read ( void *  cls)
static

Socket read task.

Parameters
clsNULL

Definition at line 2239 of file gnunet-communicator-udp.c.

References buf, calculate_cmac(), consider_ss_ack(), decrypt_box(), decrypt_rekey(), do_decrypt(), InitialKX::ephemeral, InitialKX::gcm_tag, GNUNET_break_op, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_multishortmap_get(), GNUNET_CRYPTO_eddsa_verify, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_recvfrom(), GNUNET_NO, GNUNET_NT_scanner_get_type(), GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_sh2s(), GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST, GNUNET_STATISTICS_update(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_application_validate(), GNUNET_YES, UdpBroadcastSignature::h_address, UDPBox::kid, UDPRekey::kid, nt, SenderAddress::num_secrets, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, UdpBroadcastSignature::purpose, InitialKX::rekeying, UDPBox::rekeying, SenderAddress::rekeying, UDPConfirmation::sender, UdpBroadcastSignature::sender, UDPRekey::sender, SharedSecret::sender, UdpHandshakeSignature::sender, setup_sender(), setup_shared_secret_dec(), GNUNET_CRYPTO_EccSignaturePurpose::size, sockaddr_to_udpaddr_string(), KeyCacheEntry::ss, SenderAddress::ss_head, SenderAddress::ss_rekey, SenderAddress::ss_tail, try_decrypt(), try_handle_plaintext(), uc, and verify_confirmation().

Referenced by run().

2240 {
2241  struct sockaddr_storage sa;
2242  socklen_t salen = sizeof(sa);
2243  char buf[UINT16_MAX];
2244  ssize_t rcvd;
2245 
2246  (void) cls;
2248  udp_sock,
2249  &sock_read,
2250  NULL);
2252  buf,
2253  sizeof(buf),
2254  (struct sockaddr *) &sa,
2255  &salen);
2256  if (-1 == rcvd)
2257  {
2259  return;
2260  }
2262  "Read %lu bytes\n", rcvd);
2263 
2264  if (rcvd > sizeof(struct UDPRekey))
2265  {
2266  const struct UDPRekey *rekey;
2267  const struct UDPBox *box;
2268  struct KeyCacheEntry *kce;
2269  struct SenderAddress *sender;
2270  int do_decrypt = GNUNET_NO;
2271 
2272  rekey = (const struct UDPRekey *) buf;
2273  box = (const struct UDPBox *) buf;
2275 
2276  if ((GNUNET_YES == box->rekeying) || (GNUNET_NO == box->rekeying))
2278  "UDPRekey has rekeying %u\n",
2279  box->rekeying);
2280  else
2281  do_decrypt = GNUNET_YES;
2282 
2283  if ((GNUNET_YES == do_decrypt) && (NULL != kce) && (GNUNET_YES ==
2284  kce->ss->sender->
2285  rekeying))
2286  {
2288  "UDPRekey with kid %s\n",
2289  GNUNET_sh2s (&rekey->kid));
2290  sender = setup_sender (&rekey->sender, (const struct sockaddr *) &sa,
2291  salen);
2292 
2293  if (NULL != sender->ss_rekey)
2294  return;
2295 
2296  decrypt_rekey (rekey, (size_t) rcvd, kce, sender);
2297  return;
2298  }
2299  }
2300 
2301  /* first, see if it is a UDPBox */
2302  if (rcvd > sizeof(struct UDPBox))
2303  {
2304  const struct UDPBox *box;
2305  struct KeyCacheEntry *kce;
2306 
2307  box = (const struct UDPBox *) buf;
2309  if (NULL != kce)
2310  {
2311  decrypt_box (box, (size_t) rcvd, kce);
2312  return;
2313  }
2314  }
2315 
2316  /* next, check if it is a broadcast */
2317  if (sizeof(struct UDPBroadcast) == rcvd)
2318  {
2319  const struct UDPBroadcast *ub;
2320  struct UdpBroadcastSignature uhs;
2321 
2322  ub = (const struct UDPBroadcast *) buf;
2323  uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
2324  uhs.purpose.size = htonl (sizeof(uhs));
2325  uhs.sender = ub->sender;
2326  GNUNET_CRYPTO_hash (&sa, salen, &uhs.h_address);
2327  if (GNUNET_OK ==
2329  &uhs,
2330  &ub->sender_sig,
2331  &ub->sender.public_key))
2332  {
2333  char *addr_s;
2334  enum GNUNET_NetworkType nt;
2335 
2336  addr_s =
2337  sockaddr_to_udpaddr_string ((const struct sockaddr *) &sa, salen);
2338  GNUNET_STATISTICS_update (stats, "# broadcasts received", 1, GNUNET_NO);
2339  /* use our own mechanism to determine network type */
2340  nt =
2341  GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen);
2342  GNUNET_TRANSPORT_application_validate (ah, &ub->sender, nt, addr_s);
2343  GNUNET_free (addr_s);
2344  return;
2345  }
2346  /* continue with KX, mostly for statistics... */
2347  }
2348 
2349 
2350  /* finally, test if it is a KX */
2351  if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX))
2352  {
2354  "# messages dropped (no kid, too small for KX)",
2355  1,
2356  GNUNET_NO);
2357  return;
2358  }
2360  "Got KX\n");
2361  {
2362  const struct InitialKX *kx;
2363  struct SharedSecret *ss;
2364  char pbuf[rcvd - sizeof(struct InitialKX)];
2365  const struct UDPConfirmation *uc;
2366  struct SenderAddress *sender;
2367 
2368  kx = (const struct InitialKX *) buf;
2369  ss = setup_shared_secret_dec (&kx->ephemeral);
2371  "Before DEC\n");
2372 
2373  if (GNUNET_OK != try_decrypt (ss,
2374  kx->gcm_tag,
2375  0,
2376  &buf[sizeof(*kx)],
2377  sizeof(pbuf),
2378  pbuf))
2379  {
2381  "Unable to decrypt tag, dropping...\n");
2382  GNUNET_free (ss);
2384  stats,
2385  "# messages dropped (no kid, AEAD decryption failed)",
2386  1,
2387  GNUNET_NO);
2388  return;
2389  }
2391  "Before VERIFY\n");
2392 
2393  uc = (const struct UDPConfirmation *) pbuf;
2394  if (GNUNET_OK != verify_confirmation (&kx->ephemeral, uc))
2395  {
2396  GNUNET_break_op (0);
2397  GNUNET_free (ss);
2399  "# messages dropped (sender signature invalid)",
2400  1,
2401  GNUNET_NO);
2402  return;
2403  }
2405  "Before SETUP_SENDER\n");
2406 
2407  calculate_cmac (ss);
2408  sender = setup_sender (&uc->sender, (const struct sockaddr *) &sa, salen);
2409  ss->sender = sender;
2410  GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss);
2411  sender->num_secrets++;
2412  GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
2414  "# messages decrypted without BOX",
2415  1,
2416  GNUNET_NO);
2417  try_handle_plaintext (sender, &uc[1], sizeof(pbuf) - sizeof(*uc));
2418  if ((GNUNET_NO == kx->rekeying) && (GNUNET_YES == ss->sender->rekeying))
2419  {
2420  ss->sender->rekeying = GNUNET_NO;
2421  sender->ss_rekey = NULL;
2422  // destroy_all_secrets (ss, GNUNET_NO);
2424  "Receiver stopped rekeying.\n");
2425  }
2426  else if (GNUNET_NO == kx->rekeying)
2428  else
2429  {
2430  ss->sender->rekeying = GNUNET_YES;
2432  "Got KX: Receiver doing rekeying.\n");
2433  }
2434  /*if (sender->num_secrets > MAX_SECRETS)
2435  secret_destroy (sender->ss_tail);*/
2436  }
2437 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WANT.
Definition: nt.c:314
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
struct SharedSecret * ss_tail
Shared secrets we used with target, last used is tail.
static struct GNUNET_TRANSPORT_ApplicationHandle * ah
Our handle to report addresses for validation to TRANSPORT.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
Broadcast by peer in LAN announcing its presence.
static struct SenderAddress * setup_sender(const struct GNUNET_PeerIdentity *target, const struct sockaddr *address, socklen_t address_len)
Create sender address for target.
static void consider_ss_ack(struct SharedSecret *ss, int initial)
We established a shared secret with a sender.
char gcm_tag[(128/8)]
HMAC for the following encrypted message, using GCM.
int rekeying
Flag indicating sender is initiated rekeying for this receiver.
static struct SharedSecret * setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
Setup shared secret for decryption.
void GNUNET_TRANSPORT_application_validate(struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_NetworkType nt, const char *addr)
An application (or a communicator) has received a HELLO (or other address data of another peer) and w...
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral
Ephemeral key for KX.
static struct GNUNET_CONTAINER_MultiShortmap * key_cache
Cache of pre-generated key IDs.
static struct GNUNET_FS_UnindexContext * uc
static struct GNUNET_NT_InterfaceScanner * is
Network scanner to determine network types.
struct SharedSecret * ss
Corresponding shared secret.
struct SenderAddress * sender
Sender we use this shared secret with, or NULL.
Encrypted continuation of UDP initial handshake, followed by message header with payload.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_CRYPTO_eddsa_verify(purp, ps, sig, pub)
Verify EdDSA signature.
int rekeying
A flag indicating, if the sender is doing rekeying.
static char * sockaddr_to_udpaddr_string(const struct sockaddr *address, socklen_t address_len)
Converts address to the address string format used by this communicator in HELLOs.
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
"Plaintext" header at beginning of KX message.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
struct SharedSecret * ss_head
Shared secrets we used with target, first used is head.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
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.
Pre-generated "kid" code (key and IV identification code) to quickly derive master key for a struct U...
static int verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, const struct UDPConfirmation *uc)
Check signature from uc against ephemeral.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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
#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST
Signature used by UDP broadcasts.
static char buf[2048]
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
UDP message box.
UDP message box.
static void sock_read(void *cls)
Socket read task.
static struct GNUNET_NAT_AUTO_Test * nt
Handle to a NAT test operation.
static void try_handle_plaintext(struct SenderAddress *sender, const void *buf, size_t buf_size)
Test if we have received a valid message in plaintext.
Shared secret we generated for a particular sender or receiver.
unsigned int num_secrets
Length of the DLL at ss_head.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
static void decrypt_box(const struct UDPBox *box, size_t box_len, struct KeyCacheEntry *kce)
We received a box with matching kce.
struct GNUNET_PeerIdentity sender
Sender&#39;s identity.
struct GNUNET_PeerIdentity sender
Sender&#39;s identity.
int rekeying
A flag indicating, if the sender is doing rekeying.
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
Information we track per sender address we have recently been in contact with (we decrypt messages fr...
Signature we use to verify that the broadcast was really made by the peer that claims to have made it...
#define GNUNET_log(kind,...)
struct GNUNET_ShortHashCode kid
Key and IV identification code.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static struct GNUNET_SCHEDULER_Task * read_task
ID of read task.
static void calculate_cmac(struct SharedSecret *ss)
Calcualte cmac from master in ss.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1517
static void decrypt_rekey(const struct UDPRekey *rekey, size_t rekey_len, struct KeyCacheEntry *kce, struct SenderAddress *sender)
We received a rekey with matching kce.
ssize_t GNUNET_NETWORK_socket_recvfrom(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, struct sockaddr *src_addr, socklen_t *addrlen)
Read data from a socket (always non-blocking).
Definition: network.c:754
#define GNUNET_free(ptr)
Wrapper around free.
struct SharedSecret * ss_rekey
Shared secret we use with target for rekeying.
static int try_decrypt(const struct SharedSecret *ss, const char tag[(128/8)], uint32_t serial, const char *in_buf, size_t in_buf_size, char *out_buf)
Try to decrypt buf using shared secret ss and key/iv derived using serial.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_address_to_sockaddr()

static struct sockaddr* udp_address_to_sockaddr ( const char *  bindto,
socklen_t *  sock_len 
)
static

Convert UDP bind specification to a struct sockaddr *

Parameters
bindtobind specification to convert
[out]sock_lenset to the length of the address
Returns
converted bindto specification

Definition at line 2448 of file gnunet-communicator-udp.c.

References COMMUNICATOR_CONFIG_SECTION, dummy, GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_malloc, GNUNET_memdup, GNUNET_NETWORK_test_pf(), GNUNET_NO, GNUNET_strdup, GNUNET_YES, port, and start.

Referenced by mq_init(), and run().

2449 {
2450  struct sockaddr *in;
2451  unsigned int port;
2452  char dummy[2];
2453  char *colon;
2454  char *cp;
2455 
2456  if (1 == sscanf (bindto, "%u%1s", &port, dummy))
2457  {
2458  /* interpreting value as just a PORT number */
2459  if (port > UINT16_MAX)
2460  {
2462  "BINDTO specification `%s' invalid: value too large for port\n",
2463  bindto);
2464  return NULL;
2465  }
2466  if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
2467  (GNUNET_YES ==
2470  "DISABLE_V6")))
2471  {
2472  struct sockaddr_in *i4;
2473 
2474  i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
2475  i4->sin_family = AF_INET;
2476  i4->sin_port = htons ((uint16_t) port);
2477  *sock_len = sizeof(struct sockaddr_in);
2478  in = (struct sockaddr *) i4;
2479  }
2480  else
2481  {
2482  struct sockaddr_in6 *i6;
2483 
2484  i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
2485  i6->sin6_family = AF_INET6;
2486  i6->sin6_port = htons ((uint16_t) port);
2487  *sock_len = sizeof(struct sockaddr_in6);
2488  in = (struct sockaddr *) i6;
2489  }
2490  return in;
2491  }
2492  cp = GNUNET_strdup (bindto);
2493  colon = strrchr (cp, ':');
2494  if (NULL != colon)
2495  {
2496  /* interpet value after colon as port */
2497  *colon = '\0';
2498  colon++;
2499  if (1 == sscanf (colon, "%u%1s", &port, dummy))
2500  {
2501  /* interpreting value as just a PORT number */
2502  if (port > UINT16_MAX)
2503  {
2505  "BINDTO specification `%s' invalid: value too large for port\n",
2506  bindto);
2507  GNUNET_free (cp);
2508  return NULL;
2509  }
2510  }
2511  else
2512  {
2513  GNUNET_log (
2515  "BINDTO specification `%s' invalid: last ':' not followed by number\n",
2516  bindto);
2517  GNUNET_free (cp);
2518  return NULL;
2519  }
2520  }
2521  else
2522  {
2523  /* interpret missing port as 0, aka pick any free one */
2524  port = 0;
2525  }
2526  {
2527  /* try IPv4 */
2528  struct sockaddr_in v4;
2529  if (1 == inet_pton (AF_INET, cp, &v4.sin_addr))
2530  {
2531  v4.sin_family = AF_INET;
2532  v4.sin_port = htons ((uint16_t) port);
2533 #if HAVE_SOCKADDR_IN_SIN_LEN
2534  v4.sin_len = sizeof(struct sockaddr_in);
2535 #endif
2536  in = GNUNET_memdup (&v4, sizeof(struct sockaddr_in));
2537  *sock_len = sizeof(struct sockaddr_in);
2538  GNUNET_free (cp);
2539  return in;
2540  }
2541  }
2542  {
2543  /* try IPv6 */
2544  struct sockaddr_in6 v6;
2545  const char *start;
2546 
2547  start = cp;
2548  if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
2549  {
2550  start++; /* skip over '[' */
2551  cp[strlen (cp) - 1] = '\0'; /* eat ']' */
2552  }
2553  if (1 == inet_pton (AF_INET6, start, &v6.sin6_addr))
2554  {
2555  v6.sin6_family = AF_INET6;
2556  v6.sin6_port = htons ((uint16_t) port);
2557 #if HAVE_SOCKADDR_IN_SIN_LEN
2558  v6.sin6_len = sizeof(sizeof(struct sockaddr_in6));
2559 #endif
2560  in = GNUNET_memdup (&v6, sizeof(v6));
2561  *sock_len = sizeof(v6);
2562  GNUNET_free (cp);
2563  return in;
2564  }
2565  }
2566  /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
2567  GNUNET_free (cp);
2568  return NULL;
2569 }
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct in_addr dummy
Target "dummy" address of the packet we pretend to respond to.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:82
#define GNUNET_log(kind,...)
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".
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_malloc(size)
Wrapper around malloc.
int GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:85
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_pad()

static void do_pad ( gcry_cipher_hd_t  out_cipher,
char *  dgram,
size_t  pad_size 
)
static

Pad dgram by pad_size using out_cipher.

Parameters
out_ciphercipher to use
dgramdatagram to pad
pad_sizenumber of bytes of padding to append

Definition at line 2580 of file gnunet-communicator-udp.c.

References GNUNET_assert, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_block(), GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD, and GNUNET_MessageHeader::size.

Referenced by mq_send_d(), mq_send_kx(), and send_UDPRekey().

2581 {
2582  char pad[pad_size];
2583 
2585  if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader))
2586  {
2587  struct GNUNET_MessageHeader hdr =
2588  { .size = htons (sizeof(pad)),
2589  .type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) };
2590 
2591  memcpy (pad, &hdr, sizeof(hdr));
2592  }
2593  GNUNET_assert (
2594  0 ==
2595  gcry_cipher_encrypt (out_cipher, dgram, sizeof(pad), pad, sizeof(pad)));
2596 }
#define GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD
UDP communicator padding.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
Header for all communications.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_send_kx()

static void mq_send_kx ( struct GNUNET_MQ_Handle mq,
const struct GNUNET_MessageHeader msg,
void *  impl_state 
)
static

Signature of functions implementing the sending functionality of a message queue.

Parameters
mqthe message queue
msgthe message to send
impl_stateour struct ReceiverAddress

Definition at line 2608 of file gnunet-communicator-udp.c.

References ReceiverAddress::address, ReceiverAddress::address_len, destroy_all_secrets(), do_pad(), InitialKX::ephemeral, UdpHandshakeSignature::ephemeral, InitialKX::gcm_tag, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_CRYPTO_ecdhe_key_get_public(), GNUNET_CRYPTO_eddsa_sign, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_MQ_impl_send_continue(), GNUNET_NETWORK_socket_sendto(), GNUNET_NO, GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, GNUNET_TIME_absolute_get_monotonic(), GNUNET_TIME_absolute_hton(), GNUNET_YES, ReceiverAddress::kx_mq, ReceiverAddress::kx_mtu, SharedSecret::master, MAX_SECRETS, UDPConfirmation::monotonic_time, UdpHandshakeSignature::monotonic_time, my_identity, ReceiverAddress::num_secrets, GNUNET_CRYPTO_EccSignaturePurpose::purpose, UdpHandshakeSignature::purpose, UdpHandshakeSignature::receiver, receiver_destroy(), ReceiverAddress::receiver_destroy_called, InitialKX::rekeying, ReceiverAddress::rekeying, reschedule_receiver_timeout(), UDPConfirmation::sender, UdpHandshakeSignature::sender, UDPConfirmation::sender_sig, setup_cipher(), setup_shared_secret_enc(), GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_MessageHeader::size, ReceiverAddress::target, and uc.

Referenced by setup_receiver_mq().

2611 {
2612  struct ReceiverAddress *receiver = impl_state;
2613  uint16_t msize = ntohs (msg->size);
2614  struct UdpHandshakeSignature uhs;
2615  struct UDPConfirmation uc;
2616  struct InitialKX kx;
2617  struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
2618  char dgram[receiver->kx_mtu + sizeof(uc) + sizeof(kx)];
2619  size_t dpos;
2620  gcry_cipher_hd_t out_cipher;
2621  struct SharedSecret *ss;
2622 
2623  GNUNET_assert (mq == receiver->kx_mq);
2624  if (msize > receiver->kx_mtu)
2625  {
2626  GNUNET_break (0);
2627  if (GNUNET_YES != receiver->receiver_destroy_called)
2628  receiver_destroy (receiver);
2629  return;
2630  }
2631  reschedule_receiver_timeout (receiver);
2632 
2633  /* setup key material */
2635 
2636  ss = setup_shared_secret_enc (&epriv, receiver, GNUNET_YES);
2637 
2638  if (receiver->num_secrets > MAX_SECRETS)
2639  {
2641  }
2642 
2643  setup_cipher (&ss->master, 0, &out_cipher);
2644  /* compute 'uc' */
2645  uc.sender = my_identity;
2646  uc.monotonic_time =
2648  uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
2649  uhs.purpose.size = htonl (sizeof(uhs));
2650  uhs.sender = my_identity;
2651  uhs.receiver = receiver->target;
2652  GNUNET_CRYPTO_ecdhe_key_get_public (&epriv, &uhs.ephemeral);
2653  uhs.monotonic_time = uc.monotonic_time;
2655  &uhs,
2656  &uc.sender_sig);
2657  /* Leave space for kx */
2658  dpos = sizeof(kx);
2659  /* Append encrypted uc to dgram */
2660  GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher,
2661  &dgram[dpos],
2662  sizeof(uc),
2663  &uc,
2664  sizeof(uc)));
2665  dpos += sizeof(uc);
2666  /* Append encrypted payload to dgram */
2667  GNUNET_assert (
2668  0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
2669  dpos += msize;
2670  do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
2671  /* Datagram starts with kx */
2672  kx.ephemeral = uhs.ephemeral;
2673  GNUNET_assert (
2674  0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag)));
2675  gcry_cipher_close (out_cipher);
2676  if (GNUNET_NO == receiver->rekeying)
2677  kx.rekeying = GNUNET_NO;
2678  else
2679  kx.rekeying = GNUNET_YES;
2680  memcpy (dgram, &kx, sizeof(kx));
2682  dgram,
2683  sizeof(dgram),
2684  receiver->address,
2685  receiver->address_len))
2688  "Sending KX to %s\n", GNUNET_a2s (receiver->address,
2689  receiver->address_len));
2691 }
#define GNUNET_CRYPTO_eddsa_sign(priv, ps, sig)
EdDSA sign a given block.
static struct GNUNET_PeerIdentity my_identity
Our public key.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct sockaddr * address
Address of the other peer.
static struct GNUNET_FS_UnindexContext * uc
unsigned int num_secrets
Length of the DLL at ss_head.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
Encrypted continuation of UDP initial handshake, followed by message header with payload.
#define GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE
Signature used by UDP communicator handshake.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
"Plaintext" header at beginning of KX message.
static void setup_cipher(const struct GNUNET_HashCode *msec, uint32_t serial, gcry_cipher_hd_t *cipher)
Setup cipher based on shared secret msec and serial number serial.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:419
struct GNUNET_HashCode master
Master shared secret.
struct GNUNET_MQ_Handle * kx_mq
KX message queue we are providing for the ch.
#define MAX_SECRETS
How many shared master secrets do we keep around at most per sender? Should be large enough so that w...
size_t kx_mtu
MTU we allowed transport for this receiver&#39;s KX queue.
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition: network.c:846
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
int receiver_destroy_called
receiver_destroy already called on receiver.
Information we track per receiving address we have recently been in contact with (encryption to recei...
Private ECC key encoded for transmission.
Shared secret we generated for a particular sender or receiver.
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:197
static struct SharedSecret * setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, struct ReceiverAddress *receiver, int add_to_receiver)
Setup shared secret for encryption.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
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:329
static void do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
Pad dgram by pad_size using out_cipher.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition: time.c:837
static void reschedule_receiver_timeout(struct ReceiverAddress *receiver)
Increment receiver timeout due to activity.
socklen_t address_len
Length of the address.
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
Signature we use to verify that the ephemeral key was really chosen by the specified sender...
struct GNUNET_PeerIdentity target
To whom are we talking to.
static void destroy_all_secrets(struct SharedSecret *ss, int withoutKce)
Destroying all secrets.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:499
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
int rekeying
Flag indicating sender is initiated rekeying for this receiver.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_for_rekeying()

static void check_for_rekeying ( struct ReceiverAddress receiver,
struct UDPBox box 
)
static

Definition at line 2695 of file gnunet-communicator-udp.c.

References GNUNET_TIME_Absolute::abs_value_us, ReceiverAddress::acks_available, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_sh2s(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, UDPBox::kid, ReceiverAddress::rekey_acks_available, rekey_interval, rekey_max_bytes, ReceiverAddress::rekey_send_bytes, ReceiverAddress::rekey_timeout, UDPBox::rekeying, ReceiverAddress::rekeying, GNUNET_TIME_Relative::rel_value_us, and ReceiverAddress::ss_rekey.

Referenced by mq_send_d().

2696 {
2697 
2698  struct GNUNET_TIME_Relative rt;
2699 
2701  "Timeout is %lu\n.",
2702  receiver->rekey_timeout.abs_value_us);
2703 
2704  if (0 == receiver->rekey_timeout.abs_value_us)
2705  {
2707  rekey_interval);
2708  }
2709  else
2710  {
2713  "Relative time is %lu and timeout is %lu\n.",
2714  rt.rel_value_us,
2715  receiver->rekey_timeout.abs_value_us);
2716 
2717  if ((0 == rt.rel_value_us) || (receiver->rekey_send_bytes >
2718  rekey_max_bytes) )
2719  {
2721  "Bytes send %lu greater than %llu max bytes\n.",
2722  receiver->rekey_send_bytes,
2723  rekey_max_bytes);
2725  "Relative time is %lu and timeout is %lu\n.",
2726  rt.rel_value_us,
2727  receiver->rekey_timeout.abs_value_us);
2728 
2729  receiver->rekey_timeout.abs_value_us = 0;
2730  receiver->rekey_send_bytes = 0;
2731  receiver->ss_rekey = NULL;
2732  // destroy_all_secrets (ss, GNUNET_NO);
2733  receiver->rekeying = GNUNET_YES;
2734  receiver->rekey_acks_available = receiver->acks_available;
2735  box->rekeying = GNUNET_YES;
2737  "Sender started rekeying.\n");
2738  if (GNUNET_YES == box->rekeying)
2740  "Sending rekeying with kid %s\n",
2741  GNUNET_sh2s (&box->kid));
2742  }
2743  }
2744 }
struct GNUNET_TIME_Absolute rekey_timeout
Timeout for this receiver address.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
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:246
static unsigned long long rekey_max_bytes
How often we do rekey based on number of bytes transmitted.
uint64_t abs_value_us
The actual value.
struct SharedSecret * ss_rekey
Shared secret we use with target for rekeying.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
static struct GNUNET_TIME_Relative rekey_interval
The rekey interval.
uint64_t rekey_send_bytes
Send bytes for this receiver address.
unsigned int rekey_acks_available
Acks available when we started rekeying.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
int rekeying
A flag indicating, if the sender is doing rekeying.
#define GNUNET_log(kind,...)
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:331
int rekeying
Flag indicating sender is initiated rekeying for this receiver.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_UDPRekey()

static void send_UDPRekey ( struct ReceiverAddress receiver,
struct SharedSecret ss 
)
static

Definition at line 2748 of file gnunet-communicator-udp.c.

References do_pad(), UDPRekey::gcm_tag, get_kid(), GNUNET_a2s(), GNUNET_assert, GNUNET_CRYPTO_ecdhe_key_create(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_sendto(), GNUNET_NO, GNUNET_sh2s(), UDPRekey::kid, SharedSecret::master, my_identity, SharedSecret::prev, UDPRekey::sender, SharedSecret::sequence_allowed, SharedSecret::sequence_used, setup_cipher(), and setup_shared_secret_enc().

Referenced by mq_send_d().

2749 {
2750  uint8_t is_ss_rekey_sequence_allowed_zero = GNUNET_NO;
2751  uint8_t is_acks_available_below = GNUNET_NO;
2752  uint8_t send_rekey = GNUNET_NO;
2753  uint16_t not_below;
2754  struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
2755  struct UDPRekey *rekey;
2756  size_t dpos;
2757 
2758  char rekey_dgram[sizeof(struct UDPRekey) + receiver->d_mtu];
2759 
2760  if (NULL != receiver->ss_rekey)
2761  {
2762  not_below = (receiver->rekey_acks_available
2763  - (receiver->rekey_acks_available % 3)) / 3;
2764  is_ss_rekey_sequence_allowed_zero = (0 ==
2765  receiver->ss_rekey->sequence_allowed);
2766  is_acks_available_below = (receiver->acks_available >= not_below);
2767  send_rekey = (0 == (receiver->acks_available - not_below) % not_below) &&
2768  is_acks_available_below && is_ss_rekey_sequence_allowed_zero;
2770  "send_rekey: %u, %u, %u\n",
2771  send_rekey,
2772  receiver->rekey_acks_available,
2773  receiver->acks_available);
2774  }
2775  else if (NULL == receiver->ss_rekey)
2776  {
2777  /* setup key material */
2779  receiver->ss_rekey = setup_shared_secret_enc (&epriv, receiver,
2780  GNUNET_NO);
2781  receiver->ss_rekey->sequence_allowed = 0;
2783  "Setup secret with cmac %s\n",
2784  GNUNET_h2s (&(receiver->ss_rekey->cmac)));
2786  "Setup secret with master %s.\n",
2787  GNUNET_h2s (&(receiver->ss_rekey->master)));
2788  }
2789 
2790  if (send_rekey)
2791  {
2792  GNUNET_assert (0 != receiver->number_rekeying_kce);
2793  gcry_cipher_hd_t rekey_out_cipher;
2794 
2795  while (NULL != ss && ss->sequence_used >= ss->sequence_allowed)
2796  {
2797  ss = ss->prev;
2798  }
2799 
2800  if (NULL != ss)
2801  {
2802  rekey = (struct UDPRekey *) rekey_dgram;
2803  rekey->sender = my_identity;
2804  ss->sequence_used++;
2805  get_kid (&ss->master, ss->sequence_used, &rekey->kid);
2806  receiver->number_rekeying_kce--;
2807  setup_cipher (&ss->master, ss->sequence_used, &rekey_out_cipher);
2808  /* Append encrypted payload to dgram */
2809  dpos = sizeof(struct UDPRekey);
2810 
2811  GNUNET_assert (
2812  0 == gcry_cipher_encrypt (rekey_out_cipher, &rekey_dgram[dpos],
2813  sizeof(receiver->ss_rekey->master),
2814  &(receiver->ss_rekey->master),
2815  sizeof(receiver->ss_rekey->master)));
2816  dpos += sizeof(receiver->ss_rekey->master);
2817  /* GNUNET_assert ( */
2818  /* 0 == gcry_cipher_encrypt (rekey_out_cipher, &rekey_dgram[dpos], */
2819  /* /\*sizeof(receiver->ss_rekey->cmac), */
2820  /* &(receiver->ss_rekey->cmac), */
2821  /* sizeof(receiver->ss_rekey->cmac))); */
2822  /* dpos += sizeof(receiver->ss_rekey->cmac);*\/ */
2823  /* sizeof(receiver->ss_rekey), */
2824  /* receiver->ss_rekey, */
2825  /* sizeof(receiver->ss_rekey))); */
2826  /* dpos += sizeof(receiver->ss_rekey); */
2827  do_pad (rekey_out_cipher, &rekey_dgram[dpos], sizeof(rekey_dgram)
2828  - dpos);
2829  GNUNET_assert (0 == gcry_cipher_gettag (rekey_out_cipher,
2830  rekey->gcm_tag,
2831  sizeof(rekey->gcm_tag)));
2832  gcry_cipher_close (rekey_out_cipher);
2833 
2835  "Sending rekey with kid %s and master %s\n",
2836  GNUNET_sh2s (&rekey->kid),
2837  GNUNET_h2s (&(receiver->ss_rekey->master)));
2839  "Sending rekey with cmac %s\n",
2840  GNUNET_h2s (&(receiver->ss_rekey->cmac)));
2842  "%u rekey kces left.\n",
2843  receiver->number_rekeying_kce);
2844 
2846  rekey_dgram,
2847  sizeof(rekey_dgram),
2848  receiver->address,
2849  receiver->address_len))
2851 
2852  receiver->acks_available--;
2854  "%u receiver->acks_available 1\n",
2855  receiver->acks_available);
2857  "Sending UDPRekey to %s\n", GNUNET_a2s (receiver->address,
2858  receiver->
2859  address_len));
2860  }
2861  }
2862 }
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
static struct GNUNET_PeerIdentity my_identity
Our public key.
struct GNUNET_HashCode cmac
CMAC is used to identify master in ACKs.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t sequence_allowed
Up to which sequence number did the other peer allow us to use this key, or up to which number did we...
struct sockaddr * address
Address of the other peer.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static void setup_cipher(const struct GNUNET_HashCode *msec, uint32_t serial, gcry_cipher_hd_t *cipher)
Setup cipher based on shared secret msec and serial number serial.
struct SharedSecret * ss_rekey
Shared secret we use with target for rekeying.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:419
uint32_t sequence_used
Up to which sequence number did we use this master already? (for encrypting only) ...
struct GNUNET_HashCode master
Master shared secret.
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition: network.c:846
unsigned int rekey_acks_available
Acks available when we started rekeying.
UDP message box.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
Private ECC key encoded for transmission.
static struct SharedSecret * setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, struct ReceiverAddress *receiver, int add_to_receiver)
Setup shared secret for encryption.
static void get_kid(const struct GNUNET_HashCode *msec, uint32_t serial, struct GNUNET_ShortHashCode *kid)
Compute kid.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
static void do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
Pad dgram by pad_size using out_cipher.
struct SharedSecret * prev
Kept in a DLL.
struct GNUNET_PeerIdentity sender
Sender&#39;s identity.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
socklen_t address_len
Length of the address.
#define GNUNET_log(kind,...)
struct GNUNET_ShortHashCode kid
Key and IV identification code.
char gcm_tag[(128/8)]
128-bit authentication tag for the following encrypted message, from GCM.
int number_rekeying_kce
Numer of kce we retain for sending the rekeying shared secret.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_send_d()

static void mq_send_d ( struct GNUNET_MQ_Handle mq,
const struct GNUNET_MessageHeader msg,
void *  impl_state 
)
static

Signature of functions implementing the sending functionality of a message queue.

Parameters
mqthe message queue
msgthe message to send
impl_stateour struct ReceiverAddress

Definition at line 2874 of file gnunet-communicator-udp.c.

References ReceiverAddress::acks_available, add_acks_rekey(), check_for_rekeying(), ReceiverAddress::d_mq, ReceiverAddress::d_mtu, do_pad(), UDPBox::gcm_tag, get_kid(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_log, GNUNET_log_strerror, GNUNET_MQ_impl_send_continue(), GNUNET_NETWORK_socket_sendto(), GNUNET_NO, GNUNET_YES, UDPBox::kid, SharedSecret::prev, receiver_destroy(), ReceiverAddress::receiver_destroy_called, UDPBox::rekeying, reschedule_receiver_timeout(), send_UDPRekey(), setup_cipher(), GNUNET_MessageHeader::size, and ReceiverAddress::ss_tail.

Referenced by setup_receiver_mq().

2877 {
2878  struct ReceiverAddress *receiver = impl_state;
2879  uint16_t msize = ntohs (msg->size);
2880 
2881  GNUNET_assert (mq == receiver->d_mq);
2882  if ((msize > receiver->d_mtu) ||
2883  (0 == receiver->acks_available))
2884  {
2886  "msize: %u, mtu: %lu, acks: %u\n",
2887  msize,
2888  receiver->d_mtu,
2889  receiver->acks_available);
2890 
2891  GNUNET_break (0);
2892  if (GNUNET_YES != receiver->receiver_destroy_called)
2893  receiver_destroy (receiver);
2894  return;
2895  }
2896  reschedule_receiver_timeout (receiver);
2897 
2898  /* begin "BOX" encryption method, scan for ACKs from tail! */
2899  for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev)
2900  {
2901  if (0 < ss->sequence_used)
2903  "Trying to send UDPBox with shared secrect %s sequence_used %u and ss->sequence_allowed %u\n",
2904  GNUNET_h2s (&ss->master),
2905  ss->sequence_used,
2906  ss->sequence_allowed);
2907  // Uncomment this for alternativ 1 of backchannel functionality
2908  if (ss->sequence_used >= ss->sequence_allowed)
2909  // Until here for alternativ 1
2910  // Uncomment this for alternativ 2 of backchannel functionality
2911  // if (0 == ss->sequence_allowed)
2912  // Until here for alternativ 2
2913  {
2914  continue;
2915  }
2916  char dgram[sizeof(struct UDPBox) + receiver->d_mtu];
2917  struct UDPBox *box;
2918  gcry_cipher_hd_t out_cipher;
2919  size_t dpos;
2920 
2921  box = (struct UDPBox *) dgram;
2922  ss->sequence_used++;
2923  get_kid (&ss->master, ss->sequence_used, &box->kid);
2924  setup_cipher (&ss->master, ss->sequence_used, &out_cipher);
2925  /* Append encrypted payload to dgram */
2926  dpos = sizeof(struct UDPBox);
2927  GNUNET_assert (
2928  0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
2929  dpos += msize;
2930  do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
2931  GNUNET_assert (0 == gcry_cipher_gettag (out_cipher,
2932  box->gcm_tag,
2933  sizeof(box->gcm_tag)));
2934  gcry_cipher_close (out_cipher);
2935 
2936  receiver->rekey_send_bytes += sizeof(struct UDPBox) + receiver->d_mtu;
2937 
2938  if (GNUNET_NO == receiver->rekeying)
2939  box->rekeying = GNUNET_NO;
2940  else
2941  box->rekeying = GNUNET_YES;
2942 
2944  dgram,
2945  sizeof(dgram),
2946  receiver->address,
2947  receiver->address_len))
2950  "Sending UDPBox %u acks left\n",
2951  receiver->acks_available);
2953  receiver->acks_available--;
2955  "%u receiver->acks_available 2\n",
2956  receiver->acks_available);
2957  check_for_rekeying (receiver, box);
2958  if (0 == receiver->acks_available - receiver->number_rekeying_kce)
2959  {
2960  /* We have no more ACKs */
2962  "No more acks\n");
2963  if (GNUNET_YES == receiver->rekeying)
2964  {
2965  receiver->rekeying = GNUNET_NO;
2967  "Sender stopped rekeying\n");
2968 
2969  if ((NULL != receiver->ss_rekey) && (0 <
2970  receiver->ss_rekey->
2971  sequence_allowed) )
2972  add_acks_rekey (receiver);
2973  }
2974  }
2975  else if ((GNUNET_YES == receiver->rekeying) )
2976  {
2977  send_UDPRekey (receiver, ss);
2978  }
2979 
2980  return;
2981  }
2982 }
char gcm_tag[(128/8)]
128-bit authentication tag for the following encrypted message, from GCM.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void send_UDPRekey(struct ReceiverAddress *receiver, struct SharedSecret *ss)
struct sockaddr * address
Address of the other peer.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static void setup_cipher(const struct GNUNET_HashCode *msec, uint32_t serial, gcry_cipher_hd_t *cipher)
Setup cipher based on shared secret msec and serial number serial.
struct SharedSecret * ss_rekey
Shared secret we use with target for rekeying.
struct GNUNET_ShortHashCode kid
Key and IV identification code.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
uint64_t rekey_send_bytes
Send bytes for this receiver address.
static void add_acks_rekey(struct ReceiverAddress *receiver)
struct SharedSecret * ss_tail
Shared secrets we received with target, last used is tail.
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition: network.c:846
UDP message box.
int receiver_destroy_called
receiver_destroy already called on receiver.
Information we track per receiving address we have recently been in contact with (encryption to recei...
size_t d_mtu
MTU we allowed transport for this receiver&#39;s default queue.
Shared secret we generated for a particular sender or receiver.
static void get_kid(const struct GNUNET_HashCode *msec, uint32_t serial, struct GNUNET_ShortHashCode *kid)
Compute kid.
static struct GNUNET_NETWORK_Handle * udp_sock
Our socket.
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:329
static void do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
Pad dgram by pad_size using out_cipher.
struct SharedSecret * prev
Kept in a DLL.
unsigned int acks_available
Number of BOX keys from ACKs we have currently available for this receiver.
static void reschedule_receiver_timeout(struct ReceiverAddress *receiver)
Increment receiver timeout due to activity.
int rekeying
A flag indicating, if the sender is doing rekeying.
socklen_t address_len
Length of the address.
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
static void check_for_rekeying(struct ReceiverAddress *receiver, struct UDPBox *box)
int number_rekeying_kce
Numer of kce we retain for sending the rekeying shared secret.
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:499
int rekeying
Flag indicating sender is initiated rekeying for this receiver.
struct GNUNET_MQ_Handle * d_mq
Default message queue we are providing for the ch.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_destroy_d()

static void mq_destroy_d ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Signature of functions implementing the destruction of a message queue.

Implementations must not free mq, but should take care of impl_state.

Parameters
mqthe message queue to destroy
impl_stateour struct ReceiverAddress

Definition at line 2994 of file gnunet-communicator-udp.c.

References ReceiverAddress::d_mq, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_YES, receiver_destroy(), and ReceiverAddress::receiver_destroy_called.

Referenced by setup_receiver_mq().

2995 {
2996  struct ReceiverAddress *receiver = impl_state;
2998  "Default MQ destroyed\n");
2999  if (mq == receiver->d_mq)
3000  {
3001  receiver->d_mq = NULL;
3002  if (GNUNET_YES != receiver->receiver_destroy_called)
3003  receiver_destroy (receiver);
3004  }
3005 }
int receiver_destroy_called
receiver_destroy already called on receiver.
Information we track per receiving address we have recently been in contact with (encryption to recei...
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:329
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
struct GNUNET_MQ_Handle * d_mq
Default message queue we are providing for the ch.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_destroy_kx()

static void mq_destroy_kx ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Signature of functions implementing the destruction of a message queue.

Implementations must not free mq, but should take care of impl_state.

Parameters
mqthe message queue to destroy
impl_stateour struct ReceiverAddress

Definition at line 3017 of file gnunet-communicator-udp.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_YES, ReceiverAddress::kx_mq, receiver_destroy(), and ReceiverAddress::receiver_destroy_called.

Referenced by setup_receiver_mq().

3018 {
3019  struct ReceiverAddress *receiver = impl_state;
3021  "KX MQ destroyed\n");
3022  if (mq == receiver->kx_mq)
3023  {
3024  receiver->kx_mq = NULL;
3025  if (GNUNET_YES != receiver->receiver_destroy_called)
3026  receiver_destroy (receiver);
3027  }
3028 }
struct GNUNET_MQ_Handle * kx_mq
KX message queue we are providing for the ch.
int receiver_destroy_called
receiver_destroy already called on receiver.
Information we track per receiving address we have recently been in contact with (encryption to recei...
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:329
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_cancel()

static void mq_cancel ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Implementation function that cancels the currently sent message.

Parameters
mqmessage queue
impl_stateour struct RecvierAddress

Definition at line 3038 of file gnunet-communicator-udp.c.

References GNUNET_assert.

Referenced by setup_receiver_mq().

3039 {
3040  /* Cancellation is impossible with UDP; bail */
3041  GNUNET_assert (0);
3042 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Here is the caller graph for this function:

◆ mq_error()

static void mq_error ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsour struct ReceiverAddress
errorerror code

Definition at line 3055 of file gnunet-communicator-udp.c.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, receiver_destroy(), and ReceiverAddress::target.

Referenced by setup_receiver_mq().

3056 {
3057  struct ReceiverAddress *receiver = cls;
3058 
3060  "MQ error in queue to %s: %d\n",
3061  GNUNET_i2s (&receiver->target),
3062  (int) error);
3063  receiver_destroy (receiver);
3064 }
Information we track per receiving address we have recently been in contact with (encryption to recei...
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:329
static void receiver_destroy(struct ReceiverAddress *receiver)
Destroys a receiving state due to timeout or shutdown.
#define GNUNET_log(kind,...)
struct GNUNET_PeerIdentity target
To whom are we talking to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_init()

static int mq_init ( void *  cls,
const struct GNUNET_PeerIdentity peer,
const char *  address 
)
static

Function called by the transport service to initialize a message queue given address information about another peer.

If and when the communication channel is established, the communicator must call GNUNET_TRANSPORT_communicator_mq_add() to notify the service that the channel is now up. It is the responsibility of the communicator to manage sane retries and timeouts for any peer/address combination provided by the transport service. Timeouts and retries do not need to be signalled to the transport service.

Parameters
clsclosure
peeridentity of the other peer
addresswhere to send the message, human-readable communicator-specific format, 0-terminated, UTF-8
Returns
GNUNET_OK on success, GNUNET_SYSERR if the provided address is invalid

Definition at line 3178 of file gnunet-communicator-udp.c.

References GNUNET_TIME_Absolute::abs_value_us, ReceiverAddress::address, ReceiverAddress::address_len, check_timeouts(), COMMUNICATOR_ADDRESS_PREFIX, ReceiverAddress::foreign_addr, GNUNET_break_op, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s_full(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_NT_scanner_get_type(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_set(), GNUNET_SYSERR, GNUNET_TIME_relative_to_absolute(), ReceiverAddress::hn, ReceiverAddress::nt, peer, UdpHandshakeSignature::receiver, setup_receiver_mq(), sockaddr_to_udpaddr_string(), ReceiverAddress::target, ReceiverAddress::timeout, and udp_address_to_sockaddr().

Referenced by run().

3179 {
3180  struct ReceiverAddress *receiver;
3181  const char *path;
3182  struct sockaddr *in;
3183  socklen_t in_len;
3184 
3185  if (0 != strncmp (address,
3187  strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
3188  {
3189  GNUNET_break_op (0);
3190  return GNUNET_SYSERR;
3191  }
3192  path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
3193  in = udp_address_to_sockaddr (path, &in_len);
3194 
3195  receiver = GNUNET_new (struct ReceiverAddress);
3196  receiver->address = in;
3197  receiver->address_len = in_len;
3198  receiver->target = *peer;
3199  receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
3201  receivers,
3202  &receiver->target,
3203  receiver,
3206  "Added %s to receivers\n",
3207  GNUNET_i2s_full (&receiver->target));
3208  receiver->timeout =
3211  receiver,
3212  receiver->timeout.abs_value_us);
3214  "# receivers active",
3216  GNUNET_NO);
3217  receiver->foreign_addr =
3218  sockaddr_to_udpaddr_string (receiver->address, receiver->address_len);
3219  setup_receiver_mq (receiver);
3220  if (NULL == timeout_task)
3222  return GNUNET_OK;
3223 }
enum GNUNET_NetworkType GNUNET_NT_scanner_get_type(struct GNUNET_NT_InterfaceScanner *is, const struct sockaddr *addr, socklen_t addrlen)
Returns where the address is located: loopback, LAN or WANT.
Definition: nt.c:314
struct GNUNET_CONTAINER_HeapNode * GNUNET_CONTAINER_heap_insert(struct GNUNET_CONTAINER_Heap *heap, void *element, GNUNET_CONTAINER_HeapCostType cost)
Inserts a new element into the heap.
struct GNUNET_CONTAINER_HeapNode * hn