1 | /* |
1 | /* |
2 | util.h -- process management and other utility functions |
2 | util.h -- process management and other utility functions |
3 | Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl> |
3 | Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl> |
4 | 2000-2002 Guus Sliepen <guus@sliepen.eu.org> |
4 | 2000-2002 Guus Sliepen <guus@sliepen.eu.org> |
5 | 2003-2008 Marc Lehmann <gvpe@schmorp.de> |
5 | 2003-2013 Marc Lehmann <gvpe@schmorp.de> |
6 | |
6 | |
7 | This file is part of GVPE. |
7 | This file is part of GVPE. |
8 | |
8 | |
9 | GVPE is free software; you can redistribute it and/or modify it |
9 | GVPE is free software; you can redistribute it and/or modify it |
10 | under the terms of the GNU General Public License as published by the |
10 | under the terms of the GNU General Public License as published by the |
… | |
… | |
42 | #include "gettext.h" |
42 | #include "gettext.h" |
43 | |
43 | |
44 | #include "slog.h" |
44 | #include "slog.h" |
45 | #include "ev_cpp.h" |
45 | #include "ev_cpp.h" |
46 | #include "callback.h" |
46 | #include "callback.h" |
|
|
47 | #include "global.h" |
47 | |
48 | |
48 | typedef ev_tstamp tstamp; |
49 | typedef ev_tstamp tstamp; |
49 | |
50 | |
50 | /* |
51 | /* |
51 | * check for an existing gvpe for this net, and write pid to pidfile |
52 | * check for an existing gvpe for this net, and write pid to pidfile |
… | |
… | |
119 | } |
120 | } |
120 | } |
121 | } |
121 | } |
122 | } |
122 | }; |
123 | }; |
123 | |
124 | |
124 | typedef callback<const char * ()> run_script_cb; |
125 | typedef callback<const char *()> run_script_cb; |
125 | |
126 | |
126 | // run a shell script (or actually an external program). |
127 | // run a shell script (or actually an external program). |
127 | pid_t run_script (const run_script_cb &cb, bool wait); |
128 | pid_t run_script (const run_script_cb &cb, bool wait); |
|
|
129 | |
|
|
130 | void hexdump (const char *header, void *data, int len); |
128 | |
131 | |
129 | #if ENABLE_HTTP_PROXY |
132 | #if ENABLE_HTTP_PROXY |
130 | u8 *base64_encode (const u8 *data, unsigned int len); |
133 | u8 *base64_encode (const u8 *data, unsigned int len); |
131 | #endif |
134 | #endif |
132 | |
135 | |
133 | /*****************************************************************************/ |
136 | /*****************************************************************************/ |
134 | |
137 | |
135 | typedef u8 rsaclear[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data; |
138 | // run work_cb in another thread, call done_cb in main thread when finished |
136 | typedef u8 rsacrypt[RSA_KEYLEN]; // encrypted challenge |
139 | // only one work_cb will execute at any one time. |
137 | |
140 | void async (callback<void ()> work_cb, callback<void ()> done_cb); |
138 | static inline void |
|
|
139 | rsa_encrypt (RSA *key, const rsaclear &chg, rsacrypt &encr) |
|
|
140 | { |
|
|
141 | if (RSA_public_encrypt (sizeof chg, |
|
|
142 | (unsigned char *)&chg, (unsigned char *)&encr, |
|
|
143 | key, RSA_PKCS1_OAEP_PADDING) < 0) |
|
|
144 | fatal ("RSA_public_encrypt error"); |
|
|
145 | } |
|
|
146 | |
|
|
147 | static inline bool |
|
|
148 | rsa_decrypt (RSA *key, const rsacrypt &encr, rsaclear &chg) |
|
|
149 | { |
|
|
150 | return RSA_private_decrypt (sizeof encr, |
|
|
151 | (unsigned char *)&encr, (unsigned char *)&chg, |
|
|
152 | key, RSA_PKCS1_OAEP_PADDING) > 0; |
|
|
153 | } |
|
|
154 | |
141 | |
155 | #endif |
142 | #endif |
156 | |
143 | |