diff options
Diffstat (limited to 'src/gnsrecord/test_gnsrecord_testvectors.c')
-rw-r--r-- | src/gnsrecord/test_gnsrecord_testvectors.c | 128 |
1 files changed, 128 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..153c56261 --- /dev/null +++ b/src/gnsrecord/test_gnsrecord_testvectors.c | |||
@@ -0,0 +1,128 @@ | |||
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 | "50d7b652a4efeadff37396909785e5952171a02178c8e7d450fa907925fafd98"; | ||
14 | |||
15 | |||
16 | static char *zid = | ||
17 | "00010000677c477d2d93097c85b195c6f96d84ff61f5982c2c4fe02d5a11fedfb0c2901f"; | ||
18 | |||
19 | #define RRCOUNT 2 | ||
20 | #define LABEL "test" | ||
21 | |||
22 | #define R0_EXPIRATION 14888744139323793 | ||
23 | #define R0_DATA_SIZE 4 | ||
24 | #define R0_TYPE 1 | ||
25 | #define R0_FLAGS 0 | ||
26 | #define R0_DATA "01020304" | ||
27 | |||
28 | /* Record #1*/ | ||
29 | #define R1_EXPIRATION 26147096139323793 | ||
30 | #define R1_DATA_SIZE 36 | ||
31 | #define R1_TYPE 65536 | ||
32 | #define R1_FLAGS 2 | ||
33 | #define R1_DATA \ | ||
34 | "000100000e601be42eb57fb4697610cf3a3b18347b65a33f025b5b174abefb30807bfecf" | ||
35 | |||
36 | #define R1_RRBLOCK \ | ||
37 | "000100008e16da87203b5159c5538e9b765742e968c54af9afbc0890dc80205ad14c84e107b0c115fc0089aa38b9c7ab9cbe1d77040d282a51a2ad493f61f3495f02d8170fe473a55ec6bdf9a509ab1701ffc37ea3bb4cac4a672520986df96e67cc1a73000000940000000f0034e53be193799100e4837eb5d04f92903de4b5234e8ccac5736c9793379a59c33375fc8951aca2eb7aad067bf9af60bf26758646a17f5e5c3b6215f94079545b1c4d4f1b2ebb22c2b4dad44126817b6f001530d476401dd67ac0148554e806353da9e4298079f3e1b16942c48d90c4360c61238c40d9d52911aea52cc0037ac7160bb3cf5b2f4a722fd96b" | ||
38 | |||
39 | int parsehex(char *src, char *dst, size_t dstlen, int invert) | ||
40 | { | ||
41 | char *line = src; | ||
42 | char *data = line; | ||
43 | int off; | ||
44 | int read_byte; | ||
45 | int data_len = 0; | ||
46 | |||
47 | while (sscanf(data, " %02x%n", &read_byte, &off) == 1) { | ||
48 | if (invert) | ||
49 | dst[dstlen - 1 - data_len++] = read_byte; | ||
50 | else | ||
51 | dst[data_len++] = read_byte; | ||
52 | data += off; | ||
53 | } | ||
54 | return data_len; | ||
55 | } | ||
56 | |||
57 | void | ||
58 | res_checker (void *cls, | ||
59 | unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) | ||
60 | { | ||
61 | int r0_found = 0; | ||
62 | int r1_found = 0; | ||
63 | char r0_data[R0_DATA_SIZE]; | ||
64 | char r1_data[R1_DATA_SIZE]; | ||
65 | parsehex(R0_DATA, (char*)r0_data, 0, 0); | ||
66 | parsehex(R1_DATA, (char*)r1_data, 0, 0); | ||
67 | GNUNET_assert (rd_count == RRCOUNT); | ||
68 | for (int i = 0; i < RRCOUNT; i++) | ||
69 | { | ||
70 | if (rd[i].record_type == R0_TYPE) | ||
71 | { | ||
72 | if (0 != memcmp (rd[i].data, r0_data, R0_DATA_SIZE)) | ||
73 | { | ||
74 | printf ("R0 Data mismatch\n"); | ||
75 | continue; | ||
76 | } | ||
77 | if (rd[i].expiration_time != R0_EXPIRATION) | ||
78 | { | ||
79 | printf ("R0 expiration mismatch\n"); | ||
80 | continue; | ||
81 | } | ||
82 | r0_found = 1; | ||
83 | } | ||
84 | if (rd[i].record_type == R1_TYPE) | ||
85 | { | ||
86 | if (0 != memcmp (rd[i].data, r1_data, R1_DATA_SIZE)) | ||
87 | { | ||
88 | printf ("R1 Data mismatch\n"); | ||
89 | continue; | ||
90 | } | ||
91 | if (rd[i].expiration_time != R1_EXPIRATION) | ||
92 | { | ||
93 | printf ("R1 expiration mismatch\n"); | ||
94 | continue; | ||
95 | } | ||
96 | |||
97 | r1_found = 1; | ||
98 | } | ||
99 | |||
100 | } | ||
101 | GNUNET_assert (r0_found); | ||
102 | GNUNET_assert (r1_found); | ||
103 | } | ||
104 | |||
105 | |||
106 | int | ||
107 | main() | ||
108 | { | ||
109 | struct GNUNET_IDENTITY_PrivateKey priv; | ||
110 | struct GNUNET_IDENTITY_PublicKey pub; | ||
111 | struct GNUNET_IDENTITY_PublicKey pub_parsed; | ||
112 | struct GNUNET_GNSRECORD_Block *rrblock; | ||
113 | char *bdata; | ||
114 | |||
115 | parsehex(d,(char*)&priv.ecdsa_key, sizeof (priv.ecdsa_key), 1); | ||
116 | priv.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
117 | parsehex(zid,(char*)&pub_parsed, 0, 0); | ||
118 | GNUNET_IDENTITY_key_get_public(&priv, &pub); | ||
119 | GNUNET_assert (0 == memcmp (&pub, &pub_parsed, sizeof (pub))); | ||
120 | rrblock = GNUNET_malloc (strlen (R1_RRBLOCK) / 2); | ||
121 | parsehex(R1_RRBLOCK, (char*)rrblock, 0, 0); | ||
122 | GNUNET_GNSRECORD_block_decrypt (rrblock, | ||
123 | &pub_parsed, | ||
124 | LABEL, | ||
125 | &res_checker, | ||
126 | NULL); | ||
127 | return 0; | ||
128 | } | ||