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

Invalid private key - secrets #3923

Closed
squigley opened this issue Jan 14, 2020 · 4 comments
Closed

Invalid private key - secrets #3923

squigley opened this issue Jan 14, 2020 · 4 comments
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@squigley
Copy link

Environment

  • Python version: 3.6.8
  • NetBox version: 2.6.12

Steps to Reproduce

  1. Add a preexisting public key to the admin's profile
  2. Attempt to add a secret to a device, click create, get prompted for the private key to get a session key
  3. Provide the private key which matches the public key in the admin's profile (with header/footer, without header/footer, with newlines, without newlines..)
  4. Box goes away
  5. Click create again, get prompted for the private key again.

Expected Behaviour

System would accept my private key matching the public key in the profile, give me a session key, and allow me to save the secret.

Observed Behaviour

Just keeps prompting for the private key.
Using the dev tools I see that in response to submitting the private key, I am getting a 400 error, with the text "Invalid Private Key."
It doesn't matter what format I try submitting the private key, eg including the BEGIN/END lines etc, and with the encoded body as one long line, or split after x number of characters, every attempt is invalid.

I was having this issue with 2.6.7, so I upgraded to 2.6.12, deleted the public key from the profile, readded it, but there was no change. I have tried using both Firefox and Chrome, and both fail.

@hSaria
Copy link
Contributor

hSaria commented Jan 15, 2020

I tried to recreate this but wasn't able to. What do you mean by preexisting, like one you've generated elsewhere? If you navigate to /user/user-key/, does it say that the user key is active?

Here's a dummy private and public key pair. It works with those

private

Generated with openssl genrsa -out private.pem 2048

-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA4GDcjN87MbuvRoTpNOG0RT9UA/ThzlrTJXSEuoRnLdl1KGME
g76VDrx0cHrXtBQh63Vqx0P0RNRfiPhJQO6/GjifY5gmJhJqG5Zlv95atH2NrCdY
mW0IEUslceuV2NS0PA9v6oP/5hU4cb39Y3KC5REu7LX7qunz75HTTWncnnNfmxZo
DZN8nJKco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icWw1uX156mlQ70nfwVCge079xryK3Flwri
R/hKmkKdURZ/J5fe9mYtDRTeQa2nc7lhISBVoR9rbT8SM5oXuUy/OsRBlQP69YOM
OXbUeqoKQbcoW5UVvblBXT45mmYCvuw2BYKYcAeVL7uFjWMjO8uk9YdGCR/FoA2Q
LJLm0QKBgQDn67F0j+id/mq4eSeP1OJGxrjdmOmJOBpaOqku2CmUtmvkS88E3XOW
Bwn2dcn2mm0YEdPN284EVr0iDylgoGqJRDvX8MkLCrjOqbJaq4Clfxb9jkDPglKG
wJgxfdNlhtzTS/fX77wYfTRQjNvmf7SiXTZx9OMfk2/HRErBBgxz7g==
-----END RSA PRIVATE KEY-----
public

Generated with openssl rsa -in private.pem -outform PEM -pubout -out public.pem

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4GDcjN87MbuvRoTpNOG0
RT9UA/ThzlrTJXSEuoRnLdl1KGMEg76VDrx0cHrXtBQh63Vqx0P0RNRfiPhJQO6/
GjifY5gmJhJqG5Zlv95atH2NrCdYmW0IEUslceuV2NS0PA9v6oP/5hU4cb39Y3KC
5REu7LX7qunz75HTTWncnnNfmxZoDZN8nJKcoI3L+/PLukQlQrA0dTQJTbOBlkI3
7QTHt71w+sSEzDqMtR8OEyER4VUoBWkqf6T8PttbvtK993PhRTd5sg/7rtixpJAP
5T96O6icMKamEemZbOdKKu20MKxnDbn2VPHmRoy3Huqf7TjzEyQMTEAWYEZJggUc
wwIDAQAB
-----END PUBLIC KEY-----

@squigley
Copy link
Author

Oh. I was trying to use my existing SSH private and public keys, and while it is an RSA key, I guess it is not in the PEM format which is required.

After using your generation commands to create a new private and public key in PEM format, and loading them into Netbox, I now get "session key received!" and am able to create and unlock secrets.

Can I suggest that the Secrets documentation page at https://netbox.readthedocs.io/en/stable/core-functionality/secrets/ be modified to add a note that SSH keys can't be used, or if they can, how to convert them into the correct format?

I think I got lead down the wrong path when I read the line "you can either generate a new RSA key pair, or upload the public key belonging to a pair you already have.", and I presumed this meant I could use my existing SSH key pair.

Thanks for the quick reply, which resolved my issue.

@jeremystretch
Copy link
Member

I'm going to treat this as a bug, since we should be validating the key format on input. (But the docs also need to be improved.)

@squigley Would you mind generating a new key pair in the same format as the one you tried and posting it here to assist with testing? I'm pretty sure I know what's going on but it would help to be sure.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application labels Jan 15, 2020
@squigley
Copy link
Author

Sure, the keypair I was trying to use was one which was generated by "ssh-keygen", with no parameters. eg:

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/squigley/.ssh/id_rsa): /tmp/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /tmp/id_rsa.
Your public key has been saved in /tmp/id_rsa.pub.
The key fingerprint is:
SHA256:K/717DPH8CaAuoRhpoaxCtGwBX0bU9rw5vOMVobJoBg squigley@9K771Z2L

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEA81rv3gmBjbyhNY33qDyM1vpVZ1sUSL5QGpxb23X21+et7Edkn5SG
FCOeeWXAA2FJRdNHOjk62qnu9+ABgzHtqO+Jp9gch8EWBpyTEaQcxA91cR0aio7AjgzOON
Kl8C1p8JpMUC6O9Rh+ulJn8l+vAl9sCOvOEEV6XpZIpAGcx7ptiHESIQbNhNcLcU1JAVJB
8XMbsdhJGUTpvkKINNKY0t9W57GluTYrSTiSJhwle3u7IqwF0nMfDDu5qJyY+U9N4OndIL
nBDw0v+pQYBYaWfTwOOnS5HqvS6AyXb2RpLCJMJASu3mgl3RU2qRlW4hTvHHsCpIa/8Ft/
tiHZ5f/S/vw0FpdR/OYFQnPn9EPWMKql0iKPAeWlN9ITh3FaordSvEq+V11Bh+aSOfq9zs
2XHpjhGWVcuuDLWsIouyj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qe734AGDMe2o74mn2ByHwRYGnJMRpBzED3VxHRqKjsCODM440qXwLWnwmkxQLo71GH66UmfyX68CX2wI684QRXpelkikAZzHum2IcRIhBs2E1wtxTUkBUkHxcxux2EkZROm+Qog00pjS31bnsaW5NitJOJImHCV7e7sirAXScx8MO7monJj5T03g6d0gucEPDS/6lBgFhpZ9PA46dLkeq9LoDJdvZGksIkwkBK7eaCXdFTapGVbiFO8cewKkhr/wW3+2Idnl/9L+/DQWl1H85gVCc+f0Q9YwqqXSIo8B5aU30hOHcVqit1K8Sr5XXUGH5pI5+r3OzZcemOEZZVy64Mtawii7KMfa4/Ywg07xsV34f+/VexBh9s264VH83jYaM6+LUv1D16ijVQpJZLsfSDHxnCCQntjPIm5ezWPW2+8c4wz8NcKDDDs= squigley@9K771Z2L

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants