| 132 | } |
| 133 | |
| 134 | static u8 *sync_crypto_read(const tal_t *ctx, int peer_fd, struct crypto_state *cs) |
| 135 | { |
| 136 | u8 hdr[18], *enc, *dec; |
| 137 | u16 len; |
| 138 | |
| 139 | if (!read_all(peer_fd, hdr, sizeof(hdr))) { |
| 140 | status_debug("Failed reading header: %s", strerror(errno)); |
| 141 | exit(0); |
| 142 | } |
| 143 | |
| 144 | if (!cryptomsg_decrypt_header(cs, hdr, &len)) { |
| 145 | status_debug("Failed hdr decrypt with rn=%"PRIu64, |
| 146 | cs->rn-1); |
| 147 | exit(1); |
| 148 | } |
| 149 | |
| 150 | enc = tal_arr(ctx, u8, len + 16); |
| 151 | if (!read_all(peer_fd, enc, tal_count(enc))) { |
| 152 | status_debug("Failed reading body: %s", strerror(errno)); |
| 153 | exit(1); |
| 154 | } |
| 155 | |
| 156 | dec = cryptomsg_decrypt_body(ctx, cs, enc); |
| 157 | tal_free(enc); |
| 158 | if (!dec) |
| 159 | exit(1); |
| 160 | else |
| 161 | status_peer_io(LOG_IO_IN, NULL, dec); |
| 162 | |
| 163 | return dec; |
| 164 | } |
| 165 | |
| 166 | static struct io_plan *handshake_success(struct io_conn *conn, |
| 167 | const struct pubkey *them, |
no test coverage detected