| 1124 | } |
| 1125 | |
| 1126 | struct command_result *handle_invoice_request(struct command *cmd, |
| 1127 | const u8 *invreqbin, |
| 1128 | struct blinded_path *reply_path, |
| 1129 | const struct secret *secret) |
| 1130 | { |
| 1131 | struct out_req *req; |
| 1132 | int bad_feature; |
| 1133 | size_t len = tal_count(invreqbin); |
| 1134 | const u8 *cursor = invreqbin; |
| 1135 | struct invreq *ir = tal(cmd, struct invreq); |
| 1136 | char *err; |
| 1137 | |
| 1138 | ir->reply_path = tal_steal(ir, reply_path); |
| 1139 | ir->secret = tal_dup_or_null(ir, struct secret, secret); |
| 1140 | ir->invreq = fromwire_tlv_invoice_request(cmd, &cursor, &len); |
| 1141 | |
| 1142 | if (!ir->invreq) { |
| 1143 | return fail_invreq(cmd, ir, "Invalid invreq"); |
| 1144 | } |
| 1145 | |
| 1146 | /* BOLT #12: |
| 1147 | * The reader: |
| 1148 | * ... |
| 1149 | * - MUST reject the invoice request if any non-signature TLV fields are outside the inclusive ranges: 0 to 159 and 1000000000 to 2999999999 |
| 1150 | */ |
| 1151 | /* BOLT #12: |
| 1152 | * Each form is signed using one or more *signature TLV elements*: |
| 1153 | * TLV types 240 through 1000 (inclusive) |
| 1154 | */ |
| 1155 | if (any_field_outside_range(ir->invreq->fields, true, |
| 1156 | 0, 159, |
| 1157 | 1000000000, 2999999999)) { |
| 1158 | return fail_invreq(cmd, ir, "Invalid high fields"); |
| 1159 | } |
| 1160 | |
| 1161 | /* BOLT #12: |
| 1162 | * |
| 1163 | * The reader: |
| 1164 | * - MUST reject the invoice request if `invreq_payer_id` or `invreq_metadata` |
| 1165 | * are not present. |
| 1166 | */ |
| 1167 | if (!ir->invreq->invreq_payer_id) |
| 1168 | return fail_invreq(cmd, ir, "Missing invreq_payer_id"); |
| 1169 | if (!ir->invreq->invreq_metadata) |
| 1170 | return fail_invreq(cmd, ir, "Missing invreq_metadata"); |
| 1171 | |
| 1172 | /* BOLT #12: |
| 1173 | * |
| 1174 | * The reader: |
| 1175 | *... |
| 1176 | * - if `invreq_features` contains unknown _even_ bits that are non-zero: |
| 1177 | * - MUST reject the invoice request. |
| 1178 | */ |
| 1179 | bad_feature = features_unsupported(plugin_feature_set(cmd->plugin), |
| 1180 | ir->invreq->invreq_features, |
| 1181 | BOLT12_INVREQ_FEATURE); |
| 1182 | if (bad_feature != -1) { |
| 1183 | return fail_invreq(cmd, ir, |
no test coverage detected