1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369 | // Copyright (C) 2010-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
#include <exceptions/exceptions.h>
#include <util/buffer.h>
#include <dns/messagerenderer.h>
#include <dns/rdata.h>
#include <dns/rdataclass.h>
#include <dns/rrclass.h>
#include <dns/rrtype.h>
#include <dns/time_utils.h>
#include <gtest/gtest.h><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dns/tests/unittest_util.h>
#include <util/unittests/wiredata.h>
#include <dns/tests/rdata_unittest.h>
using namespace std;
using namespace isc;
using namespace isc::dns;
using namespace isc::util;
using namespace isc::dns::rdata;
using isc::UnitTestUtil;
using isc::util::unittests::matchWireData;
namespace {
const uint8_t wiredata_rrsig[] = {
// type covered = A
0x00, 0x01,
// algorithm = 5
0x05,
// labels = 4
0x04,
// original TTL = 43200 (0x0000a8c0)
0x00, 0x00, 0xa8, 0xc0,
// signature expiration = 1266961577 (0x4b844ca9)
0x4b, 0x84, 0x4c, 0xa9,
// signature inception = 1266875177 (0x4b82fb29)
0x4b, 0x82, 0xfb, 0x29,
// key tag = 8496 (0x2130)
0x21, 0x30,
// signer's name (isc.org.)
// 3 i s c 3 o r g 0
0x03, 0x69, 0x73, 0x63, 0x03, 0x6f, 0x72, 0x67, 0x00,
// signature data follows
0x7a, 0xfc, 0x61, 0x94, 0x6c,
0x75, 0xde, 0x6a, 0x4a, 0x2d, 0x59, 0x0a, 0xb2,
0x3a, 0x46, 0xcf, 0x27, 0x12, 0xe6, 0xdc, 0x2d,
0x22, 0x8c, 0x4e, 0x9a, 0x53, 0x75, 0xe3, 0x0f,
0x6d, 0xe4, 0x08, 0x33, 0x18, 0x19, 0xb3, 0x76,
0x21, 0x9d, 0x2c, 0x8a, 0xc5, 0x69, 0xba, 0xab,
0xef, 0x66, 0x9f, 0xda, 0xb5, 0x2a, 0xf9, 0x40,
0xc1, 0x28, 0xc5, 0x97, 0xba, 0x3c, 0x19, 0x4d,
0x95, 0x13, 0xc2, 0xcd, 0xf6, 0xb1, 0x59, 0x5d,
0x0c, 0xf9, 0x3f, 0x35, 0xbb, 0x9a, 0x70, 0x93,
0x36, 0xe5, 0xf4, 0x17, 0x7e, 0xfe, 0x66, 0x3b,
0x70, 0x1f, 0xed, 0x33, 0xa8, 0xa3, 0x0d, 0xc0,
0x8c, 0xc6, 0x95, 0x1b, 0xd8, 0x9c, 0x8c, 0x25,
0xb4, 0x57, 0x9e, 0x56, 0x71, 0x64, 0x14, 0x7f,
0x8f, 0x6d, 0xfa, 0xc5, 0xca, 0x3f, 0x36, 0xe2,
0xa4, 0xdf, 0x60, 0xfa, 0xcd, 0x59, 0x3e, 0x22,
0x32, 0xa1, 0xf7
};
class Rdata_RRSIG_Test : public RdataTest {
protected:
Rdata_RRSIG_Test() :
rrsig_txt("A 5 4 43200 20100223214617 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc="),
rdata_rrsig(rrsig_txt)
{}
void checkFromText_None(const string& rdata_str) {
checkFromText<generic::RRSIG, isc::Exception, isc::Exception>(
rdata_str, rdata_rrsig, false, false);
}
void checkFromText_InvalidText(const string& rdata_str) {
checkFromText<generic::RRSIG, InvalidRdataText, InvalidRdataText>(
rdata_str, rdata_rrsig, true, true);
}
void checkFromText_InvalidType(const string& rdata_str) {
checkFromText<generic::RRSIG, InvalidRRType, InvalidRRType>(
rdata_str, rdata_rrsig, true, true);
}
void checkFromText_InvalidTime(const string& rdata_str) {
checkFromText<generic::RRSIG, InvalidTime, InvalidTime>(
rdata_str, rdata_rrsig, true, true);
}
void checkFromText_BadValue(const string& rdata_str) {
checkFromText<generic::RRSIG, BadValue, BadValue>(
rdata_str, rdata_rrsig, true, true);
}
void checkFromText_LexerError(const string& rdata_str) {
checkFromText
<generic::RRSIG, InvalidRdataText, MasterLexer::LexerError>(
rdata_str, rdata_rrsig, true, true);
}
void checkFromText_MissingOrigin(const string& rdata_str) {
checkFromText
<generic::RRSIG, MissingNameOrigin, MissingNameOrigin>(
rdata_str, rdata_rrsig, true, true);
}
void checkFromText_BadString(const string& rdata_str) {
checkFromText
<generic::RRSIG, InvalidRdataText, isc::Exception>(
rdata_str, rdata_rrsig, true, false);
}
const string rrsig_txt;
const generic::RRSIG rdata_rrsig;
};
TEST_F(Rdata_RRSIG_Test, fromText) {<--- syntax error
EXPECT_EQ(rrsig_txt, rdata_rrsig.toText());
EXPECT_EQ(isc::dns::RRType::A(), rdata_rrsig.typeCovered());
// Missing signature is OK
EXPECT_NO_THROW(const generic::RRSIG sig(
"A 5 4 43200 20100223214617 20100222214617 8496 isc.org."));
// Space in signature data is OK
checkFromText_None(
"A 5 4 43200 20100223214617 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz "
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/ "
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU "
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
// Multi-line signature data is OK, if enclosed in parentheses
checkFromText_None(
"A 5 4 43200 20100223214617 20100222214617 8496 isc.org. "
"( evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz\n"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/\n"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU\n"
"f49t+sXKPzbipN9g+s1ZPiIyofc= )");
// Trailing garbage. This should cause only the string constructor
// to fail, but the lexer constructor must be able to continue
// parsing from it.
checkFromText_BadString(
"A 5 4 43200 20100223214617 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc= ; comment\n"
"A 5 4 43200 20100223214617 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
}
TEST_F(Rdata_RRSIG_Test, badText_missingFields) {
checkFromText_LexerError("A");
checkFromText_LexerError("A 5");
checkFromText_LexerError("A 5 4");
checkFromText_LexerError("A 5 4 43200");
checkFromText_LexerError("A 5 4 43200 20100223214617");
checkFromText_LexerError("A 5 4 43200 20100223214617 20100222214617");
checkFromText_LexerError("A 5 4 43200 20100223214617 20100222214617 "
"8496");
}
TEST_F(Rdata_RRSIG_Test, badText_coveredType) {
checkFromText_InvalidType("SPORK");
}
TEST_F(Rdata_RRSIG_Test, badText_algorithm) {
checkFromText_InvalidText(
"A 555 4 43200 "
"20100223214617 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
checkFromText_LexerError(
"A FIVE 4 43200 "
"20100223214617 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
}
TEST_F(Rdata_RRSIG_Test, badText_labels) {
checkFromText_InvalidText(
"A 5 4444 43200 "
"20100223214617 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
checkFromText_LexerError(
"A 5 FOUR 43200 "
"20100223214617 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
}
TEST_F(Rdata_RRSIG_Test, badText_ttl) {
checkFromText_LexerError(
"A 5 4 999999999999 "
"20100223214617 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
checkFromText_LexerError(
"A 5 4 TTL "
"20100223214617 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
// alternate form of TTL is not okay
checkFromText_LexerError(
"A 5 4 12H 20100223214617 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz "
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/ "
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU "
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
}
TEST_F(Rdata_RRSIG_Test, badText_expiration) {
checkFromText_InvalidTime(
"A 5 4 43200 "
"201002232 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
checkFromText_InvalidTime(
"A 5 4 43200 "
"EXPIRATION 20100222214617 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
}
TEST_F(Rdata_RRSIG_Test, badText_inception) {
checkFromText_InvalidTime(
"A 5 4 43200 "
"20100223214617 20100227 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
checkFromText_InvalidTime(
"A 5 4 43200 "
"20100223214617 INCEPTION 8496 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
}
TEST_F(Rdata_RRSIG_Test, badText_keytag) {
checkFromText_InvalidText(
"A 5 4 43200 "
"20100223214617 20100222214617 999999 isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
checkFromText_LexerError(
"A 5 4 43200 "
"20100223214617 20100222214617 TAG isc.org. "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
}
TEST_F(Rdata_RRSIG_Test, badText_signer) {
checkFromText_MissingOrigin(
"A 5 4 43200 "
"20100223214617 20100222214617 8496 isc.org "
"evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
}
TEST_F(Rdata_RRSIG_Test, badText_signature) {
checkFromText_BadValue(
"A 5 4 43200 "
"20100223214617 20100222214617 8496 isc.org. "
"EEeeeeeeEEEeeeeeeGaaahAAAAAAAAHHHHHHHHHHH!=");
// no space between the tag and signer
checkFromText_LexerError(
"A 5 4 43200 20100223214617 20100222214617 "
"8496isc.org. ofc=");
// unterminated multi-line base64
checkFromText_LexerError(
"A 5 4 43200 20100223214617 20100222214617 8496 isc.org. "
"( evxhlGx13mpKLVkKsjpGzycS5twtIoxOmlN14w9t5AgzGBmz\n"
"diGdLIrFabqr72af2rUq+UDBKMWXujwZTZUTws32sVldDPk/\n"
"NbuacJM25fQXfv5mO3Af7TOoow3AjMaVG9icjCW0V55WcWQU\n"
"f49t+sXKPzbipN9g+s1ZPiIyofc=");
}
TEST_F(Rdata_RRSIG_Test, createFromLexer) {
EXPECT_EQ(0, rdata_rrsig.compare(
*test::createRdataUsingLexer(RRType::RRSIG(), RRClass::IN(),
rrsig_txt)));
// Exceptions cause null to be returned.
EXPECT_FALSE(test::createRdataUsingLexer(RRType::RRSIG(), RRClass::IN(),
"INVALIDINPUT"));
}
TEST_F(Rdata_RRSIG_Test, toWireRenderer) {
rdata_rrsig.toWire(renderer);
matchWireData(wiredata_rrsig, sizeof(wiredata_rrsig),
renderer.getData(), renderer.getLength());
}
TEST_F(Rdata_RRSIG_Test, toWireBuffer) {
rdata_rrsig.toWire(obuffer);
matchWireData(wiredata_rrsig, sizeof(wiredata_rrsig),
obuffer.getData(), obuffer.getLength());
}
TEST_F(Rdata_RRSIG_Test, createFromWire) {
const string rrsig_txt2(
"A 5 2 43200 20100327070149 20100225070149 2658 isc.org. "
"HkJk/xZTvzePU8NENl/ley8bbUumhk1hXciyqhLnz1VQFzkDooej6neX"
"ZgWZzQKeTKPOYWrnYtdZW4PnPQFeUl3orgLev7F8J6FZlDn0y/J/ThR5"
"m36Mo2/Gdxjj8lJ/IjPVkdpKyBpcnYND8KEIma5MyNCNeyO1UkfPQZGHNSQ=");
EXPECT_EQ(rrsig_txt2,
rdataFactoryFromFile(RRType("RRSIG"), RRClass("IN"),
"rdata_rrsig_fromWire1")->toText());
const generic::RRSIG rdata_rrsig2(rrsig_txt2);
EXPECT_EQ(0, rdata_rrsig2.compare(
*rdataFactoryFromFile(RRType("RRSIG"), RRClass("IN"),
"rdata_rrsig_fromWire1")));
// RDLEN is too short
EXPECT_THROW(rdataFactoryFromFile(RRType::RRSIG(), RRClass::IN(),
"rdata_rrsig_fromWire2.wire"),
InvalidRdataLength);
}
}
|