1999-07-12 16:08:42 -04:00
|
|
|
/*
|
2018-02-23 03:53:12 -05:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-07-31 21:33:37 -04:00
|
|
|
*
|
2016-06-27 00:56:38 -04:00
|
|
|
* 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/.
|
2018-02-23 03:53:12 -05:00
|
|
|
*
|
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
|
* information regarding copyright ownership.
|
1999-07-12 16:08:42 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
1999-07-12 22:05:01 -04:00
|
|
|
#include <unistd.h> /* XXX */
|
|
|
|
|
|
2000-05-08 10:38:29 -04:00
|
|
|
#include <isc/buffer.h>
|
2000-06-09 18:34:40 -04:00
|
|
|
#include <isc/entropy.h>
|
1999-07-12 16:08:42 -04:00
|
|
|
#include <isc/mem.h>
|
2015-05-23 08:21:51 -04:00
|
|
|
#include <isc/print.h>
|
2000-05-08 15:23:32 -04:00
|
|
|
#include <isc/region.h>
|
|
|
|
|
#include <isc/string.h> /* Required for HP/UX (and others?) */
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2000-05-24 19:13:32 -04:00
|
|
|
#include <dns/fixedname.h>
|
2014-01-14 18:40:56 -05:00
|
|
|
#include <dns/log.h>
|
2000-05-24 19:13:32 -04:00
|
|
|
#include <dns/name.h>
|
2000-03-17 19:42:07 -05:00
|
|
|
#include <dns/result.h>
|
|
|
|
|
|
1999-07-12 16:08:42 -04:00
|
|
|
#include <dst/dst.h>
|
|
|
|
|
#include <dst/result.h>
|
|
|
|
|
|
2000-06-01 15:11:07 -04:00
|
|
|
char *current;
|
|
|
|
|
const char *tmp = "/tmp";
|
1999-07-12 16:08:42 -04:00
|
|
|
|
|
|
|
|
static void
|
2000-06-02 14:59:33 -04:00
|
|
|
use(dst_key_t *key, isc_mem_t *mctx) {
|
2000-03-06 15:04:15 -05:00
|
|
|
isc_result_t ret;
|
2000-06-01 15:11:07 -04:00
|
|
|
const char *data = "This is some data";
|
1999-07-12 16:08:42 -04:00
|
|
|
unsigned char sig[512];
|
|
|
|
|
isc_buffer_t databuf, sigbuf;
|
|
|
|
|
isc_region_t datareg, sigreg;
|
2000-06-02 14:59:33 -04:00
|
|
|
dst_context_t *ctx = NULL;
|
1999-07-12 16:08:42 -04:00
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-26 20:03:12 -04:00
|
|
|
isc_buffer_init(&sigbuf, sig, sizeof(sig));
|
2000-06-01 15:11:07 -04:00
|
|
|
/*
|
|
|
|
|
* Advance 1 byte for fun.
|
|
|
|
|
*/
|
1999-07-12 16:08:42 -04:00
|
|
|
isc_buffer_add(&sigbuf, 1);
|
|
|
|
|
|
2012-12-07 20:48:57 -05:00
|
|
|
isc_buffer_constinit(&databuf, data, strlen(data));
|
1999-07-12 16:08:42 -04:00
|
|
|
isc_buffer_add(&databuf, strlen(data));
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-26 20:03:12 -04:00
|
|
|
isc_buffer_usedregion(&databuf, &datareg);
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2014-01-14 18:40:56 -05:00
|
|
|
ret = dst_context_create3(key, mctx,
|
|
|
|
|
DNS_LOGCATEGORY_GENERAL, ISC_TRUE, &ctx);
|
2000-06-12 14:36:38 -04:00
|
|
|
if (ret != ISC_R_SUCCESS) {
|
2018-02-14 02:20:46 -05:00
|
|
|
printf("contextcreate(%u) returned: %s\n", dst_key_alg(key),
|
2000-06-02 14:59:33 -04:00
|
|
|
isc_result_totext(ret));
|
2000-06-12 14:36:38 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2000-06-02 14:59:33 -04:00
|
|
|
ret = dst_context_adddata(ctx, &datareg);
|
2000-06-12 14:36:38 -04:00
|
|
|
if (ret != ISC_R_SUCCESS) {
|
2018-02-14 20:11:17 -05:00
|
|
|
printf("adddata(%u) returned: %s\n", dst_key_alg(key),
|
2000-06-02 14:59:33 -04:00
|
|
|
isc_result_totext(ret));
|
2000-06-12 14:36:38 -04:00
|
|
|
dst_context_destroy(&ctx);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2000-06-02 14:59:33 -04:00
|
|
|
ret = dst_context_sign(ctx, &sigbuf);
|
2018-02-14 20:11:17 -05:00
|
|
|
printf("sign(%u) returned: %s\n", dst_key_alg(key),
|
2000-03-06 15:04:15 -05:00
|
|
|
isc_result_totext(ret));
|
2000-06-02 14:59:33 -04:00
|
|
|
dst_context_destroy(&ctx);
|
1999-07-12 16:08:42 -04:00
|
|
|
|
|
|
|
|
isc_buffer_forward(&sigbuf, 1);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-26 20:03:12 -04:00
|
|
|
isc_buffer_remainingregion(&sigbuf, &sigreg);
|
2014-01-14 18:40:56 -05:00
|
|
|
ret = dst_context_create3(key, mctx,
|
|
|
|
|
DNS_LOGCATEGORY_GENERAL, ISC_FALSE, &ctx);
|
2000-06-12 14:36:38 -04:00
|
|
|
if (ret != ISC_R_SUCCESS) {
|
2018-02-14 20:11:17 -05:00
|
|
|
printf("contextcreate(%u) returned: %s\n", dst_key_alg(key),
|
2000-06-02 14:59:33 -04:00
|
|
|
isc_result_totext(ret));
|
2000-06-12 14:36:38 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2000-06-02 14:59:33 -04:00
|
|
|
ret = dst_context_adddata(ctx, &datareg);
|
2000-06-12 14:36:38 -04:00
|
|
|
if (ret != ISC_R_SUCCESS) {
|
2018-02-14 20:11:17 -05:00
|
|
|
printf("adddata(%u) returned: %s\n", dst_key_alg(key),
|
2000-06-02 14:59:33 -04:00
|
|
|
isc_result_totext(ret));
|
2000-06-12 14:36:38 -04:00
|
|
|
dst_context_destroy(&ctx);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2000-06-02 14:59:33 -04:00
|
|
|
ret = dst_context_verify(ctx, &sigreg);
|
2018-02-14 02:20:46 -05:00
|
|
|
printf("verify(%u) returned: %s\n", dst_key_alg(key),
|
2000-03-06 15:04:15 -05:00
|
|
|
isc_result_totext(ret));
|
2000-06-02 14:59:33 -04:00
|
|
|
dst_context_destroy(&ctx);
|
1999-07-12 16:08:42 -04:00
|
|
|
}
|
|
|
|
|
|
2000-04-05 18:21:17 -04:00
|
|
|
static void
|
|
|
|
|
dns(dst_key_t *key, isc_mem_t *mctx) {
|
|
|
|
|
unsigned char buffer1[2048];
|
|
|
|
|
unsigned char buffer2[2048];
|
|
|
|
|
isc_buffer_t buf1, buf2;
|
|
|
|
|
isc_region_t r1, r2;
|
|
|
|
|
dst_key_t *newkey = NULL;
|
|
|
|
|
isc_result_t ret;
|
|
|
|
|
isc_boolean_t match;
|
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-26 20:03:12 -04:00
|
|
|
isc_buffer_init(&buf1, buffer1, sizeof(buffer1));
|
2000-04-05 18:21:17 -04:00
|
|
|
ret = dst_key_todns(key, &buf1);
|
2018-02-14 02:20:46 -05:00
|
|
|
printf("todns(%u) returned: %s\n", dst_key_alg(key),
|
2000-04-05 18:21:17 -04:00
|
|
|
isc_result_totext(ret));
|
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
|
return;
|
2000-09-12 05:59:28 -04:00
|
|
|
ret = dst_key_fromdns(dst_key_name(key), dns_rdataclass_in,
|
|
|
|
|
&buf1, mctx, &newkey);
|
2018-02-14 02:20:46 -05:00
|
|
|
printf("fromdns(%u) returned: %s\n", dst_key_alg(key),
|
2000-04-05 18:21:17 -04:00
|
|
|
isc_result_totext(ret));
|
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
|
return;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-26 20:03:12 -04:00
|
|
|
isc_buffer_init(&buf2, buffer2, sizeof(buffer2));
|
2000-04-05 18:21:17 -04:00
|
|
|
ret = dst_key_todns(newkey, &buf2);
|
2018-02-14 02:20:46 -05:00
|
|
|
printf("todns2(%u) returned: %s\n", dst_key_alg(key),
|
2000-04-05 18:21:17 -04:00
|
|
|
isc_result_totext(ret));
|
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
|
return;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-26 20:03:12 -04:00
|
|
|
isc_buffer_usedregion(&buf1, &r1);
|
|
|
|
|
isc_buffer_usedregion(&buf2, &r2);
|
2000-05-23 23:27:47 -04:00
|
|
|
match = ISC_TF(r1.length == r2.length &&
|
|
|
|
|
memcmp(r1.base, r2.base, r1.length) == 0);
|
2018-02-14 02:20:46 -05:00
|
|
|
printf("compare(%u): %s\n", dst_key_alg(key),
|
2000-05-23 23:27:47 -04:00
|
|
|
match ? "true" : "false");
|
2000-05-18 20:20:59 -04:00
|
|
|
dst_key_free(&newkey);
|
2000-04-05 18:21:17 -04:00
|
|
|
}
|
|
|
|
|
|
1999-07-12 16:08:42 -04:00
|
|
|
static void
|
2000-05-24 19:13:32 -04:00
|
|
|
io(dns_name_t *name, int id, int alg, int type, isc_mem_t *mctx) {
|
2000-05-18 20:20:59 -04:00
|
|
|
dst_key_t *key = NULL;
|
2000-03-06 15:04:15 -05:00
|
|
|
isc_result_t ret;
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2000-06-06 18:01:49 -04:00
|
|
|
ret = dst_key_fromfile(name, id, alg, type, current, mctx, &key);
|
2000-03-06 15:04:15 -05:00
|
|
|
printf("read(%d) returned: %s\n", alg, isc_result_totext(ret));
|
1999-07-12 16:08:42 -04:00
|
|
|
if (ret != 0)
|
|
|
|
|
return;
|
2000-06-06 18:01:49 -04:00
|
|
|
ret = dst_key_tofile(key, type, tmp);
|
2000-03-06 15:04:15 -05:00
|
|
|
printf("write(%d) returned: %s\n", alg, isc_result_totext(ret));
|
1999-07-12 16:08:42 -04:00
|
|
|
if (ret != 0)
|
|
|
|
|
return;
|
2000-06-02 14:59:33 -04:00
|
|
|
use(key, mctx);
|
2000-04-05 18:21:17 -04:00
|
|
|
dns(key, mctx);
|
2000-05-18 20:20:59 -04:00
|
|
|
dst_key_free(&key);
|
1999-07-12 16:08:42 -04:00
|
|
|
}
|
|
|
|
|
|
1999-10-27 17:26:08 -04:00
|
|
|
static void
|
2000-05-24 19:13:32 -04:00
|
|
|
dh(dns_name_t *name1, int id1, dns_name_t *name2, int id2, isc_mem_t *mctx) {
|
2000-05-18 20:20:59 -04:00
|
|
|
dst_key_t *key1 = NULL, *key2 = NULL;
|
2000-03-06 15:04:15 -05:00
|
|
|
isc_result_t ret;
|
1999-10-27 17:26:08 -04:00
|
|
|
isc_buffer_t b1, b2;
|
|
|
|
|
isc_region_t r1, r2;
|
|
|
|
|
unsigned char array1[1024], array2[1024];
|
|
|
|
|
int alg = DST_ALG_DH;
|
2004-06-10 20:27:06 -04:00
|
|
|
int type = DST_TYPE_PUBLIC|DST_TYPE_PRIVATE|DST_TYPE_KEY;
|
1999-10-27 17:26:08 -04:00
|
|
|
|
2000-06-06 18:01:49 -04:00
|
|
|
ret = dst_key_fromfile(name1, id1, alg, type, current, mctx, &key1);
|
2000-03-06 15:04:15 -05:00
|
|
|
printf("read(%d) returned: %s\n", alg, isc_result_totext(ret));
|
1999-10-27 17:26:08 -04:00
|
|
|
if (ret != 0)
|
|
|
|
|
return;
|
2000-06-06 18:01:49 -04:00
|
|
|
ret = dst_key_fromfile(name2, id2, alg, type, current, mctx, &key2);
|
2000-03-06 15:04:15 -05:00
|
|
|
printf("read(%d) returned: %s\n", alg, isc_result_totext(ret));
|
1999-10-27 17:26:08 -04:00
|
|
|
if (ret != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2000-06-06 18:01:49 -04:00
|
|
|
ret = dst_key_tofile(key1, type, tmp);
|
2000-03-06 15:04:15 -05:00
|
|
|
printf("write(%d) returned: %s\n", alg, isc_result_totext(ret));
|
1999-10-27 17:26:08 -04:00
|
|
|
if (ret != 0)
|
|
|
|
|
return;
|
2000-06-06 18:01:49 -04:00
|
|
|
ret = dst_key_tofile(key2, type, tmp);
|
2000-03-06 15:04:15 -05:00
|
|
|
printf("write(%d) returned: %s\n", alg, isc_result_totext(ret));
|
1999-10-27 17:26:08 -04:00
|
|
|
if (ret != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-26 20:03:12 -04:00
|
|
|
isc_buffer_init(&b1, array1, sizeof(array1));
|
2000-05-17 18:48:10 -04:00
|
|
|
ret = dst_key_computesecret(key1, key2, &b1);
|
2000-03-06 15:04:15 -05:00
|
|
|
printf("computesecret() returned: %s\n", isc_result_totext(ret));
|
1999-10-27 17:26:08 -04:00
|
|
|
if (ret != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-26 20:03:12 -04:00
|
|
|
isc_buffer_init(&b2, array2, sizeof(array2));
|
2000-05-17 18:48:10 -04:00
|
|
|
ret = dst_key_computesecret(key2, key1, &b2);
|
2000-03-06 15:04:15 -05:00
|
|
|
printf("computesecret() returned: %s\n", isc_result_totext(ret));
|
1999-10-27 17:26:08 -04:00
|
|
|
if (ret != 0)
|
|
|
|
|
return;
|
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-26 20:03:12 -04:00
|
|
|
isc_buffer_usedregion(&b1, &r1);
|
|
|
|
|
isc_buffer_usedregion(&b2, &r2);
|
1999-10-27 17:26:08 -04:00
|
|
|
|
|
|
|
|
if (r1.length != r2.length || memcmp(r1.base, r2.base, r1.length) != 0)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
printf("secrets don't match\n");
|
2018-02-14 02:20:46 -05:00
|
|
|
printf("secret 1: %u bytes\n", r1.length);
|
1999-10-27 17:26:08 -04:00
|
|
|
for (i = 0; i < (int) r1.length; i++)
|
|
|
|
|
printf("%02x ", r1.base[i]);
|
|
|
|
|
printf("\n");
|
2018-02-14 02:20:46 -05:00
|
|
|
printf("secret 2: %u bytes\n", r2.length);
|
1999-10-27 17:26:08 -04:00
|
|
|
for (i = 0; i < (int) r2.length; i++)
|
|
|
|
|
printf("%02x ", r2.base[i]);
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
2000-05-18 20:20:59 -04:00
|
|
|
dst_key_free(&key1);
|
|
|
|
|
dst_key_free(&key2);
|
1999-10-27 17:26:08 -04:00
|
|
|
}
|
|
|
|
|
|
1999-07-12 16:08:42 -04:00
|
|
|
static void
|
|
|
|
|
generate(int alg, isc_mem_t *mctx) {
|
2000-03-06 15:04:15 -05:00
|
|
|
isc_result_t ret;
|
2000-05-18 20:20:59 -04:00
|
|
|
dst_key_t *key = NULL;
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2000-09-12 05:59:28 -04:00
|
|
|
ret = dst_key_generate(dns_rootname, alg, 512, 0, 0, 0,
|
|
|
|
|
dns_rdataclass_in, mctx, &key);
|
2000-03-06 15:04:15 -05:00
|
|
|
printf("generate(%d) returned: %s\n", alg, isc_result_totext(ret));
|
2000-06-12 14:36:38 -04:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
|
return;
|
1999-07-12 16:08:42 -04:00
|
|
|
|
1999-10-27 17:26:08 -04:00
|
|
|
if (alg != DST_ALG_DH)
|
2000-06-02 14:59:33 -04:00
|
|
|
use(key, mctx);
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2000-05-18 20:20:59 -04:00
|
|
|
dst_key_free(&key);
|
1999-07-12 16:08:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2000-05-23 23:27:47 -04:00
|
|
|
main(void) {
|
1999-07-12 16:08:42 -04:00
|
|
|
isc_mem_t *mctx = NULL;
|
2000-06-09 18:34:40 -04:00
|
|
|
isc_entropy_t *ectx = NULL;
|
2000-05-24 19:13:32 -04:00
|
|
|
isc_buffer_t b;
|
|
|
|
|
dns_fixedname_t fname;
|
|
|
|
|
dns_name_t *name;
|
2005-11-29 22:33:49 -05:00
|
|
|
isc_result_t result;
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2005-11-29 22:33:49 -05:00
|
|
|
result = isc_mem_create(0, 0, &mctx);
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
|
return (1);
|
1999-07-12 16:08:42 -04:00
|
|
|
|
|
|
|
|
current = isc_mem_get(mctx, 256);
|
2005-11-29 22:33:49 -05:00
|
|
|
if (current == NULL)
|
|
|
|
|
return (1);
|
2009-03-01 21:48:02 -05:00
|
|
|
if (getcwd(current, 256) == NULL) {
|
|
|
|
|
perror("getcwd");
|
|
|
|
|
return (1);
|
|
|
|
|
}
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2000-03-06 15:04:15 -05:00
|
|
|
dns_result_register();
|
2000-06-09 18:34:40 -04:00
|
|
|
|
2005-11-29 22:33:49 -05:00
|
|
|
result = isc_entropy_create(mctx, &ectx);
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
|
return (1);
|
|
|
|
|
result = isc_entropy_createfilesource(ectx, "randomfile");
|
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
|
return (1);
|
2000-06-09 18:34:40 -04:00
|
|
|
dst_lib_init(mctx, ectx, ISC_ENTROPY_BLOCKING|ISC_ENTROPY_GOODONLY);
|
2000-03-06 15:04:15 -05:00
|
|
|
|
2000-05-24 19:13:32 -04:00
|
|
|
dns_fixedname_init(&fname);
|
|
|
|
|
name = dns_fixedname_name(&fname);
|
2012-12-07 20:48:57 -05:00
|
|
|
isc_buffer_constinit(&b, "test.", 5);
|
2000-05-25 14:00:08 -04:00
|
|
|
isc_buffer_add(&b, 5);
|
2009-08-31 20:22:28 -04:00
|
|
|
result = dns_name_fromtext(name, &b, NULL, 0, NULL);
|
2005-11-29 22:33:49 -05:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
|
return (1);
|
2001-04-03 22:02:58 -04:00
|
|
|
io(name, 23616, DST_ALG_DSA, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC, mctx);
|
2000-09-01 21:17:20 -04:00
|
|
|
io(name, 54622, DST_ALG_RSAMD5, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC,
|
|
|
|
|
mctx);
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2001-04-03 22:02:58 -04:00
|
|
|
io(name, 49667, DST_ALG_DSA, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC, mctx);
|
|
|
|
|
io(name, 2, DST_ALG_RSAMD5, DST_TYPE_PRIVATE|DST_TYPE_PUBLIC, mctx);
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2012-12-07 20:48:57 -05:00
|
|
|
isc_buffer_constinit(&b, "dh.", 3);
|
2000-05-25 14:00:08 -04:00
|
|
|
isc_buffer_add(&b, 3);
|
2009-08-31 20:22:28 -04:00
|
|
|
result = dns_name_fromtext(name, &b, NULL, 0, NULL);
|
2005-11-29 22:33:49 -05:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
|
return (1);
|
2001-04-03 22:02:58 -04:00
|
|
|
dh(name, 18602, name, 48957, mctx);
|
1999-10-27 17:26:08 -04:00
|
|
|
|
2000-09-01 21:17:20 -04:00
|
|
|
generate(DST_ALG_RSAMD5, mctx);
|
1999-10-27 17:26:08 -04:00
|
|
|
generate(DST_ALG_DH, mctx);
|
1999-07-12 16:08:42 -04:00
|
|
|
generate(DST_ALG_DSA, mctx);
|
1999-09-02 11:56:33 -04:00
|
|
|
generate(DST_ALG_HMACMD5, mctx);
|
1999-07-12 16:08:42 -04:00
|
|
|
|
2000-06-06 18:01:49 -04:00
|
|
|
dst_lib_destroy();
|
2000-06-09 18:34:40 -04:00
|
|
|
isc_entropy_detach(&ectx);
|
2000-06-06 18:01:49 -04:00
|
|
|
|
1999-07-12 16:08:42 -04:00
|
|
|
isc_mem_put(mctx, current, 256);
|
|
|
|
|
/* isc_mem_stats(mctx, stdout);*/
|
|
|
|
|
isc_mem_destroy(&mctx);
|
|
|
|
|
|
2000-05-08 16:12:46 -04:00
|
|
|
return (0);
|
1999-07-12 16:08:42 -04:00
|
|
|
}
|