Jump to content

Recommended Posts

Posted

And I've added functions that make it so you never have to touch the REST stuff:

static bool SetKeys(const std::string& gamekey, const std::string& secretkey);//lua

static bool SendDesignEvent(const std::string& eventid);//lua

static bool SendDesignEvent(const std::string& eventid, const float value);//lua

static bool SendErrorEvent(const int severity, const std::string& message);//lua

static bool SendProgressEvent(const int status, const std::string& levelname);//lua

static bool SendProgressEvent(const int status, const std::string& levelname, const int score);//lua

static bool SendProgressEvent(const int status, const std::string& levelname, const int score, const int attempt_num);//lua

static bool SendResourceEvent(const int flowType, const std::string& currency, const std::string& itemType, const std::string itemid, const float amount);//lua

Let's build cool stuff and have fun. :)

Posted

For the life of me I cannot reproduce the hmac hash.

 

Using the key from the python file and the JSON from my sample, I get the following:

 

import hmac
import hashlib
key = "16813a12f718bc5c620f56944e1abc3ea13ccbac"
data = "{\"platform\":\"Windows\", \"os_version\":\"10\", \"sdk_version\":\"api v2\"}";
hash = hmac.new(key, data, digestmod=hashlib.sha256)
hash.hexdigest()

 

Produces the following HEX string a39a45d2ac53e7c4d9e3b978267a6442cad0c396a52500e6c3be9e5bb1e6edbb

 

Using the library I posted earlier I get a completely different result.

 

Using the following code which uses OpenSSL's version

#include <string.h>
#include <stdio.h>

#include <openssl/hmac.h>
#include <openssl/evp.h>

void hmac(unsigned char* key, unsigned char* message, int keylen, int messagelen, unsigned char* out)
{
 HMAC_CTX ctx;
 HMAC_CTX_init(&ctx);
 unsigned int len = 32;
 unsigned char* data[32];
 // Using sha1 hash engine here.
 // You may use other hash engines. e.g EVP_md5(), EVP_sha224, EVP_sha512, etc
 HMAC_Init_ex(&ctx, key, 20, EVP_sha256(), NULL);
 HMAC_Update(&ctx, message, messagelen);
 HMAC_Final(&ctx, out, &len);
 HMAC_CTX_cleanup(&ctx);
 memcpy(out, data, len);
 memset(out+len, 0, 32-len);
 for(int i = 0; i < len; i++)
 {
		 printf("%02x", out[i]);
 }
 printf("\n");
}

int main(int argc, const char *const *argv)
{
 unsigned char buff[32];
 const char* message = "{\"platform\":\"Windows\", \"os_version\":\"10\", \"sdk_version\":\"api v2\"}";
 const char* key = "16813a12f718bc5c620f56944e1abc3ea13ccbac";
 hmac((unsigned char*)key, (unsigned char*)message, sizeof(key), sizeof(message), buff);
}

 

I get the following printed.

0000000000000000b076bf49007f0000d859c149007f00008707400000000000

 

This sample code seems to work well. The problem is it is only windows.

 

http://stackoverflow.com/questions/22147895/is-it-possible-to-do-a-hmac-with-wincrypt

  • Upvote 2
Posted

Success!

 

Did some digging around in my test code. Apparently sizeof(char*) doesn't return the size of the static array, but just the size of a charater. Thanks G++.

 

http://martyj.net/curl.zip

 

I can't find libcurl-dev on windows for the life of me, so I had to use Linux. As I am working off of a server, I don't have Leadwerks setup so I cannot implement it in your class.

 

Sorry about the indentation as well. I was using nano to modify the files.

 

But this should help hopefully.

  • Upvote 1
Posted

I think I'm good. Thanks a lot for your help, this was really tricky. Here's the final API:

static bool Enable();//lua
static void Disable();//lua
static void SetKeys(const std::string& gamekey, const std::string& secretkey);//lua
static bool SendGenericEvent(const std::string& eventid);//lua
static bool SendGenericEvent(const std::string& eventid, const float value);//lua
static bool SendErrorEvent(const std::string& severity, const std::string& message);//lua
static bool SendProgressEvent(const std::string& status, const std::string& levelname);//lua
static bool SendProgressEvent(const std::string& status, const std::string& levelname, const int score);//lua
static bool SendProgressEvent(const std::string& status, const std::string& levelname, const int score, const int attempt_num);//lua
static bool SendResourceEvent(const std::string& flowType, const std::string& currency, const std::string& itemType, const std::string& itemid, const float amount);//lua
static bool SendBusinessEvent(const std::string& itemType, const std::string& itemid, const int amount, const std::string& currency, const uint64_t transaction_num, const std::string& cart_type = "", const std::string& receipt_info="");//lua

  • Upvote 1

Let's build cool stuff and have fun. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...