Commit e098b976 authored by Karel Slaný's avatar Karel Slaný

Added functions for server DNS cookie parsing.

parent 8de47b5e
......@@ -103,6 +103,7 @@ nobase_libknot_la_HEADERS = \
libknot/control/control.h \
libknot/cookies/client.h \
libknot/cookies/server.h \
libknot/cookies/server-parse.h \
libknot/descriptor.h \
libknot/dname.h \
libknot/errcode.h \
......@@ -129,7 +130,7 @@ nobase_libknot_la_HEADERS = \
libknot/rrtype/nsec3.h \
libknot/rrtype/nsec3param.h \
libknot/rrtype/opt.h \
libknot/rrtype/opt_cookie.h \
libknot/rrtype/opt-cookie.h \
libknot/rrtype/rdname.h \
libknot/rrtype/rrsig.h \
libknot/rrtype/soa.h \
......@@ -146,6 +147,7 @@ libknot_la_SOURCES = \
libknot/control/control.c \
libknot/cookies/client.c \
libknot/cookies/server.c \
libknot/cookies/server-parse.c \
libknot/descriptor.c \
libknot/dname.c \
libknot/error.c \
......@@ -166,7 +168,7 @@ libknot_la_SOURCES = \
libknot/rrtype/nsec3.c \
libknot/rrtype/nsec3param.c \
libknot/rrtype/opt.c \
libknot/rrtype/opt_cookie.c \
libknot/rrtype/opt-cookie.c \
libknot/rrtype/rrsig.c \
libknot/rrtype/soa.c \
libknot/rrtype/tsig.c \
......
......@@ -24,7 +24,7 @@
#include "libknot/attribute.h"
#include "libknot/cookies/client.h"
#include "libknot/errcode.h"
#include "libknot/rrtype/opt_cookie.h"
#include "libknot/rrtype/opt-cookie.h"
_public_
int knot_sockaddr_bytes(const void *sockaddr,
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <arpa/inet.h> /* ntohl() */
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "libknot/attribute.h"
#include "libknot/cookies/server-parse.h"
#include "libknot/errcode.h"
_public_
int knot_scookie_parse_simple(const uint8_t *sc, uint16_t sc_len,
struct knot_scookie_inbound *inbound)
{
if (!sc || !sc_len || !inbound) {
return KNOT_EINVAL;
}
//memset(inbound, 0, sizeof(*inbound));
inbound->hash_data = sc; /* Entire server cookie contains data. */
inbound->hash_len = sc_len;
return KNOT_EOK;
}
_public_
int knot_scookie_parse(const uint8_t *sc, uint16_t sc_len,
struct knot_scookie_inbound *inbound)
{
if (!sc || !sc_len || !inbound) {
return KNOT_EINVAL;
}
if (sc_len <= (2 * sizeof(uint32_t))) { /* nonce + time */
return KNOT_EINVAL;
}
uint32_t aux;
memcpy(&aux, sc, sizeof(aux));
inbound->nonce = ntohl(aux);
memcpy(&aux, sc + sizeof(aux), sizeof(aux));
inbound->time = ntohl(aux);
inbound->hash_data = sc + (2 * sizeof(aux));
inbound->hash_len = sc_len - (2 * sizeof(aux));
return KNOT_EOK;
}
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file
*
* \brief Functions for reading server cookie values.
*
* \addtogroup libknot
* @{
*/
#pragma once
#include "libknot/cookies/server.h"
/*!
* \brief Reads a server cookie that consists only of a hash value.
*
* \note DNS Cookies -- Appendix B.1
*
* \param sc Server cookie.
* \param sc_len Server cookie length.
* \param inbound Inbound server cookie structure to be populated.
*
* \retval KNOT_EOK
* \ratval KNOT_EINVAL
*/
int knot_scookie_parse_simple(const uint8_t *sc, uint16_t sc_len,
struct knot_scookie_inbound *inbound);
/*!
* \brief Reads a server cookie contains nonce and times stamp before actual
* hash value.
*
* \note DNS Cookies -- Appendix B.2
*
* \param sc Server cookie.
* \param sc_len Server cookie length.
* \param inbound Inbound server cookie structure to be populated.
*
* \retval KNOT_EOK
* \ratval KNOT_EINVAL
*/
int knot_scookie_parse(const uint8_t *sc, uint16_t sc_len,
struct knot_scookie_inbound *inbound);
/*! @} */
......@@ -21,7 +21,7 @@
#include "libknot/attribute.h"
#include "libknot/cookies/server.h"
#include "libknot/errcode.h"
#include "libknot/rrtype/opt_cookie.h"
#include "libknot/rrtype/opt-cookie.h"
_public_
int knot_scookie_check(const struct knot_dns_cookies *cookies,
......
......@@ -21,7 +21,7 @@
#include "libknot/consts.h" // knot_addr_family_t -- is unused
#include "libknot/errcode.h"
#include "libknot/rrtype/opt.h"
#include "libknot/rrtype/opt_cookie.h"
#include "libknot/rrtype/opt-cookie.h"
_public_
int knot_edns_opt_cookie_write(const uint8_t *cc, uint16_t cc_len,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment