Skip to content
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

Installing libcoap on ubuntu comes down to difficulties #1154

Closed
salmeghlef opened this issue Jul 2, 2023 · 50 comments
Closed

Installing libcoap on ubuntu comes down to difficulties #1154

salmeghlef opened this issue Jul 2, 2023 · 50 comments

Comments

@salmeghlef
Copy link

Hi guys,
I have used this project to do some experiments and I published two papers acknowledging this project. I was install this project with simple steps:
1- ./autogen.sh
2- ./configure
3- make
4- make install

However, after updating the project to new version, step 3 doesn't work,,, please guide ,,

Thank you
Sultan

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 2, 2023

It would really help if when raising a new issue you had filled in the bug report information so that we can see what is actually failing.

The output from stage 2 and stage 3 would be very helpful here.

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 3, 2023

@salmeghlef It would be good to get to the bottom of what is going wrong here for you. In general there is not an issue here as several of the GitHub workflow actions done for every code push to the libcoap repository follow the same steps using Ubuntu and code is built with no issues.

Please provide the requested information so we can help you.

@salmeghlef
Copy link
Author

I came over the issue. When running ./coap-server , is it supposed to support DTLS by default? the same for ./coap-client?

Answering this inquiry will result in closing this issue.
Thanks John

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 6, 2023

Firstly, when running ./configure, this can control whether the libcoap library has DTLS support or not as well as which TLS library to use if an application using libcoap wants to enable DTLS usage. ./configure —disable-dtls means there is no DTLS support for example.

./coap-server needs to be told which PSK key or PKI certificates to use if it is to listen for or accept incoming DTLS requests.

