Skip to content

Implement SHA256 authentication for Fronius firmware 1.38.6-1+#179

Merged
MaStr merged 9 commits intomainfrom
copilot/fix-178
Sep 9, 2025
Merged

Implement SHA256 authentication for Fronius firmware 1.38.6-1+#179
MaStr merged 9 commits intomainfrom
copilot/fix-178

Conversation

Copy link
Contributor

Copilot AI commented Sep 7, 2025

Fronius firmware version 1.38.6-1 changed the login encryption from MD5 to SHA256. This PR implements version-dependent authentication to support both old and new firmware versions.

Changes Made

Core Authentication Updates

  • Enhanced hash_utf8() function: Added algorithm parameter supporting both "MD5" and "SHA256" with backward-compatible MD5 default
  • Updated get_auth_header() method: Now uses version-appropriate algorithm from API config and includes correct algorithm in digest auth header
  • Extended FroniusApiConfig dataclass: Added auth_algorithm field with MD5 default for backward compatibility

Version Configuration

  • Split API configuration: Updated the last config range to create a boundary at firmware 1.38.6-1
    • Versions < 1.38.6-1: Continue using MD5
    • Versions ≥ 1.38.6-1: Use SHA256
  • Preserved existing behavior: All firmware versions before 1.38.6-1 maintain identical authentication behavior

Testing

  • Comprehensive test suite: Added 8 new test cases covering boundary conditions, algorithm selection, and hash function behavior
  • Regression testing: All existing tests continue to pass, ensuring no breaking changes

Example Usage

# Firmware 1.37.0 automatically uses MD5
config_old = get_api_config(version.parse("1.37.0"))
print(config_old.auth_algorithm)  # "MD5"

# Firmware 1.38.6-1+ automatically uses SHA256  
config_new = get_api_config(version.parse("1.38.6-1"))
print(config_new.auth_algorithm)  # "SHA256"

# Hash function supports both algorithms
hash_utf8("test", "MD5")     # 32-character MD5 hex digest
hash_utf8("test", "SHA256")  # 64-character SHA256 hex digest

The implementation maintains full backward compatibility while adding support for the new SHA256 authentication requirement in newer firmware versions.

Fixes #178.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor Author

Copilot AI commented Sep 7, 2025

@MaStr 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Co-authored-by: MaStr <1036501+MaStr@users.noreply.github.com>
Copilot AI changed the title [WIP] Adjustments for 1.38.6-1 - login encryption Implement SHA256 authentication for Fronius firmware 1.38.6-1+ Sep 7, 2025
Copilot AI requested a review from MaStr September 7, 2025 18:12
@MaStr
Copy link
Owner

MaStr commented Sep 8, 2025

This fix needs some more changes.
It seems that the change needs a two step approach.

Old passwords needs to be hashed with MD5.
Newer passwords with sha256.

On the same time the complete digest needs to be sha256 now.

@MaStr MaStr requested a review from Copilot September 8, 2025 12:41
@MaStr MaStr marked this pull request as ready for review September 8, 2025 12:42

This comment was marked as outdated.

@MaStr MaStr requested a review from Copilot September 8, 2025 19:57
Copy link
Contributor

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

Implements version-dependent SHA256 authentication for Fronius firmware 1.38.6-1+ while maintaining backward compatibility with MD5 for older versions. The authentication method is automatically selected based on firmware version.

  • Enhanced authentication system with algorithm parameter supporting both MD5 and SHA256
  • Split API configuration to handle version-specific authentication requirements
  • Added comprehensive test coverage for authentication boundary conditions

Reviewed Changes

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

File Description
src/batcontrol/inverter/fronius.py Core authentication implementation with enhanced hash function, API config updates, and multi-method login logic
tests/batcontrol/inverter/test_fronius_auth.py Comprehensive test suite covering hash algorithms, version boundaries, and authentication behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@MaStr MaStr removed their request for review September 9, 2025 05:50
@MaStr MaStr merged commit 0d23301 into main Sep 9, 2025
10 checks passed
@MaStr MaStr deleted the copilot/fix-178 branch September 9, 2025 05:50
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.

Adjustments for 1.38.6-1 - login encryption

3 participants