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

Function decrypt_scb

plugins/chanbackup.c:168–217  ·  view source on GitHub ↗

Returns decrypted SCB in form of a u8 array */

Source from the content-addressed store, hash-verified

166
167/* Returns decrypted SCB in form of a u8 array */
168static u8 *decrypt_scb(struct plugin *p)
169{
170 struct stat st;
171 int fd = open("emergency.recover", O_RDONLY);
172
173 if (stat("emergency.recover", &st) != 0)
174 plugin_err(p, "SCB file is corrupted!: %s",
175 strerror(errno));
176
177 u8 final[st.st_size];
178
179 if (!read_all(fd, &final, st.st_size)) {
180 plugin_log(p, LOG_DBG, "SCB file is corrupted!: %s",
181 strerror(errno));
182 return NULL;
183 }
184
185 crypto_secretstream_xchacha20poly1305_state crypto_state;
186
187 if (st.st_size < ABYTES +
188 HEADER_LEN)
189 plugin_err(p, "SCB file is corrupted!");
190
191 u8 *ans = tal_arr(tmpctx, u8, st.st_size -
192 ABYTES -
193 HEADER_LEN);
194
195 /* The header part */
196 if (crypto_secretstream_xchacha20poly1305_init_pull(&crypto_state,
197 final,
198 (&secret)->data) != 0)
199 {
200 plugin_err(p, "SCB file is corrupted!");
201 }
202
203 if (crypto_secretstream_xchacha20poly1305_pull(&crypto_state, ans,
204 NULL, 0,
205 final +
206 HEADER_LEN,
207 st.st_size -
208 HEADER_LEN,
209 NULL, 0) != 0) {
210 plugin_err(p, "SCB file is corrupted!");
211 }
212
213 if (close(fd) != 0)
214 plugin_err(p, "Closing: %s", strerror(errno));
215
216 return ans;
217}
218
219static struct command_result *after_recover_rpc(struct command *cmd,
220 const char *buf,

Callers 1

json_emergencyrecoverFunction · 0.85

Calls 4

read_allFunction · 0.85
statClass · 0.70
plugin_errFunction · 0.70
plugin_logFunction · 0.70

Tested by

no test coverage detected