| 1299 | } |
| 1300 | |
| 1301 | char *hsm_secret_arg(const tal_t *ctx, |
| 1302 | const char *arg, |
| 1303 | const struct hsm_secret **hsm_secret) |
| 1304 | { |
| 1305 | char *codex32_fail; |
| 1306 | struct codex32 *codex32; |
| 1307 | struct hsm_secret *hsms = tal(tmpctx, struct hsm_secret); |
| 1308 | |
| 1309 | /* We accept hex, or codex32. hex is very very very unlikely to |
| 1310 | * give a valid codex32, so try that first */ |
| 1311 | codex32 = codex32_decode(tmpctx, "cl", arg, &codex32_fail); |
| 1312 | if (codex32) { |
| 1313 | hsms->type = HSM_SECRET_PLAIN; |
| 1314 | hsms->secret_data = tal_steal(hsms, codex32->payload); |
| 1315 | if (codex32->threshold != 0 |
| 1316 | || codex32->type != CODEX32_ENCODING_SECRET) { |
| 1317 | return "This is only one share of codex32!"; |
| 1318 | } |
| 1319 | if (tal_count(hsms->secret_data) != 32) |
| 1320 | return "Invalid length: must be 32 bytes"; |
| 1321 | /* Not codex32, was it hex? */ |
| 1322 | } else if ((hsms->secret_data = tal_hexdata(hsms, arg, strlen(arg))) != NULL) { |
| 1323 | hsms->type = HSM_SECRET_PLAIN; |
| 1324 | if (tal_count(hsms->secret_data) != 32) |
| 1325 | return "Invalid length: must be 32 bytes"; |
| 1326 | /* Not hex, is is a mnemonic? */ |
| 1327 | } else { |
| 1328 | enum hsm_secret_error err = validate_mnemonic(arg); |
| 1329 | if (err != HSM_SECRET_OK) { |
| 1330 | /* If it looks kinda like a codex32, give that error. */ |
| 1331 | if (strstarts(arg, "cl")) |
| 1332 | return codex32_fail; |
| 1333 | else |
| 1334 | return "Not a valid mnemonic, hex, or codex32 string"; |
| 1335 | } |
| 1336 | hsms->type = HSM_SECRET_MNEMONIC_NO_PASS; |
| 1337 | hsms->mnemonic = tal_strdup(hsms, arg); |
| 1338 | } |
| 1339 | |
| 1340 | *hsm_secret = tal_steal(ctx, hsms); |
| 1341 | return NULL; |
| 1342 | } |
| 1343 | |
| 1344 | static char *opt_set_hsm_secret(const char *arg, struct lightningd *ld) |
| 1345 | { |
no test coverage detected