Ticket #5894 defect new
ckeygen --changepass truncates private keys to zero bytes
| Reported by: | ltaylor.volks | Owned by: | therve |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | conch | Keywords: | |
| Cc: | z3p | Branch: |
branches/ckeygen-changepass-5894
(diff, github, buildbot, log) |
| Author: | therve | Launchpad Bug: |
Description
ckeygen --changepass does not work and exhibits different failing behavior for unencrypted and encrypted keys.
- Unencrypted keys are truncated to zero bytes because the key is opened and written to in one call, which throws a TypeError (no data is written).
- Encrypted keys don't get destroyed, but the passphrase change also fails to complete due to an uncaught EncryptedKeyError. The user is never prompted for a passphrase and old/new passphrases provided on the command line are not used
1. Unencrypted key - TypeError, nulls your private key
$ ckeygen -f /Users/blah/.ssh/id_rsa -p
Enter new passphrase (empty for no passphrase):
Enter same passphrase again:
Traceback (most recent call last):
File "/Users/blah/Develop/virtualenvs/lodgeprox/bin/ckeygen", line 7, in <module>
execfile(__file__)
File "/Users/blah/Develop/code/3rdparty/twisted-hg/bin/conch/ckeygen", line 15, in <module>
run()
File "/Users/blah/Develop/code/3rdparty/twisted-hg/twisted/conch/scripts/ckeygen.py", line 66, in run
changePassPhrase(options)
File "/Users/blah/Develop/code/3rdparty/twisted-hg/twisted/conch/scripts/ckeygen.py", line 144, in changePassPhrase
keys.Key(key).toString(passphrase=options['newpass']))
TypeError: toString() got an unexpected keyword argument 'passphrase'
Fix:
- The call to toString needs to be fixed to provide the passphrase using the correct arg
- The private key should not be opened for writing until the key has been regenerated with the passphrase
- Needs tests
2. Encrypted key - EncryptedKeyError
$ ckeygen -f /Users/blah/.ssh/id_rsa -p
Traceback (most recent call last):
File "/Users/blah/Develop/virtualenvs/lodgeprox/bin/ckeygen", line 7, in <module>
execfile(__file__)
File "/Users/blah/Develop/code/3rdparty/twisted-hg/bin/conch/ckeygen", line 15, in <module>
run()
File "/Users/blah/Develop/code/3rdparty/twisted-hg/twisted/conch/scripts/ckeygen.py", line 66, in run
changePassPhrase(options)
File "/Users/blah/Develop/code/3rdparty/twisted-hg/twisted/conch/scripts/ckeygen.py", line 125, in changePassPhrase
key = keys.Key.fromFile(options['filename']).keyObject
File "/Users/blah/Develop/code/3rdparty/twisted-hg/twisted/conch/ssh/keys.py", line 66, in fromFile
return Class.fromString(file(filename, 'rb').read(), type, passphrase)
File "/Users/blah/Develop/code/3rdparty/twisted-hg/twisted/conch/ssh/keys.py", line 95, in fromString
return method(data, passphrase)
File "/Users/blah/Develop/code/3rdparty/twisted-hg/twisted/conch/ssh/keys.py", line 218, in _fromString_PRIVATE_OPENSSH
raise EncryptedKeyError('encrypted key with no passphrase'
twisted.conch.ssh.keys.EncryptedKeyError: encrypted key with no passphrase
Fix:
- Catch and deal with EncryptedKeyError
- If user provides old and new passphrases, use them
- Needs tests
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

