Browse Source

handshaked: remove.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
ebba5f85a2
  1. 1
      Makefile
  2. 2
      doc/HACKING.md
  3. 71
      handshaked/Makefile
  4. 1075
      handshaked/handshake.c
  5. 31
      handshaked/handshake_wire.csv
  6. 1
      handshaked/test/.gitignore
  7. 30
      handshaked/test/Makefile
  8. 163
      handshaked/test/run-handshake.c
  9. 1
      lightningd/.gitignore
  10. 1
      lightningd/lightningd.c

1
Makefile

@ -144,7 +144,6 @@ include common/Makefile
include wire/Makefile
include wallet/Makefile
include hsmd/Makefile
include handshaked/Makefile
include gossipd/Makefile
include openingd/Makefile
include channeld/Makefile

2
doc/HACKING.md

@ -61,8 +61,6 @@ Here's a list of parts, with notes:
* hsmd/ - daemon which looks after the cryptographic secret, and performs commitment signing.
* handshaked/ - daemon to establish a single cryptographic handshake a-la BOLT 8.
* gossipd/ - daemon to chat to peers which don't have any channels, and maintains routing information and broadcasts gossip.
* openingd/ - daemon to open a channel for a single peer.

71
handshaked/Makefile

@ -1,71 +0,0 @@
#! /usr/bin/make
# Designed to be run one level up
handshaked-wrongdir:
$(MAKE) -C .. handshaked-all
default: handshaked-all
handshaked-all: lightningd/lightning_handshaked
# handshaked needs these:
LIGHTNINGD_HANDSHAKE_HEADERS := \
handshaked/gen_handshake_wire.h
LIGHTNINGD_HANDSHAKE_SRC := handshaked/handshake.c \
$(LIGHTNINGD_HANDSHAKE_HEADERS:.h=.c)
LIGHTNINGD_HANDSHAKE_OBJS := $(LIGHTNINGD_HANDSHAKE_SRC:.c=.o)
# Make sure these depend on everything.
ALL_OBJS += $(LIGHTNINGD_HANDSHAKE_OBJS)
ALL_PROGRAMS += lightningd/lightning_handshaked
ALL_GEN_HEADERS += $(LIGHTNINGD_HANDSHAKE_HEADERS)
# Control daemon uses this:
LIGHTNINGD_HANDSHAKE_CONTROL_HEADERS := $(LIGHTNINGD_HANDSHAKE_HEADERS)
LIGHTNINGD_HANDSHAKE_CONTROL_SRC := $(LIGHTNINGD_HANDSHAKE_HEADERS:.h=.c)
LIGHTNINGD_HANDSHAKE_CONTROL_OBJS := $(LIGHTNINGD_HANDSHAKE_CONTROL_SRC:.c=.o)
LIGHTNINGD_HANDSHAKE_GEN_SRC := $(filter handshaked/gen_%, $(LIGHTNINGD_HANDSHAKE_SRC) $(LIGHTNINGD_HANDSHAKE_CONTROL_SRC))
LIGHTNINGD_HANDSHAKE_SRC_NOGEN := $(filter-out handshaked/gen_%, $(LIGHTNINGD_HANDSHAKE_SRC))
# Add to headers which any object might need.
LIGHTNINGD_HEADERS_GEN += $(LIGHTNINGD_HANDSHAKE_HEADERS)
$(LIGHTNINGD_HANDSHAKE_OBJS): $(LIGHTNINGD_HEADERS)
# Common source we use.
HANDSHAKED_COMMON_OBJS := \
common/crypto_state.o \
common/crypto_sync.o \
common/cryptomsg.o \
common/daemon_conn.o \
common/debug.o \
common/dev_disconnect.o \
common/msg_queue.o \
common/status.o \
common/type_to_string.o \
common/utils.o \
common/version.o
handshaked/gen_handshake_wire.h: $(WIRE_GEN) handshaked/handshake_wire.csv
$(WIRE_GEN) --header $@ handshake_wire_type < handshaked/handshake_wire.csv > $@
handshaked/gen_handshake_wire.c: $(WIRE_GEN) handshaked/handshake_wire.csv
$(WIRE_GEN) ${@:.c=.h} handshake_wire_type < handshaked/handshake_wire.csv > $@
LIGHTNINGD_HANDSHAKE_OBJS := $(LIGHTNINGD_HANDSHAKE_SRC:.c=.o) $(LIGHTNINGD_HANDSHAKE_GEN_SRC:.c=.o)
lightningd/lightning_handshaked: $(LIGHTNINGD_LIB_OBJS) $(LIGHTNINGD_HANDSHAKE_OBJS) $(HANDSHAKED_COMMON_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(LIGHTNINGD_HSM_CLIENT_OBJS)
check-source: $(LIGHTNINGD_HANDSHAKE_SRC_NOGEN:%=check-src-include-order/%)
check-source-bolt: $(LIGHTNINGD_HANDSHAKE_SRC:%=bolt-check/%) $(LIGHTNINGD_HANDSHAKE_HEADERS:%=bolt-check/%)
check-whitespace: $(LIGHTNINGD_HANDSHAKE_SRC_NOGEN:%=check-whitespace/%) $(LIGHTNINGD_HANDSHAKE_HEADERS_NOGEN:%=check-whitespace/%)
clean: handshaked-clean
handshaked-clean:
$(RM) $(LIGHTNINGD_HANDSHAKE_OBJS) gen_*
-include handshaked/test/Makefile

1075
handshaked/handshake.c

File diff suppressed because it is too large

31
handshaked/handshake_wire.csv

@ -1,31 +0,0 @@
#include <common/cryptomsg.h>
# FIXME: This is probably too finegrained.
initr_act_one,14001
initr_act_two,14002
initr_act_three,14003
respr_act_one,14011
respr_act_two,14012
respr_act_three,14013
success,4000
handshake_responder,4001
handshake_responder,,my_id,struct pubkey
handshake_responder_reply,4101
handshake_responder_reply,,initiator_id,struct pubkey
handshake_responder_reply,,cs,struct crypto_state
handshake_responder_reply,,gflen,u16
handshake_responder_reply,,globalfeatures,gflen*u8
handshake_responder_reply,,lflen,u16
handshake_responder_reply,,localfeatures,lflen*u8
handshake_initiator,4002
handshake_initiator,,my_id,struct pubkey
handshake_initiator,,responder_id,struct pubkey
handshake_initiator_reply,4102
handshake_initiator_reply,,cs,struct crypto_state
handshake_initiator_reply,,gflen,u16
handshake_initiator_reply,,globalfeatures,gflen*u8
handshake_initiator_reply,,lflen,u16
handshake_initiator_reply,,localfeatures,lflen*u8
Can't render this file because it has a wrong number of fields in line 4.

1
handshaked/test/.gitignore

@ -1 +0,0 @@
run-handshake

30
handshaked/test/Makefile

@ -1,30 +0,0 @@
check: lightningd/handshake-tests
# Note that these actually #include everything they need, except ccan/ and bitcoin/.
# That allows for unit testing of statics, and special effects.
LIGHTNINGD_HANDSHAKE_TEST_SRC := $(wildcard lightningd/handshake/test/run-*.c)
LIGHTNINGD_HANDSHAKE_TEST_OBJS := $(LIGHTNINGD_HANDSHAKE_TEST_SRC:.c=.o)
LIGHTNINGD_HANDSHAKE_TEST_PROGRAMS := $(LIGHTNINGD_HANDSHAKE_TEST_OBJS:.o=)
LIGHTNINGD_HANDSHAKE_TEST_COMMON_OBJS := \
common/cryptomsg.o \
common/daemon_conn.o \
common/dev_disconnect.o \
common/htlc_state.o \
common/msg_queue.o \
common/pseudorand.o \
common/status.o \
common/type_to_string.o \
common/utils.o
update-mocks: $(LIGHTNINGD_HANDSHAKE_TEST_SRC:%=update-mocks/%)
$(LIGHTNINGD_HANDSHAKE_TEST_PROGRAMS): $(LIGHTNINGD_HANDSHAKE_TEST_COMMON_OBJS) $(LIGHTNINGD_HANDSHAKE_GEN_SRC:.c=.o) $(BITCOIN_OBJS) $(WIRE_OBJS)
$(LIGHTNINGD_HANDSHAKE_TEST_OBJS): $(LIGHTNINGD_HANDSHAKE_HEADERS)
ALL_OBJS += $(LIGHTNINGD_HANDSHAKE_TEST_OBJS)
ALL_TEST_PROGRAMS += $(LIGHTNINGD_HANDSHAKE_TEST_PROGRAMS)
lightningd/handshake-tests: $(LIGHTNINGD_HANDSHAKE_TEST_PROGRAMS:%=unittest/%)

163
handshaked/test/run-handshake.c

@ -1,163 +0,0 @@
#include <assert.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <unistd.h>
#include <ccan/err/err.h>
#include <ccan/read_write_all/read_write_all.h>
#include <ccan/structeq/structeq.h>
#include <common/status.h>
/* Since we use pipes, we need different fds for read and write. */
static int read_fd, write_fd;
static bool fake_read_all(int fd, void *buf, size_t count)
{
return read_all(read_fd, buf, count);
}
static ssize_t fake_write_all(int fd, const void *buf, size_t count)
{
return write_all(write_fd, buf, count);
}
static const char *status_prefix;
/* Simply print out status updates. */
#define status_send_sync(msg) \
printf("%s:# Act %s\n", status_prefix, \
fromwire_peektype(msg) == WIRE_INITR_ACT_ONE ? "One" \
: fromwire_peektype(msg) == WIRE_INITR_ACT_TWO ? "Two" \
: fromwire_peektype(msg) == WIRE_INITR_ACT_THREE ? "Three" \
: fromwire_peektype(msg) == WIRE_RESPR_ACT_ONE ? "One" \
: fromwire_peektype(msg) == WIRE_RESPR_ACT_TWO ? "Two" \
: fromwire_peektype(msg) == WIRE_RESPR_ACT_THREE ? "Three" \
: "UNKNOWN")
#define status_failed(code, fmt, ...) \
errx(1, "%s:%s:" fmt "\n", status_prefix, #code, __VA_ARGS__)
#define status_trace(fmt, ...) \
printf("%s:" fmt "\n", status_prefix, __VA_ARGS__)
#define read_all fake_read_all
#define write_all fake_write_all
/* No randomness please, we want to replicate test vectors. */
#include <sodium/randombytes.h>
static unsigned char e_priv[32];
#define randombytes_buf(secret, len) memcpy((secret), e_priv, len)
#define TESTING
#include "../handshake.c"
#include <common/utils.h>
#include <ccan/err/err.h>
secp256k1_context *secp256k1_ctx;
const void *trc;
static struct privkey privkey;
void hsm_setup(int fd)
{
}
bool hsm_do_ecdh(struct secret *ss, const struct pubkey *point)
{
return secp256k1_ecdh(secp256k1_ctx, ss->data, &point->pubkey,
privkey.secret.data) == 1;
}
int main(void)
{
int fds1[2], fds2[2];
struct pubkey responder_id;
struct privkey responder_privkey;
struct secret ck, sk, rk;
const tal_t *ctx = tal_tmpctx(NULL);
trc = tal_tmpctx(ctx);
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
memset(responder_privkey.secret.data, 0x21,
sizeof(responder_privkey.secret.data));
if (!secp256k1_ec_pubkey_create(secp256k1_ctx,
&responder_id.pubkey,
responder_privkey.secret.data))
errx(1, "Keygen failed");
if (pipe(fds1) != 0 || pipe(fds2) != 0)
err(1, "Making pipes");
switch (fork()) {
case -1:
err(1, "fork failed");
case 0: {
struct pubkey their_id;
memset(e_priv, 0x22, sizeof(e_priv));
read_fd = fds1[0];
write_fd = fds2[1];
close(fds1[1]);
close(fds2[0]);
privkey = responder_privkey;
status_prefix = "RESPR";
status_trace("ls.priv: 0x%s",
tal_hexstr(trc, &responder_privkey,
sizeof(responder_privkey)));
status_trace("ls.pub: 0x%s",
type_to_string(trc, struct pubkey, &responder_id));
responder(-1, &responder_id, &their_id, &ck, &sk, &rk);
if (!write_all(write_fd, &ck, sizeof(ck))
|| !write_all(write_fd, &sk, sizeof(sk))
|| !write_all(write_fd, &rk, sizeof(rk)))
err(1, "writing out secrets failed");
goto out;
}
default: {
struct pubkey initiator_id;
struct privkey initiator_privkey;
struct secret their_ck, their_sk, their_rk;
read_fd = fds2[0];
write_fd = fds1[1];
close(fds2[1]);
close(fds1[0]);
memset(initiator_privkey.secret.data, 0x11,
sizeof(initiator_privkey.secret.data));
memset(e_priv, 0x12, sizeof(e_priv));
if (!secp256k1_ec_pubkey_create(secp256k1_ctx,
&initiator_id.pubkey,
initiator_privkey.secret.data))
errx(1, "Initiator keygen failed");
privkey = initiator_privkey;
status_prefix = "INITR";
status_trace("rs.pub: 0x%s",
type_to_string(trc, struct pubkey, &responder_id));
status_trace("ls.priv: 0x%s",
tal_hexstr(trc, &initiator_privkey,
sizeof(initiator_privkey)));
status_trace("ls.pub: 0x%s",
type_to_string(trc, struct pubkey, &initiator_id));
initiator(-1, &initiator_id, &responder_id, &ck, &sk, &rk);
if (!read_all(read_fd, &their_ck, sizeof(their_ck))
|| !read_all(read_fd, &their_sk, sizeof(their_sk))
|| !read_all(read_fd, &their_rk, sizeof(their_rk)))
err(1, "reading their secrets failed");
assert(structeq(&ck, &their_ck));
assert(structeq(&sk, &their_rk));
assert(structeq(&rk, &their_sk));
goto out;
}
}
out:
/* No memory leaks please */
secp256k1_context_destroy(secp256k1_ctx);
tal_free(ctx);
return 0;
}

1
lightningd/.gitignore

@ -2,7 +2,6 @@ lightningd
lightning_channeld
lightning_connectd
lightning_gossipd
lightning_handshaked
lightning_hsmd
lightning_openingd
lightning_closingd

1
lightningd/lightningd.c

@ -94,7 +94,6 @@ static const char *daemons[] = {
"lightning_channeld",
"lightning_closingd",
"lightning_gossipd",
"lightning_handshaked",
"lightning_hsmd",
"lightning_onchaind",
"lightning_openingd"

Loading…
Cancel
Save