MCPcopy Create free account
hub / github.com/ElementsProject/lightning / init_hsm

Function init_hsm

hsmd/hsmd.c:507–578  ·  view source on GitHub ↗

~ This is the response to lightningd's HSM_INIT request, which is the first * thing it sends. */

Source from the content-addressed store, hash-verified

505/*~ This is the response to lightningd's HSM_INIT request, which is the first
506 * thing it sends. */
507static struct io_plan *init_hsm(struct io_conn *conn,
508 struct client *c,
509 const u8 *msg_in)
510{
511 struct secret *hsm_encryption_key;
512 struct bip32_key_version bip32_key_version;
513 u32 minversion, maxversion;
514 struct tlv_hsmd_init_tlvs *tlvs;
515 const u32 our_minversion = 4, our_maxversion = 6;
516 const char *hsm_passphrase;
517
518 /* This must be lightningd. */
519 assert(is_lightningd(c));
520
521 /*~ The fromwire_* routines are autogenerated, based on the message
522 * definitions in hsm_client_wire.csv. The format of those files is
523 * an extension of the simple comma-separated format output by the
524 * BOLT tools/extract-formats.py tool. */
525 if (!fromwire_hsmd_init(NULL, msg_in, &bip32_key_version, &chainparams,
526 &hsm_encryption_key,
527 &dev_force_privkey,
528 &dev_force_bip32_seed,
529 &dev_force_channel_secrets,
530 &dev_force_channel_secrets_shaseed,
531 &minversion, &maxversion, &tlvs))
532 return bad_req(conn, c, msg_in);
533
534 /*~ Usually we don't worry about API breakage between internal daemons,
535 * but there are other implementations of the HSM daemon now, so we
536 * do at least the simplest, clearest thing. */
537 if (our_minversion > maxversion || our_maxversion < minversion)
538 return bad_req_fmt(conn, c, msg_in,
539 "Version %u-%u not valid: we need %u-%u",
540 minversion, maxversion,
541 our_minversion, our_maxversion);
542
543 /*~ We used to have lightningd hand us the encryption key derived from
544 * the passphrase which was used to encrypt the `hsm_secret` file. Then
545 * Rusty gave me the thankless task of introducing BIP-39 mnemonics. I
546 * think this is some kind of obscure CLN hazing ritual? Anyway, the
547 * passphrase needs to be *appended* to the mnemonic, so the HSM needs
548 * the raw passphrase. To avoid a compatibility break, I put it inside
549 * the TLV, and left the old "hsm_encryption_key" field in place (and lightningd
550 * never sets that anymore), and we use the TLV instead. */
551 if (tlvs->hsm_passphrase)
552 hsm_passphrase = tlvs->hsm_passphrase;
553 else
554 hsm_passphrase = NULL;
555
556 if (!developer) {
557 assert(!dev_force_privkey);
558 assert(!dev_force_bip32_seed);
559 assert(!dev_force_channel_secrets);
560 assert(!dev_force_channel_secrets_shaseed);
561 }
562
563 /* Once we have read the init message we know which params the master
564 * will use */

Callers 1

handle_clientFunction · 0.85

Calls 9

is_lightningdFunction · 0.85
bad_reqFunction · 0.85
bad_req_fmtFunction · 0.85
maybe_create_new_hsmFunction · 0.85
load_hsmFunction · 0.85
tal_freeFunction · 0.85
req_replyFunction · 0.85
hsmd_initFunction · 0.85
tal_bytelenFunction · 0.85

Tested by

no test coverage detected