Skip to content

ffi: add security rule enumeration API - #2424

Open
ronaldtse wants to merge 3 commits into
mainfrom
weak-cipher-reporting
Open

ffi: add security rule enumeration API#2424
ronaldtse wants to merge 3 commits into
mainfrom
weak-cipher-reporting

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

Adds two FFI functions that let callers enumerate the security profile's rule list:

  • rnp_get_security_rule_count() — total number of rules (defaults + user-added)
  • rnp_get_security_rule_at() — fetch one rule by index with type/name/level/from/flags fields

Caller owns type and name strings; free via rnp_buffer_destroy.

Why

Today the only way to inspect the active security profile is rnp_get_security_rule(), which requires you to already know the feature type and name. There is no way to enumerate the built-in defaults (SHA-1, MD5, CAST5, 3DES, IDEA, BLOWFISH, RIPEMD) or iterate the full rule list.

This matters for:

  • Downstream tooling (packagers, distros, security auditors) that wants to report which algorithms rnp considers insecure on a given date.
  • Diagnostics — e.g. "what does this rnp build consider weak right now?" without needing to query feature-by-feature.
  • Library consumers building key-management UIs that surface algorithm deprecation.

Implementation

  • src/lib/sec_profile.{hpp,cpp}: add SecurityProfile::rules() returning a const ref to the internal vector.
  • src/lib/rnp.cpp: add the two FFI functions. They reuse the existing hash_alg_map / symm_alg_map / pubkey_alg_map tables for feature int → name lookup, the existing ret_str_value() helper for string allocation, and the existing RNP_SECURITY_* constants for output.
  • src/tests/ffi.cpp: new test_ffi_security_rule_enumeration covering NULL checks, default count (3 hashes + 4 ciphers, +RIPEMD under crypto-refresh), out-of-range index, enumeration of MD5/CAST5/SHA1-data/SHA1-key rules, NULL output parameters, and that adding a rule is reflected in the count.

Test plan

  • rnp_tests --gtest_filter=rnp_tests.test_ffi_security_rule_enumeration passes locally
  • rnp_tests --gtest_filter=rnp_tests.test_ffi_security_profile still passes (no regression)
  • Build clean against main with crypto refresh enabled
  • CI green on all platforms

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.38%. Comparing base (953d2e0) to head (6be024f).

Files with missing lines Patch % Lines
src/lib/rnp.cpp 90.62% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2424      +/-   ##
==========================================
+ Coverage   85.36%   85.38%   +0.01%     
==========================================
  Files         126      126              
  Lines       22861    22932      +71     
==========================================
+ Hits        19516    19580      +64     
- Misses       3345     3352       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ronaldtse
ronaldtse requested review from antonsviridenko and ni4 July 31, 2026 16:20
@ronaldtse
ronaldtse force-pushed the weak-cipher-reporting branch from aad6962 to e34ce5b Compare August 1, 2026 08:23

@ni4 ni4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ronaldtse
ronaldtse force-pushed the weak-cipher-reporting branch from 81d3f11 to feb9fbf Compare August 4, 2026 16:24
Allows callers to enumerate the security profile's rule list, including
the built-in defaults (SHA-1, MD5, CAST5/3DES/IDEA/BLOWFISH, RIPEMD).
Useful for diagnostics, tooling, and letting downstream consumers report
which features rnp considers insecure.
Extends test_ffi_security_rule_enumeration to also add a public-key
rule (EdDSA, PROHIBITED) so the case rnp::FeatureType::PublicKey
branch in rnp_get_security_rule_at and the SecurityLevel::Disabled →
RNP_SECURITY_PROHIBITED mapping are exercised.

Adds the same RNP_FEATURE_PK_ALG handling to get_feature_sec_value()
that hash and cipher types already enjoy, so rnp_add_security_rule,
rnp_get_security_rule, and rnp_remove_security_rule accept public-key
features symmetrically with the other two types.
@ronaldtse
ronaldtse force-pushed the weak-cipher-reporting branch from feb9fbf to 6be024f Compare August 9, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants