]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[(no branch, rebasing 1880-implement-the-tkey-rr)] [(no branch, rebasing 1880-impleme...
authorFrancis Dupont <fdupont@isc.org>
Tue, 25 May 2021 20:50:32 +0000 (20:50 +0000)
committerFrancis Dupont <fdupont@isc.org>
Thu, 3 Jun 2021 09:42:15 +0000 (11:42 +0200)
17 files changed:
src/lib/dns/tests/rdata_tkey_unittest.cc
src/lib/dns/tests/testdata/Makefile.am
src/lib/dns/tests/testdata/rdata_tkey_fromWire1.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_fromWire2.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_fromWire3.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_fromWire4.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_fromWire5.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_fromWire6.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_fromWire7.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_fromWire8.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_fromWire9.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_toWire1.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_toWire2.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_toWire3.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_toWire4.spec [new file with mode: 0644]
src/lib/dns/tests/testdata/rdata_tkey_toWire5.spec [new file with mode: 0644]
src/lib/util/python/gen_wiredata.py.in

index 3bdc731dd132662d494a585936020da067c0a968..58006f196e6102712057a7c46616bcb18c0ebd41 100644 (file)
@@ -161,7 +161,6 @@ TEST_F(Rdata_TKEY_Test, badText) {
     // not enough fields
     checkFromText_LexerError("foo 20210501120000 20210501130000 0 BADKEY");
     // bad domain name
-    std::cerr << "checkFromText_TooLongLabel\n";
     checkFromText_TooLongLabel(
         "0123456789012345678901234567890123456789012345678901234567890123"
         " 20210501120000 20210501130000 0 0 0 0");
@@ -235,18 +234,13 @@ TEST_F(Rdata_TKEY_Test, createFromWireWithOtherData) {
                                         "rdata_tkey_fromWire2.wire"));
     const generic::TKEY& tkey(dynamic_cast<generic::TKEY&>(*rdata));
 
-    ////
-#if 0
-    expect_data.resize(6);
-    expect_data[0] = (otherdata >> 40);
-    expect_data[1] = ((otherdata >> 32) & 0xff);
-    expect_data[2] = ((otherdata >> 24) & 0xff);
-    expect_data[3] = ((otherdata >> 16) & 0xff);
-    expect_data[4] = ((otherdata >> 8) & 0xff);
-    expect_data[5] = (otherdata & 0xff);
+    vector<uint8_t> expect_key(32, 'x');
+    matchWireData(&expect_key[0], expect_key.size(),
+                  tkey.getKey(), tkey.getKeyLen());
+
+    vector<uint8_t> expect_data = { 'a', 'b', 'c', 'd', '0', '1', '2', '3' };
     matchWireData(&expect_data[0], expect_data.size(),
                   tkey.getOtherData(), tkey.getOtherLen());
-#endif
 }
 
 TEST_F(Rdata_TKEY_Test, createFromWireWithoutKey) {
@@ -255,6 +249,10 @@ TEST_F(Rdata_TKEY_Test, createFromWireWithoutKey) {
     const generic::TKEY& tkey(dynamic_cast<generic::TKEY&>(*rdata));
     EXPECT_EQ(0, tkey.getKeyLen());
     EXPECT_EQ(static_cast<const void*>(0), tkey.getKey());
+
+    vector<uint8_t> expect_data = { 'a', 'b', 'c', 'd', '0', '1', '2', '3' };
+    matchWireData(&expect_data[0], expect_data.size(),
+                  tkey.getOtherData(), tkey.getOtherLen());
 }
 
 TEST_F(Rdata_TKEY_Test, createFromWireWithCompression) {
index d55c8785076da1cf519cf22143f219cd12b6d60e..e5c8081c076a229b0a03a6d3eb48d075c6705a8f 100644 (file)
@@ -91,6 +91,14 @@ EXTRA_DIST += rrcode16_fromWire1 rrcode16_fromWire2
 EXTRA_DIST += rrcode32_fromWire1 rrcode32_fromWire2
 EXTRA_DIST += rrset_toWire1 rrset_toWire2
 EXTRA_DIST += rrset_toWire3 rrset_toWire4
+EXTRA_DIST += rdata_tkey_fromWire1.spec rdata_tkey_fromWire2.spec
+EXTRA_DIST += rdata_tkey_fromWire3.spec rdata_tkey_fromWire4.spec
+EXTRA_DIST += rdata_tkey_fromWire5.spec rdata_tkey_fromWire6.spec
+EXTRA_DIST += rdata_tkey_fromWire7.spec rdata_tkey_fromWire8.spec
+EXTRA_DIST += rdata_tkey_fromWire9.spec
+EXTRA_DIST += rdata_tkey_toWire1.spec rdata_tkey_toWire2.spec
+EXTRA_DIST += rdata_tkey_toWire3.spec rdata_tkey_toWire4.spec
+EXTRA_DIST += rdata_tkey_toWire5.spec
 EXTRA_DIST += rdata_tlsa_fromWire rdata_tlsa_fromWire2
 EXTRA_DIST += rdata_tlsa_fromWire3.spec rdata_tlsa_fromWire4.spec
 EXTRA_DIST += rdata_tlsa_fromWire5.spec rdata_tlsa_fromWire6.spec
@@ -189,6 +197,14 @@ EXTRA_DIST += rdata_tsig_toWire3.wire rdata_tsig_toWire4.wire
 EXTRA_DIST += rdata_tsig_toWire5.wire
 EXTRA_DIST += rdata_caa_fromWire1.wire rdata_caa_fromWire2.wire
 EXTRA_DIST += rdata_caa_fromWire3.wire rdata_caa_fromWire4.wire
+EXTRA_DIST += rdata_tkey_fromWire1.wire rdata_tkey_fromWire2.wire
+EXTRA_DIST += rdata_tkey_fromWire3.wire rdata_tkey_fromWire4.wire
+EXTRA_DIST += rdata_tkey_fromWire5.wire rdata_tkey_fromWire6.wire
+EXTRA_DIST += rdata_tkey_fromWire7.wire rdata_tkey_fromWire8.wire
+EXTRA_DIST += rdata_tkey_fromWire9.wire
+EXTRA_DIST += rdata_tkey_toWire1.wire rdata_tkey_toWire2.wire
+EXTRA_DIST += rdata_tkey_toWire3.wire rdata_tkey_toWire4.wire
+EXTRA_DIST += rdata_tkey_toWire5.wire
 EXTRA_DIST += tsigrecord_toWire1.wire tsigrecord_toWire2.wire
 EXTRA_DIST += tsig_verify1.wire tsig_verify2.wire tsig_verify3.wire
 EXTRA_DIST += tsig_verify4.wire tsig_verify5.wire tsig_verify6.wire
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_fromWire1.spec b/src/lib/dns/tests/testdata/rdata_tkey_fromWire1.spec
new file mode 100644 (file)
index 0000000..e46d9b3
--- /dev/null
@@ -0,0 +1,6 @@
+#
+# A simplest form of TKEY: all default parameters
+#
+[custom]
+sections: tkey
+[tkey]
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_fromWire2.spec b/src/lib/dns/tests/testdata/rdata_tkey_fromWire2.spec
new file mode 100644 (file)
index 0000000..e4a1920
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# TKEY with other data
+#
+[custom]
+sections: tkey
+[tkey]
+other_len: 8
+other_data: abcd0123
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_fromWire3.spec b/src/lib/dns/tests/testdata/rdata_tkey_fromWire3.spec
new file mode 100644 (file)
index 0000000..2566b58
--- /dev/null
@@ -0,0 +1,9 @@
+#
+# TKEY without Key
+#
+[custom]
+sections: tkey
+[tkey]
+key_len: 0
+other_len: 8
+other_data: abcd0123
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_fromWire4.spec b/src/lib/dns/tests/testdata/rdata_tkey_fromWire4.spec
new file mode 100644 (file)
index 0000000..33459eb
--- /dev/null
@@ -0,0 +1,11 @@
+#
+# A simplest form of TKEY, but the algorithm name is compressed (quite
+# pathological, but we accept it)
+#
+[custom]
+sections: name:tkey
+[name]
+name: gss-tsig
+[tkey]
+algorithm: ptr=0
+key_len: 32
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_fromWire5.spec b/src/lib/dns/tests/testdata/rdata_tkey_fromWire5.spec
new file mode 100644 (file)
index 0000000..da90b18
--- /dev/null
@@ -0,0 +1,7 @@
+#
+# TSIG-like RDATA but RDLEN is too short.
+#
+[custom]
+sections: tsig
+[tsig]
+rdlen: 60
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_fromWire6.spec b/src/lib/dns/tests/testdata/rdata_tkey_fromWire6.spec
new file mode 100644 (file)
index 0000000..9d2f627
--- /dev/null
@@ -0,0 +1,7 @@
+#
+# TSIG-like RDATA but RDLEN is too long.
+#
+[custom]
+sections: tsig
+[tsig]
+rdlen: 63
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_fromWire7.spec b/src/lib/dns/tests/testdata/rdata_tkey_fromWire7.spec
new file mode 100644 (file)
index 0000000..ed7a81c
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# TSIG-like RDATA but algorithm name is broken.
+#
+[custom]
+sections: tsig
+[tsig]
+algorithm: "01234567890123456789012345678901234567890123456789012345678901234"
+mac_size: 32
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_fromWire8.spec b/src/lib/dns/tests/testdata/rdata_tkey_fromWire8.spec
new file mode 100644 (file)
index 0000000..0b44f87
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# TSIG-like RDATA but MAC size is bogus
+#
+[custom]
+sections: tsig
+[tsig]
+mac_size: 65535
+mac: "dummy data"
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_fromWire9.spec b/src/lib/dns/tests/testdata/rdata_tkey_fromWire9.spec
new file mode 100644 (file)
index 0000000..f512fb4
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# TSIG-like RDATA but Other-Data length is bogus
+#
+[custom]
+sections: tsig
+[tsig]
+other_len: 65535
+otherdata: "dummy data"
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_toWire1.spec b/src/lib/dns/tests/testdata/rdata_tkey_toWire1.spec
new file mode 100644 (file)
index 0000000..eb74000
--- /dev/null
@@ -0,0 +1,11 @@
+#
+# An artificial TSIG RDATA for toWire test.
+#
+[custom]
+sections: tsig
+[tsig]
+algorithm: hmac-md5
+time_signed: 1286779327
+mac_size: 0
+original_id: 16020
+error: 17
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_toWire2.spec b/src/lib/dns/tests/testdata/rdata_tkey_toWire2.spec
new file mode 100644 (file)
index 0000000..b2c38e9
--- /dev/null
@@ -0,0 +1,13 @@
+#
+# An artificial TSIG RDATA for toWire test.
+#
+[custom]
+sections: tsig
+[tsig]
+algorithm: hmac-sha256
+time_signed: 1286779327
+mac_size: 12
+# 0x1402... would be FAKEFAKE... if encoded in BASE64
+mac: 0x140284140284140284140284
+original_id: 16020
+error: 16
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_toWire3.spec b/src/lib/dns/tests/testdata/rdata_tkey_toWire3.spec
new file mode 100644 (file)
index 0000000..6520a08
--- /dev/null
@@ -0,0 +1,15 @@
+#
+# An artificial TSIG RDATA for toWire test.
+#
+[custom]
+sections: tsig
+[tsig]
+algorithm: hmac-sha1
+time_signed: 1286779327
+mac_size: 12
+# 0x1402... would be FAKEFAKE... if encoded in BASE64
+mac: 0x140284140284140284140284
+original_id: 16020
+error: 18
+other_len: 6
+other_data: 0x140284140284
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_toWire4.spec b/src/lib/dns/tests/testdata/rdata_tkey_toWire4.spec
new file mode 100644 (file)
index 0000000..d95cd23
--- /dev/null
@@ -0,0 +1,13 @@
+#
+# An artificial TSIG RDATA for toWire test.
+#
+[custom]
+sections: name:tsig
+[name]
+name: hmac-md5.sig-alg.reg.int.
+[tsig]
+algorithm: hmac-md5
+time_signed: 1286779327
+mac_size: 0
+original_id: 16020
+error: 17
diff --git a/src/lib/dns/tests/testdata/rdata_tkey_toWire5.spec b/src/lib/dns/tests/testdata/rdata_tkey_toWire5.spec
new file mode 100644 (file)
index 0000000..81e3a78
--- /dev/null
@@ -0,0 +1,13 @@
+#
+# An artificial TSIG RDATA for toWire test.
+#
+[custom]
+sections: tsig:name
+[tsig]
+algorithm: hmac-md5
+time_signed: 1286779327
+mac_size: 0
+original_id: 16020
+error: 17
+[name]
+name: ptr=2
index 6050e43e8acb57133ac1b8f5cde8464b9eac4160..f1b51f3552e41cd4f1d5458ab50220aa17d4f221 100644 (file)
@@ -1190,7 +1190,7 @@ class TKEY(RR):
       generally interpreted as a domain name string, and will
       typically be gss-tsig.
     - inception (32-bit int): The Inception TTL field.
-    - expiration (32-bit int): The Expiration TTL field.
+    - expire (32-bit int): The Expire TTL field.
     - mode (16-bit int): The Mode field.
     - error (16-bit int): The Error field.
     - key_len (int): The Key Len field.
@@ -1210,16 +1210,16 @@ class TKEY(RR):
     '''
 
     algorithm = 'gss-tsig'
-    inception = int(time.mktime(datetime.strptime('20210501130000',
+    inception = int(time.mktime(datetime.strptime('20210501120000',
                                                   dnssec_timefmt).timetuple()))
-    expiration = int(time.mktime(datetime.strptime('20210501130000',
-                                                   dnssec_timefmt).timetuple()))
+    expire = int(time.mktime(datetime.strptime('20210501130000',
+                                               dnssec_timefmt).timetuple()))
     mode = 3                 # GSS-API
     error = 0
-    key_len = None
-    key = None               # use 'x' *
-    other_len = None
-    other_data = None        # same as key
+    key_len = 32
+    key = None               # use 'x' * key_len
+    other_len = 0
+    other_data = None
 
     # TKEY has some special defaults
     def __init__(self):
@@ -1230,11 +1230,9 @@ class TKEY(RR):
     def dump(self, f):
         name_wire = encode_name(self.algorithm)
         key_len = self.key_len
-        if key_len is None:
-            key_len = 0
         key = self.key
         if key is None:
-            key = ''
+            key = encode_string('x' * key_len)
         else:
             key = encode_string(self.key, key_len)
         other_len = self.other_len
@@ -1242,17 +1240,19 @@ class TKEY(RR):
             other_len = 0
         other_data = self.other_data
         if other_data is None:
+            other_data = ''
+        else:
             other_data = encode_string(self.other_data, other_len)
         if self.rdlen is None:
-            self.rdlen = int(len(name_wire) / 2 + 12 + len(mac) / 2 + \
+            self.rdlen = int(len(name_wire) / 2 + 16 + len(key) / 2 + \
                                  len(other_data) / 2)
         self.dump_header(f, self.rdlen)
-        f.write('# Algorithm=%s Inception=%d Expire=%d Mode=%d Error=%d\n' %
-                (self.algorithm, self.inception, self.expire,
-                 self.mode, self.error))
-        f.write('%s %08x %08x %04x %04x\n' %
-                (self.algorithm, self.inception, self.expire,
-                 self.mode, self.error))
+        f.write('# Algorithm=%s\n' % self.algorithm)
+        f.write('%s\n' % name_wire)
+        f.write('# Inception=%d Expire=%d Mode=%d Error=%d\n' %
+                (self.inception, self.expire, self.mode, self.error))
+        f.write('%08x %08x %04x %04x\n' %
+                (self.inception, self.expire, self.mode, self.error))
         f.write('# Key Len=%d Key=(see hex)\n' % key_len)
         f.write('%04x%s\n' % (key_len, ' ' + key if len(key) > 0 else ''))
         f.write('# Other-Len=%d Other-Data=(see hex)\n' % other_len)