From 3f2da84bca52ef2712ecd533005ae0af0e4759a2 Mon Sep 17 00:00:00 2001 From: Ron Eldor Date: Tue, 17 Oct 2017 15:50:30 +0300 Subject: [PATCH] Resolve PR review comments 1) Fix style comments 2) Fix typo in Makefile 3) Remove the `MBEDTLS_MD5_C` dependency from test data file, as the used keys are not encrypted --- library/pkparse.c | 4 +++- tests/data_files/Makefile | 14 +++++++++++--- tests/data_files/rsa_pkcs8_2048_public.der | Bin 0 -> 294 bytes tests/data_files/rsa_pkcs8_2048_public.pem | 9 +++++++++ tests/suites/test_suite_pkparse.data | 7 +++---- 5 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 tests/data_files/rsa_pkcs8_2048_public.der create mode 100644 tests/data_files/rsa_pkcs8_2048_public.pem diff --git a/library/pkparse.c b/library/pkparse.c index 75f1620b0..41eeadf45 100644 --- a/library/pkparse.c +++ b/library/pkparse.c @@ -1256,6 +1256,7 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx, #if defined(MBEDTLS_PEM_PARSE_C) size_t len; mbedtls_pem_context pem; + mbedtls_pem_init( &pem ); #if defined(MBEDTLS_RSA_C) /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ @@ -1278,6 +1279,7 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx, if ( ( ret = pk_get_rsapubkey( &p, p + pem.buflen, mbedtls_pk_rsa( *ctx ) ) ) != 0 ) mbedtls_pk_free( ctx ); + mbedtls_pem_free( &pem ); return( ret ); } @@ -1288,7 +1290,7 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx, } #endif /* MBEDTLS_RSA_C */ - /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ + /* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */ if( keylen == 0 || key[keylen - 1] != '\0' ) ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT; else diff --git a/tests/data_files/Makefile b/tests/data_files/Makefile index bfcdc684a..3e20f6641 100644 --- a/tests/data_files/Makefile +++ b/tests/data_files/Makefile @@ -65,11 +65,19 @@ server2-sha256.crt: server2-rsa.csr all_final += server2-sha256.crt rsa_pkcs1_2048_public.pem: server8.key - $(OPENSSL) rsa -in server8.key -outform PEM -RSAPublicKey_out -out $@ -all_final += rsa_pkcs8_2048_public.pem + $(OPENSSL) rsa -in $< -outform PEM -RSAPublicKey_out -out $@ +all_final += rsa_pkcs1_2048_public.pem rsa_pkcs1_2048_public.der: rsa_pkcs1_2048_public.pem - $(OPENSSL) -RSAPublicKey_in -in rsa_pkcs1_2048_public.pem -outform DER -RSAPublicKey_out -out $@ + $(OPENSSL) rsa -RSAPublicKey_in -in $< -outform DER -RSAPublicKey_out -out $@ +all_final += rsa_pkcs1_2048_public.der + +rsa_pkcs8_2048_public.pem: server8.key + $(OPENSSL) rsa -in $< -outform PEM -pubout -out $@ +all_final += rsa_pkcs8_2048_public.pem + +rsa_pkcs8_2048_public.der: rsa_pkcs8_2048_public.pem + $(OPENSSL) rsa -pubin -in $< -outform DER -pubout -out $@ all_final += rsa_pkcs8_2048_public.der ################################################################ diff --git a/tests/data_files/rsa_pkcs8_2048_public.der b/tests/data_files/rsa_pkcs8_2048_public.der new file mode 100644 index 0000000000000000000000000000000000000000..8644a5647e63e647adedd78acc7c631b3bd0a4cb GIT binary patch literal 294 zcmV+>0ondAf&n5h4F(A+hDe6@4FLfG1potr0S^E$f&mHwf&l>l+Z=x`3(ddI(RC1@ zqPWg|s^SIUde}r`kF~wPuo<~GxEV?g@m+L)XGVtx-dleL1HHkGUI!J_TlC!J&pr9U z5iG81xr)6VXJ!}bPQBX|nu3Sq@OZ^HpQ)K&<1_5c>I=1DUhzqOKcg+`0SwGS zns%GS&^Obu7Xe`b7Fm8A7sFHi(Q?a7U=`YZ;_9tX?~dY&)M|HC)^OQtyYcQh1URF; z;?dw{YvPz(f!sWL%K7u0_tq#ICwP3r(A8t7fi#J& sC2GC$>h1bh{N*&p!4GjQ(g+Y6twcfK{&}EdlZvrj>9Fo^0s{d60qM1nivR!s literal 0 HcmV?d00001 diff --git a/tests/data_files/rsa_pkcs8_2048_public.pem b/tests/data_files/rsa_pkcs8_2048_public.pem new file mode 100644 index 000000000..f1e29cc6e --- /dev/null +++ b/tests/data_files/rsa_pkcs8_2048_public.pem @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2xx/LgvNv87RdRCgorjO +fariBeB62ERjj7W9wLAZuTe4GUoO8V10gGdGhwbeW38GA73BjV4HFdRb9Nzlzz35 +wREsrmq5ir0dZ2YX6k692xWagofk8HjDo4WHsP2fqZlf4zPszOoLtWFe8Ul+P6Mt +6gEMzEKadpvE0DfTsRcBYQEWWX4cF8NT/dFyy0xgFdp94uqtUO+O4ovUandV1nDZ +a7vx7jkEOKO94tHgZmvinEeZ6SjmtvwuymdDhOjVg9admGsBPoHcPHrK+fOc99Yo +Gyd4fMPQ1WOngTSJrSVqvfLq7fpX/OU0xsEPcS3SCBAbrURB4P55oGOTirFd6bDu +bwIDAQAB +-----END PUBLIC KEY----- diff --git a/tests/suites/test_suite_pkparse.data b/tests/suites/test_suite_pkparse.data index 391d6c5b1..32957266c 100644 --- a/tests/suites/test_suite_pkparse.data +++ b/tests/suites/test_suite_pkparse.data @@ -103,12 +103,11 @@ depends_on:MBEDTLS_DES_C:MBEDTLS_SHA1_C:MBEDTLS_PEM_PARSE_C:MBEDTLS_PKCS5_C:MBED pk_parse_keyfile_rsa:"data_files/pkcs8_pbes2_pbkdf2_des.key":"PolarSSLTest":0 Parse Public RSA Key #1 (PKCS#8 wrapped) -depends_on:MBEDTLS_MD5_C:MBEDTLS_PEM_PARSE_C -pk_parse_public_keyfile_rsa:"data_files/format_gen.pub":0 +depends_on:MBEDTLS_PEM_PARSE_C +pk_parse_public_keyfile_rsa:"data_files/rsa_pkcs8_2048_public.pem":0 Parse Public RSA Key #1 (PKCS#8 wrapped, DER) -depends_on:MBEDTLS_MD5_C -pk_parse_public_keyfile_rsa:"data_files/rsa_pkcs8_1024_public.der":0 +pk_parse_public_keyfile_rsa:"data_files/rsa_pkcs8_2048_public.der":0 Parse Public RSA Key #3 (PKCS#1 wrapped) depends_on:MBEDTLS_RSA_C:MBEDTLS_PEM_PARSE_C