Skip to content

Add support for multi-token management in SmartCardUtils#239

Draft
krishnavema wants to merge 1 commit intoSSSD:masterfrom
krishnavema:multi-token-smart-card-support
Draft

Add support for multi-token management in SmartCardUtils#239
krishnavema wants to merge 1 commit intoSSSD:masterfrom
krishnavema:multi-token-smart-card-support

Conversation

@krishnavema
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly extends the SmartCardUtils class to support comprehensive multi-token management for SoftHSM. The changes enable the simulation of complex smart card environments with multiple tokens, which is crucial for testing scenarios that require distinct PKCS#11 slots. This enhancement improves the flexibility and realism of smart card related testing within the framework.

Highlights

  • Multi-token Initialization: Added a new method, initialize_additional_token, to allow for the creation of multiple SoftHSM tokens without removing existing ones, facilitating multi-token test environments.
  • Targeted Certificate/Key Addition: Enhanced the add_cert and add_key methods with token_label and label parameters, enabling the addition of certificates and private keys to specific PKCS#11 tokens.
  • p11-kit Integration: Introduced register_for_p11_child to configure SoftHSM as a system-wide p11-kit module, ensuring p11_child can discover and interact with multiple PKCS#11 slots.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • sssd_test_framework/utils/smartcard.py
    • Added initialize_additional_token method to support creating additional SoftHSM tokens.
    • Modified add_cert method to accept token_label and label for targeted certificate addition.
    • Modified add_key method to pass token_label and label to the underlying add_cert call.
    • Added register_for_p11_child method to configure SoftHSM for system-wide p11-kit module visibility.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@krishnavema krishnavema requested a review from spoore1 March 15, 2026 15:39
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for managing multiple smart card tokens by introducing initialize_additional_token to create new tokens without wiping existing ones, and register_for_p11_child to make them visible to p11_child. The add_cert and add_key methods are also updated to allow targeting a specific token. The changes are logical, but I have a couple of suggestions to improve maintainability and security. I've identified some code duplication that could be refactored and an instance of overly permissive file permissions that should be tightened.

Comment on lines +98 to +106
args: CLIBuilderArgs = {
"label": (self.cli.option.VALUE, label),
"free": (self.cli.option.SWITCH, True),
"so-pin": (self.cli.option.VALUE, so_pin),
"pin": (self.cli.option.VALUE, user_pin),
}
self.host.conn.run(
self.cli.command("softhsm2-util --init-token", args), env={"SOFTHSM2_CONF": self.SOFTHSM2_CONF_PATH}
)

Choose a reason for hiding this comment

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

medium

The logic for building arguments and calling softhsm2-util --init-token in this new method is identical to the one in the initialize_card method (lines 69-77). This code duplication should be avoided by extracting the common logic into a private helper method. This will improve code maintainability.

f"> /etc/systemd/system/sssd.service.d/softhsm.conf"
)
self.host.conn.run("systemctl daemon-reload")
self.host.conn.run("chmod -R o+rX /opt/test_ca/")

Choose a reason for hiding this comment

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

medium

The command chmod -R o+rX /opt/test_ca/ grants read permissions to all files under /opt/test_ca/ to all users on the system, which is overly permissive. While this is a test environment, it's better to apply the principle of least privilege. A more precise command would only grant the necessary permissions, for example by only allowing traversal of the directory and read access to the configuration file.

Suggested change
self.host.conn.run("chmod -R o+rX /opt/test_ca/")
self.host.conn.run(f"chmod o+x /opt/test_ca && chmod o+r {conf}")

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.

3 participants