| 315 | } |
| 316 | |
| 317 | static struct command_result *json_makesecret(struct command *cmd, |
| 318 | const char *buffer, |
| 319 | const jsmntok_t *obj UNNEEDED, |
| 320 | const jsmntok_t *params) |
| 321 | { |
| 322 | u8 *data; |
| 323 | const char *strdata; |
| 324 | struct json_stream *response; |
| 325 | struct secret secret; |
| 326 | |
| 327 | if (!param_check(cmd, buffer, params, |
| 328 | p_opt("hex", param_bin_from_hex, &data), |
| 329 | p_opt("string", param_string, &strdata), |
| 330 | NULL)) |
| 331 | return command_param_failed(); |
| 332 | |
| 333 | if (strdata) { |
| 334 | if (data) |
| 335 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 336 | "Cannot have both hex and string"); |
| 337 | data = tal_dup_arr(cmd, u8, (u8 *)strdata, strlen(strdata), 0); |
| 338 | } else { |
| 339 | if (!data) |
| 340 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 341 | "Must have either hex or string"); |
| 342 | } |
| 343 | |
| 344 | if (command_check_only(cmd)) |
| 345 | return command_check_done(cmd); |
| 346 | |
| 347 | u8 *msg = towire_hsmd_derive_secret(cmd, data); |
| 348 | if (!wire_sync_write(cmd->ld->hsm_fd, take(msg))) |
| 349 | return command_fail(cmd, LIGHTNINGD, |
| 350 | "Could not write to HSM: %s", strerror(errno)); |
| 351 | |
| 352 | |
| 353 | msg = wire_sync_read(tmpctx, cmd->ld->hsm_fd); |
| 354 | if (!fromwire_hsmd_derive_secret_reply(msg, &secret)) |
| 355 | return command_fail(cmd, LIGHTNINGD, |
| 356 | "Bad reply from HSM: %s", strerror(errno)); |
| 357 | |
| 358 | |
| 359 | response = json_stream_success(cmd); |
| 360 | json_add_secret(response, "secret", &secret); |
| 361 | return command_success(cmd, response); |
| 362 | } |
| 363 | |
| 364 | static const struct json_command makesecret_command = { |
| 365 | "makesecret", |
nothing calls this directly
no test coverage detected