Patch level : 10.0

Files correlati     : xvaga.dll
Ricompilazione Demo : [ ]
Commento            :
Aggiunto supporto per firma digitale basata su file in formato .pfx


git-svn-id: svn://10.65.10.50/trunk@18753 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2009-04-21 14:57:55 +00:00
parent 2dd2aeb2a3
commit ed62bfd2bc
2 changed files with 55 additions and 25 deletions

View File

@ -3775,7 +3775,7 @@ long xvt_sys_close_siblings(WINDOW win)
BOOLEAN xvt_sys_goto_url(const char* url, const char* action) BOOLEAN xvt_sys_goto_url(const char* url, const char* action)
{ {
#ifdef WIN32 #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); return OsWin32_GotoUrl(url, action);
#endif #endif
return wxLaunchDefaultBrowser(url); 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() BOOLEAN xvt_sys_dongle_server_is_running()
{ {
wxSingleInstanceChecker sic("Authorization"); wxSingleInstanceChecker sic("Authorization");
BOOLEAN ok = sic.IsAnotherRunning(); return sic.IsAnotherRunning();
#ifdef WIN32
if (!ok) // Testo anche il buon vecchio Frontend!
ok = ::GlobalFindAtom("DONGLE_SERVER_ATOM") != 0;
#endif
return ok;
} }
int xvt_sys_get_profile_string(const char* file, const char* paragraph, const char* name, 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] = ""; char defstr[16] = "", str[16] = "";
long value = defval; long value = defval;
if (defval != 0) if (defval != 0)
sprintf(defstr, "%ld", defval); wxSprintf(defstr, "%ld", defval);
if (xvt_sys_get_profile_string(file, paragraph, name, defstr, str, sizeof(str))) if (xvt_sys_get_profile_string(file, paragraph, name, defstr, str, sizeof(str)))
value = atol(str); value = atol(str);
return value; return value;

View File

@ -1,5 +1,6 @@
#include "wxinc.h" #include "wxinc.h"
#include "wx/print.h" #include "wx/print.h"
#include "wx/tokenzr.h"
#include "xvt.h" #include "xvt.h"
@ -1239,7 +1240,7 @@ typedef int (*dllVerifyMethod) (
static dllSignMethod _SignPDF = NULL; static dllSignMethod _SignPDF = NULL;
static dllVerifyMethod _VerifyPDF = NULL; static dllVerifyMethod _VerifyPDF = NULL;
static wxString _strPin; static wxString _strPin, _strDllFile, _strCertificate;
static BOOLEAN xvt_sign_init(BOOL bLoad) static BOOLEAN xvt_sign_init(BOOL bLoad)
{ {
@ -1256,10 +1257,24 @@ static BOOLEAN xvt_sign_init(BOOL bLoad)
_SignPDF = (dllSignMethod)::GetProcAddress(hESigner, "Sign"); _SignPDF = (dllSignMethod)::GetProcAddress(hESigner, "Sign");
_VerifyPDF = (dllVerifyMethod)::GetProcAddress(hESigner, "Verify"); _VerifyPDF = (dllVerifyMethod)::GetProcAddress(hESigner, "Verify");
_strPin = ""; _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; 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"); xvt_dm_post_error("Can't load ESigner.dll");
} }
else else
@ -1267,6 +1282,7 @@ static BOOLEAN xvt_sign_init(BOOL bLoad)
if (hESigner != NULL) if (hESigner != NULL)
{ {
::FreeLibrary(hESigner); ::FreeLibrary(hESigner);
hESigner = NULL;
_SignPDF = NULL; _SignPDF = NULL;
_VerifyPDF = NULL; _VerifyPDF = NULL;
_strPin = ""; _strPin = "";
@ -1288,23 +1304,38 @@ BOOLEAN xvt_sign_file(const char* input_name, char* output_name)
} }
strInput.MakeLower(); strInput.MakeLower();
if ((_strPin.IsEmpty() || _strDllFile.IsEmpty()) && !xvt_sign_start())
return FALSE;
const char* ext = strInput.EndsWith(".pdf") ? ".pdf" : "";
wxString strOutput = output_name; wxString strOutput = output_name;
if (strOutput.IsEmpty()) if (strOutput.IsEmpty())
{ {
strOutput = strInput + ".p7m"; strOutput = strInput.BeforeFirst('.') + ".p7m.pdf";
if (output_name != NULL) if (output_name != NULL)
wxStrncpy(output_name, strOutput, _MAX_PATH); wxStrncpy(output_name, strOutput, _MAX_PATH);
} }
if (_strPin.IsEmpty() && !xvt_sign_start()) int res = 0;
return FALSE; if (_strDllFile.EndsWith(".dll"))
{
const char* ext = strInput.EndsWith(".pdf") ? ".pdf" : ""; res = _SignPDF("S", "T", // "S"ignature with "T"oken or smartcard
int res = _SignPDF("S", "T", // "S"ignature with "T"oken or smartcard (char*)(const char*)strInput, (char*)(const char*)strOutput,
(char*)(const char*)strInput, (char*)(const char*)strOutput, NULL, (char*)ext, NULL, NULL, NULL, (char*)(const char*)_strDllFile,
NULL, (char*)ext, NULL, NULL, NULL, NULL, (char*)(const char*)_strPin, NULL, (char*)(const char*)_strCertificate,
(char*)(const char*)_strPin, NULL, NULL, NULL, NULL, NULL, NULL);
NULL, NULL, 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) if (res == 0)
{ {
@ -1328,11 +1359,16 @@ BOOLEAN xvt_sign_file(const char* input_name, char* output_name)
BOOLEAN xvt_sign_start() BOOLEAN xvt_sign_start()
{ {
BOOLEAN ok = xvt_sign_init(TRUE); BOOLEAN ok = xvt_sign_init(TRUE);
if (ok) if (ok)
{ {
char* pin = _strPin.GetWriteBuf(16); *pin = '\0'; }
if (ok)
{
char pin[16] = "";
xvt_dm_post_string_prompt("PIN", pin, 15); xvt_dm_post_string_prompt("PIN", pin, 15);
_strPin.UngetWriteBuf(); _strPin = pin;
ok = !_strPin.IsEmpty(); ok = !_strPin.IsEmpty();
} }
return ok; return ok;
@ -1360,6 +1396,7 @@ BOOLEAN xvt_sign_test(const char* input_name)
} }
strInput.MakeLower(); 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; return res == 0;
} }