def test_wallet_multisig():
    wallet = Wallet()
    idr1, signer1 = wallet.addIdentifier()
    idr2, signer2 = wallet.addIdentifier()
    idr3, signer3 = wallet.addIdentifier()
    authnr = CoreAuthNr()
    for idr, signer in [(idr1, signer1), (idr2, signer2), (idr3, signer3)]:
        authnr.addIdr(idr, signer.verkey)

    def serz(req):
        return {k: v for k, v in req.as_dict.items()
                if k not in authnr.excluded_from_signing}

    op = randomOperation()
    req = wallet.sign_using_multi_sig(op=op, identifier=idr1)
    assert len(req.signatures) == 1
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures, 1)) == {idr1, }
    with pytest.raises(InsufficientSignatures):
        authnr.authenticate_multi(req_data, req.signatures, 2)

    req = wallet.sign_using_multi_sig(request=req, identifier=idr2)
    assert len(req.signatures) == 2
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures, 2)) == {idr1,
                                                                           idr2}
    with pytest.raises(InsufficientSignatures):
        authnr.authenticate_multi(req_data, req.signatures, 3)

    wallet.do_multi_sig_on_req(req, identifier=idr3)
    assert len(req.signatures) == 3
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures, 3)) == {idr1,
                                                                           idr2,
                                                                           idr3}
Exemple #2
0
def integrate_plugin_in_node(node):
    node.config = get_config(node.config)
    hash_store = get_auction_hash_store(node.dataLocation)
    ledger = get_auction_ledger(node.dataLocation,
                                node.config.auctionTransactionsFile,
                                hash_store, node.config)
    state = get_auction_state(node.dataLocation,
                              node.config.auctionStateDbName, node.config)
    if AUCTION_LEDGER_ID not in node.ledger_ids:
        node.ledger_ids.append(AUCTION_LEDGER_ID)
    node.ledgerManager.addLedger(
        AUCTION_LEDGER_ID,
        ledger,
        postTxnAddedToLedgerClbk=node.postTxnFromCatchupAddedToLedger)
    node.on_new_ledger_added(AUCTION_LEDGER_ID)
    node.register_state(AUCTION_LEDGER_ID, state)

    auctions = {}
    node.write_manager.register_req_handler(
        AuctionStartHandler(node.db_manager, auctions))
    node.write_manager.register_req_handler(
        AuctionEndHandler(node.db_manager, auctions))
    node.write_manager.register_req_handler(
        PlaceBidHandler(node.db_manager, auctions))
    node.read_manager.register_req_handler(GetBalHandler(node.db_manager))
    node.read_manager.register_req_handler(GetAuctionHandler(node.db_manager))
    # FIXME: find a generic way of registering DBs
    node.db_manager.register_new_database(lid=AUCTION_LEDGER_ID,
                                          ledger=ledger,
                                          state=state)
    node.write_manager.register_batch_handler(AuctionBatchHandler(
        node.db_manager),
                                              ledger_id=AUCTION_LEDGER_ID,
                                              add_to_begin=True)
    node.write_manager.register_batch_handler(
        node.write_manager.node_reg_handler, ledger_id=AUCTION_LEDGER_ID)
    node.write_manager.register_batch_handler(
        node.write_manager.primary_reg_handler, ledger_id=AUCTION_LEDGER_ID)
    node.write_manager.register_batch_handler(
        node.write_manager.audit_b_handler, ledger_id=AUCTION_LEDGER_ID)

    auction_authnr = CoreAuthNr(node.write_manager.txn_types,
                                node.read_manager.txn_types,
                                node.action_manager.txn_types,
                                node.states[DOMAIN_LEDGER_ID])
    node.clientAuthNr.register_authenticator(auction_authnr)
    return node
def pre_reqs():
    simple_authnr = SimpleAuthNr()
    core_authnr = CoreAuthNr()
    req_authnr = ReqAuthenticator()
    return simple_authnr, core_authnr, req_authnr
Exemple #4
0
def test_wallet_multisig():
    wallet = Wallet()
    idr1, signer1 = wallet.addIdentifier()
    idr2, signer2 = wallet.addIdentifier()
    idr3, signer3 = wallet.addIdentifier()
    authnr = CoreAuthNr()
    for idr, signer in [(idr1, signer1), (idr2, signer2), (idr3, signer3)]:
        authnr.addIdr(idr, signer.verkey)

    def serz(req):
        return {
            k: v
            for k, v in req.as_dict.items()
            if k not in authnr.excluded_from_signing
        }

    op = randomOperation()
    request = Request(reqId=Request.gen_req_id(),
                      operation=op,
                      protocolVersion=CURRENT_PROTOCOL_VERSION,
                      identifier=idr1)
    req = wallet.sign_using_multi_sig(request=request, identifier=idr1)
    assert len(req.signatures) == 1
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures, 1)) == {
        idr1,
    }
    with pytest.raises(InsufficientSignatures):
        authnr.authenticate_multi(req_data, req.signatures, 2)

    req = wallet.sign_using_multi_sig(request=req, identifier=idr2)
    assert len(req.signatures) == 2
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures,
                                         2)) == {idr1, idr2}
    with pytest.raises(InsufficientSignatures):
        authnr.authenticate_multi(req_data, req.signatures, 3)

    wallet.do_multi_sig_on_req(req, identifier=idr3)
    assert len(req.signatures) == 3
    req_data = serz(req)
    assert set(authnr.authenticate_multi(req_data, req.signatures,
                                         3)) == {idr1, idr2, idr3}
def pre_reqs():
    simple_authnr = SimpleAuthNr()
    core_authnr = CoreAuthNr([NYM], [GET_TXN], [])
    req_authnr = ReqAuthenticator()
    return simple_authnr, core_authnr, req_authnr
Exemple #6
0
def testAnotherAuthenticatorCanAuthenticate(sa, signer, msg, sig):
    sa2 = CoreAuthNr()
    sa2.addIdr(signer.identifier, signer.verkey)
    assert sa.authenticate(msg, idr, sig)
Exemple #7
0
def sa(signer):
    sa = CoreAuthNr()
    sa.addIdr(signer.identifier, signer.verkey)
    return sa