Commit Graph

207 Commits

Author SHA1 Message Date
Christian Decker 323b1a558b libhsmd: Add missing implementation of status functions 2021-05-15 09:31:12 +09:30
Christian Decker 96acafcef3 libhsmd: Prefix check_client_capabilities
I wante to hide it inside the library, but it is good to have a single
place to verify that the client was permitted to send a message we are
handling, so make it officially part of the interface by prefixing it.
2021-05-04 11:18:52 +09:30
Christian Decker fb2b107bef libhsmd: Cleanup the bip32_key_version 2021-05-04 11:18:52 +09:30
Christian Decker 4d43e84afd libhsmd: Finalize encapsulation of hsmd data in libhsmd
Changelog-Added: libhsmd: Extracted the `hsmd` logic into its own library for other projects to use
2021-05-04 11:18:52 +09:30
Christian Decker c9e9581b35 libhsmd: Migrate bolt12 initialization into hsmd_init 2021-05-04 11:18:52 +09:30
Christian Decker d30392c432 libhsmd: Start migrating initialization to hsmd_init 2021-05-04 11:18:52 +09:30
Christian Decker befa7fb9f0 libhsmd: Clean up includes in hsmd.c 2021-05-04 11:18:52 +09:30
Christian Decker 1efa792edc libhsmd: Migrate handle_sign_delayer_payment_to_us 2021-05-04 11:18:52 +09:30
Christian Decker fe82181fe3 libhsmd: Migrate handle_sign_remote_htlc_to_us 2021-05-04 11:18:52 +09:30
Christian Decker e643594104 libhsmd: handle_sign_commitment_tx 2021-05-04 11:18:52 +09:30
Christian Decker 4764ebd879 libhsmd: Migrate handle_sign_penalty_to_us 2021-05-04 11:18:52 +09:30
Christian Decker bee7a65170 libhsmd: Migrate handle_sign_remote_commitment_tx 2021-05-04 11:18:52 +09:30
Christian Decker c2d035d377 libhsmd: Migrate handle_sign_remote_htlc_tx 2021-05-04 11:18:52 +09:30
Christian Decker 7b2c6ec4d3 libhsmd: Migrate handle_sign_local_htlc_tx 2021-05-04 11:18:52 +09:30
Christian Decker cd8fb641cf libhsmd: Migrate handle_sign_mutual_tx 2021-05-04 11:18:52 +09:30
Christian Decker 9aa4b5198d libhsmd: Migrate handle_sign_withdrawal_tx 2021-05-04 11:18:52 +09:30
Christian Decker e7007a7f36 libhsmd: Migrate handle_get_per_commitment_point 2021-05-04 11:18:52 +09:30
Christian Decker eab4aeaed3 libhsmd: Migrate handle_channel_update_sig 2021-05-04 11:18:52 +09:30
Christian Decker 166f0ade04 libhsmd: Migrate handle_sign_node_announcement 2021-05-04 11:18:52 +09:30
Christian Decker 4a3f24a737 libhsmd: Migrate handle_cannouncement_sig 2021-05-04 11:18:52 +09:30
Christian Decker e9cc8644b6 libhsmd: Migrate handle_get_output_scriptpubkey 2021-05-04 11:18:52 +09:30
Christian Decker ec5d40c0e7 libhsmd: Migrate handle_check_future_secret 2021-05-04 11:18:52 +09:30
Christian Decker 0e61ed32e3 libhsmd: Migrate handle_ecdh 2021-05-04 11:18:52 +09:30
Christian Decker d1b3a5b1aa libhsmd: Migrate handle_get_channel_basepoints 2021-05-04 11:18:52 +09:30
Christian Decker 2cb25a16e0 libhsmd: Migrate handle_sign_invoice 2021-05-04 11:18:52 +09:30
Christian Decker 79ec4b4808 libhsmd: Migrate handle_sign_bolt12 2021-05-04 11:18:52 +09:30
Christian Decker 3d959e128d libhsmd: Add dispatcher function 2021-05-04 11:18:52 +09:30
Christian Decker ac836bbd1b libhsmd: Add status functions to report to whoever is listening
These are currently just shims that replicate the old behavior, but
when compiling as a library we can relink the status_* functions to
something that makes sense in the context of the user, and not assume
we're running as a subdaemon.
2021-05-04 11:18:52 +09:30
Christian Decker b5a2ddd384 libhsmd: Migrate check_client_capabilities to libhsmd 2021-05-04 11:18:52 +09:30
Christian Decker ed4676bea8 libhsmd: Add scaffolding to start separating hsmd from io logic 2021-05-04 11:18:52 +09:30
Rusty Russell 9dbac21d3b doc: remove suffix for included-in-master BOLTs.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-04-07 14:34:39 +09:30
Christian Decker 65bf347ad3 hsmd: Ensure the hsmd is initialized before anything else is called
Just a security measure to avoid alternative use-cases of the hsmd
running into the issue that they need to send a `WIRE_HSMD_INIT`
message as first message. If that is not done, the `secretstuff` won't
get initialized and we'd be producing signatures from uninitialized
memory, which are completely useless.

