コード例 #1
0
ファイル: crypto_utest.py プロジェクト: zmyer/dragonchain
    def test_validate_verification_record(self):
        verification_ts = 1479435043
        """ testing crypto validate_verification_record """
        test_output = crypto.sign_verification_record(SIGNATORY,
                                                      PRIOR_BLOCK_HASH,
                                                      LOWER_HASH,
                                                      PUBLIC_KEY,
                                                      PRIVATE_KEY,
                                                      BLOCK_ID,
                                                      PHASE,
                                                      ORIGIN_ID,
                                                      verification_ts,
                                                      public_transmission=None,
                                                      verification_info=None)
        record = test_output['verification_record']
        record['verification_ts'] = verification_ts

        # testing if validate_verification_record passes
        self.assertEqual(crypto.validate_verification_record(record, None),
                         True)

        # testing that KeyError is appropriately raised
        for key in record.keys():
            if key is not "verification_info":
                record.pop(key)
                self.assertRaises(KeyError,
                                  crypto.validate_verification_record,
                                  record,
                                  None,
                                  test_mode=True)
コード例 #2
0
    def _execute_phase_4(self, config, phase_3_info):
        """ external partner notary phase """
        phase = 4
        phase_3_record = phase_3_info['record']
        p3_verification_info = phase_3_info['verification_info']
        phase_3_record['verification_info'] = p3_verification_info
        prior_block_hash = self.get_prior_hash(phase_3_record[ORIGIN_ID],
                                               phase)

        # validate phase_3's verification record
        if validate_verification_record(phase_3_record, p3_verification_info):
            # storing valid verification record
            verfication_db.insert_verification(phase_3_record)

            # updating record phase
            phase_3_record[PHASE] = phase

            lower_phase_hash = phase_3_record[SIGNATURE][HASH]

            # sign verification and rewrite record
            block_info = sign_verification_record(
                self.network.this_node.node_id, prior_block_hash,
                lower_phase_hash, self.service_config['public_key'],
                self.service_config['private_key'], phase_3_record[BLOCK_ID],
                phase_3_record[PHASE], phase_3_record[ORIGIN_ID],
                int(time.time()), None)

            # inserting verification info after signing
            verfication_db.insert_verification(
                block_info['verification_record'])
            self.network.send_block(self.network.phase_4_broadcast, block_info,
                                    phase)
            print "phase 4 executed"
コード例 #3
0
ファイル: processing.py プロジェクト: hfye/dragonchain
    def _execute_phase_2(self, config, phase_1_info):
        """
        * At this point, any participating processing nodes will have appended signed "approvals" of their respectively owned transactions and signed "validations" of un-owned transactions (see Phase 1 Verification Process).
        * Processing nodes participating in Phase 2 Verification may be a different set of nodes than the set of nodes participating in Phase 1 Verification.
        * Processing nodes may be defined for the sole purpose of Phase 2 verification (without any "owned" transactions in the system).
        * A node participating in Phase 2 verification will verify that all transactions in the prospective block are "approved" by their respective owners and are not declared invalid by a system configured portion (e.g. percentage, plurality, or majority).
        * Any transactions which are not approved will be taken out of the prospective block and "bumped" to the next block now - (d * T) for Phase 1 processing.
        * If a non-approved transaction which is older than a system configured time for the transaction type and owner, the transaction will not be "bumped" to the next block, but instead be placed in a system "pool" or "queue" for later handling or alternate processing.
        * All signed "approval" verification units will be grouped, concatenated, and cryptographically signed.
        * A "Phase 2 signature structure" is created and appended to the block.
        """

        """
        - check block sig
        - req: tx_type, tx_id, tx_ts, owner (origin - original phase_1 node_id), trans_sig
          - tx minus the payload
        """
        phase = 2
        phase_1_record = phase_1_info["record"]
        p1_verification_info = phase_1_info["verification_info"]
        phase_1_record['verification_info'] = p1_verification_info
        prior_block_hash = self.get_prior_hash(phase_1_record[ORIGIN_ID], phase)

        # validate phase_1's verification record
        if validate_verification_record(phase_1_record, p1_verification_info):
            # storing valid verification record
            verfication_db.insert_verification(phase_1_record)

            # updating record phase
            phase_1_record[PHASE] = phase

            valid_transactions, invalid_transactions = self.check_tx_requirements(p1_verification_info)

            verification_info = {
                'valid_txs': valid_transactions,
                'invalid_txs': invalid_transactions,
                'business': self.network.business,
                'deploy_location': self.network.deploy_location
            }

            lower_hash = phase_1_record[SIGNATURE][HASH]

            # sign verification and rewrite record
            block_info = sign_verification_record(self.network.this_node.node_id,
                                                  prior_block_hash,
                                                  lower_hash,
                                                  self.service_config['public_key'],
                                                  self.service_config['private_key'],
                                                  phase_1_record[BLOCK_ID],
                                                  phase_1_record[PHASE],
                                                  phase_1_record[ORIGIN_ID],
                                                  int(time.time()),
                                                  verification_info
                                                  )

            # inserting verification info after signing
            verfication_db.insert_verification(block_info['verification_record'])
            self.network.send_block(self.network.phase_2_broadcast, block_info, phase_1_record[PHASE])

            print "phase_2 executed"
