Esempio n. 1
0
 def createAddr(self, ):
     # eckey = EC_KEY(int(os.urandom(32).encode('hex'), 16))
     pk = EC_KEY(int(os.urandom(32).encode('hex'), 16))
     addr = Address()
     addr.priv = SecretToASecret(getSecret(pk), True)
     addr.addr = getAddrFromPrivateKey(addr.priv)
     self.addresses.append(addr)
Esempio n. 2
0
    def getPrivKeyForAddress(self, addr, secondPassword=None):
        '''Return private key for an address'''
        for address in self.addresses:
            if addr == address.addr:
                if address.doubleEncrypted:
                    if not secondPassword:
                        raise WrongPassword('You must provide a'
                                            ' second password for double'
                                            ' encrypted wallet')
                    try:
                        uncryptedKey = self.decryptPK(
                            address.priv,
                            secondPassword,
                            address.sharedKey)
                        try:
                            if getAddrFromPrivateKey(uncryptedKey) \
                                    != address.addr:
                                raise WrongPassword('Wrong second password')
                        except:
                            raise WrongPassword('Wrong second password')
                        return uncryptedKey
                    except:
                        import traceback
                        traceback.print_exc()
                        raise

                else:
                    return address.priv
Esempio n. 3
0
    def getPrivKeyForAddress(self, addr, secondPassword=None):
        '''Return private key for an address'''
        for address in self.addresses:
            if addr == address.addr:
                if address.doubleEncrypted:
                    if not secondPassword:
                        raise WrongPassword('You must provide a'
                                            ' second password for double'
                                            ' encrypted wallet')
                    try:
                        uncryptedKey = self.decryptPK(
                            address.priv,
                            secondPassword,
                            address.sharedKey)
                        try:
                            if getAddrFromPrivateKey(uncryptedKey) != address.addr:
                                raise WrongPassword('Wrong second password')
                        except:
                            raise WrongPassword('Wrong second password')
                        return uncryptedKey
                    except:
                        import traceback
                        traceback.print_exc()
                        raise

                else:
                    return address.priv
Esempio n. 4
0
    def doubleDecryptPrivKeys(self, secondPass):
        if any([addr.doubleEncrypted is False for addr in self.addresses]):
            raise DataError('Some keys are not double encrypted')

        self.testDoublePK(secondPass)

        for addr in self.addresses:
            if addr.sharedKey is None:
                addr.sharedKey = 'BitPurse'
            addr.priv = self.decryptPK(addr.priv, secondPass,
                                       addr.sharedKey)
            addr.doubleEncrypted = False
            assert addr.addr == getAddrFromPrivateKey(addr.priv)
            QApplication.processEvents()
        self.settings.useDoubleEncryption = True
Esempio n. 5
0
    def createAddr(self, doubleKey):
        if doubleKey:
            self.testDoublePK(doubleKey)

        # eckey = EC_KEY(int(os.urandom(32).encode('hex'), 16))
        pk = EC_KEY(int(os.urandom(32).encode('hex'), 16))
        addr = Address()
        addr.priv = SecretToASecret(getSecret(pk), True)
        addr.addr = getAddrFromPrivateKey(addr.priv)
        addr.sharedKey = 'BitPurse'
        if doubleKey:
            addr.priv = self.encryptPK(addr.priv, doubleKey, addr.sharedKey)
            addr.doubleEncrypted = True

        self.addresses.append(addr)
Esempio n. 6
0
    def testDoublePK(self, secondPass):
        # Test if password match at least for the first key
        if len(self.addresses) < 1:
            return

        try:
            if (getAddrFromPrivateKey(self.decryptPK(self.addresses[0]
                                                     .priv,
                                                     secondPass,
                                                     self.addresses[0]
                                                     .sharedKey))
                    != self.addresses[0].addr):
                raise DataError('Double Password didn\'t match '
                                'with other keys')
        except:
            raise DataError('Double Password didn\'t match with other keys')
Esempio n. 7
0
    def doubleDecryptPrivKeys(self, secondPass):
        if any([addr.doubleEncrypted is False for addr in self.addresses
                if not addr.watchOnly]):
            raise DataError('Some keys are not double encrypted')

        self.testDoublePK(secondPass)

        for addr in [address for address in self.addresses
                     if not address.watchOnly]:
            if addr.sharedKey is None:
                addr.sharedKey = 'BitPurse'
            addr.priv = self.decryptPK(addr.priv, secondPass,
                                       addr.sharedKey)
            addr.doubleEncrypted = False
            assert addr.addr == getAddrFromPrivateKey(addr.priv)
            QApplication.processEvents()
        self.settings.useDoubleEncryption = True
Esempio n. 8
0
    def testDoublePK(self, secondPass):
        # Test if password match at least for the first key
        addresses = [address for address in self.addresses
                     if not address.watchOnly]
        if len(addresses) < 1:
            return

        try:
            if (getAddrFromPrivateKey(self.decryptPK(addresses[0]
                                                     .priv,
                                                     secondPass,
                                                     addresses[0]
                                                     .sharedKey))
                    != addresses[0].addr):
                raise DataError('Double Password didn\'t match '
                                'with other keys')
        except:
            raise DataError('Double Password didn\'t match with other keys')
Esempio n. 9
0
    def importFromPrivateKey(self, passKey, privateKey,
                             label='Undefined', doubleKey=''):

        # Test if password match at least for the first key
        if doubleKey:
            self.testDoublePK(doubleKey)

        privateKey = privateKey.strip('\n')
        bc = getAddrFromPrivateKey(privateKey)
        if bc in self.getAddrAddresses():
            raise DataError('This private key is already in the wallet')

        addr = Address()
        addr.addr = bc
        addr.sharedKey = 'BitPurse'
        if doubleKey:
            privateKey = self.encryptPK(privateKey, doubleKey, addr.sharedKey)
            addr.doubleEncrypted = True
        addr.priv = privateKey
        addr.label = label

        self.addresses.append(addr)
        self.store(passKey)
Esempio n. 10
0
    def importFromPrivateKey(self, passKey, privateKey,
                             label='Undefined', doubleKey=''):

        # Test if password match at least for the first key
        if doubleKey:
            self.testDoublePK(doubleKey)

        privateKey = privateKey.strip('\n')
        bc = getAddrFromPrivateKey(privateKey)
        if bc in self.getAddrAddresses():
            raise DataError('This private key is already in the wallet')

        addr = Address()
        addr.addr = bc
        addr.sharedKey = 'BitPurse'
        if doubleKey:
            privateKey = self.encryptPK(privateKey, doubleKey, addr.sharedKey)
            addr.doubleEncrypted = True
        addr.priv = privateKey
        addr.label = label

        self.addresses.append(addr)
        self.store(passKey)