[Python] Timed Hash Verification based web api call in Lindane Scripting Language

Discussão em 'Python' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to call a web api which is secred by Timed Hash Verification system.

    I am able to call that API using python

    import hmac
    import hashlib
    import time
    import requests
    import json

    def generate_timed_hash(secret_key, data):
    timestamp = str(int(time.time())) # Current Unix timestamp
    message = data + timestamp
    hash_value = hmac.new(secret_key.encode(), message.encode(), hashlib.sha256).hexdigest()
    return hash_value, timestamp

    def testApi():
    data = json.dumps({'userId': 'c088ab7f-dd04-4836-93cd-7ab2843db971'})
    secret_key = 'mysecret'
    hash_value, timestamp = generate_timed_hash(secret_key, data)

    headers = {
    'X-Timestamp': timestamp,
    'X-Hash': hash_value,
    }

    response = requests.post('https://some-host/api/secured-plan-detail/', data={'data': data}, headers=headers)
    print(response.json())

    testApi()


    I found llSHA256String for generating SHA256 string. But still not able to figure out way tranaslate that python code.

    Here is my attempt to make http call.

    default
    {
    state_entry()
    {
    llHTTPRequest(
    "https://some-host/api/secured-plan-detail/",
    [
    HTTP_METHOD, "POST",
    HTTP_MIMETYPE, "application/json"
    //HTTP_CUSTOM_HEADER, "X-Timestamp:", timestamp
    //HTTP_CUSTOM_HEADER, "X-Hash:", hash_value
    ],
    llList2Json(JSON_OBJECT, ["userId", "c088ab7f-dd04-4836-93cd-7ab2843db971"])
    );
    }
    http_response(key request_id, integer status, list metadata, string body) {
    llOwnerSay((string)status);
    llOwnerSay("response: " + body);
    }
    }


    How can make such call in Lindane Scripting Language?

    Continue reading...

Compartilhe esta Página