X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=CryptoPkg%2FLibrary%2FBaseCryptLib%2FPk%2FCryptPkcs7Sign.c;h=d3b1a907aad9c5ae8138f0c242f15e56e633da0b;hb=a9fb7b7803763e045bd626ec7df3ce4900e3e927;hp=b275ab851ed192e1fc08c2f5cf1d19ef0a9cde6a;hpb=532616bbd62bea0fe4873f2e7a57de7be9ba3976;p=mirror_edk2.git diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Sign.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Sign.c index b275ab851e..d3b1a907aa 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Sign.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Sign.c @@ -1,7 +1,7 @@ /** @file PKCS#7 SignedData Sign Wrapper Implementation over OpenSSL. -Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -18,7 +18,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include - /** Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message Syntax Standard, version 1.5". This interface is only intended to be used for @@ -92,12 +91,21 @@ Pkcs7Sign ( return Status; } + Status = FALSE; + // // Register & Initialize necessary digest algorithms and PRNG for PKCS#7 Handling // - EVP_add_digest (EVP_md5()); - EVP_add_digest (EVP_sha1()); - EVP_add_digest (EVP_sha256()); + if (EVP_add_digest (EVP_md5 ()) == 0) { + goto _Exit; + } + if (EVP_add_digest (EVP_sha1 ()) == 0) { + goto _Exit; + } + if (EVP_add_digest (EVP_sha256 ()) == 0) { + goto _Exit; + } + RandomSeed (NULL, 0); // @@ -105,18 +113,23 @@ Pkcs7Sign ( // Key = EVP_PKEY_new (); if (Key == NULL) { - Status = FALSE; goto _Exit; } - Key->save_type = EVP_PKEY_RSA; - Key->type = EVP_PKEY_type (EVP_PKEY_RSA); - Key->pkey.rsa = (RSA *) RsaContext; + if (EVP_PKEY_assign_RSA (Key, (RSA *) RsaContext) == 0) { + goto _Exit; + } // // Convert the data to be signed to BIO format. // DataBio = BIO_new (BIO_s_mem ()); - BIO_write (DataBio, InData, (int) InDataSize); + if (DataBio == NULL) { + goto _Exit; + } + + if (BIO_write (DataBio, InData, (int) InDataSize) <= 0) { + goto _Exit; + } // // Create the PKCS#7 signedData structure. @@ -129,7 +142,6 @@ Pkcs7Sign ( PKCS7_BINARY | PKCS7_NOATTR | PKCS7_DETACHED ); if (Pkcs7 == NULL) { - Status = FALSE; goto _Exit; } @@ -138,18 +150,17 @@ Pkcs7Sign ( // P7DataSize = i2d_PKCS7 (Pkcs7, NULL); if (P7DataSize <= 19) { - Status = FALSE; goto _Exit; } P7Data = malloc (P7DataSize); if (P7Data == NULL) { - Status = FALSE; goto _Exit; } Tmp = P7Data; P7DataSize = i2d_PKCS7 (Pkcs7, (unsigned char **) &Tmp); + ASSERT (P7DataSize > 19); // // Strip ContentInfo to content only for signeddata. The data be trimmed off @@ -158,13 +169,12 @@ Pkcs7Sign ( *SignedDataSize = P7DataSize - 19; *SignedData = malloc (*SignedDataSize); if (*SignedData == NULL) { - Status = FALSE; OPENSSL_free (P7Data); goto _Exit; } CopyMem (*SignedData, P7Data + 19, *SignedDataSize); - + OPENSSL_free (P7Data); Status = TRUE; @@ -173,13 +183,6 @@ _Exit: // // Release Resources // - if (RsaContext != NULL) { - RsaFree (RsaContext); - if (Key != NULL) { - Key->pkey.rsa = NULL; - } - } - if (Key != NULL) { EVP_PKEY_free (Key); } @@ -194,4 +197,3 @@ _Exit: return Status; } -