| 1818 | } |
| 1819 | |
| 1820 | u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann, |
| 1821 | struct peer *peer, bool *was_unknown) |
| 1822 | { |
| 1823 | u8 *serialized; |
| 1824 | struct sha256_double hash; |
| 1825 | secp256k1_ecdsa_signature signature; |
| 1826 | u32 timestamp; |
| 1827 | struct node_id node_id; |
| 1828 | u8 rgb_color[3]; |
| 1829 | u8 alias[32]; |
| 1830 | u8 *features, *addresses; |
| 1831 | struct wireaddr *wireaddrs; |
| 1832 | size_t len = tal_count(node_ann); |
| 1833 | struct tlv_node_ann_tlvs *na_tlv; |
| 1834 | |
| 1835 | if (was_unknown) |
| 1836 | *was_unknown = false; |
| 1837 | |
| 1838 | serialized = tal_dup_arr(tmpctx, u8, node_ann, len, 0); |
| 1839 | if (!fromwire_node_announcement(tmpctx, serialized, |
| 1840 | &signature, &features, ×tamp, |
| 1841 | &node_id, rgb_color, alias, |
| 1842 | &addresses, |
| 1843 | &na_tlv)) { |
| 1844 | /* BOLT #7: |
| 1845 | * |
| 1846 | * - if `node_id` is NOT a valid compressed public key: |
| 1847 | * - SHOULD send a `warning`. |
| 1848 | * - MAY close the connection. |
| 1849 | * - MUST NOT process the message further. |
| 1850 | */ |
| 1851 | u8 *warn = towire_warningfmt(rstate, NULL, |
| 1852 | "Malformed node_announcement %s", |
| 1853 | tal_hex(tmpctx, node_ann)); |
| 1854 | return warn; |
| 1855 | } |
| 1856 | |
| 1857 | sha256_double(&hash, serialized + 66, tal_count(serialized) - 66); |
| 1858 | /* If node_id is invalid, it fails here */ |
| 1859 | if (!check_signed_hash_nodeid(&hash, &signature, &node_id)) { |
| 1860 | /* BOLT #7: |
| 1861 | * |
| 1862 | * - if `signature` is not a valid signature, using |
| 1863 | * `node_id` of the double-SHA256 of the entire |
| 1864 | * message following the `signature` field |
| 1865 | * (including unknown fields following |
| 1866 | * `fee_proportional_millionths`): |
| 1867 | * - SHOULD send a `warning` and close the connection. |
| 1868 | * - MUST NOT process the message further. |
| 1869 | */ |
| 1870 | u8 *warn = towire_warningfmt(rstate, NULL, |
| 1871 | "Bad signature for %s hash %s" |
| 1872 | " on node_announcement %s", |
| 1873 | type_to_string(tmpctx, |
| 1874 | secp256k1_ecdsa_signature, |
| 1875 | &signature), |
| 1876 | type_to_string(tmpctx, |
| 1877 | struct sha256_double, |
no test coverage detected