From: Jelte Jansen Date: Tue, 23 Aug 2005 09:26:22 +0000 (+0000) Subject: finished CERT type from string. renamed some values and functions, removed old code X-Git-Tag: release-1.0.0~264 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b849d34669c5654197876cbad36cd5f73143812;p=thirdparty%2Fldns.git finished CERT type from string. renamed some values and functions, removed old code --- diff --git a/host2str.c b/host2str.c index 2b4adc1f..63b21f27 100644 --- a/host2str.c +++ b/host2str.c @@ -23,16 +23,6 @@ /* lookup tables for standard DNS stuff */ -/* Taken from RFC 2538, section 2.1. */ -ldns_lookup_table ldns_certificate_types[] = { - { 0, "PKIX" }, /* X.509 as per PKIX */ - { 1, "SPKI" }, /* SPKI cert */ - { 2, "PGP" }, /* PGP cert */ - { 253, "URI" }, /* URI private */ - { 254, "OID" }, /* OID private */ - { 0, NULL } -}; - /* Taken from RFC 2535, section 7. */ ldns_lookup_table ldns_algorithms[] = { { LDNS_RSAMD5, "RSAMD5" }, @@ -46,6 +36,16 @@ ldns_lookup_table ldns_algorithms[] = { { 0, NULL } }; +/* Taken from RFC 2538 */ +ldns_lookup_table ldns_cert_algorithms[] = { + { LDNS_CERT_PKIX, "PKIX" }, + { LDNS_CERT_SPKI, "SPKI" }, + { LDNS_CERT_PGP, "PGP" }, + { LDNS_CERT_URI, "URI" }, + { LDNS_CERT_OID, "OID" }, + { 0, NULL } +}; + /* classes */ ldns_lookup_table ldns_rr_classes[] = { { LDNS_RR_CLASS_IN, "IN" }, @@ -268,27 +268,27 @@ ldns_rdf2buffer_str_class(ldns_buffer *output, ldns_rdf *rdf) } ldns_status -ldns_rdf2buffer_str_alg(ldns_buffer *output, ldns_rdf *rdf) +ldns_rdf2buffer_str_cert_alg(ldns_buffer *output, ldns_rdf *rdf) { uint8_t data = ldns_rdf_data(rdf)[0]; ldns_lookup_table *lt; - lt = ldns_lookup_by_id(ldns_algorithms, (int) data); + lt = ldns_lookup_by_id(ldns_cert_algorithms, (int) data); if (lt) { ldns_buffer_printf(output, "%s", lt->name); } else { - ldns_buffer_printf(output, "ALG%d", data); + ldns_buffer_printf(output, "%d", data); } return ldns_buffer_status(output); } ldns_status -ldns_rdf2buffer_str_cert(ldns_buffer *output, ldns_rdf *rdf) +ldns_rdf2buffer_str_alg(ldns_buffer *output, ldns_rdf *rdf) { - uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf)); + uint8_t data = ldns_rdf_data(rdf)[0]; ldns_lookup_table *lt; - lt = ldns_lookup_by_id(ldns_certificate_types, (int) data); + lt = ldns_lookup_by_id(ldns_algorithms, (int) data); if (lt) { ldns_buffer_printf(output, "%s", lt->name); } else { @@ -735,8 +735,8 @@ ldns_rdf2buffer_str(ldns_buffer *buffer, ldns_rdf *rdf) case LDNS_RDF_TYPE_CLASS: res = ldns_rdf2buffer_str_class(buffer, rdf); break; - case LDNS_RDF_TYPE_CERT: - res = ldns_rdf2buffer_str_cert(buffer, rdf); + case LDNS_RDF_TYPE_CERT_ALG: + res = ldns_rdf2buffer_str_cert_alg(buffer, rdf); break; case LDNS_RDF_TYPE_ALG: res = ldns_rdf2buffer_str_alg(buffer, rdf); diff --git a/ldns/dns.h b/ldns/dns.h index 5e35f3c3..c257d3dc 100644 --- a/ldns/dns.h +++ b/ldns/dns.h @@ -51,6 +51,8 @@ extern ldns_lookup_table ldns_certificate_types[]; /* Taken from RFC 2535, section 7. */ extern ldns_lookup_table ldns_algorithms[]; +/* Taken from RFC 2538. */ +extern ldns_lookup_table ldns_cert_algorithms[]; /* rr types */ extern ldns_lookup_table ldns_rr_classes[]; /* if these are used elsewhere */ diff --git a/ldns/host2str.h b/ldns/host2str.h index a38d7886..3168a637 100644 --- a/ldns/host2str.h +++ b/ldns/host2str.h @@ -93,7 +93,7 @@ ldns_status ldns_rdf2buffer_str_alg(ldns_buffer *output, ldns_rdf *rdf); * \param[in] *output The buffer to add the data to * \return LDNS_STATUS_OK on success, and error status on failure */ -ldns_status ldns_rdf2buffer_str_cert(ldns_buffer *output, ldns_rdf *rdf); +ldns_status ldns_rdf2buffer_str_cert_alg(ldns_buffer *output, ldns_rdf *rdf); /** * Converts an LDNS_RDF_TYPE_LOC rdata element to string format and adds it to the output buffer diff --git a/ldns/rdata.h b/ldns/rdata.h index 0f92ebee..4a5048f1 100644 --- a/ldns/rdata.h +++ b/ldns/rdata.h @@ -52,8 +52,8 @@ enum ldns_enum_rdf_type LDNS_RDF_TYPE_TYPE, /** a class */ LDNS_RDF_TYPE_CLASS, - /** certificates */ - LDNS_RDF_TYPE_CERT, + /** certificate algorithm */ + LDNS_RDF_TYPE_CERT_ALG, /** a key algorithm */ LDNS_RDF_TYPE_ALG, /** unknown types */ @@ -81,6 +81,21 @@ enum ldns_enum_rdf_type }; typedef enum ldns_enum_rdf_type ldns_rdf_type; +/** + * algorithms used in CERT rrs + */ +enum ldns_enum_cert_algorithm +{ + LDNS_CERT_PKIX = 1, + LDNS_CERT_SPKI = 2, + LDNS_CERT_PGP = 3, + LDNS_CERT_URI = 253, + LDNS_CERT_OID = 254 +}; +typedef enum ldns_enum_cert_algorithm ldns_cert_algorithm; + + + /** * Resource record data. * diff --git a/ldns/str2host.h b/ldns/str2host.h index 004a083d..dff31214 100644 --- a/ldns/str2host.h +++ b/ldns/str2host.h @@ -141,6 +141,14 @@ ldns_status ldns_str2rdf_class(ldns_rdf **rd, const char *str); */ ldns_status ldns_str2rdf_cert(ldns_rdf **rd, const char *str); +/** + * convert an certificate algorithm value into wireformat + * \param[in] rd the rdf where to put the data + * \param[in] str the string to be converted + * \return ldns_status + */ +ldns_status ldns_str2rdf_cert_alg(ldns_rdf **rd, const char *str); + /** * convert and algorithm value into wireformat * \param[in] rd the rdf where to put the data diff --git a/rdata.c b/rdata.c index 7b70a206..c1906d44 100644 --- a/rdata.c +++ b/rdata.c @@ -329,8 +329,8 @@ ldns_rdf_new_frm_str(ldns_rdf_type type, const char *str) case LDNS_RDF_TYPE_CLASS: status = ldns_str2rdf_class(&rdf, str); break; - case LDNS_RDF_TYPE_CERT: - status = ldns_str2rdf_cert(&rdf, str); + case LDNS_RDF_TYPE_CERT_ALG: + status = ldns_str2rdf_cert_alg(&rdf, str); break; case LDNS_RDF_TYPE_ALG: status = ldns_str2rdf_alg(&rdf, str); diff --git a/rr.c b/rr.c index f852dfc0..4565b2c1 100644 --- a/rr.c +++ b/rr.c @@ -397,7 +397,15 @@ ldns_rr_new_frm_fp_l(FILE *fp, uint16_t ttl, ldns_rdf *origin, int *line_nr) } rr = ldns_rr_new_frm_str((const char*) line, ttl, origin); - +/* +printf("line %d: %s\n", *line_nr, line); +*/ +if (rr && ldns_rr_get_type(rr) == LDNS_RR_TYPE_CERT) { + printf("got CERT RR:\n"); + ldns_rr_print(stdout, rr); + printf("from:\n%s\n", line); +exit(1); +} LDNS_FREE(line); return rr; } @@ -1290,7 +1298,7 @@ static const ldns_rdf_type type_kx_wireformat[] = { LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_DNAME }; static const ldns_rdf_type type_cert_wireformat[] = { - LDNS_RDF_TYPE_CERT, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_B64 + LDNS_RDF_TYPE_CERT_ALG, LDNS_RDF_TYPE_INT16, LDNS_RDF_TYPE_ALG, LDNS_RDF_TYPE_B64 }; static const ldns_rdf_type type_a6_wireformat[] = { LDNS_RDF_TYPE_DNAME }; static const ldns_rdf_type type_dname_wireformat[] = { LDNS_RDF_TYPE_DNAME }; diff --git a/str2host.c b/str2host.c index 573b8aa4..d39d50c5 100644 --- a/str2host.c +++ b/str2host.c @@ -460,14 +460,35 @@ ldns_str2rdf_class(ldns_rdf **rd, const char *str) return LDNS_STATUS_OK; } +/* An certificate alg field can either be specified as a 8 bits number + * or by its symbolic name. Handle both + */ ldns_status -ldns_str2rdf_cert(ldns_rdf **rd, const char *str) +ldns_str2rdf_cert_alg(ldns_rdf **rd, const char *str) { - rd = rd; - str = str; - return LDNS_STATUS_NOT_IMPL; -} + ldns_lookup_table *lt; + ldns_status st; + + lt = ldns_lookup_by_name(ldns_cert_algorithms, str); + st = LDNS_STATUS_OK; +printf("YOYOYO\n"); + if (lt) { +printf("LT: %s\n", str); + /* it was given as a integer */ + *rd = ldns_rdf_new_frm_data( + LDNS_RDF_TYPE_INT8, sizeof(uint8_t), <->id); + if (!*rd) { + st = LDNS_STATUS_ERR; + } + } else { +printf("NO LT: %s\n", str); + /* try as-is (a number) */ + st = ldns_str2rdf_int8(rd, str); + } + return st; +} + /* An alg field can either be specified as a 8 bits number * or by its symbolic name. Handle both */ diff --git a/wire2host.c b/wire2host.c index ce3df4c1..dde2267a 100644 --- a/wire2host.c +++ b/wire2host.c @@ -197,7 +197,7 @@ ldns_wire2rdf(ldns_rr *rr, const uint8_t *wire, break; case LDNS_RDF_TYPE_TYPE: case LDNS_RDF_TYPE_INT16: - case LDNS_RDF_TYPE_CERT: + case LDNS_RDF_TYPE_CERT_ALG: cur_rdf_length = 2; break; case LDNS_RDF_TYPE_TIME: