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

Raises exception when loading SSH Keys with using windows new lines #921

Open
Antsiscool opened this issue Aug 31, 2023 · 2 comments · May be fixed by #922
Open

Raises exception when loading SSH Keys with using windows new lines #921

Antsiscool opened this issue Aug 31, 2023 · 2 comments · May be fixed by #922

Comments

@Antsiscool
Copy link

Expected behaviour

When connecting to an SFTP server using an SSH key for authentication it should be able to connect when using the correct key. This should happen regardless of the new lines.

Actual behaviour

When the key is formatted using windows new lines (\r\n) an argument error is raised:

ArgumentError (Expected -----BEGIN OPENSSH PRIVATE KEY-----)
 at start of private key

System configuration

  • net-ssh 7.2.0

Example App

Using the sample private key from test/integration/test_agent.rb

private_key = <<~EOF
  -----BEGIN OPENSSH PRIVATE KEY-----
  b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
  QyNTUxOQAAACDuVIPDUXcVkXOyNAaFsotbySHLNG/Gw6gc3j2k2zcRVAAAAKD6bG5++mxu
  fgAAAAtzc2gtZWQyNTUxOQAAACDuVIPDUXcVkXOyNAaFsotbySHLNG/Gw6gc3j2k2zcRVA
  AAAEAydU4FtZ9+5o5Y/m1aPNHFda37Fm0Us5FlUKx50tWw+e5Ug8NRdxWRc7I0BoWyi1vJ
  Ics0b8bDqBzePaTbNxFUAAAAGmJhcnRsZUBCYXJ0bGVzLU1hY0Jvb2stUHJvAQID
  -----END OPENSSH PRIVATE KEY-----
EOF

Net::SSH::Authentication::ED25519::OpenSSHPrivateKeyLoader.read(private_key, nil)
private_key = <<~EOF
  -----BEGIN OPENSSH PRIVATE KEY-----
  b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
  QyNTUxOQAAACDuVIPDUXcVkXOyNAaFsotbySHLNG/Gw6gc3j2k2zcRVAAAAKD6bG5++mxu
  fgAAAAtzc2gtZWQyNTUxOQAAACDuVIPDUXcVkXOyNAaFsotbySHLNG/Gw6gc3j2k2zcRVA
  AAAEAydU4FtZ9+5o5Y/m1aPNHFda37Fm0Us5FlUKx50tWw+e5Ug8NRdxWRc7I0BoWyi1vJ
  Ics0b8bDqBzePaTbNxFUAAAAGmJhcnRsZUBCYXJ0bGVzLU1hY0Jvb2stUHJvAQID
  -----END OPENSSH PRIVATE KEY-----
EOF

private_key = private_key.gsub("\n", "\r\n")

Net::SSH::Authentication::ED25519::OpenSSHPrivateKeyLoader.read(private_key, nil)
@mfazekas
Copy link
Collaborator

@Antsiscool thanks much for the report. 👍 Can you make a PR fixing it?

@Antsiscool
Copy link
Author

I have made a PR #922

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

Successfully merging a pull request may close this issue.

2 participants