ojarva / python-sshpubkeys

OpenSSH public key parser for Python
BSD 3-Clause "New" or "Revised" License
101 stars 42 forks source link

UnicodeDecodeError #53

Closed sarah-peter closed 2 years ago

sarah-peter commented 6 years ago

Hello,

when I do

from sshpubkeys import SSHKey
test = "ssh-rsa AAAAB4NzaC1yc2EAAAADAQABAAACAQDPWKPR4XKgibQQixw25NIl8+zVKIWf9NabGjALfXDTjH4amm3Vc5enkqnwAnGPf5NjDlwghBR+L1N9D4v4x8m4iQxM7ic+crPFvO4eqt04RXHIObkM3cfzgrt8bGjdGfAmcvfQw482+8qtxWQGoIwr+4WCi2lZwfoRG/R3522eeNw3C1VhUpOn4swrBCVU7PkJjFLmNWlA+TirqeCeuSIadosgWDtr3JxshI7op8w4xkvqpKWIV1qX+SN/xg8lY8zkN+l8DwvxM87SP/jlginwi9RyWjNA2FTqOS24LrY4crorBkwRXnX0cX3G0Vl8YH70x0ZwtWL4xYU48WyVzzax7n3Wa1rsnrMD+Yngxdl8+N7tCD1cLWPqsiB5ZW6p3SedcaIF/jtWtpwfJmaWM+udsdwx8l1emxtibnxxx/3z5qslrDVe6NDG1D060puTLbGPoA98WlTdaQkTt/66OJnob/NgWprN9qUoGat6kVd81pDpodQ+fYyf+cAo/NzWSyo0UVXNR+Zq8pgUCrRb7leaC1pAd8QNJqG28bTaVTURwFjdE6yBpUi+FnHUKwl3KjoyIVnAMXrVJOwQxL0sUf3YMrUyUjDmwpGoUFQr7CkwDcFTARfeSjFf1it8a6M8dPrUHo8CBBPLPJz7NK8PDZclIgtpD5/50BIKR488TybypQ=="
SSHKey(test)

I get the following error:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/.../venv/lib/python3.7/site-packages/sshpubkeys/keys.py", line 132, in __init__
    self.parse(keydata)
  File "/.../venv/lib/python3.7/site-packages/sshpubkeys/keys.py", line 428, in parse
    print(unpacked_key_type.decode(encoding="ascii", errors="ignore"))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 0: invalid start byte

To me the key looks fine and I wasn't able to figure out what exactly is causing the issue.

Python 3.7.0 and 3.6.4 sshpubkeys 3.1.0

sarah-peter commented 6 years ago

After some more checking I figured out that there is indeed an issue with the key. The 14th character should be 3 instead of 4 (no clue how that snug in there). Still the package should handle this more gracefully.

ojarva commented 6 years ago

Yes, indeed it should be handled more gracefully - as you have a test data for this, feel free to open a PR fixing this, I'm happy to review and merge it. Please include a test case as well so that there won't be regressions later on.

ojarva commented 2 years ago

As this is ~3 years old with no activity, I'm going to close this as I don't expect anything to happen around this. If @sarah-peter or someone else wants to fix this, feel free to create a PR.