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

Function opt_set_hsm_password

lightningd/options.c:513–555  ·  view source on GitHub ↗

Prompt the user to enter a password, from which will be derived the key used * for `hsm_secret` encryption. * The algorithm used to derive the key is Argon2(id), to which libsodium * defaults. However argon2id-specific constants are used in case someone runs it * with a libsodium version which default constants differs (typically <1.0.9). */

Source from the content-addressed store, hash-verified

511 * with a libsodium version which default constants differs (typically <1.0.9).
512 */
513static char *opt_set_hsm_password(struct lightningd *ld)
514{
515 char *passwd, *passwd_confirmation, *err_msg;
516 int is_encrypted;
517
518 is_encrypted = is_hsm_secret_encrypted("hsm_secret");
519 if (is_encrypted == -1)
520 return tal_fmt(NULL, "Could not access 'hsm_secret': %s",
521 strerror(errno));
522
523 prompt(ld, "The hsm_secret is encrypted with a password. In order to "
524 "decrypt it and start the node you must provide the password.");
525 prompt(ld, "Enter hsm_secret password:");
526
527 passwd = read_stdin_pass_with_exit_code(&err_msg, &opt_exitcode);
528 if (!passwd)
529 return err_msg;
530 if (!is_encrypted) {
531 prompt(ld, "Confirm hsm_secret password:");
532 fflush(stdout);
533 passwd_confirmation = read_stdin_pass_with_exit_code(&err_msg, &opt_exitcode);
534 if (!passwd_confirmation)
535 return err_msg;
536
537 if (!streq(passwd, passwd_confirmation)) {
538 opt_exitcode = EXITCODE_HSM_BAD_PASSWORD;
539 return "Passwords confirmation mismatch.";
540 }
541 free(passwd_confirmation);
542 }
543 prompt(ld, "");
544
545 ld->config.keypass = tal(NULL, struct secret);
546
547 opt_exitcode = hsm_secret_encryption_key_with_exitcode(passwd, ld->config.keypass, &err_msg);
548 if (opt_exitcode > 0)
549 return err_msg;
550
551 ld->encrypted_hsm = true;
552 free(passwd);
553
554 return NULL;
555}
556
557#if DEVELOPER
558static char *opt_subprocess_debug(const char *optarg, struct lightningd *ld)

Callers

nothing calls this directly

Calls 4

is_hsm_secret_encryptedFunction · 0.85
promptFunction · 0.85

Tested by

no test coverage detected