lightningd: return both obsolete and modern blindedpaths from "blindedpath" RPC.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-11-30 13:36:05 +10:30
parent b3af5f5a2c
commit 5cf2c2fbd7
2 changed files with 37 additions and 9 deletions

View File

@@ -292,8 +292,8 @@ static struct command_result *json_blindedpath(struct command *cmd,
{ {
struct pubkey *ids; struct pubkey *ids;
struct onionmsg_path **path; struct onionmsg_path **path;
struct privkey blinding_iter; struct privkey first_blinding, blinding_iter;
struct pubkey first_blinding, first_node, me; struct pubkey first_blinding_pubkey, first_node, me;
size_t nhops; size_t nhops;
struct json_stream *response; struct json_stream *response;
@@ -317,8 +317,8 @@ static struct command_result *json_blindedpath(struct command *cmd,
type_to_string(tmpctx, struct pubkey, type_to_string(tmpctx, struct pubkey,
&ids[nhops-1])); &ids[nhops-1]));
randombytes_buf(&blinding_iter, sizeof(blinding_iter)); randombytes_buf(&first_blinding, sizeof(first_blinding));
if (!pubkey_from_privkey(&blinding_iter, &first_blinding)) if (!pubkey_from_privkey(&first_blinding, &first_blinding_pubkey))
/* Should not happen! */ /* Should not happen! */
return command_fail(cmd, LIGHTNINGD, return command_fail(cmd, LIGHTNINGD,
"Could not convert blinding to pubkey!"); "Could not convert blinding to pubkey!");
@@ -326,6 +326,36 @@ static struct command_result *json_blindedpath(struct command *cmd,
/* We convert ids into aliases as we go. */ /* We convert ids into aliases as we go. */
path = tal_arr(cmd, struct onionmsg_path *, nhops); path = tal_arr(cmd, struct onionmsg_path *, nhops);
blinding_iter = first_blinding;
for (size_t i = 0; i < nhops - 1; i++) {
path[i] = tal(path, struct onionmsg_path);
path[i]->encrypted_recipient_data = create_enctlv(path[i],
&blinding_iter,
&ids[i],
&ids[i+1],
/* FIXME: Pad? */
0,
NULL,
&blinding_iter,
&path[i]->node_id);
}
/* FIXME: Add padding! */
path[nhops-1] = tal(path, struct onionmsg_path);
path[nhops-1]->encrypted_recipient_data = create_final_enctlv(path[nhops-1],
&blinding_iter,
&ids[nhops-1],
/* FIXME: Pad? */
0,
&cmd->ld->onion_reply_secret,
&path[nhops-1]->node_id);
response = json_stream_success(cmd);
json_add_blindedpath(response, "blindedpath",
&first_blinding_pubkey, &first_node, path);
/* Now create obsolete one! */
blinding_iter = first_blinding;
for (size_t i = 0; i < nhops - 1; i++) { for (size_t i = 0; i < nhops - 1; i++) {
path[i] = tal(path, struct onionmsg_path); path[i] = tal(path, struct onionmsg_path);
path[i]->encrypted_recipient_data = create_obs2_enctlv(path[i], path[i]->encrypted_recipient_data = create_obs2_enctlv(path[i],
@@ -348,10 +378,8 @@ static struct command_result *json_blindedpath(struct command *cmd,
0, 0,
&cmd->ld->onion_reply_secret, &cmd->ld->onion_reply_secret,
&path[nhops-1]->node_id); &path[nhops-1]->node_id);
json_add_blindedpath(response, "obs2blindedpath",
response = json_stream_success(cmd); &first_blinding_pubkey, &first_node, path);
json_add_blindedpath(response, "blindedpath",
&first_blinding, &first_node, path);
return command_success(cmd, response); return command_success(cmd, response);
} }

View File

@@ -727,7 +727,7 @@ static struct command_result *use_reply_path(struct command *cmd,
struct tlv_obs2_onionmsg_payload_reply_path *rpath; struct tlv_obs2_onionmsg_payload_reply_path *rpath;
rpath = json_to_obs2_reply_path(cmd, buf, rpath = json_to_obs2_reply_path(cmd, buf,
json_get_member(buf, result, "blindedpath")); json_get_member(buf, result, "obs2blindedpath"));
if (!rpath) if (!rpath)
plugin_err(cmd->plugin, plugin_err(cmd->plugin,
"could not parse reply path %.*s?", "could not parse reply path %.*s?",