15 #ifdef HAVE_LIBTINYDTLS 
   18 #undef PACKAGE_BUGREPORT 
   21 #undef PACKAGE_TARNAME 
   23 #undef PACKAGE_VERSION 
   27 #include <dtls_debug.h> 
   29 typedef struct coap_tiny_context_t {
 
   30   struct dtls_context_t *dtls_context;
 
   37 } coap_tiny_context_t;
 
   39 static dtls_tick_t dtls_tick_0 = 0;
 
   49   dtls_ticks(&dtls_tick_0);
 
   62     const coap_tiny_context_t *t_context =
 
   65     return t_context->dtls_context;
 
   72   dtls_set_log_level(level);
 
   77   return dtls_get_log_level();
 
   80 static void get_session_addr(
const session_t *s, 
coap_address_t *a) {
 
   85   if (s->addr.sa.sa_family == AF_INET6) {
 
   88   } 
else if (s->addr.sa.sa_family == AF_INET) {
 
   92     a->
size = (socklen_t)s->size;
 
   98 static void put_session_addr(
const coap_address_t *a, session_t *s) {
 
  100   s->size = (
unsigned char)
sizeof(s->addr);
 
  104   if (a->
addr.
sa.sa_family == AF_INET6) {
 
  105     s->
size = (socklen_t)
sizeof(s->addr.sin6);
 
  107   } 
else if (a->
addr.
sa.sa_family == AF_INET) {
 
  108     s->size = (socklen_t)
sizeof(s->addr.sin);
 
  111     s->size = (socklen_t)a->
size;
 
  118 dtls_send_to_peer(
struct dtls_context_t *dtls_context,
 
  119   session_t *dtls_session, uint8 *data, 
size_t len) {
 
  120   coap_tiny_context_t *t_context =
 
  121                   (coap_tiny_context_t *)dtls_get_app_data(dtls_context);
 
  122   coap_context_t *coap_context = t_context ? t_context->coap_context : NULL;
 
  126   assert(coap_context);
 
  127   get_session_addr(dtls_session, &remote_addr);
 
  137 dtls_application_data(
struct dtls_context_t *dtls_context,
 
  138   session_t *dtls_session, uint8 *data, 
size_t len) {
 
  139   coap_tiny_context_t *t_context =
 
  140                   (coap_tiny_context_t *)dtls_get_app_data(dtls_context);
 
  141   coap_context_t *coap_context = t_context ? t_context->coap_context : NULL;
 
  145   assert(coap_context);
 
  146   get_session_addr(dtls_session, &remote_addr);
 
  150              "dropped message that was received on invalid interface\n");
 
  157 static int coap_event_dtls = 0;
 
  160 dtls_event(
struct dtls_context_t *dtls_context,
 
  161   session_t *dtls_session,
 
  162   dtls_alert_level_t level,
 
  167   if (level == DTLS_ALERT_LEVEL_FATAL)
 
  172   case DTLS_ALERT_CLOSE_NOTIFY:
 
  177   case DTLS_EVENT_CONNECTED:
 
  182   case DTLS_EVENT_RENEGOTIATE:
 
  198 get_psk_info(
struct dtls_context_t *dtls_context,
 
  199   const session_t *dtls_session,
 
  200   dtls_credentials_type_t type,
 
  201   const uint8_t *
id, 
size_t id_len,
 
  202   unsigned char *result, 
size_t result_length) {
 
  204   coap_tiny_context_t *t_context =
 
  205                   (coap_tiny_context_t *)dtls_get_app_data(dtls_context);
 
  206   coap_context_t *coap_context = t_context ? t_context->coap_context : NULL;
 
  208   int fatal_error = DTLS_ALERT_INTERNAL_ERROR;
 
  209   size_t identity_length;
 
  217   assert(coap_context);
 
  218   get_session_addr(dtls_session, &remote_addr);
 
  226   case DTLS_PSK_IDENTITY:
 
  238     coap_log(
LOG_DEBUG, 
"got psk_identity_hint: '%.*s'\n", (
int)id_len, 
id ? (
const char*)
id : 
"");
 
  249       if (psk_info == NULL)
 
  261       memcpy(result, psk_info->
identity.
s, identity_length);
 
  262       result[identity_length] = 
'\000';
 
  266       return identity_length;
 
  271     psk_len = coap_context->
get_client_psk(coap_session, (
const uint8_t*)
id, id_len, (uint8_t*)result, &identity_length, result_length, psk, 
sizeof(psk));
 
  274       fatal_error = DTLS_ALERT_CLOSE_NOTIFY;
 
  277     return (
int)identity_length;
 
  285       psk_len = coap_context->
get_client_psk(coap_session, (
const uint8_t*)
id, id_len, psk, &identity_length, 
sizeof(psk), result, result_length);
 
  288         fatal_error = DTLS_ALERT_CLOSE_NOTIFY;
 
  297         id = (
const uint8_t *)
"";
 
  309         lidentity.
length = id_len;
 
  310         lidentity.
s = (
const uint8_t*)
id;
 
  318         if (psk_key->
length > result_length)
 
  320         memcpy(result, psk_key->
s, psk_key->
length);
 
  325       return (
int)coap_context->
get_server_psk(coap_session, (
const uint8_t*)
id, id_len, (uint8_t*)result, result_length);
 
  331       return (
int)coap_context->
get_server_hint(coap_session, (uint8_t *)result, result_length);
 
  339   return dtls_alert_fatal_create(fatal_error);
 
  344 get_ecdsa_key(
struct dtls_context_t *dtls_context,
 
  346               const dtls_ecdsa_key_t **result) {
 
  347   static dtls_ecdsa_key_t ecdsa_key;
 
  348   coap_tiny_context_t *t_context =
 
  349                   (coap_tiny_context_t *)dtls_get_app_data(dtls_context);
 
  351   ecdsa_key.curve = DTLS_ECDH_CURVE_SECP256R1;
 
  352   ecdsa_key.priv_key = t_context->priv_key->s;
 
  353   ecdsa_key.pub_key_x = t_context->pub_key->s;
 
  354   ecdsa_key.pub_key_y = &t_context->pub_key->s[DTLS_EC_KEY_SIZE];
 
  356   *result = &ecdsa_key;
 
  361 static const unsigned char cert_asn1_header[] = {
 
  365         0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01,
 
  367         0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07,
 
  371 #define DTLS_CE_LENGTH (sizeof(cert_asn1_header) + key_size + key_size) 
  374 verify_ecdsa_key(
struct dtls_context_t *dtls_context 
COAP_UNUSED,
 
  376                  const uint8_t *other_pub_x,
 
  377                  const uint8_t *other_pub_y,
 
  379   coap_tiny_context_t *t_context =
 
  380                   (coap_tiny_context_t *)dtls_get_app_data(dtls_context);
 
  381   if (t_context && t_context->setup_data.validate_cn_call_back) {
 
  384     uint8 buf[DTLS_CE_LENGTH];
 
  393     memcpy(p, &cert_asn1_header, 
sizeof(cert_asn1_header));
 
  394     p += 
sizeof(cert_asn1_header);
 
  396     memcpy(p, other_pub_x, key_size);
 
  399     memcpy(p, other_pub_y, key_size);
 
  402     assert(p <= (buf + 
sizeof(buf)));
 
  404     get_session_addr(dtls_session, &remote_addr);
 
  406                                          &remote_addr, dtls_session->ifindex);
 
  410         buf, p-buf, c_session, 0, 1, t_context->setup_data.cn_call_back_arg)) {
 
  416 static dtls_handler_t ec_cb = {
 
  417   .write = dtls_send_to_peer,
 
  418   .read = dtls_application_data,
 
  420   .get_psk_info = NULL,
 
  421   .get_ecdsa_key = get_ecdsa_key,
 
  422   .verify_ecdsa_key = verify_ecdsa_key
 
  426 static dtls_handler_t psk_cb = {
 
  427   .write = dtls_send_to_peer,
 
  428   .read = dtls_application_data,
 
  430   .get_psk_info = get_psk_info,
 
  432   .get_ecdsa_key = NULL,
 
  433   .verify_ecdsa_key = NULL
 
  439   coap_tiny_context_t *t_context = 
coap_malloc(
sizeof(coap_tiny_context_t));
 
  440   struct dtls_context_t *dtls_context = t_context ? dtls_new_context(t_context) : NULL;
 
  443   memset(t_context, 0, 
sizeof(coap_tiny_context_t));
 
  444   t_context->coap_context = coap_context;
 
  446   dtls_set_handler(dtls_context, &psk_cb);
 
  459     coap_tiny_context_t *t_context = (coap_tiny_context_t *)handle;
 
  461     if (t_context->priv_key) {
 
  463       t_context->priv_key = NULL;
 
  465     if (t_context->pub_key) {
 
  467       t_context->pub_key = NULL;
 
  470     if (t_context->dtls_context)
 
  471       dtls_free_context(t_context->dtls_context);
 
  478   session_t *dtls_session = 
coap_malloc_type(COAP_DTLS_SESSION, 
sizeof(session_t));
 
  483     dtls_session_init(dtls_session);
 
  485     dtls_session->ifindex = session->
ifindex;
 
  493   return coap_dtls_new_session(session);
 
  499   dtls_context_t *dtls_context = t_context ? t_context->dtls_context : NULL;
 
  500   session_t *dtls_session = dtls_context ? coap_dtls_new_session(session) : NULL;
 
  505     dtls_get_peer(dtls_context, dtls_session);
 
  511     if (dtls_connect(dtls_context, dtls_session) >= 0) {
 
  513         dtls_get_peer(dtls_context, dtls_session);
 
  533   coap_tiny_context_t *t_context =
 
  535   dtls_context_t *dtls_context = t_context ? t_context->dtls_context : NULL;
 
  537   if (dtls_context == NULL)
 
  539   if (coap_session->
tls && dtls_context) {
 
  540     dtls_peer_t *peer = dtls_get_peer(dtls_context, (session_t *)coap_session->
tls);
 
  542       dtls_reset_peer(dtls_context, peer);
 
  544       dtls_close(dtls_context, (session_t *)coap_session->
tls);
 
  547     coap_session->
tls = NULL;
 
  560   dtls_context_t *dtls_context = t_context ? t_context->dtls_context : NULL;
 
  562   assert(dtls_context);
 
  565   coap_event_dtls = -1;
 
  567   memcpy (&data_rw, &data, 
sizeof(data_rw));
 
  568   res = dtls_write(dtls_context,
 
  569     (session_t *)session->
tls, data_rw, data_len);
 
  574   if (coap_event_dtls >= 0) {
 
  592   clock_time_t next = 0;
 
  593   coap_tiny_context_t *t_context = (coap_tiny_context_t *)tiny_context;
 
  594   dtls_context_t *dtls_context = t_context ? t_context->dtls_context : NULL;
 
  596     dtls_check_retransmit(dtls_context, &next);
 
  618   session_t *dtls_session = (session_t *)session->
tls;
 
  622   dtls_context_t *dtls_context = t_context ? t_context->dtls_context : NULL;
 
  624   assert(dtls_context);
 
  625   coap_event_dtls = -1;
 
  627   memcpy (&data_rw, &data, 
sizeof(data_rw));
 
  628   err = dtls_handle_message(dtls_context, dtls_session, data_rw, (
int)data_len);
 
  634   if (coap_event_dtls >= 0) {
 
  652   session_t dtls_session;
 
  654   dtls_context_t *dtls_context = t_context ? t_context->dtls_context : NULL;
 
  657   assert(dtls_context);
 
  658   dtls_session_init(&dtls_session);
 
  660   dtls_session.ifindex = session->
ifindex;
 
  662   memcpy (&data_rw, &data, 
sizeof(data_rw));
 
  663   int res = dtls_handle_message(dtls_context, &dtls_session,
 
  664     data_rw, (
int)data_len);
 
  666     if (dtls_get_peer(dtls_context, &dtls_session))
 
  686   const char *vers = dtls_package_version();
 
  690     long int p1, p2 = 0, p3 = 0;
 
  693     p1 = strtol(vers, &endptr, 10);
 
  694     if (*endptr == 
'.') {
 
  695       p2 = strtol(endptr+1, &endptr, 10);
 
  696       if (*endptr == 
'.') {
 
  697         p3 = strtol(endptr+1, &endptr, 10);
 
  700     version.
version = (p1 << 16) | (p2 << 8) | p3;
 
  708 static const uint8_t b64_6[256] =
 
  710   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
 
  711   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
 
  713   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
 
  715   52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
 
  717   64,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
 
  719   15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
 
  721   64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
 
  723   41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
 
  724   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
 
  725   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
 
  726   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
 
  727   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
 
  728   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
 
  729   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
 
  730   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
 
  731   64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
 
  736 pem_base64_decode (
const uint8_t *data, 
size_t size)
 
  739   size_t nbytesdecoded;
 
  744   size_t nb64bytes = 0;
 
  746   for (i = 0; i < size; i++) {
 
  754       if (b64_6[data[i]] == 64)
 
  756       tbuf[nb64bytes++] = data[i];
 
  762   nbytesdecoded = ((nb64bytes + 3) / 4) * 3;
 
  770   while (nb64bytes > 4) {
 
  771     *(out++) = b64_6[ptr[0]] << 2 | b64_6[ptr[1]] >> 4;
 
  772     *(out++) = b64_6[ptr[1]] << 4 | b64_6[ptr[2]] >> 2;
 
  773     *(out++) = b64_6[ptr[2]] << 6 | b64_6[ptr[3]];
 
  780     *(out++) = b64_6[ptr[0]] << 2 | b64_6[ptr[1]] >> 4;
 
  783     *(out++) = b64_6[ptr[1]] << 4 | b64_6[ptr[2]] >> 2;
 
  786     *(out++) = b64_6[ptr[2]] << 6 | b64_6[ptr[3]];
 
  789   decoded->
length = nbytesdecoded - ((4 - nb64bytes) & 3);
 
  794 typedef coap_binary_t * (*asn1_callback)(
const uint8_t *data, 
size_t size);
 
  797 asn1_verify_privkey(
const uint8_t *data, 
size_t size)
 
  801   if (size - 1 == DTLS_EC_KEY_SIZE && *data == 
'\000') {
 
  807   if (size != DTLS_EC_KEY_SIZE)
 
  814 asn1_verify_pubkey(
const uint8_t *data, 
size_t size)
 
  820   if (size - 2 != 2 * DTLS_EC_KEY_SIZE)
 
  827 asn1_verify_curve(
const uint8_t *data, 
size_t size)
 
  829   static uint8_t prime256v1_oid[] =
 
  831          { 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07 };
 
  834   if (size != 
sizeof(prime256v1_oid) ||
 
  835       memcmp(data, prime256v1_oid, size) != 0)
 
  842 asn1_verify_pkcs8_version(
const uint8_t *data, 
size_t size)
 
  845   if (size != 1 || *data != 0)
 
  852 asn1_verify_ec_identifier(
const uint8_t *data, 
size_t size)
 
  854   static uint8_t ec_public_key_oid[] =
 
  856          { 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01 };
 
  859   if (size != 
sizeof(ec_public_key_oid) ||
 
  860       memcmp(data, ec_public_key_oid, size) != 0)
 
  867 asn1_verify_ec_key(
const uint8_t *data, 
size_t size)
 
  878 asn1_derive_keys(coap_tiny_context_t *t_context,
 
  879                  const uint8_t *priv_data, 
size_t priv_len,
 
  880                  const uint8_t *pub_data, 
size_t pub_len,
 
  886                                      priv_len, asn1_verify_privkey);
 
  887   if (!t_context->priv_key) {
 
  892   if (t_context->priv_key->length - 1 == DTLS_EC_KEY_SIZE &&
 
  893       t_context->priv_key->s[0] == 
'\000') {
 
  894         t_context->priv_key->length--;
 
  895         t_context->priv_key->s++;
 
  905       t_context->priv_key = NULL;
 
  913   if (!t_context->pub_key) {
 
  916     t_context->priv_key = NULL;
 
  920   t_context->pub_key->s += 2;
 
  921   t_context->pub_key->length -= 2;
 
  922   dtls_set_handler(t_context->dtls_context, &ec_cb);
 
  927 ec_abstract_pkcs8_asn1(
const uint8_t *asn1_ptr, 
size_t asn1_length)
 
  932                                asn1_verify_pkcs8_version);
 
  939                                asn1_verify_ec_identifier);
 
  958 pem_decode_mem_asn1(
const char *begstr, 
const uint8_t *str)
 
  960   char *bcp = str ? strstr((
const char*)str, begstr) : NULL;
 
  961   char *tcp = bcp ? strstr(bcp, 
"-----END ") : NULL;
 
  964     bcp += strlen(begstr);
 
  965     return pem_base64_decode ((
const uint8_t *)bcp, tcp - bcp);
 
  978   coap_tiny_context_t *t_context;
 
  997   if (t_context->priv_key) {
 
  999     t_context->priv_key = NULL;
 
 1001   if (t_context->pub_key) {
 
 1003     t_context->pub_key = NULL;
 
 1005   t_context->setup_data = *setup_data;
 
 1018       asn1_priv = pem_decode_mem_asn1(
"-----BEGIN EC PRIVATE KEY-----",
 
 1021         asn1_priv = pem_decode_mem_asn1(
"-----BEGIN PRIVATE KEY-----",
 
 1027         asn1_temp = ec_abstract_pkcs8_asn1(asn1_priv->
s, asn1_priv->
length);
 
 1034         asn1_priv = asn1_temp;
 
 1037       asn1_pub = pem_decode_mem_asn1(
 
 1038                                 "-----BEGIN PUBLIC KEY-----",
 
 1041         asn1_pub = pem_decode_mem_asn1(
"-----BEGIN EC PRIVATE KEY-----",
 
 1044           asn1_pub = pem_decode_mem_asn1(
"-----BEGIN PRIVATE KEY-----",
 
 1051           asn1_temp = ec_abstract_pkcs8_asn1(asn1_pub->
s, asn1_pub->
length);
 
 1059           asn1_pub = asn1_temp;
 
 1063       if (!asn1_derive_keys(t_context, asn1_priv->
s, asn1_priv->
length,
 
 1064                             asn1_pub->
s, asn1_pub->
length, is_pkcs8)) {
 
 1083       asn1_temp = ec_abstract_pkcs8_asn1(
 
 1087         private_key = asn1_temp->
s;
 
 1088         private_key_len = asn1_temp->
length;
 
 1094         if (!asn1_derive_keys(t_context,
 
 1106         if (!asn1_derive_keys(t_context,
 
 1161         "CoAP Server with TinyDTLS does not support SNI selection\n");
 
 1173 #if !COAP_DISABLE_TCP 
 1202   dtls_sha256_ctx *digest_ctx = 
coap_malloc(
sizeof(dtls_sha256_ctx));
 
 1205     dtls_sha256_init(digest_ctx);
 
 1218                    const uint8_t *data,
 
 1220   dtls_sha256_update(digest_ctx, data, data_len);
 
 1228   dtls_sha256_final((uint8_t*)digest_buffer, digest_ctx);
 
 1240 #pragma GCC diagnostic ignored "-Wunused-function" 
Pulls together all the internal only header files.
 
void * coap_dtls_new_server_session(coap_session_t *session COAP_UNUSED)
 
int coap_dtls_context_set_spsk(coap_context_t *ctx COAP_UNUSED, coap_dtls_spsk_t *setup_data COAP_UNUSED)
 
void coap_dtls_handle_timeout(coap_session_t *session COAP_UNUSED)
 
int coap_dtls_context_set_pki(coap_context_t *ctx COAP_UNUSED, const coap_dtls_pki_t *setup_data COAP_UNUSED, const coap_dtls_role_t role COAP_UNUSED)
 
coap_tick_t coap_dtls_get_timeout(coap_session_t *session COAP_UNUSED, coap_tick_t now COAP_UNUSED)
 
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
 
int coap_dtls_send(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
 
void * coap_dtls_new_client_session(coap_session_t *session COAP_UNUSED)
 
ssize_t coap_tls_read(coap_session_t *session COAP_UNUSED, uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
 
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
 
int coap_dtls_receive(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
 
unsigned int coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED)
 
void * coap_tls_new_client_session(coap_session_t *session COAP_UNUSED, int *connected COAP_UNUSED)
 
void * coap_tls_new_server_session(coap_session_t *session COAP_UNUSED, int *connected COAP_UNUSED)
 
int coap_dtls_hello(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
 
int coap_dtls_context_check_keys_enabled(coap_context_t *ctx COAP_UNUSED)
 
int coap_dtls_context_set_cpsk(coap_context_t *ctx COAP_UNUSED, coap_dtls_cpsk_t *setup_data COAP_UNUSED)
 
ssize_t coap_tls_write(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
 
void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED)
 
int coap_dtls_context_set_pki_root_cas(coap_context_t *ctx COAP_UNUSED, const char *ca_file COAP_UNUSED, const char *ca_path COAP_UNUSED)
 
void coap_dtls_free_context(void *handle COAP_UNUSED)
 
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
 
void * coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED, coap_tls_library_t *tls_lib)
 
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
 
coap_session_t * coap_session_get_by_peer(const coap_context_t *ctx, const coap_address_t *remote_addr, int ifindex)
 
coap_binary_t * get_asn1_tag(coap_asn1_tag_t ltag, const uint8_t *ptr, size_t tlen, asn1_validate validate)
Get the asn1 tag and data from the current ptr.
 
void coap_digest_free(coap_digest_ctx_t *digest_ctx)
Free off coap_digest_ctx_t.
 
coap_digest_ctx_t * coap_digest_setup(void)
Initialize a coap_digest.
 
int coap_digest_final(coap_digest_ctx_t *digest_ctx, coap_digest_t *digest_buffer)
Finalize the coap_digest information into the provided digest_buffer.
 
int coap_digest_update(coap_digest_ctx_t *digest_ctx, const uint8_t *data, size_t data_len)
Update the coap_digest information with the next chunk of data.
 
void coap_ticks(coap_tick_t *t)
Sets t to the internal time with COAP_TICKS_PER_SECOND resolution.
 
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
 
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
 
int coap_handle_dgram(coap_context_t *ctx, coap_session_t *session, uint8_t *msg, size_t msg_len)
Parses and interprets a CoAP datagram with context ctx.
 
int coap_handle_event(coap_context_t *context, coap_event_t event, coap_session_t *session)
Invokes the event handler of context for the given event and data.
 
void coap_dtls_startup(void)
Initialize the underlying (D)TLS Library layer.
 
int coap_dtls_is_context_timeout(void)
Check if timeout is handled per CoAP session or per CoAP context.
 
void coap_dtls_shutdown(void)
Close down the underlying (D)TLS Library layer.
 
int coap_tls_is_supported(void)
Check whether TLS is available.
 
#define COAP_DTLS_PKI_SETUP_VERSION
Latest PKI setup version.
 
#define COAP_DTLS_RPK_CERT_CN
 
coap_tls_version_t * coap_get_tls_library_version(void)
Determine the type and version of the underlying (D)TLS library.
 
int coap_dtls_is_supported(void)
Check whether DTLS is available.
 
@ COAP_PKI_KEY_PKCS11
The PKI key type is PKCS11 (DER)
 
@ COAP_PKI_KEY_PEM_BUF
The PKI key type is PEM buffer.
 
@ COAP_PKI_KEY_PEM
The PKI key type is PEM file.
 
@ COAP_PKI_KEY_ASN1
The PKI key type is ASN.1 (DER) buffer.
 
@ COAP_ASN1_PKEY_EC
EC type.
 
@ COAP_TLS_LIBRARY_TINYDTLS
Using TinyDTLS library.
 
#define COAP_EVENT_DTLS_RENEGOTIATE
 
#define COAP_EVENT_DTLS_ERROR
 
#define COAP_EVENT_DTLS_CLOSED
(D)TLS events for COAP_PROTO_DTLS and COAP_PROTO_TLS
 
#define COAP_EVENT_DTLS_CONNECTED
 
void coap_dtls_set_log_level(int level)
Sets the (D)TLS logging level to the specified level.
 
int coap_dtls_get_log_level(void)
Get the current (D)TLS logging.
 
#define coap_log(level,...)
Logging function.
 
int coap_session_refresh_psk_hint(coap_session_t *session, const coap_bin_const_t *psk_hint)
Refresh the session's current Identity Hint (PSK).
 
ssize_t coap_session_send(coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for datagram data transmission.
 
int coap_session_refresh_psk_key(coap_session_t *session, const coap_bin_const_t *psk_key)
Refresh the session's current pre-shared key (PSK).
 
void coap_session_connected(coap_session_t *session)
Notify session that it has just connected or reconnected.
 
void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reason)
Notify session that it has failed.
 
@ COAP_SESSION_TYPE_CLIENT
client-side
 
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
 
void coap_delete_binary(coap_binary_t *s)
Deletes the given coap_binary_t object and releases any memory allocated.
 
coap_bin_const_t * coap_new_bin_const(const uint8_t *data, size_t size)
Take the specified byte array (text) and create a coap_bin_const_t * Returns a new const binary objec...
 
coap_binary_t * coap_new_binary(size_t size)
Returns a new binary object with at least size bytes storage allocated.
 
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
 
COAP_STATIC_INLINE void * coap_malloc(size_t size)
Wrapper function to coap_malloc_type() for backwards compatibility.
 
COAP_STATIC_INLINE void coap_free(void *object)
Wrapper function to coap_free_type() for backwards compatibility.
 
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
 
coap_address_t remote
remote address and port
 
multi-purpose address abstraction
 
socklen_t size
size of addr
 
union coap_address_t::@0 addr
 
CoAP binary data definition with const data.
 
size_t length
length of binary data
 
const uint8_t * s
read-only binary data
 
CoAP binary data definition.
 
size_t length
length of binary data
 
The CoAP stack's global state is stored in a coap_context_t object.
 
size_t(* get_server_psk)(const coap_session_t *session, const uint8_t *identity, size_t identity_len, uint8_t *psk, size_t max_psk_len)
 
size_t(* get_server_hint)(const coap_session_t *session, uint8_t *hint, size_t max_hint_len)
 
size_t(* get_client_psk)(const coap_session_t *session, const uint8_t *hint, size_t hint_len, uint8_t *identity, size_t *identity_len, size_t max_identity_len, uint8_t *psk, size_t max_psk_len)
 
coap_dtls_spsk_t spsk_setup_data
Contains the initial PSK server setup data.
 
The structure that holds the Client PSK information.
 
coap_bin_const_t identity
 
The structure used for defining the Client PSK setup data to be used.
 
void * ih_call_back_arg
Passed in to the Identity Hint callback function.
 
coap_dtls_ih_callback_t validate_ih_call_back
Identity Hint check callback function.
 
union coap_dtls_key_t::@2 key
 
coap_pki_key_pem_buf_t pem_buf
for PEM memory keys
 
coap_pki_key_t key_type
key format type
 
coap_pki_key_asn1_t asn1
for ASN.1 (DER) memory keys
 
The structure used for defining the PKI setup data to be used.
 
uint8_t is_rpk_not_cert
1 is RPK instead of Public Certificate.
 
coap_dtls_key_t pki_key
PKI key definition.
 
The structure used for defining the Server PSK setup data to be used.
 
coap_dtls_psk_sni_callback_t validate_sni_call_back
SNI check callback function.
 
coap_dtls_id_callback_t validate_id_call_back
Identity check callback function.
 
void * id_call_back_arg
Passed in to the Identity callback function.
 
const uint8_t * private_key
ASN1 (DER) Private Key.
 
coap_asn1_privatekey_type_t private_key_type
Private Key Type.
 
size_t public_cert_len
ASN1 Public Cert length.
 
size_t private_key_len
ASN1 Private Key length.
 
const uint8_t * public_cert
ASN1 (DER) Public Cert, or Public Key if RPK.
 
const uint8_t * private_key
PEM buffer Private Key If RPK and 'EC PRIVATE KEY' this can be used for both the public_cert and priv...
 
const uint8_t * public_cert
PEM buffer Public Cert, or Public Key if RPK.
 
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
 
coap_bin_const_t * psk_identity
If client, this field contains the current identity for server; When this field is NULL,...
 
coap_addr_tuple_t addr_info
key: remote/local address info
 
coap_dtls_cpsk_t cpsk_setup_data
client provided PSK initial setup data
 
void * tls
security parameters
 
coap_session_type_t type
client or server side socket
 
coap_context_t * context
session's context
 
int ifindex
interface index
 
CoAP string data definition with const data.
 
const uint8_t * s
read-only string data
 
size_t length
length of string
 
The structure used for returning the underlying (D)TLS library information.
 
uint64_t built_version
(D)TLS Built against Library Version
 
coap_tls_library_t type
Library type.
 
uint64_t version
(D)TLS runtime Library Version