X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fmeta.c;h=aaa5c30cc313f9e7572f188d71be627893bc9dc7;hb=911c05f873ad967c40d04aa7347b1067fe62c055;hp=2791ea198c2b4e4471f7e0734a613cff686cc9bf;hpb=1b8f8918360b40a2749d40355266ed7dedbe41b5;p=tinc diff --git a/src/meta.c b/src/meta.c index 2791ea19..aaa5c30c 100644 --- a/src/meta.c +++ b/src/meta.c @@ -35,7 +35,8 @@ bool send_meta(connection_t *c, const char *buffer, int length) { cp(); - ifdebug(META) logger(LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length, c->name, c->hostname); + ifdebug(META) logger(LOG_DEBUG, _("Sending %d bytes of metadata to %s (%s)"), length, + c->name, c->hostname); /* Add our data to buffer */ if(c->status.encryptout) { @@ -43,13 +44,18 @@ bool send_meta(connection_t *c, const char *buffer, int length) { size_t outlen = length; if(!cipher_encrypt(&c->outcipher, buffer, length, outbuf, &outlen, false) || outlen != length) { - logger(LOG_ERR, _("Error while encrypting metadata to %s (%s)"), c->name, c->hostname); + logger(LOG_ERR, _("Error while encrypting metadata to %s (%s)"), + c->name, c->hostname); return false; } + ifdebug(META) logger(LOG_DEBUG, _("Encrypted write %p %p %p %d"), c, c->buffer, outbuf, length); bufferevent_write(c->buffer, (void *)outbuf, length); + ifdebug(META) logger(LOG_DEBUG, _("Done.")); } else { + ifdebug(META) logger(LOG_DEBUG, _("Unencrypted write %p %p %p %d"), c, c->buffer, buffer, length); bufferevent_write(c->buffer, (void *)buffer, length); + ifdebug(META) logger(LOG_DEBUG, _("Done.")); } return true; @@ -106,14 +112,16 @@ bool receive_meta(connection_t *c) { bufp = endp; } else { size_t outlen = inlen; - evbuffer_expand(c->buffer->input, inlen); + ifdebug(META) logger(LOG_DEBUG, _("Received encrypted %d bytes"), inlen); + evbuffer_expand(c->buffer->input, c->buffer->input->off + inlen); - if(!cipher_decrypt(&c->incipher, bufp, inlen, c->buffer->input->buffer, &outlen, false) || inlen != outlen) { - logger(LOG_ERR, _("Error while decrypting metadata from %s (%s)"), c->name, c->hostname); + if(!cipher_decrypt(&c->incipher, bufp, inlen, c->buffer->input->buffer + c->buffer->input->off, &outlen, false) || inlen != outlen) { + logger(LOG_ERR, _("Error while decrypting metadata from %s (%s)"), + c->name, c->hostname); return false; } - c->buffer->input->off += inlen; + inlen = 0; }