예제 #1
0
    def update_listings_index(self):

        # Store to marketplace listing index
        contract_index_key = hashlib.sha1('contracts-%s' %
                                          self.transport.guid).hexdigest()
        hashvalue = hashlib.new('ripemd160')
        hashvalue.update(contract_index_key)
        contract_index_key = hashvalue.hexdigest()

        # Calculate index of contracts
        contract_ids = self.db.selectEntries(
            "contracts",
            {"market_id": self.transport.market_id, "deleted": 0}
        )
        my_contracts = []
        for contract_id in contract_ids:
            my_contracts.append(contract_id['key'])

        self.log.debug('My Contracts: %s' % my_contracts)

        # Sign listing index for validation and tamper resistance
        data_string = str({'guid': self.transport.guid,
                           'contracts': my_contracts})
        signature = makePrivCryptor(self.transport.settings['secret']).sign(data_string).encode('hex')

        value = {'signature': signature,
                 'data': {'guid': self.transport.guid,
                          'contracts': my_contracts}}

        # Pass off to thread to keep GUI snappy
        t = Thread(target=self.transport.dht.iterativeStore, args=(self.transport,
                                                                   contract_index_key,
                                                                   value,
                                                                   self.transport.guid,))
        t.start()
예제 #2
0
    def update_listings_index(self):

        # Store to marketplace listing index
        contract_index_key = hashlib.sha1("contracts-%s" % self.transport.guid).hexdigest()
        hashvalue = hashlib.new("ripemd160")
        hashvalue.update(contract_index_key)
        contract_index_key = hashvalue.hexdigest()

        # Calculate index of contracts
        contract_ids = self.db.selectEntries("contracts", {"market_id": self.transport.market_id, "deleted": 0})
        my_contracts = []
        for contract_id in contract_ids:
            my_contracts.append(contract_id["key"])

        self.log.debug("My Contracts: %s" % my_contracts)

        # Sign listing index for validation and tamper resistance
        data_string = str({"guid": self.transport.guid, "contracts": my_contracts})
        signature = makePrivCryptor(self.transport.settings["secret"]).sign(data_string).encode("hex")

        value = {"signature": signature, "data": {"guid": self.transport.guid, "contracts": my_contracts}}

        # Pass off to thread to keep GUI snappy
        t = Thread(
            target=self.transport.dht.iterativeStore,
            args=(self.transport, contract_index_key, value, self.transport.guid),
        )
        t.start()
예제 #3
0
    def _on_raw_message(self, serialized):
        try:

            # Decompress message
            serialized = zlib.decompress(serialized)

            msg = json.loads(serialized)
            self.log.info("Message Received [%s]" % msg.get("type", "unknown"))

            if msg.get("type") is None:

                data = msg.get("data").decode("hex")
                sig = msg.get("sig").decode("hex")

                try:
                    cryptor = makePrivCryptor(self.secret)

                    try:
                        data = cryptor.decrypt(data)
                    except Exception as e:
                        self.log.info("Exception: %s" % e)

                    self.log.debug("Signature: %s" % sig.encode("hex"))
                    self.log.debug("Signed Data: %s" % data)

                    # Check signature
                    data_json = json.loads(data)
                    sigCryptor = makePubCryptor(data_json["pubkey"])
                    if sigCryptor.verify(sig, data):
                        self.log.info("Verified")
                    else:
                        self.log.error("Message signature could not be verified %s" % msg)
                        # return

                    msg = json.loads(data)
                    self.log.debug("Message Data %s " % msg)
                except Exception as e:
                    self.log.error("Could not decrypt message properly %s" % e)

        except ValueError:
            try:
                # Encrypted?
                try:
                    msg = self._myself.decrypt(serialized)
                    msg = json.loads(msg)

                    self.log.info("Decrypted Message [%s]" % msg.get("type", "unknown"))
                except:
                    self.log.error("Could not decrypt message: %s" % msg)
                    return
            except:
                self.log.error("Message probably sent using incorrect pubkey")

                return

        if msg.get("type") is not None:
            self._on_message(msg)
        else:
            self.log.error("Received a message with no type")
