Returns warning msg if signature wrong, else NULL */
| 116 | |
| 117 | /* Returns warning msg if signature wrong, else NULL */ |
| 118 | const char *sigcheck_node_announcement(const tal_t *ctx, |
| 119 | const struct node_id *node_id, |
| 120 | const secp256k1_ecdsa_signature *signature, |
| 121 | const u8 *node_announcement) |
| 122 | { |
| 123 | /* BOLT #7: |
| 124 | * |
| 125 | * 1. type: 257 (`node_announcement`) |
| 126 | * 2. data: |
| 127 | * * [`signature`:`signature`] |
| 128 | * * [`u16`:`flen`] |
| 129 | * * [`flen*byte`:`features`] |
| 130 | * * [`u32`:`timestamp`] |
| 131 | * * [`point`:`node_id`] |
| 132 | * * [`3*byte`:`rgb_color`] |
| 133 | * * [`32*byte`:`alias`] |
| 134 | * * [`u16`:`addrlen`] |
| 135 | * * [`addrlen*byte`:`addresses`] |
| 136 | */ |
| 137 | /* 2 byte msg type + 64 byte signatures */ |
| 138 | int offset = 66; |
| 139 | struct sha256_double hash; |
| 140 | |
| 141 | sha256_double(&hash, node_announcement + offset, tal_count(node_announcement) - offset); |
| 142 | /* If node_id is invalid, it fails here */ |
| 143 | if (!check_signed_hash_nodeid(&hash, signature, node_id)) { |
| 144 | /* BOLT #7: |
| 145 | * |
| 146 | * - if `signature` is not a valid signature, using |
| 147 | * `node_id` of the double-SHA256 of the entire |
| 148 | * message following the `signature` field |
| 149 | * (including unknown fields following |
| 150 | * `fee_proportional_millionths`): |
| 151 | * - SHOULD send a `warning` and close the connection. |
| 152 | * - MUST NOT process the message further. |
| 153 | */ |
| 154 | return tal_fmt(ctx, |
| 155 | "Bad signature for %s hash %s" |
| 156 | " on node_announcement %s", |
| 157 | fmt_secp256k1_ecdsa_signature(tmpctx, |
| 158 | signature), |
| 159 | fmt_sha256_double(tmpctx, &hash), |
| 160 | tal_hex(tmpctx, node_announcement)); |
| 161 | } |
| 162 | |
| 163 | return NULL; |
| 164 | } |
no test coverage detected