Permalink
Browse files

iptunnel added but not debugged.

  • Loading branch information...
Caleb James DeLisle
Caleb James DeLisle committed Oct 23, 2012
1 parent bf31e29 commit c241af8fe340fe93139dd63bffe9fd9f3820ddd9
View
@@ -220,6 +220,7 @@ add_subdirectory(util)
add_subdirectory(switch)
add_subdirectory(net)
add_subdirectory(exception)
+add_subdirectory(tunnel)
#INSTALL(TARGETS cjdroute RUNTIME DESTINATION bin)
View
@@ -20,6 +20,7 @@
#include "interface/Interface.h"
#include "memory/Allocator.h"
#include "util/log/Log.h"
+#include "util/UniqueName.h"
#ifdef FreeBSD
#include <netinet/in.h>
@@ -91,10 +91,11 @@ void AuthorizedPasswords_init(struct Admin* admin,
context->admin = admin;
context->allocator = allocator;
context->ca = ca;
- struct Admin_FunctionArg adma[2] = {
- { .name = "password", .required = 1, .type = "String" },
- { .name = "authType", .required = 0, .type = "Int" }
- };
- Admin_registerFunction("AuthorizedPasswords_add", add, context, true, adma, admin);
+
+ Admin_registerFunction("AuthorizedPasswords_add", add, context, true,
+ ((struct Admin_FunctionArg[]){
+ { .name = "password", .required = 1, .type = "String" },
+ { .name = "authType", .required = 0, .type = "Int" }
+ }), admin);
Admin_registerFunction("AuthorizedPasswords_flush", flush, context, true, NULL, admin);
}
@@ -58,6 +58,7 @@ target_link_libraries(cjdns-core
cjdns-util-log-writer
cjdns-admin-logger
cjdns-util-log-indirect
+ cjdns-tunnel-iptunnel
)
add_executable(cjdns
View
@@ -44,6 +44,8 @@
#include "net/SwitchPinger.h"
#include "net/SwitchPinger_admin.h"
#include "switch/SwitchCore.h"
+#include "tunnel/IpTunnel.h"
+#include "tunnel/IpTunnel_admin.h"
#include "util/log/WriterLog.h"
#include "util/log/IndirectLog.h"
#include "util/Security_admin.h"
@@ -241,14 +243,17 @@ int Core_main(int argc, char** argv)
SerializationModule_register(registry, alloc);
+ struct IpTunnel* ipTun = IpTunnel_new(logger, alloc);
+
struct Ducttape* dt = Ducttape_register(privateKey,
registry,
router,
switchCore,
eventBase,
alloc,
logger,
- admin);
+ admin,
+ ipTun);
struct SwitchPinger* sp =
SwitchPinger_new(&dt->switchPingerIf, eventBase, logger, alloc);
@@ -272,6 +277,7 @@ int Core_main(int argc, char** argv)
Admin_registerFunction("Core_exit", adminExit, logger, true, NULL, admin);
Core_admin_register(addr.ip6.bytes, dt, logger, alloc, admin, eventBase);
Security_admin_register(alloc, logger, admin);
+ IpTunnel_admin_register(ipTun, admin, alloc);
struct MemoryContext* mc =
alloc->clone(sizeof(struct MemoryContext), alloc,
@@ -185,10 +185,12 @@ static int32_t serializeList(const struct Writer* writer,
const List* list)
{
int ret = writer->write("l", 1, writer);
- const struct List_Item* entry = *list;
- while (ret == 0 && entry != NULL) {
- ret = serializeGeneric(writer, entry->elem);
- entry = entry->next;
+ if (list) {
+ const struct List_Item* entry = *list;
+ while (ret == 0 && entry != NULL) {
+ ret = serializeGeneric(writer, entry->elem);
+ entry = entry->next;
+ }
}
if (ret == 0) {
ret = writer->write("e", 1, writer);
View
@@ -29,11 +29,19 @@ target_link_libraries(crypto
util
)
-add_library(cjdns-crypto-bench CryptoAuth_benchmark.c)
-target_link_libraries(cjdns-crypto-bench crypto)
+add_library(cjdns-crypto-bench
+ CryptoAuth_benchmark.c)
+target_link_libraries(cjdns-crypto-bench
+ crypto
+)
-add_library(crypto_benchmark CryptoAuth_benchmark.c)
-target_link_libraries(crypto_benchmark crypto)
+add_library(cjdns-crypto-key
+ Key.c
+)
+target_link_libraries(cjdns-crypto-key
+ util
+ crypto
+)
# Everything must be tested.
enable_testing()
View
@@ -0,0 +1,65 @@
+/* vim: set expandtab ts=4 sw=4: */
+/*
+ * You may redistribute this program 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 "crypto/Key.h"
+#include "util/Base32.h"
+#include "crypto/AddressCalc.h"
+
+char* Key_parse_strerror(int error)
+{
+ switch (error) {
+ case 0: return "none";
+ case Key_parse_TOO_SHORT: return "key must be 52 characters long";
+ case Key_parse_MALFORMED: return "key must end in .k";
+ case Key_parse_DECODE_FAILED: return "failed to base-32 decode key";
+ case Key_parse_INVALID: return "not a valid cjdns public key";
+ default: return "unknown error";
+ }
+}
+
+#define Key_parse_TOO_SHORT -1
+#define Key_parse_MALFORMED -2
+#define Key_parse_DECODE_FAILED -3
+#define Key_parse_INVALID -4
+
+
+int Key_parse(String* key, uint8_t keyBytesOut[32], uint8_t ip6Out[16])
+{
+ if (!key || key->len < 52) {
+ return Key_parse_TOO_SHORT;
+ }
+ if (key->bytes[52] != '.' || key->bytes[53] != 'k') {
+ return Key_parse_MALFORMED;
+ }
+ if (Base32_decode(keyBytesOut, 32, (uint8_t*)key->bytes, 52) != 32) {
+ return Key_parse_DECODE_FAILED;
+ }
+ if (ip6Out) {
+ AddressCalc_addressForPublicKey(ip6Out, keyBytesOut);
+ if (ip6Out[0] != 0xfc) {
+ return Key_parse_INVALID;
+ }
+ }
+ return 0;
+}
+
+String* Key_stringify(uint8_t key[32], struct Allocator* alloc)
+{
+ String* out = String_newBinary(NULL, 55, alloc);
+ Base32_encode((uint8_t*)out->bytes, 53, key, 32);
+ out->bytes[53] = '.';
+ out->bytes[54] = 'k';
+ return out;
+}
View
@@ -0,0 +1,45 @@
+/* vim: set expandtab ts=4 sw=4: */
+/*
+ * You may redistribute this program 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/>.
+ */
+#ifndef Key_H
+#define Key_H
+
+#include "benc/String.h"
+#include "memory/Allocator.h"
+
+#include <stdint.h>
+
+char* Key_parse_strerror(int error);
+
+#define Key_parse_TOO_SHORT -1
+#define Key_parse_MALFORMED -2
+#define Key_parse_DECODE_FAILED -3
+
+/** Invalid cjdns key (doesn't hash to an address beginning with FC) */
+#define Key_parse_INVALID -4
+
+/**
+ * Parse a key.
+ *
+ * @param key a public key similar to h9xgk0418x538kg2h5yw4n32rkl4wk4wplkzsmltpg20q78bu7q0.k
+ * @param keyBytesOut a 32 byte array which will be set to the key.
+ * @param ip6Out a 16 byte array which will be set to the IPv6 address, if NULL it will be skipped
+ * and the function will not check if the first byte is FC.
+ * @return an error code or 0 if no error.
+ */
+int Key_parse(String* key, uint8_t keyBytesOut[32], uint8_t ip6Out[16]);
+
+String* Key_stringify(uint8_t key[32], struct Allocator* alloc);
+
+#endif
View
@@ -26,7 +26,7 @@ add_library(interface
InterfaceConnector.c
SessionManager.c
)
-target_link_libraries(interface util ${LIBEVENT2_LIBRARIES})
+target_link_libraries(interface util cjdns-crypto-key ${LIBEVENT2_LIBRARIES})
add_library(cjdns-interface-pipeinterface
PipeInterface.c
@@ -18,7 +18,7 @@
#include "interface/UDPInterface.h"
#include "memory/Allocator.h"
#include "net/InterfaceController.h"
-#include "util/Base32.h"
+#include "crypto/Key.h"
#include <errno.h>
#include <event2/event.h>
@@ -47,21 +47,15 @@ static void beginConnection(Dict* args, void* vcontext, String* txid)
String* error = NULL;
uint8_t pkBytes[32];
-
+ int ret;
if (ctx->ifCount == 0) {
error = String_CONST("no interfaces are setup, call UDPInterface_new() first");
} else if (interfaceNumber && (*interfaceNumber >= ctx->ifCount || *interfaceNumber < 0)) {
error = String_CONST("invalid interfaceNumber");
- } else if (!publicKey
- || publicKey->len < 52
- || (publicKey->len > 52 && publicKey->bytes[52] != '.'))
- {
- error = String_CONST("publicKey must be 52 characters long.");
-
- } else if (Base32_decode(pkBytes, 32, (uint8_t*)publicKey->bytes, 52) != 32) {
- error = String_CONST("failed to parse publicKey.");
+ } else if ((ret = Key_parse(publicKey, pkBytes, NULL))) {
+ error = String_CONST(Key_parse_strerror(ret));
} else {
struct UDPInterface* udpif = ctx->ifaces[ifNum];
@@ -79,7 +79,7 @@ int main(int argc, char** argv)
Dict_putString(dict, String_CONST("address"), String_CONST("127.0.0.1:12345"), fw->alloc);
res = AdminClient_rpcCall(
String_CONST("UDPInterface_beginConnection"), dict, fw->client, fw->alloc);
- Assert_always(!strcmp("d5:error37:publicKey must be 52 characters long.e",
+ Assert_always(!strcmp("d5:error30:key must be 52 characters longe",
(char*) res->messageBytes));
//printf("result content: >>%s<<", res->messageBytes);
Oops, something went wrong.

0 comments on commit c241af8

Please sign in to comment.