diff options
author | George Hazan <george.hazan@gmail.com> | 2016-04-08 08:29:38 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2016-04-08 08:29:38 +0000 |
commit | 563ab165a8d584f192dcd353fa29a0140dec9b2f (patch) | |
tree | 8dfe637db24084ca3cc4dbc871c0e60971972e8f /protocols/AimOscar | |
parent | f4239191646ae0e49d4984a083d31110e9bc42c1 (diff) |
AIM adaptation for mir_hmac256
git-svn-id: http://svn.miranda-ng.org/main/trunk@16610 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/AimOscar')
-rwxr-xr-x | protocols/AimOscar/src/connection.cpp | 24 | ||||
-rwxr-xr-x | protocols/AimOscar/src/utility.cpp | 20 | ||||
-rwxr-xr-x | protocols/AimOscar/src/utility.h | 3 |
3 files changed, 11 insertions, 36 deletions
diff --git a/protocols/AimOscar/src/connection.cpp b/protocols/AimOscar/src/connection.cpp index 921a09c10e..2375109264 100755 --- a/protocols/AimOscar/src/connection.cpp +++ b/protocols/AimOscar/src/connection.cpp @@ -250,37 +250,33 @@ void construct_query_string(char *buf, const char *token, time_t hosttime, bool }
-void generate_signature(char *signature, const char *method, const char *url, const char *parameters, const char *session_key)
+void generate_signature(BYTE *signature, const char *method, const char *url, const char *parameters, const BYTE *session_key)
{
char *encoded_url = mir_urlEncode(url);
char *encoded_parameters = mir_urlEncode(parameters);
char signature_base[1024];
- mir_snprintf(signature_base, 1023, "%s%s%s", method, encoded_url, encoded_parameters);
+ mir_snprintf(signature_base, "%s%s%s", method, encoded_url, encoded_parameters);
mir_free(encoded_url);
mir_free(encoded_parameters);
- hmac_sha256(session_key, signature_base, signature);
-
+ mir_hmac_sha256(signature, session_key, MIR_SHA256_HASH_SIZE, (BYTE*)signature_base, mir_strlen(signature_base));
}
-void fill_session_url(char *buf, char *token, char *secret, time_t &hosttime, const char *password, bool encryption = true)
+void fill_session_url(char *buf, size_t bufSize, char *token, char *secret, time_t &hosttime, const char *password, bool encryption = true)
{
- //TODO: construct url for get request
/*
AIM_SESSION_URL?query_string?sig_sha256=signature
*/
+
char query_string[1024];
query_string[0] = 0;
construct_query_string(query_string, token, hosttime, encryption);
- char signature[512];
-
- char session_key[1024];
-
- hmac_sha256(password, secret, session_key);
+ BYTE session_key[MIR_SHA256_HASH_SIZE], signature[MIR_SHA256_HASH_SIZE];
+ mir_hmac_sha256(session_key, (BYTE*)password, mir_strlen(password), (BYTE*)secret, mir_strlen(secret));
generate_signature(signature, "GET", AIM_SESSION_URL, query_string, session_key);
- mir_snprintf(buf, 2023, "%s?%s&sig_sha256=%s", AIM_SESSION_URL, query_string, signature);
-
+ size_t cbLen = mir_snprintf(buf, bufSize, "%s?%s&sig_sha256=", AIM_SESSION_URL, query_string);
+ bin2hex(signature, sizeof(signature), buf + cbLen);
}
bool parse_start_socar_session_response(char *response, char *bos_host, unsigned short bos_port, char *cookie, char *tls_cert_name, bool encryption = true)
@@ -432,7 +428,7 @@ void CAimProto::aim_connection_clientlogin(void) req.dataLength = 0;
char url[2048];
url[0] = 0;
- fill_session_url(url, token, secret, hosttime, password, encryption);
+ fill_session_url(url, sizeof(url), token, secret, hosttime, password, encryption);
mir_free(password);
req.szUrl = url;
resp = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req);
diff --git a/protocols/AimOscar/src/utility.cpp b/protocols/AimOscar/src/utility.cpp index b6c6822db6..0c2b28e1a1 100755 --- a/protocols/AimOscar/src/utility.cpp +++ b/protocols/AimOscar/src/utility.cpp @@ -100,11 +100,9 @@ void CAimProto::start_connection(void*) }
- bool use_clientlogin = getByte(AIM_KEY_CLIENTLOGIN, 0);
-
+ bool use_clientlogin = getByte(AIM_KEY_CLIENTLOGIN, 0) != 0;
if (!use_clientlogin)
{
-
char* login_url = getStringA(AIM_KEY_HN);
//if (login_url == NULL) login_url = mir_strdup(use_ssl ? AIM_DEFAULT_SERVER : AIM_DEFAULT_SERVER_NS);
@@ -664,19 +662,3 @@ unsigned short get_random(void) id &= 0x7fff;
return id;
}
-
-void hmac_sha256(const char *key, const char *msg, char *buf)
-{
- unsigned char hash[32];
-
- HMAC_CTX hmac;
- HMAC_CTX_init(&hmac);
- HMAC_Init_ex(&hmac, &key[0], strlen(key), EVP_sha256(), NULL);
- HMAC_Update(&hmac, (unsigned char*)&msg[0], strlen(msg));
- unsigned int len = 32;
- HMAC_Final(&hmac, hash, &len);
- HMAC_CTX_cleanup(&hmac);
-
- mir_strncpy(buf, key, len);
-
-}
\ No newline at end of file diff --git a/protocols/AimOscar/src/utility.h b/protocols/AimOscar/src/utility.h index f5f6e0ef53..6b8404ea00 100755 --- a/protocols/AimOscar/src/utility.h +++ b/protocols/AimOscar/src/utility.h @@ -31,9 +31,6 @@ inline int cap_cmp(const char* cap, const char* cap2) { return memcmp(cap, cap2, inline const char* alpha_cap_str(char ver) { return (ver & 0x80) ? " Alpha" : ""; }
inline const char* secure_cap_str(char* ver) { return (*(int*)ver == 0xDEC0FE5A) ? " + SecureIM" : ""; }
-void hmac_sha256(const char *key, const char *msg, char *buf);
-
-
struct BdListItem
{
char* name;
|