Skip to content

russh doesn't parse comments from public key files #713

Description

@KazWolfe

Description

When parsing a public key file with load_public_key(path), the key's comment is not returned in the final PublicKey struct.

Steps To Reproduce

  1. Create a keypair with a comment, e.g. ssh-keygen -t ed25519 -C "my comment" -f keypair
  2. Dump key information with appropriate functions (see sample code).
  3. Observe error.

Sample Code

fn main() {
    let key = load_public_key("./keypair.pub").unwrap();
    println!("Key Type: {}", key.algorithm().to_string());
    println!("Key Bytes: {}", key.to_string());
    println!("Key Comment: {} (empty: {})", key.comment().to_string(), key.comment().is_empty());
    println!("\nEncoded Key Format:\n\t{}", key.to_openssh().unwrap());
}

Sample Execution

➜  debug git:(master) ✗ ssh-keygen -t ed25519 -C "my comment" -f keypair
Generating public/private ed25519 key pair.
[ snip ]
➜  debug git:(master) ✗ ./russh-demo                                    
Key Type: ssh-ed25519
Key Bytes: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILgm39eVWrPRMq8Kl07z6GFZyfXD4FdVcelOEdH0PVGc
Key Comment:  (empty: true)

Encoded Key Format:
        ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILgm39eVWrPRMq8Kl07z6GFZyfXD4FdVcelOEdH0PVGc

➜  debug git:(master) ✗ cat keypair.pub 
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILgm39eVWrPRMq8Kl07z6GFZyfXD4FdVcelOEdH0PVGc my comment

Expected Results

The comment should be present in both key.comment() as well as in the re-encoded .to_openssh() method.

Actual Results

The comment appears to never be parsed.

Other Notes

A similar phenomenon can also be seen with AgentClient<?>.request_identities(). In that case, however, the returned AgentIdentity will populate the comment, but the underlying public_key is still missing it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions