1111#include "access-control.h"
1212#include "security-bootstrapping.h"
1313#include "../ndn-services.h"
14+ #include "../ndn-error-code.h"
1415#include "../encode/key-storage.h"
1516#include "../encode/signed-interest.h"
1617#include "../encode/encrypted-payload.h"
2223#include "../util/msg-queue.h"
2324#include "../util/uniform-time.h"
2425
26+ #include <inttypes.h>
27+
2528#define KEY_LIFTIME 60000
2629
2730/* Logging Level: ERROR, DEBUG */
@@ -100,7 +103,7 @@ _init_ac_state()
100103 _ac_initialized = true;
101104}
102105
103- void
106+ void
104107_ac_timeout ()
105108{
106109 ndn_time_ms_t now = ndn_time_now_ms ();
@@ -138,23 +141,25 @@ _on_ac_notification(const uint8_t* interest, uint32_t interest_size, void* userd
138141 ndn_interest_from_block (& notification , interest , interest_size );
139142 // /[home-prefix]/NDN_SD_AC/NOTIFY/[service-id]/keyid
140143 NDN_LOG_DEBUG ("[ACCESSCTL] Notification: " );
141- NDN_LOG_DEBUG_NAME (& notification );
144+ NDN_LOG_DEBUG_NAME (& notification . name );
142145
143146 ndn_aes_key_t * key = ndn_ac_get_key_for_service (notification .name .components [3 ].value [0 ]);
144147 uint32_t keyid ;
145148 ndn_decoder_t decoder ;
146149 decoder_init (& decoder , notification .name .components [4 ].value , notification .name .components [4 ].size );
147150 decoder_get_uint32_value (& decoder , & keyid );
148151 if (key && key -> key_id <= keyid ) {
149- NDN_LOG_DEBUG ("[ACCESSCTL] Enforced update for Service %u , KeyID %lu \n" ,
152+ NDN_LOG_DEBUG ("[ACCESSCTL] Enforced update for Service %" PRIu32 " , KeyID %" PRIu32 " \n" ,
150153 notification .name .components [3 ].value [0 ], keyid );
151154 for (int i = 0 ; i < 10 ; i ++ ) {
152155 if (_ac_self_state .self_services [i ] == notification .name .components [3 ].value [0 ])
153156 _express_ekey_interest (notification .name .components [3 ].value [0 ]);
154157 if (_ac_self_state .access_services [i ] == notification .name .components [3 ].value [0 ])
155- _express_dkey_interest (notification .name .components [3 ].value [0 ]);
158+ _express_dkey_interest (notification .name .components [3 ].value [0 ]);
156159 }
157160 }
161+
162+ return NDN_SUCCESS ;
158163}
159164
160165/**
@@ -205,7 +210,7 @@ _on_ekey_data(const uint8_t* raw_data, uint32_t data_size, void* userdata)
205210 NDN_LOG_ERROR ("[ACCESSCTL] Cannot get the AES KeyID, Error code is %d\n" , ret );
206211 return ;
207212 }
208- NDN_LOG_DEBUG ("[ACCESSCTL] AES KeyID = %lu \n" , keyid );
213+ NDN_LOG_DEBUG ("[ACCESSCTL] AES KeyID = %" PRIu32 " \n" , keyid );
209214
210215 // set lifetime
211216 expires_in = KEY_LIFTIME ;
@@ -220,8 +225,8 @@ _on_ekey_data(const uint8_t* raw_data, uint32_t data_size, void* userdata)
220225 if (_ac_self_state .self_services [i ] == service ) {
221226 _ac_self_state .ekeys [i ].key_id = keyid ;
222227 _ac_self_state .ekeys [i ].expires_at = expires_in + now ;
223- NDN_LOG_DEBUG ("[ACCESSCTL] New expiration time is %ld, New keyid is %u\n" ,
224- _ac_self_state .ekeys [i ].expires_at , _ac_self_state .ekeys [i ].key_id );
228+ NDN_LOG_DEBUG ("[ACCESSCTL] New expiration time is %ld, New keyid is %u\n" ,
229+ _ac_self_state .ekeys [i ].expires_at , _ac_self_state .ekeys [i ].key_id );
225230 ndn_aes_key_init (ekey , value , NDN_AES_BLOCK_SIZE , _ac_self_state .ekeys [i ].key_id );
226231 _ac_self_state .ekeys [i ].in_renewal = false;
227232 }
@@ -250,7 +255,7 @@ _on_ekey_data(const uint8_t* raw_data, uint32_t data_size, void* userdata)
250255 }
251256#if ENABLE_NDN_LOG_DEBUG
252257 m_measure_tp2 = ndn_time_now_us ();
253- NDN_LOG_DEBUG ("[ACCESSCTL] Key update: %lluus \n" , m_measure_tp2 - m_measure_tp1 );
258+ NDN_LOG_DEBUG ("[ACCESSCTL] Key update: %" PRI_ndn_time_us_t " \n" , m_measure_tp2 - m_measure_tp1 );
254259#endif
255260
256261 // _ac_timeout();
@@ -305,7 +310,7 @@ _on_dkey_data(const uint8_t* raw_data, uint32_t data_size, void* userdata)
305310 NDN_LOG_ERROR ("[ACCESSCTL] Cannot get the AES KeyID, Error code is %d\n" , ret );
306311 return ;
307312 }
308- NDN_LOG_DEBUG ("[ACCESSCTL] AES KeyID = %lu \n" , keyid );
313+ NDN_LOG_DEBUG ("[ACCESSCTL] AES KeyID = %" PRIu32 " \n" , keyid );
309314
310315 // set lifetime to 3000ms
311316 expires_in = KEY_LIFTIME ;
@@ -320,8 +325,8 @@ _on_dkey_data(const uint8_t* raw_data, uint32_t data_size, void* userdata)
320325 if (_ac_self_state .access_services [i ] == service ) {
321326 _ac_self_state .ekeys [i ].key_id = keyid ;
322327 _ac_self_state .access_keys [i ].expires_at = expires_in + now ;
323- NDN_LOG_DEBUG ("[ACCESSCTL] New expiration time is %ld, New keyid is %u\n" ,
324- _ac_self_state .access_keys [i ].expires_at , _ac_self_state .access_keys [i ].key_id );
328+ NDN_LOG_DEBUG ("[ACCESSCTL] New expiration time is %ld, New keyid is %u\n" ,
329+ _ac_self_state .access_keys [i ].expires_at , _ac_self_state .access_keys [i ].key_id );
325330 ndn_aes_key_init (access_key , value , NDN_AES_BLOCK_SIZE , _ac_self_state .access_keys [i ].key_id );
326331 _ac_self_state .access_keys [i ].in_renewal = false;
327332 }
@@ -391,7 +396,7 @@ _express_ekey_interest(uint8_t service)
391396
392397 // signature signing
393398 ndn_name_t * self_identity = ndn_key_storage_get_self_identity (service );
394- ndn_name_t * self_identity_key = ndn_key_storage_get_self_identity_key (service );
399+ ndn_ecc_prv_t * self_identity_key = ndn_key_storage_get_self_identity_key (service );
395400 if (self_identity == NULL || self_identity_key == NULL ) {
396401 NDN_LOG_ERROR ("[ACCESSCTL] Cannot find proper identity to sign" );
397402 return NDN_AC_KEY_NOT_FOUND ;
@@ -569,16 +574,16 @@ ndn_ac_after_bootstrapping()
569574
570575int
571576ndn_ac_trigger_expiration (uint8_t service , uint32_t received_keyid )
572- {
577+ {
573578 int ret = -1 ;
574579 // check if it's a local key
575580 ndn_aes_key_t * aes_key = ndn_ac_get_key_for_service (service );
576581 if (aes_key -> key_id < received_keyid ) {
577- NDN_LOG_DEBUG ("[ACCESSCTL] Local Decryption Key %ld forced expired\n" , aes_key -> key_id );
582+ NDN_LOG_DEBUG ("[ACCESSCTL] Local Decryption Key %" PRIu32 " forced expired\n" , aes_key -> key_id );
578583 _express_dkey_interest (service );
579584 }
580585 else {
581- NDN_LOG_DEBUG ("[ACCESSCTL] Notifying Encryption Key %ld forced expired\n" , received_keyid );
586+ NDN_LOG_DEBUG ("[ACCESSCTL] Notifying Encryption Key %" PRIu32 " forced expired\n" , received_keyid );
582587 ndn_interest_t interest ;
583588 ndn_interest_init (& interest );
584589 ndn_key_storage_t * storage = ndn_key_storage_get_instance ();
@@ -596,4 +601,6 @@ ndn_ac_trigger_expiration(uint8_t service, uint32_t received_keyid)
596601 ret = ndn_forwarder_express_interest_struct (& interest , NULL , NULL , NULL );
597602 if (ret != 0 ) return ret ;
598603 }
604+
605+ return NDN_SUCCESS ;
599606}
0 commit comments