Skip to content

Commit ebaa1bf

Browse files
committed
No paranoid key disable for bad keyfile perms.
1 parent f8c955e commit ebaa1bf

1 file changed

Lines changed: 28 additions & 53 deletions

File tree

src/shared.py

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@
88
useVeryEasyProofOfWorkForTesting = False # If you set this to True while on the normal network, you won't be able to send or sometimes receive messages.
99

1010

11-
import threading
12-
import sys
13-
from addresses import *
14-
import highlevelcrypto
15-
import Queue
16-
import pickle
17-
import os
18-
import time
11+
# Libraries.
1912
import ConfigParser
20-
import socket
13+
import os
14+
import pickle
15+
import Queue
2116
import random
17+
import socket
18+
import sys
19+
import stat
20+
import threading
21+
import time
22+
23+
# Project imports.
24+
from addresses import *
25+
from debug import logger
2226
import highlevelcrypto
2327
import shared
24-
import stat
28+
2529

2630
config = ConfigParser.SafeConfigParser()
2731
myECCryptorObjects = {}
@@ -131,12 +135,14 @@ def lookupAppdataFolder():
131135
except KeyError:
132136
dataFolder = path.join(environ["HOME"], ".config", APPNAME)
133137
# Migrate existing data to the proper location if this is an existing install
134-
try:
135-
print "Moving data folder to ~/.config/%s" % APPNAME
136-
move(path.join(environ["HOME"], ".%s" % APPNAME), dataFolder)
137-
dataFolder = dataFolder + '/'
138-
except IOError:
139-
dataFolder = dataFolder + '/'
138+
if not os.path.exists(dataFolder):
139+
try:
140+
print "Moving data folder to ~/.config/%s" % APPNAME
141+
move(path.join(environ["HOME"], ".%s" % APPNAME), dataFolder)
142+
dataFolder = dataFolder
143+
except IOError:
144+
dataFolder = dataFolder
145+
dataFolder = dataFolder + '/'
140146
return dataFolder
141147

142148
def isAddressInMyAddressBook(address):
@@ -227,22 +233,12 @@ def reloadMyAddressHashes():
227233
myECCryptorObjects[hash] = highlevelcrypto.makeCryptor(privEncryptionKey)
228234
myAddressesByHash[hash] = addressInKeysFile
229235

230-
if not keyfileSecure:
231-
# Insecure keyfile permissions. Disable key.
232-
config.set(addressInKeysFile, 'enabled', 'false')
233236
else:
234237
sys.stderr.write('Error in reloadMyAddressHashes: Can\'t handle address '
235238
'versions other than 2 or 3.\n')
236239

237240
if not keyfileSecure:
238241
fixSensitiveFilePermissions(appdata + 'keys.dat', hasEnabledKeys)
239-
if hasEnabledKeys:
240-
try:
241-
with open(appdata + 'keys.dat', 'wb') as keyfile:
242-
config.write(keyfile)
243-
except:
244-
print 'Failed to disable vulnerable keys.'
245-
raise
246242

247243
def reloadBroadcastSendersForWhichImWatching():
248244
printLock.acquire()
@@ -350,28 +346,10 @@ def checkSensitiveFilePermissions(filename):
350346
# Fixes permissions on a sensitive file.
351347
def fixSensitiveFilePermissions(filename, hasEnabledKeys):
352348
if hasEnabledKeys:
353-
print
354-
print '******************************************************************'
355-
print '** !! WARNING !! **'
356-
print '******************************************************************'
357-
print '** Possibly major security problem: **'
358-
print '** Your keyfile was vulnerable to being read by other users **'
359-
print '** (including some untrusted daemons). You may wish to consider **'
360-
print '** generating new keys and discontinuing use of your old ones. **'
361-
print '** Your private keys have been disabled for your security, but **'
362-
print '** you may re-enable them using the "Your Identities" tab in **'
363-
print '** the default GUI or by modifying keys.dat such that your keys **'
364-
print '** show "enabled = true". **'
349+
logger.warning('Keyfile had insecure permissions, and there were enabled keys. '
350+
'The truly paranoid should stop using them immediately.')
365351
else:
366-
print '******************************************************************'
367-
print '** !! WARNING !! **'
368-
print '******************************************************************'
369-
print '** Possibly major security problem: **'
370-
print '** Your keyfile was vulnerable to being read by other users. **'
371-
print '** Fortunately, you don\'t have any enabled keys, but be aware **'
372-
print '** that any disabled keys may have been compromised by malware **'
373-
print '** running by other users and that you should reboot before **'
374-
print '** generating any new keys. **'
352+
logger.warning('Keyfile had insecure permissions, but there were no enabled keys.')
375353
try:
376354
present_permissions = os.stat(filename)[0]
377355
disallowed_permissions = stat.S_IRWXG | stat.S_IRWXO
@@ -380,12 +358,9 @@ def fixSensitiveFilePermissions(filename, hasEnabledKeys):
380358
allowed_permissions & present_permissions)
381359
os.chmod(filename, new_permissions)
382360

383-
print '** The file permissions have been automatically fixed. **'
384-
print '******************************************************************'
385-
print
361+
logger.info('Keyfile permissions automatically fixed.')
362+
386363
except Exception, e:
387-
print '** Could NOT automatically fix permissions. **'
388-
print '******************************************************************'
389-
print
364+
logger.exception('Keyfile permissions could not be fixed.')
390365
raise
391366

0 commit comments

Comments
 (0)