a134177ed9f82189504191d90f3ed9e97c2b47cbTinderbox User * Copyright (C) 2009, 2011, 2013-2017 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9cee5bb02863bf191e12cd4297adabf1971020deAutomatic Updater/* $Id: hip_55.c,v 1.8 2011/01/13 04:59:26 tbox Exp $ */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews/* reviewed: TBC */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews/* RFC 5205 */
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Dummy HIT len.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Algorithm.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(uint8_tobuffer(token.value.as_ulong, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Dummy KEY len.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * HIT (base16).
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETTOK(isc_hex_decodestring(DNS_AS_STR(token), target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Fill in HIT len.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews len = (unsigned char *)isc_buffer_used(target) - start;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews RETERR(uint8_tobuffer((isc_uint32_t)len, &hit_len));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Public key (base64).
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETTOK(isc_base64_decodestring(DNS_AS_STR(token), target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Fill in KEY len.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews len = (unsigned char *)isc_buffer_used(target) - start;
c3c8823fed039b3a2b8e5ca8bc2f3301d1dd840eMark Andrews RETERR(uint16_tobuffer((isc_uint32_t)len, &key_len));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Rendezvous Servers.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews buffer_fromregion(&buffer, &token.value.as_region);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETTOK(dns_name_fromtext(&name, &buffer, origin, options,
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews } while (1);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Let upper layer handle eol/eof.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(isc_hex_totext(®ion, 1, "", target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Public KEY.
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(isc_base64_totext(®ion, 1, "", target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews * Rendezvous Servers.
38b84a1fcfdbda4d1d0fdca409004ae83be2ace8Mark Andrews RETERR(dns_name_totext(&name, ISC_FALSE, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_region_consume(®ion, 2); /* hit length + algorithm */
e7c38ca9635e73c9a928bbab9c73c2abbd499f8bEvan Hunt if (region.length < (unsigned) (hit_len + key_len))
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(mem_tobuffer(target, rr.base, 4 + hit_len + key_len));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews isc_buffer_forward(source, 4 + hit_len + key_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(dns_name_fromwire(&name, source, dctx, options, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (mem_tobuffer(target, region.base, region.length));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline int
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata1->type == dns_rdatatype_hip);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return (isc_region_compare(®ion1, ®ion2));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews REQUIRE((hip->servers == NULL && hip->servers_len == 0) ||
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews (hip->servers != NULL && hip->servers_len != 0));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(uint8_tobuffer(hip->algorithm, target));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(mem_tobuffer(target, hip->hit, hip->hit_len));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews RETERR(mem_tobuffer(target, hip->key, hip->key_len));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews /* empty */;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews return(mem_tobuffer(target, hip->servers, hip->servers_len));
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->hit = mem_maybedup(mctx, region.base, hip->hit_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->key = mem_maybedup(mctx, region.base, hip->key_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews hip->servers = mem_maybedup(mctx, region.base, region.length);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsstatic inline void
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews region.length = hip->servers_len - hip->offset;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrewsdns_rdata_hip_current(dns_rdata_hip_t *hip, dns_name_t *name) {
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews region.length = hip->servers_len - hip->offset;
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews INSIST(name->length + hip->offset <= hip->servers_len);
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewsstatic inline int
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater REQUIRE(rdata1->rdclass == rdata2->rdclass);
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata1->type == dns_rdatatype_hip);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater isc_region_consume(&r1, 2); /* hit length + algorithm */
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater INSIST(r1.length >= (unsigned) (hit_len + key_len));
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater INSIST(r2.length >= (unsigned) (hit_len + key_len));
0c2313eb367de3b58801d643d52c0fd9bc0e5df7Evan Hunt order = memcmp(r1.base, r2.base, hit_len + key_len);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater isc_region_consume(&r1, hit_len + key_len);
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater isc_region_consume(&r2, hit_len + key_len);
e4c6491bbf7ad131cf0a9ae839566b22e3632cddMark Andrews#endif /* RDATA_GENERIC_HIP_5_C */