Esempio n. 1
0
def testHisoryDataWithInvalidSignatures():
    datum = gen.historyGen()
    vk, sk, did = gen.keyGen()
    datum[HISTORY]["signer"] = 1
    datum[HISTORY]["signers"].append(vk)

    bHistory = json.dumps(datum[HISTORY],
                          ensure_ascii=False,
                          separators=(',', ':')).encode()
    # signed data has spaces that HistoryData object will not
    bad_bHistory = json.dumps(datum[HISTORY],
                              ensure_ascii=False,
                              separators=(', ', ': ')).encode()
    signer = signing.signResource(bHistory, gen.key64uToKey(datum[SK1]))
    rotation = signing.signResource(bad_bHistory, gen.key64uToKey(datum[SK2]))

    data = {
        "history": datum[HISTORY],
        "signatures": {
            "signer": signer,
            "rotation": rotation
        }
    }

    history = resp.HistoryData(data)

    assert history.valid is False
Esempio n. 2
0
def testHistoryDataWithInceptionData():
    datum = gen.historyGen()
    bHistory = json.dumps(datum[HISTORY],
                          ensure_ascii=False,
                          separators=(',', ':')).encode()
    signature = signing.signResource(bHistory, gen.key64uToKey(datum[SK1]))

    data = {"history": datum[HISTORY], "signatures": {"signer": signature}}

    history = resp.HistoryData(data)

    assert history.data == data
    assert history.bdata == json.dumps(data,
                                       ensure_ascii=False,
                                       separators=(",", ":")).encode()
    assert history.body == data["history"]
    assert history.bbody == json.dumps(data["history"],
                                       ensure_ascii=False,
                                       separators=(",", ":")).encode()
    assert history.did == data["history"]["id"]
    assert history.vk == data["history"]["signers"][0]
    assert history.signer_sig == signature
    assert history.rotation_sig is None
    assert history.signature == signature
    assert history.valid is True
Esempio n. 3
0
def testOtpData():
    vk, sk, did = gen.keyGen()
    otp_data = {
        "id":
        did,
        "blob":
        "AeYbsHot0pmdWAcgTo5sD8iAuSQAfnH5U6wiIGpVNJQQoYKBYrPPxAoIc1i5SHCIDS8KFFgf8i0tDq8XGizaCgo9yju"
        "KHHNJZFi0QD9K6Vpt6fP0XgXlj8z_4D-7s3CcYmuoWAh6NVtYaf_GWw_2sCrHBAA2mAEsml3thLmu50Dw"
    }
    botp_data = json.dumps(otp_data, ensure_ascii=False,
                           separators=(",", ":")).encode()
    signer = signing.signResource(botp_data, gen.key64uToKey(sk))

    data = {"otp_data": otp_data, "signatures": {"signer": signer}}

    otp = resp.OtpData(data)

    assert otp.data == data
    assert otp.bdata == json.dumps(data,
                                   ensure_ascii=False,
                                   separators=(",", ":")).encode()
    assert otp.body == data["otp_data"]
    assert otp.bbody == json.dumps(data["otp_data"],
                                   ensure_ascii=False,
                                   separators=(",", ":")).encode()
    assert otp.did == did
    assert otp.vk == vk
    assert otp.signature == signer
    assert otp.valid is True
Esempio n. 4
0
def testSignResource():
    vk = b'\xbb\xc4\xd6 M\xbc\xc8\x07n\xfaQ\xab<q\xf6d\x9e\xf7\x1b\x1a\x0c\x05\x9c~\x0fw\x1f\xe9\x13\x04i7'
    sk = b'\x8dh\xf3\xa0!\xd1\xcd\xc0b\x8c^\x1d\xbcg>\xe1S\x12\xc7\xcb\xbc\x0eTOz@\xdb} \xba\x06\x04\xbb\xc4\xd6 M\xbc\xc8\x07n\xfaQ\xab<q\xf6d\x9e\xf7\x1b\x1a\x0c\x05\x9c~\x0fw\x1f\xe9\x13\x04i7'
    resource = b'{"data":"TEST!"}'

    signature = sign.signResource(resource, sk)

    exp_signature = "dcYLAFhB6A2kU9XwvEcuV0HUDrFVgiraFEtOMsnP8FfOPebFhMbwIClY6PGdKX6CYJvc-9TwCIeca91dcof1Ag=="

    assert signature == exp_signature
Esempio n. 5
0
def testResponseFactoryWtihHistoryData():
    datum = gen.historyGen()
    bHistory = json.dumps(datum[HISTORY],
                          ensure_ascii=False,
                          separators=(',', ':')).encode()
    signature = signing.signResource(bHistory, gen.key64uToKey(datum[SK1]))

    data = {"history": datum[HISTORY], "signatures": {"signer": signature}}

    response = resp.responseFactory("", 200, data)

    assert type(response) == resp.DideryResponse
    assert type(response.response) == resp.HistoryData
Esempio n. 6
0
def testHisoryDataWithInvalidSignature():
    datum = gen.historyGen()
    bHistory = json.dumps(datum[HISTORY],
                          ensure_ascii=False,
                          separators=(', ', ': ')).encode()

    # signed data has spaces that HistoryData object will not
    inv_signature = signing.signResource(bHistory, gen.key64uToKey(datum[SK1]))

    data = {"history": datum[HISTORY], "signatures": {"signer": inv_signature}}

    history = resp.HistoryData(data)

    assert history.valid is False
