]> git.pld-linux.org Git - packages/tpm-tools.git/blob - 0003-Allocate-OpenSSL-cipher-contexts-for-seal-unseal.patch
- new, raw from fedora
[packages/tpm-tools.git] / 0003-Allocate-OpenSSL-cipher-contexts-for-seal-unseal.patch
1 From c229bb590250bd9769cb5a63918ab0f6c9386be7 Mon Sep 17 00:00:00 2001
2 From: Michal Schmidt <mschmidt@redhat.com>
3 Date: Mon, 20 Feb 2017 12:00:39 +0100
4 Subject: [PATCH 3/3] Allocate OpenSSL cipher contexts for seal/unseal
5
6 Cipher contexts need to be allocated before using EVP_EncryptInit or
7 EVP_DecryptInit. Using a NULL context is invalid.
8
9 Fixes: f50ab0949438 ("Support OpenSSL 1.1.0")
10 ---
11  lib/tpm_unseal.c        | 12 ++++++++++--
12  src/cmds/tpm_sealdata.c | 11 +++++++++--
13  2 files changed, 19 insertions(+), 4 deletions(-)
14
15 diff --git a/lib/tpm_unseal.c b/lib/tpm_unseal.c
16 index fc4a84906a..005dab7f8f 100644
17 --- a/lib/tpm_unseal.c
18 +++ b/lib/tpm_unseal.c
19 @@ -86,7 +86,7 @@ int tpmUnsealFile( char* fname, unsigned char** tss_data, int* tss_size,
20         int srkSecretLen;
21         unsigned char* res_data = NULL;
22         int res_size = 0;
23 -
24 +       EVP_CIPHER_CTX *ctx = NULL;
25         BIO *bdata = NULL, *b64 = NULL, *bmem = NULL;
26         int bioRc;
27  
28 @@ -408,7 +408,12 @@ int tpmUnsealFile( char* fname, unsigned char** tss_data, int* tss_size,
29         }
30  
31         /* Decode and decrypt the encrypted data */
32 -       EVP_CIPHER_CTX *ctx = NULL;
33 +       ctx = EVP_CIPHER_CTX_new();
34 +       if ( ctx == NULL ) {
35 +               rc = TPMSEAL_STD_ERROR;
36 +               tpm_errno = ENOMEM;
37 +               goto tss_out;
38 +       }
39         EVP_DecryptInit(ctx, EVP_aes_256_cbc(), symKey, (unsigned char *)TPMSEAL_IV);
40  
41         /* Create a base64 BIO to decode the encrypted data */
42 @@ -459,6 +464,9 @@ out:
43         } else
44                 free(res_data);
45  
46 +       if (ctx)
47 +               EVP_CIPHER_CTX_free(ctx);
48 +
49         return rc;
50  }
51  
52 diff --git a/src/cmds/tpm_sealdata.c b/src/cmds/tpm_sealdata.c
53 index a2157f34b1..e25244a0f4 100644
54 --- a/src/cmds/tpm_sealdata.c
55 +++ b/src/cmds/tpm_sealdata.c
56 @@ -118,7 +118,7 @@ int main(int argc, char **argv)
57         char *passwd = NULL;
58         int pswd_len;
59         BYTE wellKnown[TCPA_SHA1_160_HASH_LEN] = TSS_WELL_KNOWN_SECRET;
60 -
61 +       EVP_CIPHER_CTX *ctx = NULL;
62         BIO *bin = NULL, *bdata=NULL, *b64=NULL;
63  
64         initIntlSys();
65 @@ -343,7 +343,11 @@ int main(int argc, char **argv)
66         BIO_puts(bdata, TPMSEAL_ENC_STRING); 
67         bdata = BIO_push(b64, bdata);
68  
69 -       EVP_CIPHER_CTX *ctx = NULL;
70 +       ctx = EVP_CIPHER_CTX_new();
71 +       if (ctx == NULL) {
72 +               logError(_("Unable to allocate cipher context\n"));
73 +               goto out_close;
74 +       }
75         EVP_EncryptInit(ctx, EVP_aes_256_cbc(), randKey, (unsigned char *)TPMSEAL_IV);
76  
77         while ((lineLen = BIO_read(bin, line, sizeof(line))) > 0) {
78 @@ -375,5 +379,8 @@ out:
79                 BIO_free(bdata);
80         if (b64)
81                 BIO_free(b64);
82 +       if (ctx)
83 +               EVP_CIPHER_CTX_free(ctx);
84 +
85         return iRc;
86  }
87 -- 
88 2.9.3
89
This page took 0.062764 seconds and 3 git commands to generate.