-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5155 from paul-elliott-arm/pcks12_fix
Fixes for pkcs12 with NULL and/or zero length password
- Loading branch information
Showing
7 changed files
with
228 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Bugfix | ||
* Fix a potential invalid pointer dereference and infinite loop bugs in | ||
pkcs12 functions when the password is empty. Fix the documentation to | ||
better describe the inputs to these functions and their possible values. | ||
Fixes #5136. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
PKCS#12 derive key : MD5: Zero length password and hash | ||
depends_on:MBEDTLS_MD5_C | ||
pkcs12_derive_key:MBEDTLS_MD_MD5:48:"":USE_GIVEN_INPUT:"":USE_GIVEN_INPUT:3:"6afdcbd5ebf943272134f1c3de2dc11b6afdcbd5ebf943272134f1c3de2dc11b6afdcbd5ebf943272134f1c3de2dc11b":0 | ||
|
||
PKCS#12 derive key: MD5: NULL password and hash | ||
depends_on:MBEDTLS_MD5_C | ||
pkcs12_derive_key:MBEDTLS_MD_MD5:48:"":USE_NULL_INPUT:"":USE_NULL_INPUT:3:"6afdcbd5ebf943272134f1c3de2dc11b6afdcbd5ebf943272134f1c3de2dc11b6afdcbd5ebf943272134f1c3de2dc11b":0 | ||
|
||
PKCS#12 derive key: MD5: Zero length password | ||
depends_on:MBEDTLS_MD5_C | ||
pkcs12_derive_key:MBEDTLS_MD_MD5:48:"":USE_GIVEN_INPUT:"0123456789abcdef":USE_GIVEN_INPUT:3:"832d8502114fcccfd3de0c2b2863b1c45fb92a8db2ed1e704727b324adc267bdd66ae4918a81fa2d1ba15febfb9e6c4e":0 | ||
|
||
PKCS#12 derive key: MD5: NULL password | ||
depends_on:MBEDTLS_MD5_C | ||
pkcs12_derive_key:MBEDTLS_MD_MD5:48:"":USE_NULL_INPUT:"0123456789abcdef":USE_GIVEN_INPUT:3:"832d8502114fcccfd3de0c2b2863b1c45fb92a8db2ed1e704727b324adc267bdd66ae4918a81fa2d1ba15febfb9e6c4e":0 | ||
|
||
PKCS#12 derive key: MD5: Invalid length NULL password | ||
depends_on:MBEDTLS_MD5_C | ||
pkcs12_derive_key:MBEDTLS_MD_MD5:48:"0123456789abcdef":USE_NULL_INPUT:"0123456789abcdef":USE_GIVEN_INPUT:3:"":MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA | ||
|
||
PKCS#12 derive key: MD5: Zero length salt | ||
depends_on:MBEDTLS_MD5_C | ||
pkcs12_derive_key:MBEDTLS_MD_MD5:48:"0123456789abcdef":USE_GIVEN_INPUT:"":USE_GIVEN_INPUT:3:"832d8502114fcccfd3de0c2b2863b1c45fb92a8db2ed1e704727b324adc267bdd66ae4918a81fa2d1ba15febfb9e6c4e":0 | ||
|
||
PKCS#12 derive key: MD5: NULL salt | ||
depends_on:MBEDTLS_MD5_C | ||
pkcs12_derive_key:MBEDTLS_MD_MD5:48:"0123456789abcdef":USE_GIVEN_INPUT:"":USE_NULL_INPUT:3:"832d8502114fcccfd3de0c2b2863b1c45fb92a8db2ed1e704727b324adc267bdd66ae4918a81fa2d1ba15febfb9e6c4e":0 | ||
|
||
PKCS#12 derive key: MD5: Invalid length NULL salt | ||
depends_on:MBEDTLS_MD5_C | ||
pkcs12_derive_key:MBEDTLS_MD_MD5:48:"0123456789abcdef":USE_GIVEN_INPUT:"0123456789abcdef":USE_NULL_INPUT:3:"":MBEDTLS_ERR_PKCS12_BAD_INPUT_DATA | ||
|
||
PKCS#12 derive key: MD5: Valid password and salt | ||
depends_on:MBEDTLS_MD5_C | ||
pkcs12_derive_key:MBEDTLS_MD_MD5:48:"0123456789abcdef":USE_GIVEN_INPUT:"0123456789abcdef":USE_GIVEN_INPUT:3:"46559deeee036836ab1b633ec620178d4c70eacf42f72a2ad7360c812efa09ca3d7567b489a109050345c2dc6a262995":0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* BEGIN_HEADER */ | ||
#include "mbedtls/pkcs12.h" | ||
#include "common.h" | ||
|
||
typedef enum | ||
{ | ||
USE_NULL_INPUT = 0, | ||
USE_GIVEN_INPUT = 1, | ||
} input_usage_method_t; | ||
|
||
/* END_HEADER */ | ||
|
||
/* BEGIN_DEPENDENCIES | ||
* depends_on:MBEDTLS_PKCS12_C | ||
* END_DEPENDENCIES | ||
*/ | ||
|
||
/* BEGIN_CASE */ | ||
void pkcs12_derive_key( int md_type, int key_size_arg, | ||
data_t *password_arg, int password_usage, | ||
data_t *salt_arg, int salt_usage, | ||
int iterations, | ||
data_t* expected_output, int expected_status ) | ||
|
||
{ | ||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; | ||
unsigned char *output_data = NULL; | ||
|
||
unsigned char *password = NULL; | ||
size_t password_len = 0; | ||
unsigned char *salt = NULL; | ||
size_t salt_len = 0; | ||
size_t key_size = key_size_arg; | ||
|
||
if( password_usage == USE_GIVEN_INPUT ) | ||
password = password_arg->x; | ||
|
||
password_len = password_arg->len; | ||
|
||
if( salt_usage == USE_GIVEN_INPUT ) | ||
salt = salt_arg->x; | ||
|
||
salt_len = salt_arg->len; | ||
|
||
ASSERT_ALLOC( output_data, key_size ); | ||
|
||
ret = mbedtls_pkcs12_derivation( output_data, | ||
key_size, | ||
password, | ||
password_len, | ||
salt, | ||
salt_len, | ||
md_type, | ||
MBEDTLS_PKCS12_DERIVE_KEY, | ||
iterations ); | ||
|
||
TEST_EQUAL( ret, expected_status ); | ||
|
||
if( expected_status == 0 ) | ||
{ | ||
ASSERT_COMPARE( expected_output->x, expected_output->len, | ||
output_data, key_size ); | ||
} | ||
|
||
exit: | ||
mbedtls_free( output_data ); | ||
|
||
} | ||
/* END_CASE */ |