Refactored config file (keys.dat) mangement to use helper_config.py and not specify filename throughout code

This commit is contained in:
DivineOmega 2013-06-27 10:42:03 +01:00
parent bfdb04716a
commit 86ce3de50d
10 changed files with 71 additions and 75 deletions

View File

@ -35,7 +35,7 @@ print 'Uncomment these next four lines to create new deterministic addresses.'
#print jsonDeterministicAddresses #print jsonDeterministicAddresses
#print json.loads(jsonDeterministicAddresses) #print json.loads(jsonDeterministicAddresses)
#print 'Uncomment this next line to print the first deterministic address that would be generated with the given passphrase. This will Not add it to the Bitmessage interface or the keys.dat file.' #print 'Uncomment this next line to print the first deterministic address that would be generated with the given passphrase. This will Not add it to the Bitmessage interface or the '+helper_config.getFileName()+' file.'
#print api.getDeterministicAddress('asdfasdfqwser'.encode('base64'),3,1) #print api.getDeterministicAddress('asdfasdfqwser'.encode('base64'),3,1)
#print 'Uncomment this line to subscribe to an address. (You must use your own address, this one is invalid).' #print 'Uncomment this line to subscribe to an address. (You must use your own address, this one is invalid).'

View File

@ -26,7 +26,7 @@ from class_singleListener import *
from class_addressGenerator import * from class_addressGenerator import *
# Helper Functions # Helper Functions
import helper_startup import helper_config
import helper_bootstrap import helper_bootstrap
def connectToStream(streamNumber): def connectToStream(streamNumber):
@ -496,7 +496,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
fromAddressEnabled = shared.config.getboolean( fromAddressEnabled = shared.config.getboolean(
fromAddress, 'enabled') fromAddress, 'enabled')
except: except:
return 'API Error 0013: Could not find your fromAddress in the keys.dat file.' return 'API Error 0013: Could not find your fromAddress in the '+helper_config.getFileName()+' file.'
if not fromAddressEnabled: if not fromAddressEnabled:
return 'API Error 0014: Your fromAddress is disabled. Cannot send.' return 'API Error 0014: Your fromAddress is disabled. Cannot send.'
@ -560,7 +560,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
fromAddressEnabled = shared.config.getboolean( fromAddressEnabled = shared.config.getboolean(
fromAddress, 'enabled') fromAddress, 'enabled')
except: except:
return 'API Error 0013: could not find your fromAddress in the keys.dat file.' return 'API Error 0013: could not find your fromAddress in the '+helper_config.getFileName()+' file.'
ackdata = OpenSSL.rand(32) ackdata = OpenSSL.rand(32)
toAddress = '[Broadcast subscribers]' toAddress = '[Broadcast subscribers]'
ripe = '' ripe = ''
@ -706,7 +706,7 @@ if __name__ == "__main__":
signal.signal(signal.SIGINT, helper_generic.signal_handler) signal.signal(signal.SIGINT, helper_generic.signal_handler)
# signal.signal(signal.SIGINT, signal.SIG_DFL) # signal.signal(signal.SIGINT, signal.SIG_DFL)
helper_startup.loadConfig() helper_config.loadConfig()
helper_bootstrap.knownNodes() helper_bootstrap.knownNodes()
helper_bootstrap.dns() helper_bootstrap.dns()

View File

