-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OSCORE: Added user-defined callback for finding oscore context #1331
base: develop
Are you sure you want to change the base?
Conversation
1ac0938
to
12629c4
Compare
Thanks for raising this PR. I would like to see I would also like to see |
If you can also change the commit title to
that would be helpful. |
Hi, |
If you are keeping all the A suggested place to do this would be in Then Edit: A 'remove from external' will be needed as well. |
12629c4
to
9f2f4ec
Compare
9f2f4ec
to
79426d6
Compare
Hello again! Just to clarify, we didn't want to keep all
This way, the library still works as designed, yet providing additional functionalities in case they are needed. What do you think about such approach? BTW. I still need to take care of the failing tests, but first, please take a look to make sure you're ok with the general idea. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general looking good.
typedef int (*coap_oscore_save_seq_num_t)(uint64_t sender_seq_num, void *param); | ||
typedef int (*coap_oscore_save_seq_num_t)(uint64_t sender_seq_num, | ||
const coap_bin_const_t *recipient_id, | ||
const coap_bin_const_t *id_context, | ||
void *param); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change to the Public API which we do not want to have to do unless it is absolutely critical.
My suggestion would be to add in save (and delete) function parameters to coap_register_oscore_context_handler()
and call those functions in the appropriate points in the code. Then from a user perspective, everything is in one place for doing the definitions.
Update coap_context-t to include something similar to external_oscore_update_context_handler and external_oscore_delete_context_handler.
/** | ||
* Opaque pointer for internal oscore_ctx_t type. | ||
*/ | ||
typedef struct oscore_ctx_t * oscore_ctx_handle_t; | ||
|
||
/** | ||
* Opaque pointer for internal oscore_recipient_ctx_t type. | ||
* | ||
*/ | ||
typedef struct oscore_recipient_ctx_t * oscore_recipient_ctx_handle_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general for libcoap, all the other typedef struct X X;
statements do not have the *
(pointer) included. We need to be consistent here.
In general, any forward declarations should be included in the appropriate place in include/coap3/coap_forward_decls.h
.
As we are trying to keep the public API to have everything prefixed with coap_
to prevent any name clashes, I think perhaps the 2 forward references (in include/coap3/coap_forward_decls.h
) should be
typedef struct oscore_ctx_t coap_oscore_handle_t
typedef struct oscore_recipient_ctx_t coap_oscore_recipient_ctx_handle_t
and then referenced in your changes with the new names.
* @param context The current coap context to use. | ||
* @param handler User callback. | ||
*/ | ||
void coap_register_oscore_context_handler(coap_context_t *context, external_oscore_find_context_handler_t handler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned previously, this should include an add/update handler as well as possibly a delete handler. Even if delete is not currently used, it is a placeholder that will not break the API with that as a change.
@@ -24,6 +24,8 @@ | |||
* @{ | |||
*/ | |||
|
|||
#include <stdbool.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For historical reasons that I cant recall, it was decided that there should not be the use of boolean in the libcoap code, so this should not be used.
* | ||
* @return True if session is encrypted, false if session is not encrypted. | ||
*/ | ||
bool coap_session_is_encrypted(const coap_session_t *session); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use int
instead of bool
, and document return value accordingly.
@@ -26,6 +26,7 @@ coap_session_get_proto, | |||
coap_session_get_state, | |||
coap_session_get_tls, | |||
coap_session_get_type, | |||
coap_session_is_encrypted, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you may have discovered, you will need to add in an entry line into man/Makefile.am
@echo ".so man3/coap_session.3" > coap_session_get_type.3
+ @echo ".so man3/coap_session.3" > coap_session_is_encrypted.3
@echo ".so man3/coap_string.3" > coap_delete_bin_const.3
I would also prefer to see this entry at the end of the list, after the set/get functions.
@@ -68,6 +69,8 @@ coap_tls_library_t *tls_lib);* | |||
|
|||
*coap_session_type_t coap_session_get_type(const coap_session_t *_session_);* | |||
|
|||
*bool coap_session_is_encrypted(const coap_session_t *session);* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use int
instead of bool
.
*coap_session_is_encrypted*() returns true if the session is using OSCORE encryption, or false if plain CoAP packets are used. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct return types not to be boolean. Also, move this to after the get functions.
The *coap_session_is_encrypted*() function is used to check if incoming _session_ is encrypted. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved to after the get functions.
rcp_ctx->recipient_id, | ||
osc_ctx->id_context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this breaks the public API - See previous comments.
Unfortunately as mentioned above, this breaks any backwards public API use. See alternative suggestions in my comments. Wherever coap_oscore_save_seq_num_t is called, just call your newly defined add/update handler. Thanks for doing all this work. |
@mopsiok Are you able to progress with this PR? |
1 similar comment
@mopsiok Are you able to progress with this PR? |
Hi, For now, feel free to close this PR if you like, and I will contact you when I'm allowed to move this task forward. Thanks for your time and effort! |
Added functionality to restore OSCORE context from external storage (e.g. FLASH), when no context was found by
oscore_find_context
.