diff --git a/src/jws.c b/src/jws.c index 2e314d9..9dda454 100644 --- a/src/jws.c +++ b/src/jws.c @@ -565,6 +565,8 @@ static bool _cjose_jws_build_sig_ec( const cjose_jwk_t *jwk, cjose_err *err) { + bool retval = false; + // ensure jwk is EC if (jwk->kty != CJOSE_JWK_KTY_EC) { @@ -579,7 +581,7 @@ static bool _cjose_jws_build_sig_ec( if (NULL == ecdsa_sig) { CJOSE_ERROR(err, CJOSE_ERR_CRYPTO); - return false; + goto _cjose_jws_build_sig_ec_cleanup; } // allocate buffer for signature @@ -599,7 +601,7 @@ static bool _cjose_jws_build_sig_ec( if (NULL == jws->sig) { CJOSE_ERROR(err, CJOSE_ERR_NO_MEMORY); - return false; + goto _cjose_jws_build_sig_ec_cleanup; } memset(jws->sig, 0, jws->sig_len); @@ -613,10 +615,16 @@ static bool _cjose_jws_build_sig_ec( &jws->sig_b64u, &jws->sig_b64u_len, err)) { CJOSE_ERROR(err, CJOSE_ERR_CRYPTO); - return false; + goto _cjose_jws_build_sig_ec_cleanup; } - return true; + retval = true; + + _cjose_jws_build_sig_ec_cleanup: + if (ecdsa_sig) + ECDSA_SIG_free(ecdsa_sig); + + return retval; } //////////////////////////////////////////////////////////////////////////////// diff --git a/test/check_jwe.c b/test/check_jwe.c index 36606c6..5682afe 100644 --- a/test/check_jwe.c +++ b/test/check_jwe.c @@ -170,6 +170,12 @@ static void _self_encrypt_self_decrypt(const char *plain1) JWK_RSA, plain1); + _self_encrypt_self_decrypt_with_key( + CJOSE_HDR_ALG_RSA1_5, + CJOSE_HDR_ENC_A256GCM, + JWK_RSA, + plain1); + _self_encrypt_self_decrypt_with_key( CJOSE_HDR_ALG_DIR, CJOSE_HDR_ENC_A256GCM, @@ -458,7 +464,7 @@ START_TEST(test_cjose_jwe_import_export_compare) // re-export the jwe object const char *cser = cjose_jwe_export(jwe, &err); ck_assert_msg(NULL != cser, - "re-export of imported JWE faied: " + "re-export of imported JWE failed: " "%s, file: %s, function: %s, line: %ld", err.message, err.file, err.function, err.line); diff --git a/test/check_jwk.c b/test/check_jwk.c index 572f6e3..2e1b4e7 100644 --- a/test/check_jwk.c +++ b/test/check_jwk.c @@ -496,6 +496,7 @@ START_TEST(test_cjose_jwk_to_json_ec) ",\"y\":\"KbkZ7r_DQ-t67pnxPnFDHObTLBqn44BSjcqn0STUkaM\"}", json ); + free(json); json = cjose_jwk_to_json(jwk, true, &err); ck_assert(NULL != json); @@ -505,6 +506,7 @@ START_TEST(test_cjose_jwk_to_json_ec) ",\"y\":\"KbkZ7r_DQ-t67pnxPnFDHObTLBqn44BSjcqn0STUkaM\"" ",\"d\":\"RSSjcBQW_EBxm1gzYhejCdWtj3Id_GuwldwEgSuKCEM\"}", json); + free(json); cjose_jwk_release(jwk); } @@ -543,8 +545,7 @@ START_TEST(test_cjose_jwk_to_json_rsa) const char *json; json = cjose_jwk_to_json(jwk, false, &err); ck_assert(NULL != json); - ck_assert_str_eq(RSA_PUBLIC_JSON, json - ); + ck_assert_str_eq(RSA_PUBLIC_JSON, json); free(json); json = cjose_jwk_to_json(jwk, true, &err); @@ -679,7 +680,7 @@ START_TEST(test_cjose_jwk_import_valid) // get json representation of "after" const char *jwk_str = cjose_jwk_to_json(jwk, true, &err); json_t *right_json = json_loads(jwk_str, 0, NULL); - ck_assert(NULL != right_json); + ck_assert(NULL != right_json); // check that cooresponding attributes match up const char *attrs[] = { "kty", "crv", "x", "y", "d", "kid", @@ -689,6 +690,7 @@ START_TEST(test_cjose_jwk_import_valid) ck_assert_str_eq(JWK[i], jwk_str); } + free(jwk_str); json_decref(left_json); json_decref(right_json); cjose_jwk_release(jwk); @@ -955,6 +957,7 @@ START_TEST(test_cjose_jwk_EC_import_with_priv_export_with_pub) ck_assert_str_eq(JWK_OUT, jwk_str); } + free(jwk_str); json_decref(left_json); json_decref(right_json); cjose_jwk_release(jwk);