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

Function read_hsm_passphrase

lightningd/options.c:556–593  ·  view source on GitHub ↗

Read HSM passphrase from user input */

Source from the content-addressed store, hash-verified

554
555/* Read HSM passphrase from user input */
556static char *read_hsm_passphrase(struct lightningd *ld)
557{
558 const char *passphrase, *passphrase_confirmation;
559 enum hsm_secret_error err;
560
561 prompt(ld, "The hsm_secret requires a passphrase. In order to "
562 "access it and start the node you must provide the passphrase.");
563 prompt(ld, "Enter hsm_secret passphrase:");
564
565 passphrase = read_stdin_pass(tmpctx, &err);
566 if (err != HSM_SECRET_OK) {
567 opt_exitcode = EXITCODE_HSM_PASSWORD_INPUT_ERR;
568 return tal_strdup(tmpctx, hsm_secret_error_str(err));
569 }
570
571 /* We need confirmation if the hsm_secret file doesn't exist yet */
572 if (!path_is_file("hsm_secret")) {
573 prompt(ld, "Confirm hsm_secret passphrase:");
574 fflush(stdout);
575 passphrase_confirmation = read_stdin_pass(tmpctx, &err);
576 if (err != HSM_SECRET_OK) {
577 opt_exitcode = EXITCODE_HSM_PASSWORD_INPUT_ERR;
578 return tal_strdup(tmpctx, hsm_secret_error_str(err));
579 }
580
581 if (!streq(passphrase, passphrase_confirmation)) {
582 opt_exitcode = EXITCODE_HSM_BAD_PASSWORD;
583 return "Passphrase confirmation mismatch.";
584 }
585 }
586
587 /* Store passphrase in lightningd struct */
588 ld->hsm_passphrase = tal_strdup(ld, passphrase);
589
590 /* Encryption key derivation is handled by hsmd internally */
591
592 return NULL;
593}
594
595/* Prompt the user to enter a password, from which will be derived the key used
596 * for `hsm_secret` encryption.

Callers 2

opt_set_hsm_passwordFunction · 0.85
opt_set_hsm_passphraseFunction · 0.85

Calls 4

promptFunction · 0.85
read_stdin_passFunction · 0.85
hsm_secret_error_strFunction · 0.85
path_is_fileFunction · 0.85

Tested by

no test coverage detected