Opened 12 years ago

Closed 9 years ago

#1588 enhancement closed duplicate (duplicate)

verifyHostKey fails if ~/.ssh/known_hosts missing or it's empty

Reported by: jaze Owned by:
Priority: normal Milestone:
Component: conch Keywords:
Cc: spiv Branch:
Author:

Description

--- twisted.orig/conch/client/default.py        2006-03-17 20:15:04.132838425 +0200
+++ twisted/conch/client/default.py     2006-03-17 20:04:32.286945052 +0200
@@ -43,10 +43,12 @@
             print 'Host key verification failed.'
             return defer.fail(ConchError('bad host key'))
         print "Warning: Permanently added '%s' (%s) to the list of known hosts." % (khHost, {'ssh-dss':'DSA', 'ssh-rsa':'RSA'}[keyType])
-        known_hosts = open(os.path.expanduser('~/.ssh/known_hosts'), 'r+')
-        known_hosts.seek(-1, 2)
-        if known_hosts.read(1) != '\n':
-            known_hosts.write('\n')
+        path = os.path.expanduser('~/.ssh/known_hosts')
+        known_hosts = open(path, 'a+')
+        if os.path.getsize(path) > 0:
+            known_hosts.seek(-1, 2)
+            if known_hosts.read(1) != '\n':
+                known_hosts.write('\n')
         encodedKey = base64.encodestring(pubKey).replace('\n', '')
         known_hosts.write('%s %s %s\n' % (khHost, keyType, encodedKey))
         known_hosts.close()

Change History (4)

comment:1 Changed 12 years ago by jaze

Component: coreconch
Owner: changed from Glyph to z3p

comment:2 Changed 12 years ago by spiv

Cc: spiv added

comment:3 Changed 9 years ago by Jean-Paul Calderone

Resolution: duplicate
Status: newclosed

Duplicate of #1301

comment:4 Changed 7 years ago by <automation>

Owner: z3p deleted
Note: See TracTickets for help on using tickets.