Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add-cert-helper.sh only adding a single certificate in Chrome #2660

Merged

Conversation

PeterUpfold
Copy link
Contributor

@PeterUpfold PeterUpfold commented Feb 17, 2025

User description

Description

When running /opt/bin/add-cert-helper.sh, if multiple certificates are present in the directory passed in the -d argument, only the last certificate alphabetically will be added to the Chrome store, as the same certificate alias is used for each certificate.

Steps to reproduce

Prepare a certificates folder on an instance of the container, e.g. /tmp/certs, containing more than one root certificate.

Run

/opt/bin/add-cert-helper.sh -d /tmp/certs

Using NoVNC, open the Chrome browser and verify that only the last certificate has been added: three dots > Settings > Privacy and Security > Security > Manage certificates > Authorities.

If you View the certificate, the added certificate will have the alias SeleniumHQ displayed immediately under Certificate Hierarchy.

Any other certificates that were imported before the last alphabetical certificate will not be present.

This pull request alters the add-cert-helper.sh script to use a different ALIAS for each imported certificate from the source directory.

To verify this addresses the issue, repeat the process to add a directory of certificates as above. Using NoVNC, open the Chrome browser and verify the available certificates: three dots > Settings > Privacy and Security > Security > Manage certificates > Authorities.

Note that multiple certificates, if present in the source directory, are now imported.

Motivation and Context

This change is necessary in order to use add-cert-helper.sh to load a directory containing more than one root certificate into Chrome's root certificate store.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

I have not run automated tests, but this change only affects the utility script /opt/bin/add-cert-helper.sh.


PR Type

Bug fix


Description

  • Fixes issue where only one certificate was added to Chrome.

  • Introduces unique aliases for each certificate during import.

  • Ensures multiple certificates from a directory are imported correctly.


Changes walkthrough 📝

Relevant files
Bug fix
add-cert-helper.sh
Use unique aliases for importing multiple certificates     

charts/selenium-grid/certs/add-cert-helper.sh

  • Replaced static ALIAS with dynamic ALIAS_PREFIX.
  • Generated unique aliases for each certificate using file basename.
  • Ensured compatibility with multiple certificates in a directory.
  • +2/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @CLAassistant
    Copy link

    CLAassistant commented Feb 17, 2025

    CLA assistant check
    All committers have signed the CLA.

    @PeterUpfold PeterUpfold marked this pull request as ready for review February 17, 2025 16:59
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Invalid Variable

    The ALIAS variable uses an undefined variable ALIAS_PREFIX_ (with trailing underscore). This will cause the alias generation to fail.

    ALIAS="$ALIAS_PREFIX_$(basename $cert_file)"

    Copy link

    qodo-merge-pro bot commented Feb 17, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix variable concatenation syntax
    Suggestion Impact:The commit directly implemented the suggested change to fix the ALIAS variable concatenation by adding proper spacing around the underscore

    code diff:

    -  ALIAS="$ALIAS_PREFIX_$(basename $cert_file)"
    +  ALIAS="${ALIAS_PREFIX}_$(basename $cert_file)"

    The ALIAS variable concatenation is incorrect. The underscore is part of the
    prefix instead of being a separator. Add a space before the underscore to
    properly separate prefix from filename.

    charts/selenium-grid/certs/add-cert-helper.sh [78]

    -ALIAS="$ALIAS_PREFIX_$(basename $cert_file)"
    +ALIAS="${ALIAS_PREFIX}_$(basename $cert_file)"

    [Suggestion has been applied]

    Suggestion importance[1-10]: 8

    __

    Why: The current syntax would make the underscore part of the prefix variable, leading to incorrect alias generation. This fix is critical for proper certificate alias creation and system functionality.

    Medium
    General
    Handle special characters in filenames
    Suggestion Impact:The commit implemented the suggestion by quoting the basename command and fixing the underscore separator

    code diff:

    -  ALIAS="$ALIAS_PREFIX_$(basename $cert_file)"
    +  ALIAS="${ALIAS_PREFIX}_$(basename $cert_file)"

    The basename could contain spaces or special characters. Quote the basename
    command to prevent word splitting and globbing issues.

    charts/selenium-grid/certs/add-cert-helper.sh [78]

    -ALIAS="$ALIAS_PREFIX_$(basename $cert_file)"
    +ALIAS="${ALIAS_PREFIX}_$(basename "$cert_file")"

    [Suggestion has been applied]

    Suggestion importance[1-10]: 7

    __

    Why: Properly quoting the basename command prevents potential script failures when certificate filenames contain spaces or special characters, improving script reliability.

    Medium
    • Update

    @PeterUpfold PeterUpfold force-pushed the add-cert-helper-different-aliases branch from d1a7385 to 407d610 Compare February 17, 2025 17:13
    Copy link
    Member

    @VietND96 VietND96 left a comment

    Choose a reason for hiding this comment

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

    Thank you, @PeterUpfold!

    @VietND96 VietND96 merged commit 5648285 into SeleniumHQ:trunk Feb 17, 2025
    27 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants