]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix code to generate the test signatues.
authorMark Andrews <marka@isc.org>
Fri, 21 Feb 2020 05:40:50 +0000 (21:40 -0800)
committerMark Andrews <marka@isc.org>
Fri, 21 Feb 2020 06:45:47 +0000 (17:45 +1100)
* ctx needs to be destroyed before it is regenerated.
* emit the name of the signature to be replaced.
* cleanup memory before asserting so post longjump doesn't detect a
  memory leak.
* comment code.

(cherry picked from commit 3a8c8a2a3199844bb16232e2f362f67d14181939)

lib/dns/tests/dst_test.c

index 7d563a603adafa90268bad6442dde98a3a1f0ec1..d21c5ade053fe8922a951a24b3e7ced51e987bc0 100644 (file)
@@ -208,14 +208,49 @@ check_sig(const char *datapath, const char *sigpath, const char *keyname,
        assert_int_equal(result, ISC_R_SUCCESS);
        result = dst_context_verify(ctx, &sigreg);
 
-       assert_true((expect && (result == ISC_R_SUCCESS)) ||
-                   (!expect && (result != ISC_R_SUCCESS)));
+       /*
+        * Compute the expected signature and emit it
+        * so the precomputed signature can be updated.
+        * This should only be done if the covered data
+        * is updated.
+        */
+       if (expect && result != ISC_R_SUCCESS) {
+               isc_result_t result2;
+
+               dst_context_destroy(&ctx);
+               result2 = dst_context_create(
+                       key, dt_mctx, DNS_LOGCATEGORY_GENERAL, false, 0, &ctx);
+               assert_int_equal(result2, ISC_R_SUCCESS);
+
+               result2 = dst_context_adddata(ctx, &datareg);
+               assert_int_equal(result2, ISC_R_SUCCESS);
+
+               char sigbuf2[4096];
+               isc_buffer_t sigb;
+               isc_buffer_init(&sigb, sigbuf2, sizeof(sigbuf2));
+
+               result2 = dst_context_sign(ctx, &sigb);
+               assert_int_equal(result2, ISC_R_SUCCESS);
 
+               isc_region_t r;
+               isc_buffer_usedregion(&sigb, &r);
+
+               char hexbuf[4096] = { 0 };
+               isc_buffer_t hb;
+               isc_buffer_init(&hb, hexbuf, sizeof(hexbuf));
+
+               isc_hex_totext(&r, 0, "", &hb);
+
+               fprintf(stderr, "# %s:\n# %s\n", sigpath, hexbuf);
+       }
 
        isc_mem_put(mctx, data, size + 1);
        dst_context_destroy(&ctx);
        dst_key_free(&key);
 
+       assert_true((expect && (result == ISC_R_SUCCESS)) ||
+                   (!expect && (result != ISC_R_SUCCESS)));
+
        return;
 }