51 # include "sha2/sha2.h"
54 #define dtls_set_version(H,V) dtls_int_to_uint16((H)->version, (V))
55 #define dtls_set_content_type(H,V) ((H)->content_type = (V) & 0xff)
56 #define dtls_set_length(H,V) ((H)->length = (V))
58 #define dtls_get_content_type(H) ((H)->content_type & 0xff)
59 #define dtls_get_version(H) dtls_uint16_to_int((H)->version)
60 #define dtls_get_epoch(H) dtls_uint16_to_int((H)->epoch)
61 #define dtls_get_sequence_number(H) dtls_uint48_to_ulong((H)->sequence_number)
62 #define dtls_get_fragment_length(H) dtls_uint24_to_int((H)->fragment_length)
65 #define HASH_FIND_PEER(head,sess,out) \
66 HASH_FIND(hh,head,sess,sizeof(session_t),out)
67 #define HASH_ADD_PEER(head,sess,add) \
68 HASH_ADD(hh,head,sess,sizeof(session_t),add)
69 #define HASH_DEL_PEER(head,delptr) \
70 HASH_DELETE(hh,head,delptr)
73 #define DTLS_RH_LENGTH sizeof(dtls_record_header_t)
74 #define DTLS_HS_LENGTH sizeof(dtls_handshake_header_t)
75 #define DTLS_CH_LENGTH sizeof(dtls_client_hello_t)
76 #define DTLS_COOKIE_LENGTH_MAX 32
77 #define DTLS_CH_LENGTH_MAX sizeof(dtls_client_hello_t) + DTLS_COOKIE_LENGTH_MAX + 12 + 26
78 #define DTLS_HV_LENGTH sizeof(dtls_hello_verify_t)
79 #define DTLS_SH_LENGTH (2 + DTLS_RANDOM_LENGTH + 1 + 2 + 1)
80 #define DTLS_CE_LENGTH (3 + 3 + 27 + DTLS_EC_KEY_SIZE + DTLS_EC_KEY_SIZE)
81 #define DTLS_SKEXEC_LENGTH (1 + 2 + 1 + 1 + DTLS_EC_KEY_SIZE + DTLS_EC_KEY_SIZE + 1 + 1 + 2 + 70)
82 #define DTLS_SKEXECPSK_LENGTH_MIN 2
83 #define DTLS_SKEXECPSK_LENGTH_MAX 2 + DTLS_PSK_MAX_CLIENT_IDENTITY_LEN
84 #define DTLS_CKXPSK_LENGTH_MIN 2
85 #define DTLS_CKXEC_LENGTH (1 + 1 + DTLS_EC_KEY_SIZE + DTLS_EC_KEY_SIZE)
86 #define DTLS_CV_LENGTH (1 + 1 + 2 + 1 + 1 + 1 + 1 + DTLS_EC_KEY_SIZE + 1 + 1 + DTLS_EC_KEY_SIZE)
87 #define DTLS_FIN_LENGTH 12
89 #define HS_HDR_LENGTH DTLS_RH_LENGTH + DTLS_HS_LENGTH
90 #define HV_HDR_LENGTH HS_HDR_LENGTH + DTLS_HV_LENGTH
92 #define HIGH(V) (((V) >> 8) & 0xff)
93 #define LOW(V) ((V) & 0xff)
95 #define DTLS_RECORD_HEADER(M) ((dtls_record_header_t *)(M))
96 #define DTLS_HANDSHAKE_HEADER(M) ((dtls_handshake_header_t *)(M))
98 #define HANDSHAKE(M) ((dtls_handshake_header_t *)((M) + DTLS_RH_LENGTH))
99 #define CLIENTHELLO(M) ((dtls_client_hello_t *)((M) + HS_HDR_LENGTH))
106 #define SKIP_VAR_FIELD(P,L,T) { \
107 if (L < dtls_ ## T ## _to_int(P) + sizeof(T)) \
109 L -= dtls_ ## T ## _to_int(P) + sizeof(T); \
110 P += dtls_ ## T ## _to_int(P) + sizeof(T); \
114 #define PRF_LABEL(Label) prf_label_##Label
115 #define PRF_LABEL_SIZE(Label) (sizeof(PRF_LABEL(Label)) - 1)
128 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x02, 0x01,
130 0x2A, 0x86, 0x48, 0xCE, 0x3D, 0x03, 0x01, 0x07,
136 PROCESS(dtls_retransmit_process,
"DTLS retransmit process");
142 return &the_dtls_context;
174 #define CALL(Context, which, ...) \
175 ((Context)->h && (Context)->h->which \
176 ? (Context)->h->which((Context), ##__VA_ARGS__) \
182 unsigned char type,
uint8 *buf_array[],
183 size_t buf_len_array[],
size_t buf_array_len);
201 uint8 *buf,
size_t buflen) {
203 type, &buf, &buflen, 1);
249 return (res >= 0) ? 0 : res;
275 if (msglen < (*msg & 0xff) +
sizeof(
uint8))
278 *cookie = msg +
sizeof(
uint8);
288 uint8 *msg,
size_t msglen,
289 uint8 *cookie,
int *clen) {
313 (
unsigned char *)&session->
addr, session->
size);
337 memset(cookie + len, 0, *clen - len);
341 memcpy(cookie, buf, *clen);
345 #ifdef DTLS_CHECK_CONTENTTYPE
347 static char const content_types[] = {
362 unsigned int rlen = 0;
365 #ifdef DTLS_CHECK_CONTENTTYPE
366 && strchr(content_types, msg[0])
389 static inline uint8 *
394 buf +=
sizeof(
uint8);
413 memset(buf, 0,
sizeof(
uint16));
414 return buf +
sizeof(
uint16);
423 static inline uint8 *
426 int frag_offset,
int frag_length,
430 buf +=
sizeof(
uint8);
442 memset(buf, 0,
sizeof(
uint16));
484 return ctx && ctx->
h && ctx->
h->get_psk_info;
494 return ctx && ctx->
h && ((!is_client && ctx->
h->get_ecdsa_key) ||
495 (is_client && ctx->
h->verify_ecdsa_key));
506 return ctx && ctx->
h && ctx->
h->get_ecdsa_key && ctx->
h->verify_ecdsa_key;
569 return "hello_request";
571 return "client_hello";
573 return "server_hello";
575 return "hello_verify_request";
577 return "certificate";
579 return "server_key_exchange";
581 return "certificate_request";
583 return "server_hello_done";
585 return "certificate_verify";
587 return "client_key_exchange";
604 unsigned char *pre_master_secret;
605 int pre_master_len = 0;
615 switch (handshake->
cipher) {
622 handshake->
keyx.psk.identity,
623 handshake->
keyx.psk.id_length,
626 dtls_crit(
"no psk key for session available\n");
637 if (pre_master_len < 0) {
638 dtls_crit(
"the psk was too long, for the pre master secret\n");
648 handshake->
keyx.ecdsa.other_eph_pub_x,
649 handshake->
keyx.ecdsa.other_eph_pub_y,
650 sizeof(handshake->
keyx.ecdsa.own_eph_priv),
653 if (pre_master_len < 0) {
654 dtls_crit(
"the curve was too long, for the pre master secret\n");
661 dtls_crit(
"calculate_key_block: unknown cipher\n");
667 dtls_debug_dump(
"pre_master_secret", pre_master_secret, pre_master_len);
669 dtls_prf(pre_master_secret, pre_master_len,
707 if (i +
sizeof(
uint16) != data_length) {
708 dtls_warn(
"the list of the supported elliptic curves should be tls extension length - 2\n");
712 for (i = data_length -
sizeof(
uint16); i > 0; i -=
sizeof(
uint16)) {
721 dtls_warn(
"no supported elliptic curve found\n");
730 data +=
sizeof(
uint8);
731 if (i +
sizeof(
uint8) != data_length) {
732 dtls_warn(
"the list of the supported certificate types should be tls extension length - 1\n");
736 for (i = data_length -
sizeof(
uint8); i > 0; i -=
sizeof(
uint8)) {
739 data +=
sizeof(
uint8);
745 dtls_warn(
"no supported certificate type found\n");
754 data +=
sizeof(
uint8);
755 if (i +
sizeof(
uint8) != data_length) {
756 dtls_warn(
"the list of the supported ec_point_formats should be tls extension length - 1\n");
760 for (i = data_length -
sizeof(
uint8); i > 0; i -=
sizeof(
uint8)) {
763 data +=
sizeof(
uint8);
769 dtls_warn(
"no supported ec_point_format found\n");
778 uint8 *data,
size_t data_length,
int client_hello)
781 int ext_elliptic_curve = 0;
782 int ext_client_cert_type = 0;
783 int ext_server_cert_type = 0;
784 int ext_ec_point_formats = 0;
787 if (data_length <
sizeof(
uint16)) {
798 data_length -=
sizeof(
uint16);
804 while (data_length) {
805 if (data_length <
sizeof(
uint16) * 2)
811 data_length -=
sizeof(
uint16);
816 data_length -=
sizeof(
uint16);
823 ext_elliptic_curve = 1;
828 ext_client_cert_type = 1;
838 ext_server_cert_type = 1;
848 ext_ec_point_formats = 1;
856 dtls_info(
"skipped encrypt-then-mac extension\n");
859 dtls_warn(
"unsupported tls extension: %i\n", i);
866 if (!ext_elliptic_curve || !ext_client_cert_type || !ext_server_cert_type
867 || !ext_ec_point_formats) {
868 dtls_warn(
"not all required tls extensions found in client hello\n");
872 if (!ext_client_cert_type || !ext_server_cert_type) {
873 dtls_warn(
"not all required tls extensions found in server hello\n");
902 uint8 *data,
size_t data_length) {
925 if (data_length < i +
sizeof(
uint16)) {
939 data_length -=
sizeof(
uint16) + i;
959 if (data_length <
sizeof(
uint8)) {
969 if (data_length < i +
sizeof(
uint8))
972 data +=
sizeof(
uint8);
973 data_length -=
sizeof(
uint8) + i;
983 data +=
sizeof(
uint8);
1007 uint8 *data,
size_t length) {
1013 dtls_debug(
"The client key exchange is too short\n");
1019 dtls_alert(
"expected 65 bytes long public point\n");
1022 data +=
sizeof(
uint8);
1025 dtls_alert(
"expected uncompressed public point\n");
1028 data +=
sizeof(
uint8);
1030 memcpy(handshake->
keyx.ecdsa.other_eph_pub_x, data,
1031 sizeof(handshake->
keyx.ecdsa.other_eph_pub_x));
1032 data +=
sizeof(handshake->
keyx.ecdsa.other_eph_pub_x);
1034 memcpy(handshake->
keyx.ecdsa.other_eph_pub_y, data,
1035 sizeof(handshake->
keyx.ecdsa.other_eph_pub_y));
1036 data +=
sizeof(handshake->
keyx.ecdsa.other_eph_pub_y);
1044 dtls_debug(
"The client key exchange is too short\n");
1053 dtls_debug(
"The identity has a wrong length\n");
1058 dtls_warn(
"please use a smaller client identity\n");
1062 handshake->
keyx.psk.id_length = id_length;
1063 memcpy(handshake->
keyx.psk.identity, data, id_length);
1081 static inline size_t
1105 uint8 *data,
size_t data_length) {
1106 size_t digest_length, label_size;
1107 const unsigned char *label;
1144 b.verify_data,
sizeof(b.verify_data));
1182 uint8 *data_array[],
size_t data_len_array[],
1183 size_t data_array_len,
1184 uint8 *sendbuf,
size_t *rlen) {
1190 dtls_alert(
"The sendbuf (%zu bytes) is too small\n", *rlen);
1201 for (i = 0; i < data_array_len; i++) {
1204 dtls_debug(
"dtls_prepare_record: send buffer too small\n");
1208 memcpy(p, data_array[i], data_len_array[i]);
1209 p += data_len_array[i];
1210 res += data_len_array[i];
1217 #define A_DATA_LEN 13
1222 dtls_debug(
"dtls_prepare_record(): encrypt using TLS_PSK_WITH_AES_128_CCM_8\n");
1224 dtls_debug(
"dtls_prepare_record(): encrypt using TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8\n");
1226 dtls_debug(
"dtls_prepare_record(): encrypt using unknown cipher\n");
1273 for (i = 0; i < data_array_len; i++) {
1276 dtls_debug(
"dtls_prepare_record: send buffer too small\n");
1280 memcpy(p, data_array[i], data_len_array[i]);
1281 p += data_len_array[i];
1282 res += data_len_array[i];
1303 res =
dtls_encrypt(start + 8, res - 8, start + 8, nonce,
1327 uint8 *data,
size_t data_length,
1331 uint8 *data_array[2];
1332 size_t data_len_array[2];
1342 data_array[i] = buf;
1343 data_len_array[i] =
sizeof(buf);
1350 data_array[i] = data;
1351 data_len_array[i] = data_length;
1354 dtls_debug(
"send handshake packet of type: %s (%i)\n",
1357 data_array, data_len_array, i);
1364 uint8 *data,
size_t data_length)
1367 header_type, data, data_length, 1);
1384 #define MUST_HASH(Type, Data, Length) \
1385 ((Type) == DTLS_CT_HANDSHAKE && \
1386 ((Data) != NULL) && ((Length) > 0) && \
1387 ((Data)[0] != DTLS_HT_HELLO_VERIFY_REQUEST) && \
1388 ((Data)[0] != DTLS_HT_CLIENT_HELLO || \
1389 ((Length) >= HS_HDR_LENGTH && \
1390 (dtls_uint16_to_int(DTLS_RECORD_HEADER(Data)->epoch > 0) || \
1391 (dtls_uint16_to_int(HANDSHAKE(Data)->message_seq) > 0)))))
1409 unsigned char type,
uint8 *buf_array[],
1410 size_t buf_len_array[],
size_t buf_array_len)
1419 size_t len =
sizeof(sendbuf);
1422 size_t overall_len = 0;
1424 res =
dtls_prepare_record(peer, security, type, buf_array, buf_len_array, buf_array_len, sendbuf, &len);
1433 for (i = 0; i < buf_array_len; i++) {
1435 overall_len += buf_len_array[i];
1452 for (i = 0; i < buf_array_len; i++) {
1453 memcpy(n->
data + n->
length, buf_array[i], buf_len_array[i]);
1454 n->
length += buf_len_array[i];
1458 dtls_warn(
"cannot add packet to retransmit buffer\n");
1463 PROCESS_CONTEXT_BEGIN(&dtls_retransmit_process);
1464 etimer_set(&ctx->retransmit_timer, n->
timeout);
1465 PROCESS_CONTEXT_END(&dtls_retransmit_process);
1476 res =
CALL(ctx, write, session, sendbuf, len);
1481 return res <= 0 ? res : overall_len - (len - res);
1487 uint8_t msg[] = { level, description };
1513 #ifndef WITH_CONTIKI
1543 uint8 *data,
size_t data_length)
1548 uint8 *cookie = NULL;
1551 #define mycookie (buf + DTLS_HV_LENGTH)
1565 dtls_warn(
"error while fetching the cookie, err: %i\n", err);
1602 dtls_warn(
"cannot send HelloVerify request\n");
1612 unsigned char **result_r,
1613 unsigned char **result_s)
1616 uint8 *data_orig = data;
1619 dtls_alert(
"only sha256 is supported in certificate verify\n");
1622 data +=
sizeof(
uint8);
1623 data_length -=
sizeof(
uint8);
1626 dtls_alert(
"only ecdsa signature is supported in client verify\n");
1629 data +=
sizeof(
uint8);
1630 data_length -=
sizeof(
uint8);
1637 data_length -=
sizeof(
uint16);
1640 dtls_alert(
"wrong ASN.1 struct, expected SEQUENCE\n");
1643 data +=
sizeof(
uint8);
1644 data_length -=
sizeof(
uint8);
1650 data +=
sizeof(
uint8);
1651 data_length -=
sizeof(
uint8);
1654 dtls_alert(
"wrong ASN.1 struct, expected Integer\n");
1657 data +=
sizeof(
uint8);
1658 data_length -=
sizeof(
uint8);
1661 data +=
sizeof(
uint8);
1662 data_length -=
sizeof(
uint8);
1671 dtls_alert(
"wrong ASN.1 struct, expected Integer\n");
1674 data +=
sizeof(
uint8);
1675 data_length -=
sizeof(
uint8);
1678 data +=
sizeof(
uint8);
1679 data_length -=
sizeof(
uint8);
1687 return data - data_orig;
1693 uint8 *data,
size_t data_length)
1697 unsigned char *result_r;
1698 unsigned char *result_s;
1707 dtls_alert(
"the packet length does not match the expected\n");
1723 sizeof(config->
keyx.ecdsa.other_pub_x),
1724 sha256hash,
sizeof(sha256hash),
1725 result_r, result_s);
1728 dtls_alert(
"wrong signature err: %i\n", ret);
1744 uint8 extension_size;
1750 extension_size = (ecdsa) ? 2 + 5 + 5 + 6 : 0;
1779 if (extension_size) {
1824 assert(p - buf <=
sizeof(buf));
1860 assert(p - buf <=
sizeof(buf));
1872 #define R_KEY_OFFSET (1 + 1 + 2 + 1 + 1 + 1 + 1)
1873 #define S_KEY_OFFSET(len_s) (R_KEY_OFFSET + (len_s) + 1 + 1)
1932 uint8 *ephemeral_pub_x;
1933 uint8 *ephemeral_pub_y;
1934 uint32_t point_r[9];
1935 uint32_t point_s[9];
1960 ephemeral_pub_x = p;
1964 ephemeral_pub_y = p;
1968 ephemeral_pub_x, ephemeral_pub_y,
1975 key_params, p - key_params,
1980 assert(p - buf <=
sizeof(buf));
1990 const unsigned char *psk_hint,
size_t len)
2000 dtls_warn(
"psk identity hint is too long\n");
2007 memcpy(p, psk_hint, len);
2010 assert(p - buf <=
sizeof(buf));
2053 assert(p - buf <=
sizeof(buf));
2080 dtls_debug(
"dtls_server_hello: cannot prepare ServerHello record\n");
2088 res =
CALL(ctx, get_ecdsa_key, &peer->
session, &ecdsa_key);
2090 dtls_crit(
"no ecdsa certificate to send in certificate\n");
2097 dtls_debug(
"dtls_server_hello: cannot prepare Certificate record\n");
2104 dtls_debug(
"dtls_server_hello: cannot prepare Server Key Exchange record\n");
2113 dtls_debug(
"dtls_server_hello: cannot prepare certificate Request record\n");
2131 dtls_debug(
"dtls_server_hello: cannot create ServerKeyExchange\n");
2139 dtls_debug(
"dtls_server_key_exchange_psk: cannot send server key exchange record\n");
2149 dtls_debug(
"dtls_server_hello: cannot prepare ServerHelloDone record\n");
2172 switch (handshake->
cipher) {
2178 handshake->
keyx.psk.identity, handshake->
keyx.psk.id_length,
2181 sizeof(handshake->
keyx.psk.identity)));
2183 dtls_crit(
"no psk identity set in kx\n");
2189 dtls_warn(
"the psk identity is too long\n");
2192 handshake->
keyx.psk.id_length = (
unsigned int)len;
2193 memcpy(handshake->
keyx.psk.identity, p +
sizeof(
uint16), len);
2198 memcpy(p, handshake->
keyx.psk.identity, handshake->
keyx.psk.id_length);
2199 p += handshake->
keyx.psk.id_length;
2206 uint8 *ephemeral_pub_x;
2207 uint8 *ephemeral_pub_y;
2216 ephemeral_pub_x = p;
2218 ephemeral_pub_y = p;
2222 ephemeral_pub_x, ephemeral_pub_y,
2233 assert(p - buf <=
sizeof(buf));
2248 uint32_t point_r[9];
2249 uint32_t point_s[9];
2264 sha256hash,
sizeof(sha256hash),
2269 assert(p - buf <=
sizeof(buf));
2278 const unsigned char *label,
size_t labellen)
2301 assert(p - buf <=
sizeof(buf));
2309 uint8 cookie[],
size_t cookie_length) {
2312 uint8_t cipher_size;
2313 uint8_t extension_size;
2322 cipher_size = 2 + ((ecdsa) ? 2 : 0) + ((psk) ? 2 : 0);
2323 extension_size = (ecdsa) ? 2 + 6 + 6 + 8 + 6: 0;
2325 if (cipher_size == 0) {
2326 dtls_crit(
"no cipher callbacks implemented\n");
2337 if (cookie_length == 0) {
2356 if (cookie_length != 0) {
2357 memcpy(p, cookie, cookie_length);
2381 if (extension_size) {
2449 assert(p - buf <=
sizeof(buf));
2451 if (cookie_length != 0)
2456 buf, p - buf, cookie_length != 0);
2462 uint8 *data,
size_t data_length)
2493 data_length -=
sizeof(
uint16);
2508 dtls_alert(
"unsupported cipher 0x%02x 0x%02x\n",
2513 data_length -=
sizeof(
uint16);
2517 dtls_alert(
"unsupported compression method 0x%02x\n", data[0]);
2520 data +=
sizeof(
uint8);
2521 data_length -=
sizeof(
uint8);
2532 uint8 *data,
size_t data_length)
2554 uint8 *data,
size_t data_length)
2566 dtls_alert(
"expect length of 94 bytes for server certificate message\n");
2572 dtls_alert(
"expect length of 91 bytes for certificate\n");
2578 dtls_alert(
"got an unexpected Subject public key format\n");
2583 memcpy(config->
keyx.ecdsa.other_pub_x, data,
2584 sizeof(config->
keyx.ecdsa.other_pub_x));
2585 data +=
sizeof(config->
keyx.ecdsa.other_pub_x);
2587 memcpy(config->
keyx.ecdsa.other_pub_y, data,
2588 sizeof(config->
keyx.ecdsa.other_pub_y));
2589 data +=
sizeof(config->
keyx.ecdsa.other_pub_y);
2592 config->
keyx.ecdsa.other_pub_x,
2593 config->
keyx.ecdsa.other_pub_y,
2594 sizeof(config->
keyx.ecdsa.other_pub_x));
2596 dtls_warn(
"The certificate was not accepted\n");
2606 uint8 *data,
size_t data_length)
2610 unsigned char *result_r;
2611 unsigned char *result_s;
2612 unsigned char *key_params;
2621 dtls_alert(
"the packet length does not match the expected\n");
2630 data +=
sizeof(
uint8);
2631 data_length -=
sizeof(
uint8);
2638 data_length -=
sizeof(
uint16);
2641 dtls_alert(
"expected 65 bytes long public point\n");
2644 data +=
sizeof(
uint8);
2645 data_length -=
sizeof(
uint8);
2648 dtls_alert(
"expected uncompressed public point\n");
2651 data +=
sizeof(
uint8);
2652 data_length -=
sizeof(
uint8);
2654 memcpy(config->
keyx.ecdsa.other_eph_pub_x, data,
sizeof(config->
keyx.ecdsa.other_eph_pub_y));
2655 data +=
sizeof(config->
keyx.ecdsa.other_eph_pub_y);
2656 data_length -=
sizeof(config->
keyx.ecdsa.other_eph_pub_y);
2658 memcpy(config->
keyx.ecdsa.other_eph_pub_y, data,
sizeof(config->
keyx.ecdsa.other_eph_pub_y));
2659 data +=
sizeof(config->
keyx.ecdsa.other_eph_pub_y);
2660 data_length -=
sizeof(config->
keyx.ecdsa.other_eph_pub_y);
2670 sizeof(config->
keyx.ecdsa.other_pub_x),
2675 result_r, result_s);
2689 uint8 *data,
size_t data_length)
2701 dtls_alert(
"the packet length does not match the expected\n");
2709 dtls_warn(
"the length of the server identity hint is worng\n");
2714 dtls_warn(
"please use a smaller server identity hint\n");
2719 config->
keyx.psk.id_length = len;
2720 memcpy(config->
keyx.psk.identity, data, len);
2728 uint8 *data,
size_t data_length)
2742 dtls_alert(
"the packet length does not match the expected\n");
2747 data +=
sizeof(
uint8);
2748 if (i + 1 > data_length) {
2749 dtls_alert(
"the cerfificate types are too long\n");
2754 for (; i > 0 ; i -=
sizeof(
uint8)) {
2758 data +=
sizeof(
uint8);
2762 dtls_alert(
"the request authentication algorithm is not supproted\n");
2768 if (i + 1 > data_length) {
2769 dtls_alert(
"the signature and hash algorithm list is too long\n");
2775 for (; i > 0 ; i -=
sizeof(
uint16)) {
2776 int current_hash_alg;
2777 int current_sig_alg;
2780 data +=
sizeof(
uint8);
2782 data +=
sizeof(
uint8);
2786 hash_alg = current_hash_alg;
2787 sig_alg = current_sig_alg;
2793 dtls_alert(
"no supported hash and signature algorithem\n");
2806 uint8 *data,
size_t data_length)
2822 res =
CALL(ctx, get_ecdsa_key, &peer->
session, &ecdsa_key);
2824 dtls_crit(
"no ecdsa certificate to send in certificate\n");
2831 dtls_debug(
"dtls_server_hello: cannot prepare Certificate record\n");
2841 dtls_debug(
"cannot send KeyExchange message\n");
2851 dtls_debug(
"dtls_server_hello: cannot prepare Certificate record\n");
2900 #define A_DATA_LEN 13
2930 clen =
dtls_decrypt(*cleartext, clen, *cleartext, nonce,
2938 printf(
"decrypt_verify(): found %i bytes cleartext\n", clen);
2994 uint8 *data,
size_t data_length) {
3011 dtls_debug(
"handle handshake packet of type: %s (%i)\n",
3026 dtls_warn(
"error in check_server_hello_verify_request err: %i\n", err);
3039 dtls_warn(
"error in check_server_hello err: %i\n", err);
3059 dtls_warn(
"error in check_server_certificate err: %i\n", err);
3092 dtls_warn(
"error in check_server_key_exchange err: %i\n", err);
3108 dtls_warn(
"error in check_server_hellodone err: %i\n", err);
3124 dtls_warn(
"error in check_certificate_request err: %i\n", err);
3139 dtls_warn(
"error in check_finished err: %i\n", err);
3157 dtls_warn(
"sending server Finished failed\n");
3183 dtls_warn(
"error in check_client_keyexchange err: %i\n", err);
3204 dtls_warn(
"error in check_client_certificate_verify err: %i\n", err);
3231 dtls_warn(
"error in dtls_verify_peer err: %i\n", err);
3236 dtls_debug(
"server hello verify was sent\n");
3284 dtls_warn(
"error updating security parameters\n");
3335 dtls_crit(
"unhandled message %d\n", data[0]);
3349 uint8 *data,
size_t data_length)
3355 dtls_warn(
"handshake message too short\n");
3360 dtls_debug(
"received handshake packet of type: %s (%i)\n",
3366 dtls_warn(
"If there is no peer only ClientHello is allowed\n");
3376 dtls_warn(
"ignore unexpected handshake message\n");
3382 dtls_warn(
"The message sequence number is too small, expected %i, got: %i\n",
3391 dtls_warn(
"the packet is too big to buffer for reoder\n");
3399 dtls_warn(
"a packet with this sequence number is already stored\n");
3407 dtls_warn(
"no space in reoder buffer\n");
3413 memcpy(n->
data, data, data_length);
3416 dtls_warn(
"cannot add packet to reoder buffer\n");
3419 dtls_info(
"Added packet for reordering\n");
3458 uint8 *record_header,
uint8 *data,
size_t data_length)
3470 dtls_warn(
"expected ChangeCipherSpec during handshake\n");
3474 if (data_length < 1 || data[0] != 1)
3497 uint8 *record_header,
uint8 *data,
size_t data_length) {
3500 if (data_length < 2)
3503 dtls_info(
"** Alert: level %d, description %d\n", data[0], data[1]);
3506 dtls_warn(
"got an alert for an unknown peer, we probably already removed it, ignore it\n");
3519 #ifndef WITH_CONTIKI
3525 PRINTF(
"removed peer [");
3565 if (err < -(1 << 8) && err > -(3 << 8)) {
3566 level = ((-err) & 0xff00) >> 8;
3567 desc = (-err) & 0xff;
3575 }
else if (err == -1) {
3593 uint8 *msg,
int msglen) {
3605 dtls_debug(
"dtls_handle_message: PEER NOT FOUND\n");
3608 dtls_debug(
"dtls_handle_message: FOUND PEER\n");
3611 while ((rlen =
is_record(msg,msglen))) {
3615 dtls_debug(
"got packet %d (%d bytes)\n", msg[0], rlen);
3618 if (data_length < 0) {
3630 state = peer->
state;
3653 err =
handle_ccs(ctx, peer, msg, data, data_length);
3655 dtls_warn(
"error while handling ChangeCipherSpec message\n");
3671 if (err < 0 || err == 1) {
3672 dtls_warn(
"received alert, peer has been invalidated\n");
3675 return err < 0 ?err:-1;
3685 uint16_t msg_epoch =
3697 if (expected_epoch != msg_epoch) {
3698 dtls_warn(
"Wrong epoch, expected %i, got: %i\n",
3699 expected_epoch, msg_epoch);
3704 err =
handle_handshake(ctx, peer, session, role, state, data, data_length);
3706 dtls_warn(
"error while handling handshake packet\n");
3720 dtls_warn(
"no peer available, send an alert\n");
3725 CALL(ctx, read, &peer->
session, data, data_length);
3728 dtls_info(
"dropped unknown message of type %d\n",msg[0]);
3743 #ifndef WITH_CONTIKI
3744 FILE *urandom = fopen(
"/dev/urandom",
"r");
3745 unsigned char buf[
sizeof(
unsigned long)];
3758 if (fread(buf, 1,
sizeof(buf), urandom) !=
sizeof(buf)) {
3780 process_start(&dtls_retransmit_process, (
char *)c);
3781 PROCESS_CONTEXT_BEGIN(&dtls_retransmit_process);
3783 etimer_set(&c->retransmit_timer, 0xFFFF);
3784 PROCESS_CONTEXT_END(&coap_retransmit_process);
3809 #ifndef WITH_CONTIKI
3835 dtls_debug(
"found peer, try to re-connect\n");
3882 }
else if (res == 0) {
3891 if (!context || !node)
3897 size_t len =
sizeof(sendbuf);
3899 unsigned char *data = node->
data;
3900 size_t length = node->
length;
3912 dtls_debug(
"** retransmit handshake packet of type: %s (%i)\n",
3921 dtls_warn(
"can not retransmit packet, err: %i\n", err);
3962 while (node && node->
t <= now) {
3976 PROCESS_THREAD(dtls_retransmit_process, ev, data)
3983 dtls_debug(
"Started DTLS retransmit process\r\n");
3987 if (ev == PROCESS_EVENT_TIMER) {
3988 if (etimer_expired(&the_dtls_context.retransmit_timer)) {
3990 node =
list_head(the_dtls_context.sendqueue);
3993 if (node && node->
t <= now) {
3995 node =
list_head(the_dtls_context.sendqueue);
4000 etimer_set(&the_dtls_context.retransmit_timer,
4001 node->
t <= now ? 1 : node->
t - now);
4003 etimer_set(&the_dtls_context.retransmit_timer, 0xFFFF);
#define CALL(Context, which,...)
static void copy_hs_hash(dtls_peer_t *peer, dtls_hash_ctx *hs_hash)
static int is_psk_supported(dtls_context_t *ctx)
unsigned char retransmit_cnt
int dtls_connect(dtls_context_t *ctx, const session_t *dst)
void dtls_handshake_free(dtls_handshake_parameters_t *handshake)
static int check_server_hello(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *data, size_t data_length)
int dtls_session_equals(const session_t *a, const session_t *b)
int dtls_handle_message(dtls_context_t *ctx, session_t *session, uint8 *msg, int msglen)
#define DTLS_HT_SERVER_HELLO
unsigned char cookie_secret[DTLS_COOKIE_SECRET_LENGTH]
static void clear_hs_hash(dtls_peer_t *peer)
#define DTLS_CT_HANDSHAKE
static int dtls_check_ecdsa_signature_elem(uint8 *data, size_t data_length, unsigned char **result_r, unsigned char **result_s)
static int dtls_update_parameters(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *data, size_t data_length)
#define dtls_kb_remote_iv(Param, Role)
static int check_server_hellodone(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *data, size_t data_length)
#define dtls_kb_local_iv(Param, Role)
void dtls_hmac_update(dtls_hmac_context_t *ctx, const unsigned char *input, size_t ilen)
int dtls_ecdh_pre_master_secret(unsigned char *priv_key, unsigned char *pub_key_x, unsigned char *pub_key_y, size_t key_size, unsigned char *result, size_t result_len)
#define LIST_STRUCT_INIT(struct_ptr, name)
static int dtls_alert_fatal_create(dtls_alert_t desc)
static int dtls_send(dtls_context_t *ctx, dtls_peer_t *peer, unsigned char type, uint8 *buf, size_t buflen)
const unsigned char * priv_key
int dtls_psk_pre_master_secret(unsigned char *key, size_t keylen, unsigned char *result, size_t result_len)
#define dtls_kb_server_mac_secret(Param, Role)
static void * list_pop(list_t list)
int dtls_encrypt(const unsigned char *src, size_t length, unsigned char *buf, unsigned char *nounce, unsigned char *key, size_t keylen, const unsigned char *aad, size_t la)
static int dtls_send_finished(dtls_context_t *ctx, dtls_peer_t *peer, const unsigned char *label, size_t labellen)
#define TLS_EXT_EC_POINT_FORMATS_UNCOMPRESSED
#define TLS_EXT_SERVER_CERTIFICATE_TYPE
#define DTLS_COOKIE_LENGTH
#define DTLS_CT_APPLICATION_DATA
static uint8 * dtls_add_ecdsa_signature_elem(uint8 *p, uint32_t *point_r, uint32_t *point_s)
static int check_certificate_request(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *data, size_t data_length)
#define HASH_ITER(hh, head, el, tmp)
netq_t * netq_next(netq_t *p)
struct dtls_handshake_parameters_t::@0::random_t random
static const unsigned char prf_label_client[]
dtls_peer_t * dtls_get_peer(const dtls_context_t *ctx, const session_t *session)
static int dtls_int_to_uint48(unsigned char *field, uint64_t value)
#define DTLS_SKEXECPSK_LENGTH_MAX
#define dtls_kb_size(Param, Role)
#define DTLS_HT_SERVER_KEY_EXCHANGE
static int dtls_send_server_key_exchange_psk(dtls_context_t *ctx, dtls_peer_t *peer, const unsigned char *psk_hint, size_t len)
void dtls_clock_init(void)
void dtls_ecdsa_create_sig_hash(const unsigned char *priv_key, size_t key_size, const unsigned char *sign_hash, size_t sign_hash_size, uint32_t point_r[9], uint32_t point_s[9])
static int verify_ext_ec_point_formats(uint8 *data, size_t data_length)
static int is_ecdsa_supported(dtls_context_t *ctx, int is_client)
#define dtls_get_fragment_length(H)
static int dtls_int_to_uint24(unsigned char *field, uint32_t value)
static int dtls_send_handshake_msg_hash(dtls_context_t *ctx, dtls_peer_t *peer, session_t *session, uint8 header_type, uint8 *data, size_t data_length, int add_hash)
static int handle_alert(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *record_header, uint8 *data, size_t data_length)
#define DTLS_CKXPSK_LENGTH_MIN
netq_t * netq_node_new(size_t size)
static uint8 * dtls_set_handshake_header(uint8 type, dtls_peer_t *peer, int length, int frag_offset, int frag_length, uint8 *buf)
#define TLS_EXT_ELLIPTIC_CURVES_SECP256R1
static int is_tls_ecdhe_ecdsa_with_aes_128_ccm_8(dtls_cipher_t cipher)
clock_time_t cookie_secret_age
#define DTLS_EVENT_CONNECT
static void dtls_stop_retransmission(dtls_context_t *context, dtls_peer_t *peer)
static void list_add(list_t list, void *item)
static dtls_security_parameters_t * dtls_security_params_epoch(dtls_peer_t *peer, uint16_t epoch)
#define DTLS_HANDSHAKE_HEADER(M)
static int dtls_send_alert(dtls_context_t *ctx, dtls_peer_t *peer, dtls_alert_level_t level, dtls_alert_t description)
#define TLS_EC_CURVE_TYPE_NAMED_CURVE
static int dtls_send_certificate_verify_ecdh(dtls_context_t *ctx, dtls_peer_t *peer, const dtls_ecdsa_key_t *key)
static int check_client_certificate_verify(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *data, size_t data_length)
#define dtls_kb_client_write_key(Param, Role)
void dtls_ecdsa_generate_key(unsigned char *priv_key, unsigned char *pub_key_x, unsigned char *pub_key_y, size_t key_size)
static void * list_item_next(void *item)
int dtls_ec_key_from_uint32_asn1(const uint32_t *key, size_t key_size, unsigned char *buf)
union dtls_handshake_parameters_t::@1 keyx
int dtls_ecdsa_verify_sig(const unsigned char *pub_key_x, const unsigned char *pub_key_y, size_t key_size, const unsigned char *client_random, size_t client_random_size, const unsigned char *server_random, size_t server_random_size, const unsigned char *keyx_params, size_t keyx_params_size, unsigned char *result_r, unsigned char *result_s)
#define TLS_EXT_SIG_HASH_ALGO_SHA256
unsigned int do_client_auth
union dtls_handshake_parameters_t::@0 tmp
#define dtls_kb_iv_size(Param, Role)
static int known_cipher(dtls_context_t *ctx, dtls_cipher_t code, int is_client)
#define DTLS_HMAC_DIGEST_SIZE
static int dtls_send_server_key_exchange_ecdh(dtls_context_t *ctx, dtls_peer_t *peer, const dtls_ecdsa_key_t *key)
static uint8_t dtls_uint8_to_int(const unsigned char *field)
static int dtls_verify_peer(dtls_context_t *ctx, dtls_peer_t *peer, session_t *session, uint8 *data, size_t data_length)
#define TLS_EXT_SIG_HASH_ALGO_ECDSA
#define dtls_kb_remote_write_key(Param, Role)
#define HASH_DEL_PEER(head, delptr)
static void dtls_security_params_free_other(dtls_peer_t *peer)
#define TLS_CLIENT_CERTIFICATE_TYPE_ECDSA_SIGN
static int dtls_alert_create(dtls_alert_level_t level, dtls_alert_t desc)
static int dtls_send_server_hello_done(dtls_context_t *ctx, dtls_peer_t *peer)
#define DTLS_HT_SERVER_HELLO_DONE
static int dtls_send_server_hello(dtls_context_t *ctx, dtls_peer_t *peer)
#define DTLS_PSK_MAX_CLIENT_IDENTITY_LEN
#define TLS_EXT_ELLIPTIC_CURVES
#define DTLS_CH_LENGTH_MAX
#define DTLS_SKEXECPSK_LENGTH_MIN
#define DTLS_COOKIE_LENGTH_MAX
static int check_server_key_exchange_psk(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *data, size_t data_length)
#define MAX_KEYBLOCK_LENGTH
static const unsigned char prf_label_finished[]
#define HASH_FIND_PEER(head, sess, out)
static int dtls_send_client_key_exchange(dtls_context_t *ctx, dtls_peer_t *peer)
#define TLS_EXT_ENCRYPT_THEN_MAC
static int dtls_check_tls_extension(dtls_peer_t *peer, uint8 *data, size_t data_length, int client_hello)
dtls_handshake_parameters_t * dtls_handshake_new()
netq_t * netq_head(list_t queue)
static int check_server_key_exchange_ecdsa(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *data, size_t data_length)
void dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr)
#define DTLS_RANDOM_LENGTH
void dtls_hmac_init(dtls_hmac_context_t *ctx, const unsigned char *key, size_t klen)
static void check_stack()
#define TLS_EXT_EC_POINT_FORMATS
static int dtls_send_hello_request(dtls_context_t *ctx, dtls_peer_t *peer)
dtls_handshake_parameters_t * handshake_params
static void dtls_hash_init(dtls_hash_t ctx)
const unsigned char * pub_key_y
#define dtls_kb_mac_secret_size(Param, Role)
static int check_client_keyexchange(dtls_context_t *ctx, dtls_handshake_parameters_t *handshake, uint8 *data, size_t length)
int dtls_close(dtls_context_t *ctx, const session_t *remote)
static int check_finished(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *data, size_t data_length)
static int verify_ext_eliptic_curves(uint8 *data, size_t data_length)
#define SKIP_VAR_FIELD(P, L, T)
static int calculate_key_block(dtls_context_t *ctx, dtls_handshake_parameters_t *handshake, dtls_peer_t *peer, session_t *session, dtls_peer_type role)
#define DTLS_DEFAULT_MAX_RETRANSMIT
#define PRF_LABEL_SIZE(Label)
static int handle_handshake(dtls_context_t *ctx, dtls_peer_t *peer, session_t *session, const dtls_peer_type role, const dtls_state_t state, uint8 *data, size_t data_length)
#define DTLS_HT_CLIENT_HELLO
#define HASH_ADD_PEER(head, sess, add)
dtls_compression_t compression
static uint8 * dtls_set_record_header(uint8 type, dtls_security_parameters_t *security, uint8 *buf)
static void dtls_retransmit(dtls_context_t *context, netq_t *node)
static const unsigned char prf_label_key[]
int dtls_connect_peer(dtls_context_t *ctx, dtls_peer_t *peer)
static int dtls_send_server_hello_msgs(dtls_context_t *ctx, dtls_peer_t *peer)
#define DTLS_HT_CERTIFICATE_VERIFY
static int dtls_int_to_uint16(unsigned char *field, uint16_t value)
static void dtls_hash_update(dtls_hash_t ctx, const unsigned char *input, size_t len)
#define DTLS_HASH_CTX_SIZE
High level DTLS API and visible structures.
#define DTLS_HT_CERTIFICATE_REQUEST
#define dtls_debug_dump(name, buf, length)
int dtls_hmac_finalize(dtls_hmac_context_t *ctx, unsigned char *result)
const unsigned char * pub_key_x
static uint16_t dtls_uint16_to_int(const unsigned char *field)
static const unsigned char prf_label_master[]
#define dtls_get_epoch(H)
static dtls_security_parameters_t * dtls_security_params(dtls_peer_t *peer)
void dtls_ecdsa_create_sig(const unsigned char *priv_key, size_t key_size, const unsigned char *client_random, size_t client_random_size, const unsigned char *server_random, size_t server_random_size, const unsigned char *keyx_params, size_t keyx_params_size, uint32_t point_r[9], uint32_t point_s[9])
#define dtls_kb_server_write_key(Param, Role)
int dtls_ecdsa_verify_sig_hash(const unsigned char *pub_key_x, const unsigned char *pub_key_y, size_t key_size, const unsigned char *sign_hash, size_t sign_hash_size, unsigned char *result_r, unsigned char *result_s)
netq_t * netq_pop_first(list_t queue)
#define dtls_kb_client_mac_secret(Param, Role)
static const unsigned char prf_label_server[]
int dtls_renegotiate(dtls_context_t *ctx, const session_t *dst)
dtls_compression_t compression
static void * list_head(list_t list)
#define DTLS_MASTER_SECRET_LENGTH
void dtls_free_peer(dtls_peer_t *peer)
uint8 key_block[MAX_KEYBLOCK_LENGTH]
static void dtls_security_params_switch(dtls_peer_t *peer)
void dtls_free_context(dtls_context_t *ctx)
static int dtls_int_to_uint32(unsigned char *field, uint32_t value)
static void update_hs_hash(dtls_peer_t *peer, uint8 *data, size_t length)
#define DTLS_CKXEC_LENGTH
static const unsigned char cert_asn1_header[]
dtls_context_t * dtls_new_context(void *app_data)
static void list_remove(list_t list, void *item)
uint8 master_secret[DTLS_MASTER_SECRET_LENGTH]
static unsigned int is_record(uint8 *msg, size_t msglen)
static dtls_context_t * malloc_context()
#define DTLS_EVENT_CONNECTED
void netq_remove(list_t queue, netq_t *p)
static int dtls_send_handshake_msg(dtls_context_t *ctx, dtls_peer_t *peer, uint8 header_type, uint8 *data, size_t data_length)
static int dtls_create_cookie(dtls_context_t *ctx, session_t *session, uint8 *msg, size_t msglen, uint8 *cookie, int *clen)
#define DTLS_RECORD_HEADER(M)
#define DTLS_HT_HELLO_REQUEST
#define DTLS_HT_HELLO_VERIFY_REQUEST
static void dtls_prng_init(unsigned short seed)
static int is_ecdsa_client_auth_supported(dtls_context_t *ctx)
#define DTLS_PSK_MAX_KEY_LEN
#define DTLS_CCM_BLOCKSIZE
static int check_server_hello_verify_request(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *data, size_t data_length)
static int check_server_certificate(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *data, size_t data_length)
static int dtls_send_certificate_ecdsa(dtls_context_t *ctx, dtls_peer_t *peer, const dtls_ecdsa_key_t *key)
static int is_tls_psk_with_aes_128_ccm_8(dtls_cipher_t cipher)
#define dtls_kb_client_iv(Param, Role)
static int dtls_prng(unsigned char *buf, size_t len)
void netq_node_free(netq_t *node)
static int equals(unsigned char *a, unsigned char *b, size_t len)
#define dtls_debug_hexdump(name, buf, length)
#define dtls_kb_key_size(Param, Role)
static size_t dtls_hash_finalize(unsigned char *buf, dtls_hash_t ctx)
static int verify_ext_cert_type(uint8 *data, size_t data_length)
#define DTLS_SKEXEC_LENGTH
static dtls_security_parameters_t * dtls_security_params_next(dtls_peer_t *peer)
static int dtls_int_to_uint8(unsigned char *field, uint8_t value)
static int dtls_send_multi(dtls_context_t *ctx, dtls_peer_t *peer, dtls_security_parameters_t *security, session_t *session, unsigned char type, uint8 *buf_array[], size_t buf_len_array[], size_t buf_array_len)
static int dtls_send_client_hello(dtls_context_t *ctx, dtls_peer_t *peer, uint8 cookie[], size_t cookie_length)
static void dtls_destroy_peer(dtls_context_t *ctx, dtls_peer_t *peer, int unlink)
static int dtls_send_server_certificate_request(dtls_context_t *ctx, dtls_peer_t *peer)
#define S_KEY_OFFSET(len_s)
static void dtls_debug_keyblock(dtls_security_parameters_t *config)
dtls_peer_t * dtls_new_peer(const session_t *session)
#define DTLS_EVENT_RENEGOTIATE
#define DTLS_HT_CERTIFICATE
int dtls_write(struct dtls_context_t *ctx, session_t *dst, uint8 *buf, size_t len)
#define TLS_CERT_TYPE_RAW_PUBLIC_KEY
static int dtls_get_cookie(uint8 *msg, size_t msglen, uint8 **cookie)
static int dtls_prepare_record(dtls_peer_t *peer, dtls_security_parameters_t *security, unsigned char type, uint8 *data_array[], size_t data_len_array[], size_t data_array_len, uint8 *sendbuf, size_t *rlen)
#define DTLS_HT_CLIENT_KEY_EXCHANGE
void dtls_check_retransmit(dtls_context_t *context, clock_time_t *next)
static int handle_handshake_msg(dtls_context_t *ctx, dtls_peer_t *peer, session_t *session, const dtls_peer_type role, const dtls_state_t state, uint8 *data, size_t data_length)
#define DTLS_COOKIE_SECRET_LENGTH
#define dtls_kb_server_iv(Param, Role)
static size_t finalize_hs_hash(dtls_peer_t *peer, uint8 *buf)
static void dtls_add_peer(dtls_context_t *ctx, dtls_peer_t *peer)
#define dtls_kb_local_write_key(Param, Role)
static char * dtls_handshake_type_to_name(int type)
size_t dtls_prf(const unsigned char *key, size_t keylen, const unsigned char *label, size_t labellen, const unsigned char *random1, size_t random1len, const unsigned char *random2, size_t random2len, unsigned char *buf, size_t buflen)
int netq_insert_node(list_t queue, netq_t *node)
#define DTLS_CT_CHANGE_CIPHER_SPEC
static uint32_t dtls_uint24_to_int(const unsigned char *field)
void dtls_ticks(dtls_tick_t *t)
static void free_context(dtls_context_t *context)
static uint8 compression_methods[]
static int dtls_send_ccs(dtls_context_t *ctx, dtls_peer_t *peer)
static int handle_ccs(dtls_context_t *ctx, dtls_peer_t *peer, uint8 *record_header, uint8 *data, size_t data_length)
static int dtls_alert_send_from_err(dtls_context_t *ctx, dtls_peer_t *peer, session_t *session, int err)
int dtls_decrypt(const unsigned char *src, size_t length, unsigned char *buf, unsigned char *nounce, unsigned char *key, size_t keylen, const unsigned char *aad, size_t la)
static int decrypt_verify(dtls_peer_t *peer, uint8 *packet, size_t length, uint8 **cleartext)
#define TLS_EXT_CLIENT_CERTIFICATE_TYPE