| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
#ifdef HAVE_CONFIG_H |
|---|
| 21 |
# include <config.h> |
|---|
| 22 |
#endif |
|---|
| 23 |
|
|---|
| 24 |
#include <stdint.h> |
|---|
| 25 |
#include <stddef.h> |
|---|
| 26 |
#include "srtp.h" |
|---|
| 27 |
|
|---|
| 28 |
#include <stdio.h> |
|---|
| 29 |
#include <string.h> |
|---|
| 30 |
|
|---|
| 31 |
#include <unistd.h> |
|---|
| 32 |
#include <netinet/in.h> |
|---|
| 33 |
|
|---|
| 34 |
int main (void) |
|---|
| 35 |
{ |
|---|
| 36 |
int fd = socket (AF_INET, SOCK_DGRAM, 0); |
|---|
| 37 |
struct sockaddr_in addr; |
|---|
| 38 |
memset (&addr, 0, sizeof (addr)); |
|---|
| 39 |
addr.sin_family = AF_INET; |
|---|
| 40 |
#ifdef HAVE_SA_LEN |
|---|
| 41 |
addr.sin_len = sizeof (addr); |
|---|
| 42 |
#endif |
|---|
| 43 |
addr.sin_port = htons (10000); |
|---|
| 44 |
addr.sin_addr.s_addr = htonl (0x7f000001); |
|---|
| 45 |
if (bind (fd, (struct sockaddr *)&addr, sizeof (addr))) |
|---|
| 46 |
return 1; |
|---|
| 47 |
|
|---|
| 48 |
static const uint8_t key[16] = |
|---|
| 49 |
"\x12\x34\x56\x78\x9A\xBC\xDE\xF0" |
|---|
| 50 |
"\x12\x34\x56\x78\x9A\xBC\xDE\xF0"; |
|---|
| 51 |
static const uint8_t salt[14] = |
|---|
| 52 |
"\x12\x34\x56\x78\x90" "\x12\x34\x56\x78\x90" "\x12\x34\x56\x78"; |
|---|
| 53 |
|
|---|
| 54 |
srtp_session_t *s = srtp_create (SRTP_ENCR_AES_CM, SRTP_AUTH_HMAC_SHA1, 10, |
|---|
| 55 |
SRTP_PRF_AES_CM, 0); |
|---|
| 56 |
if (s == NULL) |
|---|
| 57 |
return 1; |
|---|
| 58 |
if (srtp_setkey (s, key, 16, salt, 14)) |
|---|
| 59 |
goto error; |
|---|
| 60 |
|
|---|
| 61 |
uint8_t buf[1500]; |
|---|
| 62 |
size_t len; |
|---|
| 63 |
#if 0 |
|---|
| 64 |
memset (buf, 0, sizeof (buf)); |
|---|
| 65 |
buf[0] = 2 << 6; |
|---|
| 66 |
buf[1] = 1; |
|---|
| 67 |
memcpy (buf + 2, &(uint16_t){ htons (9527) }, 2); |
|---|
| 68 |
memcpy (buf + 8, "\xde\xad\xbe\xef", 4); |
|---|
| 69 |
memcpy (buf + 4, &(uint32_t){ htonl (1) }, 4); |
|---|
| 70 |
strcpy ((char *)buf + 12, "a\n"); |
|---|
| 71 |
len = 12 + strlen ((char *)buf + 12) + 1; |
|---|
| 72 |
#endif |
|---|
| 73 |
for (;;) |
|---|
| 74 |
{ |
|---|
| 75 |
len = read (fd, buf, sizeof (buf)); |
|---|
| 76 |
int val = srtp_recv (s, buf, &len); |
|---|
| 77 |
if (val) |
|---|
| 78 |
{ |
|---|
| 79 |
fprintf (stderr, "Cannot decrypt: %s\n", strerror (val)); |
|---|
| 80 |
continue; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
puts ((char *)buf + 12); |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
puts ((char *)buf + 12); |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
error: |
|---|
| 90 |
srtp_destroy (s); |
|---|
| 91 |
close (fd); |
|---|
| 92 |
return 0; |
|---|
| 93 |
} |
|---|