Commit 17a9833e authored by Olaf Bergmann's avatar Olaf Bergmann

dcaf_transaction.c: fix aud parameter

aud is now set to coaps://host where host is the address we use
to reach S.
parent 960d898c
......@@ -32,8 +32,16 @@ extern "C" {
* identifier. */
typedef uint8_t dcaf_transaction_id_t[DCAF_DEFAULT_TOKEN_SIZE];
typedef struct dcaf_host_t dcaf_host_t;
struct dcaf_host_t {
char *s;
size_t length;
};
struct dcaf_transaction_t {
dcaf_transaction_t *next;
dcaf_host_t aud; /* contents of the audience parameter */
coap_endpoint_t *local_interface;
coap_address_t remote;
coap_block_t block;
......
......@@ -120,14 +120,12 @@ am_error_handler(dcaf_context_t *dcaf_context,
#endif
static size_t
make_ticket_request(dcaf_context_t *dcaf_context,
const dcaf_transaction_t *transaction,
make_ticket_request(const dcaf_transaction_t *transaction,
const uint8_t *data, size_t data_len,
uint8_t *result, size_t max_result_len) {
cn_cbor *req = dcaf_cbor_decode(data, data_len, NULL);
cn_cbor *scope;
size_t len;
dcaf_key_t *key;
uint8_t buf[DCAF_MAX_RESOURCE_LEN+1];
size_t length = sizeof(buf);
......@@ -135,14 +133,14 @@ make_ticket_request(dcaf_context_t *dcaf_context,
return 0;
}
key = dcaf_find_key(dcaf_context, &dcaf_context->am_address, NULL, 0);
if (key) {
if (transaction->aud.length > 0) {
assert(transaction->aud.s);
dcaf_cbor_mapput_int(req, DCAF_TICKET_AUD,
dcaf_cbor_data_create(key->kid, key->kid_length, NULL),
dcaf_cbor_data_create((uint8_t *)transaction->aud.s, transaction->aud.length, NULL),
NULL);
} else {
dcaf_log(DCAF_LOG_WARNING,
"cannot set aud parameter (AM key not found)\n");
"cannot set aud parameter\n");
}
/* create scope from initial request data */
......@@ -198,8 +196,7 @@ handle_unauthorized(dcaf_context_t *dcaf_context,
uint8_t ticket_req[512];
size_t len;
len = make_ticket_request(dcaf_context, t,
data, data_len,
len = make_ticket_request(t, data, data_len,
ticket_req, sizeof(ticket_req));
if (len > 0) {
/* FIXME: Set Content-Format to DCAF_MEDIATYPE_DCAF_CBOR */
......
......@@ -140,7 +140,8 @@ dcaf_delete_transaction(dcaf_context_t *dcaf_context,
if (transaction) {
LL_DELETE(dcaf_context->transactions, transaction);
coap_delete_pdu(transaction->pdu);
coap_free(transaction);
dcaf_free_type(DCAF_STRING, transaction->aud.s);
dcaf_free_type(DCAF_TRANSACTION, transaction);
}
}
......@@ -344,6 +345,18 @@ dcaf_send_request_uri(dcaf_context_t *dcaf_context,
dcaf_log(DCAF_LOG_WARNING, "cannot create new transaction\n");
goto error;
}
{
const char aud_prefix[] = { 'c', 'o', 'a', 'p', 's', ':', '/', '/' };
t->aud.s = dcaf_alloc_type_len(DCAF_STRING, uri->host.length + sizeof(aud_prefix));
if (t->aud.s) {
t->aud.length = uri->host.length + sizeof(aud_prefix);
memcpy(t->aud.s, aud_prefix, sizeof(aud_prefix));
memcpy(t->aud.s + sizeof(aud_prefix), uri->host.s, uri->host.length);
} else {
memset(&t->aud, 0, sizeof(t->aud));
dcaf_log(DCAF_LOG_WARNING, "cannot store aud info: buffer too small.\n");
}
}
t->application_handler = app_hnd;
dcaf_log(DCAF_LOG_DEBUG, "added transaction %02x%02x%02x%02x\n",
t->tid[0], t->tid[1], t->tid[2], t->tid[3]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment