1c87c5fbaSopenharmony_ci/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2c87c5fbaSopenharmony_ci 3c87c5fbaSopenharmony_ci/* libcoap unit tests 4c87c5fbaSopenharmony_ci * 5c87c5fbaSopenharmony_ci * Copyright (C) 2021-2023 Jon Shallow <supjps-libcoap@jpshallow.com> 6c87c5fbaSopenharmony_ci * 7c87c5fbaSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause 8c87c5fbaSopenharmony_ci * 9c87c5fbaSopenharmony_ci * This file is part of the CoAP library libcoap. Please see 10c87c5fbaSopenharmony_ci * README for terms of use. 11c87c5fbaSopenharmony_ci */ 12c87c5fbaSopenharmony_ci 13c87c5fbaSopenharmony_ci#include "test_common.h" 14c87c5fbaSopenharmony_ci 15c87c5fbaSopenharmony_ci#if COAP_OSCORE_SUPPORT && COAP_SERVER_SUPPORT 16c87c5fbaSopenharmony_ci#include "test_oscore.h" 17c87c5fbaSopenharmony_ci#include "oscore/oscore.h" 18c87c5fbaSopenharmony_ci#include "oscore/oscore_context.h" 19c87c5fbaSopenharmony_ci 20c87c5fbaSopenharmony_ci#include <stdio.h> 21c87c5fbaSopenharmony_ci#include <stdlib.h> 22c87c5fbaSopenharmony_ci#include <string.h> 23c87c5fbaSopenharmony_ci 24c87c5fbaSopenharmony_ci#define CHECK_SAME(a,b) \ 25c87c5fbaSopenharmony_ci (sizeof((a)) == (b)->length && memcmp((a), (b)->s, (b)->length) == 0) 26c87c5fbaSopenharmony_ci 27c87c5fbaSopenharmony_ci#define FailIf_CU_ASSERT_PTR_NOT_NULL(value) CU_ASSERT_PTR_NOT_NULL(value); if ((void*)value == NULL) goto fail 28c87c5fbaSopenharmony_ci 29c87c5fbaSopenharmony_ci/************************************************************************ 30c87c5fbaSopenharmony_ci ** RFC8613 tests 31c87c5fbaSopenharmony_ci ************************************************************************/ 32c87c5fbaSopenharmony_ci 33c87c5fbaSopenharmony_ci/* C.1.1. Test Vector 1: Key Derivation with Master Salt, Client */ 34c87c5fbaSopenharmony_cistatic void 35c87c5fbaSopenharmony_cit_oscore_c_1_1(void) { 36c87c5fbaSopenharmony_ci static const char conf_data[] = 37c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 38c87c5fbaSopenharmony_ci "master_salt,hex,\"9e7ca92223786340\"\n" 39c87c5fbaSopenharmony_ci "sender_id,hex,\"\"\n" 40c87c5fbaSopenharmony_ci "recipient_id,hex,\"01\"\n"; 41c87c5fbaSopenharmony_ci static const uint8_t sender_key[] = { 42c87c5fbaSopenharmony_ci 0xf0, 0x91, 0x0e, 0xd7, 0x29, 0x5e, 0x6a, 0xd4, 43c87c5fbaSopenharmony_ci 0xb5, 0x4f, 0xc7, 0x93, 0x15, 0x43, 0x02, 0xff 44c87c5fbaSopenharmony_ci }; 45c87c5fbaSopenharmony_ci static const uint8_t recipient_key[] = { 46c87c5fbaSopenharmony_ci 0xff, 0xb1, 0x4e, 0x09, 0x3c, 0x94, 0xc9, 0xca, 47c87c5fbaSopenharmony_ci 0xc9, 0x47, 0x16, 0x48, 0xb4, 0xf9, 0x87, 0x10 48c87c5fbaSopenharmony_ci }; 49c87c5fbaSopenharmony_ci static const uint8_t common_iv[] = { 50c87c5fbaSopenharmony_ci 0x46, 0x22, 0xd4, 0xdd, 0x6d, 0x94, 0x41, 0x68, 51c87c5fbaSopenharmony_ci 0xee, 0xfb, 0x54, 0x98, 0x7c 52c87c5fbaSopenharmony_ci }; 53c87c5fbaSopenharmony_ci static const uint8_t sender_nonce[] = { 54c87c5fbaSopenharmony_ci 0x46, 0x22, 0xd4, 0xdd, 0x6d, 0x94, 0x41, 0x68, 55c87c5fbaSopenharmony_ci 0xee, 0xfb, 0x54, 0x98, 0x7c 56c87c5fbaSopenharmony_ci }; 57c87c5fbaSopenharmony_ci static const uint8_t recipient_nonce[] = { 58c87c5fbaSopenharmony_ci 0x47, 0x22, 0xd4, 0xdd, 0x6d, 0x94, 0x41, 0x69, 59c87c5fbaSopenharmony_ci 0xee, 0xfb, 0x54, 0x98, 0x7c 60c87c5fbaSopenharmony_ci }; 61c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 62c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 63c87c5fbaSopenharmony_ci }; 64c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 65c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 66c87c5fbaSopenharmony_ci cose_encrypt0_t cose[1]; 67c87c5fbaSopenharmony_ci uint8_t nonce_buffer[13]; 68c87c5fbaSopenharmony_ci coap_bin_const_t nonce = { 13, nonce_buffer }; 69c87c5fbaSopenharmony_ci 70c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 71c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 0); 72c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 73c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 74c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 75c87c5fbaSopenharmony_ci 76c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_key, ctx->p_osc_ctx->sender_context->sender_key)); 77c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_key, 78c87c5fbaSopenharmony_ci ctx->p_osc_ctx->recipient_chain->recipient_key)); 79c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(common_iv, ctx->p_osc_ctx->common_iv)); 80c87c5fbaSopenharmony_ci 81c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 82c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->recipient_chain->recipient_id); 83c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 84c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 85c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_nonce, &nonce)); 86c87c5fbaSopenharmony_ci 87c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 88c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->sender_context->sender_id); 89c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 90c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 91c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_nonce, &nonce)); 92c87c5fbaSopenharmony_ci 93c87c5fbaSopenharmony_cifail: 94c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 95c87c5fbaSopenharmony_ci} 96c87c5fbaSopenharmony_ci 97c87c5fbaSopenharmony_ci/* C.1.2. Test Vector 1: Key Derivation with Master Salt, Server */ 98c87c5fbaSopenharmony_cistatic void 99c87c5fbaSopenharmony_cit_oscore_c_1_2(void) { 100c87c5fbaSopenharmony_ci static const char conf_data[] = 101c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 102c87c5fbaSopenharmony_ci "master_salt,hex,\"9e7ca92223786340\"\n" 103c87c5fbaSopenharmony_ci "sender_id,hex,\"01\"\n" 104c87c5fbaSopenharmony_ci "recipient_id,hex,\"\"\n"; 105c87c5fbaSopenharmony_ci static const uint8_t sender_key[] = { 106c87c5fbaSopenharmony_ci 0xff, 0xb1, 0x4e, 0x09, 0x3c, 0x94, 0xc9, 0xca, 107c87c5fbaSopenharmony_ci 0xc9, 0x47, 0x16, 0x48, 0xb4, 0xf9, 0x87, 0x10 108c87c5fbaSopenharmony_ci }; 109c87c5fbaSopenharmony_ci static const uint8_t recipient_key[] = { 110c87c5fbaSopenharmony_ci 0xf0, 0x91, 0x0e, 0xd7, 0x29, 0x5e, 0x6a, 0xd4, 111c87c5fbaSopenharmony_ci 0xb5, 0x4f, 0xc7, 0x93, 0x15, 0x43, 0x02, 0xff 112c87c5fbaSopenharmony_ci }; 113c87c5fbaSopenharmony_ci static const uint8_t common_iv[] = { 114c87c5fbaSopenharmony_ci 0x46, 0x22, 0xd4, 0xdd, 0x6d, 0x94, 0x41, 0x68, 115c87c5fbaSopenharmony_ci 0xee, 0xfb, 0x54, 0x98, 0x7c 116c87c5fbaSopenharmony_ci }; 117c87c5fbaSopenharmony_ci static const uint8_t sender_nonce[] = { 118c87c5fbaSopenharmony_ci 0x47, 0x22, 0xd4, 0xdd, 0x6d, 0x94, 0x41, 0x69, 119c87c5fbaSopenharmony_ci 0xee, 0xfb, 0x54, 0x98, 0x7c 120c87c5fbaSopenharmony_ci }; 121c87c5fbaSopenharmony_ci static const uint8_t recipient_nonce[] = { 122c87c5fbaSopenharmony_ci 0x46, 0x22, 0xd4, 0xdd, 0x6d, 0x94, 0x41, 0x68, 123c87c5fbaSopenharmony_ci 0xee, 0xfb, 0x54, 0x98, 0x7c 124c87c5fbaSopenharmony_ci }; 125c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 126c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 127c87c5fbaSopenharmony_ci }; 128c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 129c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 130c87c5fbaSopenharmony_ci cose_encrypt0_t cose[1]; 131c87c5fbaSopenharmony_ci uint8_t nonce_buffer[13]; 132c87c5fbaSopenharmony_ci coap_bin_const_t nonce = { 13, nonce_buffer }; 133c87c5fbaSopenharmony_ci 134c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 135c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 0); 136c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 137c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 138c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 139c87c5fbaSopenharmony_ci 140c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_key, ctx->p_osc_ctx->sender_context->sender_key)); 141c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_key, 142c87c5fbaSopenharmony_ci ctx->p_osc_ctx->recipient_chain->recipient_key)); 143c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(common_iv, ctx->p_osc_ctx->common_iv)); 144c87c5fbaSopenharmony_ci 145c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 146c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->recipient_chain->recipient_id); 147c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 148c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 149c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_nonce, &nonce)); 150c87c5fbaSopenharmony_ci 151c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 152c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->sender_context->sender_id); 153c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 154c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 155c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_nonce, &nonce)); 156c87c5fbaSopenharmony_ci 157c87c5fbaSopenharmony_cifail: 158c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 159c87c5fbaSopenharmony_ci} 160c87c5fbaSopenharmony_ci 161c87c5fbaSopenharmony_ci/* C.2.1. Test Vector 2: Key Derivation without Master Salt, Client */ 162c87c5fbaSopenharmony_cistatic void 163c87c5fbaSopenharmony_cit_oscore_c_2_1(void) { 164c87c5fbaSopenharmony_ci static const char conf_data[] = 165c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 166c87c5fbaSopenharmony_ci "sender_id,hex,\"00\"\n" 167c87c5fbaSopenharmony_ci "recipient_id,hex,\"01\"\n"; 168c87c5fbaSopenharmony_ci static const uint8_t sender_key[] = { 169c87c5fbaSopenharmony_ci 0x32, 0x1b, 0x26, 0x94, 0x32, 0x53, 0xc7, 0xff, 170c87c5fbaSopenharmony_ci 0xb6, 0x00, 0x3b, 0x0b, 0x64, 0xd7, 0x40, 0x41 171c87c5fbaSopenharmony_ci }; 172c87c5fbaSopenharmony_ci static const uint8_t recipient_key[] = { 173c87c5fbaSopenharmony_ci 0xe5, 0x7b, 0x56, 0x35, 0x81, 0x51, 0x77, 0xcd, 174c87c5fbaSopenharmony_ci 0x67, 0x9a, 0xb4, 0xbc, 0xec, 0x9d, 0x7d, 0xda 175c87c5fbaSopenharmony_ci }; 176c87c5fbaSopenharmony_ci static const uint8_t common_iv[] = { 177c87c5fbaSopenharmony_ci 0xbe, 0x35, 0xae, 0x29, 0x7d, 0x2d, 0xac, 0xe9, 178c87c5fbaSopenharmony_ci 0x10, 0xc5, 0x2e, 0x99, 0xf9 179c87c5fbaSopenharmony_ci }; 180c87c5fbaSopenharmony_ci static const uint8_t sender_nonce[] = { 181c87c5fbaSopenharmony_ci 0xbf, 0x35, 0xae, 0x29, 0x7d, 0x2d, 0xac, 0xe9, 182c87c5fbaSopenharmony_ci 0x10, 0xc5, 0x2e, 0x99, 0xf9 183c87c5fbaSopenharmony_ci }; 184c87c5fbaSopenharmony_ci static const uint8_t recipient_nonce[] = { 185c87c5fbaSopenharmony_ci 0xbf, 0x35, 0xae, 0x29, 0x7d, 0x2d, 0xac, 0xe8, 186c87c5fbaSopenharmony_ci 0x10, 0xc5, 0x2e, 0x99, 0xf9 187c87c5fbaSopenharmony_ci }; 188c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 189c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 190c87c5fbaSopenharmony_ci }; 191c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 192c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 193c87c5fbaSopenharmony_ci cose_encrypt0_t cose[1]; 194c87c5fbaSopenharmony_ci uint8_t nonce_buffer[13]; 195c87c5fbaSopenharmony_ci coap_bin_const_t nonce = { 13, nonce_buffer }; 196c87c5fbaSopenharmony_ci 197c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 198c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 0); 199c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 200c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 201c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 202c87c5fbaSopenharmony_ci 203c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_key, ctx->p_osc_ctx->sender_context->sender_key)); 204c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_key, 205c87c5fbaSopenharmony_ci ctx->p_osc_ctx->recipient_chain->recipient_key)); 206c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(common_iv, ctx->p_osc_ctx->common_iv)); 207c87c5fbaSopenharmony_ci 208c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 209c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->recipient_chain->recipient_id); 210c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 211c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 212c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_nonce, &nonce)); 213c87c5fbaSopenharmony_ci 214c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 215c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->sender_context->sender_id); 216c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 217c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 218c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_nonce, &nonce)); 219c87c5fbaSopenharmony_ci 220c87c5fbaSopenharmony_cifail: 221c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 222c87c5fbaSopenharmony_ci} 223c87c5fbaSopenharmony_ci 224c87c5fbaSopenharmony_ci/* C.2.2. Test Vector 2: Key Derivation without Master Salt, Server */ 225c87c5fbaSopenharmony_cistatic void 226c87c5fbaSopenharmony_cit_oscore_c_2_2(void) { 227c87c5fbaSopenharmony_ci static const char conf_data[] = 228c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 229c87c5fbaSopenharmony_ci "sender_id,hex,\"01\"\n" 230c87c5fbaSopenharmony_ci "recipient_id,hex,\"00\"\n"; 231c87c5fbaSopenharmony_ci static const uint8_t sender_key[] = { 232c87c5fbaSopenharmony_ci 0xe5, 0x7b, 0x56, 0x35, 0x81, 0x51, 0x77, 0xcd, 233c87c5fbaSopenharmony_ci 0x67, 0x9a, 0xb4, 0xbc, 0xec, 0x9d, 0x7d, 0xda 234c87c5fbaSopenharmony_ci }; 235c87c5fbaSopenharmony_ci static const uint8_t recipient_key[] = { 236c87c5fbaSopenharmony_ci 0x32, 0x1b, 0x26, 0x94, 0x32, 0x53, 0xc7, 0xff, 237c87c5fbaSopenharmony_ci 0xb6, 0x00, 0x3b, 0x0b, 0x64, 0xd7, 0x40, 0x41 238c87c5fbaSopenharmony_ci }; 239c87c5fbaSopenharmony_ci static const uint8_t common_iv[] = { 240c87c5fbaSopenharmony_ci 0xbe, 0x35, 0xae, 0x29, 0x7d, 0x2d, 0xac, 0xe9, 241c87c5fbaSopenharmony_ci 0x10, 0xc5, 0x2e, 0x99, 0xf9 242c87c5fbaSopenharmony_ci }; 243c87c5fbaSopenharmony_ci static const uint8_t sender_nonce[] = { 244c87c5fbaSopenharmony_ci 0xbf, 0x35, 0xae, 0x29, 0x7d, 0x2d, 0xac, 0xe8, 245c87c5fbaSopenharmony_ci 0x10, 0xc5, 0x2e, 0x99, 0xf9 246c87c5fbaSopenharmony_ci }; 247c87c5fbaSopenharmony_ci static const uint8_t recipient_nonce[] = { 248c87c5fbaSopenharmony_ci 0xbf, 0x35, 0xae, 0x29, 0x7d, 0x2d, 0xac, 0xe9, 249c87c5fbaSopenharmony_ci 0x10, 0xc5, 0x2e, 0x99, 0xf9 250c87c5fbaSopenharmony_ci }; 251c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 252c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 253c87c5fbaSopenharmony_ci }; 254c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 255c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 256c87c5fbaSopenharmony_ci cose_encrypt0_t cose[1]; 257c87c5fbaSopenharmony_ci uint8_t nonce_buffer[13]; 258c87c5fbaSopenharmony_ci coap_bin_const_t nonce = { 13, nonce_buffer }; 259c87c5fbaSopenharmony_ci 260c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 261c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 0); 262c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 263c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 264c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 265c87c5fbaSopenharmony_ci 266c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_key, ctx->p_osc_ctx->sender_context->sender_key)); 267c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_key, 268c87c5fbaSopenharmony_ci ctx->p_osc_ctx->recipient_chain->recipient_key)); 269c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(common_iv, ctx->p_osc_ctx->common_iv)); 270c87c5fbaSopenharmony_ci 271c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 272c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->recipient_chain->recipient_id); 273c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 274c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 275c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_nonce, &nonce)); 276c87c5fbaSopenharmony_ci 277c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 278c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->sender_context->sender_id); 279c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 280c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 281c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_nonce, &nonce)); 282c87c5fbaSopenharmony_ci 283c87c5fbaSopenharmony_cifail: 284c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 285c87c5fbaSopenharmony_ci} 286c87c5fbaSopenharmony_ci 287c87c5fbaSopenharmony_ci/* C.3.1. Test Vector 3: Key Derivation with ID Context, Client */ 288c87c5fbaSopenharmony_cistatic void 289c87c5fbaSopenharmony_cit_oscore_c_3_1(void) { 290c87c5fbaSopenharmony_ci static const char conf_data[] = 291c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 292c87c5fbaSopenharmony_ci "master_salt,hex,\"9e7ca92223786340\"\n" 293c87c5fbaSopenharmony_ci "id_context,hex,\"37cbf3210017a2d3\"\n" 294c87c5fbaSopenharmony_ci "sender_id,hex,\"\"\n" 295c87c5fbaSopenharmony_ci "recipient_id,hex,\"01\"\n"; 296c87c5fbaSopenharmony_ci static const uint8_t sender_key[] = { 297c87c5fbaSopenharmony_ci 0xaf, 0x2a, 0x13, 0x00, 0xa5, 0xe9, 0x57, 0x88, 298c87c5fbaSopenharmony_ci 0xb3, 0x56, 0x33, 0x6e, 0xee, 0xcd, 0x2b, 0x92 299c87c5fbaSopenharmony_ci }; 300c87c5fbaSopenharmony_ci static const uint8_t recipient_key[] = { 301c87c5fbaSopenharmony_ci 0xe3, 0x9a, 0x0c, 0x7c, 0x77, 0xb4, 0x3f, 0x03, 302c87c5fbaSopenharmony_ci 0xb4, 0xb3, 0x9a, 0xb9, 0xa2, 0x68, 0x69, 0x9f 303c87c5fbaSopenharmony_ci }; 304c87c5fbaSopenharmony_ci static const uint8_t common_iv[] = { 305c87c5fbaSopenharmony_ci 0x2c, 0xa5, 0x8f, 0xb8, 0x5f, 0xf1, 0xb8, 0x1c, 306c87c5fbaSopenharmony_ci 0x0b, 0x71, 0x81, 0xb8, 0x5e 307c87c5fbaSopenharmony_ci }; 308c87c5fbaSopenharmony_ci static const uint8_t sender_nonce[] = { 309c87c5fbaSopenharmony_ci 0x2c, 0xa5, 0x8f, 0xb8, 0x5f, 0xf1, 0xb8, 0x1c, 310c87c5fbaSopenharmony_ci 0x0b, 0x71, 0x81, 0xb8, 0x5e 311c87c5fbaSopenharmony_ci }; 312c87c5fbaSopenharmony_ci static const uint8_t recipient_nonce[] = { 313c87c5fbaSopenharmony_ci 0x2d, 0xa5, 0x8f, 0xb8, 0x5f, 0xf1, 0xb8, 0x1d, 314c87c5fbaSopenharmony_ci 0x0b, 0x71, 0x81, 0xb8, 0x5e 315c87c5fbaSopenharmony_ci }; 316c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 317c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 318c87c5fbaSopenharmony_ci }; 319c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 320c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 321c87c5fbaSopenharmony_ci cose_encrypt0_t cose[1]; 322c87c5fbaSopenharmony_ci uint8_t nonce_buffer[13]; 323c87c5fbaSopenharmony_ci coap_bin_const_t nonce = { 13, nonce_buffer }; 324c87c5fbaSopenharmony_ci 325c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 326c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 0); 327c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 328c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 329c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 330c87c5fbaSopenharmony_ci 331c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_key, ctx->p_osc_ctx->sender_context->sender_key)); 332c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_key, 333c87c5fbaSopenharmony_ci ctx->p_osc_ctx->recipient_chain->recipient_key)); 334c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(common_iv, ctx->p_osc_ctx->common_iv)); 335c87c5fbaSopenharmony_ci 336c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 337c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->recipient_chain->recipient_id); 338c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 339c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 340c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_nonce, &nonce)); 341c87c5fbaSopenharmony_ci 342c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 343c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->sender_context->sender_id); 344c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 345c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 346c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_nonce, &nonce)); 347c87c5fbaSopenharmony_ci 348c87c5fbaSopenharmony_cifail: 349c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 350c87c5fbaSopenharmony_ci} 351c87c5fbaSopenharmony_ci 352c87c5fbaSopenharmony_ci/* C.3.2. Test Vector 3: Key Derivation with ID Context, Server */ 353c87c5fbaSopenharmony_cistatic void 354c87c5fbaSopenharmony_cit_oscore_c_3_2(void) { 355c87c5fbaSopenharmony_ci static const char conf_data[] = 356c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 357c87c5fbaSopenharmony_ci "master_salt,hex,\"9e7ca92223786340\"\n" 358c87c5fbaSopenharmony_ci "id_context,hex,\"37cbf3210017a2d3\"\n" 359c87c5fbaSopenharmony_ci "sender_id,hex,\"01\"\n" 360c87c5fbaSopenharmony_ci "recipient_id,hex,\"\"\n"; 361c87c5fbaSopenharmony_ci static const uint8_t sender_key[] = { 362c87c5fbaSopenharmony_ci 0xe3, 0x9a, 0x0c, 0x7c, 0x77, 0xb4, 0x3f, 0x03, 363c87c5fbaSopenharmony_ci 0xb4, 0xb3, 0x9a, 0xb9, 0xa2, 0x68, 0x69, 0x9f 364c87c5fbaSopenharmony_ci }; 365c87c5fbaSopenharmony_ci static const uint8_t recipient_key[] = { 366c87c5fbaSopenharmony_ci 0xaf, 0x2a, 0x13, 0x00, 0xa5, 0xe9, 0x57, 0x88, 367c87c5fbaSopenharmony_ci 0xb3, 0x56, 0x33, 0x6e, 0xee, 0xcd, 0x2b, 0x92 368c87c5fbaSopenharmony_ci }; 369c87c5fbaSopenharmony_ci static const uint8_t common_iv[] = { 370c87c5fbaSopenharmony_ci 0x2c, 0xa5, 0x8f, 0xb8, 0x5f, 0xf1, 0xb8, 0x1c, 371c87c5fbaSopenharmony_ci 0x0b, 0x71, 0x81, 0xb8, 0x5e 372c87c5fbaSopenharmony_ci }; 373c87c5fbaSopenharmony_ci static const uint8_t sender_nonce[] = { 374c87c5fbaSopenharmony_ci 0x2d, 0xa5, 0x8f, 0xb8, 0x5f, 0xf1, 0xb8, 0x1d, 375c87c5fbaSopenharmony_ci 0x0b, 0x71, 0x81, 0xb8, 0x5e 376c87c5fbaSopenharmony_ci }; 377c87c5fbaSopenharmony_ci static const uint8_t recipient_nonce[] = { 378c87c5fbaSopenharmony_ci 0x2c, 0xa5, 0x8f, 0xb8, 0x5f, 0xf1, 0xb8, 0x1c, 379c87c5fbaSopenharmony_ci 0x0b, 0x71, 0x81, 0xb8, 0x5e 380c87c5fbaSopenharmony_ci }; 381c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 382c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 383c87c5fbaSopenharmony_ci }; 384c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 385c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 386c87c5fbaSopenharmony_ci cose_encrypt0_t cose[1]; 387c87c5fbaSopenharmony_ci uint8_t nonce_buffer[13]; 388c87c5fbaSopenharmony_ci coap_bin_const_t nonce = { 13, nonce_buffer }; 389c87c5fbaSopenharmony_ci 390c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 391c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 0); 392c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 393c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 394c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 395c87c5fbaSopenharmony_ci 396c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_key, ctx->p_osc_ctx->sender_context->sender_key)); 397c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_key, 398c87c5fbaSopenharmony_ci ctx->p_osc_ctx->recipient_chain->recipient_key)); 399c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(common_iv, ctx->p_osc_ctx->common_iv)); 400c87c5fbaSopenharmony_ci 401c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 402c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->recipient_chain->recipient_id); 403c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 404c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 405c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(recipient_nonce, &nonce)); 406c87c5fbaSopenharmony_ci 407c87c5fbaSopenharmony_ci cose_encrypt0_init(cose); 408c87c5fbaSopenharmony_ci cose_encrypt0_set_key_id(cose, ctx->p_osc_ctx->sender_context->sender_id); 409c87c5fbaSopenharmony_ci cose_encrypt0_set_partial_iv(cose, NULL); 410c87c5fbaSopenharmony_ci oscore_generate_nonce(cose, ctx->p_osc_ctx, nonce_buffer, 13); 411c87c5fbaSopenharmony_ci CU_ASSERT(CHECK_SAME(sender_nonce, &nonce)); 412c87c5fbaSopenharmony_ci 413c87c5fbaSopenharmony_cifail: 414c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 415c87c5fbaSopenharmony_ci} 416c87c5fbaSopenharmony_ci 417c87c5fbaSopenharmony_ci/* C.4. Test Vector 4: OSCORE Request, Client */ 418c87c5fbaSopenharmony_cistatic void 419c87c5fbaSopenharmony_cit_oscore_c_4(void) { 420c87c5fbaSopenharmony_ci static const char conf_data[] = 421c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 422c87c5fbaSopenharmony_ci "master_salt,hex,\"9e7ca92223786340\"\n" 423c87c5fbaSopenharmony_ci "sender_id,hex,\"\"\n" 424c87c5fbaSopenharmony_ci "recipient_id,hex,\"01\"\n"; 425c87c5fbaSopenharmony_ci static const uint8_t unprotected_coap_request[] = { 426c87c5fbaSopenharmony_ci 0x44, 0x01, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 427c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 428c87c5fbaSopenharmony_ci 0x73, 0x74, 0x83, 0x74, 0x76, 0x31 429c87c5fbaSopenharmony_ci }; 430c87c5fbaSopenharmony_ci static const uint8_t protected_coap_request[] = { 431c87c5fbaSopenharmony_ci 0x44, 0x02, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 432c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 433c87c5fbaSopenharmony_ci 0x73, 0x74, 0x62, 0x09, 0x14, 0xff, 0x61, 0x2f, 434c87c5fbaSopenharmony_ci 0x10, 0x92, 0xf1, 0x77, 0x6f, 0x1c, 0x16, 0x68, 435c87c5fbaSopenharmony_ci 0xb3, 0x82, 0x5e 436c87c5fbaSopenharmony_ci }; 437c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 438c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 439c87c5fbaSopenharmony_ci }; 440c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 441c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 442c87c5fbaSopenharmony_ci int result; 443c87c5fbaSopenharmony_ci coap_pdu_t *pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU); 444c87c5fbaSopenharmony_ci coap_pdu_t *osc_pdu = NULL; 445c87c5fbaSopenharmony_ci coap_session_t *session = NULL; 446c87c5fbaSopenharmony_ci 447c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 448c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(pdu); 449c87c5fbaSopenharmony_ci 450c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 20); 451c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 452c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 453c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 454c87c5fbaSopenharmony_ci 455c87c5fbaSopenharmony_ci result = coap_pdu_parse(COAP_PROTO_UDP, unprotected_coap_request, 456c87c5fbaSopenharmony_ci sizeof(unprotected_coap_request), pdu); 457c87c5fbaSopenharmony_ci CU_ASSERT(result > 0); 458c87c5fbaSopenharmony_ci 459c87c5fbaSopenharmony_ci session = coap_malloc_type(COAP_SESSION, sizeof(coap_session_t)); 460c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(session); 461c87c5fbaSopenharmony_ci memset(session, 0, sizeof(coap_session_t)); 462c87c5fbaSopenharmony_ci session->proto = COAP_PROTO_UDP; 463c87c5fbaSopenharmony_ci session->type = COAP_SESSION_TYPE_CLIENT; 464c87c5fbaSopenharmony_ci session->recipient_ctx = ctx->p_osc_ctx->recipient_chain; 465c87c5fbaSopenharmony_ci 466c87c5fbaSopenharmony_ci osc_pdu = coap_oscore_new_pdu_encrypted(session, pdu, NULL, 0); 467c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(osc_pdu); 468c87c5fbaSopenharmony_ci 469c87c5fbaSopenharmony_ci result = coap_pdu_encode_header(osc_pdu, session->proto); 470c87c5fbaSopenharmony_ci CU_ASSERT(result != 0); 471c87c5fbaSopenharmony_ci CU_ASSERT(osc_pdu->hdr_size + osc_pdu->used_size == 472c87c5fbaSopenharmony_ci sizeof(protected_coap_request)); 473c87c5fbaSopenharmony_ci result = memcmp(&osc_pdu->token[-osc_pdu->hdr_size], protected_coap_request, 474c87c5fbaSopenharmony_ci osc_pdu->hdr_size + osc_pdu->used_size); 475c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 476c87c5fbaSopenharmony_ci 477c87c5fbaSopenharmony_cifail: 478c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 479c87c5fbaSopenharmony_ci coap_delete_pdu(pdu); 480c87c5fbaSopenharmony_ci coap_delete_pdu(osc_pdu); 481c87c5fbaSopenharmony_ci oscore_delete_server_associations(session); 482c87c5fbaSopenharmony_ci coap_free(session); 483c87c5fbaSopenharmony_ci} 484c87c5fbaSopenharmony_ci 485c87c5fbaSopenharmony_ci/* C.5. Test Vector 5: OSCORE Request, Client */ 486c87c5fbaSopenharmony_cistatic void 487c87c5fbaSopenharmony_cit_oscore_c_5(void) { 488c87c5fbaSopenharmony_ci static const char conf_data[] = 489c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 490c87c5fbaSopenharmony_ci "sender_id,hex,\"00\"\n" 491c87c5fbaSopenharmony_ci "recipient_id,hex,\"01\"\n"; 492c87c5fbaSopenharmony_ci static const uint8_t unprotected_coap_request[] = { 493c87c5fbaSopenharmony_ci 0x44, 0x01, 0x71, 0xc3, 0x00, 0x00, 0xb9, 0x32, 494c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 495c87c5fbaSopenharmony_ci 0x73, 0x74, 0x83, 0x74, 0x76, 0x31 496c87c5fbaSopenharmony_ci }; 497c87c5fbaSopenharmony_ci static const uint8_t protected[] = { 498c87c5fbaSopenharmony_ci 0x44, 0x02, 0x71, 0xc3, 0x00, 0x00, 0xb9, 0x32, 499c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 500c87c5fbaSopenharmony_ci 0x73, 0x74, 0x63, 0x09, 0x14, 0x00, 0xff, 0x4e, 501c87c5fbaSopenharmony_ci 0xd3, 0x39, 0xa5, 0xa3, 0x79, 0xb0, 0xb8, 0xbc, 502c87c5fbaSopenharmony_ci 0x73, 0x1f, 0xff, 0xb0 503c87c5fbaSopenharmony_ci }; 504c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 505c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 506c87c5fbaSopenharmony_ci }; 507c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 508c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 509c87c5fbaSopenharmony_ci int result; 510c87c5fbaSopenharmony_ci coap_pdu_t *pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU); 511c87c5fbaSopenharmony_ci coap_pdu_t *osc_pdu = NULL; 512c87c5fbaSopenharmony_ci coap_session_t *session = NULL; 513c87c5fbaSopenharmony_ci 514c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 515c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(pdu); 516c87c5fbaSopenharmony_ci 517c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 20); 518c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 519c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 520c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 521c87c5fbaSopenharmony_ci 522c87c5fbaSopenharmony_ci result = coap_pdu_parse(COAP_PROTO_UDP, unprotected_coap_request, 523c87c5fbaSopenharmony_ci sizeof(unprotected_coap_request), pdu); 524c87c5fbaSopenharmony_ci CU_ASSERT(result > 0); 525c87c5fbaSopenharmony_ci 526c87c5fbaSopenharmony_ci session = coap_malloc_type(COAP_SESSION, sizeof(coap_session_t)); 527c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(session); 528c87c5fbaSopenharmony_ci memset(session, 0, sizeof(coap_session_t)); 529c87c5fbaSopenharmony_ci session->proto = COAP_PROTO_UDP; 530c87c5fbaSopenharmony_ci session->type = COAP_SESSION_TYPE_CLIENT; 531c87c5fbaSopenharmony_ci session->recipient_ctx = ctx->p_osc_ctx->recipient_chain; 532c87c5fbaSopenharmony_ci 533c87c5fbaSopenharmony_ci osc_pdu = coap_oscore_new_pdu_encrypted(session, pdu, NULL, 0); 534c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(osc_pdu); 535c87c5fbaSopenharmony_ci 536c87c5fbaSopenharmony_ci result = coap_pdu_encode_header(osc_pdu, session->proto); 537c87c5fbaSopenharmony_ci CU_ASSERT(result != 0); 538c87c5fbaSopenharmony_ci CU_ASSERT(osc_pdu->hdr_size + osc_pdu->used_size == sizeof(protected)); 539c87c5fbaSopenharmony_ci result = memcmp(&osc_pdu->token[-osc_pdu->hdr_size], protected, 540c87c5fbaSopenharmony_ci osc_pdu->hdr_size + osc_pdu->used_size); 541c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 542c87c5fbaSopenharmony_ci 543c87c5fbaSopenharmony_cifail: 544c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 545c87c5fbaSopenharmony_ci coap_delete_pdu(pdu); 546c87c5fbaSopenharmony_ci coap_delete_pdu(osc_pdu); 547c87c5fbaSopenharmony_ci oscore_delete_server_associations(session); 548c87c5fbaSopenharmony_ci coap_free(session); 549c87c5fbaSopenharmony_ci} 550c87c5fbaSopenharmony_ci 551c87c5fbaSopenharmony_ci/* C.6. Test Vector 6: OSCORE Request, Client */ 552c87c5fbaSopenharmony_cistatic void 553c87c5fbaSopenharmony_cit_oscore_c_6(void) { 554c87c5fbaSopenharmony_ci static const char conf_data[] = 555c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 556c87c5fbaSopenharmony_ci "master_salt,hex,\"9e7ca92223786340\"\n" 557c87c5fbaSopenharmony_ci "id_context,hex,\"37cbf3210017a2d3\"\n" 558c87c5fbaSopenharmony_ci "sender_id,hex,\"\"\n" 559c87c5fbaSopenharmony_ci "recipient_id,hex,\"01\"\n"; 560c87c5fbaSopenharmony_ci static const uint8_t unprotected_coap_request[] = { 561c87c5fbaSopenharmony_ci 0x44, 0x01, 0x2f, 0x8e, 0xef, 0x9b, 0xbf, 0x7a, 562c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 563c87c5fbaSopenharmony_ci 0x73, 0x74, 0x83, 0x74, 0x76, 0x31 564c87c5fbaSopenharmony_ci }; 565c87c5fbaSopenharmony_ci static const uint8_t protected[] = { 566c87c5fbaSopenharmony_ci 0x44, 0x02, 0x2f, 0x8e, 0xef, 0x9b, 0xbf, 0x7a, 567c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 568c87c5fbaSopenharmony_ci 0x73, 0x74, 0x6b, 0x19, 0x14, 0x08, 0x37, 0xcb, 569c87c5fbaSopenharmony_ci 0xf3, 0x21, 0x00, 0x17, 0xa2, 0xd3, 0xff, 0x72, 570c87c5fbaSopenharmony_ci 0xcd, 0x72, 0x73, 0xfd, 0x33, 0x1a, 0xc4, 0x5c, 571c87c5fbaSopenharmony_ci 0xff, 0xbe, 0x55, 0xc3 572c87c5fbaSopenharmony_ci }; 573c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 574c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 575c87c5fbaSopenharmony_ci }; 576c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 577c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 578c87c5fbaSopenharmony_ci int result; 579c87c5fbaSopenharmony_ci coap_pdu_t *pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU); 580c87c5fbaSopenharmony_ci coap_pdu_t *osc_pdu = NULL; 581c87c5fbaSopenharmony_ci coap_session_t *session = NULL; 582c87c5fbaSopenharmony_ci 583c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 584c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(pdu); 585c87c5fbaSopenharmony_ci 586c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 20); 587c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 588c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 589c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 590c87c5fbaSopenharmony_ci 591c87c5fbaSopenharmony_ci result = coap_pdu_parse(COAP_PROTO_UDP, unprotected_coap_request, 592c87c5fbaSopenharmony_ci sizeof(unprotected_coap_request), pdu); 593c87c5fbaSopenharmony_ci CU_ASSERT(result > 0); 594c87c5fbaSopenharmony_ci 595c87c5fbaSopenharmony_ci session = coap_malloc_type(COAP_SESSION, sizeof(coap_session_t)); 596c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(session); 597c87c5fbaSopenharmony_ci memset(session, 0, sizeof(coap_session_t)); 598c87c5fbaSopenharmony_ci session->proto = COAP_PROTO_UDP; 599c87c5fbaSopenharmony_ci session->type = COAP_SESSION_TYPE_CLIENT; 600c87c5fbaSopenharmony_ci session->recipient_ctx = ctx->p_osc_ctx->recipient_chain; 601c87c5fbaSopenharmony_ci 602c87c5fbaSopenharmony_ci osc_pdu = coap_oscore_new_pdu_encrypted(session, pdu, NULL, 0); 603c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(osc_pdu); 604c87c5fbaSopenharmony_ci 605c87c5fbaSopenharmony_ci result = coap_pdu_encode_header(osc_pdu, session->proto); 606c87c5fbaSopenharmony_ci CU_ASSERT(result != 0); 607c87c5fbaSopenharmony_ci CU_ASSERT(osc_pdu->hdr_size + osc_pdu->used_size == sizeof(protected)); 608c87c5fbaSopenharmony_ci result = memcmp(&osc_pdu->token[-osc_pdu->hdr_size], protected, 609c87c5fbaSopenharmony_ci osc_pdu->hdr_size + osc_pdu->used_size); 610c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 611c87c5fbaSopenharmony_ci 612c87c5fbaSopenharmony_cifail: 613c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 614c87c5fbaSopenharmony_ci coap_delete_pdu(pdu); 615c87c5fbaSopenharmony_ci coap_delete_pdu(osc_pdu); 616c87c5fbaSopenharmony_ci oscore_delete_server_associations(session); 617c87c5fbaSopenharmony_ci coap_free(session); 618c87c5fbaSopenharmony_ci} 619c87c5fbaSopenharmony_ci 620c87c5fbaSopenharmony_ci/* C.7. Test Vector 7: OSCORE Response, Server */ 621c87c5fbaSopenharmony_cistatic void 622c87c5fbaSopenharmony_cit_oscore_c_7(void) { 623c87c5fbaSopenharmony_ci static const char conf_data[] = 624c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 625c87c5fbaSopenharmony_ci "master_salt,hex,\"9e7ca92223786340\"\n" 626c87c5fbaSopenharmony_ci "sender_id,hex,\"01\"\n" 627c87c5fbaSopenharmony_ci "recipient_id,hex,\"\"\n"; 628c87c5fbaSopenharmony_ci static const uint8_t protected_coap_request[] = { 629c87c5fbaSopenharmony_ci 0x44, 0x02, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 630c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 631c87c5fbaSopenharmony_ci 0x73, 0x74, 0x62, 0x09, 0x14, 0xff, 0x61, 0x2f, 632c87c5fbaSopenharmony_ci 0x10, 0x92, 0xf1, 0x77, 0x6f, 0x1c, 0x16, 0x68, 633c87c5fbaSopenharmony_ci 0xb3, 0x82, 0x5e 634c87c5fbaSopenharmony_ci }; 635c87c5fbaSopenharmony_ci static const uint8_t unprotected_coap_request[] = { 636c87c5fbaSopenharmony_ci 0x44, 0x01, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 637c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 638c87c5fbaSopenharmony_ci 0x73, 0x74, 0x83, 0x74, 0x76, 0x31 639c87c5fbaSopenharmony_ci }; 640c87c5fbaSopenharmony_ci static const uint8_t unprotected_coap_response[] = { 641c87c5fbaSopenharmony_ci 0x64, 0x45, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 642c87c5fbaSopenharmony_ci 0xff, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 643c87c5fbaSopenharmony_ci 0x6f, 0x72, 0x6c, 0x64, 0x21 644c87c5fbaSopenharmony_ci }; 645c87c5fbaSopenharmony_ci static const uint8_t protected_coap_response[] = { 646c87c5fbaSopenharmony_ci 0x64, 0x44, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 647c87c5fbaSopenharmony_ci 0x90, 0xff, 0xdb, 0xaa, 0xd1, 0xe9, 0xa7, 0xe7, 648c87c5fbaSopenharmony_ci 0xb2, 0xa8, 0x13, 0xd3, 0xc3, 0x15, 0x24, 0x37, 649c87c5fbaSopenharmony_ci 0x83, 0x03, 0xcd, 0xaf, 0xae, 0x11, 0x91, 0x06 650c87c5fbaSopenharmony_ci }; 651c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 652c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 653c87c5fbaSopenharmony_ci }; 654c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 655c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 656c87c5fbaSopenharmony_ci int result; 657c87c5fbaSopenharmony_ci coap_pdu_t *incoming_pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU); 658c87c5fbaSopenharmony_ci coap_pdu_t *pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU); 659c87c5fbaSopenharmony_ci coap_pdu_t *osc_pdu = NULL; 660c87c5fbaSopenharmony_ci coap_session_t *session = NULL; 661c87c5fbaSopenharmony_ci 662c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 663c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(incoming_pdu); 664c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(pdu); 665c87c5fbaSopenharmony_ci 666c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 0); 667c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 668c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 669c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 670c87c5fbaSopenharmony_ci 671c87c5fbaSopenharmony_ci result = coap_pdu_parse(COAP_PROTO_UDP, protected_coap_request, 672c87c5fbaSopenharmony_ci sizeof(protected_coap_request), incoming_pdu); 673c87c5fbaSopenharmony_ci CU_ASSERT(result > 0); 674c87c5fbaSopenharmony_ci 675c87c5fbaSopenharmony_ci result = coap_pdu_parse(COAP_PROTO_UDP, unprotected_coap_response, 676c87c5fbaSopenharmony_ci sizeof(unprotected_coap_response), pdu); 677c87c5fbaSopenharmony_ci CU_ASSERT(result > 0); 678c87c5fbaSopenharmony_ci 679c87c5fbaSopenharmony_ci session = coap_malloc_type(COAP_SESSION, sizeof(coap_session_t)); 680c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(session); 681c87c5fbaSopenharmony_ci memset(session, 0, sizeof(coap_session_t)); 682c87c5fbaSopenharmony_ci session->proto = COAP_PROTO_UDP; 683c87c5fbaSopenharmony_ci session->type = COAP_SESSION_TYPE_SERVER; 684c87c5fbaSopenharmony_ci session->recipient_ctx = ctx->p_osc_ctx->recipient_chain; 685c87c5fbaSopenharmony_ci session->recipient_ctx->initial_state = 0; 686c87c5fbaSopenharmony_ci session->context = ctx; 687c87c5fbaSopenharmony_ci 688c87c5fbaSopenharmony_ci /* First, decrypt incoming request to set up all variables for 689c87c5fbaSopenharmony_ci sending response */ 690c87c5fbaSopenharmony_ci osc_pdu = coap_oscore_decrypt_pdu(session, incoming_pdu); 691c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(osc_pdu); 692c87c5fbaSopenharmony_ci result = coap_pdu_encode_header(osc_pdu, session->proto); 693c87c5fbaSopenharmony_ci CU_ASSERT(result != 0); 694c87c5fbaSopenharmony_ci CU_ASSERT(osc_pdu->hdr_size + osc_pdu->used_size == 695c87c5fbaSopenharmony_ci sizeof(unprotected_coap_request)); 696c87c5fbaSopenharmony_ci result = memcmp(&osc_pdu->token[-osc_pdu->hdr_size], unprotected_coap_request, 697c87c5fbaSopenharmony_ci osc_pdu->hdr_size + osc_pdu->used_size); 698c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 699c87c5fbaSopenharmony_ci coap_delete_pdu(osc_pdu); 700c87c5fbaSopenharmony_ci osc_pdu = NULL; 701c87c5fbaSopenharmony_ci coap_delete_pdu(incoming_pdu); 702c87c5fbaSopenharmony_ci incoming_pdu = NULL; 703c87c5fbaSopenharmony_ci 704c87c5fbaSopenharmony_ci /* Now encrypt the server's response */ 705c87c5fbaSopenharmony_ci osc_pdu = coap_oscore_new_pdu_encrypted(session, pdu, NULL, 0); 706c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(osc_pdu); 707c87c5fbaSopenharmony_ci 708c87c5fbaSopenharmony_ci result = coap_pdu_encode_header(osc_pdu, session->proto); 709c87c5fbaSopenharmony_ci CU_ASSERT(result != 0); 710c87c5fbaSopenharmony_ci CU_ASSERT(osc_pdu->hdr_size + osc_pdu->used_size == 711c87c5fbaSopenharmony_ci sizeof(protected_coap_response)); 712c87c5fbaSopenharmony_ci result = memcmp(&osc_pdu->token[-osc_pdu->hdr_size], protected_coap_response, 713c87c5fbaSopenharmony_ci osc_pdu->hdr_size + osc_pdu->used_size); 714c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 715c87c5fbaSopenharmony_ci 716c87c5fbaSopenharmony_cifail: 717c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 718c87c5fbaSopenharmony_ci coap_delete_pdu(pdu); 719c87c5fbaSopenharmony_ci coap_delete_pdu(incoming_pdu); 720c87c5fbaSopenharmony_ci coap_delete_pdu(osc_pdu); 721c87c5fbaSopenharmony_ci oscore_delete_server_associations(session); 722c87c5fbaSopenharmony_ci coap_free(session); 723c87c5fbaSopenharmony_ci} 724c87c5fbaSopenharmony_ci 725c87c5fbaSopenharmony_ci/* 726c87c5fbaSopenharmony_ci * Decrypt the encrypted response from C.7 and check it matches input 727c87c5fbaSopenharmony_ci */ 728c87c5fbaSopenharmony_cistatic void 729c87c5fbaSopenharmony_cit_oscore_c_7_2(void) { 730c87c5fbaSopenharmony_ci static const char conf_data[] = 731c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 732c87c5fbaSopenharmony_ci "master_salt,hex,\"9e7ca92223786340\"\n" 733c87c5fbaSopenharmony_ci "sender_id,hex,\"\"\n" 734c87c5fbaSopenharmony_ci "recipient_id,hex,\"01\"\n"; 735c87c5fbaSopenharmony_ci static const uint8_t unprotected_coap_request[] = { 736c87c5fbaSopenharmony_ci 0x44, 0x01, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 737c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 738c87c5fbaSopenharmony_ci 0x73, 0x74, 0x83, 0x74, 0x76, 0x31 739c87c5fbaSopenharmony_ci }; 740c87c5fbaSopenharmony_ci static const uint8_t protected_coap_request[] = { 741c87c5fbaSopenharmony_ci 0x44, 0x02, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 742c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 743c87c5fbaSopenharmony_ci 0x73, 0x74, 0x62, 0x09, 0x14, 0xff, 0x61, 0x2f, 744c87c5fbaSopenharmony_ci 0x10, 0x92, 0xf1, 0x77, 0x6f, 0x1c, 0x16, 0x68, 745c87c5fbaSopenharmony_ci 0xb3, 0x82, 0x5e 746c87c5fbaSopenharmony_ci }; 747c87c5fbaSopenharmony_ci static const uint8_t unprotected_coap_response[] = { 748c87c5fbaSopenharmony_ci 0x64, 0x45, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 749c87c5fbaSopenharmony_ci 0xff, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 750c87c5fbaSopenharmony_ci 0x6f, 0x72, 0x6c, 0x64, 0x21 751c87c5fbaSopenharmony_ci }; 752c87c5fbaSopenharmony_ci static const uint8_t protected_coap_response[] = { 753c87c5fbaSopenharmony_ci 0x64, 0x44, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 754c87c5fbaSopenharmony_ci 0x90, 0xff, 0xdb, 0xaa, 0xd1, 0xe9, 0xa7, 0xe7, 755c87c5fbaSopenharmony_ci 0xb2, 0xa8, 0x13, 0xd3, 0xc3, 0x15, 0x24, 0x37, 756c87c5fbaSopenharmony_ci 0x83, 0x03, 0xcd, 0xaf, 0xae, 0x11, 0x91, 0x06 757c87c5fbaSopenharmony_ci }; 758c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 759c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 760c87c5fbaSopenharmony_ci }; 761c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 762c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 763c87c5fbaSopenharmony_ci int result; 764c87c5fbaSopenharmony_ci coap_pdu_t *outgoing_pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU); 765c87c5fbaSopenharmony_ci coap_pdu_t *incoming_pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU); 766c87c5fbaSopenharmony_ci coap_pdu_t *osc_pdu = NULL; 767c87c5fbaSopenharmony_ci coap_session_t *session = NULL; 768c87c5fbaSopenharmony_ci 769c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 770c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(outgoing_pdu); 771c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(incoming_pdu); 772c87c5fbaSopenharmony_ci 773c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 20); 774c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 775c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 776c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 777c87c5fbaSopenharmony_ci 778c87c5fbaSopenharmony_ci result = coap_pdu_parse(COAP_PROTO_UDP, unprotected_coap_request, 779c87c5fbaSopenharmony_ci sizeof(unprotected_coap_request), outgoing_pdu); 780c87c5fbaSopenharmony_ci CU_ASSERT(result > 0); 781c87c5fbaSopenharmony_ci result = coap_pdu_parse(COAP_PROTO_UDP, protected_coap_response, 782c87c5fbaSopenharmony_ci sizeof(protected_coap_response), incoming_pdu); 783c87c5fbaSopenharmony_ci CU_ASSERT(result > 0); 784c87c5fbaSopenharmony_ci 785c87c5fbaSopenharmony_ci session = coap_malloc_type(COAP_SESSION, sizeof(coap_session_t)); 786c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(session); 787c87c5fbaSopenharmony_ci memset(session, 0, sizeof(coap_session_t)); 788c87c5fbaSopenharmony_ci session->proto = COAP_PROTO_UDP; 789c87c5fbaSopenharmony_ci session->type = COAP_SESSION_TYPE_CLIENT; 790c87c5fbaSopenharmony_ci session->recipient_ctx = ctx->p_osc_ctx->recipient_chain; 791c87c5fbaSopenharmony_ci session->recipient_ctx->initial_state = 0; 792c87c5fbaSopenharmony_ci session->context = ctx; 793c87c5fbaSopenharmony_ci 794c87c5fbaSopenharmony_ci /* Send request, so that all associations etc. are correctly set up */ 795c87c5fbaSopenharmony_ci 796c87c5fbaSopenharmony_ci osc_pdu = coap_oscore_new_pdu_encrypted(session, outgoing_pdu, NULL, 0); 797c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(osc_pdu); 798c87c5fbaSopenharmony_ci 799c87c5fbaSopenharmony_ci result = coap_pdu_encode_header(osc_pdu, session->proto); 800c87c5fbaSopenharmony_ci CU_ASSERT(result != 0); 801c87c5fbaSopenharmony_ci CU_ASSERT(osc_pdu->hdr_size + osc_pdu->used_size == 802c87c5fbaSopenharmony_ci sizeof(protected_coap_request)); 803c87c5fbaSopenharmony_ci result = memcmp(&osc_pdu->token[-osc_pdu->hdr_size], protected_coap_request, 804c87c5fbaSopenharmony_ci osc_pdu->hdr_size + osc_pdu->used_size); 805c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 806c87c5fbaSopenharmony_ci coap_delete_pdu(outgoing_pdu); 807c87c5fbaSopenharmony_ci outgoing_pdu = NULL; 808c87c5fbaSopenharmony_ci coap_delete_pdu(osc_pdu); 809c87c5fbaSopenharmony_ci osc_pdu = NULL; 810c87c5fbaSopenharmony_ci 811c87c5fbaSopenharmony_ci /* Decrypt the encrypted response */ 812c87c5fbaSopenharmony_ci 813c87c5fbaSopenharmony_ci osc_pdu = coap_oscore_decrypt_pdu(session, incoming_pdu); 814c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(osc_pdu); 815c87c5fbaSopenharmony_ci 816c87c5fbaSopenharmony_ci result = coap_pdu_encode_header(osc_pdu, session->proto); 817c87c5fbaSopenharmony_ci CU_ASSERT(result != 0); 818c87c5fbaSopenharmony_ci CU_ASSERT(osc_pdu->hdr_size + osc_pdu->used_size == 819c87c5fbaSopenharmony_ci sizeof(unprotected_coap_response)); 820c87c5fbaSopenharmony_ci result = memcmp(&osc_pdu->token[-osc_pdu->hdr_size], 821c87c5fbaSopenharmony_ci unprotected_coap_response, 822c87c5fbaSopenharmony_ci osc_pdu->hdr_size + osc_pdu->used_size); 823c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 824c87c5fbaSopenharmony_ci 825c87c5fbaSopenharmony_cifail: 826c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 827c87c5fbaSopenharmony_ci coap_delete_pdu(incoming_pdu); 828c87c5fbaSopenharmony_ci coap_delete_pdu(outgoing_pdu); 829c87c5fbaSopenharmony_ci coap_delete_pdu(osc_pdu); 830c87c5fbaSopenharmony_ci coap_free(session); 831c87c5fbaSopenharmony_ci} 832c87c5fbaSopenharmony_ci 833c87c5fbaSopenharmony_ci/* C.8. Test Vector 8: OSCORE Response with Partial IV, Server */ 834c87c5fbaSopenharmony_cistatic void 835c87c5fbaSopenharmony_cit_oscore_c_8(void) { 836c87c5fbaSopenharmony_ci static const char conf_data[] = 837c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 838c87c5fbaSopenharmony_ci "master_salt,hex,\"9e7ca92223786340\"\n" 839c87c5fbaSopenharmony_ci "sender_id,hex,\"01\"\n" 840c87c5fbaSopenharmony_ci "recipient_id,hex,\"\"\n"; 841c87c5fbaSopenharmony_ci static const uint8_t protected_coap_request[] = { 842c87c5fbaSopenharmony_ci 0x44, 0x02, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 843c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 844c87c5fbaSopenharmony_ci 0x73, 0x74, 0x62, 0x09, 0x14, 0xff, 0x61, 0x2f, 845c87c5fbaSopenharmony_ci 0x10, 0x92, 0xf1, 0x77, 0x6f, 0x1c, 0x16, 0x68, 846c87c5fbaSopenharmony_ci 0xb3, 0x82, 0x5e 847c87c5fbaSopenharmony_ci }; 848c87c5fbaSopenharmony_ci static const uint8_t unprotected_coap_request[] = { 849c87c5fbaSopenharmony_ci 0x44, 0x01, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 850c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 851c87c5fbaSopenharmony_ci 0x73, 0x74, 0x83, 0x74, 0x76, 0x31 852c87c5fbaSopenharmony_ci }; 853c87c5fbaSopenharmony_ci static const uint8_t unprotected_coap_response[] = { 854c87c5fbaSopenharmony_ci 0x64, 0x45, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 855c87c5fbaSopenharmony_ci 0xff, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 856c87c5fbaSopenharmony_ci 0x6f, 0x72, 0x6c, 0x64, 0x21 857c87c5fbaSopenharmony_ci }; 858c87c5fbaSopenharmony_ci static const uint8_t protected_coap_response[] = { 859c87c5fbaSopenharmony_ci 0x64, 0x44, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 860c87c5fbaSopenharmony_ci 0x92, 0x01, 0x00, 0xff, 0x4d, 0x4c, 0x13, 0x66, 861c87c5fbaSopenharmony_ci 0x93, 0x84, 0xb6, 0x73, 0x54, 0xb2, 0xb6, 0x17, 862c87c5fbaSopenharmony_ci 0x5f, 0xf4, 0xb8, 0x65, 0x8c, 0x66, 0x6a, 0x6c, 863c87c5fbaSopenharmony_ci 0xf8, 0x8e 864c87c5fbaSopenharmony_ci }; 865c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 866c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 867c87c5fbaSopenharmony_ci }; 868c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 869c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 870c87c5fbaSopenharmony_ci int result; 871c87c5fbaSopenharmony_ci coap_pdu_t *incoming_pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU); 872c87c5fbaSopenharmony_ci coap_pdu_t *pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU); 873c87c5fbaSopenharmony_ci coap_pdu_t *osc_pdu = NULL; 874c87c5fbaSopenharmony_ci coap_session_t *session = NULL; 875c87c5fbaSopenharmony_ci 876c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 877c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(incoming_pdu); 878c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(pdu); 879c87c5fbaSopenharmony_ci 880c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 0); 881c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 882c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 883c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 884c87c5fbaSopenharmony_ci 885c87c5fbaSopenharmony_ci result = coap_pdu_parse(COAP_PROTO_UDP, protected_coap_request, 886c87c5fbaSopenharmony_ci sizeof(protected_coap_request), incoming_pdu); 887c87c5fbaSopenharmony_ci CU_ASSERT(result > 0); 888c87c5fbaSopenharmony_ci 889c87c5fbaSopenharmony_ci result = coap_pdu_parse(COAP_PROTO_UDP, unprotected_coap_response, 890c87c5fbaSopenharmony_ci sizeof(unprotected_coap_response), pdu); 891c87c5fbaSopenharmony_ci CU_ASSERT(result > 0); 892c87c5fbaSopenharmony_ci 893c87c5fbaSopenharmony_ci session = coap_malloc_type(COAP_SESSION, sizeof(coap_session_t)); 894c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(session); 895c87c5fbaSopenharmony_ci memset(session, 0, sizeof(coap_session_t)); 896c87c5fbaSopenharmony_ci session->proto = COAP_PROTO_UDP; 897c87c5fbaSopenharmony_ci session->type = COAP_SESSION_TYPE_SERVER; 898c87c5fbaSopenharmony_ci session->recipient_ctx = ctx->p_osc_ctx->recipient_chain; 899c87c5fbaSopenharmony_ci session->recipient_ctx->initial_state = 0; 900c87c5fbaSopenharmony_ci session->context = ctx; 901c87c5fbaSopenharmony_ci 902c87c5fbaSopenharmony_ci /* First, decrypt incoming request to set up all variables for 903c87c5fbaSopenharmony_ci sending response */ 904c87c5fbaSopenharmony_ci osc_pdu = coap_oscore_decrypt_pdu(session, incoming_pdu); 905c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(osc_pdu); 906c87c5fbaSopenharmony_ci result = coap_pdu_encode_header(osc_pdu, session->proto); 907c87c5fbaSopenharmony_ci CU_ASSERT(result != 0); 908c87c5fbaSopenharmony_ci CU_ASSERT(osc_pdu->hdr_size + osc_pdu->used_size == 909c87c5fbaSopenharmony_ci sizeof(unprotected_coap_request)); 910c87c5fbaSopenharmony_ci result = memcmp(&osc_pdu->token[-osc_pdu->hdr_size], unprotected_coap_request, 911c87c5fbaSopenharmony_ci osc_pdu->hdr_size + osc_pdu->used_size); 912c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 913c87c5fbaSopenharmony_ci coap_delete_pdu(osc_pdu); 914c87c5fbaSopenharmony_ci osc_pdu = NULL; 915c87c5fbaSopenharmony_ci coap_delete_pdu(incoming_pdu); 916c87c5fbaSopenharmony_ci incoming_pdu = NULL; 917c87c5fbaSopenharmony_ci 918c87c5fbaSopenharmony_ci /* Now encrypt the server's response */ 919c87c5fbaSopenharmony_ci osc_pdu = coap_oscore_new_pdu_encrypted(session, pdu, NULL, 1); 920c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(osc_pdu); 921c87c5fbaSopenharmony_ci 922c87c5fbaSopenharmony_ci result = coap_pdu_encode_header(osc_pdu, session->proto); 923c87c5fbaSopenharmony_ci CU_ASSERT(result != 0); 924c87c5fbaSopenharmony_ci CU_ASSERT(osc_pdu->hdr_size + osc_pdu->used_size == 925c87c5fbaSopenharmony_ci sizeof(protected_coap_response)); 926c87c5fbaSopenharmony_ci result = memcmp(&osc_pdu->token[-osc_pdu->hdr_size], protected_coap_response, 927c87c5fbaSopenharmony_ci osc_pdu->hdr_size + osc_pdu->used_size); 928c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 929c87c5fbaSopenharmony_ci 930c87c5fbaSopenharmony_cifail: 931c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 932c87c5fbaSopenharmony_ci coap_delete_pdu(pdu); 933c87c5fbaSopenharmony_ci coap_delete_pdu(incoming_pdu); 934c87c5fbaSopenharmony_ci coap_delete_pdu(osc_pdu); 935c87c5fbaSopenharmony_ci oscore_delete_server_associations(session); 936c87c5fbaSopenharmony_ci coap_free(session); 937c87c5fbaSopenharmony_ci} 938c87c5fbaSopenharmony_ci 939c87c5fbaSopenharmony_ci/* 940c87c5fbaSopenharmony_ci * Decrypt the encrypted response from C.8 and check it matches input 941c87c5fbaSopenharmony_ci */ 942c87c5fbaSopenharmony_cistatic void 943c87c5fbaSopenharmony_cit_oscore_c_8_2(void) { 944c87c5fbaSopenharmony_ci static const char conf_data[] = 945c87c5fbaSopenharmony_ci "master_secret,hex,\"0102030405060708090a0b0c0d0e0f10\"\n" 946c87c5fbaSopenharmony_ci "master_salt,hex,\"9e7ca92223786340\"\n" 947c87c5fbaSopenharmony_ci "sender_id,hex,\"\"\n" 948c87c5fbaSopenharmony_ci "recipient_id,hex,\"01\"\n"; 949c87c5fbaSopenharmony_ci static const uint8_t unprotected_coap_request[] = { 950c87c5fbaSopenharmony_ci 0x44, 0x01, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 951c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 952c87c5fbaSopenharmony_ci 0x73, 0x74, 0x83, 0x74, 0x76, 0x31 953c87c5fbaSopenharmony_ci }; 954c87c5fbaSopenharmony_ci static const uint8_t protected_coap_request[] = { 955c87c5fbaSopenharmony_ci 0x44, 0x02, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 956c87c5fbaSopenharmony_ci 0x39, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 957c87c5fbaSopenharmony_ci 0x73, 0x74, 0x62, 0x09, 0x14, 0xff, 0x61, 0x2f, 958c87c5fbaSopenharmony_ci 0x10, 0x92, 0xf1, 0x77, 0x6f, 0x1c, 0x16, 0x68, 959c87c5fbaSopenharmony_ci 0xb3, 0x82, 0x5e 960c87c5fbaSopenharmony_ci }; 961c87c5fbaSopenharmony_ci static const uint8_t unprotected_coap_response[] = { 962c87c5fbaSopenharmony_ci 0x64, 0x45, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 963c87c5fbaSopenharmony_ci 0xff, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 964c87c5fbaSopenharmony_ci 0x6f, 0x72, 0x6c, 0x64, 0x21 965c87c5fbaSopenharmony_ci }; 966c87c5fbaSopenharmony_ci static const uint8_t protected_coap_response[] = { 967c87c5fbaSopenharmony_ci 0x64, 0x44, 0x5d, 0x1f, 0x00, 0x00, 0x39, 0x74, 968c87c5fbaSopenharmony_ci 0x92, 0x01, 0x00, 0xff, 0x4d, 0x4c, 0x13, 0x66, 969c87c5fbaSopenharmony_ci 0x93, 0x84, 0xb6, 0x73, 0x54, 0xb2, 0xb6, 0x17, 970c87c5fbaSopenharmony_ci 0x5f, 0xf4, 0xb8, 0x65, 0x8c, 0x66, 0x6a, 0x6c, 971c87c5fbaSopenharmony_ci 0xf8, 0x8e 972c87c5fbaSopenharmony_ci }; 973c87c5fbaSopenharmony_ci const coap_str_const_t conf = { sizeof(conf_data)-1, 974c87c5fbaSopenharmony_ci (const uint8_t *)conf_data 975c87c5fbaSopenharmony_ci }; 976c87c5fbaSopenharmony_ci coap_context_t ctx[1]; 977c87c5fbaSopenharmony_ci coap_oscore_conf_t *oscore_conf; 978c87c5fbaSopenharmony_ci int result; 979c87c5fbaSopenharmony_ci coap_pdu_t *outgoing_pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU); 980c87c5fbaSopenharmony_ci coap_pdu_t *incoming_pdu = coap_pdu_init(0, 0, 0, COAP_DEFAULT_MTU); 981c87c5fbaSopenharmony_ci coap_pdu_t *osc_pdu = NULL; 982c87c5fbaSopenharmony_ci coap_session_t *session = NULL; 983c87c5fbaSopenharmony_ci 984c87c5fbaSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 985c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(outgoing_pdu); 986c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(incoming_pdu); 987c87c5fbaSopenharmony_ci 988c87c5fbaSopenharmony_ci oscore_conf = coap_new_oscore_conf(conf, NULL, NULL, 20); 989c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(oscore_conf); 990c87c5fbaSopenharmony_ci coap_context_oscore_server(ctx, oscore_conf); 991c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(ctx->p_osc_ctx); 992c87c5fbaSopenharmony_ci 993c87c5fbaSopenharmony_ci result = coap_pdu_parse(COAP_PROTO_UDP, unprotected_coap_request, 994c87c5fbaSopenharmony_ci sizeof(unprotected_coap_request), outgoing_pdu); 995c87c5fbaSopenharmony_ci CU_ASSERT(result > 0); 996c87c5fbaSopenharmony_ci result = coap_pdu_parse(COAP_PROTO_UDP, protected_coap_response, 997c87c5fbaSopenharmony_ci sizeof(protected_coap_response), incoming_pdu); 998c87c5fbaSopenharmony_ci CU_ASSERT(result > 0); 999c87c5fbaSopenharmony_ci 1000c87c5fbaSopenharmony_ci session = coap_malloc_type(COAP_SESSION, sizeof(coap_session_t)); 1001c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(session); 1002c87c5fbaSopenharmony_ci memset(session, 0, sizeof(coap_session_t)); 1003c87c5fbaSopenharmony_ci session->proto = COAP_PROTO_UDP; 1004c87c5fbaSopenharmony_ci session->type = COAP_SESSION_TYPE_CLIENT; 1005c87c5fbaSopenharmony_ci session->recipient_ctx = ctx->p_osc_ctx->recipient_chain; 1006c87c5fbaSopenharmony_ci session->context = ctx; 1007c87c5fbaSopenharmony_ci 1008c87c5fbaSopenharmony_ci /* Send request, so that all associations etc. are correctly set up */ 1009c87c5fbaSopenharmony_ci 1010c87c5fbaSopenharmony_ci osc_pdu = coap_oscore_new_pdu_encrypted(session, outgoing_pdu, NULL, 0); 1011c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(osc_pdu); 1012c87c5fbaSopenharmony_ci 1013c87c5fbaSopenharmony_ci result = coap_pdu_encode_header(osc_pdu, session->proto); 1014c87c5fbaSopenharmony_ci CU_ASSERT(result != 0); 1015c87c5fbaSopenharmony_ci CU_ASSERT(osc_pdu->hdr_size + osc_pdu->used_size == 1016c87c5fbaSopenharmony_ci sizeof(protected_coap_request)); 1017c87c5fbaSopenharmony_ci result = memcmp(&osc_pdu->token[-osc_pdu->hdr_size], protected_coap_request, 1018c87c5fbaSopenharmony_ci osc_pdu->hdr_size + osc_pdu->used_size); 1019c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 1020c87c5fbaSopenharmony_ci coap_delete_pdu(outgoing_pdu); 1021c87c5fbaSopenharmony_ci /* CDI 1566477 */ 1022c87c5fbaSopenharmony_ci outgoing_pdu = NULL; 1023c87c5fbaSopenharmony_ci coap_delete_pdu(osc_pdu); 1024c87c5fbaSopenharmony_ci osc_pdu = NULL; 1025c87c5fbaSopenharmony_ci 1026c87c5fbaSopenharmony_ci /* Decrypt the encrypted response */ 1027c87c5fbaSopenharmony_ci 1028c87c5fbaSopenharmony_ci osc_pdu = coap_oscore_decrypt_pdu(session, incoming_pdu); 1029c87c5fbaSopenharmony_ci FailIf_CU_ASSERT_PTR_NOT_NULL(osc_pdu); 1030c87c5fbaSopenharmony_ci 1031c87c5fbaSopenharmony_ci result = coap_pdu_encode_header(osc_pdu, session->proto); 1032c87c5fbaSopenharmony_ci CU_ASSERT(result != 0); 1033c87c5fbaSopenharmony_ci CU_ASSERT(osc_pdu->hdr_size + osc_pdu->used_size == 1034c87c5fbaSopenharmony_ci sizeof(unprotected_coap_response)); 1035c87c5fbaSopenharmony_ci result = memcmp(&osc_pdu->token[-osc_pdu->hdr_size], 1036c87c5fbaSopenharmony_ci unprotected_coap_response, 1037c87c5fbaSopenharmony_ci osc_pdu->hdr_size + osc_pdu->used_size); 1038c87c5fbaSopenharmony_ci CU_ASSERT(result == 0); 1039c87c5fbaSopenharmony_ci 1040c87c5fbaSopenharmony_cifail: 1041c87c5fbaSopenharmony_ci oscore_free_contexts(ctx); 1042c87c5fbaSopenharmony_ci coap_delete_pdu(incoming_pdu); 1043c87c5fbaSopenharmony_ci coap_delete_pdu(outgoing_pdu); 1044c87c5fbaSopenharmony_ci coap_delete_pdu(osc_pdu); 1045c87c5fbaSopenharmony_ci coap_free(session); 1046c87c5fbaSopenharmony_ci} 1047c87c5fbaSopenharmony_ci 1048c87c5fbaSopenharmony_ci/************************************************************************ 1049c87c5fbaSopenharmony_ci ** initialization 1050c87c5fbaSopenharmony_ci ************************************************************************/ 1051c87c5fbaSopenharmony_ci 1052c87c5fbaSopenharmony_ciCU_pSuite 1053c87c5fbaSopenharmony_cit_init_oscore_tests(void) { 1054c87c5fbaSopenharmony_ci CU_pSuite suite[5]; 1055c87c5fbaSopenharmony_ci 1056c87c5fbaSopenharmony_ci suite[0] = CU_add_suite("RFC8613 Appendix C OSCORE tests", NULL, NULL); 1057c87c5fbaSopenharmony_ci if (!suite[0]) { /* signal error */ 1058c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add OSCORE test suite (%s)\n", 1059c87c5fbaSopenharmony_ci CU_get_error_msg()); 1060c87c5fbaSopenharmony_ci 1061c87c5fbaSopenharmony_ci return NULL; 1062c87c5fbaSopenharmony_ci } 1063c87c5fbaSopenharmony_ci 1064c87c5fbaSopenharmony_ci#define OSCORE_TEST(n) \ 1065c87c5fbaSopenharmony_ci if (!CU_add_test(suite[0], #n, n)) { \ 1066c87c5fbaSopenharmony_ci fprintf(stderr, "W: cannot add OSCORE test (%s)\n", \ 1067c87c5fbaSopenharmony_ci CU_get_error_msg()); \ 1068c87c5fbaSopenharmony_ci } 1069c87c5fbaSopenharmony_ci 1070c87c5fbaSopenharmony_ci if (coap_oscore_is_supported()) { 1071c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_1_1); 1072c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_1_2); 1073c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_2_1); 1074c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_2_2); 1075c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_3_1); 1076c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_3_2); 1077c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_4); 1078c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_5); 1079c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_6); 1080c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_7); 1081c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_7_2); 1082c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_8); 1083c87c5fbaSopenharmony_ci OSCORE_TEST(t_oscore_c_8_2); 1084c87c5fbaSopenharmony_ci } 1085c87c5fbaSopenharmony_ci 1086c87c5fbaSopenharmony_ci return suite[0]; 1087c87c5fbaSopenharmony_ci} 1088c87c5fbaSopenharmony_ci 1089c87c5fbaSopenharmony_ci#else /* COAP_OSCORE_SUPPORT && COAP_SERVER_SUPPORT */ 1090c87c5fbaSopenharmony_ci 1091c87c5fbaSopenharmony_ci#ifdef __clang__ 1092c87c5fbaSopenharmony_ci/* Make compilers happy that do not like empty modules. As this function is 1093c87c5fbaSopenharmony_ci * never used, we ignore -Wunused-function at the end of compiling this file 1094c87c5fbaSopenharmony_ci */ 1095c87c5fbaSopenharmony_ci#pragma GCC diagnostic ignored "-Wunused-function" 1096c87c5fbaSopenharmony_ci#endif 1097c87c5fbaSopenharmony_cistatic inline void 1098c87c5fbaSopenharmony_cidummy(void) { 1099c87c5fbaSopenharmony_ci} 1100c87c5fbaSopenharmony_ci 1101c87c5fbaSopenharmony_ci#endif /* COAP_OSCORE_SUPPORT && COAP_SERVER_SUPPORT */ 1102