Derive the encryption key from the password provided, and try to decrypt * the cipher. */
| 83 | /* Derive the encryption key from the password provided, and try to decrypt |
| 84 | * the cipher. */ |
| 85 | static 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. */ |
| 112 | static void get_channel_seed(struct secret *channel_seed, struct node_id *peer_id, |
no test coverage detected