@ -29,6 +29,7 @@ import os
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
import pickle import pickle
import platform import platform
import helper_config
try: try:
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -72,11 +73,10 @@ class MyForm(QtGui.QMainWindow):
self, 'Message', displayMsg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) self, 'Message', displayMsg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes: if reply == QtGui.QMessageBox.Yes:
shared.config.remove_section(addressInKeysFile) shared.config.remove_section(addressInKeysFile)
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig();
shared.config.write(configfile)
# Configure Bitmessage to start on startup (or remove the # Configure Bitmessage to start on startup (or remove the
# configuration) based on the setting in the keys.dat file # configuration) based on the setting in the config file
if 'win32' in sys.platform or 'win64' in sys.platform: if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows # Auto-startup for Windows
RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run" RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
@ -924,23 +924,19 @@ class MyForm(QtGui.QMainWindow):
def click_actionManageKeys(self): def click_actionManageKeys(self):
if 'darwin' in sys.platform or 'linux' in sys.platform: if 'darwin' in sys.platform or 'linux' in sys.platform:
if shared.appdata == '': if shared.appdata == '':
# reply = QtGui.QMessageBox.information(self, 'keys.dat?','You reply = QtGui.QMessageBox.information(self, helper_config.getFileName()+'?', _translate(
# may manage your keys by editing the keys.dat file stored in "MainWindow", "You may manage your keys by editing the "+helper_config.getFileName()+" file stored in the same directory as this program. It is important that you back up this file."), QMessageBox.Ok)
# the same directory as this program. It is important that you
# back up this file.', QMessageBox.Ok)
reply = QtGui.QMessageBox.information(self, 'keys.dat?', _translate(
"MainWindow", "You may manage your keys by editing the keys.dat file stored in the same directory as this program. It is important that you back up this file."), QMessageBox.Ok)
else: else:
QtGui.QMessageBox.information(self, 'keys.dat?', _translate( QtGui.QMessageBox.information(self, helper_config.getFileName()+'?', _translate(
"MainWindow", "You may manage your keys by editing the keys.dat file stored in\n %1 \nIt is important that you back up this file.").arg(shared.appdata), QMessageBox.Ok) "MainWindow", "You may manage your keys by editing the "+helper_config.getFileName()+" file stored in\n %1 \nIt is important that you back up this file.").arg(shared.appdata), QMessageBox.Ok)
elif sys.platform == 'win32' or sys.platform == 'win64': elif sys.platform == 'win32' or sys.platform == 'win64':
if shared.appdata == '': if shared.appdata == '':
reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open keys.dat?"), _translate( reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open "+helper_config.getFileName()+"?"), _translate(
"MainWindow", "You may manage your keys by editing the keys.dat file stored in the same directory as this program. It is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)"), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) "MainWindow", "You may manage your keys by editing the "+helper_config.getFileName()+" file stored in the same directory as this program. It is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)"), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
else: else:
reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open keys.dat?"), _translate( reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open "+helper_config.getFileName()+"?"), _translate(
"MainWindow", "You may manage your keys by editing the keys.dat file stored in\n %1 \nIt is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)").arg(shared.appdata), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No) "MainWindow", "You may manage your keys by editing the "+helper_config.getFileName()+" file stored in\n %1 \nIt is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)").arg(shared.appdata), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes: if reply == QtGui.QMessageBox.Yes:
self.openKeysFile() self.openKeysFile()
@ -974,9 +970,9 @@ class MyForm(QtGui.QMainWindow):
def openKeysFile(self): def openKeysFile(self):
if 'linux' in sys.platform: if 'linux' in sys.platform:
subprocess.call(["xdg-open", shared.appdata + 'keys.dat']) subprocess.call(["xdg-open", helper_config.getFilepath()])
else: else:
os.startfile(shared.appdata + 'keys.dat') os.startfile(helper_config.getFilepath())
def changeEvent(self, event): def changeEvent(self, event):
if event.type() == QtCore.QEvent.WindowStateChange: if event.type() == QtCore.QEvent.WindowStateChange:
@ -1783,8 +1779,7 @@ class MyForm(QtGui.QMainWindow):
# shared.config.set('bitmessagesettings', 'maxcores', # shared.config.set('bitmessagesettings', 'maxcores',
# str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText())) # str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()))
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
if 'win32' in sys.platform or 'win64' in sys.platform: if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows # Auto-startup for Windows
@ -1802,19 +1797,18 @@ class MyForm(QtGui.QMainWindow):
pass pass
if shared.appdata != '' and self.settingsDialogInstance.ui.checkBoxPortableMode.isChecked(): # If we are NOT using portable mode now but the user selected that we should... if shared.appdata != '' and self.settingsDialogInstance.ui.checkBoxPortableMode.isChecked(): # If we are NOT using portable mode now but the user selected that we should...
# Write the keys.dat file to disk in the new location # Write the config file to disk in the new location
shared.sqlLock.acquire() shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('movemessagstoprog') shared.sqlSubmitQueue.put('movemessagstoprog')
shared.sqlLock.release() shared.sqlLock.release()
with open('keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
# Write the knownnodes.dat file to disk in the new location # Write the knownnodes.dat file to disk in the new location
shared.knownNodesLock.acquire() shared.knownNodesLock.acquire()
output = open('knownnodes.dat', 'wb') output = open('knownnodes.dat', 'wb')
pickle.dump(shared.knownNodes, output) pickle.dump(shared.knownNodes, output)
output.close() output.close()
shared.knownNodesLock.release() shared.knownNodesLock.release()
os.remove(shared.appdata + 'keys.dat') os.remove(shared.appdata + helper_config.getFileName())
os.remove(shared.appdata + 'knownnodes.dat') os.remove(shared.appdata + 'knownnodes.dat')
shared.appdata = '' shared.appdata = ''
@ -1825,23 +1819,21 @@ class MyForm(QtGui.QMainWindow):
shared.sqlLock.acquire() shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('movemessagstoappdata') shared.sqlSubmitQueue.put('movemessagstoappdata')
shared.sqlLock.release() shared.sqlLock.release()
# Write the keys.dat file to disk in the new location # Write the config file to disk in the new location
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
# Write the knownnodes.dat file to disk in the new location # Write the knownnodes.dat file to disk in the new location
shared.knownNodesLock.acquire() shared.knownNodesLock.acquire()
output = open(shared.appdata + 'knownnodes.dat', 'wb') output = open(shared.appdata + 'knownnodes.dat', 'wb')
pickle.dump(shared.knownNodes, output) pickle.dump(shared.knownNodes, output)
output.close() output.close()
shared.knownNodesLock.release() shared.knownNodesLock.release()
os.remove('keys.dat') os.remove(helper_config.getFileName())
os.remove('knownnodes.dat') os.remove('knownnodes.dat')
def click_radioButtonBlacklist(self): def click_radioButtonBlacklist(self):
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'white': if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'white':
shared.config.set('bitmessagesettings', 'blackwhitelist', 'black') shared.config.set('bitmessagesettings', 'blackwhitelist', 'black')
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
# self.ui.tableWidgetBlacklist.clearContents() # self.ui.tableWidgetBlacklist.clearContents()
self.ui.tableWidgetBlacklist.setRowCount(0) self.ui.tableWidgetBlacklist.setRowCount(0)
self.loadBlackWhiteList() self.loadBlackWhiteList()
@ -1850,8 +1842,7 @@ class MyForm(QtGui.QMainWindow):
def click_radioButtonWhitelist(self): def click_radioButtonWhitelist(self):
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black': if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black':
shared.config.set('bitmessagesettings', 'blackwhitelist', 'white') shared.config.set('bitmessagesettings', 'blackwhitelist', 'white')
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
# self.ui.tableWidgetBlacklist.clearContents() # self.ui.tableWidgetBlacklist.clearContents()
self.ui.tableWidgetBlacklist.setRowCount(0) self.ui.tableWidgetBlacklist.setRowCount(0)
self.loadBlackWhiteList() self.loadBlackWhiteList()
@ -1931,8 +1922,7 @@ class MyForm(QtGui.QMainWindow):
shared.config.set(str(addressAtCurrentRow), 'mailinglistname', str( shared.config.set(str(addressAtCurrentRow), 'mailinglistname', str(
self.dialog.ui.lineEditMailingListName.text().toUtf8())) self.dialog.ui.lineEditMailingListName.text().toUtf8()))
self.ui.tableWidgetYourIdentities.item(currentRow, 1).setTextColor(QtGui.QColor(137, 04, 177)) self.ui.tableWidgetYourIdentities.item(currentRow, 1).setTextColor(QtGui.QColor(137, 04, 177))
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
self.rerenderInboxToLabels() self.rerenderInboxToLabels()
def click_NewAddressDialog(self): def click_NewAddressDialog(self):
@ -2442,8 +2432,7 @@ class MyForm(QtGui.QMainWindow):
addressAtCurrentRow = str( addressAtCurrentRow = str(
self.ui.tableWidgetYourIdentities.item(currentRow, 1).text()) self.ui.tableWidgetYourIdentities.item(currentRow, 1).text())
shared.config.set(addressAtCurrentRow, 'enabled', 'true') shared.config.set(addressAtCurrentRow, 'enabled', 'true')
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
self.ui.tableWidgetYourIdentities.item( self.ui.tableWidgetYourIdentities.item(
currentRow, 0).setTextColor(QtGui.QColor(0, 0, 0)) currentRow, 0).setTextColor(QtGui.QColor(0, 0, 0))
self.ui.tableWidgetYourIdentities.item( self.ui.tableWidgetYourIdentities.item(
@ -2467,8 +2456,7 @@ class MyForm(QtGui.QMainWindow):
currentRow, 2).setTextColor(QtGui.QColor(128, 128, 128)) currentRow, 2).setTextColor(QtGui.QColor(128, 128, 128))
if shared.safeConfigGetBoolean(addressAtCurrentRow, 'mailinglist'): if shared.safeConfigGetBoolean(addressAtCurrentRow, 'mailinglist'):
self.ui.tableWidgetYourIdentities.item(currentRow, 1).setTextColor(QtGui.QColor(137, 04, 177)) self.ui.tableWidgetYourIdentities.item(currentRow, 1).setTextColor(QtGui.QColor(137, 04, 177))
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
shared.reloadMyAddressHashes() shared.reloadMyAddressHashes()
def on_action_YourIdentitiesClipboard(self): def on_action_YourIdentitiesClipboard(self):
@ -2561,8 +2549,7 @@ class MyForm(QtGui.QMainWindow):
currentRow, 1).text() currentRow, 1).text()
shared.config.set(str(addressAtCurrentRow), 'label', str( shared.config.set(str(addressAtCurrentRow), 'label', str(
self.ui.tableWidgetYourIdentities.item(currentRow, 0).text().toUtf8())) self.ui.tableWidgetYourIdentities.item(currentRow, 0).text().toUtf8()))
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
self.rerenderComboBoxSendFrom() self.rerenderComboBoxSendFrom()
# self.rerenderInboxFromLabels() # self.rerenderInboxFromLabels()
self.rerenderInboxToLabels() self.rerenderInboxToLabels()

