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

Function hsm_init

lightningd/hsm_control.c:78–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78struct ext_key *hsm_init(struct lightningd *ld)
79{
80 u8 *msg;
81 int fds[2];
82 struct ext_key *bip32_base;
83
84 /* We actually send requests synchronously: only status is async. */
85 if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0)
86 err(EXITCODE_HSM_GENERIC_ERROR, "Could not create hsm socketpair");
87
88 ld->hsm = new_global_subd(ld, "lightning_hsmd",
89 hsmd_wire_name,
90 hsm_msg,
91 take(&fds[1]), NULL);
92 if (!ld->hsm)
93 err(EXITCODE_HSM_GENERIC_ERROR, "Could not subd hsm");
94
95 /* If hsm_secret is encrypted and the --encrypted-hsm startup option is
96 * not passed, don't let hsmd use the first 32 bytes of the cypher as the
97 * actual secret. */
98 if (!ld->config.keypass) {
99 if (is_hsm_secret_encrypted("hsm_secret") == 1)
100 errx(EXITCODE_HSM_ERROR_IS_ENCRYPT, "hsm_secret is encrypted, you need to pass the "
101 "--encrypted-hsm startup option.");
102 }
103
104 ld->hsm_fd = fds[0];
105 if (!wire_sync_write(ld->hsm_fd, towire_hsmd_init(tmpctx,
106 &chainparams->bip32_key_version,
107 chainparams,
108 ld->config.keypass,
109 IFDEV(ld->dev_force_privkey, NULL),
110 IFDEV(ld->dev_force_bip32_seed, NULL),
111 IFDEV(ld->dev_force_channel_secrets, NULL),
112 IFDEV(ld->dev_force_channel_secrets_shaseed, NULL))))
113 err(EXITCODE_HSM_GENERIC_ERROR, "Writing init msg to hsm");
114
115 bip32_base = tal(ld, struct ext_key);
116 msg = wire_sync_read(tmpctx, ld->hsm_fd);
117 if (!fromwire_hsmd_init_reply(msg,
118 &ld->id, bip32_base,
119 &ld->bolt12_base,
120 &ld->onion_reply_secret)) {
121 if (ld->config.keypass)
122 errx(EXITCODE_HSM_BAD_PASSWORD, "Wrong password for encrypted hsm_secret.");
123 errx(EXITCODE_HSM_GENERIC_ERROR, "HSM did not give init reply");
124 }
125
126 return bip32_base;
127}
128
129static struct command_result *json_makesecret(struct command *cmd,
130 const char *buffer,

Callers 1

mainFunction · 0.70

Calls 6

errFunction · 0.85
new_global_subdFunction · 0.85
is_hsm_secret_encryptedFunction · 0.85
errxFunction · 0.85
wire_sync_writeFunction · 0.50
wire_sync_readFunction · 0.50

Tested by

no test coverage detected