Changelog-None: Internal change only
2021-03-09 14:40:02 +10:30
Rusty Russell 001b5d6416 offers: make it a runtime option.
The fetchinvoice and offers plugins disable themselves if the option
isn't enabled (it's enabled by default on EXPERIMENTAL_FEATURES).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: `experimental-offers` enables fetch, payment and creation of (early draft) offers.
2021-01-13 14:45:36 +01:00
Rusty Russell 6dab04ebd5 tools/generate-wire.py: include digits in #ifndef idempotent header.
Otherwise check complains that it's '#ifndef LIGHTNING_WIRE_BOLT_WIREGEN_H':

wire/bolt12_wiregen.h seems to be missing the expected include guard:
  #ifndef LIGHTNING_WIRE_BOLT12_WIREGEN_H
  #define LIGHTNING_WIRE_BOLT12_WIREGEN_H
  ...
  #endif /* LIGHTNING_WIRE_BOLT12_WIREGEN_H */

make: *** [Makefile:458: check-includes] Error 1

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2021-01-13 14:45:36 +01:00
Antoine Poinsot 45bb1bfa3c hsmd: cleanup encrypted hsm_secret detection
This makes use of the constant defined in the previous commits to more
accurately detect plaintext, encrypted, and invalid seeds. We now error
on invalid seeds.

Changelog-changed: hsmd: we now error at startup on invalid hsm_secret
Changelog-changed: hsmtool: all commands now error on invalid hsm_secret
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-01-06 13:50:01 +01:00
Antoine Poinsot d2a903992c hsmd: regroup hsm_secret decryption logic
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-01-06 13:50:01 +01:00
Antoine Poinsot c6bc22b0f5 hsmd: group hsm_secret encryption
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-01-06 13:50:01 +01:00
Antoine Poinsot 917f78a4f8 lightningd: group hsm_secret encryption key derivation
This avoids duplication of both logic and error-prone values, such as
the salt. Grouping all hsm encryption logic into a public API will also
allow us to fuzz it.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-01-06 13:50:01 +01:00
Rusty Russell 59efd160c1 hsmd: code to sign bolt12 messages with a tweaked key.
Invoices are signed with our own key, but we use a transient payer_key with a
tweak for invoice_requests (and refunds).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-23 14:24:39 +01:00
Rusty Russell 86176e8d0a hsmd: code to sign a bolt12 merkle root.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-09 16:40:13 +10:30
Rusty Russell a11edebb7c utf8: handle UTF-8 arrays.
BOLT 12 introduces this as a new fundamental type, which lets us easily
validate them.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-09 16:40:13 +10:30
Rusty Russell ff8830876d wire/tlvstream: add tlv_make_fields helper to populate ->fields array.
This is vital for calculating merkle trees; I previously used
towire+fromwire to get this!

Requires generation change so we can magic the ARRAY_SIZE var (the C
pre-processor can't uppercase things).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-04 20:16:54 -06:00
Rusty Russell 5c167d16ab tools/generate-wire.py: use helpers.
This was terrible cut & paste.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-04 20:16:54 -06:00
Rusty Russell dc83e64003 tools/generate-wire: don't use void * pointers for tlv fromwire.
And fix up the one place which got it wrong.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-12-04 20:16:54 -06:00
niftynei 4508584b21 dualfund: rearrange things so that the wire-dependent calls are separate
There's a few structs/wire calls that only exist under experimental features.
These were in a common file that was shared/used a bunch of places but
this causes problems. Here we move one of the problematic methods back
into `openingd`, as it's only used locally and then isolate the
references to the `witness_stack` in a new `common/psbt_internal` file.

This lets us remove the iff EXP_FEATURES inclusion switches in most of
the Makefiles.
2020-10-20 14:27:19 +10:30
niftynei 41ebf71e26 psbt: new methods for generating serial_ids for an input/output
we need to do this elsewhere later, pull it out so we can use it
2020-10-20 12:50:31 +10:30
niftynei 82c0b48215 wires: towire/fromwire for wally_tx
We're eventually moving away from 'bitcoin_tx
2020-10-20 12:50:31 +10:30
Rusty Russell d5cb0d85b5 utils: use a cleaner pattern to capture wally allocations.
We force use of tal_wally_start/tal_wally_end around every wally
allocation, and with "end" make the caller choose where to reparent
everything.

This is particularly powerful where we allocate a tx or a psbt: we
want that tx or psbt to be the parent of the other allocations, so
this way we can reparent the tx or psbt, then reparent everything
else onto it.

Implementing psbt_finalize (which uses a behavior flag antipattern)
was tricky, so I ended up splitting that into 'psbt_finalize' and
'psbt_final_tx', which I think also makes the callers clearer.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 14:45:53 +02:00
Rusty Russell f37f2b6193 common/memleak: simplify and document API.
1. Rename memleak_enter_allocations to memleak_find_allocations.
2. Unify scanning for pointers into memleak_remove_region / memleak_remove_pointer.
3. Document the functions.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 13:52:49 +09:30
Rusty Russell c23001d508 bitcoin: use tal_gather_wally() so we don't leave unattached allocations.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2020-09-23 13:52:49 +09:30