const EVP_CIPHER *outcipher; /* Cipher we will use to send data to him */
EVP_CIPHER_CTX *inctx; /* Context of encrypted meta data that will come from him to us */
EVP_CIPHER_CTX *outctx; /* Context of encrypted meta data that will be sent from us to him */
+ uint64_t inbudget; /* Encrypted bytes send budget */
+ uint64_t outbudget; /* Encrypted bytes receive budget */
char *inkey; /* His symmetric meta key + iv */
char *outkey; /* Our symmetric meta key + iv */
int inkeylength; /* Length of his key + iv */
/* Add our data to buffer */
if(c->status.encryptout) {
+ /* Check encryption limits */
+ if(length > c->outbudget) {
+ ifdebug(META) logger(LOG_ERR, "Byte limit exceeded for encryption to %s (%s)", c->name, c->hostname);
+ return false;
+ } else {
+ c->outbudget -= length;
+ }
+
result = EVP_EncryptUpdate(c->outctx, (unsigned char *)c->outbuf + c->outbufstart + c->outbuflen,
&outlen, (unsigned char *)buffer, length);
if(!result || outlen < length) {
/* Decrypt */
if(c->status.decryptin && !decrypted) {
+ /* Check decryption limits */
+ if(lenin > c->inbudget) {
+ ifdebug(META) logger(LOG_ERR, "Byte limit exceeded for decryption from %s (%s)", c->name, c->hostname);
+ return false;
+ } else {
+ c->inbudget -= lenin;
+ }
+
result = EVP_DecryptUpdate(c->inctx, (unsigned char *)inbuf, &lenout, (unsigned char *)c->buffer + oldlen, lenin);
if(!result || lenout != lenin) {
logger(LOG_ERR, "Error while decrypting metadata from %s (%s): %s",
return false;
}
+ c->outbudget = (uint64_t)4 << EVP_CIPHER_key_length(c->outcipher);
c->status.encryptout = true;
}
return false;
}
+ c->inbudget = (uint64_t)4 << EVP_CIPHER_key_length(c->incipher);
c->status.decryptin = true;
} else {
c->incipher = NULL;