示例#1
0
 def __init__(self, wallet=None, walletPath=''):
    if wallet != None:
       self.wallet = wallet
    else:
       if not os.path.exists(walletPath):
          print 'Wallet does not exist:'
          print '  ', walletPath
          raise WalletNotFound
       self.wallet = PyBtcWallet().readWalletFile(walletPath)
示例#2
0
 def __init__(self, wallet=None, walletPath=''):
    if wallet != None:
       self.wallet = wallet
    else:
       if not os.path.exists(walletPath):
          print 'Wallet does not exist:'
          print '  ', walletPath
          raise WalletNotFound
       self.wallet = PyBtcWallet().readWalletFile(walletPath)
示例#3
0
def signAssertFile(wltPath, assertFile):
    wlt = PyBtcWallet().readWalletFile(wltPath)
    if not wlt.hasAddr(signAddress):
        print 'Supplied wallet does not have the correct signing key'
        exit(1)

    if wlt.useEncryption and wlt.isLocked:
        print 'Must unlock wallet to sign the assert file...'
        passcnt = 0
        while True:
            passwd = SecureBinaryData(getpass.getpass('Wallet passphrase: '))
            if not wlt.verifyPassphrase(passwd):
                print 'Invalid passphrase!'
                if passcnt == 2:
                    print 'Too many password attempts. Exiting.'
                    exit(1)
                passcnt += 1
                continue
            break

        wlt.unlock(securePassphrase=passwd)
        passwd.destroy()

    addrObj = wlt.getAddrByHash160(addrStr_to_hash160(signAddress)[1])

    def doSignFile(inFile, outFile):
        with open(inFile, 'rb') as f:
            try:
                sigBlock = ASv1CS(addrObj.binPrivKey32_Plain.toBinStr(),
                                  f.read())
            except:
                print 'Error with call to sigBlock'
                exit(1)

        with open(outFile, 'wb') as f:
            f.write(sigBlock)

    doSignFile(assertFile, '%s.sig' % assertFile)
示例#4
0
class PasswordFinder(object): 
   def __init__(self, wallet=None, walletPath=''):
      if wallet != None:
         self.wallet = wallet
      else:
         if not os.path.exists(walletPath):
            print 'Wallet does not exist:'
            print '  ', walletPath
            raise WalletNotFound
         self.wallet = PyBtcWallet().readWalletFile(walletPath)

   def countPasswords(self, segList, segOrdList):
      return reduce(add, [reduce(mul, [len(segList[segIndex])
                                       for segIndex in segOrd])
                          for segOrd in segOrdList])
   
   def recursivePasswordGenerator(self, segList):
      if len(segList) > 0:
         for a in segList[0]:
            for b in self.recursivePasswordGenerator(segList[1:]):
               yield a + b
      else:
         yield ''
         
   # Generates passwords from segs in segList
   #     Example Input: [['Andy','b','c'],['1','2'],['!']]
   # The segOrdList contains a list of ordered 
   # permutations of the segList:
   #     Example Input: [[0,1,2],[2,0,1,],[0,1]]
   # Yields one password at a time until all permutations are exhausted
   #     Example: Andy1!, Andy2!, b1!, b2!, c1!, c2!,
   #              !Andy1, !Andy2, !b1, !b2, !c1, !c2,
   #              Andy1, Andy2, b1, b2, c1, c2
   # The above example is a test case found in test/FindPassTest.py
   def passwordGenerator(self, segList, segOrdList):
      for segOrd in segOrdList:
         orderedSegList = [segList[segIndex] for segIndex in segOrd]
         for result in self.recursivePasswordGenerator(orderedSegList):
            yield result
   
   def searchForPassword(self, segList, segOrdList=[]):
      if len(segOrdList) == 0:
         segOrdList = [range(len(segList))]
      passwordCount = self.countPasswords(segList, segOrdList)
      startTime = RightNow()
      found = False
      result = None
      for i,p in enumerate(self.passwordGenerator(segList, segOrdList)):
         isValid = self.wallet.verifyPassphrase( SecureBinaryData(p) ) 
            
         if isValid:
            # If the passphrase was wrong, it would error out, and not continue
            print 'Passphrase found!'
            print ''
            print '\t', p
            print ''
            print 'Thanks for using this script.  If you recovered coins because of it, '
            print 'please consider donating :) '
            print '   1ArmoryXcfq7TnCSuZa9fQjRYwJ4bkRKfv'
            print ''
            found = True
            open('FOUND_PASSWORD.txt','w').write(p)
            result = p
            break
         elif i%100==0:
               telapsed = (RightNow() - startTime)/3600.
               print ('%d/%d passphrases tested... (%0.1f hours so far)'%(i,passwordCount,telapsed)).rjust(40)
         print p,
         if i % 10 == 9:
            print
      if not found:
         print ''
         
         print 'Script finished!'
         print 'Sorry, none of the provided passphrases were correct :('
         print ''
      return result
