Skip to content

Fix to correctly validate authentication settings #222

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jnmt
Copy link
Collaborator

@jnmt jnmt commented Aug 5, 2025

Description

This PR fixes LedgerConfig validation for correct authentication settings. It also revises Javadoc based on the recent docs site changes in scalar-labs/docs-internal-scalardl#621, although it's not directly related to the bugfix.

Related issues and/or PRs

  • scalar-labs/scalar#1458
  • scalar-labs/docs-internal-scalardl#621

Changes made

  • Reject the incorrect combination of digital-signature with the secret key for the Ledger-Auditor authentication.
  • Revise Javadoc

Checklist

The following is a best-effort checklist. If any items in this checklist are not applicable to this PR or are dependent on other, unmerged PRs, please still mark the checkboxes after you have read and understood each item.

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • I have considered whether similar issues could occur in other products, components, or modules if this PR is for bug fixes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

This fix can affect the backward compatibility if users configure the server's authentication differently from the client's authentication (i.e., using both digital signature and HMAC). However, we decided to prevent this configuration, since it's a rare misconfiguration and useless when users focus on either non-repudiation or performance.

Release notes

Fixed Ledger configuration validation for correct authentication settings.

@jnmt jnmt requested a review from Copilot August 5, 2025 08:31
@jnmt jnmt self-assigned this Aug 5, 2025
@jnmt jnmt added the bugfix label Aug 5, 2025
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.

Summary of Changes

Hello @jnmt, 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!

I've implemented a fix to improve the validation of authentication settings, particularly concerning the interaction between Ledger and Auditor configurations. The primary goal is to ensure that the system correctly identifies when a private key is missing, but only under the specific condition that digital signature authentication is enabled. This change enhances the robustness of the configuration validation process and provides more accurate error messages to users.

Highlights

  • Refined Authentication Validation Logic: I've refined the validation logic for authentication settings, specifically ensuring that the presence of a private key is checked only when digital signature authentication is explicitly chosen and the Auditor is enabled. This prevents incorrect validation errors in other authentication scenarios.
  • Improved Configuration Documentation: I've updated the Javadoc comments in ClientConfig.java and LedgerConfig.java to provide clearer guidance on authentication method configuration, emphasizing the need for consistency between client and server settings.
  • Enhanced Error Messaging: I've made the error message for invalid authentication settings more precise, now clearly stating that a private key is required for digital signature authentication when the Auditor is enabled.
  • Expanded Test Coverage for Authentication Configurations: I've updated and added new unit tests in LedgerConfigTest.java to cover various authentication configuration scenarios more thoroughly, ensuring that both digital signature and HMAC authentication methods are correctly validated for missing keys under different conditions.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 or fill out our survey to provide feedback.

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.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves authentication setting validation in the Ledger configuration to ensure proper configuration between clients and servers. The changes fix validation logic to correctly check authentication method requirements and update related error messages and documentation.

Key changes include:

  • Fixed authentication validation logic to properly check for required keys based on authentication method
  • Updated error messages to be clearer and more specific
  • Enhanced test coverage for authentication configuration scenarios

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
LedgerConfig.java Fixed validation logic to check authentication method before requiring private keys and updated error message parameters
LedgerError.java Simplified error message to be more specific about digital signature authentication requirements
LedgerConfigTest.java Removed redundant test and added comprehensive tests for authentication validation scenarios
ClientConfig.java Updated documentation comments to clarify authentication method configuration requirements

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 fixes a bug in the validation of authentication settings when the Auditor is enabled. The previous logic could allow a misconfiguration where the authentication method and the provided credentials (private key or HMAC secret) for server-to-server communication did not match. The new logic correctly enforces that the appropriate credential is provided based on the selected authentication method. The changes also include updating related error messages and tests to reflect this fix. My review includes one suggestion to improve the Javadoc for the authentication method configuration in LedgerConfig.java to ensure clarity and prevent potential misconfigurations.

@@ -450,20 +450,6 @@ public void constructor_AuditorAndProofEnabledAndPrivateKeyGiven_ShouldConstruct
assertThat(thrown).doesNotThrowAnyException();
}

@Test
public void constructor_AuditorAndProofEnabledAndSecretKeyGiven_ShouldConstructProperly() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since the HMAC configuration always requires the server's secret key, this test should be covered by
constructor_ProofAndAuditorEnabledAndHmacConfiguredWithCipherKeyAndSecretKeyGiven_ShouldConstructProperly.

@jnmt jnmt requested review from choplin and feeblefakie August 6, 2025 03:11
Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants