Changeset 99404 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c
- Timestamp:
- Apr 14, 2023 3:17:44 PM (21 months ago)
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-145445 /vendor/edk2/current 103735-103757,103769-103776,129194-156846
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c
r85718 r99404 31 31 INTN KeyLength; 32 32 33 ZeroMem ((VOID *) Buf, (UINTN)Size);33 ZeroMem ((VOID *)Buf, (UINTN)Size); 34 34 if (Key != NULL) { 35 35 // 36 36 // Duplicate key phrase directly. 37 37 // 38 KeyLength = (INTN) 39 KeyLength = (KeyLength > Size 40 CopyMem (Buf, Key, (UINTN) 38 KeyLength = (INTN)AsciiStrLen ((CHAR8 *)Key); 39 KeyLength = (KeyLength > Size) ? Size : KeyLength; 40 CopyMem (Buf, Key, (UINTN)KeyLength); 41 41 return KeyLength; 42 42 } else { … … 77 77 // Check input parameters. 78 78 // 79 if ( PemData == NULL || RsaContext == NULL || PemSize > INT_MAX) {79 if ((PemData == NULL) || (RsaContext == NULL) || (PemSize > INT_MAX)) { 80 80 return FALSE; 81 81 } … … 88 88 return FALSE; 89 89 } 90 90 91 if (EVP_add_cipher (EVP_aes_192_cbc ()) == 0) { 91 92 return FALSE; 92 93 } 94 93 95 if (EVP_add_cipher (EVP_aes_256_cbc ()) == 0) { 94 96 return FALSE; … … 105 107 } 106 108 107 if (BIO_write (PemBio, PemData, (int) 109 if (BIO_write (PemBio, PemData, (int)PemSize) <= 0) { 108 110 goto _Exit; 109 111 } … … 112 114 // Retrieve RSA Private Key from encrypted PEM data. 113 115 // 114 *RsaContext = PEM_read_bio_RSAPrivateKey (PemBio, NULL, (pem_password_cb *) &PasswordCallback, (void *)Password);116 *RsaContext = PEM_read_bio_RSAPrivateKey (PemBio, NULL, (pem_password_cb *)&PasswordCallback, (void *)Password); 115 117 if (*RsaContext != NULL) { 116 118 Status = TRUE; … … 125 127 return Status; 126 128 } 129 130 /** 131 Retrieve the EC Private Key from the password-protected PEM key data. 132 133 @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. 134 @param[in] PemSize Size of the PEM key data in bytes. 135 @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. 136 @param[out] EcContext Pointer to new-generated EC DSA context which contain the retrieved 137 EC private key component. Use EcFree() function to free the 138 resource. 139 140 If PemData is NULL, then return FALSE. 141 If EcContext is NULL, then return FALSE. 142 143 @retval TRUE EC Private Key was retrieved successfully. 144 @retval FALSE Invalid PEM key data or incorrect password. 145 146 **/ 147 BOOLEAN 148 EFIAPI 149 EcGetPrivateKeyFromPem ( 150 IN CONST UINT8 *PemData, 151 IN UINTN PemSize, 152 IN CONST CHAR8 *Password, 153 OUT VOID **EcContext 154 ) 155 { 156 BOOLEAN Status; 157 BIO *PemBio; 158 159 // 160 // Check input parameters. 161 // 162 if ((PemData == NULL) || (EcContext == NULL) || (PemSize > INT_MAX)) { 163 return FALSE; 164 } 165 166 // 167 // Add possible block-cipher descriptor for PEM data decryption. 168 // NOTE: Only support most popular ciphers AES for the encrypted PEM. 169 // 170 if (EVP_add_cipher (EVP_aes_128_cbc ()) == 0) { 171 return FALSE; 172 } 173 174 if (EVP_add_cipher (EVP_aes_192_cbc ()) == 0) { 175 return FALSE; 176 } 177 178 if (EVP_add_cipher (EVP_aes_256_cbc ()) == 0) { 179 return FALSE; 180 } 181 182 Status = FALSE; 183 184 // 185 // Read encrypted PEM Data. 186 // 187 PemBio = BIO_new (BIO_s_mem ()); 188 if (PemBio == NULL) { 189 goto _Exit; 190 } 191 192 if (BIO_write (PemBio, PemData, (int)PemSize) <= 0) { 193 goto _Exit; 194 } 195 196 // 197 // Retrieve EC Private Key from encrypted PEM data. 198 // 199 *EcContext = PEM_read_bio_ECPrivateKey (PemBio, NULL, (pem_password_cb *)&PasswordCallback, (void *)Password); 200 if (*EcContext != NULL) { 201 Status = TRUE; 202 } 203 204 _Exit: 205 // 206 // Release Resources. 207 // 208 BIO_free (PemBio); 209 210 return Status; 211 }
Note:
See TracChangeset
for help on using the changeset viewer.