diff options
Diffstat (limited to 'src/gnsrecord/test_gnsrecord_testvectors.c')
-rw-r--r-- | src/gnsrecord/test_gnsrecord_testvectors.c | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/src/gnsrecord/test_gnsrecord_testvectors.c b/src/gnsrecord/test_gnsrecord_testvectors.c new file mode 100644 index 000000000..67085c089 --- /dev/null +++ b/src/gnsrecord/test_gnsrecord_testvectors.c | |||
@@ -0,0 +1,135 @@ | |||
1 | #include "platform.h" | ||
2 | #include "gnunet_util_lib.h" | ||
3 | #include "gnunet_signatures.h" | ||
4 | #include "gnunet_gns_service.h" | ||
5 | #include "gnunet_gnsrecord_lib.h" | ||
6 | #include "gnunet_dnsparser_lib.h" | ||
7 | #include "gnunet_testing_lib.h" | ||
8 | #include <inttypes.h> | ||
9 | |||
10 | |||
11 | |||
12 | static char *d = | ||
13 | "f81e0165a9d95177" | ||
14 | "8e1210715f6b38a0" | ||
15 | "3df791ac1b75cd1e" | ||
16 | "dba5de4546ba565f"; | ||
17 | |||
18 | |||
19 | static char *zid = | ||
20 | "00010000d4d4dd1b" | ||
21 | "2671d5e181dc17b4" | ||
22 | "5d7e511d5de03a1f" | ||
23 | "bdcf2e8791cfd4e5" | ||
24 | "d11b6c3b"; | ||
25 | |||
26 | #define RRCOUNT 2 | ||
27 | #define LABEL "test" | ||
28 | |||
29 | #define R0_EXPIRATION 14888738786885085 | ||
30 | #define R0_DATA_SIZE 4 | ||
31 | #define R0_TYPE 1 | ||
32 | #define R0_FLAGS 0 | ||
33 | #define R0_DATA "01020304" | ||
34 | |||
35 | /* Record #1*/ | ||
36 | #define R1_EXPIRATION 26147090786885085 | ||
37 | #define R1_DATA_SIZE 36 | ||
38 | #define R1_TYPE 65536 | ||
39 | #define R1_FLAGS 2 | ||
40 | #define R1_DATA \ | ||
41 | "00010000060aa8a60cb0f2b039fa3e2208c9d0e7def84d793a695fd8743fd1e0317a84ee" | ||
42 | |||
43 | #define R1_RRBLOCK \ | ||
44 | "0001000040d538f47218b3a3559f6123fd7daf0313851d3ea99e95a24e50bd389453235009f3782627f1854d12ef4af86a2c614620b6af6f6f9666f12db4352a22a40b3903180c9b8707546be464b821960e3c908bfa135b4e5453b8c41377f6d9666901000000940000000f0034e53aa28bbddd43b26fb37089034819e6e4facf3036b270d761bbaddd9f44d2293dc25fc3bc405092786138215dc1c5a988b741892c5d191687acbedfa21d3baee4325c176742ec8f29c576a8ed684d28934ab671b47e44424fd453476071b9412b6b77da4cb9c24b9da6de79e74b6e44fee012091edd2ea441dc1b0ce3c608a4438ec2abaec699c0d006" | ||
45 | |||
46 | int parsehex(char *src, char *dst, size_t dstlen, int invert) | ||
47 | { | ||
48 | char *line = src; | ||
49 | char *data = line; | ||
50 | int off; | ||
51 | int read_byte; | ||
52 | int data_len = 0; | ||
53 | |||
54 | while (sscanf(data, " %02x%n", &read_byte, &off) == 1) { | ||
55 | if (invert) | ||
56 | dst[dstlen - 1 - data_len++] = read_byte; | ||
57 | else | ||
58 | dst[data_len++] = read_byte; | ||
59 | data += off; | ||
60 | } | ||
61 | return data_len; | ||
62 | } | ||
63 | |||
64 | void | ||
65 | res_checker (void *cls, | ||
66 | unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) | ||
67 | { | ||
68 | int r0_found = 0; | ||
69 | int r1_found = 0; | ||
70 | char r0_data[R0_DATA_SIZE]; | ||
71 | char r1_data[R1_DATA_SIZE]; | ||
72 | parsehex(R0_DATA, (char*)r0_data, 0, 0); | ||
73 | parsehex(R1_DATA, (char*)r1_data, 0, 0); | ||
74 | GNUNET_assert (rd_count == RRCOUNT); | ||
75 | for (int i = 0; i < RRCOUNT; i++) | ||
76 | { | ||
77 | if (rd[i].record_type == R0_TYPE) | ||
78 | { | ||
79 | if (0 != memcmp (rd[i].data, r0_data, R0_DATA_SIZE)) | ||
80 | { | ||
81 | printf ("R0 Data mismatch\n"); | ||
82 | continue; | ||
83 | } | ||
84 | if (rd[i].expiration_time != R0_EXPIRATION) | ||
85 | { | ||
86 | printf ("R0 expiration mismatch\n"); | ||
87 | continue; | ||
88 | } | ||
89 | r0_found = 1; | ||
90 | } | ||
91 | if (rd[i].record_type == R1_TYPE) | ||
92 | { | ||
93 | if (0 != memcmp (rd[i].data, r1_data, R1_DATA_SIZE)) | ||
94 | { | ||
95 | printf ("R1 Data mismatch\n"); | ||
96 | continue; | ||
97 | } | ||
98 | if (rd[i].expiration_time != R1_EXPIRATION) | ||
99 | { | ||
100 | printf ("R1 expiration mismatch\n"); | ||
101 | continue; | ||
102 | } | ||
103 | |||
104 | r1_found = 1; | ||
105 | } | ||
106 | |||
107 | } | ||
108 | GNUNET_assert (r0_found); | ||
109 | GNUNET_assert (r1_found); | ||
110 | } | ||
111 | |||
112 | |||
113 | int | ||
114 | main() | ||
115 | { | ||
116 | struct GNUNET_IDENTITY_PrivateKey priv; | ||
117 | struct GNUNET_IDENTITY_PublicKey pub; | ||
118 | struct GNUNET_IDENTITY_PublicKey pub_parsed; | ||
119 | struct GNUNET_GNSRECORD_Block *rrblock; | ||
120 | char *bdata; | ||
121 | |||
122 | parsehex(d,(char*)&priv.ecdsa_key, sizeof (priv.ecdsa_key), 0); | ||
123 | priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
124 | parsehex(zid,(char*)&pub_parsed, 0, 0); | ||
125 | GNUNET_IDENTITY_key_get_public(&priv, &pub); | ||
126 | GNUNET_assert (0 == memcmp (&pub, &pub_parsed, sizeof (pub))); | ||
127 | rrblock = GNUNET_malloc (strlen (R1_RRBLOCK) / 2); | ||
128 | parsehex(R1_RRBLOCK, (char*)rrblock, 0, 0); | ||
129 | GNUNET_GNSRECORD_block_decrypt (rrblock, | ||
130 | &pub_parsed, | ||
131 | LABEL, | ||
132 | &res_checker, | ||
133 | NULL); | ||
134 | return 0; | ||
135 | } | ||