summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmrk-srv-build.sh1
-rw-r--r--mrk.c59
-rw-r--r--mrklib.h5
-rw-r--r--mrklib_priv.h5
-rw-r--r--mrklib_serv.c29
-rw-r--r--mrklib_svc.c49
6 files changed, 147 insertions, 1 deletions
diff --git a/mrk-srv-build.sh b/mrk-srv-build.sh
index 09a248c..132bc29 100755
--- a/mrk-srv-build.sh
+++ b/mrk-srv-build.sh
@@ -20,6 +20,7 @@ export MRKARCH="x86_64"
20export MRKOS="linux" 20export MRKOS="linux"
21mrk build 21mrk build
22mrk bin 22mrk bin
23mrk src
23export D="$2"/"$MRKOS-$MRKARCH" 24export D="$2"/"$MRKOS-$MRKARCH"
24mkdir -p "$D" || true 25mkdir -p "$D" || true
25cp "$NAME"-"$VERSION".mkb "$D" 26cp "$NAME"-"$VERSION".mkb "$D"
diff --git a/mrk.c b/mrk.c
index 5449b5e..2a9958e 100644
--- a/mrk.c
+++ b/mrk.c
@@ -19,11 +19,14 @@ static const char *arch = NULL;
19static const char *os = NULL; 19static const char *os = NULL;
20static char key_priv_buf[4096]; 20static char key_priv_buf[4096];
21static char key_cert_buf[4096]; 21static char key_cert_buf[4096];
22static char get_cert_buf[4096];
22static const char *key_priv = NULL; 23static const char *key_priv = NULL;
23static const char *key_cert = NULL; 24static const char *key_cert = NULL;
25static const char *get_cert = NULL;
24 26
25static Eina_Bool move_to_cwd = EINA_FALSE; 27static Eina_Bool move_to_cwd = EINA_FALSE;
26static Eina_Bool install_bin = EINA_FALSE; 28static Eina_Bool install_bin = EINA_FALSE;
29static Eina_Bool get_new_key = EINA_FALSE;
27 30
28static void 31static void
29_cb_connect(void *data EINA_UNUSED, Mrk *server EINA_UNUSED) 32_cb_connect(void *data EINA_UNUSED, Mrk *server EINA_UNUSED)
@@ -108,6 +111,8 @@ _cb_download_success(void *data EINA_UNUSED, Mrk *server EINA_UNUSED, const char
108 const char *fname = ecore_file_file_get(file); 111 const char *fname = ecore_file_file_get(file);
109 char tmp[PATH_MAX], wd[PATH_MAX]; 112 char tmp[PATH_MAX], wd[PATH_MAX];
110 113
114 if (!mrk_package_verify(file, get_cert))
115 _mrk_err("Failed to verify signature\n");
111 if (fname) 116 if (fname)
112 { 117 {
113 if (ecore_file_exists(fname)) _mrk_err("File: '%s' exists in ./\n", fname); 118 if (ecore_file_exists(fname)) _mrk_err("File: '%s' exists in ./\n", fname);
@@ -120,6 +125,8 @@ _cb_download_success(void *data EINA_UNUSED, Mrk *server EINA_UNUSED, const char
120 } 125 }
121 else if (install_bin) 126 else if (install_bin)
122 { 127 {
128 if (!mrk_package_verify(file, get_cert))
129 _mrk_err("Failed to verify signature\n");
123 if (!mrk_package_bin_install(file, os, arch)) 130 if (!mrk_package_bin_install(file, os, arch))
124 _mrk_err("Failed to install\n"); 131 _mrk_err("Failed to install\n");
125 if (!mrk_package_bin_clean()) _mrk_err("Failed to clean\n"); 132 if (!mrk_package_bin_clean()) _mrk_err("Failed to clean\n");
@@ -145,6 +152,31 @@ _cb_answer_end(void *data EINA_UNUSED, Mrk *server EINA_UNUSED)
145 ecore_main_loop_quit(); 152 ecore_main_loop_quit();
146} 153}
147 154
155static void
156_cb_getkey(void *data EINA_UNUSED, Mrk *server EINA_UNUSED, const char *result)
157{
158 if (get_new_key)
159 {
160 FILE *f;
161 char *dir;
162
163 dir = ecore_file_dir_get(get_cert);
164 if (dir)
165 {
166 ecore_file_mkpath(dir);
167 free(dir);
168 }
169 f = fopen(get_cert, "wb");
170 if (f)
171 {
172 fwrite(result, strlen(result), 1, f);
173 fclose(f);
174 }
175 if ((!install_bin) && (!move_to_cwd)) ecore_main_loop_quit();
176 }
177}
178
179
148int 180int
149main(int argc, char **argv) 181main(int argc, char **argv)
150{ 182{
@@ -158,12 +190,13 @@ main(int argc, char **argv)
158 " check\n" 190 " check\n"
159 " src\n" 191 " src\n"
160 " newkey\n" 192 " newkey\n"
193 " fixup\n"
161 " verify FILE\n" 194 " verify FILE\n"
162 " extract FILE\n" 195 " extract FILE\n"
163 " inst FILE\n" 196 " inst FILE\n"
164 " rm PKGNAME\n" 197 " rm PKGNAME\n"
165 " rel [FILE]\n" 198 " rel [FILE]\n"
166 " fixup\n" 199 " getkey\n"
167 " down PKGNAME\n" 200 " down PKGNAME\n"
168 " get PKGNAME\n" 201 " get PKGNAME\n"
169 " getsrc PKGNAME\n" 202 " getsrc PKGNAME\n"
@@ -188,6 +221,10 @@ main(int argc, char **argv)
188 key_priv = key_priv_buf; 221 key_priv = key_priv_buf;
189 key_cert = key_cert_buf; 222 key_cert = key_cert_buf;
190 223
224 snprintf(get_cert_buf, sizeof(get_cert_buf),
225 "%s/.marrakesh/keys/Marrakesh-cert.pem", getenv("HOME"));
226 get_cert = get_cert_buf;
227
191 if (getenv("MRKHOST")) server_host = getenv("MRKHOST"); 228 if (getenv("MRKHOST")) server_host = getenv("MRKHOST");
192 if (getenv("MRKPORT")) server_port = atoi(getenv("MRKPORT")); 229 if (getenv("MRKPORT")) server_port = atoi(getenv("MRKPORT"));
193 if (getenv("MRKARCH")) arch = getenv("MRKARCH"); 230 if (getenv("MRKARCH")) arch = getenv("MRKARCH");
@@ -221,6 +258,9 @@ main(int argc, char **argv)
221 258
222 snprintf(tmp, sizeof(tmp), "%s/.marrakesh/keys", getenv("HOME")); 259 snprintf(tmp, sizeof(tmp), "%s/.marrakesh/keys", getenv("HOME"));
223 ecore_file_mkpath(tmp); 260 ecore_file_mkpath(tmp);
261 chmod(tmp, S_IRUSR | S_IWUSR | S_IXUSR);
262 snprintf(tmp, sizeof(tmp), "%s/.marrakesh", getenv("HOME"));
263 chmod(tmp, S_IRUSR | S_IWUSR | S_IXUSR);
224 snprintf(tmp, sizeof(tmp), 264 snprintf(tmp, sizeof(tmp),
225 "openssl genrsa -out " 265 "openssl genrsa -out "
226 "%s/.marrakesh/keys/default-priv.pem " 266 "%s/.marrakesh/keys/default-priv.pem "
@@ -370,6 +410,8 @@ main(int argc, char **argv)
370 _cb_answer_begin, NULL, 410 _cb_answer_begin, NULL,
371 _cb_answer_progress, NULL, 411 _cb_answer_progress, NULL,
372 _cb_answer_end, NULL); 412 _cb_answer_end, NULL);
413 mrk_callback_getkey_set(server,
414 _cb_getkey, NULL);
373 415
374 if (!strcmp(argv[1], "down")) 416 if (!strcmp(argv[1], "down"))
375 { 417 {
@@ -377,10 +419,20 @@ main(int argc, char **argv)
377 move_to_cwd = EINA_TRUE; 419 move_to_cwd = EINA_TRUE;
378 mrk_download(server, argv[2]); 420 mrk_download(server, argv[2]);
379 } 421 }
422 else if (!strcmp(argv[1], "getkey"))
423 {
424 get_new_key = EINA_TRUE;
425 mrk_getkey(server);
426 }
380 else if (!strcmp(argv[1], "get")) 427 else if (!strcmp(argv[1], "get"))
381 { 428 {
382 if (argc < 2) _mrk_err("Must provide PKGNAME as argument\n"); 429 if (argc < 2) _mrk_err("Must provide PKGNAME as argument\n");
383 install_bin = EINA_TRUE; 430 install_bin = EINA_TRUE;
431 if (!ecore_file_exists(get_cert))
432 {
433 get_new_key = EINA_TRUE;
434 mrk_getkey(server);
435 }
384 mrk_download(server, argv[2]); 436 mrk_download(server, argv[2]);
385 } 437 }
386 else if (!strcmp(argv[1], "rel")) 438 else if (!strcmp(argv[1], "rel"))
@@ -432,6 +484,11 @@ main(int argc, char **argv)
432 { 484 {
433 if (argc < 2) _mrk_err("Must provide PKGNAME as argument\n"); 485 if (argc < 2) _mrk_err("Must provide PKGNAME as argument\n");
434 move_to_cwd = EINA_TRUE; 486 move_to_cwd = EINA_TRUE;
487 if (!ecore_file_exists(get_cert))
488 {
489 get_new_key = EINA_TRUE;
490 mrk_getkey(server);
491 }
435 mrk_download_source(server, argv[2]); 492 mrk_download_source(server, argv[2]);
436 } 493 }
437 ecore_main_loop_begin(); 494 ecore_main_loop_begin();
diff --git a/mrklib.h b/mrklib.h
index 54ace32..9490acf 100644
--- a/mrklib.h
+++ b/mrklib.h
@@ -24,6 +24,8 @@ EAPI Eina_Bool mrk_download(Mrk *server, const char *package);
24EAPI Eina_Bool mrk_download_source(Mrk *server, const char *package); 24EAPI Eina_Bool mrk_download_source(Mrk *server, const char *package);
25EAPI Eina_Bool mrk_list(Mrk *server, const char *category); 25EAPI Eina_Bool mrk_list(Mrk *server, const char *category);
26EAPI Eina_Bool mrk_search(Mrk *server, const char *keys); 26EAPI Eina_Bool mrk_search(Mrk *server, const char *keys);
27EAPI Eina_Bool mrk_getkey(Mrk *server);
28
27EAPI void mrk_callback_connect_set(Mrk *server, 29EAPI void mrk_callback_connect_set(Mrk *server,
28 void (*connect) (void *data, Mrk *server), 30 void (*connect) (void *data, Mrk *server),
29 void *connect_data, 31 void *connect_data,
@@ -54,6 +56,9 @@ EAPI void mrk_callback_answer_set(Mrk *server,
54 void *answer_progress_data, 56 void *answer_progress_data,
55 void (*answer_end) (void *data, Mrk *server), 57 void (*answer_end) (void *data, Mrk *server),
56 void *answer_end_data); 58 void *answer_end_data);
59EAPI void mrk_callback_getkey_set(Mrk *server,
60 void (*getkey) (void *data, Mrk *server, const char *answer),
61 void *getkey_data);
57 62
58// api to run a mrk server - right now you have very little choice here 63// api to run a mrk server - right now you have very little choice here
59// as everything is just magically handled internally - in future some way 64// as everything is just magically handled internally - in future some way
diff --git a/mrklib_priv.h b/mrklib_priv.h
index a20b012..cb2d252 100644
--- a/mrklib_priv.h
+++ b/mrklib_priv.h
@@ -76,6 +76,11 @@ extern int _mrk_uuid_len;
76#define M_INF_GET_SP 65 76#define M_INF_GET_SP 65
77#define M_INF_GET_IN 66 77#define M_INF_GET_IN 66
78 78
79#define M_GETKEY_B 70
80#define M_GETKEY_E 80
81#define M_GETKEY_REQ 71
82#define M_GETKEY_ANS 72
83
79 84
80#if defined(__x86_64__) 85#if defined(__x86_64__)
81# define ARCH "x86_64" 86# define ARCH "x86_64"
diff --git a/mrklib_serv.c b/mrklib_serv.c
index 9cb7fbf..744ecde 100644
--- a/mrklib_serv.c
+++ b/mrklib_serv.c
@@ -314,6 +314,33 @@ _mrk_inf_data(Mrk_Serve *server EINA_UNUSED, Client *c, Ecore_Ipc_Event_Client_D
314} 314}
315 315
316static Eina_Bool 316static Eina_Bool
317_mrk_getkey_data(Mrk_Serve *server, Client *c, Ecore_Ipc_Event_Client_Data *e)
318{
319 if ((!c->uuid) || (!c->version) || (!c->arch)) return EINA_FALSE;
320 if (e->minor == M_GETKEY_REQ)
321 {
322 char tmp[4096];
323 Eina_File *ef;
324 int size;
325 void *data;
326
327 snprintf(tmp, sizeof(tmp), "%s/Marrakesh-Cert.pem", server->repodir);
328 ef = eina_file_open(tmp, EINA_FALSE);
329 if (ef)
330 {
331 size = (int)eina_file_size_get(ef);
332 data = eina_file_map_all(ef, EINA_FILE_SEQUENTIAL);
333 ecore_ipc_client_send(c->client, M_OP, M_GETKEY_ANS, 0, 0, 0, data, size);
334 eina_file_close(ef);
335 }
336 else
337 ecore_ipc_client_send(c->client, M_OP, M_GETKEY_ANS, 0, 0, 0, NULL, 0);
338 return EINA_TRUE;
339 }
340 return EINA_FALSE;
341}
342
343static Eina_Bool
317_mrk_data_handle(Mrk_Serve *server, Client *c, Ecore_Ipc_Event_Client_Data *e) 344_mrk_data_handle(Mrk_Serve *server, Client *c, Ecore_Ipc_Event_Client_Data *e)
318{ 345{
319 if ((e->minor > M_UP_B) && (e->minor < M_UP_E)) 346 if ((e->minor > M_UP_B) && (e->minor < M_UP_E))
@@ -324,6 +351,8 @@ _mrk_data_handle(Mrk_Serve *server, Client *c, Ecore_Ipc_Event_Client_Data *e)
324 return _mrk_id_data(server, c, e); 351 return _mrk_id_data(server, c, e);
325 else if ((e->minor > M_INF_B) && (e->minor < M_INF_E)) 352 else if ((e->minor > M_INF_B) && (e->minor < M_INF_E))
326 return _mrk_inf_data(server, c, e); 353 return _mrk_inf_data(server, c, e);
354 else if ((e->minor > M_GETKEY_B) && (e->minor < M_GETKEY_E))
355 return _mrk_getkey_data(server, c, e);
327 return EINA_FALSE; 356 return EINA_FALSE;
328} 357}
329 358
diff --git a/mrklib_svc.c b/mrklib_svc.c
index 45daab8..adf13ff 100644
--- a/mrklib_svc.c
+++ b/mrklib_svc.c
@@ -26,6 +26,8 @@ struct _Mrk
26 void (*answer_begin) (void *data, Mrk *server); 26 void (*answer_begin) (void *data, Mrk *server);
27 void (*answer_progress) (void *data, Mrk *server, const char *result); 27 void (*answer_progress) (void *data, Mrk *server, const char *result);
28 void (*answer_end) (void *data, Mrk *server); 28 void (*answer_end) (void *data, Mrk *server);
29
30 void (*getkey) (void *data, Mrk *server, const char *result);
29 } func; 31 } func;
30 struct { 32 struct {
31 void *connect; 33 void *connect;
@@ -44,6 +46,7 @@ struct _Mrk
44 void *answer_begin; 46 void *answer_begin;
45 void *answer_progress; 47 void *answer_progress;
46 void *answer_end; 48 void *answer_end;
49 void *getkey;
47 } data; 50 } data;
48}; 51};
49 52
@@ -290,6 +293,35 @@ _mrk_query_data(Mrk *server, Ecore_Ipc_Event_Server_Data *e)
290} 293}
291 294
292static Eina_Bool 295static Eina_Bool
296_mrk_getkey(Mrk *server)
297{
298 if (server->f) return EINA_FALSE;
299 ecore_ipc_server_send(server->server, M_OP, M_GETKEY_REQ, 0, 0, 0, NULL, 0);
300 return EINA_TRUE;
301}
302
303static Eina_Bool
304_mrk_getkey_data(Mrk *server, Ecore_Ipc_Event_Server_Data *e)
305{
306 if (e->minor == M_GETKEY_ANS)
307 {
308 if ((e->data) && (e->size > 0) && (e->size <= 100000))
309 {
310 char *str = _mrk_util_proto_string(e);
311
312 if (str)
313 {
314 if (server->func.getkey)
315 server->func.getkey(server->data.getkey, server, str);
316 free(str);
317 }
318 }
319 return EINA_TRUE;
320 }
321 return EINA_FALSE;
322}
323
324static Eina_Bool
293_mrk_data_handle(Mrk *server, Ecore_Ipc_Event_Server_Data *e) 325_mrk_data_handle(Mrk *server, Ecore_Ipc_Event_Server_Data *e)
294{ 326{
295 if ((e->minor > M_UP_B) && (e->minor < M_UP_E)) 327 if ((e->minor > M_UP_B) && (e->minor < M_UP_E))
@@ -300,6 +332,8 @@ _mrk_data_handle(Mrk *server, Ecore_Ipc_Event_Server_Data *e)
300 return _mrk_download_src_data(server, e); 332 return _mrk_download_src_data(server, e);
301 else if ((e->minor > M_ANS_B) && (e->minor < M_ANS_E)) 333 else if ((e->minor > M_ANS_B) && (e->minor < M_ANS_E))
302 return _mrk_query_data(server, e); 334 return _mrk_query_data(server, e);
335 else if ((e->minor > M_GETKEY_B) && (e->minor < M_GETKEY_E))
336 return _mrk_getkey_data(server, e);
303 return EINA_FALSE; 337 return EINA_FALSE;
304} 338}
305 339
@@ -419,6 +453,12 @@ mrk_search(Mrk *server, const char *keys)
419 return _mrk_query_search(server, keys); 453 return _mrk_query_search(server, keys);
420} 454}
421 455
456EAPI Eina_Bool
457mrk_getkey(Mrk *server)
458{
459 return _mrk_getkey(server);
460}
461
422EAPI void 462EAPI void
423mrk_callback_connect_set(Mrk *server, 463mrk_callback_connect_set(Mrk *server,
424 void (*connect) (void *data, Mrk *server), 464 void (*connect) (void *data, Mrk *server),
@@ -490,3 +530,12 @@ mrk_callback_answer_set(Mrk *server,
490 server->func.answer_end = answer_end; 530 server->func.answer_end = answer_end;
491 server->data.answer_end = answer_end_data; 531 server->data.answer_end = answer_end_data;
492} 532}
533
534EAPI void
535mrk_callback_getkey_set(Mrk *server,
536 void (*getkey) (void *data, Mrk *server, const char *keydata),
537 void *getkey_data)
538{
539 server->func.getkey = getkey;
540 server->data.getkey = getkey_data;
541}