From 10133575b9c85b2652260c80d915969741d637bd Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 29 May 2015 10:52:18 +0930 Subject: [PATCH] leak-anchor-sigs: the horrible hack until we have normalized txs. Signed-off-by: Rusty Russell --- Makefile | 8 ++++-- leak-anchor-sigs.c | 37 ++++++++++++++++++++++++++ lightning.pb-c.c | 66 +++++++++++++++++++++++----------------------- lightning.pb-c.h | 42 ++++++++++++++--------------- lightning.proto | 4 +-- pkt.c | 10 +++++++ pkt.h | 9 +++++++ 7 files changed, 118 insertions(+), 58 deletions(-) create mode 100644 leak-anchor-sigs.c diff --git a/Makefile b/Makefile index a3d81d759..d107f4990 100644 --- a/Makefile +++ b/Makefile @@ -3,13 +3,14 @@ # Needs to have oneof support: Ubuntu vivid's is too old :( PROTOCC:=protoc-c -PROGRAMS := open-channel open-anchor-sig +PROGRAMS := open-channel open-anchor-sig leak-anchor-sigs HELPER_OBJS := base58.o lightning.pb-c.o shadouble.o pkt.o bitcoin_script.o perturb.o signature.o bitcoin_tx.o bitcoin_address.o CCAN_OBJS := ccan-crypto-sha256.o ccan-crypto-shachain.o ccan-err.o ccan-tal.o ccan-tal-str.o ccan-take.o ccan-list.o ccan-str.o ccan-opt-helpers.o ccan-opt.o ccan-opt-parse.o ccan-opt-usage.o ccan-read_write_all.o ccan-str-hex.o ccan-tal-grab_file.o ccan-noerr.o OPEN_CHANNEL_OBJS := open-channel.o OPEN_ANCHOR_SIG_OBJS := open-anchor-sig.o +LEAK_ANCHOR_SIGS_OBJS := leak-anchor-sigs.o HEADERS := $(wildcard *.h) @@ -28,12 +29,15 @@ $(OPEN_CHANNEL_OBJS): $(HEADERS) open-anchor-sig: $(OPEN_ANCHOR_SIG_OBJS) $(HELPER_OBJS) $(CCAN_OBJS) $(OPEN_ANCHOR_SIG_OBJS): $(HEADERS) +leak-anchor-sigs: $(LEAK_ANCHOR_SIGS_OBJS) $(HELPER_OBJS) $(CCAN_OBJS) +$(LEAK_ANCHOR_SIGS_OBJS): $(HEADERS) + distclean: clean $(RM) lightning.pb-c.c lightning.pb-c.h clean: $(RM) $(PROGRAMS) - $(RM) $(OPEN_CHANNEL_OBJS) $(OPEN_ANCHOR_SIG_OBJS) $(HELPER_OBJS) $(CCAN_OBJS) + $(RM) $(OPEN_CHANNEL_OBJS) $(OPEN_ANCHOR_SIG_OBJS) $(LEAK_ANCHOR_SIGS_OBJS) $(HELPER_OBJS) $(CCAN_OBJS) ccan-tal.o: $(CCANDIR)/ccan/tal/tal.c $(CC) $(CFLAGS) -c -o $@ $< diff --git a/leak-anchor-sigs.c b/leak-anchor-sigs.c new file mode 100644 index 000000000..3c77e0ce8 --- /dev/null +++ b/leak-anchor-sigs.c @@ -0,0 +1,37 @@ +/* Insecure hack to leak signatures early, to make up for non-normalized txs */ +#include +#include +#include +#include "lightning.pb-c.h" +#include "pkt.h" +#include + +int main(int argc, char *argv[]) +{ + const tal_t *ctx = tal_arr(NULL, char, 0); + OpenAnchorSig *s; + struct pkt *pkt; + + err_set_progname(argv[0]); + + opt_register_noarg("--help|-h", opt_usage_and_exit, + "\n" + "Create LeakAnchorSigsAndPretendWeDidnt to stdout", + "Print this message."); + + opt_parse(&argc, argv, opt_log_stderr_exit); + + if (argc != 2) + opt_usage_and_exit(NULL); + + s = pkt_from_file(argv[1], PKT__PKT_OPEN_ANCHOR_SIG)->open_anchor_sig; + + pkt = leak_anchor_sigs_and_pretend_we_didnt_pkt(ctx, s); + if (!write_all(STDOUT_FILENO, pkt, + sizeof(pkt->len) + le32_to_cpu(pkt->len))) + err(1, "Writing out packet"); + + tal_free(ctx); + return 0; +} + diff --git a/lightning.pb-c.c b/lightning.pb-c.c index cd3a91a39..ea177a553 100644 --- a/lightning.pb-c.c +++ b/lightning.pb-c.c @@ -394,47 +394,47 @@ void open_anchor_sig__free_unpacked assert(message->base.descriptor == &open_anchor_sig__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } -void give_early_anchor_sig_and_pretend_we_didnt__init - (GiveEarlyAnchorSigAndPretendWeDidnt *message) +void leak_anchor_sigs_and_pretend_we_didnt__init + (LeakAnchorSigsAndPretendWeDidnt *message) { - static GiveEarlyAnchorSigAndPretendWeDidnt init_value = GIVE_EARLY_ANCHOR_SIG_AND_PRETEND_WE_DIDNT__INIT; + static LeakAnchorSigsAndPretendWeDidnt init_value = LEAK_ANCHOR_SIGS_AND_PRETEND_WE_DIDNT__INIT; *message = init_value; } -size_t give_early_anchor_sig_and_pretend_we_didnt__get_packed_size - (const GiveEarlyAnchorSigAndPretendWeDidnt *message) +size_t leak_anchor_sigs_and_pretend_we_didnt__get_packed_size + (const LeakAnchorSigsAndPretendWeDidnt *message) { - assert(message->base.descriptor == &give_early_anchor_sig_and_pretend_we_didnt__descriptor); + assert(message->base.descriptor == &leak_anchor_sigs_and_pretend_we_didnt__descriptor); return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message)); } -size_t give_early_anchor_sig_and_pretend_we_didnt__pack - (const GiveEarlyAnchorSigAndPretendWeDidnt *message, +size_t leak_anchor_sigs_and_pretend_we_didnt__pack + (const LeakAnchorSigsAndPretendWeDidnt *message, uint8_t *out) { - assert(message->base.descriptor == &give_early_anchor_sig_and_pretend_we_didnt__descriptor); + assert(message->base.descriptor == &leak_anchor_sigs_and_pretend_we_didnt__descriptor); return protobuf_c_message_pack ((const ProtobufCMessage*)message, out); } -size_t give_early_anchor_sig_and_pretend_we_didnt__pack_to_buffer - (const GiveEarlyAnchorSigAndPretendWeDidnt *message, +size_t leak_anchor_sigs_and_pretend_we_didnt__pack_to_buffer + (const LeakAnchorSigsAndPretendWeDidnt *message, ProtobufCBuffer *buffer) { - assert(message->base.descriptor == &give_early_anchor_sig_and_pretend_we_didnt__descriptor); + assert(message->base.descriptor == &leak_anchor_sigs_and_pretend_we_didnt__descriptor); return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer); } -GiveEarlyAnchorSigAndPretendWeDidnt * - give_early_anchor_sig_and_pretend_we_didnt__unpack +LeakAnchorSigsAndPretendWeDidnt * + leak_anchor_sigs_and_pretend_we_didnt__unpack (ProtobufCAllocator *allocator, size_t len, const uint8_t *data) { - return (GiveEarlyAnchorSigAndPretendWeDidnt *) - protobuf_c_message_unpack (&give_early_anchor_sig_and_pretend_we_didnt__descriptor, + return (LeakAnchorSigsAndPretendWeDidnt *) + protobuf_c_message_unpack (&leak_anchor_sigs_and_pretend_we_didnt__descriptor, allocator, len, data); } -void give_early_anchor_sig_and_pretend_we_didnt__free_unpacked - (GiveEarlyAnchorSigAndPretendWeDidnt *message, +void leak_anchor_sigs_and_pretend_we_didnt__free_unpacked + (LeakAnchorSigsAndPretendWeDidnt *message, ProtobufCAllocator *allocator) { - assert(message->base.descriptor == &give_early_anchor_sig_and_pretend_we_didnt__descriptor); + assert(message->base.descriptor == &leak_anchor_sigs_and_pretend_we_didnt__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } void open_complete__init @@ -1588,7 +1588,7 @@ const ProtobufCMessageDescriptor open_anchor_sig__descriptor = (ProtobufCMessageInit) open_anchor_sig__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor give_early_anchor_sig_and_pretend_we_didnt__field_descriptors[1] = +static const ProtobufCFieldDescriptor leak_anchor_sigs_and_pretend_we_didnt__field_descriptors[1] = { { "anchor_scriptsigs", @@ -1596,34 +1596,34 @@ static const ProtobufCFieldDescriptor give_early_anchor_sig_and_pretend_we_didnt PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_MESSAGE, 0, /* quantifier_offset */ - offsetof(GiveEarlyAnchorSigAndPretendWeDidnt, anchor_scriptsigs), + offsetof(LeakAnchorSigsAndPretendWeDidnt, anchor_scriptsigs), &open_anchor_sig__descriptor, NULL, 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, }; -static const unsigned give_early_anchor_sig_and_pretend_we_didnt__field_indices_by_name[] = { +static const unsigned leak_anchor_sigs_and_pretend_we_didnt__field_indices_by_name[] = { 0, /* field[0] = anchor_scriptsigs */ }; -static const ProtobufCIntRange give_early_anchor_sig_and_pretend_we_didnt__number_ranges[1 + 1] = +static const ProtobufCIntRange leak_anchor_sigs_and_pretend_we_didnt__number_ranges[1 + 1] = { { 1, 0 }, { 0, 1 } }; -const ProtobufCMessageDescriptor give_early_anchor_sig_and_pretend_we_didnt__descriptor = +const ProtobufCMessageDescriptor leak_anchor_sigs_and_pretend_we_didnt__descriptor = { PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, - "give_early_anchor_sig_and_pretend_we_didnt", - "GiveEarlyAnchorSigAndPretendWeDidnt", - "GiveEarlyAnchorSigAndPretendWeDidnt", + "leak_anchor_sigs_and_pretend_we_didnt", + "LeakAnchorSigsAndPretendWeDidnt", + "LeakAnchorSigsAndPretendWeDidnt", "", - sizeof(GiveEarlyAnchorSigAndPretendWeDidnt), + sizeof(LeakAnchorSigsAndPretendWeDidnt), 1, - give_early_anchor_sig_and_pretend_we_didnt__field_descriptors, - give_early_anchor_sig_and_pretend_we_didnt__field_indices_by_name, - 1, give_early_anchor_sig_and_pretend_we_didnt__number_ranges, - (ProtobufCMessageInit) give_early_anchor_sig_and_pretend_we_didnt__init, + leak_anchor_sigs_and_pretend_we_didnt__field_descriptors, + leak_anchor_sigs_and_pretend_we_didnt__field_indices_by_name, + 1, leak_anchor_sigs_and_pretend_we_didnt__number_ranges, + (ProtobufCMessageInit) leak_anchor_sigs_and_pretend_we_didnt__init, NULL,NULL,NULL /* reserved[123] */ }; static const ProtobufCFieldDescriptor open_complete__field_descriptors[1] = @@ -2240,7 +2240,7 @@ static const ProtobufCFieldDescriptor pkt__field_descriptors[15] = PROTOBUF_C_TYPE_MESSAGE, offsetof(Pkt, pkt_case), offsetof(Pkt, omg_fail), - &give_early_anchor_sig_and_pretend_we_didnt__descriptor, + &leak_anchor_sigs_and_pretend_we_didnt__descriptor, NULL, 0 | PROTOBUF_C_FIELD_FLAG_ONEOF, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ diff --git a/lightning.pb-c.h b/lightning.pb-c.h index 011ed233e..b90b8bd92 100644 --- a/lightning.pb-c.h +++ b/lightning.pb-c.h @@ -24,7 +24,7 @@ typedef struct _Anchor Anchor; typedef struct _OpenChannel OpenChannel; typedef struct _OpenCommitSig OpenCommitSig; typedef struct _OpenAnchorSig OpenAnchorSig; -typedef struct _GiveEarlyAnchorSigAndPretendWeDidnt GiveEarlyAnchorSigAndPretendWeDidnt; +typedef struct _LeakAnchorSigsAndPretendWeDidnt LeakAnchorSigsAndPretendWeDidnt; typedef struct _OpenComplete OpenComplete; typedef struct _Update Update; typedef struct _UpdateAccept UpdateAccept; @@ -252,13 +252,13 @@ struct _OpenAnchorSig * malleability anyway). So for testing, we send the scriptsigs for the * anchor transaction's inputs immediately. */ -struct _GiveEarlyAnchorSigAndPretendWeDidnt +struct _LeakAnchorSigsAndPretendWeDidnt { ProtobufCMessage base; OpenAnchorSig *anchor_scriptsigs; }; -#define GIVE_EARLY_ANCHOR_SIG_AND_PRETEND_WE_DIDNT__INIT \ - { PROTOBUF_C_MESSAGE_INIT (&give_early_anchor_sig_and_pretend_we_didnt__descriptor) \ +#define LEAK_ANCHOR_SIGS_AND_PRETEND_WE_DIDNT__INIT \ + { PROTOBUF_C_MESSAGE_INIT (&leak_anchor_sigs_and_pretend_we_didnt__descriptor) \ , NULL } @@ -500,7 +500,7 @@ struct _Pkt * Opening */ OpenChannel *open; - GiveEarlyAnchorSigAndPretendWeDidnt *omg_fail; + LeakAnchorSigsAndPretendWeDidnt *omg_fail; OpenCommitSig *open_commit_sig; OpenAnchorSig *open_anchor_sig; OpenComplete *open_complete; @@ -704,24 +704,24 @@ OpenAnchorSig * void open_anchor_sig__free_unpacked (OpenAnchorSig *message, ProtobufCAllocator *allocator); -/* GiveEarlyAnchorSigAndPretendWeDidnt methods */ -void give_early_anchor_sig_and_pretend_we_didnt__init - (GiveEarlyAnchorSigAndPretendWeDidnt *message); -size_t give_early_anchor_sig_and_pretend_we_didnt__get_packed_size - (const GiveEarlyAnchorSigAndPretendWeDidnt *message); -size_t give_early_anchor_sig_and_pretend_we_didnt__pack - (const GiveEarlyAnchorSigAndPretendWeDidnt *message, +/* LeakAnchorSigsAndPretendWeDidnt methods */ +void leak_anchor_sigs_and_pretend_we_didnt__init + (LeakAnchorSigsAndPretendWeDidnt *message); +size_t leak_anchor_sigs_and_pretend_we_didnt__get_packed_size + (const LeakAnchorSigsAndPretendWeDidnt *message); +size_t leak_anchor_sigs_and_pretend_we_didnt__pack + (const LeakAnchorSigsAndPretendWeDidnt *message, uint8_t *out); -size_t give_early_anchor_sig_and_pretend_we_didnt__pack_to_buffer - (const GiveEarlyAnchorSigAndPretendWeDidnt *message, +size_t leak_anchor_sigs_and_pretend_we_didnt__pack_to_buffer + (const LeakAnchorSigsAndPretendWeDidnt *message, ProtobufCBuffer *buffer); -GiveEarlyAnchorSigAndPretendWeDidnt * - give_early_anchor_sig_and_pretend_we_didnt__unpack +LeakAnchorSigsAndPretendWeDidnt * + leak_anchor_sigs_and_pretend_we_didnt__unpack (ProtobufCAllocator *allocator, size_t len, const uint8_t *data); -void give_early_anchor_sig_and_pretend_we_didnt__free_unpacked - (GiveEarlyAnchorSigAndPretendWeDidnt *message, +void leak_anchor_sigs_and_pretend_we_didnt__free_unpacked + (LeakAnchorSigsAndPretendWeDidnt *message, ProtobufCAllocator *allocator); /* OpenComplete methods */ void open_complete__init @@ -999,8 +999,8 @@ typedef void (*OpenCommitSig_Closure) typedef void (*OpenAnchorSig_Closure) (const OpenAnchorSig *message, void *closure_data); -typedef void (*GiveEarlyAnchorSigAndPretendWeDidnt_Closure) - (const GiveEarlyAnchorSigAndPretendWeDidnt *message, +typedef void (*LeakAnchorSigsAndPretendWeDidnt_Closure) + (const LeakAnchorSigsAndPretendWeDidnt *message, void *closure_data); typedef void (*OpenComplete_Closure) (const OpenComplete *message, @@ -1056,7 +1056,7 @@ extern const ProtobufCMessageDescriptor anchor__descriptor; extern const ProtobufCMessageDescriptor open_channel__descriptor; extern const ProtobufCMessageDescriptor open_commit_sig__descriptor; extern const ProtobufCMessageDescriptor open_anchor_sig__descriptor; -extern const ProtobufCMessageDescriptor give_early_anchor_sig_and_pretend_we_didnt__descriptor; +extern const ProtobufCMessageDescriptor leak_anchor_sigs_and_pretend_we_didnt__descriptor; extern const ProtobufCMessageDescriptor open_complete__descriptor; extern const ProtobufCMessageDescriptor update__descriptor; extern const ProtobufCMessageDescriptor update_accept__descriptor; diff --git a/lightning.proto b/lightning.proto index 31e865fdf..6b1c77102 100644 --- a/lightning.proto +++ b/lightning.proto @@ -101,7 +101,7 @@ message open_anchor_sig { // txid until it's signed by both sides, and then we'd have to worry about // malleability anyway). So for testing, we send the scriptsigs for the // anchor transaction's inputs immediately. -message give_early_anchor_sig_and_pretend_we_didnt { +message leak_anchor_sigs_and_pretend_we_didnt { required open_anchor_sig anchor_scriptsigs = 1; } @@ -192,7 +192,7 @@ message pkt { oneof pkt { // Opening open_channel open = 201; - give_early_anchor_sig_and_pretend_we_didnt omg_fail = 205; + leak_anchor_sigs_and_pretend_we_didnt omg_fail = 205; open_commit_sig open_commit_sig = 202; open_anchor_sig open_anchor_sig = 203; open_complete open_complete = 204; diff --git a/pkt.c b/pkt.c index a0f5e0b08..121018e76 100644 --- a/pkt.c +++ b/pkt.c @@ -131,3 +131,13 @@ struct pkt *open_anchor_sig_pkt(const tal_t *ctx, u8 **sigs, size_t num_sigs) return to_pkt(ctx, PKT__PKT_OPEN_ANCHOR_SIG, &o); } + +struct pkt *leak_anchor_sigs_and_pretend_we_didnt_pkt(const tal_t *ctx, + OpenAnchorSig *s) +{ + LeakAnchorSigsAndPretendWeDidnt omg_fail + = LEAK_ANCHOR_SIGS_AND_PRETEND_WE_DIDNT__INIT; + + omg_fail.anchor_scriptsigs = s; + return to_pkt(ctx, PKT__PKT_OMG_FAIL, &omg_fail); +} diff --git a/pkt.h b/pkt.h index 3e91397ee..833a71932 100644 --- a/pkt.h +++ b/pkt.h @@ -49,6 +49,15 @@ struct pkt *openchannel_pkt(const tal_t *ctx, */ struct pkt *open_anchor_sig_pkt(const tal_t *ctx, u8 **sigs, size_t num_sigs); +/** + * leak_anchor_sigs_and_pretend_we_didnt_pkt - leak anchor scriptsigs + * @ctx: tal context to allocate off. + * @s: OpenAnchorSig. + */ +struct pkt *leak_anchor_sigs_and_pretend_we_didnt_pkt(const tal_t *ctx, + OpenAnchorSig *s); + + /* Useful helper for allocating & populating a protobuf Sha256Hash */ Sha256Hash *sha256_to_proto(const tal_t *ctx, const struct sha256 *hash); void proto_to_sha256(const Sha256Hash *pb, struct sha256 *hash);