libcoap  4.3.0beta
coap_dtls_gnutls.c File Reference
#include "coap_config.h"
#include "address.h"
#include "coap_debug.h"
#include "mem.h"
#include "coap_dtls.h"
#include "coap_keystore.h"
#include "utlist.h"
#include <inttypes.h>
#include <stdio.h>
#include <errno.h>
#include <gnutls/gnutls.h>
#include <gnutls/x509.h>
#include <unistd.h>
+ Include dependency graph for coap_dtls_gnutls.c:

Go to the source code of this file.

Data Structures

struct  queue_t
 
struct  coap_dtls_session_t
 
struct  coap_dtls_context_t
 

Macros

#define UNUSED
 
#define COAP_COPY_ADDRESS(DST, SRC)
 
#define ITEM_SIZE   (sizeof(struct queue_t) + data_length)
 
#define CONTEXT_SIZE   (sizeof(struct coap_dtls_context_t))
 

Typedefs

typedef enum CertificateFormat_ CertificateFormat
 
typedef struct coap_dtls_context_t coap_dtls_context_t
 

Enumerations

enum  CredentialType { CREDENTIAL_TYPE_NOT_SET , CREDENTIAL_TYPE_CLIENT_PSK , CREDENTIAL_TYPE_SERVER_PSK }
 
enum  CertificateFormat_ { CERTIFICATE_FORMAT_NONE , CERTIFICATE_FORMAT_ASN1 , CERTIFICATE_FORMAT_PEM }
 

Functions

void dtls_set_psk (struct coap_dtls_context_t *ctx, const char *identity, const uint8_t *key, int key_length)
 
int coap_dtls_is_supported (void)
 Returns 1 if support for DTLS is enabled, or 0 otherwise. More...
 
void coap_dtls_set_log_level (int level)
 Sets the log level to the specified value. More...
 
int coap_dtls_get_log_level (void)
 Returns the current log level. More...
 
static int push_data_item (struct coap_dtls_session_t *session, coap_tid_t id, const unsigned char *data, size_t data_length)
 
struct coap_dtls_context_tcoap_dtls_new_context (struct coap_context_t *coap_context)
 Creates a new DTLS context for the given coap_context. More...
 
void coap_dtls_free_context (struct coap_dtls_context_t *dtls_context)
 Releases the storage allocated for dtls_context. More...
 
static ssize_t decrypt_callback (gnutls_transport_ptr_t context, void *receive_buffer, size_t receive_buffer_length)
 
static ssize_t dtls_send_to_peer (gnutls_transport_ptr_t context, const void *send_buffer, size_t send_buffer_length)
 
static int psk_client_callback (gnutls_session_t session, char **username, gnutls_datum_t *key)
 
static int psk_callback (gnutls_session_t session, const char *username, gnutls_datum_t *key)
 
struct coap_dtls_session_tcoap_dtls_new_session (struct coap_dtls_context_t *dtls_context, const coap_endpoint_t *local_interface, const coap_address_t *remote)
 
void coap_dtls_free_session (struct coap_dtls_context_t *dtls_context, struct coap_dtls_session_t *session)
 
static struct coap_dtls_session_tcoap_dtls_find_session (coap_dtls_context_t *dtls_context, const coap_endpoint_t *local_interface, const coap_address_t *dst)
 
struct coap_dtls_session_tcoap_dtls_get_session (struct coap_context_t *coap_context, const coap_endpoint_t *local_interface, const coap_address_t *dst)
 
int coap_dtls_send (struct coap_context_t *coap_context, struct coap_dtls_session_t *session, const coap_pdu_t *pdu)
 
int coap_dtls_handle_message (struct coap_context_t *coap_context, const coap_endpoint_t *local_interface, const coap_address_t *dst, const unsigned char *data, size_t data_len)
 

Macro Definition Documentation

◆ COAP_COPY_ADDRESS

#define COAP_COPY_ADDRESS (   DST,
  SRC 
)
Value:
do { \
(DST)->size = (SRC)->size; \
if ((SRC)->addr.sa.sa_family == AF_INET6) { \
(DST)->addr.sin6.sin6_family = (SRC)->addr.sin6.sin6_family; \
(DST)->addr.sin6.sin6_addr = (SRC)->addr.sin6.sin6_addr; \
(DST)->addr.sin6.sin6_port = (SRC)->addr.sin6.sin6_port; \
} else { \
(DST)->addr.st = (SRC)->addr.st; \
} \
} while (0);

Definition at line 89 of file coap_dtls_gnutls.c.

