示例#1
0
def plugin_start():
    """
    Start this plugin
    :return:
    """
    sys.stderr.write(PLUGNAME + " plugin started\n")  # appears in %TMP%/EDMarketConnector.log in packaged Windows app
    identity.first_run(THISDIR)
示例#2
0
def test_ecdh(tmpdir):
    """
    Test and ECDH key exchange
    :param tmpdir:
    :return:
    """
    alicedir = os.path.join(tmpdir.strpath, "alice")
    os.makedirs(alicedir)

    identity.first_run(alicedir)
    alicepriv = identity.get_priv_keyfilename(alicedir)
    aliceprivkey = identity.load(alicepriv)

    bobdir = os.path.join(tmpdir.strpath, "bob")
    os.makedirs(bobdir)

    identity.first_run(bobdir)
    bobpriv = identity.get_priv_keyfilename(bobdir)
    bobprivkey = identity.load(bobpriv)

    alicepub = identity.loadpub(identity.get_pub_keyfilename(alicedir))
    bobpub = identity.loadpub(identity.get_pub_keyfilename(bobdir))

    shared_bob = identity.ecdh(bobprivkey, alicepub)
    shared_alice = identity.ecdh(aliceprivkey, bobpub)

    assert shared_alice == shared_bob
示例#3
0
def test_generate_sign(tmpdir):
    """
    Test key generation
    :param tmpdir:
    :return:
    """
    datafolder = tmpdir.strpath
    identity.first_run(datafolder)
    keyfile = identity.get_priv_keyfilename(datafolder)

    assert os.path.isfile(keyfile)

    key = identity.load(keyfile)
    signature = identity.sign_string(key, "hello")

    pub = identity.loadpub(identity.get_pub_keyfilename(datafolder))
    assert identity.verify_string(pub, signature, "hello")
示例#4
0
MAX_LOCATION_AGE = 600
MAX_SESSION_AGE = 600
MAX_PENDING_SESSION_AGE = 60

# things connecting to us
pending_sessions = dict()
# sessions that have completed handshakes
sessions = dict()
session_lock = threading.Semaphore()


# server's identity is this folder, if we don't have one, generate
KEYFILE = identity.get_priv_keyfilename(libs.THISDIR)
if not os.path.exists(KEYFILE):
    identity.first_run(libs.THISDIR)
PRIVKEY = identity.load(identity.get_priv_keyfilename(libs.THISDIR))


def run():
    urls = ("/handshake_begin", "handshake_begin",
            "/handshake_finish", "handshake_finish",
            "/submit_location", "submit_location",)
    app = web.application(urls, globals())
    app.run()


def encode_message(payload):
    """
    Encode the message into something we can send/encrypt or sign
    :param challenge: