コード例 #1
0
def test_update_state(revoc_reg_entry_handler, revoc_reg_entry_request,
                      revoc_reg_def_handler, revoc_reg_def_request):
    # create revoc_req_def
    seq_no = 1
    txn_time = 1560241030
    revoc_reg_def_request.operation[ISSUANCE_TYPE] = ISSUANCE_BY_DEFAULT
    txn = reqToTxn(revoc_reg_def_request)
    append_txn_metadata(txn, seq_no, txn_time)
    path = RevocRegDefHandler.prepare_revoc_def_for_state(txn, path_only=True)
    revoc_reg_def_handler.update_state(txn, None, revoc_reg_def_request)

    # create revoc_req_entry
    seq_no = 2
    txn_time = 1560241033
    revoc_reg_entry_request.operation[REVOC_REG_DEF_ID] = path.decode()
    txn = reqToTxn(revoc_reg_entry_request)
    append_txn_metadata(txn, seq_no, txn_time)
    revoc_reg_entry_handler.update_state(txn, None, revoc_reg_entry_request)

    # check state for revoc_reg_entry
    txn_data = get_payload_data(txn)
    txn_data[f.SEQ_NO.nm] = seq_no
    txn_data[TXN_TIME] = txn_time
    assert revoc_reg_entry_handler.get_from_state(
        RevocRegEntryHandler.prepare_revoc_reg_entry_for_state(
            txn, path_only=True)) == (txn_data, seq_no, txn_time)
    # check state for revoc_reg_entry
    txn_data[VALUE] = {ACCUM: txn_data[VALUE][ACCUM]}
    path, _ = RevocRegEntryHandler.prepare_revoc_reg_entry_accum_for_state(txn)
    assert revoc_reg_entry_handler.get_from_state(path) == (txn_data, seq_no,
                                                            txn_time)
コード例 #2
0
    def get_result(self, request: Request):
        self._validate_request_type(request)
        req_ts = request.operation.get(TIMESTAMP)
        revoc_reg_def_id = request.operation.get(REVOC_REG_DEF_ID)
        # Get root hash corresponding with given timestamp
        past_root = self.database_manager.ts_store.get_equal_or_prev(req_ts)
        # Path to corresponding ACCUM record in state
        path = RevocRegEntryHandler.make_state_path_for_revoc_reg_entry_accum(revoc_reg_def_id=revoc_reg_def_id)
        entry_state = StateValue()
        if past_root is not None:
            encoded_entry, proof = self._get_value_from_state(path,
                                                              head_hash=past_root,
                                                              with_proof=True)
            entry_state.proof = proof
            if encoded_entry:
                revoc_reg_entry_accum, seq_no, last_update_time = decode_state_value(encoded_entry)
                entry_state = StateValue(root_hash=past_root,
                                         value=revoc_reg_entry_accum,
                                         seq_no=seq_no,
                                         update_time=last_update_time,
                                         proof=proof)

        return self.make_result(request=request,
                                data=entry_state.value,
                                last_seq_no=entry_state.seq_no,
                                update_time=entry_state.update_time,
                                proof=entry_state.proof)
コード例 #3
0
 def _get_revoc_def_entry(self,
                          revoc_reg_def_id,
                          is_committed=True) -> (str, int, int, list):
     assert revoc_reg_def_id
     path = RevocRegEntryHandler.make_state_path_for_revoc_reg_entry(revoc_reg_def_id=revoc_reg_def_id)
     try:
         keys, seq_no, last_update_time, proof = self.lookup(path, is_committed, with_proof=True)
         return keys, seq_no, last_update_time, proof
     except KeyError:
         return None, None, None, None
コード例 #4
0
ファイル: node_bootstrap.py プロジェクト: shntnkd/indy-node
 def _register_domain_req_handlers(self):
     # Read handlers
     get_nym_handler = GetNymHandler(database_manager=self.node.db_manager)
     get_attribute_handler = GetAttributeHandler(
         database_manager=self.node.db_manager)
     get_schema_handler = GetSchemaHandler(
         database_manager=self.node.db_manager)
     get_claim_def_handler = GetClaimDefHandler(
         database_manager=self.node.db_manager)
     get_revoc_reg_def_handler = GetRevocRegDefHandler(
         database_manager=self.node.db_manager)
     get_revoc_reg_handler = GetRevocRegHandler(
         database_manager=self.node.db_manager)
     get_revoc_reg_delta_handler = GetRevocRegDeltaHandler(
         database_manager=self.node.db_manager,
         get_revocation_strategy=RevocRegDefHandler.get_revocation_strategy)
     # Write handlers
     nym_handler = NymHandler(
         config=self.node.config,
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator)
     attrib_handler = AttributeHandler(
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator)
     schema_handler = SchemaHandler(
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator)
     claim_def_handler = ClaimDefHandler(
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator)
     revoc_reg_def_handler = RevocRegDefHandler(
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator)
     revoc_reg_entry_handler = RevocRegEntryHandler(
         database_manager=self.node.db_manager,
         write_req_validator=self.node.write_req_validator,
         get_revocation_strategy=RevocRegDefHandler.get_revocation_strategy)
     # Register write handlers
     self.node.write_manager.register_req_handler(nym_handler)
     self.node.write_manager.register_req_handler(attrib_handler)
     self.node.write_manager.register_req_handler(schema_handler)
     self.node.write_manager.register_req_handler(claim_def_handler)
     self.node.write_manager.register_req_handler(revoc_reg_def_handler)
     self.node.write_manager.register_req_handler(revoc_reg_entry_handler)
     # Additional handler for idCache
     self.register_idr_cache_nym_handler()
     # Register read handlers
     self.node.read_manager.register_req_handler(get_nym_handler)
     self.node.read_manager.register_req_handler(get_attribute_handler)
     self.node.read_manager.register_req_handler(get_schema_handler)
     self.node.read_manager.register_req_handler(get_claim_def_handler)
     self.node.read_manager.register_req_handler(get_revoc_reg_def_handler)
     self.node.read_manager.register_req_handler(get_revoc_reg_handler)
     self.node.read_manager.register_req_handler(
         get_revoc_reg_delta_handler)
コード例 #5
0
def revoc_reg_entry_handler(db_manager):
    class Validator:
        def __init__(self, state):
            pass

        def validate(self, current_entry, request):
            pass

    def get_revocation_strategy(type):
        return Validator

    def get_current_revoc_entry_and_revoc_def(author_did, revoc_reg_def_id,
                                              req_id):
        return True, {VALUE: {ISSUANCE_TYPE: ISSUANCE_BY_DEFAULT}}

    f = FakeSomething()
    f.get_current_revoc_entry_and_revoc_def = get_current_revoc_entry_and_revoc_def
    return RevocRegEntryHandler(db_manager, f, get_revocation_strategy)
コード例 #6
0
    def get_result(self, request: Request):
        """
        For getting reply we need:
        1. Get REVOC_REG_ENTRY by "TO" timestamp from state
        2. If FROM is given in request, then Get REVOC_REG_ENTRY by "FROM" timestamp from state
        3. Get ISSUANCE_TYPE for REVOC_REG_DEF (revoked/issued strategy)
        4. Compute issued and revoked indices by corresponding strategy
        5. Make result
           5.1 Now, if "FROM" is presented in request, then STATE_PROOF_FROM and ACCUM (revocation entry for "FROM" timestamp)
               will added into data section
           5.2 If not, then only STATE_PROOF for "TO" revocation entry will added
        :param request:
        :return: Reply
        """
        self._validate_request_type(request)
        req_ts_from = request.operation.get(FROM, None)
        req_ts_to = request.operation.get(TO)
        revoc_reg_def_id = request.operation.get(REVOC_REG_DEF_ID)
        reply = None
        """
        Get root hash for "to" timestamp
        Get REVOC_REG_ENTRY and ACCUM record for timestamp "to"
        """
        path_to_reg_entry = RevocRegEntryHandler.make_state_path_for_revoc_reg_entry(
            revoc_reg_def_id=revoc_reg_def_id)
        path_to_reg_entry_accum = RevocRegEntryHandler.make_state_path_for_revoc_reg_entry_accum(
            revoc_reg_def_id=revoc_reg_def_id)

        entry_to = self._get_reg_entry_by_timestamp(req_ts_to,
                                                    path_to_reg_entry)
        accum_to = self._get_reg_entry_accum_by_timestamp(
            req_ts_to, path_to_reg_entry_accum)
        entry_from = StateValue()
        accum_from = StateValue()

        if accum_to.value and entry_to.value:
            """Get issuance type from REVOC_REG_DEF"""
            encoded_revoc_reg_def = self.state.get_for_root_hash(
                entry_to.root_hash, revoc_reg_def_id)
            if encoded_revoc_reg_def:
                revoc_reg_def, _, _ = decode_state_value(encoded_revoc_reg_def)
                strategy_cls = self.get_revocation_strategy(
                    revoc_reg_def[VALUE][ISSUANCE_TYPE])
                issued_to = entry_to.value[VALUE].get(ISSUED, [])
                revoked_to = entry_to.value[VALUE].get(REVOKED, [])
                if req_ts_from:
                    """Get REVOC_REG_ENTRY and ACCUM records for timestamp from if exist"""
                    entry_from = self._get_reg_entry_by_timestamp(
                        req_ts_from, path_to_reg_entry)
                    accum_from = self._get_reg_entry_accum_by_timestamp(
                        req_ts_from, path_to_reg_entry_accum)
                if req_ts_from and entry_from.value and accum_from.value:
                    """Compute issued/revoked lists corresponding with ISSUANCE_TYPE strategy"""
                    issued_from = entry_from.value[VALUE].get(ISSUED, [])
                    revoked_from = entry_from.value[VALUE].get(REVOKED, [])
                    result_issued, result_revoked = strategy_cls.get_delta(
                        {
                            ISSUED: issued_to,
                            REVOKED: revoked_to
                        }, {
                            ISSUED: issued_from,
                            REVOKED: revoked_from
                        })
                else:
                    result_issued, result_revoked = strategy_cls.get_delta(
                        {
                            ISSUED: issued_to,
                            REVOKED: revoked_to
                        }, None)
                reply = {
                    REVOC_REG_DEF_ID: revoc_reg_def_id,
                    REVOC_TYPE: revoc_reg_def.get(REVOC_TYPE),
                    VALUE: {
                        ACCUM_TO:
                        accum_to.value if entry_from.value else entry_to.value,
                        ISSUED:
                        result_issued,
                        REVOKED:
                        result_revoked
                    }
                }
                """If we got "from" timestamp, then add state proof into "data" section of reply"""
                if req_ts_from:
                    reply[STATE_PROOF_FROM] = accum_from.proof
                    reply[VALUE][ACCUM_FROM] = accum_from.value

        if accum_to and entry_to:
            seq_no = accum_to.seq_no if entry_from.value else entry_to.seq_no
            update_time = accum_to.update_time if entry_from.value else entry_to.update_time
            proof = accum_to.proof if entry_from.value else entry_to.proof
            if reply is None and req_ts_from is not None:
                # TODO: change this according to INDY-2115
                reply = {}
                accum_from = self._get_reg_entry_accum_by_timestamp(
                    req_ts_from, path_to_reg_entry_accum)
                reply[STATE_PROOF_FROM] = accum_from.proof
                reply[VALUE] = {}
                reply[VALUE][ACCUM_TO] = None
                reply[VALUE][ACCUM_FROM] = accum_from.value
        else:
            seq_no = None
            update_time = None
            proof = None

        return self.make_result(request=request,
                                data=reply,
                                last_seq_no=seq_no,
                                update_time=update_time,
                                proof=proof)
コード例 #7
0
def revoc_reg_entry_handler(db_manager, write_auth_req_validator):
    return RevocRegEntryHandler(db_manager, write_auth_req_validator,
                                RevocRegDefHandler.get_revocation_strategy)
コード例 #8
0
    def _register_domain_req_handlers(self):
        # Read handlers
        get_nym_handler = GetNymHandler(database_manager=self.node.db_manager)
        get_attribute_handler = GetAttributeHandler(
            database_manager=self.node.db_manager)
        get_schema_handler = GetSchemaHandler(
            database_manager=self.node.db_manager)
        get_claim_def_handler = GetClaimDefHandler(
            database_manager=self.node.db_manager)
        get_revoc_reg_def_handler = GetRevocRegDefHandler(
            database_manager=self.node.db_manager)
        get_revoc_reg_handler = GetRevocRegHandler(
            database_manager=self.node.db_manager)
        get_revoc_reg_delta_handler = GetRevocRegDeltaHandler(
            database_manager=self.node.db_manager,
            get_revocation_strategy=RevocRegDefHandler.get_revocation_strategy)
        # Write handlers
        nym_handler = NymHandler(
            config=self.node.config,
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        attrib_handler = AttributeHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        schema_handler = SchemaHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        claim_def_handler = ClaimDefHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        revoc_reg_def_handler = RevocRegDefHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        revoc_reg_entry_handler = RevocRegEntryHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator,
            get_revocation_strategy=RevocRegDefHandler.get_revocation_strategy)
        json_ld_context_handler = JsonLdContextHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        rich_schema_handler = RichSchemaHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        rich_schema_encoding_handler = RichSchemaEncodingHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        rich_schema_mapping_handler = RichSchemaMappingHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        rich_schema_cred_def_handler = RichSchemaCredDefHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        rich_schema_pres_def_handler = RichSchemaPresDefHandler(
            database_manager=self.node.db_manager,
            write_req_validator=self.node.write_req_validator)
        get_rich_schema_obj_by_id_handler = GetRichSchemaObjectByIdHandler(
            database_manager=self.node.db_manager)
        get_rich_schema_obj_by_metadata_handler = GetRichSchemaObjectByMetadataHandler(
            database_manager=self.node.db_manager)

        # Register write handlers
        self.node.write_manager.register_req_handler(nym_handler)
        self.node.write_manager.register_req_handler(attrib_handler)
        self.node.write_manager.register_req_handler(schema_handler)
        self.node.write_manager.register_req_handler(claim_def_handler)
        self.node.write_manager.register_req_handler(revoc_reg_def_handler)
        self.node.write_manager.register_req_handler(revoc_reg_entry_handler)
        self.node.write_manager.register_req_handler(json_ld_context_handler)
        self.node.write_manager.register_req_handler(rich_schema_handler)
        self.node.write_manager.register_req_handler(
            rich_schema_encoding_handler)
        self.node.write_manager.register_req_handler(
            rich_schema_mapping_handler)
        self.node.write_manager.register_req_handler(
            rich_schema_cred_def_handler)
        self.node.write_manager.register_req_handler(
            rich_schema_pres_def_handler)
        # Additional handler for idCache
        self.register_idr_cache_nym_handler()
        # Register read handlers
        self.node.read_manager.register_req_handler(get_nym_handler)
        self.node.read_manager.register_req_handler(get_attribute_handler)
        self.node.read_manager.register_req_handler(get_schema_handler)
        self.node.read_manager.register_req_handler(get_claim_def_handler)
        self.node.read_manager.register_req_handler(get_revoc_reg_def_handler)
        self.node.read_manager.register_req_handler(get_revoc_reg_handler)
        self.node.read_manager.register_req_handler(
            get_revoc_reg_delta_handler)
        self.node.read_manager.register_req_handler(
            get_rich_schema_obj_by_id_handler)
        self.node.read_manager.register_req_handler(
            get_rich_schema_obj_by_metadata_handler)