From bc331976f82eeeedae6c7b2fef714137316f167f Mon Sep 17 00:00:00 2001 From: Nickolay Olshevsky Date: Tue, 25 Jul 2023 12:53:51 +0300 Subject: [PATCH] Add tests for v5 data signatures verification. --- src/tests/ffi-enc.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/tests/ffi-enc.cpp b/src/tests/ffi-enc.cpp index b37cb689b3..775353c575 100644 --- a/src/tests/ffi-enc.cpp +++ b/src/tests/ffi-enc.cpp @@ -1469,3 +1469,51 @@ TEST_F(rnp_tests, test_ffi_encrypt_no_wrap) // final cleanup rnp_ffi_destroy(ffi); } + +TEST_F(rnp_tests, test_ffi_v5_signatures) +{ + rnp_ffi_t ffi = NULL; + assert_rnp_success(rnp_ffi_create(&ffi, "GPG", "GPG")); + /* import v5 keys */ + assert_true(import_pub_keys(ffi, "data/test_stream_key_load/v5-rsa-pub.asc")); + /* verify v5 attached signature */ + rnp_input_t input = NULL; + assert_rnp_success( + rnp_input_from_path(&input, "data/test_messages/message.txt.signed.v5-rsa")); + rnp_output_t output = NULL; + assert_rnp_success(rnp_output_to_null(&output)); + rnp_op_verify_t verify = NULL; + assert_rnp_success(rnp_op_verify_create(&verify, ffi, input, output)); + assert_rnp_success(rnp_op_verify_execute(verify)); + rnp_op_verify_signature_t sig = NULL; + assert_rnp_success(rnp_op_verify_get_signature_at(verify, 0, &sig)); + assert_rnp_success(rnp_op_verify_signature_get_status(sig)); + rnp_op_verify_destroy(verify); + rnp_input_destroy(input); + rnp_output_destroy(output); + /* verify v5 detached signature */ + assert_rnp_success(rnp_input_from_path(&input, "data/test_messages/message.txt")); + rnp_input_t sigin = NULL; + assert_rnp_success( + rnp_input_from_path(&sigin, "data/test_messages/message.txt.signed.v5-detached-rsa")); + assert_rnp_success(rnp_op_verify_detached_create(&verify, ffi, input, sigin)); + assert_rnp_success(rnp_op_verify_execute(verify)); + assert_rnp_success(rnp_op_verify_get_signature_at(verify, 0, &sig)); + assert_rnp_success(rnp_op_verify_signature_get_status(sig)); + rnp_op_verify_destroy(verify); + rnp_input_destroy(input); + rnp_input_destroy(sigin); + /* verify cleartext signature */ + assert_rnp_success( + rnp_input_from_path(&input, "data/test_messages/message.txt.signed.v5-clear-rsa")); + assert_rnp_success(rnp_output_to_null(&output)); + assert_rnp_success(rnp_op_verify_create(&verify, ffi, input, output)); + assert_rnp_success(rnp_op_verify_execute(verify)); + assert_rnp_success(rnp_op_verify_get_signature_at(verify, 0, &sig)); + assert_rnp_success(rnp_op_verify_signature_get_status(sig)); + rnp_op_verify_destroy(verify); + rnp_input_destroy(input); + rnp_output_destroy(output); + + rnp_ffi_destroy(ffi); +}