View File

@ -173,7 +173,7 @@ class Ui_NewAddressDialog(object):
NewAddressDialog.setWindowTitle(_translate("NewAddressDialog", "Create new Address", None)) NewAddressDialog.setWindowTitle(_translate("NewAddressDialog", "Create new Address", None))
self.label.setText(_translate("NewAddressDialog", "Here you may generate as many addresses as you like. Indeed, creating and abandoning addresses is encouraged. You may generate addresses by using either random numbers or by using a passphrase. If you use a passphrase, the address is called a \"deterministic\" address.\n" self.label.setText(_translate("NewAddressDialog", "Here you may generate as many addresses as you like. Indeed, creating and abandoning addresses is encouraged. You may generate addresses by using either random numbers or by using a passphrase. If you use a passphrase, the address is called a \"deterministic\" address.\n"
"The \'Random Number\' option is selected by default but deterministic addresses have several pros and cons:", None)) "The \'Random Number\' option is selected by default but deterministic addresses have several pros and cons:", None))
self.label_5.setText(_translate("NewAddressDialog", "<html><head/><body><p><span style=\" font-weight:600;\">Pros:<br/></span>You can recreate your addresses on any computer from memory. <br/>You need-not worry about backing up your keys.dat file as long as you can remember your passphrase. <br/><span style=\" font-weight:600;\">Cons:<br/></span>You must remember (or write down) your passphrase if you expect to be able to recreate your keys if they are lost. <br/>You must remember the address version number and the stream number along with your passphrase. <br/>If you choose a weak passphrase and someone on the Internet can brute-force it, they can read your messages and send messages as you.</p></body></html>", None)) self.label_5.setText(_translate("NewAddressDialog", "<html><head/><body><p><span style=\" font-weight:600;\">Pros:<br/></span>You can recreate your addresses on any computer from memory. <br/>You need-not worry about backing up your private keys as long as you can remember your passphrase. <br/><span style=\" font-weight:600;\">Cons:<br/></span>You must remember (or write down) your passphrase if you expect to be able to recreate your keys if they are lost. <br/>You must remember the address version number and the stream number along with your passphrase. <br/>If you choose a weak passphrase and someone on the Internet can brute-force it, they can read your messages and send messages as you.</p></body></html>", None))
self.radioButtonRandomAddress.setText(_translate("NewAddressDialog", "Use a random number generator to make an address", None)) self.radioButtonRandomAddress.setText(_translate("NewAddressDialog", "Use a random number generator to make an address", None))
self.radioButtonDeterministicAddress.setText(_translate("NewAddressDialog", "Use a passphrase to make addresses", None)) self.radioButtonDeterministicAddress.setText(_translate("NewAddressDialog", "Use a passphrase to make addresses", None))
self.checkBoxEighteenByteRipe.setText(_translate("NewAddressDialog", "Spend several minutes of extra computing time to make the address(es) 1 or 2 characters shorter", None)) self.checkBoxEighteenByteRipe.setText(_translate("NewAddressDialog", "Spend several minutes of extra computing time to make the address(es) 1 or 2 characters shorter", None))

