@@ -1292,21 +1292,23 @@ static coap_context_t*
12921292doc_setup_server_context (const uint8_t * key , unsigned key_len , const char * hint ) {
12931293 coap_address_t listen_addr ;
12941294 coap_context_t * coap_context = coap_new_context (NULL );
1295- coap_dtls_spsk_t dtls_psk ;
12961295
12971296 coap_context_set_block_mode (coap_context ,
12981297 COAP_BLOCK_USE_LIBCOAP | COAP_BLOCK_SINGLE_BODY );
12991298
1300- /* setup dtls */
1301- memset (& dtls_psk , 0 , sizeof (dtls_psk ));
1299+ if (key && hint ) {
1300+ /* setup dtls */
1301+ coap_dtls_spsk_t dtls_psk ;
1302+ memset (& dtls_psk , 0 , sizeof (dtls_psk ));
13021303
1303- dtls_psk .version = COAP_DTLS_SPSK_SETUP_VERSION ;
1304- dtls_psk .psk_info .hint .s = (const uint8_t * )hint ;
1305- dtls_psk .psk_info .hint .length = hint ? strlen (hint ) : 0 ;
1306- dtls_psk .psk_info .key .s = key ;
1307- dtls_psk .psk_info .key .length = key_len ;
1304+ dtls_psk .version = COAP_DTLS_SPSK_SETUP_VERSION ;
1305+ dtls_psk .psk_info .hint .s = (const uint8_t * )hint ;
1306+ dtls_psk .psk_info .hint .length = hint ? strlen (hint ) : 0 ;
1307+ dtls_psk .psk_info .key .s = key ;
1308+ dtls_psk .psk_info .key .length = key_len ;
13081309
1309- coap_context_set_psk2 (coap_context , & dtls_psk );
1310+ coap_context_set_psk2 (coap_context , & dtls_psk );
1311+ }
13101312
13111313 /* setup oscore */
13121314 uint64_t start_seq_num = 0 ;
@@ -1624,6 +1626,7 @@ ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp,
16241626 int * reuseport , int transparent , int tcp_mss , int freebind ,
16251627 int http2_nodelay , int use_systemd , int dnscrypt_port , int dscp ,
16261628 int quic_port , int coap_port , int coaps_port ,
1629+ const char * coaps_psk , const char * coaps_psk_id ,
16271630 int http_notls_downstream , int sock_queue_timeout )
16281631{
16291632 int s , noip6 = 0 ;
@@ -1644,14 +1647,16 @@ ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp,
16441647 const char * add = NULL ;
16451648
16461649#ifdef HAVE_COAP
1647- static const uint8_t psk_key [] = "psk" ;
1648- ssize_t psk_length = sizeof (psk_key ) - 1 ;
1649- static const char * hint = "client" ;
1650- coap_context_t * coap_context = doc_setup_server_context (psk_key , psk_length , hint );
1650+ printf ("coaps_psk: %s, coaps_psk_len: %lu, coaps_psk_id: %s\n" , coaps_psk , strlen (coaps_psk ), coaps_psk_id );
1651+ coap_context_t * coap_context = doc_setup_server_context (
1652+ (const uint8_t * )coaps_psk , strlen (coaps_psk ), coaps_psk_id );
16511653
16521654 if (!coap_context ) {
16531655 fatal_exit ("Unable to get server context" );
16541656 }
1657+ #else
1658+ (void )coaps_psk ;
1659+ (void )coaps_psk_id ;
16551660#endif /* HAVE_COAP */
16561661
16571662 if (!do_udp && !do_tcp )
@@ -2369,6 +2374,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
23692374 cfg -> http_nodelay , cfg -> use_systemd ,
23702375 cfg -> dnscrypt_port , cfg -> ip_dscp ,
23712376 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2377+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
23722378 cfg -> http_notls_downstream ,
23732379 cfg -> sock_queue_timeout )) {
23742380 listening_ports_free (list );
@@ -2389,6 +2395,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
23892395 cfg -> http_nodelay , cfg -> use_systemd ,
23902396 cfg -> dnscrypt_port , cfg -> ip_dscp ,
23912397 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2398+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
23922399 cfg -> http_notls_downstream ,
23932400 cfg -> sock_queue_timeout )) {
23942401 listening_ports_free (list );
@@ -2411,6 +2418,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
24112418 cfg -> http_nodelay , cfg -> use_systemd ,
24122419 cfg -> dnscrypt_port , cfg -> ip_dscp ,
24132420 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2421+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
24142422 cfg -> http_notls_downstream ,
24152423 cfg -> sock_queue_timeout )) {
24162424 listening_ports_free (list );
@@ -2430,6 +2438,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
24302438 cfg -> http_nodelay , cfg -> use_systemd ,
24312439 cfg -> dnscrypt_port , cfg -> ip_dscp ,
24322440 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2441+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
24332442 cfg -> http_notls_downstream ,
24342443 cfg -> sock_queue_timeout )) {
24352444 listening_ports_free (list );
@@ -2451,6 +2460,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
24512460 cfg -> http_nodelay , cfg -> use_systemd ,
24522461 cfg -> dnscrypt_port , cfg -> ip_dscp ,
24532462 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2463+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
24542464 cfg -> http_notls_downstream ,
24552465 cfg -> sock_queue_timeout )) {
24562466 listening_ports_free (list );
@@ -2470,6 +2480,7 @@ listening_ports_open(struct config_file* cfg, char** ifs, int num_ifs,
24702480 cfg -> http_nodelay , cfg -> use_systemd ,
24712481 cfg -> dnscrypt_port , cfg -> ip_dscp ,
24722482 cfg -> quic_port , cfg -> coap_port , cfg -> coaps_port ,
2483+ cfg -> coaps_psk , cfg -> coaps_psk_id ,
24732484 cfg -> http_notls_downstream ,
24742485 cfg -> sock_queue_timeout )) {
24752486 listening_ports_free (list );
0 commit comments