From ad98a8699371c9c449982fbbd8ceda91ad745f2a Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 14 Oct 2004 05:55:52 +0000 Subject: [PATCH] 1747. [func] Make public the function to read a key file, dst_key_read_public(). [RT #12450] --- CHANGES | 3 +++ lib/dns/sec/dst/dst_api.c | 37 +++++++++++++------------------ lib/dns/sec/dst/include/dst/dst.h | 25 ++++++++++++++++++++- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/CHANGES b/CHANGES index 849e7b1c55..84f7525cef 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +1747. [func] Make public the function to read a key file, + dst_key_read_public(). [RT #12450] + 1745. [placeholder] rt12745 1744. [bug] If tuple2msgname() failed to convert a tuple to diff --git a/lib/dns/sec/dst/dst_api.c b/lib/dns/sec/dst/dst_api.c index 8d12bee55e..4d8c0b28c9 100644 --- a/lib/dns/sec/dst/dst_api.c +++ b/lib/dns/sec/dst/dst_api.c @@ -18,7 +18,7 @@ /* * Principal Author: Brian Wellington - * $Id: dst_api.c,v 1.118 2004/10/01 00:10:59 marka Exp $ + * $Id: dst_api.c,v 1.119 2004/10/14 05:55:51 marka Exp $ */ #include @@ -69,10 +69,6 @@ static dst_key_t * get_key_struct(dns_name_t *name, unsigned int bits, dns_rdataclass_t rdclass, isc_mem_t *mctx); -static isc_result_t read_public_key(const char *filename, - int type, - isc_mem_t *mctx, - dst_key_t **keyp); static isc_result_t write_public_key(const dst_key_t *key, int type, const char *directory); static isc_result_t buildfilename(dns_name_t *name, @@ -392,7 +388,15 @@ dst_key_fromnamedfile(const char *filename, int type, isc_mem_t *mctx, REQUIRE(mctx != NULL); REQUIRE(keyp != NULL && *keyp == NULL); - result = read_public_key(filename, type, mctx, &pubkey); + newfilenamelen = strlen(filename) + 5; + newfilename = isc_mem_get(mctx, newfilenamelen); + if (newfilename == NULL) + return (ISC_R_NOMEMORY); + result = addsuffix(newfilename, newfilenamelen, filename, ".key"); + INSIST(result == ISC_R_SUCCESS); + + result = dst_key_read_public(newfilename, type, mctx, &pubkey); + isc_mem_put(mctx, newfilename, newfilenamelen); if (result != ISC_R_SUCCESS) return (result); @@ -825,9 +829,9 @@ get_key_struct(dns_name_t *name, unsigned int alg, /* * Reads a public key from disk */ -static isc_result_t -read_public_key(const char *filename, int type, - isc_mem_t *mctx, dst_key_t **keyp) +isc_result_t +dst_key_read_public(const char *filename, int type, + isc_mem_t *mctx, dst_key_t **keyp) { u_char rdatabuf[DST_KEY_MAXSIZE]; isc_buffer_t b; @@ -837,25 +841,16 @@ read_public_key(const char *filename, int type, isc_result_t ret; dns_rdata_t rdata = DNS_RDATA_INIT; unsigned int opt = ISC_LEXOPT_DNSMULTILINE; - char *newfilename; - unsigned int newfilenamelen; dns_rdataclass_t rdclass = dns_rdataclass_in; isc_lexspecials_t specials; isc_uint32_t ttl; isc_result_t result; dns_rdatatype_t keytype; - newfilenamelen = strlen(filename) + 5; - newfilename = isc_mem_get(mctx, newfilenamelen); - if (newfilename == NULL) - return (ISC_R_NOMEMORY); - ret = addsuffix(newfilename, newfilenamelen, filename, ".key"); - INSIST(ret == ISC_R_SUCCESS); - /* * Open the file and read its formatted contents * File format: - * domain.name [ttl] [class] KEY + * domain.name [ttl] [class] [KEY|DNSKEY] */ /* 1500 should be large enough for any key */ @@ -870,7 +865,7 @@ read_public_key(const char *filename, int type, isc_lex_setspecials(lex, specials); isc_lex_setcomments(lex, ISC_LEXCOMMENT_DNSMASTERFILE); - ret = isc_lex_openfile(lex, newfilename); + ret = isc_lex_openfile(lex, filename); if (ret != ISC_R_SUCCESS) goto cleanup; @@ -942,8 +937,6 @@ read_public_key(const char *filename, int type, cleanup: if (lex != NULL) isc_lex_destroy(&lex); - isc_mem_put(mctx, newfilename, newfilenamelen); - return (ret); } diff --git a/lib/dns/sec/dst/include/dst/dst.h b/lib/dns/sec/dst/include/dst/dst.h index 0589efe110..20dd8136cd 100644 --- a/lib/dns/sec/dst/include/dst/dst.h +++ b/lib/dns/sec/dst/include/dst/dst.h @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dst.h,v 1.48 2004/06/11 00:27:01 marka Exp $ */ +/* $Id: dst.h,v 1.49 2004/10/14 05:55:52 marka Exp $ */ #ifndef DST_DST_H #define DST_DST_H 1 @@ -253,6 +253,29 @@ dst_key_fromnamedfile(const char *filename, int type, isc_mem_t *mctx, * If successful, *keyp will contain a valid key. */ + +isc_result_t +dst_key_read_public(const char *filename, int type, + isc_mem_t *mctx, dst_key_t **keyp); +/* + * Reads a public key from permanent storage. The key must be a public key. + * + * Requires: + * "filename" is not NULL + * "type" is DST_TYPE_KEY look for a KEY record otherwise DNSKEY + * "mctx" is a valid memory context + * "keyp" is not NULL and "*keyp" is NULL. + * + * Returns: + * ISC_R_SUCCESS + * DST_R_BADKEYTYPE if the key type is not the expected one + * ISC_R_UNEXPECTEDTOKEN if the file can not be parsed as a public key + * any other result indicates failure + * + * Ensures: + * If successful, *keyp will contain a valid key. + */ + isc_result_t dst_key_tofile(const dst_key_t *key, int type, const char *directory); /*