Move RSA key generation into the wrappers.
[tinc] / src / meta.c
index 2791ea1..82dde3a 100644 (file)
@@ -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 %zu 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;
                }