|
| 1 | +# DTLS 1.2 Multicast Example |
| 2 | + |
| 3 | +This example demonstrates DTLS 1.2 multicast communication using wolfSSL's multicast APIs. Three peer applications can securely communicate with each other over UDP multicast. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +DTLS multicast allows multiple peers to share encrypted/authenticated communication over IP multicast. Unlike traditional TLS/DTLS which uses a handshake to establish keys, multicast DTLS uses pre-shared secrets that are distributed out-of-band to all participants. |
| 8 | + |
| 9 | +This example uses: |
| 10 | +- **WDM-NULL-SHA256** cipher suite (NULL encryption with SHA-256 for message authentication) |
| 11 | +- Pre-shared secret material (PMS, client random, server random) |
| 12 | +- Multicast group `239.255.0.1:12345` |
| 13 | + |
| 14 | +NOTE: Since this is using NULL encryption, all messages going over the wire are plaintext. This example provides no confidentiality. |
| 15 | + |
| 16 | +## Requirements |
| 17 | + |
| 18 | +wolfSSL must be built with multicast support: |
| 19 | + |
| 20 | +```bash |
| 21 | +cd /path/to/wolfssl |
| 22 | +./configure --enable-dtls --enable-mcast |
| 23 | +make |
| 24 | +``` |
| 25 | + |
| 26 | +## Building |
| 27 | + |
| 28 | +```bash |
| 29 | +make |
| 30 | +``` |
| 31 | +## Usage |
| 32 | + |
| 33 | +Run each peer in a separate terminal with a unique node ID (0, 1, or 2): |
| 34 | + |
| 35 | +```bash |
| 36 | +# Terminal 1 |
| 37 | +./mcast-peer 0 |
| 38 | + |
| 39 | +# Terminal 2 |
| 40 | +./mcast-peer 1 |
| 41 | + |
| 42 | +# Terminal 3 |
| 43 | +./mcast-peer 2 |
| 44 | +``` |
| 45 | + |
| 46 | +Each peer will: |
| 47 | +1. Join the multicast group |
| 48 | +2. Send a message every 3 seconds |
| 49 | +3. Receive and display messages from other peers |
| 50 | +4. Exit cleanly on Ctrl+C |
| 51 | + |
| 52 | +## Example Output |
| 53 | + |
| 54 | +``` |
| 55 | +=== DTLS Multicast Peer - Node 0 === |
| 56 | +Node 0: Sockets ready, joined multicast group 239.255.0.1:12345 |
| 57 | +Node 0: Added peer 1 to receive tracking |
| 58 | +Node 0: Added peer 2 to receive tracking |
| 59 | +Node 0: Ready. Press Ctrl+C to exit. |
| 60 | +Node 0: Sending messages every 3 seconds... |
| 61 | +
|
| 62 | +Node 0: Sent: "Hello from node 0, message #1" |
| 63 | +Node 0: Received from peer 1: "Hello from node 1, message #1" |
| 64 | +Node 0: Received from peer 2: "Hello from node 2, message #1" |
| 65 | +``` |
| 66 | + |
| 67 | +## API Usage Notes |
| 68 | + |
| 69 | +The wolfSSL multicast APIs must be called in a specific order: |
| 70 | + |
| 71 | +1. `wolfSSL_CTX_mcast_set_member_id()` - Set this node's ID |
| 72 | +2. `wolfSSL_CTX_set_cipher_list()` - Set multicast cipher suite |
| 73 | +3. `wolfSSL_new()` - Create SSL objects |
| 74 | +4. `wolfSSL_mcast_peer_add()` - Register expected peers (**before** setting secret) |
| 75 | +5. `wolfSSL_set_secret()` - Set the pre-shared secret (**after** adding peers) |
| 76 | +6. `wolfSSL_write()` / `wolfSSL_mcast_read()` - Send/receive messages |
| 77 | + |
| 78 | +**Important**: `wolfSSL_mcast_peer_add()` must be called BEFORE `wolfSSL_set_secret()` because `wolfSSL_mcast_peer_add()` zeros the peer entry (including the epoch), and `wolfSSL_set_secret()` sets the epoch for all registered peers. |
| 79 | + |
| 80 | +## Key Concepts |
| 81 | + |
| 82 | +### Multicast Member ID |
| 83 | +Each peer has a unique ID (0-255) set via `wolfSSL_CTX_mcast_set_member_id()`. This ID is embedded in outgoing DTLS records and used by receivers to identify the sender. |
| 84 | + |
| 85 | +### Pre-Shared Secret |
| 86 | +All peers must use identical secret material: |
| 87 | +- Pre-master secret (PMS) |
| 88 | +- Client random |
| 89 | +- Server random |
| 90 | +- Cipher suite identifier |
| 91 | + |
| 92 | +In production, this material would be distributed securely out-of-band (e.g., via a key server). |
| 93 | + |
| 94 | +### NULL Encryption |
| 95 | +This example is using NULL encryption. That means all messages going over the wire are plaintext. This example provides no confidentiality. |
| 96 | + |
| 97 | +## References |
| 98 | + |
| 99 | +- [wolfSSL Manual - DTLS](https://www.wolfssl.com/documentation/manuals/wolfssl/chapter02.html) |
| 100 | +- [RFC 6347 - DTLS 1.2](https://tools.ietf.org/html/rfc6347) |
0 commit comments