Skip to content

Commit

Permalink
coap_session.[hc]: Added function to retrieve PSK identity from session
Browse files Browse the repository at this point in the history
The new function coap_session_get_psk_identity() returns the given
session's psk_identity as provided during the handhake (for CoAP server)
or a session setup (for CoAP client).
  • Loading branch information
obgm committed Oct 21, 2021
1 parent c821148 commit df9071c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/coap3/coap_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ coap_session_t *coap_new_client_session_psk2(
const coap_bin_const_t * coap_session_get_psk_hint(
const coap_session_t *session);

/**
* Get the server session's current PSK identity (PSK).
*
* @param session The current coap_session_t object.
*
* @return PSK identity if successful, else @c NULL.
*/
const coap_bin_const_t *coap_session_get_psk_identity(
const coap_session_t *session);
/**
* Get the session's current pre-shared key (PSK).
*
Expand Down
1 change: 1 addition & 0 deletions libcoap-3.map
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ global:
coap_session_get_max_retransmit;
coap_session_get_proto;
coap_session_get_psk_hint;
coap_session_get_psk_identity;
coap_session_get_psk_key;
coap_session_get_state;
coap_session_get_tls;
Expand Down
1 change: 1 addition & 0 deletions libcoap-3.sym
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ coap_session_get_ifindex
coap_session_get_max_retransmit
coap_session_get_proto
coap_session_get_psk_hint
coap_session_get_psk_identity
coap_session_get_psk_key
coap_session_get_state
coap_session_get_tls
Expand Down
12 changes: 12 additions & 0 deletions src/coap_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,18 @@ coap_session_get_psk_hint(const coap_session_t *session) {
}
#endif /* COAP_SERVER_SUPPORT */

const coap_bin_const_t *
coap_session_get_psk_identity(const coap_session_t *session) {
const coap_bin_const_t *psk_identity = NULL;
if (session) {
psk_identity = session->psk_identity;
if (psk_identity == NULL) {
psk_identity = &session->cpsk_setup_data.psk_info.identity;
}
}
return psk_identity;
}

const coap_bin_const_t *
coap_session_get_psk_key(const coap_session_t *session) {
if (session)
Expand Down

0 comments on commit df9071c

Please sign in to comment.