Anjay Lite
Loading...
Searching...
No Matches
security_object.h File Reference

Default implementation of the LwM2M Security Object (/0). More...

#include <anj/init.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <anj/defs.h>
#include <anj/dm/core.h>
#include <anj/persistence.h>
#include <anj/crypto.h>

Go to the source code of this file.

Data Structures

struct  anj_dm_security_instance_t
 
struct  anj_dm_security_instance_init_t
 
struct  anj_dm_security_obj_t
 

Enumerations

enum  anj_dm_security_mode_t {
  ANJ_DM_SECURITY_PSK = 0 , ANJ_DM_SECURITY_RPK = 1 , ANJ_DM_SECURITY_CERTIFICATE = 2 , ANJ_DM_SECURITY_NOSEC = 3 ,
  ANJ_DM_SECURITY_EST = 4
}
 

Functions

void anj_dm_security_obj_init (anj_dm_security_obj_t *security_obj_ctx)
 
int anj_dm_security_obj_add_instance (anj_dm_security_obj_t *security_obj_ctx, const anj_dm_security_instance_init_t *instance)
 
int anj_dm_security_obj_install (anj_t *anj, anj_dm_security_obj_t *security_obj_ctx)
 
int anj_dm_security_obj_get_psk (const anj_t *anj, bool bootstrap_credentials, anj_crypto_security_info_t *out_psk_identity, anj_crypto_security_info_t *out_psk_key)
 
int anj_dm_security_obj_store (anj_t *anj, anj_dm_security_obj_t *security_obj_ctx, const anj_persistence_context_t *ctx)
 
int anj_dm_security_obj_restore (anj_t *anj, anj_dm_security_obj_t *security_obj_ctx, const anj_persistence_context_t *ctx)
 

Detailed Description

Default implementation of the LwM2M Security Object (/0).

Provides initialization, instance management, optional persistence, and access to stored security credentials.

Enumeration Type Documentation

◆ anj_dm_security_mode_t

Possible values of the Security Mode Resource, as described in the Security Object definition. For details, see OMA LwM2M Core Specification v1.2.2 [OMA-TS-LightweightM2M_Core-V1_2_2-20240613-A] §E.1.

Enumerator
ANJ_DM_SECURITY_PSK 

Pre-Shared Key mode

ANJ_DM_SECURITY_RPK 

Raw Public Key mode

ANJ_DM_SECURITY_CERTIFICATE 

Certificate mode

ANJ_DM_SECURITY_NOSEC 

NoSec mode

ANJ_DM_SECURITY_EST 

Certificate mode with EST

Function Documentation

◆ anj_dm_security_obj_add_instance()

int anj_dm_security_obj_add_instance ( anj_dm_security_obj_t security_obj_ctx,
const anj_dm_security_instance_init_t instance 
)

Adds new Instance of Security Object.

Note
All data from instance is copied, so the caller can free it.
Warning
This function must not be called after anj_dm_security_obj_install.
Parameters
security_obj_ctxSecurity Object state.
instanceInstance to insert.
Returns
0 on success, a non-zero value in case of an error.

◆ anj_dm_security_obj_get_psk()

int anj_dm_security_obj_get_psk ( const anj_t anj,
bool  bootstrap_credentials,
anj_crypto_security_info_t out_psk_identity,
anj_crypto_security_info_t out_psk_key 
)

Retrieves the Pre-Shared Key (PSK) identity and key for the specified connection.

Note
Anjay Lite supports only one non-Bootstrap Server LwM2M Server.
Parameters
anjAnjay object to take the Security Object from.
bootstrap_credentialsIf true, retrieves credentials for the Bootstrap Server, otherwise for the regular LwM2M Server.
[out]out_psk_identityOutput parameter for the PSK identity.
[out]out_psk_keyOutput parameter for the PSK key.
Returns
0 in case of success, ANJ_DM_ERR_NOT_FOUND if instance not found.

◆ anj_dm_security_obj_init()

void anj_dm_security_obj_init ( anj_dm_security_obj_t security_obj_ctx)

Initializes Security Object internal state variable.

This function must be called once, before adding any Instances.

Parameters
security_obj_ctxPointer to a variable that will hold the state of the Object.

◆ anj_dm_security_obj_install()

int anj_dm_security_obj_install ( anj_t anj,
anj_dm_security_obj_t security_obj_ctx 
)

Installs Security Object in data model.

Call this function after adding all Instances using anj_dm_security_obj_add_instance. After calling this function, new Instances can be added only by LwM2M Bootstrap Server.

Parameters
anjAnjay object.
security_obj_ctxSecurity Object state.
Returns
0 in case of success, negative value in case of error.

◆ anj_dm_security_obj_restore()

int anj_dm_security_obj_restore ( anj_t anj,
anj_dm_security_obj_t security_obj_ctx,
const anj_persistence_context_t ctx 
)

Deserializes the LwM2M Security Object from the persistence stream.

Reads Security Object instances and their resources from the underlying medium via ctx->read.

Parameters
anjInitialized Anjay-Lite handle.
security_obj_ctxSecurity Object context to fill.
ctxPersistence context; must have anj_persistence_context_t::direction set to ANJ_PERSISTENCE_RESTORE.
Returns
0 on success, negative value on error.

◆ anj_dm_security_obj_store()

int anj_dm_security_obj_store ( anj_t anj,
anj_dm_security_obj_t security_obj_ctx,
const anj_persistence_context_t ctx 
)

Serializes the current LwM2M Security Object into the persistence stream.

Writes all present Security Object instances and their resources to the underlying medium via ctx->write.

Parameters
anjInitialized Anjay-Lite handle.
security_obj_ctxSecurity Object context to serialize.
ctxPersistence context; must have anj_persistence_context_t::direction set to ANJ_PERSISTENCE_STORE.
Returns
0 on success, negative value on error.