def CreateQRMatrix(dataToEncode, errLevel=QRErrorCorrectLevel.L): dataLen = len(dataToEncode) baseSz = 4 if errLevel == QRErrorCorrectLevel.L else \ 5 if errLevel == QRErrorCorrectLevel.M else \ 6 if errLevel == QRErrorCorrectLevel.Q else \ 7 # errLevel = QRErrorCorrectLevel.H sz = baseSz if dataLen < 70 else 5 + (dataLen - 70) / 30 qrmtrx = [[]] while sz<20: try: errCorrectEnum = getattr(QRErrorCorrectLevel, errLevel.upper()) qr = QRCode(sz, errCorrectEnum) qr.addData(dataToEncode) qr.make() success=True break except TypeError: sz += 1 if not success: LOGERROR('Unsuccessful attempt to create QR code') LOGERROR('Data to encode: (Length: %s, isAscii: %s)', \ len(dataToEncode), isASCII(dataToEncode)) return [[0]], 1 qrmtrx = [] modCt = qr.getModuleCount() for r in range(modCt): tempList = [0]*modCt for c in range(modCt): # The matrix is transposed by default, from what we normally expect tempList[c] = 1 if qr.isDark(c,r) else 0 qrmtrx.append(tempList) return [qrmtrx, modCt]
def clearSignMessage(self): messageText = str(self.messageTextEdit.toPlainText()) if not isASCII(messageText): QMessageBox.warning(self, self.tr('Non ASCII Text'), self.tr('Message to sign must be ASCII'), QMessageBox.Ok) else: try: privateKey = self.getPrivateKeyFromAddrInput() except: QMessageBox.warning(self, self.tr('Invalid Address'), self.tr('The signing address is invalid.'), QMessageBox.Ok) raise if privateKey: signature = ASv1CS(privateKey, messageText) self.signatureDisplay.setPlainText(signature) else: QMessageBox.warning(self, self.tr('Private Key Not Known'), self.tr('The private key is not known for this address.'), QMessageBox.Ok)
def bareSignMessage(self): messageText = str(self.messageTextEdit.toPlainText()) if not isASCII(messageText): QMessageBox.warning(self, 'Non ASCII Text', 'Message to sign must be ASCII', QMessageBox.Ok) else: try: privateKey = self.getPrivateKeyFromAddrInput() if privateKey: signature = ASv0(privateKey, messageText) self.signatureDisplay.setPlainText(signature['b64-signature']) else: QMessageBox.warning(self, 'Private Key Not Known', 'The private key is not known for this address.', QMessageBox.Ok) except: QMessageBox.warning(self, 'Invalid Address', 'The signing address is invalid.', QMessageBox.Ok) raise
def readBitcoinConf(self, makeIfDNE=False): LOGINFO('Reading groestlcoin.conf file') bitconf = os.path.join(self.satoshiRoot, 'groestlcoin.conf') if not os.path.exists(bitconf): if not makeIfDNE: raise self.BitcoinDotConfError, 'Could not find groestlcoin.conf' else: LOGINFO('No groestlcoin.conf available. Creating it...') touchFile(bitconf) # Guarantee that bitcoin.conf file has very strict permissions if OS_WINDOWS: if OS_VARIANT[0].lower() == 'xp': LOGERROR('Cannot set permissions correctly in XP!') LOGERROR('Please confirm permissions on the following file ') LOGERROR('are set to exclusive access only for your user ') LOGERROR( '(it usually is, but Groestlcoin Armory cannot guarantee it ' ) LOGERROR('on XP systems):') LOGERROR(' %s', bitconf) else: LOGINFO('Setting permissions on groestlcoin.conf') import ctypes username_u16 = ctypes.create_unicode_buffer(u'\0', 512) str_length = ctypes.c_int(512) ctypes.windll.Advapi32.GetUserNameW(ctypes.byref(username_u16), ctypes.byref(str_length)) CLI_OPTIONS.disableConfPermis = True #!!!GRS if not CLI_OPTIONS.disableConfPermis: import win32process LOGINFO('Setting permissions on groestlcoin.conf') cmd_icacls = [ u'icacls', bitconf, u'/inheritance:r', u'/grant:r', u'%s:F' % username_u16.value ] kargs = {} kargs['shell'] = True kargs['creationflags'] = win32process.CREATE_NO_WINDOW icacls_out = subprocess_check_output(cmd_icacls, **kargs) LOGINFO('icacls returned: %s', icacls_out) else: LOGWARN( 'Skipped setting permissions on groestlcoin.conf file') else: if not CLI_OPTIONS.disableConfPermis: LOGINFO('Setting permissions on groestlcoin.conf') os.chmod(bitconf, stat.S_IRUSR | stat.S_IWUSR) else: LOGWARN('Skipped setting permissions on groestlcoin.conf file') with open(bitconf, 'r') as f: # Find the last character of the each line: either a newline or '#' endchr = lambda line: line.find('#') if line.find( '#') > 1 else len(line) # Reduce each line to a list of key,value pairs separated with '=' allconf = [l[:endchr(l)].strip().split('=') for l in f.readlines()] # Need to convert to (x[0],x[1:]) in case the password has '=' in it allconfPairs = [[x[0], '='.join(x[1:])] for x in allconf if len(x) > 1] # Convert the list of pairs to a dictionary self.bitconf = dict(allconfPairs) # Look for rpcport, use default if not there self.bitconf['rpcport'] = int( self.bitconf.get('rpcport', BITCOIN_RPC_PORT)) # We must have a username and password. If not, append to file if not self.bitconf.has_key('rpcuser'): LOGDEBUG('No rpcuser: creating one') with open(bitconf, 'a') as f: f.write('\n') f.write('rpcuser=generated_by_armory\n') self.bitconf['rpcuser'] = '******' if not self.bitconf.has_key('rpcpassword'): LOGDEBUG('No rpcpassword: creating one') with open(bitconf, 'a') as f: randBase58 = SecureBinaryData().GenerateRandom(32).toBinStr() randBase58 = binary_to_base58(randBase58) f.write('\n') f.write('rpcpassword=%s' % randBase58) self.bitconf['rpcpassword'] = randBase58 if not isASCII(self.bitconf['rpcuser']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcuser)!') if not isASCII(self.bitconf['rpcpassword']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcpassword)!') self.bitconf['host'] = '127.0.0.1'
def readBitcoinConf(self, makeIfDNE=False): LOGINFO('Reading bitcoin.conf file') bitconf = os.path.join(self.satoshiRoot, 'bitcoin.conf') if not os.path.exists(bitconf): if not makeIfDNE: raise self.BitcoinDotConfError, 'Could not find bitcoin.conf' else: LOGINFO('No bitcoin.conf available. Creating it...') touchFile(bitconf) # Guarantee that bitcoin.conf file has very strict permissions if OS_WINDOWS: if OS_VARIANT[0].lower()=='xp': LOGERROR('Cannot set permissions correctly in XP!') LOGERROR('Please confirm permissions on the following file ') LOGERROR('are set to exclusive access only for your user ') LOGERROR('(it usually is, but Armory cannot guarantee it ') LOGERROR('on XP systems):') LOGERROR(' %s', bitconf) else: LOGINFO('Setting permissions on bitcoin.conf') import ctypes username_u16 = ctypes.create_unicode_buffer(u'\0', 512) str_length = ctypes.c_int(512) ctypes.windll.Advapi32.GetUserNameW(ctypes.byref(username_u16), ctypes.byref(str_length)) if not CLI_OPTIONS.disableConfPermis: import win32process LOGINFO('Setting permissions on bitcoin.conf') cmd_icacls = [u'icacls',bitconf,u'/inheritance:r',u'/grant:r', u'%s:F' % username_u16.value] kargs = {} kargs['shell'] = True kargs['creationflags'] = win32process.CREATE_NO_WINDOW icacls_out = subprocess_check_output(cmd_icacls, **kargs) LOGINFO('icacls returned: %s', icacls_out) else: LOGWARN('Skipped setting permissions on bitcoin.conf file') else: if not CLI_OPTIONS.disableConfPermis: LOGINFO('Setting permissions on bitcoin.conf') os.chmod(bitconf, stat.S_IRUSR | stat.S_IWUSR) else: LOGWARN('Skipped setting permissions on bitcoin.conf file') with open(bitconf,'r') as f: # Find the last character of the each line: either a newline or '#' endchr = lambda line: line.find('#') if line.find('#')>1 else len(line) # Reduce each line to a list of key,value pairs separated with '=' allconf = [l[:endchr(l)].strip().split('=') for l in f.readlines()] # Need to convert to (x[0],x[1:]) in case the password has '=' in it allconfPairs = [[x[0], '='.join(x[1:])] for x in allconf if len(x)>1] # Convert the list of pairs to a dictionary self.bitconf = dict(allconfPairs) # Look for rpcport, use default if not there self.bitconf['rpcport'] = int(self.bitconf.get('rpcport', BITCOIN_RPC_PORT)) # We must have a username and password. If not, append to file if not self.bitconf.has_key('rpcuser'): LOGDEBUG('No rpcuser: creating one') with open(bitconf,'a') as f: f.write('\n') f.write('rpcuser=generated_by_armory\n') self.bitconf['rpcuser'] = '******' if not self.bitconf.has_key('rpcpassword'): LOGDEBUG('No rpcpassword: creating one') with open(bitconf,'a') as f: randBase58 = SecureBinaryData().GenerateRandom(32).toBinStr() randBase58 = binary_to_base58(randBase58) f.write('\n') f.write('rpcpassword=%s' % randBase58) self.bitconf['rpcpassword'] = randBase58 if not isASCII(self.bitconf['rpcuser']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcuser)!') if not isASCII(self.bitconf['rpcpassword']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcpassword)!') self.bitconf['host'] = '127.0.0.1'
def readBitcoinConf(self, makeIfDNE=False): LOGINFO('Reading bitcoin.conf file') bitconf = os.path.join( self.satoshiHome, 'bitcoin.conf' ) if not os.path.exists(bitconf): if not makeIfDNE: raise self.BitcoinDotConfError, 'Could not find bitcoin.conf' else: LOGINFO('No bitcoin.conf available. Creating it...') touchFile(bitconf) # Guarantee that bitcoin.conf file has very strict permissions if OS_WINDOWS: if OS_VARIANT[0].lower()=='xp': LOGERROR('Cannot set permissions correctly in XP!') LOGERROR('Please confirm permissions on the following file ') LOGERROR('are set to exclusive access only for your user ') LOGERROR('(it usually is, but Armory cannot guarantee it ') LOGERROR('on XP systems):') LOGERROR(' %s', bitconf) else: LOGINFO('Setting permissions on bitcoin.conf') import win32api username = win32api.GetUserName() LOGINFO('Setting permissions on bitcoin.conf') cmd_icacls = ['icacls',bitconf,'/inheritance:r','/grant:r', '%s:F' % username] icacls_out = subprocess_check_output(cmd_icacls, shell=True) LOGINFO('icacls returned: %s', icacls_out) else: LOGINFO('Setting permissions on bitcoin.conf') os.chmod(bitconf, stat.S_IRUSR | stat.S_IWUSR) with open(bitconf,'r') as f: # Find the last character of the each line: either a newline or '#' endchr = lambda line: line.find('#') if line.find('#')>1 else len(line) # Reduce each line to a list of key,value pairs separated with '=' allconf = [l[:endchr(l)].strip().split('=') for l in f.readlines()] # Need to convert to (x[0],x[1:]) in case the password has '=' in it allconfPairs = [[x[0], '='.join(x[1:])] for x in allconf if len(x)>1] # Convert the list of pairs to a dictionary self.bitconf = dict(allconfPairs) # Look for rpcport, use default if not there self.bitconf['rpcport'] = int(self.bitconf.get('rpcport', BITCOIN_RPC_PORT)) # We must have a username and password. If not, append to file if not self.bitconf.has_key('rpcuser'): LOGDEBUG('No rpcuser: creating one') with open(bitconf,'a') as f: f.write('\n') f.write('rpcuser=generated_by_armory\n') self.bitconf['rpcuser'] = '******' if not self.bitconf.has_key('rpcpassword'): LOGDEBUG('No rpcpassword: creating one') with open(bitconf,'a') as f: randBase58 = SecureBinaryData().GenerateRandom(32).toBinStr() randBase58 = binary_to_base58(randBase58) f.write('\n') f.write('rpcpassword=%s' % randBase58) self.bitconf['rpcpassword'] = randBase58 if not isASCII(self.bitconf['rpcuser']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcuser)!') if not isASCII(self.bitconf['rpcpassword']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcpassword)!') self.bitconf['host'] = '127.0.0.1'
def accept(self): if not isASCII(unicode(self.editSegment.text())): UnicodeErrorBox(self) return else: super(DlgEnterSegment, self).accept()