コード例 #4
0
ファイル: processing.py プロジェクト: hfye/dragonchain
    def _execute_phase_3(self, config, phase_2_info):
        """
        * At this point, any participating processing nodes will have appended signed Phase 2 verification proof to the block.
        * Processing nodes participating in Phase 3 Verification may be a different set of nodes than the set of nodes participating in Phase 1 and Phase 2 Verification processes.
        * Processing nodes may be defined for the sole purpose of Phase 3 verification (e.g. for independent blockchain verification auditing purposes).
        * A participating node will verify that no invalid transaction has been included in the set of approved transaction.
        * A participating node will verify that all "approved" transactions are signed by their respective owner.
        * A node may perform extra validation steps on all transactions and verification units.
        * All signed "Phase 3 Signature Structures" will be grouped, concatenated, and cryptographically signed by the node.
        """
        phase = 3
        phase_2_record = phase_2_info['record']
        p2_verification_info = phase_2_info['verification_info']
        phase_2_record['verification_info'] = p2_verification_info
        prior_block_hash = self.get_prior_hash(phase_2_record[ORIGIN_ID], phase)

        # validate phase_2's verification record
        if validate_verification_record(phase_2_record, p2_verification_info):
            # storing valid verification record
            verfication_db.insert_verification(phase_2_record)

            phase_2_records = self.get_sig_records(phase_2_record)

            signatories, businesses, locations = self.get_verification_diversity(phase_2_records)

            # checking if passed requirements to move on to next phase
            if len(signatories) >= P2_COUNT_REQ and len(businesses) >= P2_BUS_COUNT_REQ and len(locations) >= P2_LOC_COUNT_REQ:
                # updating record phase
                phase_2_record[PHASE] = phase
                lower_hashes = [record[SIGNATURE]['signatory'] + ":" + record[SIGNATURE][HASH]
                                      for record in phase_2_records]

                # TODO: add a structure such as a tuple to pair signatory with it's appropriate hash (signatory, hash)
                # TODO: and store that instead of lower_phase_hashes also add said structure to phase_3_msg in thrift
                verification_info = {
                    'lower_hashes': lower_hashes,
                    'p2_count': len(signatories),
                    'businesses': list(businesses),
                    'deploy_locations': list(locations)
                }

                lower_hash = str(deep_hash(lower_hashes))

                # sign verification and rewrite record
                block_info = sign_verification_record(self.network.this_node.node_id,
                                                      prior_block_hash,
                                                      lower_hash,
                                                      self.service_config['public_key'],
                                                      self.service_config['private_key'],
                                                      phase_2_record[BLOCK_ID],
                                                      phase_2_record[PHASE],
                                                      phase_2_record[ORIGIN_ID],
                                                      int(time.time()),
                                                      verification_info
                                                      )

                # inserting verification info after signing
                verfication_db.insert_verification(block_info['verification_record'])
                self.network.send_block(self.network.phase_3_broadcast, block_info, phase)
                print "phase 3 executed"
コード例 #5
0
    def _execute_phase_5(self, config, verification):
        """ public, Bitcoin bridge phase """
        phase = 5
        verification_record = verification['record']

        verification_info = verification['verification_info']
        verification_record['verification_info'] = verification_info

        # set block_id and origin_id to None for the reason that the records can come from any phase
        if validate_verification_record(verification_record, verification_info):
            timestamp_db.insert_verification(verification_record)
            verification_db.insert_verification(verification_record)
            print "phase 5 executed"
