Skip to content
Permalink
Browse files

Add preliminary DNSCurve plugin.

  • Loading branch information...
vstakhov committed Feb 10, 2014
1 parent 36d6fc5 commit d63bad406da4d432bdc75a33dad2bcc941015ea8
Showing with 149 additions and 1 deletion.
  1. +2 −1 CMakeLists.txt
  2. +62 −0 include/rdns_curve.h
  3. +85 −0 src/dns_curve.c
@@ -20,7 +20,8 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")

SET(LIBRDNSSRC src/dns_util.c
src/dns.c
src/punycode.c)
src/punycode.c
src/dns_curve.c)

INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src"
"${CMAKE_SOURCE_DIR}/include"
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2014, Vsevolod Stakhov
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef RDNS_CURVE_H_
#define RDNS_CURVE_H_

#define RDSN_CURVE_PUBKEY_LEN 32

struct rdns_curve_ctx;

/**
* Create new dnscurve ctx
* @return
*/
struct rdns_curve_ctx* rdns_curve_ctx_new (void);

/**
* Add key for server `name`
* @param ctx curve context
* @param name name of server (ip address)
* @param pubkey pubkey bytes (must be `RDSN_CURVE_PUBKEY_LEN`)
*/
void rdns_curve_ctx_add_key (struct rdns_curve_ctx *ctx,
const char *name, const char *pubkey);

/**
* Destroy curve context
* @param ctx
*/
void rdns_curve_ctx_destroy (struct rdns_curve_ctx *ctx);


/**
* Register DNSCurve plugin (libsodium should be enabled for this)
* @param resolver
* @param ctx
*/
void rdns_curve_register_plugin (struct rdns_resolver *resolver,
struct rdns_curve_ctx *ctx);

#endif /* RDNS_CURVE_H_ */
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2014, Vsevolod Stakhov
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "rdns.h"
#include "dns_private.h"
#include "rdns_curve.h"

struct rdns_curve_entry {
char *name;
char pubkey[RDSN_CURVE_PUBKEY_LEN];
UT_hash_handle hh;
};

struct rdns_curve_ctx {
struct rdns_curve_entry *entries;
};

struct rdns_curve_ctx*
rdns_curve_ctx_new (void)
{
struct rdns_curve_ctx *new;

new = calloc (1, sizeof (struct rdns_curve_ctx));

return new;
}


void
rdns_curve_ctx_add_key (struct rdns_curve_ctx *ctx,
const char *name, const char *pubkey)
{
struct rdns_curve_entry *entry;
int len;

len = strlen (pubkey);

if (len == RDSN_CURVE_PUBKEY_LEN) {
entry = malloc (sizeof (struct rdns_curve_entry));
entry->name = strdup (name);
memcpy (entry->pubkey, pubkey, sizeof (entry->pubkey));
HASH_ADD_KEYPTR (hh, ctx->entries, entry->name, strlen (entry->name), entry);
}
}

void rdns_curve_ctx_destroy (struct rdns_curve_ctx *ctx)
{
struct rdns_curve_entry *entry, *tmp;

HASH_ITER (hh, ctx->entries, entry, tmp) {
free (entry->name);
free (entry);
}

free (ctx);
}

void
rdns_curve_register_plugin (struct rdns_resolver *resolver,
struct rdns_curve_ctx *ctx)
{

}

0 comments on commit d63bad4

Please sign in to comment.
You can’t perform that action at this time.