--- gvpe/src/util.h 2008/08/07 17:54:27 1.25 +++ gvpe/src/util.h 2013/07/16 16:44:37 1.31 @@ -2,7 +2,7 @@ util.h -- process management and other utility functions Copyright (C) 1998-2002 Ivo Timmermans 2000-2002 Guus Sliepen - 2003-2008 Marc Lehmann + 2003-2013 Marc Lehmann This file is part of GVPE. @@ -35,6 +35,7 @@ #define UTIL_H__ #include +#include #include @@ -43,6 +44,7 @@ #include "slog.h" #include "ev_cpp.h" #include "callback.h" +#include "global.h" typedef ev_tstamp tstamp; @@ -85,14 +87,13 @@ seq = seqno; } - bool recv_ok (u32 seqno) + // 0 == ok, 1 == far history, 2 == duplicate in-window, 3 == far future + int seqno_classify (u32 seqno) { if (seqno <= seq - WINDOWSIZE) - slog (L_ERR, _("received duplicate or outdated packet (received %08lx, expected %08lx)\n" - "possible replay attack, or just massive packet reordering"), seqno, seq + 1); - else if (seqno > seq + WINDOWSIZE * 4) - slog (L_ERR, _("received duplicate or out-of-sync packet (received %08lx, expected %08lx)\n" - "possible replay attack, or just massive packet loss"), seqno, seq + 1); + return 1; + else if (seqno > seq + WINDOWSIZE * 16) + return 3; else { while (seqno > seq) @@ -111,23 +112,20 @@ u32 mask = 1 << (s & 31); if (*cell & mask) - slog (L_ERR, _("received duplicate packet (received %08lx, expected %08lx)\n" - "possible replay attack, or just packet duplication"), seqno, seq + 1); + return 2; else { *cell |= mask; - return true; + return 0; } } - - return false; } }; -typedef callback run_script_cb; +typedef callback run_script_cb; // run a shell script (or actually an external program). -bool run_script (const run_script_cb &cb, bool wait); +pid_t run_script (const run_script_cb &cb, bool wait); #if ENABLE_HTTP_PROXY u8 *base64_encode (const u8 *data, unsigned int len); @@ -135,25 +133,9 @@ /*****************************************************************************/ -typedef u8 rsaclear[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data; -typedef u8 rsacrypt[RSA_KEYLEN]; // encrypted challenge - -static inline void -rsa_encrypt (RSA *key, const rsaclear &chg, rsacrypt &encr) -{ - if (RSA_public_encrypt (sizeof chg, - (unsigned char *)&chg, (unsigned char *)&encr, - key, RSA_PKCS1_OAEP_PADDING) < 0) - fatal ("RSA_public_encrypt error"); -} - -static inline bool -rsa_decrypt (RSA *key, const rsacrypt &encr, rsaclear &chg) -{ - return RSA_private_decrypt (sizeof encr, - (unsigned char *)&encr, (unsigned char *)&chg, - key, RSA_PKCS1_OAEP_PADDING) > 0; -} +// run work_cb in another thread, call done_cb in main thread when finished +// only one work_cb will execute at any one time. +void async (callback work_cb, callback done_cb); #endif