Example #1
0
def test_sign():
	params = setup()

	# user parameters
	m = 10

	# signer 1
	(sk1, vk1) = keygen(params)
	sig1 = sign(params, sk1, m)

	# signer 2
	(sk2, vk2) = keygen(params)
	sig2 = sign(params, sk2, m)

	# affregate signatures
	sig = aggregate_sign(sig1, sig2)

	# randomize signature
	randomize(params, sig)

	# aggregate keys
	vk = aggregate_keys(vk1, vk2)

	# verify signature
	assert verify(params, vk, m, sig)
Example #2
0
def sign_queries(queries, source_id):
    """
    Will sign queries not already signed by this source. If debug info is
    turned on, this will also log info about already signed queries.
    """

    all_signed_queries = []
    this_signed_queries = {}
    for query in queries:
        logger.debug("query     %s", query)
        if source_id in query['signed_by']:
            if set(query["signed_by"]) == set(query["sources"]):
                logger.debug("Is ready: %s", query["id"])
                all_signed_queries.append(query)
            else:
                logger.debug("I have signed this, but not everybody else: %s",
                             query["id"])

        else:
            original = query['signed']

            # verify
            verified = verify(original)
            if not verified:
                raise VerificationError(
                    "Signature could not be verified for query %s", query)

            # sign
            signed = sign(original)
            this_signed_queries[query['id']] = signed.data.decode("utf-8")

    return all_signed_queries, this_signed_queries
Example #3
0
def weibo_login(device_info, access_token, uid):
    # cURL
    # GET https://is.snssdk.com/passport/auth/login/

    params = {
        "platform": "sina_weibo",
        "access_token": access_token,
        "expires_in": str(int(time())),
        "uid": uid,
        "retry_type": "no_retry",
        "iid": device_info['install_id'],
        "device_id": device_info['device_id'],
        "ac": "wifi",
        "channel": "wandoujia_zhiwei",
        "aid": "1128",
        "app_name": "aweme",
        "version_code": "290",
        "version_name": "2.9.0",
        "device_platform": "android",
        "ssmix": "a",
        "device_type": "ONEPLUS A6010",
        "device_brand": "OnePlus",
        "language": "zh",
        "os_api": "28",
        "os_version": "9",
        "uuid": device_info['uuid'],
        "openudid": device_info['openudid'],
        "manifest_version_code": "290",
        "resolution": "1080*2261",
        "dpi": "420",
        "update_version_code": "2902",
        "_rticket": str(int(time())) + "000",
    }
    args = ""
    for (idx, val) in params.items():
        args += "&{0}={1}".format(idx, val)
    original_url = "http://is.snssdk.com/passport/auth/login/?" + args

    signed_url = sign(original_url, token=API_TOKEN)
    print(signed_url)
    response = requests.get(
        url=signed_url,
        headers={
            "Cache-Control": "max-stale=0",
            "Sdk-Version": "1",
            "Accept-Encoding": "gzip",
            "User-Agent": "okhttp/3.10.0.1",
        },
    )
    print('Response HTTP Status Code: {status_code}'.format(
        status_code=response.status_code))
    print('Response HTTP Response Body: {content}'.format(
        content=response.content.decode("utf-8")))
    print('Response HTTP Response Cookie: {cookie}'.format(
        cookie=response.cookies.items()))
Example #4
0
def init(amount, currency=None, email="", description="", language=None):
    """
    Init payment

    Params:
    * amount - Amount to pay
    * currency - Suggested currency (can be changed by user)
    * email - User's email (can be changed by user)
    * description - Transaction description
    * language - "en" or "ru"

    Return tuple (rk.models.Transaction instance, robokassa redirect URL)
    """

    from models import Transaction

    if amount is None:
        return None

    currency = currency or lib.conf("RK_DEFAULT_CURRENCY")
    language = language or lib.conf("RK_DEFAULT_LANGUAGE")

    login = lib.conf("RK_MERCHANT_LOGIN")
    pass1 = lib.conf("RK_MERCHANT_PASS1")

    # 2. Create transaction in DB
    tr = Transaction(amount=amount, currency=currency, description=description)
    tr.save()
    _id = tr.id

    signature = lib.sign([login, amount, str(_id), pass1])

    # 3. Redirect to robokassa
    params = {"MrchLogin": login,
              "OutSum": amount,
              "InvId": _id,
              "Desc": description,
              "SignatureValue": signature,
              "IncCurrLabel": currency,
              "Email": email,
              "Culture": language}

    if lib.conf("RK_USE_TEST_SERVER"):
        rk_url = lib.conf("RK_TEST_URL")
    else:
        rk_url = lib.conf("RK_URL")

    url = rk_url + "?%s" % urllib.urlencode(params)

    return (tr, url)
Example #5
0
def fetch_queries(registry_id):
    """Fetching queries. Will also sign those not seen before."""

    data = request.urlopen(config.WEB_SERVER_QUERY_URL).read()
    logger.debug("all queries %s", data.decode("utf-8"))

    queries = json.loads(data.decode("utf-8"))
    for query in queries['queries']:
        # fill local cache
        query_id = query.get('id')
        if not query.get('status') and query_id not in signed_query_store:
            query['signed_by'] = []
            original = json.dumps(query['fields'])
            signed = sign(original)
            query['signed'] = signed.data.decode("utf-8")
            signed_query_store[query_id] = query
        elif query.get('status'):
            del signed_query_store[query_id]
Example #6
0
def test_threshold_sign():
	params = setup()

	# user parameters
	m = 10
	t, n = 2, 4

	# generate key
	(sk, vk, vvk) = ttp_th_keygen(params, t, n)

	# sign
	sigs = [sign(params, ski, m) for ski in sk]

	# affregate signatures
	sig = aggregate_th_sign(params, sigs)

	# randomize signature
	sig = randomize(params, sig)

	# verify signature
	assert verify(params, vvk, m, sig)
Example #7
0
def sign_wrapper(data):
	m = data["message"]
	sig = sign(params, app.sk, m)
	return format(pack(sig))
Example #8
0
def test_sign(token):
    print(
        sign(
            "https://api-hl.amemv.com/aweme/v1/commit/follow/user/?user_id=60514131756&type=1&retry_type=no_retry&iid=65734914098&device_id=66679620049&ac=wifi&channel=wandoujia_zhiwei&aid=1128&app_name=aweme&version_code=290&version_name=2.9.0&device_platform=android&ssmix=a&device_type=ONEPLUS%20A6010&device_brand=OnePlus&language=zh&os_api=28&os_version=9&uuid=432635101856947&openudid=8522097096784651&manifest_version_code=290&resolution=1080*2261&dpi=420&update_version_code=2902&_rticket=1552285914901",
            token=token))