Returns decrypted SCB in form of a u8 array */
| 255 | |
| 256 | /* Returns decrypted SCB in form of a u8 array */ |
| 257 | static u8 *decrypt_scb(struct plugin *p) |
| 258 | { |
| 259 | const struct chanbackup *cb = chanbackup(p); |
| 260 | u8 *filedata = get_file_data(tmpctx, p); |
| 261 | |
| 262 | crypto_secretstream_xchacha20poly1305_state crypto_state; |
| 263 | |
| 264 | if (tal_bytelen(filedata) < ABYTES + |
| 265 | HEADER_LEN) |
| 266 | plugin_err(p, "SCB file is corrupted!"); |
| 267 | |
| 268 | u8 *decrypt_scb = tal_arr(tmpctx, u8, tal_bytelen(filedata) - |
| 269 | ABYTES - |
| 270 | HEADER_LEN); |
| 271 | |
| 272 | /* The header part */ |
| 273 | if (crypto_secretstream_xchacha20poly1305_init_pull(&crypto_state, |
| 274 | filedata, |
| 275 | cb->secret.data) != 0) |
| 276 | { |
| 277 | plugin_err(p, "SCB file is corrupted!"); |
| 278 | } |
| 279 | |
| 280 | if (crypto_secretstream_xchacha20poly1305_pull(&crypto_state, decrypt_scb, |
| 281 | NULL, 0, |
| 282 | filedata + |
| 283 | HEADER_LEN, |
| 284 | tal_bytelen(filedata)- |
| 285 | HEADER_LEN, |
| 286 | NULL, 0) != 0) { |
| 287 | plugin_err(p, "SCB file is corrupted!"); |
| 288 | } |
| 289 | return decrypt_scb; |
| 290 | } |
| 291 | |
| 292 | static struct command_result *after_recover_rpc(struct command *cmd, |
| 293 | const char *method, |
no test coverage detected