summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Friloux <guillaume.friloux@gmail.com>2013-08-14 23:58:06 +0200
committerGuillaume Friloux <guillaume.friloux@gmail.com>2013-08-14 23:58:06 +0200
commit861424f3d1e05e82c5ccfb660491e7d794d87413 (patch)
tree8940eb6bf5396f42508b9ef17c5266ffcd4e22f6
parent0061ee5f7dc2e2c77d75d06ec74e8cf7aae485cc (diff)
Removed useless securities (spank spank spank, dont copy/paste code from mega sdk without checking EVERYTHING).
We are now able to generate the hash used for auth.
-rw-r--r--src/modules/mega/mega.h7
-rw-r--r--src/modules/mega/mega_main.c18
-rw-r--r--src/modules/mega/mega_utils.c77
3 files changed, 63 insertions, 39 deletions
diff --git a/src/modules/mega/mega.h b/src/modules/mega/mega.h
index b7bae74..7189725 100644
--- a/src/modules/mega/mega.h
+++ b/src/modules/mega/mega.h
@@ -1,5 +1,8 @@
1#include <skypunch_private.h> 1#include <skypunch_private.h>
2#include <aes.h> 2#include <aes.h>
3 3
4const char * mega_utils_str_to_a32(const char *s, size_t *l); 4const char * mega_utils_key_encode(const char *s);
5const char * mega_utils_key_encode(const char *s, size_t *l); 5const char * mega_utils_login_hash(const char *email, const char *password);
6const char * mega_utils_login_encode(const char *auth, size_t *len);
7void mega_utils_print(const char *s, int len);
8
diff --git a/src/modules/mega/mega_main.c b/src/modules/mega/mega_main.c
index 1c5473d..9edd4f3 100644
--- a/src/modules/mega/mega_main.c
+++ b/src/modules/mega/mega_main.c
@@ -3,26 +3,16 @@
3Eina_Bool 3Eina_Bool
4mega_login(Skypunch *skypunch) 4mega_login(Skypunch *skypunch)
5{ 5{
6 size_t len, 6 size_t len;
7 len_enc; 7 const char *hash;
8 char **auth,
9 *password,
10 *password_enc;
11 unsigned int nb;
12 8
13 EINA_SAFETY_ON_NULL_RETURN_VAL(skypunch, EINA_FALSE); 9 EINA_SAFETY_ON_NULL_RETURN_VAL(skypunch, EINA_FALSE);
14 10
15 DBG("skypunch[%p]"); 11 DBG("skypunch[%p]");
16 12
17 auth = eina_str_split_full(skypunch->auth, ":", 2, &nb); 13 hash = mega_utils_login_encode(skypunch->auth, &len);
18 14
19 password = mega_utils_str_to_a32(auth[1], &len); 15 mega_utils_print(hash, 16);
20 password_enc = mega_utils_key_encode(password, &len_enc);
21
22 free(password_enc);
23 free(password);
24 free(auth[0]);
25 free(auth);
26 return EINA_TRUE; 16 return EINA_TRUE;
27} 17}
28 18
diff --git a/src/modules/mega/mega_utils.c b/src/modules/mega/mega_utils.c
index 9a46641..7ec92ca 100644
--- a/src/modules/mega/mega_utils.c
+++ b/src/modules/mega/mega_utils.c
@@ -1,26 +1,7 @@
1#include "mega.h" 1#include "mega.h"
2 2
3const char *
4mega_utils_str_to_a32(const char *s, size_t *l)
5{
6 size_t sl,
7 slf;
8 char *s2;
9
10 EINA_SAFETY_ON_NULL_RETURN_VAL(s, NULL);
11 EINA_SAFETY_ON_NULL_RETURN_VAL(l, NULL);
12
13 sl = strlen(s);
14 slf = 4 * ((sl+3)>>2);
15
16 s2 = calloc(1, slf);
17 strcpy(s2, s);
18 return s2;
19}
20
21/*
22void 3void
23___print(char *s, int len) 4mega_utils_print(const char *s, int len)
24{ 5{
25 int i; 6 int i;
26 printf("___print = "); 7 printf("___print = ");
@@ -28,10 +9,10 @@ ___print(char *s, int len)
28 printf("%02x ", s[i]); 9 printf("%02x ", s[i]);
29 printf("\n"); 10 printf("\n");
30} 11}
31*/ 12
32 13
33const char * 14const char *
34mega_utils_key_encode(const char *s, size_t *l) 15mega_utils_key_encode(const char *s)
35{ 16{
36 unsigned int i, 17 unsigned int i,
37 r = 65536, 18 r = 65536,
@@ -43,7 +24,6 @@ mega_utils_key_encode(const char *s, size_t *l)
43 WORD key_schedule[60]; 24 WORD key_schedule[60];
44 25
45 EINA_SAFETY_ON_NULL_RETURN_VAL(s, NULL); 26 EINA_SAFETY_ON_NULL_RETURN_VAL(s, NULL);
46 EINA_SAFETY_ON_NULL_RETURN_VAL(l, NULL);
47 27
48 sl = strlen(s); 28 sl = strlen(s);
49 n = (sl+15)/16; 29 n = (sl+15)/16;
@@ -64,3 +44,54 @@ mega_utils_key_encode(const char *s, size_t *l)
64 memcpy(key, pkey, 16); 44 memcpy(key, pkey, 16);
65 return key; 45 return key;
66} 46}
47
48const char *
49mega_utils_login_hash(const char *email, const char *password)
50{
51 char *hash;
52 size_t t;
53 unsigned int i;
54 WORD key_schedule[60];
55
56 t = strlen(email) & -16;
57
58 hash = calloc(1, 16);
59 strncpy(hash, email+t, 16);
60
61 while (t)
62 {
63 t -= 16;
64
65 for (i = 0; i<16; i++)
66 {
67 hash[i] ^= email[t+i];
68 }
69 }
70
71 i = 16384;
72 aes_key_setup(password, key_schedule, 128);
73
74 while (i--)
75 {
76 aes_encrypt(hash, hash, key_schedule, 128);
77 }
78 return hash;
79}
80
81const char *
82mega_utils_login_encode(const char *auth, size_t *len)
83{
84 char **s;
85 const char *password_enc,
86 *hash;
87 unsigned int nb;
88
89 s = eina_str_split_full(auth, ":", 2, &nb);
90 password_enc = mega_utils_key_encode(s[1]);
91 hash = mega_utils_login_hash(s[0], password_enc);
92
93 free((char *)password_enc);
94 free(s[0]);
95 free(s);
96 return hash;
97}