Skip to content

Commit

Permalink
Update OpenSSL backend version retrieval and corresponding tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ni4 committed Jan 15, 2024
1 parent dc9b84a commit cee25ba
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/windows-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ jobs:
run: |
echo OPENSSL_ROOT_DIR=${{ env.VCPKG_DIR_U }}/installed/${{ matrix.arch.triplet }} >> $GITHUB_ENV
echo OPENSSL_MODULES=${{ env.VCPKG_DIR_U }}/installed/${{ matrix.arch.triplet }}/bin >> $GITHUB_ENV
echo RNP_TESTS_OPENSSL_ROOT=${{ env.VCPKG_DIR_U }}/installed/${{ matrix.arch.triplet }} >> $GITHUB_ENV
- name: Adjust settings for s2k_iteration_tuning test
# This step adjusts s2k_iteration_tuning threshold for
Expand Down
7 changes: 5 additions & 2 deletions src/lib/crypto/backend_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ backend_version()
if (version[0]) {
return version;
}
const char *reg = "OpenSSL (([0-9]\\.[0-9]\\.[0-9])[a-z]*(-beta[0-9])*(-dev)*) ";
const char *reg = "OpenSSL (([0-9]\\.[0-9]\\.[0-9])[a-z]*(-[a-z0-9]+)*) ";
#ifndef RNP_USE_STD_REGEX
static regex_t r;
regmatch_t matches[5];
Expand All @@ -84,7 +84,9 @@ backend_version()
return "unknown";
}
}
if (regexec(&r, ver, 5, matches, 0) != 0) {
int res = regexec(&r, ver, 5, matches, 0);
if (res != 0) {
RNP_LOG("regexec() failed on %s: %d", ver, res);
return "unknown";
}
assert(sizeof(version) > matches[1].rm_eo - matches[1].rm_so);
Expand All @@ -95,6 +97,7 @@ backend_version()
std::smatch result;
std::string ver = OpenSSL_version(OPENSSL_VERSION);
if (!std::regex_search(ver, result, re)) {
RNP_LOG("std::regex_search failed on \"%s\"", ver.c_str());
return "unknown";
}
assert(sizeof(version) > result[1].str().size());
Expand Down
7 changes: 7 additions & 0 deletions src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ function(add_cli_test suite)
"RNP_TESTS_GPG_PATH=${GPG_EXECUTABLE}"
"RNP_TESTS_GPGCONF_PATH=${GPGCONF_EXECUTABLE}"
)
if (CRYPTO_BACKEND_OPENSSL)
get_filename_component(ossl_root "${OPENSSL_INCLUDE_DIR}" DIRECTORY)
list(APPEND _env
"RNP_TESTS_OPENSSL_ROOT=${ossl_root}"
)
endif()

set_tests_properties(${_test_name} PROPERTIES
TIMEOUT 3000
FIXTURES_REQUIRED testdata
Expand Down
19 changes: 12 additions & 7 deletions src/tests/cli_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3140,28 +3140,33 @@ def test_backend_version(self):
if not match:
match = re.match(OPENSSL_BACKEND_VERSION, out)
backend_prog = 'openssl'
openssl_root = os.getenv('OPENSSL_ROOT_DIR')
openssl_root = os.getenv('RNP_TESTS_OPENSSL_ROOT')
else:
openssl_root = None
self.assertTrue(match)
# check there is no unexpected output
self.assertNotRegex(err, r'(?is)^.*Unsupported.*$')
self.assertNotRegex(err, r'(?is)^.*pgp_sa_to_openssl_string.*$')
self.assertNotRegex(err, r'(?is)^.*unknown.*$')

# In case when there are several openssl installations
# testing environment is supposed to point to the right one
# through OPENSSL_ROOT_DIR environment variable
if is_windows():
backend_prog += '.exe'
backend_prog_ext = None
if openssl_root is not None:
backen_prog_ext = shutil.which(backend_prog, path = openssl_root + '/bin')
backend_prog_ext = shutil.which(backend_prog, path = openssl_root + '/bin')
else:
# In all other cases
# check that botan or openssl executable binary exists in PATH
backen_prog_ext = shutil.which(backend_prog)
backend_prog_ext = shutil.which(backend_prog)

if backen_prog_ext is not None:
ret, out, _ = run_proc(backen_prog_ext, ['version'])
self.assertEqual(ret, 0)
self.assertIn(match.group(1), out)
if backend_prog_ext is None:
return
ret, out, _ = run_proc(backend_prog_ext, ['version'])
self.assertEqual(ret, 0)
self.assertIn(match.group(1), out)

def test_help_message(self):
# rnp help message
Expand Down

0 comments on commit cee25ba

Please sign in to comment.