diff --git a/xvaga/xvaga.cpp b/xvaga/xvaga.cpp index dcefa08bb..e7ab30152 100755 --- a/xvaga/xvaga.cpp +++ b/xvaga/xvaga.cpp @@ -3775,7 +3775,7 @@ long xvt_sys_close_siblings(WINDOW win) BOOLEAN xvt_sys_goto_url(const char* url, const char* action) { #ifdef WIN32 - if (action != NULL && xvt_str_compare_ignoring_case(action, "open") != 0) + if (action && *action && xvt_str_compare_ignoring_case(action, "open") != 0) return OsWin32_GotoUrl(url, action); #endif return wxLaunchDefaultBrowser(url); @@ -3784,14 +3784,7 @@ BOOLEAN xvt_sys_goto_url(const char* url, const char* action) BOOLEAN xvt_sys_dongle_server_is_running() { wxSingleInstanceChecker sic("Authorization"); - BOOLEAN ok = sic.IsAnotherRunning(); - -#ifdef WIN32 - if (!ok) // Testo anche il buon vecchio Frontend! - ok = ::GlobalFindAtom("DONGLE_SERVER_ATOM") != 0; -#endif - - return ok; + return sic.IsAnotherRunning(); } int xvt_sys_get_profile_string(const char* file, const char* paragraph, const char* name, @@ -3833,7 +3826,7 @@ long xvt_sys_get_profile_int(const char* file, const char* paragraph, const char char defstr[16] = "", str[16] = ""; long value = defval; if (defval != 0) - sprintf(defstr, "%ld", defval); + wxSprintf(defstr, "%ld", defval); if (xvt_sys_get_profile_string(file, paragraph, name, defstr, str, sizeof(str))) value = atol(str); return value; diff --git a/xvaga/xvtextra.cpp b/xvaga/xvtextra.cpp index 88263290a..099acd3bc 100755 --- a/xvaga/xvtextra.cpp +++ b/xvaga/xvtextra.cpp @@ -1,5 +1,6 @@ #include "wxinc.h" #include "wx/print.h" +#include "wx/tokenzr.h" #include "xvt.h" @@ -1239,7 +1240,7 @@ typedef int (*dllVerifyMethod) ( static dllSignMethod _SignPDF = NULL; static dllVerifyMethod _VerifyPDF = NULL; -static wxString _strPin; +static wxString _strPin, _strDllFile, _strCertificate; static BOOLEAN xvt_sign_init(BOOL bLoad) { @@ -1256,10 +1257,24 @@ static BOOLEAN xvt_sign_init(BOOL bLoad) _SignPDF = (dllSignMethod)::GetProcAddress(hESigner, "Sign"); _VerifyPDF = (dllVerifyMethod)::GetProcAddress(hESigner, "Verify"); _strPin = ""; + + char str[_MAX_PATH] = ""; + xvt_sys_get_profile_string(NULL, NULL, "Study", "", str, sizeof(str)); + wxString strConfig; strConfig << str << "/config/" << wxGetHostName() << ".ini"; + xvt_sys_get_profile_string(strConfig, "fd", "Cert_"+wxGetUserId(), "", str, sizeof(str)); + wxStringTokenizer strDllCert(str, ","); + _strDllFile = strDllCert.GetNextToken(); + _strCertificate = strDllCert.GetNextToken(); } } ok = hESigner != NULL && _SignPDF != NULL && _VerifyPDF != NULL; - if (!ok) + if (ok) + { + ok = wxFileExists(_strDllFile); + if (!ok) + xvt_dm_post_error("Can't load certificate or driver"); + } + else xvt_dm_post_error("Can't load ESigner.dll"); } else @@ -1267,6 +1282,7 @@ static BOOLEAN xvt_sign_init(BOOL bLoad) if (hESigner != NULL) { ::FreeLibrary(hESigner); + hESigner = NULL; _SignPDF = NULL; _VerifyPDF = NULL; _strPin = ""; @@ -1288,23 +1304,38 @@ BOOLEAN xvt_sign_file(const char* input_name, char* output_name) } strInput.MakeLower(); + if ((_strPin.IsEmpty() || _strDllFile.IsEmpty()) && !xvt_sign_start()) + return FALSE; + + const char* ext = strInput.EndsWith(".pdf") ? ".pdf" : ""; + wxString strOutput = output_name; if (strOutput.IsEmpty()) { - strOutput = strInput + ".p7m"; + strOutput = strInput.BeforeFirst('.') + ".p7m.pdf"; if (output_name != NULL) wxStrncpy(output_name, strOutput, _MAX_PATH); } - if (_strPin.IsEmpty() && !xvt_sign_start()) - return FALSE; - - const char* ext = strInput.EndsWith(".pdf") ? ".pdf" : ""; - int res = _SignPDF("S", "T", // "S"ignature with "T"oken or smartcard - (char*)(const char*)strInput, (char*)(const char*)strOutput, - NULL, (char*)ext, NULL, NULL, NULL, NULL, - (char*)(const char*)_strPin, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + int res = 0; + if (_strDllFile.EndsWith(".dll")) + { + res = _SignPDF("S", "T", // "S"ignature with "T"oken or smartcard + (char*)(const char*)strInput, (char*)(const char*)strOutput, + NULL, (char*)ext, NULL, NULL, NULL, (char*)(const char*)_strDllFile, + (char*)(const char*)_strPin, NULL, (char*)(const char*)_strCertificate, + NULL, NULL, NULL, NULL, NULL, NULL); + } + else + { + wxString strFile = strOutput; + strFile = strFile.BeforeLast('.'); + res = _SignPDF("S", "P", // "S"ignature with "P"fx file + (char*)(const char*)strInput, (char*)(const char*)strFile, + NULL, (char*)ext, NULL, NULL, (char*)(const char*)_strDllFile, NULL, + (char*)(const char*)_strPin, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL); + } if (res == 0) { @@ -1328,11 +1359,16 @@ BOOLEAN xvt_sign_file(const char* input_name, char* output_name) BOOLEAN xvt_sign_start() { BOOLEAN ok = xvt_sign_init(TRUE); + if (ok) { - char* pin = _strPin.GetWriteBuf(16); *pin = '\0'; + } + + if (ok) + { + char pin[16] = ""; xvt_dm_post_string_prompt("PIN", pin, 15); - _strPin.UngetWriteBuf(); + _strPin = pin; ok = !_strPin.IsEmpty(); } return ok; @@ -1360,6 +1396,7 @@ BOOLEAN xvt_sign_test(const char* input_name) } strInput.MakeLower(); - int res = _VerifyPDF("V", (char*)(const char*)strInput, NULL, NULL, NULL, NULL); + char result[_MAX_PATH]; + int res = _VerifyPDF("V", (char*)(const char*)strInput, NULL, NULL, NULL, result); return res == 0; }