View File

@ -9,6 +9,7 @@ import highlevelcrypto
from addresses import * from addresses import *
from pyelliptic import arithmetic from pyelliptic import arithmetic
import tr import tr
import helper_config
class addressGenerator(threading.Thread): class addressGenerator(threading.Thread):
@ -114,8 +115,7 @@ class addressGenerator(threading.Thread):
address, 'privSigningKey', privSigningKeyWIF) address, 'privSigningKey', privSigningKeyWIF)
shared.config.set( shared.config.set(
address, 'privEncryptionKey', privEncryptionKeyWIF) address, 'privEncryptionKey', privEncryptionKeyWIF)
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
# It may be the case that this address is being generated # It may be the case that this address is being generated
# as a result of a call to the API. Let us put the result # as a result of a call to the API. Let us put the result
@ -226,8 +226,7 @@ class addressGenerator(threading.Thread):
address, 'privSigningKey', privSigningKeyWIF) address, 'privSigningKey', privSigningKeyWIF)
shared.config.set( shared.config.set(
address, 'privEncryptionKey', privEncryptionKeyWIF) address, 'privEncryptionKey', privEncryptionKeyWIF)
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
shared.UISignalQueue.put(('writeNewAddressToTable', ( shared.UISignalQueue.put(('writeNewAddressToTable', (
label, address, str(streamNumber)))) label, address, str(streamNumber))))

