mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 23:54:22 +01:00
common/blindedpath: generalize construction routines.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -256,8 +256,12 @@ u8 *create_enctlv(const tal_t *ctx,
|
|||||||
const struct privkey *blinding,
|
const struct privkey *blinding,
|
||||||
const struct pubkey *node,
|
const struct pubkey *node,
|
||||||
const struct pubkey *next_node,
|
const struct pubkey *next_node,
|
||||||
|
const struct short_channel_id *next_scid,
|
||||||
size_t padlen,
|
size_t padlen,
|
||||||
const struct pubkey *next_blinding_override,
|
const struct pubkey *next_blinding_override,
|
||||||
|
const struct tlv_encrypted_data_tlv_payment_relay *payment_relay TAKES,
|
||||||
|
const struct tlv_encrypted_data_tlv_payment_constraints *payment_constraints TAKES,
|
||||||
|
const u8 *allowed_features TAKES,
|
||||||
struct privkey *next_blinding,
|
struct privkey *next_blinding,
|
||||||
struct pubkey *node_alias)
|
struct pubkey *node_alias)
|
||||||
{
|
{
|
||||||
@@ -266,6 +270,11 @@ u8 *create_enctlv(const tal_t *ctx,
|
|||||||
encmsg->padding = tal_arrz(encmsg, u8, padlen);
|
encmsg->padding = tal_arrz(encmsg, u8, padlen);
|
||||||
encmsg->next_node_id = cast_const(struct pubkey *, next_node);
|
encmsg->next_node_id = cast_const(struct pubkey *, next_node);
|
||||||
encmsg->next_blinding_override = cast_const(struct pubkey *, next_blinding_override);
|
encmsg->next_blinding_override = cast_const(struct pubkey *, next_blinding_override);
|
||||||
|
encmsg->payment_relay = tal_dup_or_null(encmsg, struct tlv_encrypted_data_tlv_payment_relay,
|
||||||
|
payment_relay);
|
||||||
|
encmsg->payment_constraints = tal_dup_or_null(encmsg, struct tlv_encrypted_data_tlv_payment_constraints,
|
||||||
|
payment_constraints);
|
||||||
|
encmsg->allowed_features = tal_dup_talarr(encmsg, u8, allowed_features);
|
||||||
|
|
||||||
return enctlv_from_encmsg(ctx, blinding, node, encmsg,
|
return enctlv_from_encmsg(ctx, blinding, node, encmsg,
|
||||||
next_blinding, node_alias);
|
next_blinding, node_alias);
|
||||||
@@ -276,6 +285,7 @@ u8 *create_final_enctlv(const tal_t *ctx,
|
|||||||
const struct pubkey *final_node,
|
const struct pubkey *final_node,
|
||||||
size_t padlen,
|
size_t padlen,
|
||||||
const struct secret *path_id,
|
const struct secret *path_id,
|
||||||
|
const u8 *allowed_features TAKES,
|
||||||
struct pubkey *node_alias)
|
struct pubkey *node_alias)
|
||||||
{
|
{
|
||||||
struct tlv_encrypted_data_tlv *encmsg = tlv_encrypted_data_tlv_new(tmpctx);
|
struct tlv_encrypted_data_tlv *encmsg = tlv_encrypted_data_tlv_new(tmpctx);
|
||||||
@@ -285,6 +295,7 @@ u8 *create_final_enctlv(const tal_t *ctx,
|
|||||||
encmsg->padding = tal_arrz(encmsg, u8, padlen);
|
encmsg->padding = tal_arrz(encmsg, u8, padlen);
|
||||||
if (path_id)
|
if (path_id)
|
||||||
encmsg->path_id = (u8 *)tal_dup(encmsg, struct secret, path_id);
|
encmsg->path_id = (u8 *)tal_dup(encmsg, struct secret, path_id);
|
||||||
|
encmsg->allowed_features = tal_dup_talarr(encmsg, u8, allowed_features);
|
||||||
|
|
||||||
return enctlv_from_encmsg(ctx, blinding, final_node, encmsg,
|
return enctlv_from_encmsg(ctx, blinding, final_node, encmsg,
|
||||||
&unused_next_blinding, node_alias);
|
&unused_next_blinding, node_alias);
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ struct route_info;
|
|||||||
struct pubkey;
|
struct pubkey;
|
||||||
struct privkey;
|
struct privkey;
|
||||||
struct secret;
|
struct secret;
|
||||||
|
struct short_channel_id;
|
||||||
|
struct tlv_encrypted_data_tlv_payment_constraints;
|
||||||
|
struct tlv_encrypted_data_tlv_payment_relay;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create_enctlv - Encrypt an encmsg to form an enctlv.
|
* create_enctlv - Encrypt an encmsg to form an enctlv.
|
||||||
@@ -16,22 +19,31 @@ struct secret;
|
|||||||
* @blinding: e(i), the blinding secret
|
* @blinding: e(i), the blinding secret
|
||||||
* @node: the pubkey of the node to encrypt for
|
* @node: the pubkey of the node to encrypt for
|
||||||
* @next_node: the pubkey of the next node, to place in enctlv
|
* @next_node: the pubkey of the next node, to place in enctlv
|
||||||
|
* @next_scid: the short_channel_id to the next node, to place in enctlv
|
||||||
* @padlen: if non-zero, the bytes of padding to add (also adds 2 byte padding hdr)
|
* @padlen: if non-zero, the bytes of padding to add (also adds 2 byte padding hdr)
|
||||||
* @next_blinding_override: the optional blinding point to place in enctlv
|
* @next_blinding_override: the optional blinding point to place in enctlv
|
||||||
|
* @payment_relay: optional payment_relay tlv
|
||||||
|
* @payment_constraints: optional payment_constraints tlv
|
||||||
|
* @allowed_features: optional allowed_features array
|
||||||
* @next_blinding: (out) e(i+1), the next blinding secret.
|
* @next_blinding: (out) e(i+1), the next blinding secret.
|
||||||
* @node_alias: (out) the blinded pubkey of the node to tell the recipient.
|
* @node_alias: (out) the blinded pubkey of the node to tell the recipient.
|
||||||
*
|
*
|
||||||
|
* Exactly one of next_node and next_scid must be non-NULL.
|
||||||
* Returns the enctlv blob, or NULL if the secret is invalid.
|
* Returns the enctlv blob, or NULL if the secret is invalid.
|
||||||
*/
|
*/
|
||||||
u8 *create_enctlv(const tal_t *ctx,
|
u8 *create_enctlv(const tal_t *ctx,
|
||||||
const struct privkey *blinding,
|
const struct privkey *blinding,
|
||||||
const struct pubkey *node,
|
const struct pubkey *node,
|
||||||
const struct pubkey *next_node,
|
const struct pubkey *next_node,
|
||||||
|
const struct short_channel_id *next_scid,
|
||||||
size_t padlen,
|
size_t padlen,
|
||||||
const struct pubkey *next_blinding_override,
|
const struct pubkey *next_blinding_override,
|
||||||
|
const struct tlv_encrypted_data_tlv_payment_relay *payment_relay TAKES,
|
||||||
|
const struct tlv_encrypted_data_tlv_payment_constraints *payment_constraints TAKES,
|
||||||
|
const u8 *allowed_features TAKES,
|
||||||
struct privkey *next_blinding,
|
struct privkey *next_blinding,
|
||||||
struct pubkey *node_alias)
|
struct pubkey *node_alias)
|
||||||
NON_NULL_ARGS(2, 3, 4, 7, 8);
|
NON_NULL_ARGS(2, 3, 11, 12);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create_final_enctlv - Encrypt an encmsg to form the final enctlv.
|
* create_final_enctlv - Encrypt an encmsg to form the final enctlv.
|
||||||
@@ -39,6 +51,7 @@ u8 *create_enctlv(const tal_t *ctx,
|
|||||||
* @blinding: e(i), the blinding secret
|
* @blinding: e(i), the blinding secret
|
||||||
* @final_node: the pubkey of the node to encrypt for
|
* @final_node: the pubkey of the node to encrypt for
|
||||||
* @padlen: if non-zero, the bytes of padding to add (also adds 2 byte padding hdr)
|
* @padlen: if non-zero, the bytes of padding to add (also adds 2 byte padding hdr)
|
||||||
|
* @allowed_features: optional allowed_features array
|
||||||
* @path_id: secret to include in enctlv, if not NULL.
|
* @path_id: secret to include in enctlv, if not NULL.
|
||||||
* @node_alias: (out) the blinded pubkey of the node to tell the recipient.
|
* @node_alias: (out) the blinded pubkey of the node to tell the recipient.
|
||||||
*
|
*
|
||||||
@@ -49,8 +62,9 @@ u8 *create_final_enctlv(const tal_t *ctx,
|
|||||||
const struct pubkey *final_node,
|
const struct pubkey *final_node,
|
||||||
size_t padlen,
|
size_t padlen,
|
||||||
const struct secret *path_id,
|
const struct secret *path_id,
|
||||||
|
const u8 *allowed_features TAKES,
|
||||||
struct pubkey *node_alias)
|
struct pubkey *node_alias)
|
||||||
NON_NULL_ARGS(2, 3, 6);
|
NON_NULL_ARGS(2, 3, 7);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unblind_onion - tweak onion epheremeral key so we can decode it with ours.
|
* unblind_onion - tweak onion epheremeral key so we can decode it with ours.
|
||||||
|
|||||||
@@ -171,8 +171,8 @@ int main(int argc, char *argv[])
|
|||||||
"\t},\n",
|
"\t},\n",
|
||||||
type_to_string(tmpctx, struct pubkey, &bob_id));
|
type_to_string(tmpctx, struct pubkey, &bob_id));
|
||||||
|
|
||||||
enctlv = create_enctlv(tmpctx, &blinding, &alice_id, &bob_id,
|
enctlv = create_enctlv(tmpctx, &blinding, &alice_id, &bob_id, NULL,
|
||||||
0, NULL, &blinding, &alias);
|
0, NULL, NULL, NULL, NULL, &blinding, &alias);
|
||||||
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n"
|
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n"
|
||||||
"},\n",
|
"},\n",
|
||||||
tal_hex(tmpctx, enctlv));
|
tal_hex(tmpctx, enctlv));
|
||||||
@@ -201,8 +201,9 @@ int main(int argc, char *argv[])
|
|||||||
type_to_string(tmpctx, struct pubkey, &carol_id),
|
type_to_string(tmpctx, struct pubkey, &carol_id),
|
||||||
type_to_string(tmpctx, struct privkey, &override_blinding));
|
type_to_string(tmpctx, struct privkey, &override_blinding));
|
||||||
|
|
||||||
enctlv = create_enctlv(tmpctx, &blinding, &bob_id, &carol_id,
|
enctlv = create_enctlv(tmpctx, &blinding, &bob_id, &carol_id, NULL,
|
||||||
0, &override_blinding_pub, &blinding, &alias);
|
0, &override_blinding_pub, NULL, NULL, NULL,
|
||||||
|
&blinding, &alias);
|
||||||
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n"
|
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n"
|
||||||
"},\n",
|
"},\n",
|
||||||
tal_hex(tmpctx, enctlv));
|
tal_hex(tmpctx, enctlv));
|
||||||
@@ -230,8 +231,8 @@ int main(int argc, char *argv[])
|
|||||||
type_to_string(tmpctx, struct pubkey, &dave_id),
|
type_to_string(tmpctx, struct pubkey, &dave_id),
|
||||||
tal_hex(tmpctx, tal_arrz(tmpctx, u8, 35)));
|
tal_hex(tmpctx, tal_arrz(tmpctx, u8, 35)));
|
||||||
|
|
||||||
enctlv = create_enctlv(tmpctx, &blinding, &carol_id, &dave_id,
|
enctlv = create_enctlv(tmpctx, &blinding, &carol_id, &dave_id, NULL,
|
||||||
35, NULL, &blinding, &alias);
|
35, NULL, NULL, NULL, NULL, &blinding, &alias);
|
||||||
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n"
|
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n"
|
||||||
"},\n",
|
"},\n",
|
||||||
tal_hex(tmpctx, enctlv));
|
tal_hex(tmpctx, enctlv));
|
||||||
@@ -256,7 +257,7 @@ int main(int argc, char *argv[])
|
|||||||
type_to_string(tmpctx, struct secret, &self_id));
|
type_to_string(tmpctx, struct secret, &self_id));
|
||||||
|
|
||||||
enctlv = create_final_enctlv(tmpctx, &blinding, &dave_id,
|
enctlv = create_final_enctlv(tmpctx, &blinding, &dave_id,
|
||||||
0, &self_id, &alias);
|
0, &self_id, NULL, &alias);
|
||||||
|
|
||||||
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n",
|
printf("\t\"encrypted_recipient_data_hex\": \"%s\"\n",
|
||||||
tal_hex(tmpctx, enctlv));
|
tal_hex(tmpctx, enctlv));
|
||||||
|
|||||||
@@ -170,8 +170,9 @@ int main(int argc, char *argv[])
|
|||||||
pubkey_from_privkey(&blinding[ALICE], &blinding_pub[ALICE]);
|
pubkey_from_privkey(&blinding[ALICE], &blinding_pub[ALICE]);
|
||||||
|
|
||||||
enctlv[ALICE] = create_enctlv(tmpctx, &blinding[ALICE],
|
enctlv[ALICE] = create_enctlv(tmpctx, &blinding[ALICE],
|
||||||
&id[ALICE], &id[BOB],
|
&id[ALICE], &id[BOB], NULL,
|
||||||
0, NULL, &blinding[BOB], &alias[ALICE]);
|
0, NULL, NULL, NULL, NULL,
|
||||||
|
&blinding[BOB], &alias[ALICE]);
|
||||||
|
|
||||||
pubkey_from_privkey(&blinding[BOB], &blinding_pub[BOB]);
|
pubkey_from_privkey(&blinding[BOB], &blinding_pub[BOB]);
|
||||||
|
|
||||||
@@ -179,8 +180,8 @@ int main(int argc, char *argv[])
|
|||||||
memset(&override_blinding, 7, sizeof(override_blinding));
|
memset(&override_blinding, 7, sizeof(override_blinding));
|
||||||
pubkey_from_privkey(&override_blinding, &override_blinding_pub);
|
pubkey_from_privkey(&override_blinding, &override_blinding_pub);
|
||||||
enctlv[BOB] = create_enctlv(tmpctx, &blinding[BOB],
|
enctlv[BOB] = create_enctlv(tmpctx, &blinding[BOB],
|
||||||
&id[BOB], &id[CAROL],
|
&id[BOB], &id[CAROL], NULL,
|
||||||
0, &override_blinding_pub,
|
0, &override_blinding_pub, NULL, NULL, NULL,
|
||||||
&blinding[CAROL], &alias[BOB]);
|
&blinding[CAROL], &alias[BOB]);
|
||||||
|
|
||||||
/* That replaced the blinding */
|
/* That replaced the blinding */
|
||||||
@@ -188,14 +189,15 @@ int main(int argc, char *argv[])
|
|||||||
blinding_pub[CAROL] = override_blinding_pub;
|
blinding_pub[CAROL] = override_blinding_pub;
|
||||||
|
|
||||||
enctlv[CAROL] = create_enctlv(tmpctx, &blinding[CAROL],
|
enctlv[CAROL] = create_enctlv(tmpctx, &blinding[CAROL],
|
||||||
&id[CAROL], &id[DAVE],
|
&id[CAROL], &id[DAVE], NULL,
|
||||||
35, NULL, &blinding[DAVE], &alias[CAROL]);
|
35, NULL, NULL, NULL, NULL,
|
||||||
|
&blinding[DAVE], &alias[CAROL]);
|
||||||
|
|
||||||
for (size_t i = 0; i < sizeof(self_id); i++)
|
for (size_t i = 0; i < sizeof(self_id); i++)
|
||||||
self_id.data[i] = i+1;
|
self_id.data[i] = i+1;
|
||||||
|
|
||||||
enctlv[DAVE] = create_final_enctlv(tmpctx, &blinding[DAVE], &id[DAVE],
|
enctlv[DAVE] = create_final_enctlv(tmpctx, &blinding[DAVE], &id[DAVE],
|
||||||
0, &self_id, &alias[DAVE]);
|
0, &self_id, NULL, &alias[DAVE]);
|
||||||
pubkey_from_privkey(&blinding[DAVE], &blinding_pub[DAVE]);
|
pubkey_from_privkey(&blinding[DAVE], &blinding_pub[DAVE]);
|
||||||
|
|
||||||
/* Create an onion which encodes this. */
|
/* Create an onion which encodes this. */
|
||||||
|
|||||||
@@ -336,10 +336,10 @@ static struct command_result *json_blindedpath(struct command *cmd,
|
|||||||
path[i]->encrypted_recipient_data = create_enctlv(path[i],
|
path[i]->encrypted_recipient_data = create_enctlv(path[i],
|
||||||
&blinding_iter,
|
&blinding_iter,
|
||||||
&ids[i],
|
&ids[i],
|
||||||
&ids[i+1],
|
&ids[i+1], NULL,
|
||||||
/* FIXME: Pad? */
|
/* FIXME: Pad? */
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL, NULL, NULL, NULL,
|
||||||
&blinding_iter,
|
&blinding_iter,
|
||||||
&path[i]->node_id);
|
&path[i]->node_id);
|
||||||
}
|
}
|
||||||
@@ -352,6 +352,7 @@ static struct command_result *json_blindedpath(struct command *cmd,
|
|||||||
/* FIXME: Pad? */
|
/* FIXME: Pad? */
|
||||||
0,
|
0,
|
||||||
&cmd->ld->onion_reply_secret,
|
&cmd->ld->onion_reply_secret,
|
||||||
|
NULL,
|
||||||
&path[nhops-1]->node_id);
|
&path[nhops-1]->node_id);
|
||||||
|
|
||||||
response = json_stream_success(cmd);
|
response = json_stream_success(cmd);
|
||||||
|
|||||||
@@ -638,9 +638,10 @@ send_modern_message(struct command *cmd,
|
|||||||
&blinding_iter,
|
&blinding_iter,
|
||||||
&sent->path[i],
|
&sent->path[i],
|
||||||
&sent->path[i+1],
|
&sent->path[i+1],
|
||||||
|
NULL,
|
||||||
/* FIXME: Pad? */
|
/* FIXME: Pad? */
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL, NULL, NULL, NULL,
|
||||||
&blinding_iter,
|
&blinding_iter,
|
||||||
&node_alias[i]);
|
&node_alias[i]);
|
||||||
}
|
}
|
||||||
@@ -650,7 +651,7 @@ send_modern_message(struct command *cmd,
|
|||||||
/* We don't include enctlv in final, but it gives us final alias */
|
/* We don't include enctlv in final, but it gives us final alias */
|
||||||
if (!create_final_enctlv(tmpctx, &blinding_iter, &sent->path[nhops-1],
|
if (!create_final_enctlv(tmpctx, &blinding_iter, &sent->path[nhops-1],
|
||||||
/* FIXME: Pad? */ 0,
|
/* FIXME: Pad? */ 0,
|
||||||
NULL,
|
NULL, NULL,
|
||||||
&node_alias[nhops-1])) {
|
&node_alias[nhops-1])) {
|
||||||
/* Should not happen! */
|
/* Should not happen! */
|
||||||
return command_fail(cmd, LIGHTNINGD,
|
return command_fail(cmd, LIGHTNINGD,
|
||||||
|
|||||||
Reference in New Issue
Block a user