Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking Signature not working #61

Open
dirkstraathof opened this issue Mar 2, 2023 · 3 comments
Open

Checking Signature not working #61

dirkstraathof opened this issue Mar 2, 2023 · 3 comments

Comments

@dirkstraathof
Copy link

I'm using sample code from the Test project to calculate the signature and check if the push message is valid. But I can't get it to work.

This is my test code

// JSON push as it is received by the client system.
try
{
    SdkClient BuckarooClient = new SdkClient();
    PushHandler pushHandler = BuckarooClient.GetPushHandler("xkduEg374bs63nsiGFs");

    var bodyAsBytes = Encoding.UTF8.GetBytes(requestBody);           // DEZE IS BELANGRIJK: BERICHT AS BYTE[]

    // calculate UNIX time
    var epochStart = new DateTime(1970, 01, 01, 0, 0, 0, 0, DateTimeKind.Utc);
    var timeSpan = DateTime.UtcNow - epochStart;
    var requestTimeStamp = Convert.ToUInt64(timeSpan.TotalSeconds).ToString();
    // create random nonce for each request


    var pushSignature = BuckarooClient.GetSignatureCalculationService().CalculateSignature(bodyAsBytes, HttpMethod.Post.ToString(),
        requestTimeStamp, Guid.NewGuid().ToString("N"),
        "https://5rmj616c-7142.euw.devtunnels.ms/api/BuckarooPush?code=rP_gjf0lzLaP8a1vn99A0-mLd-eM9V3enM1JgjAxFFVBAzFuB3uxAQ==", "ahpfM7jwcb", "xkduEg374bs63nsiGFs");


    var authorizationheader = $"hmac {pushSignature}";              // DEZE IS BELANGRIJK: SIGNATURE

    // Function that returns a structured push, based on the JSON pushed that is received.
    var push = pushHandler.DeserializePush(bodyAsBytes, "https://5rmj616c-7142.euw.devtunnels.ms/api/BuckarooPush?code=rP_gjf0lzLaP8a1vn99A0-mLd-eM9V3enM1JgjAxFFVBAzFuB3uxAQ==", authorizationheader);

    var service = push.GetServices();

    var responseData = push.GetActionResponse<IdealPayPush>();
}
catch (Exception ex)
{
    string s = ex.ToString();
}

And this is the error I'm receiving:
System.Security.Authentication.AuthenticationException: System error.
at BuckarooSdk.Base.PushHandler.DeserializePush(Byte[] body, String requestUri, String authorizationHeader)

Can anybody point me in the right directory on how to handle this?

@Michael-Buckaroo
Copy link

Michael-Buckaroo commented Apr 5, 2023

I haven't tested it, but my first guess would be that the requestUri is manipulated inside DeserializePush, while i did not spot the same in the CalculateSignature code path. I'm not familiar with the code base of this project though and was just quickly scanning through it, so i might have missed it somewhere (or it might have no effect at all). Just thinking out loud in the hope it helps! :)

Will create a ticket internally for this too.

@gerardva
Copy link

As @Michael-Buckaroo mentioned the issue seems to be with the requestUri. The issue for me was that the requestUri input parameter for the CalculateSignature function needed to be url encoded and made lowercase first. So i fixed it like this:
CalculateSignature(.., ..., ..., ..., WebUtility.UrlEncode(requestUri).ToLowerInvariant(), ..., ...)

@dirkstraathof
Copy link
Author

dirkstraathof commented May 4, 2023

As @Michael-Buckaroo mentioned the issue seems to be with the requestUri. The issue for me was that the requestUri input parameter for the CalculateSignature function needed to be url encoded and made lowercase first. So i fixed it like this: CalculateSignature(.., ..., ..., ..., WebUtility.UrlEncode(requestUri).ToLowerInvariant(), ..., ...)

Thanks, I will test this at the next service moment for the App. Maybe the documentation for the Buckaroo package can be clarified @Michael-Buckaroo? Looks like something you miss easily when trying to make this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants