diff options
author | Andres AG <andres.amayagarcia@arm.com> | 2017-03-01 11:53:29 +0000 |
---|---|---|
committer | Andres AG <andres.amayagarcia@arm.com> | 2017-03-09 13:53:48 +0000 |
commit | 56e942e252f912f816f98982439e43bba80841ed (patch) | |
tree | cd7519bf499aaf72e2865bd1a54c9172674584f0 | |
parent | 4590955b963dd006e1136d5e878814fee6b7a430 (diff) | |
download | mbedtls-archive/iotssl-1169-pem-missing-checks.zip mbedtls-archive/iotssl-1169-pem-missing-checks.tar.gz mbedtls-archive/iotssl-1169-pem-missing-checks.tar.bz2 |
Add negative testing for mbedtls_pem_read_buffer()archive/iotssl-1169-pem-missing-checks
-rw-r--r-- | tests/suites/test_suite_pem.data | 12 | ||||
-rw-r--r-- | tests/suites/test_suite_pem.function | 23 |
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/suites/test_suite_pem.data b/tests/suites/test_suite_pem.data index 973c923..3801810 100644 --- a/tests/suites/test_suite_pem.data +++ b/tests/suites/test_suite_pem.data @@ -15,3 +15,15 @@ mbedtls_pem_write_buffer:"-----START TEST-----\n":"-----END TEST-----\n":"000102 PEM write (exactly two lines + 1) mbedtls_pem_write_buffer:"-----START TEST-----\n":"-----END TEST-----\n":"000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F00":"-----START TEST-----\nAAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8AAQIDBAUGBwgJCgsMDQ4P\nAAECAwQFBgcICQoLDA0ODwABAgMEBQYHCAkKCwwNDg8AAQIDBAUGBwgJCgsMDQ4P\nAA==\n-----END TEST-----\n" + +PEM read (malformed PEM DES-CBC) +depends_on:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC +mbedtls_pem_read_buffer:"-----BEGIN EC PRIVATE KEY-----":"-----END EC PRIVATE KEY-----":"-----BEGIN EC PRIVATE KEY-----\nProc-Type\: 4,ENCRYPTED\nDEK-Info\: DES-CBC,AA94892A169FA426\n\nMAAA\n-----END EC PRIVATE KEY-----":"pwd":MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH + +PEM read (malformed PEM DES-EDE3-CBC) +depends_on:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC +mbedtls_pem_read_buffer:"-----BEGIN EC PRIVATE KEY-----":"-----END EC PRIVATE KEY-----":"-----BEGIN EC PRIVATE KEY-----\nProc-Type\: 4,ENCRYPTED\nDEK-Info\: DES-EDE3-CBC,AA94892A169FA426\n\nMAAA\n-----END EC PRIVATE KEY-----":"pwd":MBEDTLS_ERR_DES_INVALID_INPUT_LENGTH + +PEM read (malformed PEM AES-128-CBC) +depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CBC +mbedtls_pem_read_buffer:"-----BEGIN EC PRIVATE KEY-----":"-----END EC PRIVATE KEY-----":"-----BEGIN EC PRIVATE KEY-----\nProc-Type\: 4,ENCRYPTED\nDEK-Info\: AES-128-CBC,AA94892A169FA426AA94892A169FA426\n\nMAAA\n-----END EC PRIVATE KEY-----":"pwd":MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH diff --git a/tests/suites/test_suite_pem.function b/tests/suites/test_suite_pem.function index 6a62bfe..330c457 100644 --- a/tests/suites/test_suite_pem.function +++ b/tests/suites/test_suite_pem.function @@ -1,6 +1,8 @@ /* BEGIN_HEADER */ #include "mbedtls/base64.h" #include "mbedtls/pem.h" +#include "mbedtls/des.h" +#include "mbedtls/aes.h" /* END_HEADER */ /* BEGIN_DEPENDENCIES @@ -38,3 +40,24 @@ exit: mbedtls_free( check_buf ); } /* END_CASE */ + +/* BEGIN_CASE */ +void mbedtls_pem_read_buffer( char *header, char *footer, char *data, char *pwd, + int res ) +{ + mbedtls_pem_context ctx; + int ret; + size_t use_len = 0; + size_t pwd_len = strlen( pwd ); + + mbedtls_pem_init( &ctx ); + + ret = mbedtls_pem_read_buffer( &ctx, header, footer, (unsigned char *)data, + (unsigned char *)pwd, pwd_len, &use_len ); + TEST_ASSERT( ret == res ); + +exit: + mbedtls_pem_free( &ctx ); + +} +/* END_CASE */ |