mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 13:25:43 +01:00
tools/hsmtool.c: Add to hsmtools to get content of emergency.recover in bech32 format.
Changelog-Added: `hsmtool`: new command `getemergencyrecover` to extract emergency.recover in bech32 format (clnemerge1...)
This commit is contained in:
parent
b0c603581f
commit
8d36b7c438
@ -18,7 +18,7 @@ tools/headerversions: $(FORCE) tools/headerversions.o libccan.a
|
||||
tools/headerversions.o: ccan/config.h
|
||||
tools/check-bolt: tools/check-bolt.o $(TOOLS_COMMON_OBJS)
|
||||
|
||||
tools/hsmtool: tools/hsmtool.o $(TOOLS_COMMON_OBJS) $(BITCOIN_OBJS) common/amount.o common/autodata.o common/bech32.o common/bigsize.o common/codex32.o common/configdir.o common/configvar.o common/derive_basepoints.o common/descriptor_checksum.o common/hsm_encryption.o common/node_id.o common/type_to_string.o common/version.o wire/fromwire.o wire/towire.o
|
||||
tools/hsmtool: tools/hsmtool.o $(TOOLS_COMMON_OBJS) $(BITCOIN_OBJS) common/amount.o common/autodata.o common/bech32.o common/bech32_util.o common/bigsize.o common/codex32.o common/configdir.o common/configvar.o common/derive_basepoints.o common/descriptor_checksum.o common/hsm_encryption.o common/node_id.o common/type_to_string.o common/version.o wire/fromwire.o wire/towire.o
|
||||
|
||||
tools/lightning-hsmtool: tools/hsmtool
|
||||
cp $< $@
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <ccan/tal/path/path.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <common/bech32.h>
|
||||
#include <common/bech32_util.h>
|
||||
#include <common/codex32.h>
|
||||
#include <common/configdir.h>
|
||||
#include <common/derive_basepoints.h>
|
||||
@ -46,6 +47,7 @@ static void show_usage(const char *progname)
|
||||
printf(" - dumponchaindescriptors <path/to/hsm_secret> [network]\n");
|
||||
printf(" - makerune <path/to/hsm_secret>\n");
|
||||
printf(" - getcodexsecret <path/to/hsm_secret> <id>\n");
|
||||
printf(" - getemergencyrecover <path/to/emergency.recover>\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@ -262,6 +264,28 @@ static int make_codexsecret(const char *hsm_secret_path,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getemergencyrecover(const char *emer_rec_path)
|
||||
{
|
||||
u8 *scb = grab_file(tmpctx, emer_rec_path);
|
||||
char *output, *hrp = "clnemerg";
|
||||
if (!scb) {
|
||||
errx(EXITCODE_ERROR_HSM_FILE, "Reading emergency.recover");
|
||||
} else {
|
||||
/* grab_file adds nul term */
|
||||
tal_resize(&scb, tal_bytelen(scb) - 1);
|
||||
}
|
||||
u5 *data = tal_arr(tmpctx, u5, 0);
|
||||
|
||||
bech32_push_bits(&data, scb, tal_bytelen(scb) * 8);
|
||||
output = tal_arr(tmpctx, char, strlen(hrp) + tal_count(data) + 8);
|
||||
|
||||
bech32_encode(output, hrp, data, tal_count(data), (size_t)-1,
|
||||
BECH32_ENCODING_BECH32);
|
||||
|
||||
printf("%s\n", output);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int encrypt_hsm(const char *hsm_secret_path)
|
||||
{
|
||||
int fd;
|
||||
@ -768,5 +792,12 @@ int main(int argc, char *argv[])
|
||||
show_usage(argv[0]);
|
||||
return make_codexsecret(argv[2], argv[3]);
|
||||
}
|
||||
|
||||
if(streq(method, "getemergencyrecover")) {
|
||||
if (argc < 3)
|
||||
show_usage(argv[0]);
|
||||
return getemergencyrecover(argv[2]);
|
||||
}
|
||||
|
||||
show_usage(argv[0]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user