Esempio n. 7
0
def testHistoryDataWithRotationData():
    datum = gen.historyGen()
    vk, sk, did = gen.keyGen()
    datum[HISTORY]["signer"] = 1
    datum[HISTORY]["signers"].append(vk)

    bHistory = json.dumps(datum[HISTORY],
                          ensure_ascii=False,
                          separators=(',', ':')).encode()
    signer = signing.signResource(bHistory, gen.key64uToKey(datum[SK1]))
    rotation = signing.signResource(bHistory, gen.key64uToKey(datum[SK2]))

    data = {
        "history": datum[HISTORY],
        "signatures": {
            "signer": signer,
            "rotation": rotation
        }
    }

    history = resp.HistoryData(data)

    assert history.data == data
    assert history.bdata == json.dumps(data,
                                       ensure_ascii=False,
                                       separators=(",", ":")).encode()
    assert history.body == data["history"]
    assert history.bbody == json.dumps(data["history"],
                                       ensure_ascii=False,
                                       separators=(",", ":")).encode()
    assert history.did == data["history"]["id"]
    assert history.vk == data["history"]["signers"][1]
    assert history.signer_sig == signer
    assert history.rotation_sig == rotation
    assert history.signature == rotation
    assert history.valid is True
Esempio n. 8
0
def testResponseFactoryWtihOtpData():
    vk, sk, did = gen.keyGen()
    otp_data = {
        "id":
        did,
        "blob":
        "AeYbsHot0pmdWAcgTo5sD8iAuSQAfnH5U6wiIGpVNJQQoYKBYrPPxAoIc1i5SHCIDS8KFFgf8i0tDq8XGizaCgo9yju"
        "KHHNJZFi0QD9K6Vpt6fP0XgXlj8z_4D-7s3CcYmuoWAh6NVtYaf_GWw_2sCrHBAA2mAEsml3thLmu50Dw"
    }
    botp_data = json.dumps(otp_data, ensure_ascii=False,
                           separators=(",", ":")).encode()
    signer = signing.signResource(botp_data, gen.key64uToKey(sk))

    data = {"otp_data": otp_data, "signatures": {"signer": signer}}

    response = resp.responseFactory("", 200, data)

    assert type(response) == resp.DideryResponse
    assert type(response.response) == resp.OtpData
Esempio n. 9
0
def testConsenseResults():
    consense = consensing.Consense()
    datum1 = gen.historyGen()  # (history, vk1, sk1, vk2, sk2)
    datum2 = gen.historyGen()

    # Test simple majority
    vk, sk, did = gen.keyGen()
    datum1[HISTORY]["signer"] = 1
    datum1[HISTORY]["signers"].append(vk)

    bHistory1 = json.dumps(datum1[HISTORY],
                           ensure_ascii=False,
                           separators=(',', ':')).encode()
    bHistory2 = json.dumps(datum2[HISTORY],
                           ensure_ascii=False,
                           separators=(',', ':')).encode()

    data = {
        "http://localhost:8000/history":
        resp.responseFactory(
            "http://localhost:8000/history", 200, {
                "history": datum2[HISTORY],
                "signatures": {
                    "signer":
                    signing.signResource(bHistory2, gen.key64uToKey(
                        datum2[SK1]))
                }
            }),
        "http://localhost:8080/history":
        resp.responseFactory(
            "http://localhost:8080/history", 200, {
                "history": datum1[HISTORY],
                "signatures": {
                    "signer":
                    signing.signResource(bHistory1, gen.key64uToKey(
                        datum1[SK1])),
                    "rotation":
                    signing.signResource(bHistory1, gen.key64uToKey(
                        datum1[SK2]))
                }
            }),
        "http://localhost:8081/history":
        resp.responseFactory(
            "http://localhost:8081/history", 200, {
                "history": datum1[HISTORY],
                "signatures": {
                    "signer":
                    signing.signResource(bHistory1, gen.key64uToKey(
                        datum1[SK1])),
                    "rotation":
                    signing.signResource(bHistory1, gen.key64uToKey(
                        datum1[SK2]))
                }
            })
    }

    results = consense.consense(data)[1]
    urls = [
        "http://localhost:8000/history", "http://localhost:8080/history",
        "http://localhost:8081/history"
    ]

    assert len(results) == 3
    for url in urls:
        assert url in results

    exp_results = {
        "http://localhost:8000/history": consenseModel.ConsensusResult.VALID,
        "http://localhost:8080/history": consenseModel.ConsensusResult.VALID,
        "http://localhost:8081/history": consenseModel.ConsensusResult.VALID
    }

    for url, status in exp_results.items():
        assert results[url].validation_status == status

    # Test failed signature validation
    consense = consensing.Consense()
    data["http://localhost:8000/history"] = resp.responseFactory(
        "http://localhost:8000/history", 200, {
            "history": datum2[HISTORY],
            "signatures": {
                "signer":
                signing.signResource(bHistory2, gen.key64uToKey(datum2[SK2]))
            }
        })

    results = consense.consense(data)[1]

    assert len(results) == 3
    for url in urls:
        assert url in results

    exp_results[
        "http://localhost:8000/history"] = consenseModel.ConsensusResult.FAILED

    for url, status in exp_results.items():
        assert results[url].validation_status == status

    # Test failed request
    consense = consensing.Consense()
    data["http://localhost:8000/history"] = resp.responseFactory(
        "http://localhost:8000/history", 400, {
            "history": datum2[HISTORY],
            "signatures": {
                "signer":
                signing.signResource(bHistory2, gen.key64uToKey(datum2[SK1]))
            }
        })

    results = consense.consense(data)[1]

    assert len(results) == 3
    for url in urls:
        assert url in results

    exp_results[
        "http://localhost:8000/history"] = consenseModel.ConsensusResult.ERROR

    for url, status in exp_results.items():
        assert results[url].validation_status == status