◆ CONTEXT_SIZE

#define CONTEXT_SIZE   (sizeof(struct coap_dtls_context_t))

◆ ITEM_SIZE

#define ITEM_SIZE   (sizeof(struct queue_t) + data_length)

◆ UNUSED

#define UNUSED

Definition at line 27 of file coap_dtls_gnutls.c.

Typedef Documentation

◆ CertificateFormat

◆ coap_dtls_context_t

Enumeration Type Documentation

◆ CertificateFormat_

Enumerator
CERTIFICATE_FORMAT_NONE 
CERTIFICATE_FORMAT_ASN1 
CERTIFICATE_FORMAT_PEM 

Definition at line 40 of file coap_dtls_gnutls.c.

◆ CredentialType

Enumerator
CREDENTIAL_TYPE_NOT_SET 
CREDENTIAL_TYPE_CLIENT_PSK 
CREDENTIAL_TYPE_SERVER_PSK 

Definition at line 33 of file coap_dtls_gnutls.c.

Function Documentation

◆ coap_dtls_find_session()

static struct coap_dtls_session_t* coap_dtls_find_session ( coap_dtls_context_t dtls_context,
const coap_endpoint_t local_interface,
const coap_address_t dst 
)
static

Definition at line 484 of file coap_dtls_gnutls.c.

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

◆ coap_dtls_free_context()

void coap_dtls_free_context ( struct coap_dtls_context_t dtls_context)

Releases the storage allocated for dtls_context.

Definition at line 195 of file coap_dtls_gnutls.c.

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

◆ coap_dtls_free_session()

void coap_dtls_free_session ( struct coap_dtls_context_t dtls_context,
struct coap_dtls_session_t session 
)

Definition at line 467 of file coap_dtls_gnutls.c.

+ Here is the caller graph for this function:

◆ coap_dtls_get_session()

struct coap_dtls_session_t* coap_dtls_get_session ( struct coap_context_t coap_context,
const coap_endpoint_t local_interface,
const coap_address_t dst 
)

Definition at line 498 of file coap_dtls_gnutls.c.

+ Here is the call graph for this function:

◆ coap_dtls_handle_message()

int coap_dtls_handle_message ( struct coap_context_t coap_context,
const coap_endpoint_t local_interface,
const coap_address_t dst,
const unsigned char *  data,
size_t  data_len 
)

Definition at line 564 of file coap_dtls_gnutls.c.

+ Here is the call graph for this function:

◆ coap_dtls_new_session()

struct coap_dtls_session_t* coap_dtls_new_session ( struct coap_dtls_context_t dtls_context,
const coap_endpoint_t local_interface,
const coap_address_t remote 
)

Definition at line 363 of file coap_dtls_gnutls.c.

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

◆ coap_dtls_send()

int coap_dtls_send ( struct coap_context_t coap_context,
struct coap_dtls_session_t session,
const coap_pdu_t pdu 
)

Definition at line 520 of file coap_dtls_gnutls.c.

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

◆ decrypt_callback()

static ssize_t decrypt_callback ( gnutls_transport_ptr_t  context,
void *  receive_buffer,
size_t  receive_buffer_length 
)
static

Definition at line 232 of file coap_dtls_gnutls.c.

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

◆ dtls_send_to_peer()

static ssize_t dtls_send_to_peer ( gnutls_transport_ptr_t  context,
const void *  send_buffer,
size_t  send_buffer_length 
)
static

Definition at line 283 of file coap_dtls_gnutls.c.

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

◆ dtls_set_psk()

void dtls_set_psk ( struct coap_dtls_context_t ctx,
const char *  identity,
const uint8_t key,
int  key_length 
)

Definition at line 111 of file coap_dtls_gnutls.c.

+ Here is the caller graph for this function:

◆ psk_callback()

static int psk_callback ( gnutls_session_t  session,
const char *  username,
gnutls_datum_t *  key 
)
static

Definition at line 318 of file coap_dtls_gnutls.c.

+ Here is the caller graph for this function:

◆ psk_client_callback()

static int psk_client_callback ( gnutls_session_t  session,
char **  username,
gnutls_datum_t *  key 
)
static

Definition at line 310 of file coap_dtls_gnutls.c.

+ Here is the caller graph for this function:

◆ push_data_item()

static int push_data_item ( struct coap_dtls_session_t session,
coap_tid_t  id,
const unsigned char *  data,
size_t  data_length 
)
static

Definition at line 140 of file coap_dtls_gnutls.c.

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