コード例 #6
0
    def test_validate_verification_record(self):
        """ testing crypto validate_verification_record """
        verification_ts = 1479435043
        test_output = crypto.sign_verification_record(SIGNATORY, PRIOR_BLOCK_HASH, LOWER_HASH, PUBLIC_KEY, PRIVATE_KEY, BLOCK_ID, PHASE, ORIGIN_ID,
                                                      verification_ts, public_transmission=None, verification_info=None)
        record = test_output['verification_record']
        record['verification_ts'] = verification_ts

        # testing if validate_verification_record passes
        self.assertEqual(crypto.validate_verification_record(record, None), True)

        # testing that KeyError is appropriately raised
        for key in record.keys():
            if key is not "verification_info":
                record.pop(key)
                self.assertRaises(KeyError, crypto.validate_verification_record, record, None, test_mode=True)
コード例 #7
0
    def _execute_phase_4(self, config, phase_3_info):
        """ external partner notary phase """
        phase = 4
        phase_3_record = phase_3_info['record']
        p3_verification_info = phase_3_info['verification_info']
        phase_3_record['verification_info'] = p3_verification_info
        prior_block_hash = self.get_prior_hash(phase_3_record[ORIGIN_ID], phase)

        # validate phase_3's verification record
        if validate_verification_record(phase_3_record, p3_verification_info):
            # storing valid verification record
            verification_db.insert_verification(phase_3_record)

            # updating record phase
            phase_3_record[PHASE] = phase

            lower_hash = phase_3_record[SIGNATURE][HASH]

            verification_info = lower_hash

            # sign verification and rewrite record
            block_info = sign_verification_record(self.network.this_node.node_id,
                                                  prior_block_hash,
                                                  lower_hash,
                                                  self.service_config['public_key'],
                                                  self.service_config['private_key'],
                                                  phase_3_record[BLOCK_ID],
                                                  phase_3_record[PHASE],
                                                  phase_3_record[ORIGIN_ID],
                                                  int(time.time()),
                                                  phase_3_record['public_transmission'],
                                                  verification_info
                                                  )

            # inserting verification info after signing
            verification_id = str(uuid.uuid4())
            verification_db.insert_verification(block_info['verification_record'], verification_id)

            # inserting receipt of signed verification for data transfer
            vr_transfers_db.insert_transfer(phase_3_record['origin_id'], phase_3_record['signature']['signatory'], verification_id)

            # send block info off for public transmission if configured to do so
            if phase_3_record['public_transmission']['p4_pub_trans']:
                self.network.public_broadcast(block_info, phase)

            print "phase 4 executed"
コード例 #8
0
    def _execute_phase_3(self, config, phase_2_info):
        """
        * At this point, any participating processing nodes will have appended signed Phase 2 verification proof to the block.
        * Processing nodes participating in Phase 3 Verification may be a different set of nodes than the set of nodes participating in Phase 1 and Phase 2 Verification processes.
        * Processing nodes may be defined for the sole purpose of Phase 3 verification (e.g. for independent blockchain verification auditing purposes).
        * A participating node will verify that no invalid transaction has been included in the set of approved transaction.
        * A participating node will verify that all "approved" transactions are signed by their respective owner.
        * A node may perform extra validation steps on all transactions and verification units.
        * All signed "Phase 3 Signature Structures" will be grouped, concatenated, and cryptographically signed by the node.
        """
        phase = 3
        phase_2_record = phase_2_info['record']
        p2_verification_info = phase_2_info['verification_info']
        phase_2_record['verification_info'] = p2_verification_info
        prior_block_hash = self.get_prior_hash(phase_2_record[ORIGIN_ID], phase)

        # validate phase_2's verification record
        if validate_verification_record(phase_2_record, p2_verification_info):
            # storing valid verification record
            verification_db.insert_verification(phase_2_record)

            # retrieve all phase 2 records for current block
            phase_2_records = self.get_sig_records(phase_2_record)

            signatories, businesses, locations = self.get_verification_diversity(phase_2_records)

            # checking if passed requirements to move on to next phase
            if len(signatories) >= P2_COUNT_REQ and len(businesses) >= P2_BUS_COUNT_REQ and len(locations) >= P2_LOC_COUNT_REQ:
                # updating record phase
                phase_2_record[PHASE] = phase
                lower_hashes = [record[SIGNATURE]['signatory'] + ":" + record[SIGNATURE][HASH] for record in phase_2_records]

                verification_info = {
                    'lower_hashes': lower_hashes,
                    'p2_count': len(signatories),
                    'businesses': list(businesses),
                    'deploy_locations': list(locations)
                }

                lower_hash = str(final_hash(lower_hashes))

                # sign verification and rewrite record
                block_info = sign_verification_record(self.network.this_node.node_id,
                                                      prior_block_hash,
                                                      lower_hash,
                                                      self.service_config['public_key'],
                                                      self.service_config['private_key'],
                                                      phase_2_record[BLOCK_ID],
                                                      phase_2_record[PHASE],
                                                      phase_2_record[ORIGIN_ID],
                                                      int(time.time()),
                                                      phase_2_record['public_transmission'],
                                                      verification_info
                                                      )

                # inserting verification info after signing
                verification_id = str(uuid.uuid4())
                verification_db.insert_verification(block_info['verification_record'], verification_id)

                # inserting receipt for each phase 2 record received
                for record in phase_2_records:
                    vr_transfers_db.insert_transfer(record['origin_id'], record['signature']['signatory'], verification_id)

                # send block info off for public transmission if configured to do so
                if phase_2_record['public_transmission']['p3_pub_trans']:
                    self.network.public_broadcast(block_info, phase)

                # send block info for phase 4 validation
                self.network.send_block(self.network.phase_3_broadcast, block_info, phase)
                print "phase 3 executed"
