- EVP_EncryptUpdate(c->outctx, outbuf, &outlen, buffer, length);
- bufp = outbuf;
- length = outlen;
- } else
- bufp = buffer;
-
- if(write(c->socket, bufp, length) < 0) {
- syslog(LOG_ERR, _("Sending meta data to %s (%s) failed: %s"), c->name,
- c->hostname, strerror(errno));
- return -1;
+ char outbuf[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);
+ 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.");