Browse Source

lightningd/handshake: simple daemon to do BOLT 8 crypto handshake.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
32e1b5bb06
  1. 3
      lightningd/Makefile
  2. 57
      lightningd/handshake/Makefile
  3. 1025
      lightningd/handshake/handshake.c
  4. 12
      lightningd/handshake/handshake_control_wire_csv
  5. 31
      lightningd/handshake/handshake_status_wire_csv
  6. 3
      lightningd/lightningd.c

3
lightningd/Makefile

@ -4,7 +4,7 @@
lightningd-wrongdir:
$(MAKE) -C .. lightningd-all
lightningd-all: lightningd/lightningd lightningd/lightningd_hsm
lightningd-all: lightningd/lightningd lightningd/lightningd_hsm lightningd/lightningd_handshake
default: lightningd-all
@ -46,6 +46,7 @@ LIGHTNINGD_HEADERS := \
$(LIGHTNINGD_OBJS) $(LIGHTNINGD_LIB_OBJS): $(LIGHTNINGD_HEADERS) $(LIGHTNINGD_JSMN_HEADERS) $(BITCOIN_HEADERS) $(CORE_HEADERS) $(GEN_HEADERS) $(CCAN_HEADERS) $(DAEMON_HEADERS) $(LIGHTNINGD_HSM_CONTROL_HEADERS) $(LIBBASE58_HEADERS)
include lightningd/hsm/Makefile
include lightningd/handshake/Makefile
check-source: $(LIGHTNINGD_SRC:%=check-src-include-order/%)
check-source: $(LIGHTNINGD_LIB_SRC:%=check-src-include-order/%)

57
lightningd/handshake/Makefile

@ -0,0 +1,57 @@
#! /usr/bin/make
# Designed to be run one level up
lightningd/handshake-wrongdir:
$(MAKE) -C .. lightningd/handshake-all
default: lightningd/handshake-all
lightningd/handshake-all: lightningd/lightningd_handshake
# lightningd/handshake needs these:
LIGHTNINGD_HANDSHAKE_HEADERS := \
lightningd/handshake/gen_handshake_control_wire.h \
lightningd/handshake/gen_handshake_status_wire.h
LIGHTNINGD_HANDSHAKE_SRC := lightningd/handshake/handshake.c \
$(LIGHTNINGD_HANDSHAKE_HEADERS:.h=.c)
LIGHTNINGD_HANDSHAKE_OBJS := $(LIGHTNINGD_HANDSHAKE_SRC:.c=.o)
# 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 lightningd/handshake/gen_%, $(LIGHTNINGD_HANDSHAKE_SRC) $(LIGHTNINGD_HANDSHAKE_CONTROL_SRC))
LIGHTNINGD_HANDSHAKE_SRC_NOGEN := $(filter-out lightningd/handshake/gen_%, $(LIGHTNINGD_HANDSHAKE_SRC))
$(LIGHTNINGD_HANDSHAKE_OBJS): $(CCAN_HEADERS) $(CORE_HEADERS) $(GEN_HEADERS) $(WIRE_HEADERS) $(BITCOIN_HEADERS) $(LIGHTNINGD_HANDSHAKE_HEADERS) $(LIGHTNINGD_HSM_CLIENT_HEADERS) $(LIBBASE58_HEADERS)
lightningd/handshake/gen_handshake_control_wire.h: $(WIRE_GEN) lightningd/handshake/handshake_control_wire_csv
$(WIRE_GEN) --header $@ handshake_control_wire_type < lightningd/handshake/handshake_control_wire_csv > $@
lightningd/handshake/gen_handshake_control_wire.c: $(WIRE_GEN) lightningd/handshake/handshake_control_wire_csv
$(WIRE_GEN) ${@:.c=.h} handshake_control_wire_type < lightningd/handshake/handshake_control_wire_csv > $@
lightningd/handshake/gen_handshake_status_wire.h: $(WIRE_GEN) lightningd/handshake/handshake_status_wire_csv
$(WIRE_GEN) --header $@ handshake_status_wire_type < lightningd/handshake/handshake_status_wire_csv > $@
lightningd/handshake/gen_handshake_status_wire.c: $(WIRE_GEN) lightningd/handshake/handshake_status_wire_csv
$(WIRE_GEN) ${@:.c=.h} handshake_status_wire_type < lightningd/handshake/handshake_status_wire_csv > $@
LIGHTNINGD_HANDSHAKE_OBJS := $(LIGHTNINGD_HANDSHAKE_SRC:.c=.o) $(LIGHTNINGD_HANDSHAKE_GEN_SRC:.c=.o)
lightningd/lightningd_handshake: $(LIGHTNINGD_LIB_OBJS) $(LIGHTNINGD_HANDSHAKE_OBJS) $(CORE_OBJS) $(WIRE_OBJS) $(BITCOIN_OBJS) $(CCAN_OBJS) $(LIGHTNINGD_HSM_CLIENT_OBJS) $(LIBBASE58_OBJS) libsecp256k1.a
$(CC) $(CFLAGS) -o $@ $^ $(LDLIBS)
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: lightningd/handshake-clean
lightningd/handshake-clean:
$(RM) $(LIGHTNINGD_HANDSHAKE_OBJS) gen_*
-include lightningd/handshake/test/Makefile

1025
lightningd/handshake/handshake.c

File diff suppressed because it is too large

12
lightningd/handshake/handshake_control_wire_csv

@ -0,0 +1,12 @@
#include <lightningd/cryptomsg.h>
handshake_responder_req,0
handshake_responder_req,0,my_id,33
handshake_responder_resp,1
handshake_responder_resp,0,initiator_id,33
handshake_responder_resp,33,cs,144,struct crypto_state
handshake_initiator_req,2
handshake_initiator_req,0,my_id,33
handshake_initiator_req,33,responder_id,33
handshake_initiator_resp,3
handshake_initiator_resp,0,cs,144,struct crypto_state
handshake_exit_req,4

31
lightningd/handshake/handshake_status_wire_csv

@ -0,0 +1,31 @@
bad_command,0x8000
bad_fdpass,0x8001
initr_act1_bad_ecdh_for_ss,0x8011
initr_act1_write_failed,0x8012
initr_act2_read_failed,0x8013
initr_act2_bad_version,0x8014
initr_act2_bad_pubkey,0x8015
initr_act2_bad_ecdh_for_ss,0x8016
initr_act2_bad_tag,0x8017
initr_act3_bad_hsm_ecdh,0x8018
initr_act3_write_failed,0x8019
respr_act1_read_failed,0x801A
respr_act1_bad_version,0x801B
respr_act1_bad_pubkey,0x801C
respr_act1_bad_hsm_ecdh,0x801D
respr_act1_bad_tag,0x801E
respr_act2_bad_ecdh_for_ss,0x801F
respr_act2_write_failed,0x8020
respr_act3_read_failed,0x8021
respr_act3_bad_version,0x8022
respr_act3_bad_ciphertext,0x8023
respr_act3_bad_pubkey,0x8024
respr_act3_bad_ecdh_for_ss,0x8025
respr_act3_bad_tag,0x8026
initr_act_one,1
initr_act_two,2
initr_act_three,3
respr_act_one,4
respr_act_two,5
respr_act_three,6
success,0

3
lightningd/lightningd.c

@ -96,7 +96,8 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
static const char *daemons[] = {
"lightningd",
"lightningd_hsm"
"lightningd_hsm",
"lightningd_handshake"
};
/* Check we can run them, and check their versions */

Loading…
Cancel
Save