示例#5
0
class PasswordFinder(object): 
   def __init__(self, wallet=None, walletPath=''):
      if wallet != None:
         self.wallet = wallet
      else:
         if not os.path.exists(walletPath):
            print 'Wallet does not exist:'
            print '  ', walletPath
            raise WalletNotFound
         self.wallet = PyBtcWallet().readWalletFile(walletPath)

   def countPasswords(self, segList, segOrdList):
      return reduce(add, [reduce(mul, [len(segList[segIndex])
                                       for segIndex in segOrd])
                          for segOrd in segOrdList])
   
   def recursivePasswordGenerator(self, segList):
      if len(segList) > 0:
         for a in segList[0]:
            for b in self.recursivePasswordGenerator(segList[1:]):
               yield a + b
      else:
         yield ''
         
   # Generates passwords from segs in segList
   #     Example Input: [['Andy','b','c'],['1','2'],['!']]
   # The segOrdList contains a list of ordered 
   # permutations of the segList:
   #     Example Input: [[0,1,2],[2,0,1,],[0,1]]
   # Yields one password at a time until all permutations are exhausted
   #     Example: Andy1!, Andy2!, b1!, b2!, c1!, c2!,
   #              !Andy1, !Andy2, !b1, !b2, !c1, !c2,
   #              Andy1, Andy2, b1, b2, c1, c2
   # The above example is a test case found in test/FindPassTest.py
   def passwordGenerator(self, segList, segOrdList):
      for segOrd in segOrdList:
         orderedSegList = [segList[segIndex] for segIndex in segOrd]
         for result in self.recursivePasswordGenerator(orderedSegList):
            yield result
   
   def searchForPassword(self, segList, segOrdList=[]):
      if len(segOrdList) == 0:
         segOrdList = [range(len(segList))]
      passwordCount = self.countPasswords(segList, segOrdList)
      startTime = RightNow()
      found = False
      result = None
      for i,p in enumerate(self.passwordGenerator(segList, segOrdList)):
         isValid = self.wallet.verifyPassphrase( SecureBinaryData(p) ) 
            
         if isValid:
            # If the passphrase was wrong, it would error out, and not continue
            print 'Passphrase found!'
            print ''
            print '\t', p
            print ''
            print 'Thanks for using this script.  If you recovered coins because of it, '
            print 'please consider donating :) '
            print '   1ArmoryXcfq7TnCSuZa9fQjRYwJ4bkRKfv'
            print ''
            found = True
            open('FOUND_PASSWORD.txt','w').write(p)
            result = p
            break
         elif i%100==0:
               telapsed = (RightNow() - startTime)/3600.
               print ('%d/%d passphrases tested... (%0.1f hours so far)'%(i,passwordCount,telapsed)).rjust(40)
         print p,
         if i % 10 == 9:
            print
      if not found:
         print ''
         
         print 'Script finished!'
         print 'Sorry, none of the provided passphrases were correct :('
         print ''
      return result