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

Support encrypting user password with ed25519 SSH keys #131

Open
kallioli opened this issue Feb 21, 2024 · 2 comments
Open

Support encrypting user password with ed25519 SSH keys #131

kallioli opened this issue Feb 21, 2024 · 2 comments

Comments

@kallioli
Copy link

Hello,

When attempting to encrypt a user password with an Ed25519 SSH public key, we encountered the following error in the startup log:

2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init [-] plugin 'SetUserPasswordPlugin' failed with error 'Invalid SSH key': cloudbaseinit.utils.crypt.CryptException: Invalid SSH key
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init [-] Invalid SSH key: cloudbaseinit.utils.crypt.CryptException: Invalid SSH key
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init Traceback (most recent call last):
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\init.py", line 67, in _exec_plugin
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init     shared_data)
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\plugins\common\setuserpassword.py", line 131, in execute
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init     self._set_metadata_password(password, service)
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\plugins\common\setuserpassword.py", line 64, in _set_metadata_password
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init     user_pwd_encryption_key, password)
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\plugins\common\setuserpassword.py", line 35, in _encrypt_password
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init     with cm.load_ssh_rsa_public_key(ssh_pub_key) as rsa:
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init   File "C:\Program Files\Cloudbase Solutions\Cloudbase-Init\Python\lib\site-packages\cloudbaseinit\utils\crypt.py", line 173, in load_ssh_rsa_public_key
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init     raise CryptException('Invalid SSH key')
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init cloudbaseinit.utils.crypt.CryptException: Invalid SSH key
2024-02-14 13:50:30.467 5192 ERROR cloudbaseinit.init

I believe the problem stems from the cryptography library used to encrypt passwords (in cloudbaseinit/utils/crypt.py), which does not support encryption methods for elliptic key formats (like Ed25519).

Are there any plans to add support for these formats in the future?

Thank you.

Do you plan in future adding support for theses format ?

@ader1990
Copy link
Member

ader1990 commented Apr 3, 2024

Hello, the RSA backend implementation has the encrypt function in python cryptography https://github.com/pyca/cryptography/blob/main/src/rust/src/backend/rsa.rs#L446, whereas the Ed25519 does not https://github.com/pyca/cryptography/blob/main/src/rust/src/backend/ed25519.rs#L120.

More investigation is required to see how to implement this in a safe way. From the literature, the Ed25519 keys are used primarly for signing, not for encryption/decryption.

One way would be similar to this https://stackoverflow.com/questions/65684414/how-to-use-ssh-keygen-ed25519-keys-for-encryption-in-python.

@kallioli can you please provide the broader context for the feature and a decryption workflow that you are already using to make sure the Python implementation is compatible for encryption?

Thank you,
Adrian Vladu

@ale9412
Copy link

ale9412 commented Jul 23, 2024

I am having the same issue using ECDSA with a curve P384

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

No branches or pull requests

3 participants