コード例 #9
0
    def _execute_phase_2(self, config, phase_1_info):
        """
        * At this point, any participating processing nodes will have appended signed "approvals" of their respectively owned transactions and signed "validations" of un-owned transactions (see Phase 1 Verification Process).
        * Processing nodes participating in Phase 2 Verification may be a different set of nodes than the set of nodes participating in Phase 1 Verification.
        * Processing nodes may be defined for the sole purpose of Phase 2 verification (without any "owned" transactions in the system).
        * A node participating in Phase 2 verification will verify that all transactions in the prospective block are "approved" by their respective owners and are not declared invalid by a system configured portion (e.g. percentage, plurality, or majority).
        * Any transactions which are not approved will be taken out of the prospective block and "bumped" to the next block now - (d * T) for Phase 1 processing.
        * If a non-approved transaction which is older than a system configured time for the transaction type and owner, the transaction will not be "bumped" to the next block, but instead be placed in a system "pool" or "queue" for later handling or alternate processing.
        * All signed "approval" verification units will be grouped, concatenated, and cryptographically signed.
        * A "Phase 2 signature structure" is created and appended to the block.
        """

        """
        - check block sig
        - req: tx_type, tx_id, tx_ts, owner (origin - original phase_1 node_id), trans_sig
          - tx minus the payload
        """
        phase = 2
        phase_1_record = phase_1_info["record"]
        p1_verification_info = phase_1_info["verification_info"]
        phase_1_record['verification_info'] = p1_verification_info
        prior_block_hash = self.get_prior_hash(phase_1_record[ORIGIN_ID], phase)

        # validate phase_1's verification record
        if validate_verification_record(phase_1_record, p1_verification_info):
            # storing valid verification record
            verification_db.insert_verification(phase_1_record)

            # updating record phase
            phase_1_record[PHASE] = phase

            valid_transactions, invalid_transactions = self.check_tx_requirements(p1_verification_info)

            verification_info = {
                'valid_txs': valid_transactions,
                'invalid_txs': invalid_transactions,
                'business': self.network.business,
                'deploy_location': self.network.deploy_location
            }

            lower_hash = phase_1_record[SIGNATURE][HASH]

            # sign verification and rewrite record
            block_info = sign_verification_record(self.network.this_node.node_id,
                                                  prior_block_hash,
                                                  lower_hash,
                                                  self.service_config['public_key'],
                                                  self.service_config['private_key'],
                                                  phase_1_record[BLOCK_ID],
                                                  phase_1_record[PHASE],
                                                  phase_1_record[ORIGIN_ID],
                                                  int(time.time()),
                                                  phase_1_record['public_transmission'],
                                                  verification_info
                                                  )

            # inserting verification info after signing
            verification_id = str(uuid.uuid4())
            verification_db.insert_verification(block_info['verification_record'], verification_id)

            # inserting receipt of signed verification for data transfer
            vr_transfers_db.insert_transfer(phase_1_record['origin_id'], phase_1_record['signature']['signatory'], verification_id)

            # send block info off for public transmission if configured to do so
            if phase_1_record['public_transmission']['p2_pub_trans']:
                self.network.public_broadcast(block_info, phase)

            # send block info for phase 3 validation
            self.network.send_block(self.network.phase_2_broadcast, block_info, phase)

            print "phase_2 executed"