Skip to content

Commit

Permalink
onionmessages: remove obsolete onion message parsing.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Sep 29, 2022
1 parent 342e330 commit 41ef853
Show file tree
Hide file tree
Showing 34 changed files with 66 additions and 1,259 deletions.
1 change: 0 additions & 1 deletion channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
case WIRE_PONG:
case WIRE_WARNING:
case WIRE_ERROR:
case WIRE_OBS2_ONION_MESSAGE:
case WIRE_ONION_MESSAGE:
abort();
}
Expand Down
157 changes: 0 additions & 157 deletions common/blindedpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,6 @@ static u8 *enctlv_from_encmsg_raw(const tal_t *ctx,
return ret;
}

static u8 *enctlv_from_obs2_encmsg(const tal_t *ctx,
const struct privkey *blinding,
const struct pubkey *node,
const struct tlv_obs2_encmsg_tlvs *encmsg,
struct privkey *next_blinding,
struct pubkey *node_alias)
{
u8 *encmsg_raw = tal_arr(NULL, u8, 0);
towire_tlv_obs2_encmsg_tlvs(&encmsg_raw, encmsg);
return enctlv_from_encmsg_raw(ctx, blinding, node, take(encmsg_raw),
next_blinding, node_alias);
}

static u8 *enctlv_from_encmsg(const tal_t *ctx,
const struct privkey *blinding,
const struct pubkey *node,
Expand Down Expand Up @@ -196,22 +183,6 @@ static u8 *decrypt_encmsg_raw(const tal_t *ctx,
return dec;
}

static struct tlv_obs2_encmsg_tlvs *decrypt_obs2_encmsg(const tal_t *ctx,
const struct pubkey *blinding,
const struct secret *ss,
const u8 *enctlv)
{
const u8 *cursor = decrypt_encmsg_raw(tmpctx, blinding, ss, enctlv);
size_t maxlen = tal_bytelen(cursor);

/* BOLT-onion-message #4:
*
* - if the `enctlv` is not a valid TLV...
* - MUST drop the message.
*/
return fromwire_tlv_obs2_encmsg_tlvs(ctx, &cursor, &maxlen);
}

static struct tlv_encrypted_data_tlv *decrypt_encmsg(const tal_t *ctx,
const struct pubkey *blinding,
const struct secret *ss,
Expand Down Expand Up @@ -354,131 +325,3 @@ u8 *create_final_enctlv(const tal_t *ctx,
return enctlv_from_encmsg(ctx, blinding, final_node, encmsg,
&unused_next_blinding, node_alias);
}

/* Obsolete variants */
bool decrypt_obs2_enctlv(const struct pubkey *blinding,
const struct secret *ss,
const u8 *enctlv,
struct pubkey *next_node,
struct pubkey *next_blinding)
{
struct tlv_obs2_encmsg_tlvs *encmsg;

encmsg = decrypt_obs2_encmsg(tmpctx, blinding, ss, enctlv);
if (!encmsg)
return false;

/* BOLT-onion-message #4:
*
* The reader:
* - if it is not the final node according to the onion encryption:
*...
* - if the `enctlv` ... does not contain
* `next_node_id`:
* - MUST drop the message.
*/
if (!encmsg->next_node_id)
return false;

/* BOLT-onion-message #4:
* The reader:
* - if it is not the final node according to the onion encryption:
*...
* - if the `enctlv` contains `self_id`:
* - MUST drop the message.
*/
if (encmsg->self_id)
return false;

/* BOLT-onion-message #4:
* The reader:
* - if it is not the final node according to the onion encryption:
*...
* - if `blinding` is specified in the `enctlv`:
* - MUST pass that as `blinding` in the `onion_message`
* - otherwise:
* - MUST pass `blinding` derived as in
* [Route Blinding][route-blinding] (i.e.
* `E(i+1) = H(E(i) || ss(i)) * E(i)`).
*/
*next_node = *encmsg->next_node_id;
if (encmsg->next_blinding)
*next_blinding = *encmsg->next_blinding;
else {
/* E(i-1) = H(E(i) || ss(i)) * E(i) */
struct sha256 h;
blinding_hash_e_and_ss(blinding, ss, &h);
blinding_next_pubkey(blinding, &h, next_blinding);
}
return true;
}

bool decrypt_obs2_final_enctlv(const tal_t *ctx,
const struct pubkey *blinding,
const struct secret *ss,
const u8 *enctlv,
const struct pubkey *my_id,
struct pubkey *alias,
struct secret **self_id)
{
struct tlv_obs2_encmsg_tlvs *encmsg;
struct secret node_id_blinding;

/* Repeat the tweak to get the alias it was using for us */
subkey_from_hmac("blinded_node_id", ss, &node_id_blinding);
*alias = *my_id;
if (secp256k1_ec_pubkey_tweak_mul(secp256k1_ctx,
&alias->pubkey,
node_id_blinding.data) != 1)
return false;

encmsg = decrypt_obs2_encmsg(tmpctx, blinding, ss, enctlv);
if (!encmsg)
return false;

if (tal_bytelen(encmsg->self_id) == sizeof(**self_id)) {
*self_id = tal(ctx, struct secret);
memcpy(*self_id, encmsg->self_id, sizeof(**self_id));
} else
*self_id = NULL;

return true;
}

u8 *create_obs2_enctlv(const tal_t *ctx,
const struct privkey *blinding,
const struct pubkey *node,
const struct pubkey *next_node,
size_t padlen,
const struct pubkey *override_blinding,
struct privkey *next_blinding,
struct pubkey *node_alias)
{
struct tlv_obs2_encmsg_tlvs *encmsg = tlv_obs2_encmsg_tlvs_new(tmpctx);
if (padlen)
encmsg->padding = tal_arrz(encmsg, u8, padlen);
encmsg->next_node_id = cast_const(struct pubkey *, next_node);
encmsg->next_blinding = cast_const(struct pubkey *, override_blinding);

return enctlv_from_obs2_encmsg(ctx, blinding, node, encmsg,
next_blinding, node_alias);
}

u8 *create_obs2_final_enctlv(const tal_t *ctx,
const struct privkey *blinding,
const struct pubkey *final_node,
size_t padlen,
const struct secret *self_id,
struct pubkey *node_alias)
{
struct tlv_obs2_encmsg_tlvs *encmsg = tlv_obs2_encmsg_tlvs_new(tmpctx);
struct privkey unused_next_blinding;

if (padlen)
encmsg->padding = tal_arrz(encmsg, u8, padlen);
if (self_id)
encmsg->self_id = (u8 *)tal_dup(encmsg, struct secret, self_id);

return enctlv_from_obs2_encmsg(ctx, blinding, final_node, encmsg,
&unused_next_blinding, node_alias);
}
32 changes: 0 additions & 32 deletions common/blindedpath.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,4 @@ bool decrypt_final_enctlv(const tal_t *ctx,
struct secret **path_id)
NON_NULL_ARGS(1, 2, 4, 5);

/* Obsolete variants */
u8 *create_obs2_enctlv(const tal_t *ctx,
const struct privkey *blinding,
const struct pubkey *node,
const struct pubkey *next_node,
size_t padlen,
const struct pubkey *override_blinding,
struct privkey *next_blinding,
struct pubkey *node_alias)
NON_NULL_ARGS(2, 3, 4, 7, 8);
u8 *create_obs2_final_enctlv(const tal_t *ctx,
const struct privkey *blinding,
const struct pubkey *final_node,
size_t padlen,
const struct secret *self_id,
struct pubkey *node_alias)
NON_NULL_ARGS(2, 3, 6);
bool decrypt_obs2_enctlv(const struct pubkey *blinding,
const struct secret *ss,
const u8 *enctlv,
struct pubkey *next_node,
struct pubkey *next_blinding)
NON_NULL_ARGS(1, 2, 4, 5);
bool decrypt_obs2_final_enctlv(const tal_t *ctx,
const struct pubkey *blinding,
const struct secret *ss,
const u8 *enctlv,
const struct pubkey *my_id,
struct pubkey *alias,
struct secret **self_id)
NON_NULL_ARGS(1, 2, 4, 5);

#endif /* LIGHTNING_COMMON_BLINDEDPATH_H */
1 change: 0 additions & 1 deletion common/gossip_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ static bool public_msg_type(enum peer_wire type)
case WIRE_QUERY_CHANNEL_RANGE:
case WIRE_REPLY_CHANNEL_RANGE:
case WIRE_GOSSIP_TIMESTAMP_FILTER:
case WIRE_OBS2_ONION_MESSAGE:
case WIRE_ONION_MESSAGE:
#if EXPERIMENTAL_FEATURES
case WIRE_STFU:
Expand Down
36 changes: 0 additions & 36 deletions common/json_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -647,42 +647,6 @@ struct wally_psbt *json_to_psbt(const tal_t *ctx, const char *buffer,
return psbt_from_b64(ctx, buffer + tok->start, tok->end - tok->start);
}

struct tlv_obs2_onionmsg_payload_reply_path *
json_to_obs2_reply_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok)
{
struct tlv_obs2_onionmsg_payload_reply_path *rpath;
const jsmntok_t *hops, *t;
size_t i;
const char *err;

rpath = tal(ctx, struct tlv_obs2_onionmsg_payload_reply_path);
err = json_scan(tmpctx, buffer, tok, "{blinding:%,first_node_id:%}",
JSON_SCAN(json_to_pubkey, &rpath->blinding),
JSON_SCAN(json_to_pubkey, &rpath->first_node_id),
NULL);
if (err)
return tal_free(rpath);

hops = json_get_member(buffer, tok, "hops");
if (!hops || hops->size < 1)
return tal_free(rpath);

rpath->path = tal_arr(rpath, struct onionmsg_path *, hops->size);
json_for_each_arr(i, t, hops) {
rpath->path[i] = tal(rpath->path, struct onionmsg_path);
err = json_scan(tmpctx, buffer, t, "{id:%,encrypted_recipient_data:%}",
JSON_SCAN(json_to_pubkey,
&rpath->path[i]->node_id),
JSON_SCAN_TAL(rpath->path[i],
json_tok_bin_from_hex,
&rpath->path[i]->encrypted_recipient_data));
if (err)
return tal_free(rpath);
}

return rpath;
}

struct tlv_onionmsg_payload_reply_path *
json_to_reply_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok)
{
Expand Down
4 changes: 0 additions & 4 deletions common/json_parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ bool json_to_coin_mvt_tag(const char *buffer, const jsmntok_t *tok,
struct tlv_onionmsg_payload_reply_path *
json_to_reply_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok);

/* Obsolete version! */
struct tlv_obs2_onionmsg_payload_reply_path *
json_to_obs2_reply_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok);