예제 #4
0
    def _on_raw_message(self, serialized):
        try:

            msg = json.loads(serialized)
            self.log.info("Message Received [%s]" % msg.get('type', 'unknown'))

            if msg.get('type') is None:

                data = msg.get('data').decode('hex')
                sig = msg.get('sig').decode('hex')

                try:
                    cryptor = makePrivCryptor(self.secret)

                    try:
                        data = cryptor.decrypt(data)
                    except Exception as e:
                        self.log.info('Exception: %s' % e)

                    self.log.debug('Signature: %s' % sig.encode('hex'))
                    self.log.debug('Signed Data: %s' % data)

                    # Check signature
                    data_json = json.loads(data)
                    sigCryptor = makePubCryptor(data_json['pubkey'])
                    if sigCryptor.verify(sig, data):
                        self.log.info('Verified')
                    else:
                        self.log.error('Message signature could not be verified %s' % msg)
                        # return

                    msg = json.loads(data)
                    self.log.debug('Message Data %s ' % msg)
                except Exception as e:
                    self.log.error('Could not decrypt message properly %s' % e)

        except ValueError:
            try:
                # Encrypted?
                try:
                    msg = self._myself.decrypt(serialized)
                    msg = json.loads(msg)

                    self.log.info(
                        "Decrypted Message [%s]" % msg.get('type', 'unknown')
                    )
                except:
                    self.log.error("Could not decrypt message: %s" % msg)
                    return
            except:
                self.log.error('Message probably sent using incorrect pubkey')

                return

        if msg.get('type') is not None:
            self._on_message(msg)
        else:
            self.log.error('Received a message with no type')
예제 #5
0
 def sign(self, data):
     self.log.info('secret %s' % self.transport.settings['secret'])
     cryptor = makePrivCryptor(self.transport.settings['secret'])
     return cryptor.sign(data)
예제 #6
0
    def _on_raw_message(self, serialized):
        try:

            # Decompress message
            serialized = zlib.decompress(serialized)

            msg = json.loads(serialized)
            self.log.info("Message Received [%s]" % msg.get('type', 'unknown'))

            if msg.get('type') is None:

                data = msg.get('data').decode('hex')
                sig = msg.get('sig').decode('hex')

                try:
                    cryptor = makePrivCryptor(self.secret)

                    try:
                        data = cryptor.decrypt(data)
                    except Exception as e:
                        self.log.info('Exception: %s' % e)

                    self.log.debug('Signature: %s' % sig.encode('hex'))
                    self.log.debug('Signed Data: %s' % data)

                    # Check signature
                    data_json = json.loads(data)
                    sigCryptor = makePubCryptor(data_json['pubkey'])
                    if sigCryptor.verify(sig, data):
                        self.log.info('Verified')
                    else:
                        self.log.error(
                            'Message signature could not be verified %s' % msg)
                        # return

                    msg = json.loads(data)
                    self.log.debug('Message Data %s ' % msg)
                except Exception as e:
                    self.log.error('Could not decrypt message properly %s' % e)

        except ValueError:
            try:
                # Encrypted?
                try:
                    msg = self._myself.decrypt(serialized)
                    msg = json.loads(msg)

                    self.log.info("Decrypted Message [%s]" %
                                  msg.get('type', 'unknown'))
                except:
                    self.log.error("Could not decrypt message: %s" % msg)
                    return
            except:
                self.log.error('Message probably sent using incorrect pubkey')

                return

        if msg.get('type') is not None:
            self._on_message(msg)
        else:
            self.log.error('Received a message with no type')
예제 #7
0
 def sign(self, data):
     cryptor = makePrivCryptor(self.transport.settings['secret'])
     return cryptor.sign(data)
예제 #8
0
 def sign(self, data):
     self.log.info('secret %s' % self.transport.settings['secret'])
     cryptor = makePrivCryptor(self.transport.settings['secret'])
     return cryptor.sign(data)