mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-15 02:54:21 +01:00
common: rename current onion message structures to obs2_.
Yes, we changed the spec again. Hopefully for the last time! Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -61,7 +61,7 @@ static bool blind_node(const struct privkey *blinding,
|
||||
static u8 *enctlv_from_encmsg(const tal_t *ctx,
|
||||
const struct privkey *blinding,
|
||||
const struct pubkey *node,
|
||||
const struct tlv_encmsg_tlvs *encmsg,
|
||||
const struct tlv_obs2_encmsg_tlvs *encmsg,
|
||||
struct privkey *next_blinding,
|
||||
struct pubkey *node_alias)
|
||||
{
|
||||
@@ -89,7 +89,7 @@ static u8 *enctlv_from_encmsg(const tal_t *ctx,
|
||||
|
||||
/* Marshall */
|
||||
ret = tal_arr(ctx, u8, 0);
|
||||
towire_encmsg_tlvs(&ret, encmsg);
|
||||
towire_obs2_encmsg_tlvs(&ret, encmsg);
|
||||
SUPERVERBOSE("\t\"encmsg_hex\": \"%s\",\n", tal_hex(tmpctx, ret));
|
||||
|
||||
/*
|
||||
@@ -136,16 +136,16 @@ bool unblind_onion(const struct pubkey *blinding,
|
||||
hmac.data) == 1;
|
||||
}
|
||||
|
||||
static struct tlv_encmsg_tlvs *decrypt_encmsg(const tal_t *ctx,
|
||||
const struct pubkey *blinding,
|
||||
const struct secret *ss,
|
||||
const u8 *enctlv)
|
||||
static struct tlv_obs2_encmsg_tlvs *decrypt_encmsg(const tal_t *ctx,
|
||||
const struct pubkey *blinding,
|
||||
const struct secret *ss,
|
||||
const u8 *enctlv)
|
||||
{
|
||||
struct secret rho;
|
||||
u8 *dec;
|
||||
const u8 *cursor;
|
||||
size_t maxlen;
|
||||
struct tlv_encmsg_tlvs *encmsg;
|
||||
struct tlv_obs2_encmsg_tlvs *encmsg;
|
||||
/* All-zero npub */
|
||||
static const unsigned char npub[crypto_aead_chacha20poly1305_ietf_NPUBBYTES];
|
||||
|
||||
@@ -179,21 +179,21 @@ static struct tlv_encmsg_tlvs *decrypt_encmsg(const tal_t *ctx,
|
||||
* - if the `enctlv` is not a valid TLV...
|
||||
* - MUST drop the message.
|
||||
*/
|
||||
encmsg = tlv_encmsg_tlvs_new(ctx);
|
||||
if (!fromwire_encmsg_tlvs(&cursor, &maxlen, encmsg)
|
||||
encmsg = tlv_obs2_encmsg_tlvs_new(ctx);
|
||||
if (!fromwire_obs2_encmsg_tlvs(&cursor, &maxlen, encmsg)
|
||||
|| !tlv_fields_valid(encmsg->fields, NULL, NULL))
|
||||
return tal_free(encmsg);
|
||||
|
||||
return encmsg;
|
||||
}
|
||||
|
||||
bool decrypt_enctlv(const struct pubkey *blinding,
|
||||
const struct secret *ss,
|
||||
const u8 *enctlv,
|
||||
struct pubkey *next_node,
|
||||
struct pubkey *next_blinding)
|
||||
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_encmsg_tlvs *encmsg;
|
||||
struct tlv_obs2_encmsg_tlvs *encmsg;
|
||||
|
||||
encmsg = decrypt_encmsg(tmpctx, blinding, ss, enctlv);
|
||||
if (!encmsg)
|
||||
@@ -244,15 +244,15 @@ bool decrypt_enctlv(const struct pubkey *blinding,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool decrypt_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)
|
||||
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_encmsg_tlvs *encmsg;
|
||||
struct tlv_obs2_encmsg_tlvs *encmsg;
|
||||
struct secret node_id_blinding;
|
||||
|
||||
/* Repeat the tweak to get the alias it was using for us */
|
||||
@@ -276,16 +276,16 @@ bool decrypt_final_enctlv(const tal_t *ctx,
|
||||
return true;
|
||||
}
|
||||
|
||||
u8 *create_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)
|
||||
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_encmsg_tlvs *encmsg = tlv_encmsg_tlvs_new(tmpctx);
|
||||
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);
|
||||
@@ -295,14 +295,14 @@ u8 *create_enctlv(const tal_t *ctx,
|
||||
next_blinding, node_alias);
|
||||
}
|
||||
|
||||
u8 *create_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)
|
||||
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_encmsg_tlvs *encmsg = tlv_encmsg_tlvs_new(tmpctx);
|
||||
struct tlv_obs2_encmsg_tlvs *encmsg = tlv_obs2_encmsg_tlvs_new(tmpctx);
|
||||
struct privkey unused_next_blinding;
|
||||
|
||||
if (padlen)
|
||||
|
||||
@@ -23,7 +23,7 @@ struct secret;
|
||||
*
|
||||
* Returns the enctlv blob, or NULL if the secret is invalid.
|
||||
*/
|
||||
u8 *create_enctlv(const tal_t *ctx,
|
||||
u8 *create_obs2_enctlv(const tal_t *ctx,
|
||||
const struct privkey *blinding,
|
||||
const struct pubkey *node,
|
||||
const struct pubkey *next_node,
|
||||
@@ -44,7 +44,7 @@ u8 *create_enctlv(const tal_t *ctx,
|
||||
*
|
||||
* If it fails, it means one of the privkeys is bad.
|
||||
*/
|
||||
u8 *create_final_enctlv(const tal_t *ctx,
|
||||
u8 *create_obs2_final_enctlv(const tal_t *ctx,
|
||||
const struct privkey *blinding,
|
||||
const struct pubkey *final_node,
|
||||
size_t padlen,
|
||||
@@ -77,7 +77,7 @@ bool unblind_onion(const struct pubkey *blinding,
|
||||
*
|
||||
* Returns false if decryption failed or encmsg was malformed.
|
||||
*/
|
||||
bool decrypt_enctlv(const struct pubkey *blinding,
|
||||
bool decrypt_obs2_enctlv(const struct pubkey *blinding,
|
||||
const struct secret *ss,
|
||||
const u8 *enctlv,
|
||||
struct pubkey *next_node,
|
||||
@@ -96,7 +96,7 @@ bool decrypt_enctlv(const struct pubkey *blinding,
|
||||
*
|
||||
* Returns false if decryption failed or encmsg was malformed.
|
||||
*/
|
||||
bool decrypt_final_enctlv(const tal_t *ctx,
|
||||
bool decrypt_obs2_final_enctlv(const tal_t *ctx,
|
||||
const struct pubkey *blinding,
|
||||
const struct secret *ss,
|
||||
const u8 *enctlv,
|
||||
|
||||
@@ -141,15 +141,15 @@ 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_onionmsg_payload_reply_path *
|
||||
json_to_reply_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok)
|
||||
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_onionmsg_payload_reply_path *rpath;
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *rpath;
|
||||
const jsmntok_t *hops, *t;
|
||||
size_t i;
|
||||
const char *err;
|
||||
|
||||
rpath = tal(ctx, struct tlv_onionmsg_payload_reply_path);
|
||||
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),
|
||||
|
||||
@@ -80,8 +80,8 @@ bool split_tok(const char *buffer, const jsmntok_t *tok,
|
||||
jsmntok_t *b);
|
||||
|
||||
/* Extract reply path from this JSON */
|
||||
struct tlv_onionmsg_payload_reply_path *
|
||||
json_to_reply_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok);
|
||||
struct tlv_obs2_onionmsg_payload_reply_path *
|
||||
json_to_obs2_reply_path(const tal_t *ctx, const char *buffer, const jsmntok_t *tok);
|
||||
|
||||
/* Helpers for outputting JSON results */
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ static void test_decrypt(const struct pubkey *blinding,
|
||||
|
||||
mykey = me;
|
||||
assert(unblind_onion(blinding, test_ecdh, &dummy, &ss));
|
||||
assert(decrypt_enctlv(blinding, &ss, enctlv, &next_node, &next_blinding));
|
||||
assert(decrypt_obs2_enctlv(blinding, &ss, enctlv, &next_node, &next_blinding));
|
||||
|
||||
pubkey_from_privkey(expected_next_blinding_priv, &expected_next_blinding);
|
||||
assert(pubkey_eq(&next_blinding, &expected_next_blinding));
|
||||
@@ -106,8 +106,8 @@ static void test_final_decrypt(const struct pubkey *blinding,
|
||||
mykey = me;
|
||||
pubkey_from_privkey(me, &my_pubkey);
|
||||
assert(unblind_onion(blinding, test_ecdh, &dummy, &ss));
|
||||
assert(decrypt_final_enctlv(tmpctx, blinding, &ss, enctlv, &my_pubkey,
|
||||
&alias, &self_id));
|
||||
assert(decrypt_obs2_final_enctlv(tmpctx, blinding, &ss, enctlv, &my_pubkey,
|
||||
&alias, &self_id));
|
||||
|
||||
assert(pubkey_eq(&alias, expected_alias));
|
||||
assert(secret_eq_consttime(self_id, expected_self_id));
|
||||
@@ -150,8 +150,8 @@ int main(int argc, char *argv[])
|
||||
"\t},\n",
|
||||
type_to_string(tmpctx, struct pubkey, &bob_id));
|
||||
|
||||
enctlv = create_enctlv(tmpctx, &blinding, &alice_id, &bob_id,
|
||||
0, NULL, &blinding, &alias);
|
||||
enctlv = create_obs2_enctlv(tmpctx, &blinding, &alice_id, &bob_id,
|
||||
0, NULL, &blinding, &alias);
|
||||
printf("\t\"enctlv_hex\": \"%s\"\n"
|
||||
"},\n",
|
||||
tal_hex(tmpctx, enctlv));
|
||||
@@ -180,8 +180,8 @@ int main(int argc, char *argv[])
|
||||
type_to_string(tmpctx, struct pubkey, &carol_id),
|
||||
type_to_string(tmpctx, struct privkey, &override_blinding));
|
||||
|
||||
enctlv = create_enctlv(tmpctx, &blinding, &bob_id, &carol_id,
|
||||
0, &override_blinding_pub, &blinding, &alias);
|
||||
enctlv = create_obs2_enctlv(tmpctx, &blinding, &bob_id, &carol_id,
|
||||
0, &override_blinding_pub, &blinding, &alias);
|
||||
printf("\t\"enctlv_hex\": \"%s\"\n"
|
||||
"},\n",
|
||||
tal_hex(tmpctx, enctlv));
|
||||
@@ -209,8 +209,8 @@ int main(int argc, char *argv[])
|
||||
type_to_string(tmpctx, struct pubkey, &dave_id),
|
||||
tal_hex(tmpctx, tal_arrz(tmpctx, u8, 35)));
|
||||
|
||||
enctlv = create_enctlv(tmpctx, &blinding, &carol_id, &dave_id,
|
||||
35, NULL, &blinding, &alias);
|
||||
enctlv = create_obs2_enctlv(tmpctx, &blinding, &carol_id, &dave_id,
|
||||
35, NULL, &blinding, &alias);
|
||||
printf("\t\"enctlv_hex\": \"%s\"\n"
|
||||
"}]\n",
|
||||
tal_hex(tmpctx, enctlv));
|
||||
@@ -220,8 +220,8 @@ int main(int argc, char *argv[])
|
||||
/* FIXME: Add this to the test vectors! */
|
||||
fclose(stdout);
|
||||
memset(&self_id, 0x77, sizeof(self_id));
|
||||
enctlv = create_final_enctlv(tmpctx, &blinding, &dave_id,
|
||||
0, &self_id, &alias);
|
||||
enctlv = create_obs2_final_enctlv(tmpctx, &blinding, &dave_id,
|
||||
0, &self_id, &alias);
|
||||
|
||||
pubkey_from_privkey(&blinding, &blinding_pub);
|
||||
test_final_decrypt(&blinding_pub, enctlv, &dave, &alias, &self_id);
|
||||
|
||||
Reference in New Issue
Block a user