]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dcrypt-iostream: Ref/unref keys
authorAki Tuomi <aki.tuomi@dovecot.fi>
Fri, 15 Jul 2016 13:30:51 +0000 (16:30 +0300)
committerGitLab <gitlab@git.dovecot.net>
Thu, 4 Aug 2016 11:45:28 +0000 (14:45 +0300)
src/lib-dcrypt/istream-decrypt.c
src/lib-dcrypt/ostream-encrypt.c

index cbe9b3e967993edb469b0cbfce28d30968f489bc..6df03b55571e017de0b90d3d02433b41f29138c9 100644 (file)
@@ -132,6 +132,7 @@ ssize_t i_stream_decrypt_read_header_v1(struct decrypt_istream *stream,
                                io_stream_set_error(&stream->istream.iostream, "Private key not available");
                                return -1;
                        }
+                       dcrypt_key_ref_private(stream->priv_key);
                } else {
                        io_stream_set_error(&stream->istream.iostream, "Private key not available");
                        return -1;
@@ -306,6 +307,7 @@ ssize_t i_stream_decrypt_key(struct decrypt_istream *stream, const char *malg, u
                                return -1;
                        }
                        if (ret > 0) {
+                               dcrypt_key_ref_private(stream->priv_key);
                                have_key = TRUE;
                                break;
                        }
@@ -803,6 +805,8 @@ void i_stream_decrypt_destroy(struct iostream_private *stream)
                dcrypt_ctx_sym_destroy(&(dstream->ctx_sym));
        if (dstream->ctx_mac != NULL)
                dcrypt_ctx_hmac_destroy(&(dstream->ctx_mac));
+       if (dstream->priv_key != NULL)
+               dcrypt_key_unref_private(&(dstream->priv_key));
 
        i_stream_unref(&(dstream->istream.parent));
 }
@@ -835,6 +839,7 @@ i_stream_create_decrypt(struct istream *input, struct dcrypt_private_key *priv_k
        struct decrypt_istream *dstream;
 
        dstream = i_stream_create_decrypt_common(input);
+       dcrypt_key_ref_private(priv_key);
        dstream->priv_key = priv_key;
        return &dstream->istream.istream;
 }
index aca819eb9359cab79660b2901126e85f2fc803c9..37a937673d58685aa91d77b4c005f261d3278ce3 100644 (file)
@@ -561,7 +561,7 @@ void o_stream_encrypt_destroy(struct iostream_private *stream)
        if (estream->key_data != NULL) i_free(estream->key_data);
        if (estream->cipher_oid != NULL) buffer_free(&(estream->cipher_oid));
        if (estream->mac_oid != NULL) buffer_free(&(estream->mac_oid));
-
+       if (estream->pub != NULL) dcrypt_key_unref_public(&(estream->pub));
        o_stream_unref(&estream->ostream.parent);
 }
 
@@ -645,6 +645,7 @@ o_stream_create_encrypt(struct ostream *output, const char *algorithm,
        struct encrypt_ostream *estream = o_stream_create_encrypt_common(flags);
        int ec;
 
+       dcrypt_key_ref_public(box_pub);
        estream->pub = box_pub;
 
        T_BEGIN {