23#if COAP_OSCORE_SUPPORT
32#define E_AAD_BUF_LEN 512
33#define AAD_BUF_LEN (E_AAD_BUF_LEN + 32)
38#if COAP_CLIENT_SUPPORT
46 coap_log_warn(
"OSCORE: Recipient ID must be defined for a client\n");
54 if (id_context ==
NULL) {
65 osc_ctx = coap_oscore_init(session->
context, oscore_conf);
66 if (osc_ctx ==
NULL) {
70 session->oscore_encryption = 1;
160 oscore_conf, app_data, callback, ws_host);
179 app_data, callback, ws_host);
221 oscore_conf, app_data, callback, ws_host);
240 app_data, callback, ws_host);
252#if COAP_SERVER_SUPPORT
271 osc_ctx = coap_oscore_init(context, oscore_conf);
285 uint8_t option_value_buffer[15];
293 memset(&uri, 0,
sizeof(uri));
315 sizeof(option_value_buffer),
317 option_value_buffer))
350#if COAP_MAX_LOGGING_LEVEL < _COAP_LOG_OSCORE
370#if COAP_OSCORE_GROUP_SUPPORT
408 uint8_t pdu_code = pdu->
code;
411 uint8_t *ciphertext_buffer =
NULL;
412 size_t ciphertext_len = 0;
413 uint8_t aad_buffer[AAD_BUF_LEN];
414 uint8_t nonce_buffer[13];
420#if COAP_OSCORE_GROUP_SUPPORT
421 cose_sign1_t sign[1];
423 uint8_t group_flag = 0;
425 int doing_observe = 0;
426 uint32_t observe_value = 0;
429 uint8_t external_aad_buffer[E_AAD_BUF_LEN];
431 uint8_t oscore_option[255];
432 ssize_t oscore_option_len;
459 rcp_ctx = session->recipient_ctx;
471 if (association ==
NULL)
481#if COAP_OSCORE_GROUP_SUPPORT
482 cose_sign1_init(sign);
492 if (coap_request || doing_observe ||
494 uint8_t partial_iv_buffer[8];
495 size_t partial_iv_len;
498 sizeof(partial_iv_buffer),
500 if (snd_ctx->
seq == 0) {
502 partial_iv_buffer[0] =
'\000';
505 partial_iv.
s = partial_iv_buffer;
506 partial_iv.
length = partial_iv_len;
517 if (coap_request || doing_observe ||
528 nonce.
s = nonce_buffer;
566 if (oscore_option_len < 0) {
619 external_aad.
s = external_aad_buffer;
622#
if COAP_OSCORE_GROUP_SUPPORT
633 sizeof(external_aad_buffer));
634 if (external_aad.
length == 0)
646 assert(aad.
length < AAD_BUF_LEN);
660 if (plain_pdu ==
NULL)
774 dump_cose(cose,
"Pre encrypt");
777 if (ciphertext_buffer ==
NULL)
782 if ((
int)ciphertext_len <= 0) {
783 coap_log_warn(
"OSCORE: Encryption Failure, result code: %d \n",
784 (
int)ciphertext_len);
787 assert(ciphertext_len < OSCORE_CRYPTO_BUFFER_SIZE);
789#if COAP_OSCORE_GROUP_SUPPORT
792 size_t sign_size = snd_ctx->sender_cred->wire_sign_size;
793 uint8_t *sig_buffer =
NULL;
794 size_t sig_len = external_aad.
length + ciphertext_len + 30;
796 uint8_t *buffer = ciphertext_buffer + ciphertext_len;
798 assert(ciphertext_len + sign_size < OSCORE_CRYPTO_BUFFER_SIZE);
800 if (keystream ==
NULL)
803 if (sig_buffer ==
NULL)
805 oscore_populate_sign(sign,
807 snd_ctx->sender_cred,
808 snd_ctx->my_private_key);
809 sig_len = oscore_prepare_sig_structure(sig_buffer,
815 cose_sign1_set_signature(sign,
816 ciphertext_buffer + ciphertext_len,
818 cose_sign1_set_ciphertext(sign, sig_buffer, sig_len);
819 sign_size = cose_sign1_sign(sign);
821 if (sign_size == 0) {
827 ciphertext_len += sign_size;
838 for (
size_t i = 0; i < sign_size; i++) {
839 buffer[i] = buffer[i] ^ keystream[i];
853 if (!
coap_add_data(osc_pdu, ciphertext_len, ciphertext_buffer))
857 ciphertext_buffer =
NULL;
887 if (doing_observe && observe_value == 1) {
932 if (ciphertext_buffer)
943 const char *diagnostic,
946 int encrypt_oscore) {
949 int oscore_encryption = session->oscore_encryption;
950 unsigned char buf[4];
958 (diagnostic ? strlen(diagnostic) : 0));
964 }
else if (kid_context ==
NULL) {
971 coap_add_data(err_pdu, strlen(diagnostic), (
const uint8_t *)diagnostic);
972 session->oscore_encryption = encrypt_oscore;
974 if ((echo_data || kid_context) && encrypt_oscore) {
982 session->oscore_encryption = 0;
991 session->oscore_encryption = oscore_encryption;
1000 if (oscore_ctx ==
NULL) {
1022 uint64_t sliding_window;
1023 uint8_t initial_state;
1025} oscore_replay_state_t;
1043 coap_log_oscore(
"OSCORE: replay state restored after verification failure\n");
1076 const uint8_t *osc_value;
1080#if COAP_OSCORE_GROUP_SUPPORT
1081 uint8_t group_message = 0;
1082 cose_sign1_t sign[1];
1086 uint8_t aad_buffer[AAD_BUF_LEN];
1087 uint8_t nonce_buffer[13];
1091 int got_resp_piv = 0;
1092 int doing_resp_observe = 0;
1095 oscore_replay_state_t replay_saved = { 0, 0, 0, 0 };
1097 uint8_t *st_encrypt;
1103 uint8_t external_aad_buffer[E_AAD_BUF_LEN];
1106#if COAP_CLIENT_SUPPORT
1114 if (no_replay && !coap_request) {
1115 coap_log_warn(
"OSCORE: NO_REPLAY is only defined for requests\n");
1141#if COAP_OSCORE_GROUP_SUPPORT
1142 cose_sign1_init(sign);
1148 if (decrypt_pdu ==
NULL) {
1215 uint64_t incoming_seq;
1222 coap_log_warn(
"OSCORE: OSCORE Option cannot be decoded.\n");
1224 build_and_send_error_pdu(session,
1227 "Failed to decode COSE",
1246 session->oscore_r2 != 0 ? (uint8_t *)&session->oscore_r2 :
NULL,
1257 if (kid_context.
length > length)
1264 kid_context.
s = ptr;
1267 if (session->oscore_r2 != 0) {
1286 if (osc_ctx ==
NULL)
1307 build_and_send_error_pdu(session,
1310 "Security context not found",
1332 oscore_replay_save(&replay_saved, rcp_ctx);
1338 build_and_send_error_pdu(session,
1359 coap_log_warn(
"OSCORE: OSCORE Option cannot be decoded.\n");
1372#if COAP_CLIENT_SUPPORT
1383 if (kid_context.
length > length)
1390 kid_context.
s = ptr;
1421 coap_log_crit(
"OSCORE: Security Context association not found\n");
1429#if COAP_OSCORE_GROUP_SUPPORT
1486 external_aad.
s = external_aad_buffer;
1491#
if COAP_OSCORE_GROUP_SUPPORT
1497 external_aad_buffer,
1498 sizeof(external_aad_buffer));
1499 if (external_aad.
length == 0)
1508 sizeof(aad_buffer));
1511 assert(aad.
length < AAD_BUF_LEN);
1523 nonce.
s = nonce_buffer;
1531 association = no_replay ?
NULL :
1536 association->
nonce =
1568 decrypt_request_association = no_replay ?
NULL :
1586 oscore_replay_save(&replay_saved, rcp_ctx);
1595 coap_log_warn(
"OSCORE Replay protection, SEQ larger than SEQ_MAX.\n");
1607 nonce.
s = nonce_buffer;
1611#ifdef OSCORE_EXTRA_DEBUG
1612 dump_cose(cose,
"!req post set nonce");
1660#ifdef OSCORE_EXTRA_DEBUG
1661 dump_cose(cose,
"!req pre aad");
1663 external_aad.
s = external_aad_buffer;
1666#
if COAP_OSCORE_GROUP_SUPPORT
1676 external_aad_buffer,
1677 sizeof(external_aad_buffer));
1678 if (external_aad.
length == 0)
1687 sizeof(aad_buffer));
1690 assert(aad.
length < AAD_BUF_LEN);
1692#ifdef OSCORE_EXTRA_DEBUG
1693 dump_cose(cose,
"!req post set aad");
1708 st_encrypt = pdu->
data;
1710#if COAP_OSCORE_GROUP_SUPPORT
1711 if (group_message == 1)
1712 encrypt_len = encrypt_len - 64 ;
1714 if (encrypt_len <= 0) {
1726 if (encrypt_len <= tag_len) {
1731 build_and_send_error_pdu(session,
1734 "Decryption failed",
1748 if (plain_pdu ==
NULL) {
1769 plain_pdu->
used_size = encrypt_len - tag_len;
1771#if COAP_OSCORE_GROUP_SUPPORT
1772 if (group_message == 1) {
1774 size_t sign_size = 64 ;
1775 uint8_t *st_signature = st_encrypt + encrypt_len;
1776 uint8_t *sig_buffer =
NULL;
1777 size_t sig_len = external_aad.
length + encrypt_len + 30;
1782 oscore_populate_sign(sign, osc_ctx, rcp_ctx->rem_cred,
NULL);
1783 sig_len = oscore_prepare_sig_structure(sig_buffer,
1785 external_aad_buffer,
1789 assert(external_aad.
length + encrypt_len + 30 > sig_len);
1790 cose_sign1_set_signature(sign, st_signature, sign_size);
1791 cose_sign1_set_ciphertext(sign, sig_buffer, sig_len);
1802 for (
size_t i = 0; i < sign_size; i++) {
1803 st_signature[i] = st_signature[i] ^ keystream[i];
1807 sign_res = cose_sign1_verify(sign);
1809 if (sign_res == 0) {
1811 oscore_replay_restore(&replay_saved, rcp_ctx);
1814 build_and_send_error_pdu(session,
1817 "Decryption failed",
1831 dump_cose(cose,
"Pre decrypt");
1834 if (pltxt_size <= 0) {
1835 coap_log_warn(
"OSCORE: Decryption Failure, result code: %d \n",
1837 oscore_replay_restore(&replay_saved, rcp_ctx);
1841 build_and_send_error_pdu(session,
1844 "Decryption failed",
1861 session->
context->oscore_update_seq_num_cb !=
NULL) {
1870 assert((
size_t)pltxt_size < pdu->alloc_size + pdu->
max_hdr_size);
1887 coap_prng_lkd(&session->oscore_r2,
sizeof(session->oscore_r2));
1888 memcpy(kc->
s, &session->oscore_r2,
sizeof(session->oscore_r2));
1889 memcpy(&kc->
s[
sizeof(session->oscore_r2)],
1896 oscore_r2.
length =
sizeof(session->oscore_r2);
1897 oscore_r2.
s = (
const uint8_t *)&session->oscore_r2;
1899 build_and_send_error_pdu(session,
1906 decrypt_request_association =
NULL;
1909#if COAP_CLIENT_SUPPORT
1916 coap_log_warn(
"OSCORE Appendix B.2: Expected 4.01 response\n");
1954 if (!session->b_2_retransmit_token) {
1958 if (coap_retransmit_oscore_pdu(session, sent_pdu,
NULL) ==
1966#if COAP_SERVER_SUPPORT
1978 build_and_send_error_pdu(session,
1987 if (session->
context->oscore_update_seq_num_cb !=
NULL) {
2007 build_and_send_error_pdu(session,
2014 decrypt_request_association =
NULL;
2028 decrypt_pdu->
code = plain_pdu->
token[0];
2036 switch (opt_iter.
number) {
2040 if (!coap_request) {
2054 doing_resp_observe = 1;
2057 association = no_replay ?
NULL :
2078 if (!coap_request && !doing_resp_observe) {
2113 if (session->b_2_retransmit_token) {
2115 session->b_2_retransmit_token->s);
2117 session->b_2_retransmit_token =
NULL;
2120#if COAP_CLIENT_SUPPORT
2133 sent_pdu = lg_crcv->sent_pdu;
2141 if (coap_retransmit_oscore_pdu(session, sent_pdu, opt) !=
COAP_INVALID_MID) {
2142 session->doing_b_1_2 = 1;
2146 }
else if (!no_replay && session->doing_b_1_2) {
2151 coap_update_token(decrypt_pdu, lg_crcv->app_token->length, lg_crcv->app_token->s);
2154 session->doing_b_1_2 = 0;
2157 if (association && association->
is_observe == 0)
2165 if (decrypt_request_association) {
2167 decrypt_request_association =
NULL;
2169 if (association && association->
is_observe == 0)
2177 COAP_ENC_ASCII = 0x001,
2178 COAP_ENC_HEX = 0x002,
2179#if COAP_OSCORE_GROUP_SUPPORT
2180 COAP_ENC_PUB_RAW = 0x004,
2181 COAP_ENC_PUB_ASN1 = 0x008,
2182 COAP_ENC_PUB_FILE_PEM = 0x010,
2183 COAP_ENC_PUB_CCS = 0x020,
2184 COAP_ENC_PRI_RAW = 0x040,
2185 COAP_ENC_PRI_ASN1 = 0x080,
2186 COAP_ENC_PRI_FILE_PEM = 0x100,
2188 COAP_ENC_CONFIG = 0x0200,
2189 COAP_ENC_INTEGER = 0x400,
2190 COAP_ENC_TEXT = 0x800,
2191 COAP_ENC_BOOL = 0x1000,
2192 COAP_ENC_UNSIGNED64 = 0x2000,
2194} coap_oscore_coding_t;
2197#define TEXT_MAPPING(t, v) \
2198 { { sizeof(#t)-1, (const uint8_t *)#t }, v }
2200static struct coap_oscore_encoding_t {
2202 coap_oscore_coding_t encoding;
2203} oscore_encoding[] = {
2204 TEXT_MAPPING(ascii, COAP_ENC_ASCII),
2205 TEXT_MAPPING(hex, COAP_ENC_HEX),
2206#if COAP_OSCORE_GROUP_SUPPORT
2207 TEXT_MAPPING(pub_raw, COAP_ENC_PUB_RAW),
2208 TEXT_MAPPING(pub_asn1, COAP_ENC_PUB_ASN1),
2209 TEXT_MAPPING(pub_file_pem, COAP_ENC_PUB_FILE_PEM),
2210 TEXT_MAPPING(pub_ccs, COAP_ENC_PUB_CCS),
2211 TEXT_MAPPING(pri_raw, COAP_ENC_PRI_RAW),
2212 TEXT_MAPPING(pri_asn1, COAP_ENC_PRI_ASN1),
2213 TEXT_MAPPING(pri_file_pem, COAP_ENC_PRI_FILE_PEM),
2215 TEXT_MAPPING(config, COAP_ENC_CONFIG),
2216 TEXT_MAPPING(integer, COAP_ENC_INTEGER),
2217 TEXT_MAPPING(unsigned64, COAP_ENC_UNSIGNED64),
2218 TEXT_MAPPING(text, COAP_ENC_TEXT),
2219 TEXT_MAPPING(
bool, COAP_ENC_BOOL),
2220 {{0,
NULL}, COAP_ENC_LAST}
2224 coap_oscore_coding_t encoding;
2225 const char *encoding_name;
2228 uint64_t value_int64;
2230#if COAP_OSCORE_GROUP_SUPPORT
2243hex_to_char(
char c, uint8_t *value) {
2244 if (
'a' <= c && c <=
'f') {
2245 *value = c -
'a' + 10;
2246 }
else if (
'A' <= c && c <=
'F') {
2247 *value = c -
'A' + 10;
2248 }
else if (
'0' <= c && c <=
'9') {
2259parse_hex_bin(
const char *begin,
const char *end) {
2267 for (i = 0; (i < (size_t)(end - begin)); i++) {
2268 while ((i < (
size_t)(end - begin)) &&
2269 (begin[i] ==
'\r' || begin[i] ==
'\n' || begin[i] ==
' ')) {
2272 if (i == (
size_t)(end - begin))
2274 if (isxdigit((uint8_t)begin[i])) {
2277 if (!hex_to_char(begin[i], &value)) {
2280 binary->
s[o] = value << 4;
2282 while ((i < (
size_t)(end - begin)) &&
2283 (begin[i] ==
'\r' || begin[i] ==
'\n' || begin[i] ==
' ')) {
2286 if (i == (
size_t)(end - begin))
2288 if (!hex_to_char(begin[i], &value)) {
2291 binary->
s[o++] += value;
2296 if (i != (
size_t)(end - begin))
2305#if COAP_OSCORE_GROUP_SUPPORT
2315 const uint8_t *data = binary->
s;
2316 size_t data_len = binary->
length;
2334 if (map_count_m > data_len)
2336 for (m = 0; m < map_count_m; m++) {
2349 if (elem_size > data_len)
2352 data_len -= elem_size;
2362 if (elem_size > data_len)
2371 if (elem_size > data_len)
2374 data_len -= elem_size;
2382 if (map_count_n > data_len)
2384 for (n = 0; n < map_count_n; n++) {
2395 if (map_count_o > data_len)
2397 for (o = 0; o < map_count_o; o++) {
2406 local->cred_kty = oo;
2412 local->cred_alg = oo;
2418 local->cred_crv = oo;
2425 if (elem_size > data_len)
2434 data_len -= elem_size;
2437 coap_log_warn(
"coap_crypto_read_ccs_public_cred: COSE_Key %" PRIi64
" not supported\n", oo);
2445 coap_log_warn(
"coap_crypto_read_ccs_public_cred: CWT Confirmation Claim %" PRIi64
2446 " not supported\n", nn);
2454 static const uint8_t spki_ed25519[] = {
2455 0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65,
2456 0x70, 0x03, 0x21, 0x00
2464 memcpy(der->
s, spki_ed25519,
sizeof(spki_ed25519));
2465 memcpy(der->
s +
sizeof(spki_ed25519), local->
pub_raw->
s,
2477 cred->cred_type = OSCORE_AUTH_CRED_CCS;
2478 cred->cred_kty = local->cred_kty;
2479 cred->cred_crv = local->cred_crv;
2480 cred->cred_alg = local->cred_alg;
2486 coap_log_warn(
"coap_crypto_read_ccs_public_cred: Not all of kty, crv and public_key defined\n");
2489 coap_log_warn(
"coap_crypto_read_ccs_public_cred: CBOR Web Token (CWT) Claims %" PRIi64
2490 " not supported\n", mm);
2513get_split_entry(
const char **start,
2516 oscore_value_t *value,
2518 const char *begin = *start;
2519 const char *keep_start = *start;
2526#if COAP_OSCORE_GROUP_SUPPORT
2537 kend = end = memchr(begin,
'\n', size);
2542 if ((tend = memchr(begin,
'"', end - begin))) {
2544 if (!memchr(tend + 1,
'"', end - tend -1)) {
2546 kend = end = memchr(end,
'"', size - (end - begin));
2549 kend = end = memchr(kend,
'\n', size - (kend - begin));
2557 if (end > begin && end[-1] ==
'\r')
2560 if (begin[0] ==
'#' || (end - begin) == 0) {
2562 size -= kend - begin + 1;
2564 keep_start = *start;
2569 split = memchr(begin,
',', end - begin);
2573 keyword->
s = (
const uint8_t *)begin;
2574 keyword->
length = split - begin;
2577 if ((end - begin) == 0)
2580 split = memchr(begin,
',', end - begin);
2584 for (i = 0; oscore_encoding[i].name.s; i++) {
2588 value->encoding = oscore_encoding[i].encoding;
2589 value->encoding_name = (
const char *)oscore_encoding[i].name.s;
2593 if (oscore_encoding[i].name.s ==
NULL)
2597 if ((end - begin) == 0)
2600 if (value->encoding == COAP_ENC_CONFIG && begin[0] ==
'\'') {
2601 split = memchr(&begin[1],
'\'', size - (begin - keep_start) - 1);
2604 end = memchr(split,
'\n', size - (split - keep_start));
2611 if (begin[0] ==
'"') {
2612 split = memchr(&begin[1],
'"', end - split - 1);
2619 switch (value->encoding) {
2620 case COAP_ENC_CONFIG:
2621 case COAP_ENC_ASCII:
2622 value->u.value_bin =
2624 if (value->u.value_bin ==
NULL)
2629 value->u.value_bin = parse_hex_bin(begin, end);
2630 if (value->u.value_bin ==
NULL)
2633#if COAP_OSCORE_GROUP_SUPPORT
2634 case COAP_ENC_PUB_FILE_PEM:
2637 if (file_name ==
NULL)
2639 memcpy(file_name->
s, begin, end - begin);
2640 if (coap_crypto_read_pem_public_cred((
const char *)file_name->
s, &cred) ==
2644 value->u.value_cred = cred;
2647 case COAP_ENC_PRI_FILE_PEM:
2650 if (file_name ==
NULL)
2652 memcpy(file_name->
s, begin, end - begin);
2653 if (coap_crypto_read_pem_private_key((
const char *)file_name->
s,
2657 value->u.value_pri = pri_key;
2660 case COAP_ENC_PUB_ASN1:
2662 binary = parse_hex_bin(begin, end);
2666 if (coap_crypto_read_asn1_public_cred(binary, &cred) == 0) {
2669 value->u.value_cred = cred;
2671 case COAP_ENC_PRI_ASN1:
2673 binary = parse_hex_bin(begin, end);
2677 if (coap_crypto_read_asn1_private_key(binary, &pri_key) == 0) {
2680 value->u.value_pri = pri_key;
2682 case COAP_ENC_PUB_RAW:
2684 binary = parse_hex_bin(begin, end);
2688 if (coap_crypto_read_raw_public_cred(sign_curve,
2693 value->u.value_cred = cred;
2695 case COAP_ENC_PRI_RAW:
2696 if (sign_curve == 0)
2699 binary = parse_hex_bin(begin, end);
2702 asn1 = coap_asn1_pri_key(sign_curve, binary);
2708 if (coap_crypto_read_asn1_private_key(binary, &pri_key) == 0) {
2711 value->u.value_pri = pri_key;
2713 case COAP_ENC_PUB_CCS:
2715 binary = parse_hex_bin(begin, end);
2719 if (coap_crypto_read_ccs_public_cred(binary,
2723 value->u.value_cred = cred;
2726 case COAP_ENC_INTEGER:
2727 value->u.value_int = atoi(begin);
2729 case COAP_ENC_UNSIGNED64: {
2730 value->u.value_int64 = strtoull(begin,
NULL, 10);
2734 value->u.value_str.s = (
const uint8_t *)begin;
2735 value->u.value_str.length = end - begin;
2738 len = (size_t)(end - begin);
2739 if (len == 4 && memcmp(
"true", begin, len) == 0)
2740 value->u.value_int = 1;
2741 else if (len == 5 && memcmp(
"false", begin, len) == 0)
2742 value->u.value_int = 0;
2753 coap_log_warn(
"oscore_conf: Unrecognized configuration entry '%.*s'\n",
2758#if COAP_OSCORE_GROUP_SUPPORT
2761 coap_log_warn(
"oscore_conf: Bad configuration file_pem entry '%.*s'\n",
2768 coap_log_warn(
"oscore_conf: RAW private key must be defined after public key\n");
2774#define CONFIG_ENTRY(n, e, t) \
2775 { { sizeof(#n)-1, (const uint8_t *)#n }, e, \
2776 offsetof(coap_oscore_conf_t, n), t }
2778#undef CONFIG_SND_ENTRY
2779#define CONFIG_SND_ENTRY(n, e, t) \
2780 { { sizeof(#n)-1, (const uint8_t *)#n }, e, \
2781 offsetof(coap_oscore_snd_conf_t, n), t }
2783#undef CONFIG_RCP_ENTRY
2784#define CONFIG_RCP_ENTRY(n, e, t) \
2785 { { sizeof(#n)-1, (const uint8_t *)#n }, e, \
2786 offsetof(coap_oscore_rcp_conf_t, n), t }
2788#undef CONFIG_DUMMY_ENTRY
2789#define CONFIG_DUMMY_ENTRY(n, e, t) \
2790 { { sizeof(#n)-1, (const uint8_t *)#n }, e, 0, t }
2792typedef struct oscore_text_mapping_t {
2795} oscore_text_mapping_t;
2798static oscore_text_mapping_t text_aead_alg[] = {
2804static oscore_text_mapping_t text_hkdf_alg[] = {
2809#if COAP_OSCORE_GROUP_SUPPORT
2810static oscore_text_mapping_t text_alg_signature[] = {
2815static oscore_text_mapping_t text_sign_curve[] = {
2821static oscore_text_mapping_t text_alg_pairwise[] = {
2837typedef struct oscore_config_t {
2839 coap_oscore_coding_t encoding;
2841 oscore_text_mapping_t *text_mapping;
2844static oscore_config_t oscore_config[] = {
2845 CONFIG_ENTRY(aead_alg, COAP_ENC_INTEGER | COAP_ENC_TEXT, text_aead_alg),
2846 CONFIG_ENTRY(hkdf_alg, COAP_ENC_INTEGER | COAP_ENC_TEXT, text_hkdf_alg),
2847 CONFIG_ENTRY(master_secret, COAP_ENC_HEX | COAP_ENC_ASCII,
NULL),
2848 CONFIG_ENTRY(master_salt, COAP_ENC_HEX | COAP_ENC_ASCII,
NULL),
2849 CONFIG_ENTRY(id_context, COAP_ENC_HEX | COAP_ENC_ASCII,
NULL),
2851 CONFIG_DUMMY_ENTRY(sender_id, COAP_ENC_HEX | COAP_ENC_ASCII,
NULL),
2853 CONFIG_DUMMY_ENTRY(recipient_id, COAP_ENC_HEX | COAP_ENC_ASCII,
NULL),
2855 CONFIG_ENTRY(replay_window, COAP_ENC_INTEGER,
NULL),
2856 CONFIG_ENTRY(ssn_freq, COAP_ENC_INTEGER,
NULL),
2857 CONFIG_ENTRY(rfc8613_b_1_2, COAP_ENC_BOOL,
NULL),
2858 CONFIG_ENTRY(rfc8613_b_2, COAP_ENC_BOOL,
NULL),
2859 CONFIG_ENTRY(break_sender_key, COAP_ENC_BOOL,
NULL),
2860 CONFIG_ENTRY(break_recipient_key, COAP_ENC_BOOL,
NULL),
2861 CONFIG_DUMMY_ENTRY(complex_sender, COAP_ENC_CONFIG,
NULL),
2862 CONFIG_DUMMY_ENTRY(complex_recipient, COAP_ENC_CONFIG,
NULL),
2863#if COAP_OSCORE_GROUP_SUPPORT
2866 CONFIG_DUMMY_ENTRY(complex_sender, COAP_ENC_CONFIG,
NULL),
2867 CONFIG_DUMMY_ENTRY(complex_recipient, COAP_ENC_CONFIG,
NULL),
2868 CONFIG_ENTRY(cred_fmt, COAP_ENC_INTEGER,
NULL),
2870 CONFIG_ENTRY(alg_group_enc, COAP_ENC_INTEGER | COAP_ENC_TEXT, text_aead_alg),
2871 CONFIG_ENTRY(alg_signature, COAP_ENC_INTEGER | COAP_ENC_TEXT, text_alg_signature),
2872 CONFIG_ENTRY(sign_curve, COAP_ENC_INTEGER | COAP_ENC_TEXT, text_sign_curve),
2875 CONFIG_ENTRY(ecdh_alg, COAP_ENC_INTEGER | COAP_ENC_TEXT, text_sign_curve),
2878 CONFIG_ENTRY(alg_pairwise_key_agreement, COAP_ENC_INTEGER | COAP_ENC_TEXT, text_alg_pairwise),
2880 gm_cred, COAP_ENC_PUB_ASN1 | COAP_ENC_PUB_FILE_PEM | COAP_ENC_PUB_CCS,
NULL),
2885static oscore_config_t oscore_snd_config[] = {
2886 CONFIG_SND_ENTRY(sender_id, COAP_ENC_HEX | COAP_ENC_ASCII,
NULL),
2887#if COAP_OSCORE_GROUP_SUPPORT
2888 CONFIG_SND_ENTRY(group_mode, COAP_ENC_BOOL,
NULL),
2889 CONFIG_SND_ENTRY(pairwise_mode, COAP_ENC_BOOL,
NULL),
2891 gs_public_cred, COAP_ENC_PUB_ASN1 | COAP_ENC_PUB_FILE_PEM | COAP_ENC_PUB_CCS,
NULL),
2893 gs_private_key, COAP_ENC_PRI_ASN1 | COAP_ENC_PRI_FILE_PEM | COAP_ENC_PRI_RAW,
NULL),
2897static oscore_config_t oscore_rcp_config[] = {
2898 CONFIG_RCP_ENTRY(recipient_id, COAP_ENC_HEX | COAP_ENC_ASCII,
NULL),
2899 CONFIG_RCP_ENTRY(silent_server, COAP_ENC_BOOL,
NULL),
2900 CONFIG_DUMMY_ENTRY(last_seq, COAP_ENC_UNSIGNED64,
NULL),
2901 CONFIG_DUMMY_ENTRY(sliding_window, COAP_ENC_UNSIGNED64,
NULL),
2902#if COAP_OSCORE_GROUP_SUPPORT
2903 CONFIG_RCP_ENTRY(group_mode, COAP_ENC_BOOL,
NULL),
2904 CONFIG_RCP_ENTRY(pairwise_mode, COAP_ENC_BOOL,
NULL),
2905 CONFIG_RCP_ENTRY(silent_server, COAP_ENC_BOOL,
NULL),
2907 gr_public_cred, COAP_ENC_PUB_ASN1 | COAP_ENC_PUB_FILE_PEM | COAP_ENC_PUB_CCS,
NULL),
2913 if (snd_conf ==
NULL)
2917#if COAP_OSCORE_GROUP_SUPPORT
2918 coap_crypto_delete_public_cred(snd_conf->gs_public_cred);
2919 coap_crypto_delete_private_key(snd_conf->gs_private_key);
2927 if (rcp_conf ==
NULL)
2931#if COAP_OSCORE_GROUP_SUPPORT
2932 coap_crypto_delete_public_cred(rcp_conf->gr_public_cred);
2941 if (oscore_conf ==
NULL)
2954 rcp_conf = rcp_next;
2956#if COAP_OSCORE_GROUP_SUPPORT
2957 coap_crypto_delete_public_cred(oscore_conf->gm_cred);
2965cleanup_value(oscore_value_t *value) {
2966 switch (value->encoding) {
2967 case COAP_ENC_ASCII:
2969 case COAP_ENC_CONFIG:
2972#if COAP_OSCORE_GROUP_SUPPORT
2973 case COAP_ENC_PUB_RAW:
2974 case COAP_ENC_PUB_ASN1:
2975 case COAP_ENC_PUB_FILE_PEM:
2976 case COAP_ENC_PUB_CCS:
2977 coap_crypto_delete_public_cred(value->u.value_cred);
2979 case COAP_ENC_PRI_RAW:
2980 case COAP_ENC_PRI_ASN1:
2981 case COAP_ENC_PRI_FILE_PEM:
2982 coap_crypto_delete_private_key(value->u.value_pri);
2985 case COAP_ENC_INTEGER:
2988 case COAP_ENC_UNSIGNED64:
2997 const char *start = (
const char *)conf_mem.
s;
2998 const char *end = start + conf_mem.length;
3000 oscore_value_t value;
3004 if (snd_conf ==
NULL)
3008 memset(&value, 0,
sizeof(value));
3010#if COAP_OSCORE_GROUP_SUPPORT
3011 while (end > start &&
3012 get_split_entry(&start, end - start, &keyword, &value,
3013 snd_conf->gs_public_cred ? snd_conf->gs_public_cred->sign_curve : 0) > 0)
3015 while (end > start &&
3016 get_split_entry(&start, end - start, &keyword, &value, 0) > 0)
3022 for (i = 0; i <
sizeof(oscore_snd_config) /
sizeof(oscore_snd_config[0]); i++) {
3024 value.encoding & oscore_snd_config[i].encoding) {
3027 switch (value.encoding) {
3029 case COAP_ENC_ASCII:
3030 memcpy(&unused_check,
3031 &(((
char *)snd_conf)[oscore_snd_config[i].offset]),
3032 sizeof(unused_check));
3033 if (unused_check !=
NULL) {
3034 coap_log_warn(
"oscore_snd_conf: Keyword '%.*s' duplicated\n",
3036 (
const char *)keyword.
s);
3040 memcpy(&(((
char *)snd_conf)[oscore_snd_config[i].offset]),
3042 sizeof(value.u.value_bin));
3044#if COAP_OSCORE_GROUP_SUPPORT
3045 case COAP_ENC_PUB_RAW:
3046 case COAP_ENC_PUB_ASN1:
3047 case COAP_ENC_PUB_FILE_PEM:
3048 case COAP_ENC_PUB_CCS:
3049 memcpy(&unused_check,
3050 &(((
char *)snd_conf)[oscore_snd_config[i].offset]),
3051 sizeof(unused_check));
3052 if (unused_check !=
NULL) {
3053 coap_log_warn(
"oscore_snd_conf: Keyword '%.*s' duplicated\n",
3055 (
const char *)keyword.
s);
3056 cleanup_value(&value);
3059 memcpy(&(((
char *)snd_conf)[oscore_snd_config[i].offset]),
3060 &value.u.value_cred,
3061 sizeof(value.u.value_cred));
3063 case COAP_ENC_PRI_RAW:
3064 case COAP_ENC_PRI_ASN1:
3065 case COAP_ENC_PRI_FILE_PEM:
3066 memcpy(&unused_check,
3067 &(((
char *)snd_conf)[oscore_snd_config[i].offset]),
3068 sizeof(unused_check));
3069 if (unused_check !=
NULL) {
3070 coap_log_warn(
"oscore_snd_conf: Keyword '%.*s' duplicated\n",
3072 (
const char *)keyword.
s);
3073 cleanup_value(&value);
3076 memcpy(&(((
char *)snd_conf)[oscore_snd_config[i].offset]),
3078 sizeof(value.u.value_pri));
3081 case COAP_ENC_INTEGER:
3083 memcpy(&(((
char *)snd_conf)[oscore_snd_config[i].offset]),
3085 sizeof(value.u.value_int));
3088 for (j = 0; oscore_snd_config[i].text_mapping[j].text.s !=
NULL; j++) {
3089 if (memcmp(value.u.value_str.s,
3090 oscore_snd_config[i].text_mapping[j].text.s,
3091 value.u.value_str.length) == 0) {
3092 memcpy(&(((
char *)snd_conf)[oscore_snd_config[i].offset]),
3093 &oscore_snd_config[i].text_mapping[j].value,
3094 sizeof(oscore_snd_config[i].text_mapping[j].value));
3098 if (oscore_snd_config[i].text_mapping[j].text.s ==
NULL) {
3099 coap_log_warn(
"oscore_snd_conf: Keyword '%.*s': value '%.*s' unknown\n",
3101 (
const char *)keyword.
s,
3102 (
int)value.u.value_str.length,
3103 (
const char *)value.u.value_str.s);
3107 case COAP_ENC_CONFIG:
3108 case COAP_ENC_UNSIGNED64:
3117 if (i ==
sizeof(oscore_snd_config) /
sizeof(oscore_snd_config[0])) {
3118 coap_log_warn(
"oscore_snd_conf: Keyword '%.*s', type '%s' unknown\n",
3120 (
const char *)keyword.
s,
3121 value.encoding_name);
3122 cleanup_value(&value);
3126 if (!snd_conf->sender_id) {
3130 if (snd_conf->sender_id->length > 7) {
3131 coap_log_warn(
"oscore_snd_conf: Maximum size of sender_id is 7 bytes\n");
3134#if COAP_OSCORE_GROUP_SUPPORT
3135 if ((snd_conf->group_mode || snd_conf->pairwise_mode) &&
3136 (!snd_conf->gs_public_cred || !snd_conf->gs_private_key)) {
3138 " gs_public_cred and gs_private_key not defined\n");
3151 const char *start = (
const char *)conf_mem.
s;
3152 const char *end = start + conf_mem.length;
3154 oscore_value_t value;
3158 if (rcp_conf ==
NULL)
3162 memset(&value, 0,
sizeof(value));
3163#if COAP_OSCORE_GROUP_SUPPORT
3168#if COAP_OSCORE_GROUP_SUPPORT
3169 while (end > start &&
3170 get_split_entry(&start, end - start, &keyword, &value, rcp_conf->sign_curve) > 0)
3172 while (end > start &&
3173 get_split_entry(&start, end - start, &keyword, &value, 0) > 0)
3179 for (i = 0; i <
sizeof(oscore_rcp_config) /
sizeof(oscore_rcp_config[0]); i++) {
3181 value.encoding & oscore_rcp_config[i].encoding) {
3183 rcp_conf->
last_seq = value.u.value_int64;
3191 switch (value.encoding) {
3193 case COAP_ENC_ASCII:
3194 memcpy(&unused_check,
3195 &(((
char *)rcp_conf)[oscore_rcp_config[i].offset]),
3196 sizeof(unused_check));
3197 if (unused_check !=
NULL) {
3198 coap_log_warn(
"oscore_rcp_conf: Keyword '%.*s' duplicated\n",
3200 (
const char *)keyword.
s);
3204 memcpy(&(((
char *)rcp_conf)[oscore_rcp_config[i].offset]),
3206 sizeof(value.u.value_bin));
3208#if COAP_OSCORE_GROUP_SUPPORT
3209 case COAP_ENC_PUB_RAW:
3210 case COAP_ENC_PUB_ASN1:
3211 case COAP_ENC_PUB_FILE_PEM:
3212 case COAP_ENC_PUB_CCS:
3213 memcpy(&unused_check,
3214 &(((
char *)rcp_conf)[oscore_rcp_config[i].offset]),
3215 sizeof(unused_check));
3216 if (unused_check !=
NULL) {
3217 coap_log_warn(
"oscore_rcp_conf: Keyword '%.*s' duplicated\n",
3219 (
const char *)keyword.
s);
3220 cleanup_value(&value);
3223 memcpy(&(((
char *)rcp_conf)[oscore_rcp_config[i].offset]),
3224 &value.u.value_cred,
3225 sizeof(value.u.value_cred));
3227 case COAP_ENC_PRI_RAW:
3228 case COAP_ENC_PRI_ASN1:
3229 case COAP_ENC_PRI_FILE_PEM:
3230 memcpy(&unused_check,
3231 &(((
char *)rcp_conf)[oscore_rcp_config[i].offset]),
3232 sizeof(unused_check));
3233 if (unused_check !=
NULL) {
3234 coap_log_warn(
"oscore_rcp_conf: Keyword '%.*s' duplicated\n",
3236 (
const char *)keyword.
s);
3237 cleanup_value(&value);
3240 memcpy(&(((
char *)rcp_conf)[oscore_rcp_config[i].offset]),
3242 sizeof(value.u.value_pri));
3245 case COAP_ENC_INTEGER:
3247 memcpy(&(((
char *)rcp_conf)[oscore_rcp_config[i].offset]),
3249 sizeof(value.u.value_int));
3252 for (j = 0; oscore_rcp_config[i].text_mapping[j].text.s !=
NULL; j++) {
3253 if (memcmp(value.u.value_str.s,
3254 oscore_rcp_config[i].text_mapping[j].text.s,
3255 value.u.value_str.length) == 0) {
3256 memcpy(&(((
char *)rcp_conf)[oscore_rcp_config[i].offset]),
3257 &oscore_rcp_config[i].text_mapping[j].value,
3258 sizeof(oscore_rcp_config[i].text_mapping[j].value));
3262 if (oscore_rcp_config[i].text_mapping[j].text.s ==
NULL) {
3263 coap_log_warn(
"oscore_rcp_conf: Keyword '%.*s': value '%.*s' unknown\n",
3265 (
const char *)keyword.
s,
3266 (
int)value.u.value_str.length,
3267 (
const char *)value.u.value_str.s);
3271 case COAP_ENC_CONFIG:
3272 case COAP_ENC_UNSIGNED64:
3282 if (i ==
sizeof(oscore_rcp_config) /
sizeof(oscore_rcp_config[0])) {
3283 coap_log_warn(
"oscore_rcp_conf: Keyword '%.*s', type '%s' unknown\n",
3285 (
const char *)keyword.
s,
3286 value.encoding_name);
3287 cleanup_value(&value);
3291 if (!rcp_conf->recipient_id) {
3292 coap_log_warn(
"oscore_rcp_conf: recipient_id not defined\n");
3295 if (rcp_conf->recipient_id->length > 7) {
3296 coap_log_warn(
"oscore_rcp_conf: Maximum size of recipient_id is 7 bytes\n");
3299#if COAP_OSCORE_GROUP_SUPPORT
3300 if ((rcp_conf->group_mode || rcp_conf->pairwise_mode) &&
3301 !rcp_conf->gr_public_cred) {
3302 coap_log_warn(
"oscore_rcp_conf: group: gr_public_cred not defined\n");
3315 const char *start = (
const char *)conf_mem.
s;
3316 const char *end = start + conf_mem.length;
3318 oscore_value_t value;
3323 if (oscore_conf ==
NULL)
3327 memset(&value, 0,
sizeof(value));
3336#if COAP_OSCORE_GROUP_SUPPORT
3347#if COAP_OSCORE_GROUP_SUPPORT
3348 while (end > start &&
3349 (split_ok = get_split_entry(&start, end - start, &keyword, &value, oscore_conf->sign_curve)) > 0)
3351 while (end > start &&
3352 (split_ok = get_split_entry(&start, end - start, &keyword, &value, 0)) > 0)
3358 for (i = 0; i <
sizeof(oscore_config) /
sizeof(oscore_config[0]); i++) {
3360 value.encoding & oscore_config[i].encoding) {
3362 if (value.u.value_bin->length > 7) {
3363 coap_log_warn(
"oscore_conf: Maximum size of sender_id is 7 bytes\n");
3364 goto error_free_value;
3366 if (oscore_conf->
sender) {
3368 goto error_free_value;
3371 if (!oscore_conf->
sender)
3372 goto error_free_value;
3379 if (value.u.value_bin->length > 7) {
3380 coap_log_warn(
"oscore_conf: Maximum size of recipient_id is 7 bytes\n");
3381 goto error_free_value;
3386 goto error_free_value;
3395 switch (value.encoding) {
3396 case COAP_ENC_CONFIG:
3397 if (keyword.
length ==
sizeof(
"complex_sender") - 1 &&
3398 memcmp(keyword.
s,
"complex_sender", keyword.
length) == 0) {
3400 coap_parse_oscore_snd_conf_mem(*value.u.value_bin);
3405 (
const char *)keyword.
s);
3406 goto error_free_value;
3408#if COAP_OSCORE_GROUP_SUPPORT
3409 if (snd_conf->group_mode || snd_conf->pairwise_mode) {
3410 if (oscore_conf->cred_type != 0 &&
3411 oscore_conf->cred_type != snd_conf->gs_public_cred->cred_type) {
3413 goto error_free_value;
3415 oscore_conf->cred_type = snd_conf->gs_public_cred->cred_type;
3419 if (oscore_conf->
sender) {
3422 goto error_free_value;
3424 oscore_conf->
sender = snd_conf;
3428 if (keyword.
length ==
sizeof(
"complex_recipient") - 1 &&
3429 memcmp(keyword.
s,
"complex_recipient", keyword.
length) == 0) {
3431 coap_parse_oscore_rcp_conf_mem(*value.u.value_bin);
3436 (
const char *)keyword.
s);
3437 goto error_free_value;
3439#if COAP_OSCORE_GROUP_SUPPORT
3440 if (rcp_conf->group_mode || rcp_conf->pairwise_mode) {
3441 if (oscore_conf->cred_type != 0 &&
3442 oscore_conf->cred_type != rcp_conf->gr_public_cred->cred_type) {
3444 goto error_free_value;
3446 oscore_conf->cred_type = rcp_conf->gr_public_cred->cred_type;
3455 case COAP_ENC_ASCII:
3457 memcpy(&unused_check,
3458 &(((
char *)oscore_conf)[oscore_config[i].offset]),
3459 sizeof(unused_check));
3460 if (unused_check !=
NULL) {
3463 (
const char *)keyword.
s);
3464 goto error_free_value;
3466 memcpy(&(((
char *)oscore_conf)[oscore_config[i].offset]),
3468 sizeof(value.u.value_bin));
3470#if COAP_OSCORE_GROUP_SUPPORT
3471 case COAP_ENC_PUB_RAW:
3472 case COAP_ENC_PUB_ASN1:
3473 case COAP_ENC_PUB_FILE_PEM:
3474 case COAP_ENC_PUB_CCS:
3475 memcpy(&unused_check,
3476 &(((
char *)oscore_conf)[oscore_config[i].offset]),
3477 sizeof(unused_check));
3478 if (unused_check !=
NULL) {
3481 (
const char *)keyword.
s);
3482 cleanup_value(&value);
3485 memcpy(&(((
char *)oscore_conf)[oscore_config[i].offset]),
3486 &value.u.value_cred,
3487 sizeof(value.u.value_cred));
3489 case COAP_ENC_PRI_RAW:
3490 case COAP_ENC_PRI_ASN1:
3491 case COAP_ENC_PRI_FILE_PEM:
3492 memcpy(&unused_check,
3493 &(((
char *)oscore_conf)[oscore_config[i].offset]),
3494 sizeof(unused_check));
3495 if (unused_check !=
NULL) {
3498 (
const char *)keyword.
s);
3499 cleanup_value(&value);
3502 memcpy(&(((
char *)oscore_conf)[oscore_config[i].offset]),
3504 sizeof(value.u.value_pri));
3507 case COAP_ENC_INTEGER:
3509 memcpy(&(((
char *)oscore_conf)[oscore_config[i].offset]),
3511 sizeof(value.u.value_int));
3514 for (j = 0; oscore_config[i].text_mapping[j].text.s !=
NULL; j++) {
3516 &oscore_config[i].text_mapping[j].text)) {
3517 memcpy(&(((
char *)oscore_conf)[oscore_config[i].offset]),
3518 &oscore_config[i].text_mapping[j].value,
3519 sizeof(oscore_config[i].text_mapping[j].value));
3523 if (oscore_config[i].text_mapping[j].text.s ==
NULL) {
3524 coap_log_warn(
"oscore_conf: Keyword '%.*s': value '%.*s' unknown\n",
3526 (
const char *)keyword.
s,
3527 (
int)value.u.value_str.length,
3528 (
const char *)value.u.value_str.s);
3532 case COAP_ENC_UNSIGNED64:
3542 if (i ==
sizeof(oscore_config) /
sizeof(oscore_config[0])) {
3543 coap_log_warn(
"oscore_conf: Keyword '%.*s', type '%s' unknown\n",
3545 (
const char *)keyword.
s,
3546 value.encoding_name);
3548 cleanup_value(&value);
3554 if (!oscore_conf->master_secret) {
3558 if (!oscore_conf->sender) {
3583#if COAP_OSCORE_GROUP_SUPPORT
3585 coap_log_warn(
"COSE: Group Encryption Algorithm %d not supported\n",
3586 oscore_conf->alg_group_enc);
3594 coap_log_crit(
"OSCORE: Could not create Security Context!\n");
3628 if (session ==
NULL || recipient_ctx ==
NULL)
3631 if (session->recipient_ctx == recipient_ctx) {
3636 old_ctx = session->recipient_ctx;
3638 if (old_ctx !=
NULL) {
3645 session->recipient_ctx = recipient_ctx;
3646 session->recipient_ctx->
ref++;
3648 if (old_ctx !=
NULL) {
3658 if (association ==
NULL)
3667 if (recipient_ctx !=
NULL)
3670 if (old_ctx !=
NULL)
3677 void *save_seq_num_func_param,
3678 uint64_t start_seq_num) {
3681 if (oscore_conf ==
NULL)
3696 size_t overhead = 0;
3702 if (osc_ctx ==
NULL)
3734#if COAP_OSCORE_GROUP_SUPPORT
3736 overhead += osc_ctx->
sender_context->sender_cred->wire_sign_size;
3764 if (context->p_osc_ctx ==
NULL) {
3769 if (rcp_conf ==
NULL) {
3777 if (rcp_ctx ==
NULL)
3787 if (!context || !recipient_id)
3799 if (context->p_osc_ctx ==
NULL)
3808 if (context ==
NULL)
3812 context->oscore_find_cb = find_handler;
3813 context->oscore_update_seq_num_cb = update_seq_num_handler;
3835 uint64_t last_seq, uint64_t seq_window) {
3848 uint64_t last_seq, uint64_t seq_window) {
3851 rcp_conf = coap_oscore_get_recipient_conf(oscore_conf, recipient_id);
4002 void *save_seq_num_func_param,
4003 uint64_t start_seq_num) {
4005 (void)save_seq_num_func;
4006 (void)save_seq_num_func_param;
4007 (void)start_seq_num;
4039 (void)update_seq_num_handler;
4045 uint64_t last_seq, uint64_t seq_window) {
struct coap_lg_crcv_t coap_lg_crcv_t
Library specific build wrapper for coap_internal.h.
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.
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
uint8_t coap_opt_t
Use byte-oriented access methods here because sliding a complex struct coap_opt_t over the data buffe...
@ COAP_OPTION_IF_NONE_MATCH
@ COAP_OPTION_PROXY_SCHEME
@ COAP_OPTION_CONTENT_FORMAT
@ COAP_OPTION_LOCATION_QUERY
@ COAP_OPTION_LOCATION_PATH
@ COAP_OPTION_URI_PATH_ABB
static int coap_uri_scheme_is_secure(const coap_uri_t *uri)
coap_mid_t coap_send_ack_lkd(coap_session_t *session, const coap_pdu_t *request)
Sends an ACK message with code 0 for the specified request to dst.
int coap_prng_lkd(void *buf, size_t len)
Fills buf with len random bytes using the default pseudo random number generator.
int coap_handle_event_lkd(coap_context_t *context, coap_event_t event, coap_session_t *session)
Invokes the event handler of context for the given event and data.
coap_mid_t coap_send_internal(coap_session_t *session, coap_pdu_t *pdu, coap_pdu_t *request_pdu)
Sends a CoAP message to given peer.
void coap_cancel_all_messages(coap_context_t *context, coap_session_t *session, coap_bin_const_t *token)
Cancels all outstanding messages for session session that have the specified token.
#define COAP_OSCORE_DEFAULT_REPLAY_WINDOW
int coap_crypto_check_hkdf_alg(cose_hkdf_alg_t hkdf_alg)
Check whether the defined hkdf algorithm is supported by the underlying crypto library.
int coap_crypto_check_cipher_alg(cose_alg_t alg)
Check whether the defined cipher algorithm is supported by the underlying crypto library.
unsigned int coap_encode_var_safe(uint8_t *buf, size_t length, unsigned int val)
Encodes multiple-length byte sequences.
unsigned int coap_decode_var_bytes(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
uint64_t coap_decode_var_bytes8(const uint8_t *buf, size_t len)
Decodes multiple-length byte sequences.
unsigned int coap_encode_var_safe8(uint8_t *buf, size_t length, uint64_t val)
Encodes multiple-length byte sequences.
@ COAP_EVENT_OSCORE_DECODE_ERROR
Triggered when there is an OSCORE decode of OSCORE option failure.
@ COAP_EVENT_OSCORE_INTERNAL_ERROR
Triggered when there is an OSCORE internal error i.e malloc failed.
@ COAP_EVENT_OSCORE_NOT_ENABLED
Triggered when trying to use OSCORE to decrypt, but it is not enabled.
@ COAP_EVENT_OSCORE_RECIPIENT_CHANGED
Triggered when coap_oscore_session_set_recipient_ctx() replaces the recipient context bound to a sess...
@ COAP_EVENT_OSCORE_NO_SECURITY
Triggered when there is no OSCORE security definition found.
@ COAP_EVENT_OSCORE_NO_PROTECTED_PAYLOAD
Triggered when there is no OSCORE encrypted payload provided.
@ COAP_EVENT_OSCORE_SIGNATURE_FAILURE
Triggered when there is an OSCORE signature failure.
@ COAP_EVENT_OSCORE_DECRYPTION_FAILURE
Triggered when there is an OSCORE decryption failure.
#define coap_lock_callback(func)
Dummy for no thread-safe code.
#define coap_lock_unlock()
Dummy for no thread-safe code.
#define coap_lock_check_locked()
Dummy for no thread-safe code.
#define coap_lock_lock(failed)
Dummy for no thread-safe code.
#define coap_log_debug(...)
coap_log_t coap_get_log_level(void)
Get the current logging level.
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu)
Display the contents of the specified pdu.
#define coap_log_oscore(...)
#define coap_log_warn(...)
#define coap_log_err(...)
#define coap_log_crit(...)
coap_opt_t * coap_option_next(coap_opt_iterator_t *oi)
Updates the iterator oi to point to the next option.
uint32_t coap_opt_length(const coap_opt_t *opt)
Returns the length of the given option.
coap_opt_iterator_t * coap_option_iterator_init(const coap_pdu_t *pdu, coap_opt_iterator_t *oi, const coap_opt_filter_t *filter)
Initializes the given option iterator oi to point to the beginning of the pdu's option list.
void coap_delete_optlist(coap_optlist_t *queue)
Removes all entries from the optlist_chain, freeing off their memory usage.
#define COAP_OPT_ALL
Pre-defined filter that includes all options.
int coap_add_optlist_pdu(coap_pdu_t *pdu, coap_optlist_t **options)
The current optlist of optlist_chain is first sorted (as per RFC7272 ordering requirements) and then ...
coap_opt_t * coap_check_option(const coap_pdu_t *pdu, coap_option_num_t number, coap_opt_iterator_t *oi)
Retrieves the first option of number number from pdu.
const uint8_t * coap_opt_value(const coap_opt_t *opt)
Returns a pointer to the value of the given option.
uint64_t oscore_cbor_get_element_size(const uint8_t **buffer, size_t *buf_size)
#define CBOR_UNSIGNED_INTEGER
uint8_t oscore_cbor_get_next_element(const uint8_t **buffer, size_t *buf_size)
#define CBOR_FLOATING_POINT
uint8_t oscore_cbor_get_number(const uint8_t **data, size_t *buf_size, int64_t *value)
void cose_encrypt0_set_plaintext(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size)
int cose_encrypt0_set_key(cose_encrypt0_t *ptr, coap_bin_const_t *key)
void cose_encrypt0_set_kid_context(cose_encrypt0_t *ptr, coap_bin_const_t *kid_context)
const char * cose_get_alg_name(cose_alg_t id, char *buffer, size_t buflen)
void cose_encrypt0_set_ciphertext(cose_encrypt0_t *ptr, uint8_t *buffer, size_t size)
int cose_encrypt0_decrypt(cose_encrypt0_t *ptr, uint8_t *plaintext_buffer, size_t plaintext_len)
size_t cose_tag_len(cose_alg_t cose_alg)
void cose_encrypt0_set_aad(cose_encrypt0_t *ptr, coap_bin_const_t *aad)
int cose_encrypt0_encrypt(cose_encrypt0_t *ptr, uint8_t *ciphertext_buffer, size_t ciphertext_len)
void cose_encrypt0_set_partial_iv(cose_encrypt0_t *ptr, coap_bin_const_t *partial_iv)
void cose_encrypt0_set_external_aad(cose_encrypt0_t *ptr, coap_bin_const_t *external_aad)
void cose_encrypt0_init(cose_encrypt0_t *ptr)
void cose_encrypt0_set_alg(cose_encrypt0_t *ptr, uint8_t alg)
void cose_encrypt0_set_key_id(cose_encrypt0_t *ptr, coap_bin_const_t *key_id)
void cose_encrypt0_set_nonce(cose_encrypt0_t *ptr, coap_bin_const_t *nonce)
@ COSE_HKDF_ALG_HKDF_SHA_256
@ COSE_ALGORITHM_ECDH_SS_HKDF_256
@ COSE_ALGORITHM_AES_CCM_16_64_128
@ COSE_ALGORITHM_AES_CCM_16_64_256
size_t oscore_prepare_aad(const uint8_t *external_aad_buffer, size_t external_aad_len, uint8_t *aad_buffer, size_t aad_size)
void oscore_reference_recipient_ctx(oscore_recipient_ctx_t *recipient_ctx)
Increment the recipient context reference count.
void coap_oscore_association_set_recipient_ctx(oscore_association_t *association, oscore_recipient_ctx_t *recipient_ctx)
Set the recipient context of an association.
oscore_ctx_t * oscore_derive_ctx_from_conf(coap_oscore_conf_t *oscore_conf)
oscore_derive_ctx_from_conf - derive a osc_ctx from oscore_conf information
int coap_delete_oscore_recipient_lkd(coap_context_t *context, coap_bin_const_t *recipient_id)
Release all the information associated for the specific Recipient ID (and hence and stop any further ...
int oscore_delete_association(coap_session_t *session, oscore_association_t *association)
coap_session_t * coap_new_client_session_oscore3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_oscore_conf_t *oscore_conf, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, protecting the data using OSCORE,...
uint8_t oscore_validate_sender_seq(oscore_recipient_ctx_t *ctx, cose_encrypt0_t *cose)
oscore_recipient_ctx_t * oscore_add_recipient(oscore_ctx_t *ctx, coap_oscore_rcp_conf_t *rcp_conf, uint32_t break_key)
oscore_add_recipient - add in recipient information
oscore_ctx_t * coap_init_oscore_context_from_conf(coap_oscore_conf_t *oscore_conf)
Initializes an OSCORE context from the given configuration.
void coap_oscore_session_set_recipient_ctx(coap_session_t *session, oscore_recipient_ctx_t *recipient_ctx)
Attach the OSCORE recipient context information to the session.
int oscore_decode_option_value(const uint8_t *option_value, size_t option_len, cose_encrypt0_t *cose)
int coap_delete_oscore_snd_conf(coap_oscore_snd_conf_t *oscore_snd_conf)
Release all the information associated with the OSCORE complex Sender configuration.
coap_pdu_t * coap_oscore_new_pdu_encrypted_lkd(coap_session_t *session, coap_pdu_t *pdu, coap_bin_const_t *kid_context, oscore_partial_iv_t send_partial_iv)
Encrypts the specified pdu when OSCORE encryption is required on session.
int oscore_delete_recipient(oscore_ctx_t *osc_ctx, coap_bin_const_t *rid)
#define COAP_OSCORE_DECRYPT_NO_REPLAY
coap_oscore_decrypt_pdu_ext() flag: verify a request without the replay check and without touching th...
uint8_t oscore_increment_sender_seq(oscore_ctx_t *ctx)
void oscore_update_ctx(oscore_ctx_t *osc_ctx, coap_bin_const_t *id_context)
oscore_update_ctx - update a osc_ctx with a new id_context
coap_session_t * coap_new_client_session_oscore_psk3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_cpsk_t *psk_data, coap_oscore_conf_t *oscore_conf, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PSK credentials protecting the data using...
struct coap_pdu_t * coap_oscore_decrypt_pdu_ext(coap_session_t *session, coap_pdu_t *pdu, uint32_t flags)
As coap_oscore_decrypt_pdu(), with flags (COAP_OSCORE_DECRYPT_*).
oscore_ctx_t * oscore_derive_ctx(coap_context_t *c_context, coap_oscore_conf_t *oscore_conf)
oscore_derive_ctx - derive a osc_ctx from oscore_conf information
COAP_API coap_pdu_t * coap_oscore_new_pdu_encrypted(coap_session_t *session, coap_pdu_t *pdu, coap_bin_const_t *kid_context, oscore_partial_iv_t send_partial_iv)
Encrypts the specified pdu when OSCORE encryption is required on session.
void oscore_roll_back_seq(oscore_recipient_ctx_t *ctx)
int oscore_new_association(coap_session_t *session, coap_pdu_t *sent_pdu, coap_bin_const_t *token, oscore_recipient_ctx_t *recipient_ctx, coap_bin_const_t *aad, coap_bin_const_t *nonce, coap_bin_const_t *partial_iv, int is_observe)
void oscore_delete_server_associations(coap_session_t *session)
void oscore_log_char_value(coap_log_t level, const char *name, const char *value)
oscore_ctx_t * oscore_find_context(coap_session_t *session, const coap_bin_const_t rcpkey_id, const coap_bin_const_t *ctxkey_id, uint8_t *oscore_r2, oscore_recipient_ctx_t **recipient_ctx)
oscore_find_context - Locate recipient context (and hence OSCORE context)
struct coap_pdu_t * coap_oscore_decrypt_pdu(coap_session_t *session, coap_pdu_t *pdu)
Decrypts the OSCORE-encrypted parts of pdu when OSCORE is used.
int coap_oscore_recipient_set_latest_seq_lkd(coap_oscore_conf_t *oscore_conf, const coap_bin_const_t *recipient_id, uint64_t last_seq, uint64_t seq_window)
Set the latest sequence number and sliding window for the specified recipient id in the compiled conf...
int coap_rebuild_pdu_for_proxy(coap_pdu_t *pdu)
Convert PDU to use Proxy-Scheme option if Proxy-Uri option is present.
void oscore_free_contexts(coap_context_t *c_context)
void oscore_log_hex_value(coap_log_t level, const char *name, coap_bin_const_t *value)
void coap_delete_oscore_associations(coap_session_t *session)
Cleanup all allocated OSCORE association information.
void oscore_log_int_value(coap_log_t level, const char *name, int value)
int coap_oscore_initiate(coap_session_t *session, coap_oscore_conf_t *oscore_conf)
Initiate an OSCORE session.
int coap_new_oscore_recipient_lkd(coap_context_t *context, coap_bin_const_t *recipient_id)
Add in the specific Recipient ID into the OSCORE context (server only).
oscore_ctx_t * oscore_duplicate_ctx(coap_context_t *c_context, oscore_ctx_t *o_osc_ctx, coap_bin_const_t *sender_id, coap_bin_const_t *recipient_id, coap_bin_const_t *id_context)
oscore_duplicate_ctx - duplicate a osc_ctx
void coap_delete_all_oscore(coap_context_t *context)
Cleanup all allocated OSCORE information.
void oscore_generate_nonce(cose_encrypt0_t *ptr, oscore_ctx_t *ctx, uint8_t *buffer, uint8_t size)
int oscore_remove_context(coap_context_t *c_context, oscore_ctx_t *osc_ctx)
int oscore_derive_keystream(oscore_ctx_t *osc_ctx, cose_encrypt0_t *code, uint8_t coap_request, coap_bin_const_t *sender_key, coap_bin_const_t *id_context, size_t cs_size, uint8_t *keystream, size_t keystream_size)
oscore_association_t * oscore_find_association(coap_session_t *session, coap_bin_const_t *token)
int coap_context_oscore_server_lkd(coap_context_t *context, coap_oscore_conf_t *oscore_conf)
Set the context's default OSCORE configuration for a server.
int coap_delete_oscore_rcp_conf(coap_oscore_rcp_conf_t *oscore_rcp_conf)
Release all the information associated with the OSCORE complex Recipient configuration.
size_t oscore_prepare_e_aad(oscore_ctx_t *ctx, cose_encrypt0_t *cose, const uint8_t *oscore_option, size_t oscore_option_len, coap_crypto_cred_t *sender_cred, uint8_t *external_aad_ptr, size_t external_aad_size)
void oscore_release_recipient_ctx(oscore_recipient_ctx_t **recipient_ctx)
Cleanup recipient context, including releasing the oscore context if the oscore context referenced is...
coap_session_t * coap_new_client_session_oscore_pki3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_pki_t *pki_data, coap_oscore_conf_t *oscore_conf, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PKI credentials protecting the data using...
ssize_t oscore_encode_option_value(uint8_t *option_buffer, size_t option_buf_len, cose_encrypt0_t *cose, uint8_t group_flag, uint8_t appendix_b_2)
Encode the OSCORE option.
size_t coap_oscore_overhead(coap_session_t *session, coap_pdu_t *pdu)
Determine the additional data size requirements for adding in OSCORE.
@ OSCORE_MODE_SINGLE
Vanilla RFC 8613 support.
@ OSCORE_MODE_GROUP
RFC 10021 support.
@ OSCORE_SEND_PARTIAL_IV
Send partial IV with encrypted PDU.
@ OSCORE_SEND_NO_IV
Do not send partial IV unless added by a response.
COAP_API int coap_oscore_recipient_set_latest_seq(coap_oscore_conf_t *oscore_conf, const coap_bin_const_t *recipient_id, uint64_t last_seq, uint64_t seq_window)
Set the latest sequence number and sliding window for the specified recipient id in the compiled conf...
coap_oscore_conf_t * coap_new_oscore_conf(coap_str_const_t conf_mem, coap_oscore_save_seq_num_t save_seq_num_func, void *save_seq_num_func_param, uint64_t start_seq_num)
Parse an OSCORE configuration (held in memory) and populate a OSCORE configuration structure.
coap_session_t * coap_new_client_session_oscore_psk(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_cpsk_t *psk_data, coap_oscore_conf_t *oscore_conf)
Creates a new client session to the designated server with PSK credentials as well as protecting the ...
coap_session_t * coap_new_client_session_oscore_psk3(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_cpsk_t *psk_data, coap_oscore_conf_t *oscore_conf, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PSK credentials protecting the data using...
int(* coap_oscore_update_seq_num_handler_t)(const coap_session_t *session, const coap_bin_const_t *rcpkey_id, const coap_bin_const_t *ctxkey_id, uint64_t receiver_seq_num, uint64_t seq_num_window)
Callback function type for persisting the OSCORE receiver sequence number and anti-replay sliding win...
int coap_delete_oscore_conf(coap_oscore_conf_t *oscore_conf)
Release all the information associated with the OSCORE configuration.
coap_session_t * coap_new_client_session_oscore(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_oscore_conf_t *oscore_conf)
Creates a new client session to the designated server, protecting the data using OSCORE.
int coap_context_oscore_server(coap_context_t *context, coap_oscore_conf_t *oscore_conf)
Set the context's default OSCORE configuration for a server.
coap_oscore_conf_t *(* coap_oscore_find_handler_t)(const coap_session_t *session, const coap_bin_const_t *rcpkey_id, const coap_bin_const_t *ctxkey_id)
Callback function type for overriding oscore_find_context().
coap_session_t * coap_new_client_session_oscore_pki(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_pki_t *pki_data, coap_oscore_conf_t *oscore_conf)
Creates a new client session to the designated server with PKI credentials as well as protecting the ...
coap_session_t * coap_new_client_session_oscore3(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_oscore_conf_t *oscore_conf, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, protecting the data using OSCORE,...
int coap_new_oscore_recipient(coap_context_t *context, coap_bin_const_t *recipient_id)
Add in the specific Recipient ID into the OSCORE context (server only).
int(* coap_oscore_save_seq_num_t)(uint64_t sender_seq_num, void *param)
Definition of the function used to save the current Sender Sequence Number.
int coap_delete_oscore_recipient(coap_context_t *context, coap_bin_const_t *recipient_id)
Release all the information associated for the specific Recipient ID (and hence stop any further OSCO...
void coap_oscore_register_external_handlers(coap_context_t *context, coap_oscore_find_handler_t find_handler, coap_oscore_update_seq_num_handler_t update_seq_num_handler)
Register external storage handlers for OSCORE session state.
coap_session_t * coap_new_client_session_oscore_pki3(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_pki_t *pki_data, coap_oscore_conf_t *oscore_conf, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PKI credentials protecting the data using...
void coap_delete_pdu_lkd(coap_pdu_t *pdu)
Dispose of an CoAP PDU and free off associated storage.
size_t coap_insert_option(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Inserts option of given number in the pdu with the appropriate data.
int coap_remove_option(coap_pdu_t *pdu, coap_option_num_t number)
Removes (first) option of given number from the pdu.
int coap_update_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Updates token in pdu with length len and data.
#define COAP_PDU_IS_PING(pdu)
coap_pdu_t * coap_pdu_duplicate_lkd(const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, const uint8_t *token, coap_opt_filter_t *drop_options, coap_bool_t expand_opt_abb)
Duplicate an existing PDU.
size_t coap_pdu_encode_header(coap_pdu_t *pdu, coap_proto_t proto)
Compose the protocol specific header for the specified PDU.
#define COAP_PAYLOAD_START
int coap_pdu_resize(coap_pdu_t *pdu, size_t new_size)
Dynamically grows the size of pdu to new_size.
#define COAP_PDU_IS_REQUEST(pdu)
size_t coap_add_option_internal(coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
Adds option of given number to pdu that is passed as first parameter.
#define COAP_DEFAULT_PORT
#define COAP_RESPONSE_CODE(N)
#define COAP_RESPONSE_CLASS(C)
coap_proto_t
CoAP protocol types Note: coap_layers_coap[] needs updating if extended.
coap_pdu_code_t
Set of codes available for a PDU.
int coap_add_token(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds token of length len to pdu.
#define COAPS_DEFAULT_PORT
int coap_get_data(const coap_pdu_t *pdu, size_t *len, const uint8_t **data)
Retrieves the length and data pointer of specified PDU.
coap_pdu_t * coap_pdu_init(coap_pdu_type_t type, coap_pdu_code_t code, coap_mid_t mid, size_t size)
Creates a new CoAP PDU with at least enough storage space for the given size maximum message size.
#define COAP_INVALID_MID
Indicates an invalid message id.
int coap_add_data(coap_pdu_t *pdu, size_t len, const uint8_t *data)
Adds given data to the pdu that is passed as first parameter.
coap_bin_const_t coap_pdu_get_token(const coap_pdu_t *pdu)
Gets the token associated with pdu.
@ COAP_REQUEST_CODE_FETCH
coap_session_t * coap_new_client_session_pki3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_pki_t *setup_data, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PKI credentials along with app_data infor...
coap_session_t * coap_new_client_session_psk3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, coap_dtls_cpsk_t *setup_data, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PSK credentials along with app_data infor...
void coap_session_release_lkd(coap_session_t *session)
Decrement reference counter on a session.
coap_session_t * coap_new_client_session3_lkd(coap_context_t *ctx, const coap_address_t *local_if, const coap_address_t *server, coap_proto_t proto, void *app_data, coap_app_data_free_callback_t callback, coap_str_const_t *ws_host)
Creates a new client session to the designated server, with PSK credentials along with app_data infor...
void(* coap_app_data_free_callback_t)(void *data)
Callback to free off the app data when the entry is being deleted / freed off.
void coap_delete_bin_const(coap_bin_const_t *s)
Deletes the given const binary data and releases any memory allocated.
void coap_delete_str_const(coap_str_const_t *s)
Deletes the given const string and releases any memory allocated.
coap_binary_t * coap_new_binary(size_t size)
Returns a new binary object with at least size bytes storage allocated.
coap_str_const_t * coap_make_str_const(const char *string)
Take the specified byte array (text) and create a coap_str_const_t *.
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...
struct coap_str_const_t coap_str_const_t
CoAP string data definition with const data.
void coap_delete_binary(coap_binary_t *s)
Deletes the given coap_binary_t object and releases any memory allocated.
#define coap_binary_equal(binary1, binary2)
Compares the two binary data for equality.
#define coap_string_equal(string1, string2)
Compares the two strings for equality.
coap_string_t * coap_new_string(size_t size)
Returns a new string object with at least size+1 bytes storage allocated.
coap_str_const_t * coap_new_str_const(const uint8_t *data, size_t size)
Returns a new const string object with at least size+1 bytes storage allocated, and the provided data...
void coap_delete_string(coap_string_t *s)
Deletes the given string and releases any memory allocated.
int coap_oscore_group_is_supported(void)
Check whether OSCORE Group support is available.
int coap_oscore_pairwise_is_supported(void)
Check whether OSCORE Pairwise support is available.
int coap_oscore_is_supported(void)
Check whether OSCORE is available.
int coap_query_into_optlist(const uint8_t *s, size_t length, coap_option_num_t optnum, coap_optlist_t **optlist_chain)
Splits the given URI query into '&' separate segments, and then adds the Uri-Query / Location-Query o...
int coap_path_into_optlist(const uint8_t *s, size_t length, coap_option_num_t optnum, coap_optlist_t **optlist_chain)
Splits the given URI path into '/' separate segments, and then adds the Uri-Path / Location-Path opti...
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
coap_uri_info_t coap_uri_scheme[COAP_URI_SCHEME_LAST]
Multi-purpose address abstraction.
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.
Holds credential definitions.
coap_bin_const_t * auth_cred
Authentication Credentials of type type.
coap_bin_const_t * pub_raw
Raw Value of the public key abstracted from key_tls.
coap_bin_const_t * pub_der
DER Value of the public key abstracted from key_tls.
Holds private key definitions.
The structure used for defining the Client PSK setup data to be used.
The structure used for defining the PKI setup data to be used.
Iterator to run through PDU options.
coap_opt_t * next_option
pointer to the unparsed next option
size_t length
remaining length of PDU
coap_option_num_t number
decoded option number
Representation of chained list of CoAP options to install.
The structure used to hold the OSCORE configuration information.
void * save_seq_num_func_param
Passed to save_seq_num_func().
uint32_t rfc8613_b_2
1 if rfc8613 B.2 protocol else 0
cose_hkdf_alg_t hkdf_alg
Set to one of COSE_HKDF_ALG_*.
uint32_t break_sender_key
1 if sender key to be broken, else 0
coap_oscore_snd_conf_t * sender
The sender - i.e.
coap_oscore_rcp_conf_t * recipient_chain
The recipients as a chain.
uint32_t ssn_freq
Sender Seq Num update frequency.
coap_oscore_save_seq_num_t save_seq_num_func
Called every seq num change.
uint32_t rfc8613_b_1_2
1 if rfc8613 B.1.2 enabled else 0
uint64_t start_seq_num
Used for ssn_freq updating.
uint32_t break_recipient_key
1 if recipient key to be broken, else 0
coap_bin_const_t * master_secret
Common Master Secret.
cose_alg_t aead_alg
Set to one of COSE_ALGORITHM_AES*.
coap_bin_const_t * master_salt
Common Master Salt.
uint32_t replay_window
Replay window size Use COAP_OSCORE_DEFAULT_REPLAY_WINDOW.
coap_bin_const_t * id_context
Common ID context.
The structure used to hold the OSCORE Recipient configuration.
coap_bin_const_t * recipient_id
Recipient ID (i.e.
uint64_t last_seq
Highest sequence number used for this recipient.
uint8_t window_initialized
Contains if the sliding window is initialized 1 if initialized, 0 otherwise.
struct coap_oscore_rcp_conf_t * next_recipient
Used to maintain the chain.
uint64_t sliding_window
bitfield sequence counter window
The structure used to hold the OSCORE Sender configuration information.
coap_bin_const_t * sender_id
Sender ID (i.e.
uint8_t max_hdr_size
space reserved for protocol-specific header
uint8_t * token
first byte of token (or extended length bytes prefix), if any, or options
coap_pdu_code_t code
request method (value 1–31) or response code (value 64-255)
coap_bin_const_t actual_token
Actual token in pdu.
uint8_t * data
first byte of payload, if any
coap_mid_t mid
message id, if any, in regular host byte order
uint32_t e_token_length
length of Token space (includes leading extended bytes
size_t used_size
used bytes of storage for token, options and payload
coap_pdu_type_t type
message type
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
uint32_t max_token_size
Largest token size supported RFC8974.
coap_proto_t proto
protocol used
unsigned ref
reference count from queues
uint8_t con_active
Active CON request sent.
coap_context_t * context
session's context
CoAP string data definition with const data.
const uint8_t * s
read-only string data
size_t length
length of string
CoAP string data definition.
size_t length
length of string
Representation of parsed URI.
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
coap_str_const_t path
The complete path if present or {0, NULL}.
uint16_t port
The port in host byte order.
coap_str_const_t query
The complete query if present or {0, NULL}.
coap_str_const_t host
The host part of the URI.
coap_bin_const_t partial_iv
coap_bin_const_t kid_context
coap_bin_const_t external_aad
coap_bin_const_t oscore_option
coap_bin_const_t * obs_partial_iv
coap_bin_const_t * partial_iv
oscore_recipient_ctx_t * recipient_ctx
uint8_t rfc8613_b_1_2
1 if rfc8613 B.1.2 enabled else 0
void * save_seq_num_func_param
Passed to save_seq_num_func().
oscore_sender_ctx_t * sender_context
cose_alg_t aead_alg
Set to one of COSE_ALGORITHM_AES*.
uint8_t rfc8613_b_2
1 if rfc8613 B.2 protocol else 0
coap_oscore_save_seq_num_t save_seq_num_func
Called every seq num change.
oscore_recipient_ctx_t * recipient_chain
coap_bin_const_t * id_context
contains GID in case of group
uint32_t ssn_freq
Sender Seq Num update frequency.
coap_bin_const_t * recipient_key
coap_bin_const_t * recipient_id
coap_bin_const_t * sender_id
uint64_t seq
Sender Sequence Number.
coap_bin_const_t * sender_key
uint64_t next_seq
Used for ssn_freq updating.