mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-30 10:17:08 +03:00
dtls: Added basic keystore implementation
coap_keystore.[hc] provides a simple data structure for managing credentials to be used during DTLS handshake. Each coap_context_t has its own keystore object that is independent of the actual DTLS context. Applications can access the keystore during the entire lifetime of the coap context. The existing implementation is not thread-safe.
This commit is contained in:
1 parent
e3b82756c0
commit
90fb5fdffc
7 files changed
+265
-7
No files matched your search
@@ -15,6 +15,8 @@
|
||||
#ifndef _COAP_ASYNC_H_
|
||||
#define _COAP_ASYNC_H_
|
||||
|
||||
#include "coap_time.h"
|
||||
#include "pdu.h"
|
||||
#include "net.h"
|
||||
|
||||
#ifndef WITHOUT_ASYNC
|
||||
|
||||
@@ -36,6 +36,8 @@ extern "C" {
|
||||
#include "async.h"
|
||||
#include "bits.h"
|
||||
#include "block.h"
|
||||
#include "coap_dtls.h"
|
||||
#include "coap_keystore.h"
|
||||
#include "coap_io.h"
|
||||
#include "coap_time.h"
|
||||
#include "debug.h"
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* coap_keystore.h -- libcoap keystore
|
||||
*
|
||||
* Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see README for terms
|
||||
* of use.
|
||||
*/
|
||||
|
||||
#ifndef _COAP_KEYSTORE_H_
|
||||
#define _COAP_KEYSTORE_H_
|
||||
|
||||
#include "coap_config.h"
|
||||
#include "address.h"
|
||||
|
||||
/**
|
||||
* @defgroup keys Keystore
|
||||
* Generic container to store keys for secure communication.
|
||||
* @{
|
||||
*/
|
||||
|
||||
struct coap_keystore_t;
|
||||
typedef struct coap_keystore_t coap_keystore_t;
|
||||
struct coap_keystore_item_t;
|
||||
typedef struct coap_keystore_item_t coap_keystore_item_t;
|
||||
|
||||
coap_keystore_t *coap_new_keystore(void);
|
||||
|
||||
void coap_free_keystore(coap_keystore_t *keystore);
|
||||
|
||||
#define COAP_KEYSTORE_RELEASE_REALM 0x01
|
||||
#define COAP_KEYSTORE_RELEASE_ID 0x02
|
||||
#define COAP_KEYSTORE_RELEASE_KEY 0x04
|
||||
|
||||
coap_keystore_item_t *
|
||||
coap_keystore_new_psk(void *realm, size_t realm_length,
|
||||
void *id, size_t id_length,
|
||||
void *key, size_t key_length,
|
||||
int flags);
|
||||
|
||||
|
||||
void coap_keystore_free_item(coap_keystore_item_t *item);
|
||||
|
||||
int coap_keystore_store_item(coap_keystore_t *keystore,
|
||||
coap_keystore_item_t *item,
|
||||
const coap_address_t *remote);
|
||||
|
||||
void coap_keystore_remove_item(coap_keystore_t *keystore,
|
||||
coap_keystore_item_t *item);
|
||||
|
||||
coap_keystore_item_t *coap_keystore_find_psk(const coap_keystore_t *keystore,
|
||||
const void *realm,
|
||||
size_t realm_length,
|
||||
const void *id,
|
||||
size_t identity_length,
|
||||
const coap_address_t *remote);
|
||||
|
||||
ssize_t coap_psk_set_identity(const coap_keystore_item_t *psk,
|
||||
uint8_t *buf, size_t max_len);
|
||||
|
||||
ssize_t coap_psk_set_key(const coap_keystore_item_t *psk,
|
||||
uint8_t *buf, size_t max_len);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* COAP_KEYSTORE_H */
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "coap_io.h"
|
||||
#include "coap_dtls.h"
|
||||
#include "coap_keystore.h"
|
||||
#include "coap_time.h"
|
||||
#include "option.h"
|
||||
#include "pdu.h"
|
||||
@@ -125,6 +126,7 @@ typedef struct coap_context_t {
|
||||
|
||||
ssize_t (*network_read)(coap_endpoint_t *ep, coap_packet_t **packet);
|
||||
|
||||
coap_keystore_t *keystore;
|
||||
struct coap_dtls_context_t *dtls_context;
|
||||
} coap_context_t;
|
||||
|
||||
|
||||
Reference in new issue
Block a user