libtpmtss: Fix problematic usage of chunk_from_chars() in TSS2 implementations
authorTobias Brunner <tobias@strongswan.org>
Wed, 29 Jan 2020 10:22:07 +0000 (11:22 +0100)
committerTobias Brunner <tobias@strongswan.org>
Thu, 30 Jan 2020 17:18:33 +0000 (18:18 +0100)
See 8ea13bbc5ccd for details.

References #3249.

src/libtpmtss/tpm_tss_tss2_v1.c
src/libtpmtss/tpm_tss_tss2_v2.c

index fb26d05..31465da 100644 (file)
@@ -494,7 +494,8 @@ METHOD(tpm_tss_t, get_public, chunk_t,
                {
                        TPM2B_PUBLIC_KEY_RSA *rsa;
                        TPMT_RSA_SCHEME *scheme;
-                       chunk_t aik_exponent, aik_modulus;
+                       chunk_t aik_exponent = chunk_from_chars(0x01, 0x00, 0x01);
+                       chunk_t aik_modulus;
                        uint32_t exponent;
 
                        scheme = &public.t.publicArea.parameters.rsaDetail.scheme;
@@ -504,11 +505,7 @@ METHOD(tpm_tss_t, get_public, chunk_t,
                        rsa = &public.t.publicArea.unique.rsa;
                        aik_modulus = chunk_create(rsa->t.buffer, rsa->t.size);
                        exponent = htonl(public.t.publicArea.parameters.rsaDetail.exponent);
-                       if (!exponent)
-                       {
-                               aik_exponent = chunk_from_chars(0x01, 0x00, 0x01);
-                       }
-                       else
+                       if (exponent)
                        {
                                aik_exponent = chunk_from_thing(exponent);
                        }
index c5d78d6..fef32e1 100644 (file)
@@ -448,7 +448,8 @@ METHOD(tpm_tss_t, get_public, chunk_t,
                {
                        TPM2B_PUBLIC_KEY_RSA *rsa;
                        TPMT_RSA_SCHEME *scheme;
-                       chunk_t aik_exponent, aik_modulus;
+                       chunk_t aik_exponent = chunk_from_chars(0x01, 0x00, 0x01);
+                       chunk_t aik_modulus;
                        uint32_t exponent;
 
                        scheme = &public.publicArea.parameters.rsaDetail.scheme;
@@ -458,11 +459,7 @@ METHOD(tpm_tss_t, get_public, chunk_t,
                        rsa = &public.publicArea.unique.rsa;
                        aik_modulus = chunk_create(rsa->buffer, rsa->size);
                        exponent = htonl(public.publicArea.parameters.rsaDetail.exponent);
-                       if (!exponent)
-                       {
-                               aik_exponent = chunk_from_chars(0x01, 0x00, 0x01);
-                       }
-                       else
+                       if (exponent)
                        {
                                aik_exponent = chunk_from_thing(exponent);
                        }