bool json_tok_channel_id(const char *buffer, const jsmntok_t *tok,
struct channel_id *cid);

Expand Down
2 changes: 0 additions & 2 deletions connectd/connectd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ msgdata,connectd_ping_reply,totlen,u16,

# We tell lightningd we got an onionmsg
msgtype,connectd_got_onionmsg_to_us,2145
msgdata,connectd_got_onionmsg_to_us,obs2,bool,
msgdata,connectd_got_onionmsg_to_us,node_alias,pubkey,
msgdata,connectd_got_onionmsg_to_us,self_id,?secret,
msgdata,connectd_got_onionmsg_to_us,reply_blinding,?pubkey,
Expand All @@ -130,7 +129,6 @@ msgdata,connectd_got_onionmsg_to_us,rawmsg,u8,rawmsg_len

# Lightningd tells us to send an onion message.
msgtype,connectd_send_onionmsg,2041
msgdata,connectd_send_onionmsg,obs2,bool,
msgdata,connectd_send_onionmsg,id,node_id,
msgdata,connectd_send_onionmsg,onion_len,u16,
msgdata,connectd_send_onionmsg,onion,u8,onion_len
Expand Down
1 change: 0 additions & 1 deletion connectd/gossip_rcvd_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ static bool is_msg_gossip_broadcast(const u8 *cursor)
case WIRE_QUERY_CHANNEL_RANGE:
case WIRE_REPLY_CHANNEL_RANGE:
case WIRE_ONION_MESSAGE:
case WIRE_OBS2_ONION_MESSAGE:
case WIRE_WARNING:
case WIRE_INIT:
case WIRE_PING:
Expand Down
4 changes: 0 additions & 4 deletions connectd/multiplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ static bool is_urgent(enum peer_wire type)
case WIRE_QUERY_CHANNEL_RANGE:
case WIRE_REPLY_CHANNEL_RANGE:
case WIRE_GOSSIP_TIMESTAMP_FILTER:
case WIRE_OBS2_ONION_MESSAGE:
case WIRE_ONION_MESSAGE:
#if EXPERIMENTAL_FEATURES
case WIRE_STFU:
Expand Down Expand Up @@ -754,9 +753,6 @@ static bool handle_message_locally(struct peer *peer, const u8 *msg)
} else if (type == WIRE_PONG) {
handle_pong_in(peer, msg);
return true;
} else if (type == WIRE_OBS2_ONION_MESSAGE) {
handle_obs2_onion_message(peer->daemon, peer, msg);
return true;
} else if (type == WIRE_ONION_MESSAGE) {
handle_onion_message(peer->daemon, peer, msg);
return true;
Expand Down
Loading

0 comments on commit 41ef853

Please sign in to comment.