Skip to content

Commit d63bad4

Browse files
committed
Add preliminary DNSCurve plugin.
1 parent 36d6fc5 commit d63bad4

3 files changed

Lines changed: 149 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
2020

2121
SET(LIBRDNSSRC src/dns_util.c
2222
src/dns.c
23-
src/punycode.c)
23+
src/punycode.c
24+
src/dns_curve.c)
2425

2526
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/src"
2627
"${CMAKE_SOURCE_DIR}/include"

include/rdns_curve.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2014, Vsevolod Stakhov
3+
*
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY AUTHOR ''AS IS'' AND ANY
15+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
* DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
18+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
#ifndef RDNS_CURVE_H_
26+
#define RDNS_CURVE_H_
27+
28+
#define RDSN_CURVE_PUBKEY_LEN 32
29+
30+
struct rdns_curve_ctx;
31+
32+
/**
33+
* Create new dnscurve ctx
34+
* @return
35+
*/
36+
struct rdns_curve_ctx* rdns_curve_ctx_new (void);
37+
38+
/**
39+
* Add key for server `name`
40+
* @param ctx curve context
41+
* @param name name of server (ip address)
42+
* @param pubkey pubkey bytes (must be `RDSN_CURVE_PUBKEY_LEN`)
43+
*/
44+
void rdns_curve_ctx_add_key (struct rdns_curve_ctx *ctx,
45+
const char *name, const char *pubkey);
46+
47+
/**
48+
* Destroy curve context
49+
* @param ctx
50+
*/
51+
void rdns_curve_ctx_destroy (struct rdns_curve_ctx *ctx);
52+
53+
54+
/**
55+
* Register DNSCurve plugin (libsodium should be enabled for this)
56+
* @param resolver
57+
* @param ctx
58+
*/
59+
void rdns_curve_register_plugin (struct rdns_resolver *resolver,
60+
struct rdns_curve_ctx *ctx);
61+
62+
#endif /* RDNS_CURVE_H_ */

src/dns_curve.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2014, Vsevolod Stakhov
3+
*
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY AUTHOR ''AS IS'' AND ANY
15+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
* DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
18+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#include "rdns.h"
27+
#include "dns_private.h"
28+
#include "rdns_curve.h"
29+
30+
struct rdns_curve_entry {
31+
char *name;
32+
char pubkey[RDSN_CURVE_PUBKEY_LEN];
33+
UT_hash_handle hh;
34+
};
35+
36+
struct rdns_curve_ctx {
37+
struct rdns_curve_entry *entries;
38+
};
39+
40+
struct rdns_curve_ctx*
41+
rdns_curve_ctx_new (void)
42+
{
43+
struct rdns_curve_ctx *new;
44+
45+
new = calloc (1, sizeof (struct rdns_curve_ctx));
46+
47+
return new;
48+
}
49+
50+
51+
void
52+
rdns_curve_ctx_add_key (struct rdns_curve_ctx *ctx,
53+
const char *name, const char *pubkey)
54+
{
55+
struct rdns_curve_entry *entry;
56+
int len;
57+
58+
len = strlen (pubkey);
59+
60+
if (len == RDSN_CURVE_PUBKEY_LEN) {
61+
entry = malloc (sizeof (struct rdns_curve_entry));
62+
entry->name = strdup (name);
63+
memcpy (entry->pubkey, pubkey, sizeof (entry->pubkey));
64+
HASH_ADD_KEYPTR (hh, ctx->entries, entry->name, strlen (entry->name), entry);
65+
}
66+
}
67+
68+
void rdns_curve_ctx_destroy (struct rdns_curve_ctx *ctx)
69+
{
70+
struct rdns_curve_entry *entry, *tmp;
71+
72+
HASH_ITER (hh, ctx->entries, entry, tmp) {
73+
free (entry->name);
74+
free (entry);
75+
}
76+
77+
free (ctx);
78+
}
79+
80+
void
81+
rdns_curve_register_plugin (struct rdns_resolver *resolver,
82+
struct rdns_curve_ctx *ctx)
83+
{
84+
85+
}

0 commit comments

Comments
 (0)