./coap-client will, or will not use DTLS depending on the scheme used in the URI (coaps:// or coap:// respectively). Furthermore, you should define the PSK or PKI information to use for DTLS.

@salmeghlef
Copy link
Author

salmeghlef commented Jul 6, 2023

Many thanks John. Now, kindly, tell what is the best PSK facility (GnuTLS for instance) to be installed in order to enable DTLS. You may answer with terminal commands directly, then I will run ./configure --disable-documentation again.

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 6, 2023

Any of the 4 supported TLS libraries are fine to use for DTLS (see libcoap setup). The respective library needs to be installed on Ubuntu before ./configure is run. The latest documentation can always be found at libcoap documentation.

@salmeghlef
Copy link
Author

salmeghlef commented Jul 8, 2023

I've done everything and enabling tinydtls, found an issue when running ./coap-server, following the solution at https://github.com/smartuni/examples/wiki/libcoap, but it gives the following error:

gcc -I /usr/local/include/coap client.c coap_list.c -o client -lcoap-1 -DWITH_POSIX
cc1: fatal error: client.c: No such file or directory
compilation terminated.
coap_list.c:36:13: error: unknown type name ‘coap_list_t’; did you mean ‘coap_log_t’?
36 | coap_insert(coap_list_t **head, coap_list_t *node) {
| ^~~~~~~~~~~
| coap_log_t
coap_list.c:36:33: error: unknown type name ‘coap_list_t’; did you mean ‘coap_log_t’?
36 | coap_insert(coap_list_t **head, coap_list_t *node) {
| ^~~~~~~~~~~
| coap_log_t
coap_list.c:49:13: error: unknown type name ‘coap_list_t’; did you mean ‘coap_log_t’?
49 | coap_delete(coap_list_t *node) {
| ^~~~~~~~~~~
| coap_log_t
coap_list.c:57:18: error: unknown type name ‘coap_list_t’; did you mean ‘coap_log_t’?
57 | coap_delete_list(coap_list_t *queue) {
| ^~~~~~~~~~~
| coap_log_t

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 8, 2023

Have you read BUILDING?

Response to un-edited comment above.

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 8, 2023

https://github.com/smartuni/examples/wiki/libcoap was written 7 years ago. A lot has changed since then with client.c being renamed and coap_list.c no longer used (as documented in the header lines of that file).

@salmeghlef
Copy link
Author

salmeghlef commented Jul 9, 2023

I compiled everything and example folder contains the executable files for coap-server and coap-client with dtls or not. However, when running ./coap-client-tinydtls , it gives this message:

./coap-client-tinydtls: error: '/home/kali/libcoap/ex/.libs/coap-client-tinydtls' does not exist
This script is just a wrapper for coap-client-tinydtls.
See the libtool documentation for more information.

when running without back slash coap-server, it gives this error:

coap-server: error while loading shared libraries: libcoap-3-tinydtls.so.3: cannot open shared object file: No such file or directory

@salmeghlef
Copy link
Author

I spent much of time to resolve the issue above, but no to avail. Kindly, help with this final touch for this issue.

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 10, 2023

/home/kali/libcoap/ex/.libs/coap-client-tinydtls

I am not expecting/ex/in the path, but would be expecting /examples/ so it looks like you renamed directories at some point and have confused the autotools build system. Put all the directories back as they should be, clean up files (make clean) and build everything again. Better still, start from a clean git clone.

coap-server: error while loading shared libraries: libcoap-3-tinydtls.so.3: cannot open shared object file: No such file or directory

Looks like you did not do a clean sudo make install. In case the binary loader cache is messed up, you can try sudo /sbin/ldconfig.

@salmeghlef
Copy link
Author

I follow your advice to restart cloning the project again, doing these steps:
./autogen.sh OK
./configure --enable-dtls --with-tinydtls --disable-shared --disable-doxygen --disable-manpages

./make =====> gives the following error: (do I have to build the tinydtls inside libcoap independently)

src/coap_tinydtls.c: In function 'coap_dtls_startup':
src/coap_tinydtls.c:153:3: warning: implicit declaration of function 'dtls_set_log_handler'; did you mean 'dtls_set_handler'? [-Wimplicit-function-declaration]
153 | dtls_set_log_handler(dtls_logging);
| ^~~~~~~~~~~~~~~~~~~~
| dtls_set_handler
src/coap_tinydtls.c:153:3: warning: nested extern declaration of 'dtls_set_log_handler' [-Wnested-externs]
src/coap_tinydtls.c: In function 'coap_crypto_aead_encrypt':
src/coap_tinydtls.c:1589:3: error: unknown type name 'dtls_ccm_params_t'
1589 | dtls_ccm_params_t dtls_params;
| ^~~~~~~~~~~~~~~~~
src/coap_tinydtls.c:1611:14: error: request for member 'nonce' in something not a structure or union
1611 | dtls_params.nonce = ccm->nonce;
| ^
src/coap_tinydtls.c:1612:14: error: request for member 'tag_length' in something not a structure or union
1612 | dtls_params.tag_length = ccm->tag_len;
| ^
src/coap_tinydtls.c:1613:14: error: request for member 'l' in something not a structure or union
1613 | dtls_params.l = ccm->l;
| ^
src/coap_tinydtls.c:1622:15: warning: implicit declaration of function 'dtls_encrypt_params'; did you mean 'dtls_security_params'? [-Wimplicit-function-declaration]
1622 | num_bytes = dtls_encrypt_params(&dtls_params,
| ^~~~~~~~~~~~~~~~~~~
| dtls_security_params
src/coap_tinydtls.c:1622:15: warning: nested extern declaration of 'dtls_encrypt_params' [-Wnested-externs]
src/coap_tinydtls.c: In function 'coap_crypto_aead_decrypt':
src/coap_tinydtls.c:1641:3: error: unknown type name 'dtls_ccm_params_t'
1641 | dtls_ccm_params_t dtls_params;
| ^~~~~~~~~~~~~~~~~
src/coap_tinydtls.c:1664:14: error: request for member 'nonce' in something not a structure or union
1664 | dtls_params.nonce = ccm->nonce;
| ^
src/coap_tinydtls.c:1665:14: error: request for member 'tag_length' in something not a structure or union
1665 | dtls_params.tag_length = ccm->tag_len;
| ^
src/coap_tinydtls.c:1666:14: error: request for member 'l' in something not a structure or union
1666 | dtls_params.l = ccm->l;
| ^
src/coap_tinydtls.c:1675:15: warning: implicit declaration of function 'dtls_decrypt_params'; did you mean 'dtls_security_params'? [-Wimplicit-function-declaration]
1675 | num_bytes = dtls_decrypt_params(&dtls_params,
| ^~~~~~~~~~~~~~~~~~~
| dtls_security_params
src/coap_tinydtls.c:1675:15: warning: nested extern declaration of 'dtls_decrypt_params' [-Wnested-externs]
make[2]: *** [Makefile:1169: src/libcoap_3-tinydtls_la-coap_tinydtls.lo] Error 1
make[2]: Leaving directory '/home/kali/libcoap'
make[1]: *** [Makefile:1305: all-recursive] Error 1
make[1]: Leaving directory '/home/kali/libcoap'
make: *** [Makefile:718: all] Error 2

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 10, 2023

As per #1154 (comment) I refer you again to BUILDING where it says

TinyDTLS Only
=============

It is possible that you may need to execute the following two commands once to
get the TinyDTLS code into your project, so the TinyDTLS library can be used.

 git submodule init
 git submodule update

You either need to do this, or separately (build and) install the tinydtls library.

@salmeghlef
Copy link
Author

git submodule update

I did these steps, the same error !!!!

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 10, 2023

As your build does not complain about unable to access tinydtls.h, it looks like you have an older version of TinyDTLS installed on your system.

There is a ./configure option --with-submodule-tinydtls which should override trying to use the older version.

I would expect your configuration summary to look something like (which works fine on my Ubuntu system)

libcoap Configuration Summary:
      libcoap package version        : "4.3.1"
      libcoap package source         : "v4.3.1-202-ge8005c5"
      libcoap library version        : "3.0.0"
      libcoap API version            : "3"
      libcoap DTLS lib extn          : "-tinydtls"
      host system                    : "x86_64-pc-linux-gnu"
      build with server support      : "yes"
      build with client support      : "yes"
      build with IPv4 support        : "yes"
      build with IPv6 support        : "yes"
      build with Unix socket support : "yes"
      build with TCP support         : "yes"
      build DTLS support             : "yes"
         -->  TinyDTLS around        : "yes" (submodule)
              TinyDTLS_CFLAGS        : "-I $(top_srcdir)/ext -I $(top_srcdir)/ext/tinydtls"
              TinyDTLS_LIBS          : "-L$(top_builddir)/ext/tinydtls -l:libtinydtls.a"
      add default names              : "yes"
      build Observe Persist          : "yes"
      build using epoll              : "yes"
      enable small stack size        : "no"
      enable separate responses      : "yes"
      enable OSCORE support          : "yes"
      enable max logging level       : "none"
      build doxygen pages            : "no"
      build man pages                : "no"
      build unit test binary         : "no"
      build examples                 : "yes"
      install examples source        : "yes"
      build with gcov support        : "no"
      build shared library           : "no"
      build static library           : "yes"

@salmeghlef
Copy link
Author

Indeed, my system is Kali-linux based Debian, not Ubuntu-based. Is this going to affect the process?

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 11, 2023

I am not familiar with Kali Linux. Does --with-submodule-tinydtls work for you or not?

@obgm
Copy link
Owner

obgm commented Jul 11, 2023

Indeed, my system is Kali-linux based Debian, not Ubuntu-based. Is this going to affect the process?

There is no (significant) difference between (plain) Debian and Ubuntu regarding the libcoap build.
Could you provide the last part of the configure output as shown above? Your error output looks as if the compiler does not find the correct tinydtls version. I think I have a Kali VM lying around to try later today.

@salmeghlef
Copy link
Author

libcoap Configuration Summary:
libcoap package version : "4.3.1"
libcoap package source : "v4.3.1-202-ge8005c5"
libcoap library version : "3.0.0"
libcoap API version : "3"
libcoap DTLS lib extn : "-tinydtls"
host system : "x86_64-pc-linux-gnu"
build with server support : "yes"
build with client support : "yes"
build with IPv4 support : "yes"
build with IPv6 support : "yes"
build with Unix socket support : "yes"
build with TCP support : "yes"
build DTLS support : "yes"
--> TinyDTLS around : "yes (found TinyDTLS 0.8.6)"
TinyDTLS_CFLAGS : "-I/usr/local/include/tinydtls "
TinyDTLS_LIBS : "-L/usr/local/lib -ltinydtls "
add default names : "yes"
build Observe Persist : "yes"
build using epoll : "yes"
enable small stack size : "no"
enable separate responses : "yes"
enable OSCORE support : "yes"
enable max logging level : "none"
build doxygen pages : "no"
build man pages : "no"
build unit test binary : "no"
build examples : "yes"
install examples source : "yes"
build with gcov support : "no"
build shared library : "no"
build static library : "yes"

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 11, 2023

Ok, you are finding an old installed version of TinyDTLS which does not include code added in Oct 2019.
Please try using the --with-submodule-tinydtls option when running the ./configure command.

@salmeghlef
Copy link
Author

salmeghlef commented Jul 11, 2023

when running:
./configure --disable-documentation --disable-shared --enable-dtls --with-submodule-update

it gives the permanent error:

configure: error: ==> Option '--enable-dtls' is set but none of the needed cryptography libraries GnuTLS, OpenSSL, Mbed TLS or TinyDTLS could be found!
Install at least one of the package(s) that contains the development files for GnuTLS (>= 3.3.0), OpenSSL(>= 1.1.0), Mbed TLS(>= 2.7.10), or TinyDTLS(>= 0.8.6)
or disable the DTLS support using '--disable-dtls'.

It is not working. Hope you can provide the updated version of tinydtls that fit for your project.

Thank you

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 11, 2023

git submodule update when in the libcoap directory gives you the latest version of TinyDTLS for use with libcoap in the ext/tinydtls directory. Then run ./configure with the --with-submodule-tinydtls option and give us the configuration summary again.

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 11, 2023

For your edited update, --with-submodule-update is not the correct option and not recognised by ./configure. It is —with-submodule-tinydtls

@obgm
Copy link
Owner

obgm commented Jul 11, 2023

—with-submodule-tinydtls

Note that this requires --with-tinydtls as pointed out by configure. On a fresh Kali VM this works like a charm:

$ ./configure --disable-documentation --disable-shared --enable-dtls --with-submodule-tinydtls --with-tinydtls
...
libcoap Configuration Summary:
      libcoap package version        : "4.3.1"
      libcoap package source         : "v4.3.1-204-ge55ecc9"
      libcoap library version        : "3.0.0"
      libcoap API version            : "3"
      libcoap DTLS lib extn          : "-tinydtls"
      host system                    : "x86_64-pc-linux-gnu"
      build with server support      : "yes"
      build with client support      : "yes"
      build with IPv4 support        : "yes"
      build with IPv6 support        : "yes"
      build with Unix socket support : "yes"
      build with TCP support         : "yes"
      build DTLS support             : "yes"
         -->  TinyDTLS around        : "yes" (submodule)
              TinyDTLS_CFLAGS        : "-I $(top_srcdir)/ext -I $(top_srcdir)/ext/tinydtls"
              TinyDTLS_LIBS          : "-L$(top_builddir)/ext/tinydtls -l:libtinydtls.a"
      add default names              : "yes"
      build Observe Persist          : "yes"
      build using epoll              : "yes"
      enable small stack size        : "no"
      enable separate responses      : "yes"
      enable OSCORE support          : "yes"
      enable Q-Block support         : "yes"
      enable max logging level       : "none"
      build doxygen pages            : "no"
      build man pages                : "no"
      build unit test binary         : "no"
      build examples                 : "yes"
      install examples source        : "yes"
      build with gcov support        : "no"
      build shared library           : "no"
      build static library           : "yes"
$ make -j
...
$ examples/coap-client-tinydtls -v
examples/coap-client-tinydtls: option requires an argument -- 'v'
coap-client-tinydtls v4.3.1 -- a small CoAP implementation
Copyright (C) 2010-2023 Olaf Bergmann <bergmann@tzi.org> and others

Build: v4.3.1-204-ge55ecc9
TLS Library: TinyDTLS - runtime 0.8.6, libcoap built for 0.8.6
(DTLS and no TLS support; PSK, no PKI, no PKCS11, and RPK support)
(Have OSCORE)
(No WebSockets)
...

@salmeghlef
Copy link
Author

libcoap Configuration Summary:
libcoap package version : "4.3.1"
libcoap package source : "v4.3.1-204-ge55ecc9"
libcoap library version : "3.0.0"
libcoap API version : "3"
libcoap DTLS lib extn : "-tinydtls"
host system : "x86_64-pc-linux-gnu"
build with server support : "yes"
build with client support : "yes"
build with IPv4 support : "yes"
build with IPv6 support : "yes"
build with Unix socket support : "yes"
build with TCP support : "yes"
build DTLS support : "yes"
--> TinyDTLS around : "yes" (submodule)
TinyDTLS_CFLAGS : "-I $(top_srcdir)/ext -I $(top_srcdir)/ext/tinydtls"
TinyDTLS_LIBS : "-L$(top_builddir)/ext/tinydtls -l:libtinydtls.a"
add default names : "yes"
build Observe Persist : "yes"
build using epoll : "yes"
enable small stack size : "no"
enable separate responses : "yes"
enable OSCORE support : "yes"
enable Q-Block support : "yes"
enable max logging level : "none"
build doxygen pages : "no"
build man pages : "no"
build unit test binary : "no"
build examples : "yes"
install examples source : "yes"
build with gcov support : "no"
build shared library : "no"
build static library : "yes"

However, when running $make .. it gives this error:

warning: Changing CLASS_GRAPH option to TEXT because obsolete option CLASS_DIAGRAM was found and set to NO.
/home/kali/libcoap/ext/tinydtls/ccm.c:62: error: found documented return type for add_auth_data that does not return anything (warning treated as error, aborting now)
make[3]: *** [Makefile:22: doc] Error 1
make[3]: Leaving directory '/home/kali/libcoap/ext/tinydtls/doc'
make[2]: *** [Makefile:106: doc] Error 2
make[2]: Leaving directory '/home/kali/libcoap/ext/tinydtls'
make[1]: *** [Makefile:1305: all-recursive] Error 1
make[1]: Leaving directory '/home/kali/libcoap'
make: *** [Makefile:718: all] Error 2

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 11, 2023

This is an issue with the TinyDTLS code which your version of Kali-Linux has picked up. A PR has been raised for that - see eclipse/tinydtls#200.

I suggest you make the following change to the TinyDTLS code in the interim.

diff --git a/ccm.c b/ccm.c
index 0a5e0ce..e0bb77c 100644
--- a/ccm.c
+++ b/ccm.c
@@ -70,7 +70,6 @@ block0(size_t M,       /* number of auth bytes */
  *             authentication block.
  * \param X    The output buffer where the result of the CBC calculation
  *             is placed.
- * \return     The result is written to \p X.
  */
 static void
 add_auth_data(rijndael_ctx *ctx, const unsigned char *msg, uint64_t la,

@salmeghlef
Copy link
Author

I am not aware where to find the interim for TinyDTLS nor I am a software developer. Kindly, elaborate in short steps, for instance:
open terminal,
cd to libcoap,
head to tinydtls folder,
nano the file cmc.c , add the code ......

This way can end up this issue.

Thank you for your consideration

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 12, 2023

Open terminal

$ cd /home/kali/libcoap/ext/tinydtls
$ sed -i '73d' ccm.c
$ git diff                                      # To check diff is what I showed above
$ cd /home/kali/libcoap
$ make

@salmeghlef
Copy link
Author

salmeghlef commented Jul 12, 2023

I followed the steps and the code is the same for the one you provided. Unfortunately, an error is appearing.

Anyway, I have installed ubuntu 22.04 as VM. It is working just fine now. Thanks a lot for you cooperation. To end up this issue, kindly, refer me to how to create PERMANENT interface in ubuntu. Always missing the created interfaces even adding them in /etc/network/.... after rebooting the system.

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 12, 2023

Good that things are now working. It would have been useful to have had the next stage build error.

This forum is specifically about libcoap issues / requests, and your Ubuntu network interface question need to be asked on another forum - sorry.

@salmeghlef
Copy link
Author

salmeghlef commented Jul 12, 2023

Okay Olaf. Kindly see this issue:
When running
sudo ./coap-server-tinydtls -A 192.168.1.1 -p 5683
and from another terminal:
sudo ./coap-client-tinydtls -a 192.168.1.2 -m get coaps://[192.168.1.1]/time
WARN coap_is_bcst: insufficient space for broadcast addresses
ERR: cannot create client session

The same for coap instead of coaps.
!!!

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 13, 2023

3 things here, could be more depending on your network interface definitions.

You should not be using sudo here.

[192.168.1.1] is an invalid address for the client URI. The use of [] is for using IPv6 addresses, not IPv4 addresses which is the same for other URIs such as http:// and https://. Remove the [] wrapper.

There is no default Pre-Shared Key (PSK) definitions - you need to define them using the appropriate options if you want to use DTLS using the TinyDTLS library.

Separately, you may want to use the -v7 option to get additional logging.

@salmeghlef
Copy link
Author

I executed this line and the results showed:

./coap-server-tinydtls -v7 -A 192.168.1.1
Jul 13 09:22:06.829 DEBG (D)TLS not enabled as none of -k, -c or -M options specified
Jul 13 09:22:06.829 DEBG created TCP  endpoint 192.168.1.1:5683
Jul 13 09:22:06.829 DEBG created UDP  endpoint 192.168.1.1:5683

Kindly, tell how to define the PSK since DTLS is not enabled as the message above.

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 13, 2023

It is telling you to use one of the -k, -c, or -M options. ./coap-server-tinydtls -? tells you what the options are.

@salmeghlef
Copy link
Author

salmeghlef commented Jul 13, 2023

./coap-server-tinydtls -v 7 -k mysecretKey -A 192.168.1.3
Jul 13 10:17:26.104 DEBG created TCP  endpoint 192.168.1.3:5683
Jul 13 10:17:26.104 DEBG created UDP  endpoint 192.168.1.3:5683
Jul 13 10:17:26.104 DEBG created DTLS endpoint 192.168.1.3:5684

It is working fine. Now, kindly tell me what is the best command to read the time from the server. For instance, I tried ./coap-client-tinydtls -v 7 -k mysecretKey -m get coap://192.168.1.3/time , it gives error!!

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 13, 2023

Please look at your error message, and then look at the documentation to define what you have not defined for PSK.

Once things are working, you may want to stop using the verbose -v7 option.

@salmeghlef
Copy link
Author

salmeghlef commented Jul 14, 2023

Do I have to define the secret key in -k mysecret for both coap-server and coap-client . if this is the case, in a real scenario, how the client knows the secret key defined by the server ?

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 14, 2023

Yes, both client and server need to share the same key, which is done by an out of band method. Hence Pre-Shared Key (PSK).

@salmeghlef
Copy link
Author

Thanks Olaf. I think we are putting the final touch to launch ./coap-server-tinydtls and coap-client-tinydtls

when running:
./coap-client-tinydtls -v7 -a 192.168.1.2 -k mtsecretkey -m get coap://192.168.1.1/
It works but the error in the bold section appears!!!

J```
ul 14 16:08:34.213 WARN coap_is_bcst: Insufficient space for broadcast addresses
Jul 14 16:08:34.214 DEBG ***192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : session 0x5651834f2a70: created outgoing session
Jul 14 16:08:34.214 DEBG ***192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : session connected
Jul 14 16:08:34.214 DEBG timeout is set to 90 seconds
Jul 14 16:08:34.214 DEBG sending CoAP request:
Jul 14 16:08:34.214 DEBG * 192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : netif: sent 12 bytes
v:1 t:CON c:GET i:9fe0 {01} [ Request-Tag:0x74bf5d09 ]
Jul 14 16:08:34.214 DEBG ** 192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : mid=0x9fe0: added to retransmit queue (2688ms)
Jul 14 16:08:36.902 DEBG ***EVENT: COAP_EVENT_MSG_RETRANSMITTED
Jul 14 16:08:36.902 DEBG ** 192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : mid=0x9fe0: retransmission #1 (next 5376ms)
Jul 14 16:08:36.902 DEBG * 192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : netif: sent 12 bytes
v:1 t:CON c:GET i:9fe0 {01} [ Request-Tag:0x74bf5d09 ]
Jul 14 16:08:42.278 DEBG ***EVENT: COAP_EVENT_MSG_RETRANSMITTED
Jul 14 16:08:42.278 DEBG ** 192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : mid=0x9fe0: retransmission #2 (next 10752ms)
Jul 14 16:08:42.279 DEBG * 192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : netif: sent 12 bytes
v:1 t:CON c:GET i:9fe0 {01} [ Request-Tag:0x74bf5d09 ]
Jul 14 16:08:53.030 DEBG ***EVENT: COAP_EVENT_MSG_RETRANSMITTED
Jul 14 16:08:53.030 DEBG ** 192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : mid=0x9fe0: retransmission #3 (next 21504ms)
Jul 14 16:08:53.030 DEBG * 192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : netif: sent 12 bytes
v:1 t:CON c:GET i:9fe0 {01} [ Request-Tag:0x74bf5d09 ]
Jul 14 16:09:14.534 DEBG ***EVENT: COAP_EVENT_MSG_RETRANSMITTED
Jul 14 16:09:14.534 DEBG ** 192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : mid=0x9fe0: retransmission #4 (next 43008ms)
Jul 14 16:09:14.534 DEBG * 192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : netif: sent 12 bytes
v:1 t:CON c:GET i:9fe0 {01} [ Request-Tag:0x74bf5d09 ]
Jul 14 16:09:57.543 WARN ** 192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : mid=0x9fe0: give up after 4 attempts
**Jul 14 16:09:57.543 ERR cannot send CoAP pdu
Jul 14 16:09:57.543 DEBG *192.168.1.2:5683 <-> 192.168.1.1:5683 UDP : session 0x5651834f2a70: closed

Kindly, help to fix this bug.

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 14, 2023

This is not a bug, but there is no server responding to the client's requests - the logs are reporting that after 4 attempts to talk to the server, the client is giving up. This could be for a multitude of reasons, which could be the server is listening on the wrong IP address or port, the client it trying to talk to the wrong IP address, or there is a firewall rule dropping the request (or the servers response).

I am puzzled by

Jul 14 16:08:34.213 WARN coap_is_bcst: Insufficient space for broadcast addresses

It is as if you have more than 6 interfaces defined and enabled on the VM instance or host that you are running ./coap-client-tinydtls on - is this correct? Why so many interfaces?
It would be good to see the output from ifconfig -a.

@salmeghlef
Copy link
Author

That is totally true. I created 6 interfaces to test some attacks from different clients (multicast attack). I dedicated the interface 192.168.1.1 to run the coap-server-tinydtls. The others are for coap-client-tinydtls to test the coherent security for DTLS.

By the way, if I want to access global coap-servers such as californium by Achim. How to know the pre-shared key (PSK) ?? Do I have to contact the coap-server owner to know the secrets ???

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Jul 14, 2023

For anyone hosting a CoAP server, you will need to ask them what PSK (and Identity) to use. In this case it is sesame and password respectively.

@salmeghlef
Copy link
Author

Dear Olaf , I have created only three interfaces (tap1 192.168.1.1, tap2 and tap3 192.168.1.3)

I am running the coap-server on tap1 as follows:
./coap-server-tinydtls -v7 -A 192.168.1.1 -k mysecret 18:02:15.083 DEBG created TCP endpoint [::]:5683
18:02:15.084 DEBG created UDP endpoint [::]:5683
18:02:15.084 DEBG created DTLS endpoint [::]:5684
then,
I am running coap-client as follows:
./coap-client-tinydtls -v7 -k mysecret -a 192.168.1.2 -m get coap://192.168.1.1/
after 4 attemps, it says the client gives up with this error:
cannot send coAP pdu

I am following the documentation to write the commands, but it it is not working. kindly help ..

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Aug 9, 2023

I suspect that you have an underlying Linux networking issue with your tap interfaces and how they communicate (i.e forward / route packets). If the client / server work with regular network interfaces (can even be a single network interface), then this is not a libcoap issue.

That said,

$ ./coap-server-tinydtls -v7 -A 192.168.1.1 -k mysecret  
18:02:15.083 DEBG created TCP endpoint [::]:5683
18:02:15.084 DEBG created UDP endpoint [::]:5683
18:02:15.084 DEBG created DTLS endpoint [::]:5684

surprises me as I would expect the endpoint addresses to be

18:02:15.083 DEBG created TCP endpoint 192.168.1.1:5683
18:02:15.084 DEBG created UDP endpoint 192.168.1.1:5683
18:02:15.084 DEBG created DTLS endpoint 192.168.1.1:5684

if you are using the unchanged examples/coap-server.c as the source for your server application.

@salmeghlef
Copy link
Author

salmeghlef commented Aug 9, 2023

Thanks Olaf, it is working fine now after checking your suspicion by enabling the ip v4 route

however, when using coaps://

it says, WARN PSK is not defined

Cannot create client session

Kindly, guide me how to define the PSK since I tried to edit /etc/ipsec.secrets, then add:
192.168.1.1: PSK "mysecret"
but not working

Hence, 192.168.1.1 is my coap-server

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Aug 10, 2023

You are not using the IPSEC protocol here. So /etc/ipsec.secrets is not relevant here.

I suspect you need to include the -u option when running the client.

@salmeghlef
Copy link
Author

salmeghlef commented Aug 11, 2023

Thanks a lot Olaf. It is working now for coaps:// after embedding -u in the request.

The last inquiry is: if I am running coap-server-tinydtls , is DTLS is working on the port 5683 or I have to dedicate the requests to port 5684 to ensure DTLS is enabled.

18:02:15.083 DEBG created TCP endpoint 192.168.1.1:5683
18:02:15.084 DEBG created UDP endpoint 192.168.1.1:5683
18:02:15.084 DEBG created DTLS endpoint 192.168.1.1:5684

As it looks here, DTLS is working on port 5684!

@mrdeep1
Copy link
Collaborator

mrdeep1 commented Aug 11, 2023

coap-server-tinydtls (and coap-client-tinydtls) supports both the coap:// and coaps:// protocols. By default, a client using the coap:// scheme will talk to the CoAP UDP insecure port 5683 unless the port is explicitly stated in the URI and a client using the coaps:// scheme will talk to the CoAP UDP (DTLS) secure port 5684 unless the port is explicitly stated in the URI.

In a similar manner, the coap+tcp:// scheme will talk to the CoAP TCP insecure port 5683 unless the port is explicitly stated in the URI.

@salmeghlef
Copy link
Author

Thanks Olaf. I think it is time to close this issue. Your support is tremendously appreciated.

@mrdeep1 mrdeep1 closed this as completed Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants