diff options
Diffstat (limited to 'plugins/CryptoPP/src/GPGw')
-rw-r--r-- | plugins/CryptoPP/src/GPGw/gpg_main.cpp | 162 | ||||
-rw-r--r-- | plugins/CryptoPP/src/GPGw/gpgw.h | 1 |
2 files changed, 81 insertions, 82 deletions
diff --git a/plugins/CryptoPP/src/GPGw/gpg_main.cpp b/plugins/CryptoPP/src/GPGw/gpg_main.cpp index 311d7daa7c..f0b96bcf47 100644 --- a/plugins/CryptoPP/src/GPGw/gpg_main.cpp +++ b/plugins/CryptoPP/src/GPGw/gpg_main.cpp @@ -10,8 +10,8 @@ char logfile[fullfilenamesize]; char *txtbeginpgppublickeyblock="-----BEGIN PGP PUBLIC KEY BLOCK-----";
char *txtendpgppublickeyblock="-----END PGP PUBLIC KEY BLOCK-----";
*/
-char *txtbeginpgpmessage="-----BEGIN PGP MESSAGE-----";
-char *txtendpgpmessage="-----END PGP MESSAGE-----";
+char *txtbeginpgpmessage = "-----BEGIN PGP MESSAGE-----";
+char *txtendpgpmessage = "-----END PGP MESSAGE-----";
void __cdecl ErrorMessage(const char *alevel, const char *atext, const char *ahint)
{
@@ -28,10 +28,10 @@ void __cdecl LogMessage(const char *astart, const char *atext, const char *aend) {
FILE *log;
- if(logfile[0]=='\0') return;
+ if (logfile[0] == '\0') return;
- log=fopen(logfile, "a");
- if(log!=NULL)
+ log = fopen(logfile, "a");
+ if (log != NULL)
{
fputs(astart, log);
fputs(atext, log);
@@ -42,8 +42,8 @@ void __cdecl LogMessage(const char *astart, const char *atext, const char *aend) int __cdecl _gpg_init()
{
- GetTempPath(sizeof(temporarydirectory),temporarydirectory);
- logfile[0]='\0';
+ GetTempPath(sizeof(temporarydirectory), temporarydirectory);
+ logfile[0] = '\0';
initPassphrases();
initKeyUserIDs(publickeyuserid);
initKeyUserIDs(secretkeyuserid);
@@ -62,13 +62,13 @@ int __cdecl _gpg_done() int __cdecl _gpg_open_keyrings(LPSTR ExecPath, LPSTR HomePath)
{
- if ( !ExecPath || (!*ExecPath && !ShowSelectExecDlg(ExecPath)) ) {
+ if (!ExecPath || (!*ExecPath && !ShowSelectExecDlg(ExecPath))) {
return 0;
}
- if ( !HomePath || (!*HomePath && !ShowSelectHomeDlg(HomePath)) ) {
+ if (!HomePath || (!*HomePath && !ShowSelectHomeDlg(HomePath))) {
return 0;
}
- if ( !existsFile(ExecPath) ) {
+ if (!existsFile(ExecPath)) {
// ErrorMessage(txtwarning, txtinvalidexecutable, txtverifyoptions);
return 0;
}
@@ -94,15 +94,15 @@ LPSTR __cdecl _gpg_get_error() void __cdecl _gpg_set_log(LPCSTR LogPath)
{
- if(LogPath) strncpy(logfile,LogPath,sizeof(logfile));
- else logfile[0]='\0';
+ if (LogPath) strncpy(logfile, LogPath, sizeof(logfile));
+ else logfile[0] = '\0';
}
void __cdecl _gpg_set_tmp(LPCSTR TmpPath)
{
- if(TmpPath) strncpy(temporarydirectory,TmpPath,sizeof(temporarydirectory));
- else GetTempPath(sizeof(temporarydirectory),temporarydirectory);
+ if (TmpPath) strncpy(temporarydirectory, TmpPath, sizeof(temporarydirectory));
+ else GetTempPath(sizeof(temporarydirectory), temporarydirectory);
}
@@ -110,21 +110,21 @@ LPSTR __cdecl _gpg_get_passphrases() {
size_t i; char *b, x;
- b = (char *) LocalAlloc(LPTR,(keyuseridsize+passphrasesize)*passphrasecount+1); *b = '\0';
+ b = (char *)LocalAlloc(LPTR, (keyuseridsize + passphrasesize)*passphrasecount + 1); *b = '\0';
- for(i=0; i<(size_t)passphrasecount; i++) {
- strcat(b,passphrases[i].keyuserid); strcat(b,"\x01");
- strcat(b,passphrases[i].passphrase); strcat(b,"\x02");
+ for (i = 0; i < (size_t)passphrasecount; i++) {
+ strcat(b, passphrases[i].keyuserid); strcat(b, "\x01");
+ strcat(b, passphrases[i].passphrase); strcat(b, "\x02");
}
// encrypt
- for(i=0; i<strlen(b); i++)
- if ( b[i]>2 ) {
- x = b[i] ^ ( (i&0x7f) ^ 13);
- if ( x>2 ) b[i]=x;
+ for (i = 0; i < strlen(b); i++)
+ if (b[i] > 2) {
+ x = b[i] ^ ((i & 0x7f) ^ 13);
+ if (x > 2) b[i] = x;
}
- return b;
+ return b;
}
@@ -132,25 +132,25 @@ void __cdecl _gpg_set_passphrases(LPCSTR buffer) {
size_t i, l = strlen(buffer); char *t, *p, *b, x;
- if ( !l ) return;
+ if (!l) return;
- b = (char *) LocalAlloc(LPTR,l+1);
+ b = (char *)LocalAlloc(LPTR, l + 1);
strcpy(b, buffer);
// decrypt
- for(i=0; i<strlen(b); i++)
- if ( b[i]>2 ) {
- x = b[i] ^ ( (i&0x7f) ^ 13);
- if ( x>2 ) b[i]=x;
+ for (i = 0; i < strlen(b); i++)
+ if (b[i] > 2) {
+ x = b[i] ^ ((i & 0x7f) ^ 13);
+ if (x > 2) b[i] = x;
}
- while(*b) {
+ while (*b) {
t = strchr(b, '\x02');
- if(t) {
+ if (t) {
*t = '\0';
p = strchr(b, '\x01');
*p = '\0';
- addPassphrase(b, p+1);
+ addPassphrase(b, p + 1);
t++;
}
b = t;
@@ -165,16 +165,16 @@ LPSTR __cdecl _gpg_encrypt(LPCSTR message, LPCSTR keyid) char *encmessage = 0;
gpgResult gpgresult;
- if(strlen(keyid))
+ if (strlen(keyid))
{
memset(buffer, 0, sizeof(buffer));
- gpgresult=gpgEncrypt(buffer, keyid, message);
+ gpgresult = gpgEncrypt(buffer, keyid, message);
- if(gpgresult!=gpgSuccess)
+ if (gpgresult != gpgSuccess)
return 0;
- size_t encmessagelen = strlen(buffer)+1;
- encmessage = (char *) LocalAlloc(LPTR,encmessagelen);
+ size_t encmessagelen = strlen(buffer) + 1;
+ encmessage = (char *)LocalAlloc(LPTR, encmessagelen);
memcpy(encmessage, buffer, encmessagelen);
}
@@ -196,64 +196,64 @@ LPSTR __cdecl _gpg_decrypt(LPCSTR message) const char *begin = strstr(message, txtbeginpgpmessage);
const char *end = strstr(message, txtendpgpmessage);
- if ((begin!=NULL)&&(end!=NULL))
+ if ((begin != NULL) && (end != NULL))
{
strcpy(buffer, "");
- strncat(buffer, begin, end-begin+strlen(txtendpgpmessage));
+ strncat(buffer, begin, end - begin + strlen(txtendpgpmessage));
replace(buffer, "\r", "");
replace(buffer, "\n", txtcrlf);
memset(keyuserid, 0, sizeof(keyuserid));
- gpgresult=gpgDetectUserID(keyuserid, buffer);
- storedpassphrase=NULL;
+ gpgresult = gpgDetectUserID(keyuserid, buffer);
+ storedpassphrase = NULL;
- if(gpgresult!=gpgSuccess)
+ if (gpgresult != gpgSuccess)
{
// ErrorMessage(txtwarning, txtdetectuseridfailed, txtverifyoptions);
strcpy(keyuserid, txtunknownuserid);
- useridvalid=FALSE;
+ useridvalid = FALSE;
}
else
{
- storedpassphrase=getPassphrase(keyuserid);
- useridvalid=TRUE;
+ storedpassphrase = getPassphrase(keyuserid);
+ useridvalid = TRUE;
}
- if(storedpassphrase!=NULL)
+ if (storedpassphrase != NULL)
{
strcpy(passphrase, storedpassphrase);
memset(plaintext, 0, sizeof(plaintext));
- gpgresult=gpgDecrypt(plaintext, buffer, passphrase);
+ gpgresult = gpgDecrypt(plaintext, buffer, passphrase);
}
- else gpgresult=gpgUnknownError;
+ else gpgresult = gpgUnknownError;
- dlgresult=IDOK;
- while((gpgresult!=gpgSuccess)&&(dlgresult!=IDCANCEL))
+ dlgresult = IDOK;
+ while ((gpgresult != gpgSuccess) && (dlgresult != IDCANCEL))
{
- dlgresult=DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_PASSPHRASE), NULL, PassphraseDialogProcedure, (LPARAM)keyuserid);
+ dlgresult = DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_PASSPHRASE), NULL, PassphraseDialogProcedure, (LPARAM)keyuserid);
- if(dlgresult==IDOK)
+ if (dlgresult == IDOK)
{
strcpy(passphrase, dlgpassphrase);
memset(dlgpassphrase, 0, passphrasesize);
strcat(passphrase, txtcrlf);
memset(plaintext, 0, sizeof(plaintext));
- gpgresult=gpgDecrypt(plaintext, buffer, passphrase);
+ gpgresult = gpgDecrypt(plaintext, buffer, passphrase);
}
}
- if(gpgresult==gpgSuccess)
+ if (gpgresult == gpgSuccess)
{
strcpy(buffer, plaintext);
}
- if ( gpgresult==gpgSuccess && useridvalid==TRUE)
+ if (gpgresult == gpgSuccess && useridvalid == TRUE)
addPassphrase(keyuserid, passphrase);
SecureZeroMemory(passphrase, sizeof(passphrase));
- size_t decmessagelen = strlen(buffer)+1;
- decmessage = (char *) LocalAlloc(LPTR,decmessagelen);
+ size_t decmessagelen = strlen(buffer) + 1;
+ decmessage = (char *)LocalAlloc(LPTR, decmessagelen);
memcpy(decmessage, buffer, decmessagelen);
}
@@ -272,32 +272,32 @@ int __cdecl _gpg_select_keyid(HWND hdlg, LPSTR keyid) int dlgresult;
memset(keyid, 0, keyidsize);
- dlgresult=DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_SELECTKEY), hdlg, UserIdDialogProcedure, (LPARAM)keyid);
+ dlgresult = DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SELECTKEY), hdlg, UserIdDialogProcedure, (LPARAM)keyid);
- if(dlgresult!=IDOK)
+ if (dlgresult != IDOK)
memset(keyid, 0, keyidsize);
- return (dlgresult==IDOK);
+ return (dlgresult == IDOK);
}
void noBackslash(LPSTR path)
{
LPSTR ptr = path + strlen(path) - 1;
- if ( *ptr=='\\' ) *ptr = '\0';
+ if (*ptr == '\\') *ptr = '\0';
}
static char buf[MAX_PATH];
-LPSTR GetRegValue(HKEY hKey , LPCSTR szPath, LPCSTR szName)
+LPSTR GetRegValue(HKEY hKey, LPCSTR szPath, LPCSTR szName)
{
- DWORD len=MAX_PATH,type;
- LPSTR ret=0;
+ DWORD len = MAX_PATH, type;
+ LPSTR ret = 0;
- RegOpenKey(hKey,szPath,&hKey);
- if ( RegQueryValueEx(hKey,szName,NULL,&type,(LPBYTE)&buf,&len)==ERROR_SUCCESS ) {
+ RegOpenKey(hKey, szPath, &hKey);
+ if (RegQueryValueEx(hKey, szName, NULL, &type, (LPBYTE)&buf, &len) == ERROR_SUCCESS) {
noBackslash((LPSTR)&buf);
ret = (LPSTR)&buf;
}
@@ -309,9 +309,9 @@ LPSTR GetRegValue(HKEY hKey , LPCSTR szPath, LPCSTR szName) LPSTR GetEnvValue(LPCSTR szName)
{
- LPSTR ret=0;
+ LPSTR ret = 0;
- if ( GetEnvironmentVariable(szName, buf, MAX_PATH) > 0 ) {
+ if (GetEnvironmentVariable(szName, buf, MAX_PATH) > 0) {
noBackslash((LPSTR)&buf);
ret = (LPSTR)&buf;
}
@@ -325,15 +325,15 @@ BOOL ShowSelectExecDlg(LPSTR path) OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
- ofn.lpstrFile = GetRegValue(HKEY_CURRENT_USER,"Software\\GNU\\GnuPG","gpgProgram");
- if ( ofn.lpstrFile && existsFile(ofn.lpstrFile) ) {
+ ofn.lpstrFile = GetRegValue(HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", "gpgProgram");
+ if (ofn.lpstrFile && existsFile(ofn.lpstrFile)) {
strcpy(path, ofn.lpstrFile);
return TRUE;
}
- ofn.lpstrFile = GetRegValue(HKEY_LOCAL_MACHINE,"Software\\GNU\\GnuPG","Install Directory");
- if ( ofn.lpstrFile ) {
- strcat(ofn.lpstrFile,"\\gpg.exe");
- if ( existsFile(ofn.lpstrFile) ) {
+ ofn.lpstrFile = GetRegValue(HKEY_LOCAL_MACHINE, "Software\\GNU\\GnuPG", "Install Directory");
+ if (ofn.lpstrFile) {
+ strcat(ofn.lpstrFile, "\\gpg.exe");
+ if (existsFile(ofn.lpstrFile)) {
strcpy(path, ofn.lpstrFile);
return TRUE;
}
@@ -357,19 +357,19 @@ BOOL ShowSelectHomeDlg(LPSTR path) OPENFILENAME ofn;
ofn.lpstrFile = GetEnvValue("GNUPGHOME");
- if ( ofn.lpstrFile && existsPath(ofn.lpstrFile) ) {
+ if (ofn.lpstrFile && existsPath(ofn.lpstrFile)) {
strcpy(path, ofn.lpstrFile);
return TRUE;
}
- ofn.lpstrFile = GetRegValue(HKEY_CURRENT_USER,"Software\\GNU\\GnuPG","HomeDir");
- if ( ofn.lpstrFile && existsPath(ofn.lpstrFile) ) {
+ ofn.lpstrFile = GetRegValue(HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", "HomeDir");
+ if (ofn.lpstrFile && existsPath(ofn.lpstrFile)) {
strcpy(path, ofn.lpstrFile);
return TRUE;
}
ofn.lpstrFile = GetEnvValue("APPDATA");
- if ( ofn.lpstrFile ) {
- strcat(ofn.lpstrFile,"\\gnupg");
- if ( existsPath(ofn.lpstrFile) ) {
+ if (ofn.lpstrFile) {
+ strcat(ofn.lpstrFile, "\\gnupg");
+ if (existsPath(ofn.lpstrFile)) {
strcpy(path, ofn.lpstrFile);
return TRUE;
}
@@ -385,7 +385,7 @@ BOOL ShowSelectHomeDlg(LPSTR path) if (!GetOpenFileName(&ofn)) return FALSE;
int i;
- for(i = (int)strlen(path);i && path[i]!='\\';i--);
+ for (i = (int)strlen(path); i && path[i] != '\\'; i--);
path[i] = 0;
return TRUE;
diff --git a/plugins/CryptoPP/src/GPGw/gpgw.h b/plugins/CryptoPP/src/GPGw/gpgw.h index 041c79abc5..aefa913d04 100644 --- a/plugins/CryptoPP/src/GPGw/gpgw.h +++ b/plugins/CryptoPP/src/GPGw/gpgw.h @@ -39,7 +39,6 @@ extern char *txtendpgpmessage; extern LPCSTR szModuleName;
extern LPCSTR szVersionStr;
-extern HINSTANCE g_hInst;
#define DLLEXPORT __declspec(dllexport)
|