lwm2m: made LWM2M security object URI and key size configurable + fixed typo

This commit is contained in:
Niclas Finne 2017-12-19 18:12:14 +01:00
parent 2d31c06a1e
commit 811a62d8db
2 changed files with 21 additions and 12 deletions

View File

@ -178,7 +178,7 @@ lwm2m_callback(lwm2m_object_instance_t *object,
switch(ctx->resource_id) {
case LWM2M_SECURITY_SERVER_URI_ID:
LOG_DBG("Writing security URI value: len: %d\n", (int)ctx->inbuf->size);
value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->server_uri, URI_SIZE);
value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->server_uri, LWM2M_SECURITY_URI_SIZE);
/* This is string... */
security->server_uri_len = ctx->last_value_len;
break;
@ -201,7 +201,7 @@ lwm2m_callback(lwm2m_object_instance_t *object,
}
break;
case LWM2M_SECURITY_CLIENT_PKI_ID:
value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->public_key, KEY_SIZE);
value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->public_key, LWM2M_SECURITY_KEY_SIZE);
security->public_key_len = ctx->last_value_len;
LOG_DBG("Writing client PKI: len: %d '", (int)ctx->last_value_len);
@ -210,7 +210,7 @@ lwm2m_callback(lwm2m_object_instance_t *object,
LOG_DBG_("'\n");
break;
case LWM2M_SECURITY_KEY_ID:
value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->secret_key, URI_SIZE);
value = lwm2m_object_read_string(ctx, ctx->inbuf->buffer, ctx->inbuf->size, security->secret_key, LWM2M_SECURITY_KEY_SIZE);
security->secret_key_len = ctx->last_value_len;
LOG_DBG("Writing secret key: len: %d '", (int)ctx->last_value_len);
@ -255,7 +255,7 @@ lwm2m_security_add_server(uint16_t instance_id,
lwm2m_security_server_t *server;
int i;
if(server_uri_len > URI_SIZE) {
if(server_uri_len > LWM2M_SECURITY_URI_SIZE) {
LOG_WARN("too long server URI: %u\n", server_uri_len);
return NULL;
}
@ -312,11 +312,11 @@ lwm2m_security_set_server_psk(lwm2m_security_server_t *server,
if(server == NULL || identity == NULL || key == NULL) {
return 0;
}
if(identity_len > KEY_SIZE) {
if(identity_len > LWM2M_SECURITY_KEY_SIZE) {
LOG_WARN("too large identity: %u\n", identity_len);
return 0;
}
if(key_len > KEY_SIZE) {
if(key_len > LWM2M_SECURITY_KEY_SIZE) {
LOG_WARN("too large identity: %u\n", key_len);
return 0;
}

View File

@ -36,21 +36,30 @@
#ifndef LWM2M_SECURITY_H
#define LWM2M_SECURITY_H
#define URI_SIZE 64
#define KEY_SIZE 32
#ifdef LWM2M_SECURITY_CONF_URI_SIZE
#define LWM2M_SECURITY_URI_SIZE LWM2M_SECURITY_CONF_URI_SIZE
#else /* LWM2M_SECURITY_CONF_URI_SIZE */
#define LWM2M_SECURITY_URI_SIZE 64
#endif /* LWM2M_SECURITY_CONF_URI_SIZE */
#ifdef LWM2M_SECURITY_CONF_KEY_SIZE
#define LWM2M_SECURITY_KEY_SIZE LWM2M_SECURITY_CONF_KEY_SIZE
#else /* LWM2M_SECURITY_CONF_KEY_SIZE */
#define LWM2M_SECURITY_KEY_SIZE 32
#endif /* LWM2M_SECURITY_CONF_KEY_SIZE */
typedef struct {
lwm2m_object_instance_t instance;
uint16_t server_id;
uint8_t bootstrap;
uint8_t security_mode;
uint8_t server_uri[URI_SIZE];
uint8_t server_uri[LWM2M_SECURITY_URI_SIZE];
uint8_t server_uri_len;
uint8_t public_key[KEY_SIZE];
uint8_t public_key[LWM2M_SECURITY_KEY_SIZE];
uint8_t public_key_len;
uint8_t secret_key[KEY_SIZE];
uint8_t secret_key[LWM2M_SECURITY_KEY_SIZE];
uint8_t secret_key_len;
uint8_t server_public_key[KEY_SIZE];
uint8_t server_public_key[LWM2M_SECURITY_KEY_SIZE];
uint8_t server_public_key_len;
} lwm2m_security_server_t;