View File

@ -125,7 +125,7 @@ class singleWorker(threading.Thread):
except Exception as err: except Exception as err:
shared.printLock.acquire() shared.printLock.acquire()
sys.stderr.write( sys.stderr.write(
'Error within doPOWForMyV2Pubkey. Could not read the keys from the keys.dat file for a requested address. %s\n' % err) 'Error within doPOWForMyV2Pubkey. Could not read the keys from the '+helper_config.getFileName()+' file for a requested address. %s\n' % err)
shared.printLock.release() shared.printLock.release()
return return
@ -170,8 +170,7 @@ class singleWorker(threading.Thread):
shared.UISignalQueue.put(('updateStatusBar', '')) shared.UISignalQueue.put(('updateStatusBar', ''))
shared.config.set( shared.config.set(
myAddress, 'lastpubkeysendtime', str(int(time.time()))) myAddress, 'lastpubkeysendtime', str(int(time.time())))
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
def doPOWForMyV3Pubkey(self, hash): # This function also broadcasts out the pubkey message once it is done with the POW def doPOWForMyV3Pubkey(self, hash): # This function also broadcasts out the pubkey message once it is done with the POW
myAddress = shared.myAddressesByHash[hash] myAddress = shared.myAddressesByHash[hash]
@ -192,7 +191,7 @@ class singleWorker(threading.Thread):
except Exception as err: except Exception as err:
shared.printLock.acquire() shared.printLock.acquire()
sys.stderr.write( sys.stderr.write(
'Error within doPOWForMyV3Pubkey. Could not read the keys from the keys.dat file for a requested address. %s\n' % err) 'Error within doPOWForMyV3Pubkey. Could not read the keys from the '+helper_config.getFileName()+' file for a requested address. %s\n' % err)
shared.printLock.release() shared.printLock.release()
return return
@ -246,8 +245,7 @@ class singleWorker(threading.Thread):
shared.UISignalQueue.put(('updateStatusBar', '')) shared.UISignalQueue.put(('updateStatusBar', ''))
shared.config.set( shared.config.set(
myAddress, 'lastpubkeysendtime', str(int(time.time()))) myAddress, 'lastpubkeysendtime', str(int(time.time())))
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
def sendBroadcast(self): def sendBroadcast(self):
shared.sqlLock.acquire() shared.sqlLock.acquire()
@ -271,7 +269,7 @@ class singleWorker(threading.Thread):
fromaddress, 'privencryptionkey') fromaddress, 'privencryptionkey')
except: except:
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', ( shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file.")))) ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the "+helper_config.getFileName()+" file."))))
continue continue
privSigningKeyHex = shared.decodeWalletImportFormat( privSigningKeyHex = shared.decodeWalletImportFormat(
@ -345,7 +343,7 @@ class singleWorker(threading.Thread):
fromaddress, 'privencryptionkey') fromaddress, 'privencryptionkey')
except: except:
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', ( shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file.")))) ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the "+helper_config.getFileName()+" file."))))
continue continue
privSigningKeyHex = shared.decodeWalletImportFormat( privSigningKeyHex = shared.decodeWalletImportFormat(
@ -639,7 +637,7 @@ class singleWorker(threading.Thread):
fromaddress, 'privencryptionkey') fromaddress, 'privencryptionkey')
except: except:
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', ( shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file.")))) ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the "+helper_config.getFileName()+" file."))))
continue continue
privSigningKeyHex = shared.decodeWalletImportFormat( privSigningKeyHex = shared.decodeWalletImportFormat(
@ -685,7 +683,7 @@ class singleWorker(threading.Thread):
fromaddress, 'privencryptionkey') fromaddress, 'privencryptionkey')
except: except:
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', ( shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file.")))) ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the "+helper_config.getFileName()+" file."))))
continue continue
privSigningKeyHex = shared.decodeWalletImportFormat( privSigningKeyHex = shared.decodeWalletImportFormat(

View File

@ -5,6 +5,7 @@ import time
import shutil # used for moving the messages.dat file import shutil # used for moving the messages.dat file
import sys import sys
import os import os
import helper_config
# This thread exists because SQLITE3 is so un-threadsafe that we must # This thread exists because SQLITE3 is so un-threadsafe that we must
# submit queries to it and it puts results back in a different queue. They # submit queries to it and it puts results back in a different queue. They
@ -82,8 +83,7 @@ class sqlThread(threading.Thread):
shared.config.set('bitmessagesettings', 'sockspassword', '') shared.config.set('bitmessagesettings', 'sockspassword', '')
shared.config.set('bitmessagesettings', 'keysencrypted', 'false') shared.config.set('bitmessagesettings', 'keysencrypted', 'false')
shared.config.set('bitmessagesettings', 'messagesencrypted', 'false') shared.config.set('bitmessagesettings', 'messagesencrypted', 'false')
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
# People running earlier versions of PyBitmessage do not have the # People running earlier versions of PyBitmessage do not have the
# usedpersonally field in their pubkeys table. Let's add it. # usedpersonally field in their pubkeys table. Let's add it.
@ -94,8 +94,7 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
shared.config.set('bitmessagesettings', 'settingsversion', '3') shared.config.set('bitmessagesettings', 'settingsversion', '3')
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
# People running earlier versions of PyBitmessage do not have the # People running earlier versions of PyBitmessage do not have the
# encodingtype field in their inbox and sent tables or the read field # encodingtype field in their inbox and sent tables or the read field
@ -115,8 +114,7 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
shared.config.set('bitmessagesettings', 'settingsversion', '4') shared.config.set('bitmessagesettings', 'settingsversion', '4')
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
if shared.config.getint('bitmessagesettings', 'settingsversion') == 4: if shared.config.getint('bitmessagesettings', 'settingsversion') == 4:
shared.config.set('bitmessagesettings', 'defaultnoncetrialsperbyte', str( shared.config.set('bitmessagesettings', 'defaultnoncetrialsperbyte', str(
@ -131,8 +129,7 @@ class sqlThread(threading.Thread):
shared.config.set( shared.config.set(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', '0') 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', '0')
shared.config.set('bitmessagesettings', 'settingsversion', '6') shared.config.set('bitmessagesettings', 'settingsversion', '6')
with open(shared.appdata + 'keys.dat', 'wb') as configfile: helper_config.saveConfig()
shared.config.write(configfile)
# From now on, let us keep a 'version' embedded in the messages.dat # From now on, let us keep a 'version' embedded in the messages.dat
# file so that when we make changes to the database, the database # file so that when we make changes to the database, the database

View File

@ -3,6 +3,7 @@ import socket
import defaultKnownNodes import defaultKnownNodes
import pickle import pickle
import time import time
import helper_config
def knownNodes(): def knownNodes():
try: try:
@ -17,7 +18,7 @@ def knownNodes():
shared.knownNodes = pickle.load(pickleFile) shared.knownNodes = pickle.load(pickleFile)
pickleFile.close() pickleFile.close()
if shared.config.getint('bitmessagesettings', 'settingsversion') > 6: if shared.config.getint('bitmessagesettings', 'settingsversion') > 6:
print 'Bitmessage cannot read future versions of the keys file (keys.dat). Run the newer version of Bitmessage.' print 'Bitmessage cannot read future versions of the keys file ('+helper_config.getFileName()+'). Run the newer version of Bitmessage.'
raise SystemExit raise SystemExit

View File

@ -4,21 +4,28 @@ import sys
import os import os
storeConfigFilesInSameDirectoryAsProgramByDefault = False # The user may de-select Portable Mode in the settings if they want the config files to stay in the application data folder. storeConfigFilesInSameDirectoryAsProgramByDefault = False # The user may de-select Portable Mode in the settings if they want the config files to stay in the application data folder.
filename = 'keys.dat'
def getFileName():
return filename
def getFilePath():
return shared.appdata + filename
def loadConfig(): def loadConfig():
# First try to load the config file (the keys.dat file) from the program # First try to load the config file (as defiend in 'filename') from the program
# directory # directory
shared.config.read('keys.dat') shared.config.read(getFilePath())
try: try:
shared.config.get('bitmessagesettings', 'settingsversion') shared.config.get('bitmessagesettings', 'settingsversion')
print 'Loading config files from same directory as program' print 'Loading config files from same directory as program'
shared.appdata = '' shared.appdata = ''
except: except:
# Could not load the keys.dat file in the program directory. Perhaps it # Could not load the config file in the program directory. Perhaps it
# is in the appdata directory. # is in the appdata directory.
shared.appdata = shared.lookupAppdataFolder() shared.appdata = shared.lookupAppdataFolder()
shared.config = ConfigParser.SafeConfigParser() shared.config = ConfigParser.SafeConfigParser()
shared.config.read(shared.appdata + 'keys.dat') shared.config.read(getFilePath())
try: try:
shared.config.get('bitmessagesettings', 'settingsversion') shared.config.get('bitmessagesettings', 'settingsversion')
print 'Loading existing config files from', shared.appdata print 'Loading existing config files from', shared.appdata
@ -74,5 +81,11 @@ def loadConfig():
print 'Creating new config files in', shared.appdata print 'Creating new config files in', shared.appdata
if not os.path.exists(shared.appdata): if not os.path.exists(shared.appdata):
os.makedirs(shared.appdata) os.makedirs(shared.appdata)
with open(shared.appdata + 'keys.dat', 'wb') as configfile:
shared.config.write(configfile) saveConfig();
def saveConfig():
with open(getFilePath(), 'wb') as configfile:
shared.config.write(configfile)

View File

@ -21,6 +21,7 @@ import socket
import random import random
import highlevelcrypto import highlevelcrypto
import shared import shared
import helper_config
config = ConfigParser.SafeConfigParser() config = ConfigParser.SafeConfigParser()
myECCryptorObjects = {} myECCryptorObjects = {}
@ -201,7 +202,7 @@ def decodeWalletImportFormat(WIFstring):
def reloadMyAddressHashes(): def reloadMyAddressHashes():
printLock.acquire() printLock.acquire()
print 'reloading keys from keys.dat file' print 'reloading keys from '+helper_config.getFileName()+' file'
printLock.release() printLock.release()
myECCryptorObjects.clear() myECCryptorObjects.clear()
myAddressesByHash.clear() myAddressesByHash.clear()