Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Showing
with 581 additions and 258 deletions
# SPDX-License-Identifier: GPL-3.0-or-later
#run unbound
service unbound start && service unbound status;
# dig @localhost -p 53535
#run bind
service named start && service named status;
# dig @localhost -p 53533
#run kresd
$PREFIX/sbin/kresd -n -q -c $(pwd)/ci/respdiff/kresd.config &>kresd.log &
# dig @localhost -p 5353
# Project
MAJOR := 1
MINOR := 1
PATCH := 0
ABIVER := 1
BUILDMODE := dynamic
HARDENING := yes
# Paths
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
SBINDIR ?= $(PREFIX)/sbin
LIBDIR ?= $(PREFIX)/lib
INCLUDEDIR ?= $(PREFIX)/include
MODULEDIR ?= $(LIBDIR)/kdns_modules
ETCDIR ?= $(PREFIX)/etc/kresd
# Tools
CC ?= cc
RM := rm -f
LN := ln -s
XXD := ./scripts/embed.sh
INSTALL := install
# Flags
BUILD_LDFLAGS += $(LDFLAGS)
BUILD_CFLAGS := $(CFLAGS) -std=c99 -D_GNU_SOURCE -Wno-unused -Wtype-limits -Wformat -Wformat-security -Wall -I$(abspath .) -I$(abspath lib/generic) -I$(abspath contrib) -I$(abspath contrib/lmdb)
BUILD_CFLAGS += -DPACKAGE_VERSION="\"$(MAJOR).$(MINOR).$(PATCH)\"" -DPREFIX="\"$(PREFIX)\"" -DMODULEDIR="\"$(MODULEDIR)\"" -DETCDIR="\"$(ETCDIR)\""
ifeq (,$(findstring -O,$(CFLAGS)))
BUILD_CFLAGS += -O2
endif
ifeq (,$(findstring -fsanitize=address,$(CFLAGS)))
BUILD_CFLAGS += -D_FORTIFY_SOURCE=2
endif
/* Copyright (C) 2011 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 <https://www.gnu.org/licenses/>.
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "contrib/base32hex.h"
#include "base32hex.h"
#include <stdlib.h>
#include <stdint.h>
......@@ -23,9 +11,9 @@
#define MAX_BIN_DATA_LEN ((INT32_MAX / 8) * 5)
/*! \brief Base32hex padding character. */
const uint8_t base32hex_pad = '=';
/*! \brief Base32hex alphabet. */
const uint8_t base32hex_enc[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
static const uint8_t base32hex_pad = '=';
/*! \brief Base32hex alphabet. Beware: original code was upper-case. */
static const uint8_t base32hex_enc[] = "0123456789abcdefghijklmnopqrstuv";
/*! \brief Indicates bad Base32hex character. */
#define KO 255
......@@ -33,7 +21,7 @@ const uint8_t base32hex_enc[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
#define PD 32
/*! \brief Transformation and validation table for decoding Base32hex. */
const uint8_t base32hex_dec[256] = {
static const uint8_t base32hex_dec[256] = {
[ 0] = KO, [ 43] = KO, ['V'] = 31, [129] = KO, [172] = KO, [215] = KO,
[ 1] = KO, [ 44] = KO, ['W'] = KO, [130] = KO, [173] = KO, [216] = KO,
[ 2] = KO, [ 45] = KO, ['X'] = KO, [131] = KO, [174] = KO, [217] = KO,
......@@ -205,3 +193,85 @@ int32_t base32hex_decode(const uint8_t *in,
return (bin - out);
}
int32_t base32hex_encode(const uint8_t *in,
const uint32_t in_len,
uint8_t *out,
const uint32_t out_len)
{
// Checking inputs.
if (in == NULL || out == NULL) {
return -1;
}
if (in_len > MAX_BIN_DATA_LEN || out_len < ((in_len + 4) / 5) * 8) {
return -1;
}
uint8_t rest_len = in_len % 5;
const uint8_t *stop = in + in_len - rest_len;
uint8_t *text = out;
// Encoding loop takes 5 bytes and creates 8 characters.
while (in < stop) {
text[0] = base32hex_enc[in[0] >> 3];
text[1] = base32hex_enc[(in[0] & 0x07) << 2 | in[1] >> 6];
text[2] = base32hex_enc[(in[1] & 0x3E) >> 1];
text[3] = base32hex_enc[(in[1] & 0x01) << 4 | in[2] >> 4];
text[4] = base32hex_enc[(in[2] & 0x0F) << 1 | in[3] >> 7];
text[5] = base32hex_enc[(in[3] & 0x7C) >> 2];
text[6] = base32hex_enc[(in[3] & 0x03) << 3 | in[4] >> 5];
text[7] = base32hex_enc[in[4] & 0x1F];
text += 8;
in += 5;
}
// Processing of padding, if any.
switch (rest_len) {
case 4:
text[0] = base32hex_enc[in[0] >> 3];
text[1] = base32hex_enc[(in[0] & 0x07) << 2 | in[1] >> 6];
text[2] = base32hex_enc[(in[1] & 0x3E) >> 1];
text[3] = base32hex_enc[(in[1] & 0x01) << 4 | in[2] >> 4];
text[4] = base32hex_enc[(in[2] & 0x0F) << 1 | in[3] >> 7];
text[5] = base32hex_enc[(in[3] & 0x7C) >> 2];
text[6] = base32hex_enc[(in[3] & 0x03) << 3];
text[7] = base32hex_pad;
text += 8;
break;
case 3:
text[0] = base32hex_enc[in[0] >> 3];
text[1] = base32hex_enc[(in[0] & 0x07) << 2 | in[1] >> 6];
text[2] = base32hex_enc[(in[1] & 0x3E) >> 1];
text[3] = base32hex_enc[(in[1] & 0x01) << 4 | in[2] >> 4];
text[4] = base32hex_enc[(in[2] & 0x0F) << 1];
text[5] = base32hex_pad;
text[6] = base32hex_pad;
text[7] = base32hex_pad;
text += 8;
break;
case 2:
text[0] = base32hex_enc[in[0] >> 3];
text[1] = base32hex_enc[(in[0] & 0x07) << 2 | in[1] >> 6];
text[2] = base32hex_enc[(in[1] & 0x3E) >> 1];
text[3] = base32hex_enc[(in[1] & 0x01) << 4];
text[4] = base32hex_pad;
text[5] = base32hex_pad;
text[6] = base32hex_pad;
text[7] = base32hex_pad;
text += 8;
break;
case 1:
text[0] = base32hex_enc[in[0] >> 3];
text[1] = base32hex_enc[(in[0] & 0x07) << 2];
text[2] = base32hex_pad;
text[3] = base32hex_pad;
text[4] = base32hex_pad;
text[5] = base32hex_pad;
text[6] = base32hex_pad;
text[7] = base32hex_pad;
text += 8;
break;
}
return (text - out);
}
/* Copyright (C) 2011 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 <https://www.gnu.org/licenses/>.
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
/*!
* \file
......@@ -49,4 +37,24 @@ int32_t base32hex_decode(const uint8_t *in,
uint8_t *out,
const uint32_t out_len);
/*!
* \brief Encodes binary data using Base32hex. Lower case is used!
*
* \note Output data buffer contains Base32hex text string which isn't
* terminated with '\0'!
*
* \param in Input binary data.
* \param in_len Length of input data.
* \param out Output data buffer.
* \param out_len Size of output buffer.
*
* \retval >=0 length of output string.
* \retval <0 if error.
*/
int32_t base32hex_encode(const uint8_t *in,
const uint32_t in_len,
uint8_t *out,
const uint32_t out_len);
/*! @} */
SPDXVersion: SPDX-2.1
DataLicense: CC0-1.0
SPDXID: SPDXRef-DOCUMENT
DocumentName: knotdns-base32hex
DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-4f29f08d-5fbf-4793-934c-9a6a2e6d5517
PackageName: knotdns-base32hex
PackageDownloadLocation: git+https://gitlab.nic.cz/knot/knot-dns.git@2b3c828a4cb8d9595318552483d4947345426c30#src/libknot/internal/base32hex.c
PackageOriginator: Organization: Knot DNS contributors
PackageLicenseDeclared: GPL-3.0-or-later
/* Copyright (C) 2011 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/>.
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "contrib/base64.h"
#include "base64.h"
#include "libknot/errcode.h"
#include <stdlib.h>
......@@ -81,7 +69,7 @@ static const uint8_t base64_dec[256] = {
[ 42] = KO, ['U'] = 20, [128] = KO, [171] = KO, [214] = KO,
};
int32_t base64_encode(const uint8_t *in,
int32_t kr_base64_encode(const uint8_t *in,
const uint32_t in_len,
uint8_t *out,
const uint32_t out_len)
......@@ -129,7 +117,7 @@ int32_t base64_encode(const uint8_t *in,
return (text - out);
}
int32_t base64_encode_alloc(const uint8_t *in,
int32_t kr_base64_encode_alloc(const uint8_t *in,
const uint32_t in_len,
uint8_t **out)
{
......@@ -151,15 +139,16 @@ int32_t base64_encode_alloc(const uint8_t *in,
}
// Encode data.
int32_t ret = base64_encode(in, in_len, *out, out_len);
int32_t ret = kr_base64_encode(in, in_len, *out, out_len);
if (ret < 0) {
free(*out);
*out = NULL;
}
return ret;
}
int32_t base64_decode(const uint8_t *in,
int32_t kr_base64_decode(const uint8_t *in,
const uint32_t in_len,
uint8_t *out,
const uint32_t out_len)
......@@ -215,8 +204,10 @@ int32_t base64_decode(const uint8_t *in,
switch (pad_len) {
case 0:
bin[2] = (c3 << 6) + c4;
// FALLTHROUGH
case 1:
bin[1] = (c2 << 4) + (c3 >> 2);
// FALLTHROUGH
case 2:
bin[0] = (c1 << 2) + (c2 >> 4);
}
......@@ -240,7 +231,7 @@ int32_t base64_decode(const uint8_t *in,
return (bin - out);
}
int32_t base64_decode_alloc(const uint8_t *in,
int32_t kr_base64_decode_alloc(const uint8_t *in,
const uint32_t in_len,
uint8_t **out)
{
......@@ -259,9 +250,10 @@ int32_t base64_decode_alloc(const uint8_t *in,
}
// Decode data.
int32_t ret = base64_decode(in, in_len, *out, out_len);
int32_t ret = kr_base64_decode(in, in_len, *out, out_len);
if (ret < 0) {
free(*out);
*out = NULL;
}
return ret;
......
/* Copyright (C) 2011 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/>.
/* Copyright (C) CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
/*!
* \file
......@@ -40,7 +28,7 @@
* \retval >=0 length of output string.
* \retval KNOT_E* if error.
*/
int32_t base64_encode(const uint8_t *in,
int32_t kr_base64_encode(const uint8_t *in,
const uint32_t in_len,
uint8_t *out,
const uint32_t out_len);
......@@ -60,7 +48,7 @@ int32_t base64_encode(const uint8_t *in,
* \retval >=0 length of output string.
* \retval KNOT_E* if error.
*/
int32_t base64_encode_alloc(const uint8_t *in,
int32_t kr_base64_encode_alloc(const uint8_t *in,
const uint32_t in_len,
uint8_t **out);
......@@ -79,7 +67,7 @@ int32_t base64_encode_alloc(const uint8_t *in,
* \retval >=0 length of output data.
* \retval KNOT_E* if error.
*/
int32_t base64_decode(const uint8_t *in,
int32_t kr_base64_decode(const uint8_t *in,
const uint32_t in_len,
uint8_t *out,
const uint32_t out_len);
......@@ -100,7 +88,7 @@ int32_t base64_decode(const uint8_t *in,
* \retval >=0 length of output data.
* \retval KNOT_E* if error.
*/
int32_t base64_decode_alloc(const uint8_t *in,
int32_t kr_base64_decode_alloc(const uint8_t *in,
const uint32_t in_len,
uint8_t **out);
......
SPDXVersion: SPDX-2.1
DataLicense: CC0-1.0
SPDXID: SPDXRef-DOCUMENT
DocumentName: knotdns-base64
DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-669dfa8c-3b50-425f-92fc-9b7ce18999f2
PackageName: knotdns-base64
PackageDownloadLocation: git+https://gitlab.nic.cz/knot/knot-dns.git@2b3c828a4cb8d9595318552483d4947345426c30#src/libknot/internal/base64.c
PackageOriginator: Organization: Knot DNS contributors
PackageLicenseDeclared: GPL-3.0-or-later
This diff is collapsed.
/* Copyright (C) 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 <https://www.gnu.org/licenses/>.
*/
/*!
* \brief Base64url implementation (RFC 4648).
*/
#pragma once
#include <stdint.h>
/*!
* \brief Encodes binary data using Base64.
*
* \note Output data buffer contains Base64 text string which isn't
* terminated with '\0'!
*
* \param in Input binary data.
* \param in_len Length of input data.
* \param out Output data buffer.
* \param out_len Size of output buffer.
*
* \retval >=0 length of output string.
* \retval KNOT_E* if error.
*/
int32_t kr_base64url_encode(const uint8_t *in,
const uint32_t in_len,
uint8_t *out,
const uint32_t out_len);
/*!
* \brief Encodes binary data using Base64 and output stores to own buffer.
*
* \note Output data buffer contains Base64 text string which isn't
* terminated with '\0'!
*
* \note Output buffer should be deallocated after use.
*
* \param in Input binary data.
* \param in_len Length of input data.
* \param out Output data buffer.
*
* \retval >=0 length of output string.
* \retval KNOT_E* if error.
*/
int32_t kr_base64url_encode_alloc(const uint8_t *in,
const uint32_t in_len,
uint8_t **out);
/*!
* \brief Decodes text data using Base64.
*
* \note Input data needn't be terminated with '\0'.
*
* \note Input data must be continuous Base64 string!
*
* \param in Input text data.
* \param in_len Length of input string.
* \param out Output data buffer.
* \param out_len Size of output buffer.
*
* \retval >=0 length of output data.
* \retval KNOT_E* if error.
*/
int32_t kr_base64url_decode(const uint8_t *in,
uint32_t in_len,
uint8_t *out,
const uint32_t out_len);
/*!
* \brief Decodes text data using Base64 and output stores to own buffer.
*
* \note Input data needn't be terminated with '\0'.
*
* \note Input data must be continuous Base64 string!
*
* \note Output buffer should be deallocated after use.
*
* \param in Input text data.
* \param in_len Length of input string.
* \param out Output data buffer.
*
* \retval >=0 length of output data.
* \retval KNOT_E* if error.
*/
int32_t kr_base64url_decode_alloc(const uint8_t *in,
const uint32_t in_len,
uint8_t **out);
/*! @} */
This diff is collapsed.
/* Licensed under BSD-MIT - see LICENSE file for details */
/* SPDX-License-Identifier: MIT
* Source: https://ccodearchive.net/info/asprintf.html */
#include <ccan/asprintf/asprintf.h>
#include <stdarg.h>
#include <stdio.h>
......@@ -16,7 +17,7 @@ char *PRINTF_FMT(1, 2) afmt(const char *fmt, ...)
return ptr;
}
#if !HAVE_ASPRINTF && !defined(__USE_FORTIFY_LEVEL)
#if !HAVE_ASPRINTF
#include <stdarg.h>
#include <stdlib.h>
......
This diff is collapsed.
SPDXVersion: SPDX-2.1
DataLicense: CC0-1.0
SPDXID: SPDXRef-DOCUMENT
DocumentName: ccan-asprintf
DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-40d4b71d-00e9-4e75-b6da-559203e6b815
PackageName: asprintf
PackageDownloadLocation: git+https://github.com/rustyrussell/ccan@fb1dfd092940905883ea6473162f5f6e36624da2#ccan/asprintf
PackageOriginator: Person: Rusty Russell (rusty@rustcorp.com.au)
PackageLicenseDeclared: MIT
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.