@@ -1288,21 +1288,23 @@ static coap_context_t*
12881288doc_setup_server_context (const uint8_t * key , unsigned key_len , const char * hint ) {
12891289 coap_address_t listen_addr ;
12901290 coap_context_t * coap_context = coap_new_context (NULL );
1291- coap_dtls_spsk_t dtls_psk ;
12921291
12931292 coap_context_set_block_mode (coap_context ,
12941293 COAP_BLOCK_USE_LIBCOAP | COAP_BLOCK_SINGLE_BODY );
12951294
1296- /* setup dtls */
1297- memset (& dtls_psk , 0 , sizeof (dtls_psk ));
1295+ if (key && hint ) {
1296+ /* setup dtls */
1297+ coap_dtls_spsk_t dtls_psk ;
1298+ memset (& dtls_psk , 0 , sizeof (dtls_psk ));
12981299
1299- dtls_psk .version = COAP_DTLS_SPSK_SETUP_VERSION ;
1300- dtls_psk .psk_info .hint .s = (const uint8_t * )hint ;
1301- dtls_psk .psk_info .hint .length = hint ? strlen (hint ) : 0 ;
1302- dtls_psk .psk_info .key .s = key ;
1303- dtls_psk .psk_info .key .length = key_len ;
1300+ dtls_psk .version = COAP_DTLS_SPSK_SETUP_VERSION ;
1301+ dtls_psk .psk_info .hint .s = (const uint8_t * )hint ;
1302+ dtls_psk .psk_info .hint .length = hint ? strlen (hint ) : 0 ;
1303+ dtls_psk .psk_info .key .s = key ;
1304+ dtls_psk .psk_info .key .length = key_len ;
13041305
1305- coap_context_set_psk2 (coap_context , & dtls_psk );
1306+ coap_context_set_psk2 (coap_context , & dtls_psk );
1307+ }
13061308
13071309 /* setup oscore */
13081310 uint64_t start_seq_num = 0 ;
@@ -1611,6 +1613,7 @@ ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp,
16111613 int * reuseport , int transparent , int tcp_mss , int freebind ,
16121614 int http2_nodelay , int use_systemd , int dnscrypt_port , int dscp ,
16131615 int quic_port , int coap_port , int coaps_port ,
1616+ const char * coaps_psk , const char * coaps_psk_id ,
16141617 int http_notls_downstream , int sock_queue_timeout )
16151618{
16161619 int s , noip6 = 0 ;
@@ -1631,14 +1634,16 @@ ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp,
16311634 const char * add = NULL ;
16321635
16331636#ifdef HAVE_COAP
1634- static const uint8_t psk_key [] = "psk" ;
1635- ssize_t psk_length = sizeof (psk_key ) - 1 ;
1636- static const char * hint = "client" ;
1637- coap_context_t * coap_context = doc_setup_server_context (psk_key , psk_length , hint );
1637+ printf ("coaps_psk: %s, coaps_psk_len: %lu, coaps_psk_id: %s\n" , coaps_psk , strlen (coaps_psk ), coaps_psk_id );
1638+ coap_context_t * coap_context = doc_setup_server_context (
1639+ (const uint8_t * )coaps_psk , strlen (coaps_psk ), coaps_psk_id );
16381640
16391641 if (!coap_context ) {
16401642 fatal_exit ("Unable to get server context" );
16411643 }
1644+ #else
1645+ (void )coaps_psk ;
1646+ (void )coaps_psk_id ;
16421647#endif /* HAVE_COAP */
16431648
16441649 if (!do_udp && !do_tcp )
@@ -2356,6 +2361,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
23562361 cfg -> http_nodelay , cfg -> use_systemd ,
23572362 cfg -> dnscrypt_port , cfg -> ip_dscp ,
23582363 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2364+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
23592365 cfg -> http_notls_downstream ,
23602366 cfg -> sock_queue_timeout )) {
23612367 listening_ports_free (list );
@@ -2376,6 +2382,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
23762382 cfg -> http_nodelay , cfg -> use_systemd ,
23772383 cfg -> dnscrypt_port , cfg -> ip_dscp ,
23782384 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2385+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
23792386 cfg -> http_notls_downstream ,
23802387 cfg -> sock_queue_timeout )) {
23812388 listening_ports_free (list );
@@ -2398,6 +2405,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
23982405 cfg -> http_nodelay , cfg -> use_systemd ,
23992406 cfg -> dnscrypt_port , cfg -> ip_dscp ,
24002407 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2408+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
24012409 cfg -> http_notls_downstream ,
24022410 cfg -> sock_queue_timeout )) {
24032411 listening_ports_free (list );
@@ -2417,6 +2425,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
24172425 cfg -> http_nodelay , cfg -> use_systemd ,
24182426 cfg -> dnscrypt_port , cfg -> ip_dscp ,
24192427 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2428+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
24202429 cfg -> http_notls_downstream ,
24212430 cfg -> sock_queue_timeout )) {
24222431 listening_ports_free (list );
@@ -2438,6 +2447,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
24382447 cfg -> http_nodelay , cfg -> use_systemd ,
24392448 cfg -> dnscrypt_port , cfg -> ip_dscp ,
24402449 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2450+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
24412451 cfg -> http_notls_downstream ,
24422452 cfg -> sock_queue_timeout )) {
24432453 listening_ports_free (list );
@@ -2457,6 +2467,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
24572467 cfg -> http_nodelay , cfg -> use_systemd ,
24582468 cfg -> dnscrypt_port , cfg -> ip_dscp ,
24592469 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2470+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
24602471 cfg -> http_notls_downstream ,
24612472 cfg -> sock_queue_timeout )) {
24622473 listening_ports_free (list );
0 commit comments