| 103 | } |
| 104 | |
| 105 | static u8 *next_onion(const tal_t *ctx, u8 *omsg, |
| 106 | const struct privkey *nodekey, |
| 107 | const struct pubkey *expected_blinding) |
| 108 | { |
| 109 | struct onionpacket *op; |
| 110 | struct pubkey blinding, ephemeral; |
| 111 | struct pubkey next_node, next_blinding; |
| 112 | struct tlv_onionmsg_payload *om; |
| 113 | struct secret ss, onion_ss; |
| 114 | const u8 *cursor; |
| 115 | size_t max, maxlen; |
| 116 | struct route_step *rs; |
| 117 | |
| 118 | assert(fromwire_onion_message(tmpctx, omsg, &blinding, &omsg)); |
| 119 | assert(pubkey_eq(&blinding, expected_blinding)); |
| 120 | |
| 121 | op = parse_onionpacket(tmpctx, omsg, tal_bytelen(omsg), NULL); |
| 122 | ephemeral = op->ephemeralkey; |
| 123 | |
| 124 | ecdh_key = nodekey; |
| 125 | assert(unblind_onion(&blinding, ecdh, &ephemeral, &ss)); |
| 126 | |
| 127 | ecdh(&ephemeral, &onion_ss); |
| 128 | rs = process_onionpacket(tmpctx, op, &onion_ss, NULL, 0, false); |
| 129 | assert(rs); |
| 130 | |
| 131 | /* The raw payload is prepended with length in the modern onion. */ |
| 132 | cursor = rs->raw_payload; |
| 133 | max = tal_bytelen(rs->raw_payload); |
| 134 | maxlen = fromwire_bigsize(&cursor, &max); |
| 135 | om = fromwire_tlv_onionmsg_payload(tmpctx, &cursor, &maxlen); |
| 136 | |
| 137 | if (rs->nextcase == ONION_END) |
| 138 | return NULL; |
| 139 | |
| 140 | assert(decrypt_enctlv(&blinding, &ss, om->encrypted_data_tlv, &next_node, |
| 141 | &next_blinding)); |
| 142 | return towire_onion_message(ctx, &next_blinding, |
| 143 | serialize_onionpacket(tmpctx, rs->next)); |
| 144 | } |
| 145 | |
| 146 | int main(int argc, char *argv[]) |
| 147 | { |
no test coverage detected