/** @file\r
PEM (Privacy Enhanced Mail) Format Handler Wrapper Implementation over OpenSSL.\r
\r
-Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2010 - 2020, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
**/\r
INTN\r
PasswordCallback (\r
- OUT CHAR8 *Buf, \r
- IN INTN Size, \r
- IN INTN Flag, \r
+ OUT CHAR8 *Buf,\r
+ IN INTN Size,\r
+ IN INTN Flag,\r
IN VOID *Key\r
)\r
{\r
INTN KeyLength;\r
\r
- ZeroMem ((VOID *) Buf, (UINTN) Size);\r
+ ZeroMem ((VOID *)Buf, (UINTN)Size);\r
if (Key != NULL) {\r
//\r
// Duplicate key phrase directly.\r
//\r
- KeyLength = (INTN) AsciiStrLen ((CHAR8 *)Key);\r
- KeyLength = (KeyLength > Size ) ? Size : KeyLength;\r
- CopyMem (Buf, Key, (UINTN) KeyLength);\r
+ KeyLength = (INTN)AsciiStrLen ((CHAR8 *)Key);\r
+ KeyLength = (KeyLength > Size) ? Size : KeyLength;\r
+ CopyMem (Buf, Key, (UINTN)KeyLength);\r
return KeyLength;\r
} else {\r
return 0;\r
//\r
// Check input parameters.\r
//\r
- if (PemData == NULL || RsaContext == NULL || PemSize > INT_MAX) {\r
+ if ((PemData == NULL) || (RsaContext == NULL) || (PemSize > INT_MAX)) {\r
return FALSE;\r
}\r
\r
- Status = FALSE;\r
- PemBio = NULL;\r
-\r
//\r
// Add possible block-cipher descriptor for PEM data decryption.\r
- // NOTE: Only support most popular ciphers (3DES, AES) for the encrypted PEM.\r
+ // NOTE: Only support most popular ciphers AES for the encrypted PEM.\r
//\r
- EVP_add_cipher (EVP_des_ede3_cbc ());\r
- EVP_add_cipher (EVP_aes_128_cbc ());\r
- EVP_add_cipher (EVP_aes_192_cbc ());\r
- EVP_add_cipher (EVP_aes_256_cbc ());\r
+ if (EVP_add_cipher (EVP_aes_128_cbc ()) == 0) {\r
+ return FALSE;\r
+ }\r
+\r
+ if (EVP_add_cipher (EVP_aes_192_cbc ()) == 0) {\r
+ return FALSE;\r
+ }\r
+\r
+ if (EVP_add_cipher (EVP_aes_256_cbc ()) == 0) {\r
+ return FALSE;\r
+ }\r
+\r
+ Status = FALSE;\r
\r
//\r
// Read encrypted PEM Data.\r
//\r
PemBio = BIO_new (BIO_s_mem ());\r
- BIO_write (PemBio, PemData, (int) PemSize);\r
if (PemBio == NULL) {\r
goto _Exit;\r
}\r
\r
+ if (BIO_write (PemBio, PemData, (int)PemSize) <= 0) {\r
+ goto _Exit;\r
+ }\r
+\r
//\r
// Retrieve RSA Private Key from encrypted PEM data.\r
//\r
- *RsaContext = PEM_read_bio_RSAPrivateKey (PemBio, NULL, (pem_password_cb *) &PasswordCallback, (void *) Password);\r
+ *RsaContext = PEM_read_bio_RSAPrivateKey (PemBio, NULL, (pem_password_cb *)&PasswordCallback, (void *)Password);\r
if (*RsaContext != NULL) {\r
Status = TRUE;\r
}\r