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

Function get_encrypted_hsm_secret

tools/hsmtool.c:85–109  ·  view source on GitHub ↗

Derive the encryption key from the password provided, and try to decrypt * the cipher. */

Source from the content-addressed store, hash-verified

83/* Derive the encryption key from the password provided, and try to decrypt
84 * the cipher. */
85static void get_encrypted_hsm_secret(struct secret *hsm_secret,
86 const char *hsm_secret_path,
87 const char *passwd)
88{
89 int fd;
90 struct secret key;
91 struct encrypted_hsm_secret encrypted_secret;
92 char *err;
93 int exit_code = 0;
94
95 fd = open(hsm_secret_path, O_RDONLY);
96 if (fd < 0)
97 errx(EXITCODE_ERROR_HSM_FILE, "Could not open hsm_secret");
98
99 if (!read_all(fd, encrypted_secret.data, ENCRYPTED_HSM_SECRET_LEN))
100 errx(EXITCODE_ERROR_HSM_FILE, "Could not read encrypted hsm_secret");
101
102 exit_code = hsm_secret_encryption_key_with_exitcode(passwd, &key, &err);
103 if (exit_code > 0)
104 errx(exit_code, "%s", err);
105 if (!decrypt_hsm_secret(&key, &encrypted_secret, hsm_secret))
106 errx(ERROR_LIBSODIUM, "Could not retrieve the seed. Wrong password ?");
107
108 close(fd);
109}
110
111/* Taken from hsmd. */
112static void get_channel_seed(struct secret *channel_seed, struct node_id *peer_id,

Callers 5

decrypt_hsmFunction · 0.85
dump_commitments_infosFunction · 0.85
guess_to_remoteFunction · 0.85
dumponchaindescriptorsFunction · 0.85
check_hsmFunction · 0.85

Calls 4

errxFunction · 0.85
read_allFunction · 0.85
decrypt_hsm_secretFunction · 0.85

Tested by

no test coverage detected