mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
sphinx: Fixed the onion generation and decoding tool
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
@@ -28,6 +28,7 @@ static void do_generate(int argc, char **argv)
|
|||||||
if (secp256k1_ec_pubkey_create(secp256k1_ctx, &path[i].pubkey,
|
if (secp256k1_ec_pubkey_create(secp256k1_ctx, &path[i].pubkey,
|
||||||
privkeys[i]) != 1)
|
privkeys[i]) != 1)
|
||||||
errx(1, "Could not decode pubkey");
|
errx(1, "Could not decode pubkey");
|
||||||
|
printf("Node %d pubkey %s\n", i, secp256k1_pubkey_to_hexstr(ctx, &path[i].pubkey));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < num_hops; i++) {
|
for (int i = 0; i < num_hops; i++) {
|
||||||
@@ -47,10 +48,9 @@ static void do_generate(int argc, char **argv)
|
|||||||
u8 *serialized = serialize_onionpacket(ctx, res);
|
u8 *serialized = serialize_onionpacket(ctx, res);
|
||||||
if (!serialized)
|
if (!serialized)
|
||||||
errx(1, "Error serializing message.");
|
errx(1, "Error serializing message.");
|
||||||
|
else
|
||||||
char hextemp[2 * tal_count(serialized) + 1];
|
printf("%s\n", tal_hex(ctx, serialized));
|
||||||
hex_encode(serialized, tal_count(serialized), hextemp, sizeof(hextemp));
|
tal_free(ctx);
|
||||||
printf("%s\n", hextemp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_decode(int argc, char **argv)
|
static void do_decode(int argc, char **argv)
|
||||||
@@ -65,15 +65,21 @@ static void do_decode(int argc, char **argv)
|
|||||||
u8 shared_secret[32];
|
u8 shared_secret[32];
|
||||||
u8 assocdata[32];
|
u8 assocdata[32];
|
||||||
|
|
||||||
|
memset(&assocdata, 'B', sizeof(assocdata));
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
opt_usage_exit_fail("Expect a privkey with --decode");
|
opt_usage_exit_fail("Expect a privkey with --decode");
|
||||||
|
|
||||||
if (!hex_decode(argv[1], strlen(argv[1]), &seckey, sizeof(seckey)))
|
if (!hex_decode(argv[1], strlen(argv[1]), &seckey, sizeof(seckey)))
|
||||||
errx(1, "Invalid private key hex '%s'", argv[1]);
|
errx(1, "Invalid private key hex '%s'", argv[1]);
|
||||||
|
|
||||||
if (!read_all(STDIN_FILENO, hextemp, sizeof(hextemp)))
|
if (!read_all(STDIN_FILENO, hextemp, sizeof(hextemp)))
|
||||||
errx(1, "Reading in onion");
|
errx(1, "Reading in onion");
|
||||||
|
|
||||||
hex_decode(hextemp, sizeof(hextemp), serialized, sizeof(serialized));
|
hex_decode(hextemp, sizeof(hextemp), serialized, sizeof(serialized));
|
||||||
|
|
||||||
msg = parse_onionpacket(ctx, serialized, sizeof(serialized));
|
msg = parse_onionpacket(ctx, serialized, sizeof(serialized));
|
||||||
|
|
||||||
if (!msg)
|
if (!msg)
|
||||||
errx(1, "Error parsing message.");
|
errx(1, "Error parsing message.");
|
||||||
|
|
||||||
@@ -83,15 +89,15 @@ static void do_decode(int argc, char **argv)
|
|||||||
step = process_onionpacket(ctx, msg, shared_secret, assocdata,
|
step = process_onionpacket(ctx, msg, shared_secret, assocdata,
|
||||||
sizeof(assocdata));
|
sizeof(assocdata));
|
||||||
|
|
||||||
if (!step->next)
|
if (!step || !step->next)
|
||||||
errx(1, "Error processing message.");
|
errx(1, "Error processing message.");
|
||||||
|
|
||||||
u8 *ser = serialize_onionpacket(ctx, step->next);
|
u8 *ser = serialize_onionpacket(ctx, step->next);
|
||||||
if (!ser)
|
if (!ser)
|
||||||
errx(1, "Error serializing message.");
|
errx(1, "Error serializing message.");
|
||||||
|
|
||||||
hex_encode(ser, tal_count(ser), hextemp, sizeof(hextemp));
|
printf("%s\n", tal_hex(ctx, ser));
|
||||||
printf("%s\n", hextemp);
|
tal_free(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
|||||||
Reference in New Issue
Block a user