mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
sphinx: explain why parse_onionpacket fails.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
66de6b84be
commit
59febcb968
@ -534,9 +534,12 @@ static struct secret *get_shared_secret(const tal_t *ctx,
|
||||
struct onionpacket *op;
|
||||
struct secret *secret = tal(ctx, struct secret);
|
||||
const u8 *msg;
|
||||
/* FIXME: Use this! */
|
||||
enum onion_type why_bad;
|
||||
|
||||
/* We unwrap the onion now. */
|
||||
op = parse_onionpacket(tmpctx, htlc->routing, TOTAL_PACKET_SIZE);
|
||||
op = parse_onionpacket(tmpctx, htlc->routing, TOTAL_PACKET_SIZE,
|
||||
&why_bad);
|
||||
if (!op)
|
||||
return tal_free(secret);
|
||||
|
||||
|
@ -75,30 +75,31 @@ u8 *serialize_onionpacket(
|
||||
return dst;
|
||||
}
|
||||
|
||||
struct onionpacket *parse_onionpacket(
|
||||
const tal_t *ctx,
|
||||
const void *src,
|
||||
const size_t srclen
|
||||
)
|
||||
struct onionpacket *parse_onionpacket(const tal_t *ctx,
|
||||
const void *src,
|
||||
const size_t srclen,
|
||||
enum onion_type *why_bad)
|
||||
{
|
||||
struct onionpacket *m;
|
||||
int p = 0;
|
||||
u8 rawEphemeralkey[33];
|
||||
|
||||
if (srclen != TOTAL_PACKET_SIZE)
|
||||
return NULL;
|
||||
assert(srclen == TOTAL_PACKET_SIZE);
|
||||
|
||||
m = talz(ctx, struct onionpacket);
|
||||
|
||||
read_buffer(&m->version, src, 1, &p);
|
||||
if (m->version != 0x00) {
|
||||
// FIXME add logging
|
||||
*why_bad = WIRE_INVALID_ONION_VERSION;
|
||||
return tal_free(m);
|
||||
}
|
||||
read_buffer(rawEphemeralkey, src, 33, &p);
|
||||
|
||||
if (secp256k1_ec_pubkey_parse(secp256k1_ctx, &m->ephemeralkey, rawEphemeralkey, 33) != 1)
|
||||
if (secp256k1_ec_pubkey_parse(secp256k1_ctx, &m->ephemeralkey, rawEphemeralkey, 33) != 1) {
|
||||
*why_bad = WIRE_INVALID_ONION_KEY;
|
||||
return tal_free(m);
|
||||
}
|
||||
|
||||
read_buffer(&m->routinginfo, src, ROUTING_INFO_SIZE, &p);
|
||||
read_buffer(&m->mac, src, SECURITY_PARAMETER, &p);
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <secp256k1.h>
|
||||
#include <sodium/randombytes.h>
|
||||
#include <wire/gen_onion_wire.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
#define SECURITY_PARAMETER 32
|
||||
@ -148,13 +149,13 @@ u8 *serialize_onionpacket(
|
||||
*
|
||||
* @ctx: tal context to allocate from
|
||||
* @src: buffer to read the packet from
|
||||
* @srclen: length of the @src
|
||||
* @srclen: length of the @src (must be TOTAL_PACKET_SIZE)
|
||||
* @why_bad: if NULL return, this is what was wrong with the packet.
|
||||
*/
|
||||
struct onionpacket *parse_onionpacket(
|
||||
const tal_t *ctx,
|
||||
const void *src,
|
||||
const size_t srclen
|
||||
);
|
||||
struct onionpacket *parse_onionpacket(const tal_t *ctx,
|
||||
const void *src,
|
||||
const size_t srclen,
|
||||
enum onion_type *why_bad);
|
||||
|
||||
struct onionreply {
|
||||
/* Node index in the path that is replying */
|
||||
|
@ -14,7 +14,8 @@ DEVTOOLS_COMMON_OBJS := \
|
||||
common/type_to_string.o \
|
||||
common/utils.o \
|
||||
common/version.o \
|
||||
common/wireaddr.o
|
||||
common/wireaddr.o \
|
||||
wire/gen_onion_wire.o
|
||||
|
||||
devtools-all: $(DEVTOOLS)
|
||||
|
||||
|
@ -66,6 +66,7 @@ static void do_decode(int argc, char **argv)
|
||||
memset(hextemp, 0, sizeof(hextemp));
|
||||
u8 shared_secret[32];
|
||||
u8 assocdata[32];
|
||||
enum onion_type why_bad;
|
||||
|
||||
memset(&assocdata, 'B', sizeof(assocdata));
|
||||
|
||||
@ -82,10 +83,10 @@ static void do_decode(int argc, char **argv)
|
||||
errx(1, "Invalid onion hex '%s'", hextemp);
|
||||
}
|
||||
|
||||
msg = parse_onionpacket(ctx, serialized, sizeof(serialized));
|
||||
msg = parse_onionpacket(ctx, serialized, sizeof(serialized), &why_bad);
|
||||
|
||||
if (!msg)
|
||||
errx(1, "Error parsing message.");
|
||||
errx(1, "Error parsing message: %s", onion_type_name(why_bad));
|
||||
|
||||
if (!onion_shared_secret(shared_secret, msg, &seckey))
|
||||
errx(1, "Error creating shared secret.");
|
||||
|
@ -648,7 +648,8 @@ static bool peer_accepted_htlc(struct channel *channel,
|
||||
|
||||
/* channeld tests this, so it should pass. */
|
||||
op = parse_onionpacket(tmpctx, hin->onion_routing_packet,
|
||||
sizeof(hin->onion_routing_packet));
|
||||
sizeof(hin->onion_routing_packet),
|
||||
failcode);
|
||||
if (!op) {
|
||||
channel_internal_error(channel,
|
||||
"bad onion in got_revoke: %s",
|
||||
|
@ -367,11 +367,10 @@ struct command_result *param_tok(struct command *cmd UNNEEDED, const char *name
|
||||
const jsmntok_t **out UNNEEDED)
|
||||
{ fprintf(stderr, "param_tok called!\n"); abort(); }
|
||||
/* Generated stub for parse_onionpacket */
|
||||
struct onionpacket *parse_onionpacket(
|
||||
const tal_t *ctx UNNEEDED,
|
||||
const void *src UNNEEDED,
|
||||
const size_t srclen
|
||||
)
|
||||
struct onionpacket *parse_onionpacket(const tal_t *ctx UNNEEDED,
|
||||
const void *src UNNEEDED,
|
||||
const size_t srclen UNNEEDED,
|
||||
enum onion_type *why_bad UNNEEDED)
|
||||
{ fprintf(stderr, "parse_onionpacket called!\n"); abort(); }
|
||||
/* Generated stub for payment_failed */
|
||||
void payment_failed(struct lightningd *ld UNNEEDED, const struct htlc_out *hout UNNEEDED,
|
||||
|
Loading…
Reference in New Issue
Block a user