contiki-ng / tinydtls

A version of tinyDTLS that is refactored to be more easy to use "standalone" (e.g. without bindings to a specific IP-stack).
Other
8 stars 25 forks source link

Help on testing contiki-ng's coap-server with TinyDTLS and libcoap's client #17

Closed dpapdpap closed 3 years ago

dpapdpap commented 4 years ago

Hi, I try to connect libcoap's coap-client and contiki-ng's coap-server. Without DTLS they can connect and exchange messages as expected. Using TinyDTLS on client's site and compiling coap-server with TinyDTLS (I append in project.conf: MAKE_WITH_DTLS=1 MAKE_COAP_DTLS_KEYSTORE=MAKE_COAP_DTLS_KEYSTORE_SIMPLE

define COAP_DTLS_PSK_DEFAULT_IDENTITY "Client_identity"

define COAP_DTLS_PSK_DEFAULT_KEY "secretPSK"), the server reject the connection with this output :

pi@raspberrypi:~/libcoap/examples $ ./coap-client -m get coaps://[fd00::212:4b00:1204:ddc6]/ -u Client_identity -k secretPSK -v9
Jul 21 00:54:19.530 DEBG ***[fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: new outgoing session
Jul 21 00:54:19.530 DEBG ***new session 0x1a1a120
Jul 21 00:54:19 DEBG dtls_new_peer: [fd00::212:4b00:1204:ddc6]:5684
Jul 21 00:54:19 DEBG DTLSv12: initialize HASH_SHA256
Jul 21 00:54:19 DEBG send handshake packet of type: client_hello (1)
Jul 21 00:54:19 DEBG send header: (13 bytes):
00000000 16 FE FF 00 00 00 00 00  00 00 00 00 36 
Jul 21 00:54:19 DEBG send unencrypted: (12 bytes):
00000000 01 00 00 2A 00 00 00 00  00 00 00 2A 
Jul 21 00:54:19 DEBG send unencrypted: (42 bytes):
00000000 FE FD 00 00 00 00 2B 03  A4 B1 8A 6C 3A A7 09 63 
00000010 53 2B 02 27 A2 32 70 E0  F8 52 79 BA 00 34 0C 87 
00000020 26 39 00 00 00 02 C0 A8  01 00 
Jul 21 00:54:19.531 DEBG *  [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: sent 67 bytes
Jul 21 00:54:19.531 DEBG sending CoAP request:
Jul 21 00:54:19.531 DEBG ** [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: tid=22224: delayed
Jul 21 00:54:19.531 DEBG timeout is set to 90 seconds
Jul 21 00:54:19.531 DEBG ** DTLS global timeout set to 2000ms
Jul 21 00:54:20.532 DEBG ** DTLS global timeout set to 999ms
Jul 21 00:54:21 DEBG ** retransmit handshake packet of type: client_hello (1)
Jul 21 00:54:21 DEBG retransmit header: (13 bytes):
00000000 16 FE FD 00 00 00 00 00  00 00 01 00 36 
Jul 21 00:54:21 DEBG retransmit unencrypted: (54 bytes):
00000000 01 00 00 2A 00 00 00 00  00 00 00 2A FE FD 00 00 
00000010 00 00 2B 03 A4 B1 8A 6C  3A A7 09 63 53 2B 02 27 
00000020 A2 32 70 E0 F8 52 79 BA  00 34 0C 87 26 39 00 00 
00000030 00 02 C0 A8 01 00 
Jul 21 00:54:21.532 DEBG *  [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: sent 67 bytes
Jul 21 00:54:21.532 DEBG ** DTLS global timeout set to 4001ms
Jul 21 00:54:21.532 DEBG ** DTLS global timeout set to 4000ms
Jul 21 00:54:21.642 DEBG *  [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: received 44 bytes
Jul 21 00:54:21 DEBG dtls_handle_message: FOUND PEER
Jul 21 00:54:21 DEBG got packet 22 (44 bytes)
Jul 21 00:54:21 DEBG receive header: (13 bytes):
00000000 16 FE FD 00 00 00 00 00  00 00 00 00 1F 
Jul 21 00:54:21 DEBG receive unencrypted: (31 bytes):
00000000 03 00 00 13 00 00 00 00  00 00 00 13 FE FD 10 EB 
00000010 B7 C4 4E 39 B0 C0 7D 96  E9 C1 C0 AA B2 E8 D5 
Jul 21 00:54:21 DEBG received handshake packet of type: hello_verify_request (3)
Jul 21 00:54:21 DEBG handle handshake packet of type: hello_verify_request (3)
Jul 21 00:54:21 DEBG clear MAC
Jul 21 00:54:21 DEBG add MAC data: (12 bytes): 0100003A000100000000003A
Jul 21 00:54:21 DEBG add MAC data: (58 bytes): FEFD000000002B03A4B18A6C3AA70963532B0227A23270E0F85279BA00340C8726390010EBB7C44E39B0C07D96E9C1C0AAB2E8D50002C0A80100
Jul 21 00:54:21 DEBG send handshake packet of type: client_hello (1)
Jul 21 00:54:21 DEBG send header: (13 bytes):
00000000 16 FE FF 00 00 00 00 00  00 00 02 00 46 
Jul 21 00:54:21 DEBG send unencrypted: (12 bytes):
00000000 01 00 00 3A 00 01 00 00  00 00 00 3A 
Jul 21 00:54:21 DEBG send unencrypted: (58 bytes):
00000000 FE FD 00 00 00 00 2B 03  A4 B1 8A 6C 3A A7 09 63 
00000010 53 2B 02 27 A2 32 70 E0  F8 52 79 BA 00 34 0C 87 
00000020 26 39 00 10 EB B7 C4 4E  39 B0 C0 7D 96 E9 C1 C0 
00000030 AA B2 E8 D5 00 02 C0 A8  01 00 
Jul 21 00:54:21.644 DEBG *  [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: sent 83 bytes
Jul 21 00:54:21.644 DEBG ** DTLS global timeout set to 2000ms
Jul 21 00:54:22.645 DEBG ** DTLS global timeout set to 999ms
Jul 21 00:54:23 DEBG ** retransmit handshake packet of type: client_hello (1)
Jul 21 00:54:23 DEBG retransmit header: (13 bytes):
00000000 16 FE FD 00 00 00 00 00  00 00 03 00 46 
Jul 21 00:54:23 DEBG retransmit unencrypted: (70 bytes):
00000000 01 00 00 3A 00 01 00 00  00 00 00 3A FE FD 00 00 
00000010 00 00 2B 03 A4 B1 8A 6C  3A A7 09 63 53 2B 02 27 
00000020 A2 32 70 E0 F8 52 79 BA  00 34 0C 87 26 39 00 10 
00000030 EB B7 C4 4E 39 B0 C0 7D  96 E9 C1 C0 AA B2 E8 D5 
00000040 00 02 C0 A8 01 00 
Jul 21 00:54:23.645 DEBG *  [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: sent 83 bytes
Jul 21 00:54:23.645 DEBG ** DTLS global timeout set to 4001ms
Jul 21 00:54:23.645 DEBG ** DTLS global timeout set to 4000ms
Jul 21 00:54:23.813 DEBG *  [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: received 63 bytes
Jul 21 00:54:23 DEBG dtls_handle_message: FOUND PEER
Jul 21 00:54:23 DEBG got packet 22 (63 bytes)
Jul 21 00:54:23 DEBG new packet arrived with seq_nr: 1
Jul 21 00:54:23 DEBG new bitfield is               : ffffffffffffffff
Jul 21 00:54:23 DEBG receive header: (13 bytes):
00000000 16 FE FD 00 00 00 00 00  00 00 01 00 32 
Jul 21 00:54:23 DEBG receive unencrypted: (50 bytes):
00000000 02 00 00 26 00 01 00 00  00 00 00 26 FE FD 00 00 
00000010 03 F9 FC 5F BC AF 79 17  49 A5 8F B9 53 47 50 85 
00000020 6C 80 B1 18 C9 2A CC F8  6E 1C 2D CD F5 B8 00 C0 
00000030 A8 00 
Jul 21 00:54:23 DEBG received handshake packet of type: server_hello (2)
Jul 21 00:54:23 DEBG handle handshake packet of type: server_hello (2)
Jul 21 00:54:23 DEBG add MAC data: (50 bytes): 020000260001000000000026FEFD000003F9FC5FBCAF791749A58FB9534750856C80B118C92ACCF86E1C2DCDF5B800C0A800
Jul 21 00:54:23.837 DEBG *  [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: received 25 bytes
Jul 21 00:54:23 DEBG dtls_handle_message: FOUND PEER
Jul 21 00:54:23 DEBG got packet 22 (25 bytes)
Jul 21 00:54:23 DEBG new packet arrived with seq_nr: 2
Jul 21 00:54:23 DEBG new bitfield is               : ffffffffffffffff
Jul 21 00:54:23 DEBG receive header: (13 bytes):
00000000 16 FE FD 00 00 00 00 00  00 00 02 00 0C 
Jul 21 00:54:23 DEBG receive unencrypted: (12 bytes):
00000000 0E 00 00 00 00 02 00 00  00 00 00 00 
Jul 21 00:54:23 DEBG received handshake packet of type: server_hello_done (14)
Jul 21 00:54:23 DEBG handle handshake packet of type: server_hello_done (14)
Jul 21 00:54:23 DEBG add MAC data: (12 bytes): 0E0000000002000000000000
Jul 21 00:54:23.838 DEBG got psk_identity_hint: ''
Jul 21 00:54:23.838 INFO Identity Hint '' provided
Jul 21 00:54:23 DEBG add MAC data: (12 bytes): 100000110002000000000011
Jul 21 00:54:23 DEBG add MAC data: (17 bytes): 000F436C69656E745F6964656E74697479
Jul 21 00:54:23 DEBG send handshake packet of type: client_key_exchange (16)
Jul 21 00:54:23 DEBG send header: (13 bytes):
00000000 16 FE FD 00 00 00 00 00  00 00 04 00 1D 
Jul 21 00:54:23 DEBG send unencrypted: (12 bytes):
00000000 10 00 00 11 00 02 00 00  00 00 00 11 
Jul 21 00:54:23 DEBG send unencrypted: (17 bytes):
00000000 00 0F 43 6C 69 65 6E 74  5F 69 64 65 6E 74 69 74 
00000010 79 
Jul 21 00:54:23.838 DEBG *  [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: sent 42 bytes
Jul 21 00:54:23 DEBG psk: (9 bytes):
00000000 73 65 63 72 65 74 50 53  4B 
Jul 21 00:54:23 DEBG client_random: (32 bytes): 000000002B03A4B18A6C3AA70963532B0227A23270E0F85279BA00340C872639
Jul 21 00:54:23 DEBG server_random: (32 bytes): 000003F9FC5FBCAF791749A58FB9534750856C80B118C92ACCF86E1C2DCDF5B8

Jul 21 00:54:23 DEBG pre_master_secret: (22 bytes): 0009000000000000000000000973656372657450534B
Jul 21 00:54:23 DEBG master_secret: (48 bytes): 3E223992F158E4BA08F73CD0C8ACA7095121006FC2CC847D1AACC8AAC0FB9CAE7B85AA0F2B56AEC5B58119C87B20D598
Jul 21 00:54:23 DEBG key_block (40 bytes):
Jul 21 00:54:23 DEBG   client_MAC_secret: (0 bytes): 
Jul 21 00:54:23 DEBG   server_MAC_secret: (0 bytes): 
Jul 21 00:54:23 DEBG   client_write_key: (16 bytes): 4A34346C03C2663C6B8E841013D1DDCC
Jul 21 00:54:23 DEBG   server_write_key: (16 bytes): 54587DE735010C566107EFAE354174FD
Jul 21 00:54:23 DEBG   client_IV: (4 bytes): FB407F58
Jul 21 00:54:23 DEBG   server_IV: (4 bytes): 4F528AD3
Jul 21 00:54:23 DEBG send header: (13 bytes):
00000000 14 FE FD 00 00 00 00 00  00 00 05 00 01 
Jul 21 00:54:23 DEBG send unencrypted: (1 bytes):
00000000 01 
Jul 21 00:54:23.840 DEBG *  [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: sent 14 bytes
Jul 21 00:54:23 DEBG server finished MAC: (12 bytes): 2D9C9F21432DFAF331BD2A76
Jul 21 00:54:23 DEBG add MAC data: (12 bytes): 1400000C000300000000000C
Jul 21 00:54:23 DEBG add MAC data: (12 bytes): 2D9C9F21432DFAF331BD2A76
Jul 21 00:54:23 DEBG send handshake packet of type: finished (20)
Jul 21 00:54:23 DEBG dtls_prepare_record(): encrypt using TLS_PSK_WITH_AES_128_CCM_8
Jul 21 00:54:23 DEBG nonce:: (16 bytes): FB407F58000100000000000000000000
Jul 21 00:54:23 DEBG key:: (16 bytes): 4A34346C03C2663C6B8E841013D1DDCC
Jul 21 00:54:23 DEBG message:: (40 bytes): 000100000000000075F072E5F4D55546D2D95CECE8104F7D9C3744F9F0C8F092B0B2B86FDA1479C5
Jul 21 00:54:23 DEBG send header: (13 bytes):
00000000 16 FE FD 00 01 00 00 00  00 00 00 00 28 
Jul 21 00:54:23 DEBG send unencrypted: (12 bytes):
00000000 14 00 00 0C 00 03 00 00  00 00 00 0C 
Jul 21 00:54:23 DEBG send unencrypted: (12 bytes):
00000000 2D 9C 9F 21 43 2D FA F3  31 BD 2A 76 
Jul 21 00:54:23.841 DEBG *  [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: sent 53 bytes
Jul 21 00:54:23.842 DEBG ** DTLS global timeout set to 1997ms
Jul 21 00:54:23.919 DEBG *  [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: received 15 bytes
Jul 21 00:54:23 DEBG dtls_handle_message: FOUND PEER
Jul 21 00:54:23 DEBG got packet 21 (15 bytes)
Jul 21 00:54:23 DEBG new packet arrived with seq_nr: 3
Jul 21 00:54:23 DEBG new bitfield is               : ffffffffffffffff
Jul 21 00:54:23 DEBG receive header: (13 bytes):
00000000 15 FE FD 00 00 00 00 00  00 00 03 00 02 
Jul 21 00:54:23 DEBG receive unencrypted: (2 bytes):
00000000 02 33 
Jul 21 00:54:23 INFO ** Alert: level 2, description 51
Jul 21 00:54:23 ALRT 51 invalidate peer
Jul 21 00:54:23 DEBG removed peer: [fd00::212:4b00:1204:ddc6]:5684
Jul 21 00:54:23 WARN received alert, peer has been invalidated
Jul 21 00:54:23.920 DEBG ***EVENT: 0x0200
Jul 21 00:54:23.920 DEBG ***[fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: session disconnected (reason 3)
Jul 21 00:54:23.920 DEBG ***removed session 0x1a1a120
Jul 21 00:54:23.920 DEBG ***EVENT: 0x0000
Jul 21 00:54:23.920 DEBG ** [fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: tid=22224: not transmitted after disconnect
Jul 21 00:54:23.921 DEBG ***[fd00::1]:37517 <-> [fd00::212:4b00:1204:ddc6]:5684 DTLS: session closed

Can somebody help to solve this problem please ? I suppose there are many other that faced this problem. How they solved it ? Thanks in advance