Skip to content

feat: ECDSA key handling and ByteBuffer conversions for OpenSSH format#6

Merged
nedithgar merged 5 commits intomainfrom
feat/OpenSSH-ECDSA-Support
Jul 29, 2025
Merged

feat: ECDSA key handling and ByteBuffer conversions for OpenSSH format#6
nedithgar merged 5 commits intomainfrom
feat/OpenSSH-ECDSA-Support

Conversation

@nedithgar
Copy link
Copy Markdown
Owner

This pull request introduces support for handling ECDSA keys (P-256, P-384, and P-521) in OpenSSH format by adding parsing, serialization, and validation functionalities. It also includes test coverage for these features to ensure correctness. Below is a summary of the most important changes:

ECDSA Key Support

  • Added ByteBufferConvertible conformances for P256, P384, and P521 private and public keys to enable reading and writing keys in OpenSSH format. This includes handling curve-specific constraints and key serialization requirements. (Sources/Citadel/Algorithms/ECDSA.swift, Sources/Citadel/Algorithms/ECDSA.swiftR1-R265)
  • Implemented OpenSSHPrivateKey conformances for P256, P384, and P521 private keys, defining key prefixes and types for OpenSSH integration. (Sources/Citadel/Algorithms/ECDSA.swift, Sources/Citadel/Algorithms/ECDSA.swiftR1-R265)

ByteBuffer Enhancements

OpenSSH Key Type Updates

  • Made OpenSSH.KeyType and OpenSSH enums public and added new key types for ECDSA (ecdsaP256, ecdsaP384, ecdsaP521). (Sources/Citadel/OpenSSHKey.swift, [1] [2]

ECDSA Key Parsing APIs

  • Added initializers to P256, P384, and P521 private keys for creating keys from OpenSSH private key strings or data, with optional decryption support. (Sources/Citadel/SSHCert.swift, Sources/Citadel/SSHCert.swiftR124-R192)

Unit Tests

  • Introduced ECDSAKeyTests to validate parsing, serialization, and signing functionality for P-256, P-384, and P-521 private keys. Tests include scenarios for valid keys, encrypted keys, invalid formats, and curve mismatches. (Tests/CitadelTests/ECDSAKeyTests.swift, Tests/CitadelTests/ECDSAKeyTests.swiftR1-R122)

@nedithgar nedithgar self-assigned this Jul 29, 2025
Copilot AI review requested due to automatic review settings July 29, 2025 15:00

This comment was marked as outdated.

@nedithgar nedithgar requested a review from Copilot July 29, 2025 15:17

This comment was marked as outdated.

@nedithgar nedithgar requested a review from Copilot July 29, 2025 15:27

This comment was marked as outdated.

@nedithgar nedithgar requested a review from Copilot July 29, 2025 15:35

This comment was marked as outdated.

@nedithgar nedithgar requested a review from Copilot July 29, 2025 15:41
Copy link
Copy Markdown

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 pull request adds comprehensive ECDSA key support for OpenSSH format, enabling parsing, serialization, and validation of P-256, P-384, and P-521 elliptic curve keys. The implementation provides a complete ECDSA key handling solution with proper SSH format compliance.

Key changes include:

  • ECDSA key type support with ByteBuffer serialization/deserialization for all three curve types
  • SSH bignum handling methods for proper numeric data encoding/decoding
  • Public API extensions for creating ECDSA keys from OpenSSH formatted strings

Reviewed Changes

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

Show a summary per file
File Description
Sources/Citadel/Algorithms/ECDSA.swift Implements ByteBufferConvertible and OpenSSHPrivateKey conformances for P256/P384/P521 keys with SSH format support
Sources/Citadel/ByteBufferHelpers.swift Adds SSH bignum read/write methods and string helper functions for key serialization
Sources/Citadel/OpenSSHKey.swift Makes OpenSSH types public and adds ECDSA key type enumerations
Sources/Citadel/SSHCert.swift Provides convenient initializers for creating ECDSA keys from OpenSSH strings
Tests/CitadelTests/ECDSAKeyTests.swift Comprehensive test suite covering key parsing, validation, and error handling scenarios
Comments suppressed due to low confidence (1)

Tests/CitadelTests/ECDSAKeyTests.swift:90

  • This test uses an empty string which doesn't properly test encrypted key parsing. Consider using a real encrypted key or testing the specific error type that should be thrown for invalid formats.
        XCTAssertThrowsError(try P256.Signing.PrivateKey(sshECDSA: "", decryptionKey: passphrase.data(using: .utf8)))

@nedithgar nedithgar merged commit ba4bc81 into main Jul 29, 2025
1 check passed
@nedithgar nedithgar deleted the feat/OpenSSH-ECDSA-Support branch July 29, 2025 15:48
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