diff options
38 files changed, 3931 insertions, 0 deletions
diff --git a/GnuPG/contactmenu.cpp b/GnuPG/contactmenu.cpp new file mode 100644 index 0000000..db84b78 --- /dev/null +++ b/GnuPG/contactmenu.cpp @@ -0,0 +1,89 @@ +#include "gnupgplugin.h"
+
+HANDLE useencryption;
+HANDLE sendpublickey;
+
+// service namen der menueintraege
+char *svcuseencryption="GnuPGPlugin/UseEncryption";
+char *svcsendpublickey="GnuPGPlugin/SendPublicKey";
+
+int UpdateContactMenu(WPARAM wparam, LPARAM lparam)
+{
+ DBVARIANT dbv;
+ CLISTMENUITEM cmi;
+ char keyuserid[keyuseridsize];
+ BOOL ischecked;
+
+ int error=DBGetContactSetting(NULL,pluginid,dbkeyuserid,&dbv);
+ if (!error) strcpy(keyuserid,dbv.pszVal);
+ else strcpy(keyuserid,"");
+ DBFreeVariant(&dbv);
+
+ ZeroMemory(&cmi,sizeof(cmi));
+ cmi.cbSize=sizeof(CLISTMENUITEM);
+ cmi.flags=CMIM_FLAGS|CMIF_NOTOFFLINE;
+ if (strlen(keyuserid)==0) cmi.flags|=CMIF_HIDDEN;
+ CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)sendpublickey,(LPARAM)&cmi);
+
+ error=DBGetContactSetting((HANDLE)wparam,pluginid,dbkeyuserid,&dbv);
+ if (!error) strcpy(keyuserid,dbv.pszVal);
+ else strcpy(keyuserid,"");
+ DBFreeVariant(&dbv);
+
+ ZeroMemory(&cmi,sizeof(cmi));
+ cmi.cbSize=sizeof(CLISTMENUITEM);
+ cmi.flags=CMIM_FLAGS|CMIF_HIDDEN;
+
+ if (strlen(keyuserid)!=0)
+ {
+ cmi.flags=CMIM_FLAGS;
+
+ ischecked=DBGetContactSettingByte((HANDLE)wparam,pluginid,dbuseencryption,FALSE);
+ if (ischecked) cmi.flags|=CMIF_CHECKED;
+ }
+
+ CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)useencryption,(LPARAM)&cmi);
+ return 0;
+}
+
+int UseEncryptionService(WPARAM wparam, LPARAM lparam)
+{
+ BOOL ischecked=DBGetContactSettingByte((HANDLE)wparam,pluginid,dbuseencryption,FALSE);
+ DBWriteContactSettingByte((HANDLE)wparam,pluginid,dbuseencryption,(BYTE)!ischecked);
+ return 0;
+}
+
+int SendPublicKeyService(WPARAM wparam, LPARAM lparam)
+{
+ int error;
+ DBVARIANT dbv;
+ char keyuserid[keyuseridsize];
+ char keybuffer[keybuffersize];
+ char keyid[keyidsize];
+ gpgResult gpgresult;
+
+ error=DBGetContactSetting(NULL,pluginid,dbkeyuserid,&dbv);
+ if (!error) strcpy(keyuserid,dbv.pszVal);
+ else strcpy(keyuserid,"");
+ DBFreeVariant(&dbv);
+
+ // sollte nicht auftreten
+ if (strlen(keyuserid)==0)
+ {
+ ErrorMessage(txterror,txtinvaliduserid,txtverifyoptions);
+ return 0;
+ }
+
+ getNextPart(keyid,keyuserid,txtidseparator);
+ ZeroMemory(keybuffer,sizeof(keybuffer));
+ gpgresult=gpgExportPublicKey(keybuffer,keyid);
+
+ if (gpgresult!=gpgSuccess)
+ {
+ ErrorMessage(txterror,txtexportpublickeyfailed,txtverifyoptions);
+ return 0;
+ }
+
+ CallService(MS_MSG_SENDMESSAGE,wparam,(LPARAM)keybuffer);
+ return 0;
+}
diff --git a/GnuPG/contactmenu.h b/GnuPG/contactmenu.h new file mode 100644 index 0000000..94920d1 --- /dev/null +++ b/GnuPG/contactmenu.h @@ -0,0 +1,20 @@ +#ifndef __CONTACTMENU_H__
+#define __CONTACTMENU_H__
+
+#define menuitemposition 10000000
+
+// handles fuer die menueintraege
+extern HANDLE useencryption;
+extern HANDLE sendpublickey;
+
+// service namen der menueintraege
+extern char *svcuseencryption;
+extern char *svcsendpublickey;
+
+// service functions
+int UseEncryptionService(WPARAM wparam, LPARAM lparam);
+int SendPublicKeyService(WPARAM wparam, LPARAM lparam);
+// event function ME_CLIST_PREBUILDCONTACTMENU
+int UpdateContactMenu(WPARAM wparam, LPARAM lparam);
+
+#endif // __CONTACTMENU_H__
\ No newline at end of file diff --git a/GnuPG/docs/copyright.txt b/GnuPG/docs/copyright.txt new file mode 100644 index 0000000..0eed778 --- /dev/null +++ b/GnuPG/docs/copyright.txt @@ -0,0 +1,2 @@ +Copyright (C) 2006-2007 by Zakhar Bardymov
+Copyright (C) 2003 by Harald Treder
diff --git a/GnuPG/docs/gnupg.txt b/GnuPG/docs/gnupg.txt new file mode 100644 index 0000000..ebf6018 --- /dev/null +++ b/GnuPG/docs/gnupg.txt @@ -0,0 +1,38 @@ +GnuPG Plugin for Miranda IM
+===========================
+This GnuPG Plugin enables OpenPGP/GnuPG encryption support for Miranda IM.
+
+Installation:
+
+You should already have GnuPG 1.4.x suite installed and working. The
+suite is available at http://www.gnupg.org.
+
+Since you have GnuPG suite installed and working just copy gnupg.dll
+to Miranda's plugin directory. Then restart Miranda and check "GnuPG"
+and "GnuPG Advanced" forms at Miranda plugins settings. You are supposed
+to be familiar with GnuPG suite to modify the settings.
+
+Recommendations:
+
+0. "Executable" parameter is a full path and name of gnupg.exe executable.
+1. "Home directory" parameter points to GnuPG's home directory, so there
+are supposed to exist all required files with parameters and people's keys.
+2. "Home directory" parameter SHOULD NOT be terminated with backslash "\"
+character.
+3. "Tempdir" parameter SHOULD point to user's private writable directory.
+4. "Log to File" parameter if enabled SHOULD point to writable file
+within writable directory.
+
+More info:
+
+1. See "history.txt" file for changelog.
+2. See Harald Treder's original documentation at "docs/old" subdirectory.
+3. Some installation notes for GnuPG (for Russians):
+ http://www.proton-isc.ru/docs/GnuPG-Windows-Mini-HOWTO.txt
+
+E-mail: zvb(at)irkutsk.ru
+
+Copyright (C) 2006-2007 by Zakhar V. Bardymov
+Copyright (C) 2003 by Harald Treder
+
+END OF FILE
diff --git a/GnuPG/docs/history.txt b/GnuPG/docs/history.txt new file mode 100644 index 0000000..1dfcfa3 --- /dev/null +++ b/GnuPG/docs/history.txt @@ -0,0 +1,37 @@ +History file for GnuPG plugin for Miranda IM
+============================================
+
+GnuPG Plugin Discussion Thread:
+ http://forums.miranda-im.org/showthread.php?t=10656
+
+20071011 -- 0.7.0.2
+
+ 2007100901 - copyright.txt corrected.
+ 2007101001 - Bugfix: MSVCR80.dll is not required by the plugin now.
+
+20071008 -- 0.7.0.1
+
+ 2007100801 - Quick dirty hack to be compatible with Miranda IM 0.7.0.
+ 2007100802 - Plugin version has been changed to 0.7.0.1.
+
+20070331 -- 0.0.1.3
+
+ 2007033001 - Large keyrings should now be comfortable for the plugin.
+ 2007033101 - Temporary directory now may be set via GnuPG Advanced setting.
+
+20070328 -- 0.0.1.2
+
+ 1. Wild pointers are under control now.
+ 3. Memory handling and (re)allocation methods are corrected.
+ 4. No time. No time. C++... Deep code redesign...
+ 5. a2u and u2a from george hazan's JabberG plugin sources...
+ 6. 2007032601 - the code *works* again after the redesign...
+ 7. 2007032801 - the code finally seems working functionally similar to v 0.0.1.1.
+
+20060905 -- 0.0.1.1
+
+ 1. "(Unknown Contact)" entries now removed from Modules -> GnuPG.
+ 2. GnuPG now encrypts under Miranda IM Unicode release.
+ 3. GnuPG Plugin v 0.0.1.x source code branch started.
+
+END OF FILE
\ No newline at end of file diff --git a/GnuPG/docs/license.txt b/GnuPG/docs/license.txt new file mode 100644 index 0000000..31092b1 --- /dev/null +++ b/GnuPG/docs/license.txt @@ -0,0 +1,353 @@ + GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
+
+---------------------------------------
+As a special exception, the authors give permission to modify code,
+dynamically link and distribute the Program in binary form within the QIP
+installer or archive, as long as the following requirements are fullfilled:
+1. The Jabber plugin must be announced and advertized as a separate product,
+clearly stating that the Jabber protocol is supported via a separate plugin
+ported from Miranda IM
+2. Any kind of QIP Infium distribution must include this license agreement
+and original copyrights
+3. The original copyrights must be available within the UI
+4. Each version of the modified code must be freely available
+5. Any changes made in the source code are subject to this license.
diff --git a/GnuPG/docs/moreinfo.txt b/GnuPG/docs/moreinfo.txt new file mode 100644 index 0000000..d4344e2 --- /dev/null +++ b/GnuPG/docs/moreinfo.txt @@ -0,0 +1,3 @@ +
+http://dimgel.ru/texts/miranda-gnupg/
+Very comprehensive explanation for Russians
diff --git a/GnuPG/docs/old/gnupg-history.txt b/GnuPG/docs/old/gnupg-history.txt new file mode 100644 index 0000000..754a4af --- /dev/null +++ b/GnuPG/docs/old/gnupg-history.txt @@ -0,0 +1,25 @@ +0.0.0.4
+
+- fixed buffer overflow of the key parsing routine (serious bug)
+- changed appearance of the passphrase dialog to system modal
+- added logging capability
+
+0.0.0.3
+
+- fixed problems running on smp machines (thanks braini)
+- moved temporary stored files to the plugin directory
+- updated some translations
+
+0.0.0.2
+
+- removed readonly checkbox from the <Select GnuPG Executable> dialog
+- disabled multiple warnings at startup if "gpg.exe" not available
+- redesigned option dialog pages
+- added userdefined plugin tags ("<GnuPG Plugin>", "</GnuPG Plugin>")
+- changed initial value of <Store Passphrases Temporary> to checked
+- added translation support (not tested)
+- some minor changes
+
+0.0.0.1
+
+- initial release
diff --git a/GnuPG/docs/old/gnupg.txt b/GnuPG/docs/old/gnupg.txt new file mode 100644 index 0000000..3510125 --- /dev/null +++ b/GnuPG/docs/old/gnupg.txt @@ -0,0 +1,128 @@ +GnuPG plugin for miranda icq
+version 0.0.0.4
+
+this is still beta code. it probably contains bugs. use it at your own risk.
+
+this plugin adds openpgp support to the miranda icq im. it doesn't encrypt/decrypt anything. this job is done by the openpgp implementation gnupg.
+
+----- requirements -----
+
+windows 2000
+miranda icq 0.1.2.1
+gnupg 1.0.6
+
+(should be run in other configurations)
+
+----- features -----
+
+transparent sending and receiving of encrypted messages
+minimal key management
+
+----- added functionality -----
+
+contact menu:
+
+<Use GnuPG Encryption>
+if checked: all messages to this user will be sent encrypted. (available if you have selected a key for this contact)
+
+<Send GnuPG Key>
+sends your public key to the selected contact. (available if you have specified your key and the user is online)
+
+---
+
+options -> gnupg:
+
+<Executable> and [...]
+full path to the GnuPG executable file "gpg.exe". enter it manually or use the browse button. (required)
+
+<Home Directory>
+your GnuPG home directory. note: don't terminate the string with "\" or "/"! (required)
+
+<Your Key>
+the public key, which belongs to the selected secret key, will be sent, if you choose <Send GnuPG Key>.
+
+<Contact Key>
+use the listview and the dropdown to assign keys to your contacts. the plugin uses the keys, if you send encrypted messages to them.
+
+[Refresh]
+use these buttons to refresh the keylist dropdowns.
+
+---
+
+options -> gnupg advanced (expert options):
+
+<Store Passphrases Temporary>
+if checked: passphrases are stored in memory until the miranda session ends or the user disables this option. the plugin wipes out passphrases as soon as possible. they are never stored on disk. (initially checked)
+
+<Import Public Keys Automatically>
+if checked: the plugin adds received keys automatically to your keyring. if unchecked: you have to do this manually. (initially checked)
+
+messages are tagged, if they were modified by the plugin. you can define your own tags. use "\r", "\n" or "\t" to format the messages.
+
+<Start Tag>
+(initially "<GnuPG Plugin>\r\n")
+
+<End Tag>
+(initially "\r\n</GnuPG Plugin>")
+
+<Commandline Arguments>
+the plugin spawns a GnuPG process for the encryption/decryption operations. sometimes it stores the input/output of the "gpg.exe" in files. sometimes it reads the output (writes the input) directly from (to) the process using pipes.
+
+the plugin generates a commandline for each operation. it will be assembled from <Executable>, <Home Directory> and these commandline strings. you can modify the commandline argument like you did it with the path to the "gpg.exe". but i hope you know what you are doing, if you change these settings.
+
+the strings contain some patterns, which will be replaced during the assembling process. in most cases the commandline have to include these patterns. otherwise the plugin will not work correctly.
+
+%home%: replaced with <Home Directory>
+%keyfile%: file containing a key
+%userid%: the plugin uses key ids to identify GnuPG keys
+%cipherfile%: file with ciphertext
+%plainfile%: plaintext in a file
+
+[Reset]
+restores all commandline strings to their initial values.
+
+---
+
+userinfo -> GnuPG Plugin:
+
+<User ID>, <Key ID>
+key assigned to this contact
+
+<Key Received>
+date/time when you received the last key from this user.
+
+<Key>
+the key you received.
+
+[Import]
+add the key to your keyring.
+
+----- to do -----
+
+fix bugs if necessary
+
+----- known problems -----
+
+<Send GnuPG Key> doesn't work from the send message dialog. can't fix this, because i'm not able to determine if the menu was opened there.
+
+the GnuPG plugin (and with it miranda) will hang up, if you place "\" or "/" at the end of <Home Directory>. (use the taskmanager to kill the running "gpg.exe" process in that case. miranda will return immediately.)
+
+please sign the public keys of your contacts. the plugin can't encrypt messages with unsigned keys. (alternative but not recommended: add "--always-trust" to M->Plugins->GnuPG Advanced->Encrypt.)
+
+----- notes -----
+
+it's not possible to send encrypted icq messages or public keys to offline contacts. they have to be stored on the icq server. but the server can't handle large messages (450? or more characters). encrpyted icq messages und public keys exceed this limit.
+
+----- author -----
+
+contact me for bug reports, suggestions and comments. write an e-mail to <harald.treder@gmx.de>. enjoy reading my english ;).
+
+----- thanks -----
+
+cyreve (richard hughes): developing support
+braini (michael baumann): bug reports und fixes
+
+----- resources -----
+
+http://miranda-icq.sourceforge.net
+http://www.gnupg.org
diff --git a/GnuPG/gnupg-langpack.txt b/GnuPG/gnupg-langpack.txt new file mode 100644 index 0000000..1cef064 --- /dev/null +++ b/GnuPG/gnupg-langpack.txt @@ -0,0 +1,57 @@ +[Please verify your settings in M->Options->Plugins->GnuPG and GnuPG Advanced.]
+[The GnuPG Plugin requires the GnuPG executable \"gpg.exe\".]
+[Could not obtain the GnuPG user id.]
+[The export of your public key failed.]
+[The import of the key failed.]
+[Could not generate a list of the public GnuPG keys.]
+[Could not generate a list of the secret GnuPG keys.]
+[Plugins]
+[GnuPG Plugin]
+[Executable Files]
+[Select GnuPG Executable]
+[GnuPG Plugin - Warning]
+[GnuPG Plugin - Error]
+[<none>]
+[Use GnuPG Encryption]
+[Send GnuPG Key]
+[You received a public key.]
+[You received a public key. It was added to your keyring.]
+[You received an encrypted message. Could not detect the user id of the public key, used to encrypt it.]
+[Unknown User ID]
+[Could not encrypt the message. It wasn't sent.]
+[GnuPG]
+[GnuPG Advanced]
+[Contact]
+[Key and User ID]
+[User ID:]
+[Key ID:]
+[Key received:]
+[&Import]
+[GnuPG Plugin - Passphrase]
+[Ok]
+[Cancel]
+[Enter passphrase for the secret key of user:]
+[User ID]
+[Basic]
+[Executable:]
+[Home Directory:]
+[Key Assignment]
+[Your Key]
+[&Refresh]
+[Contact Key]
+[R&efresh]
+[Options]
+[Store Passphrases Temporary]
+[Import Public Keys Automatically]
+[Tags]
+[Start Tag]
+[End Tag]
+[Commandline Arguments]
+[List Public Keys:]
+[List Secret Keys:]
+[Import Public Key:]
+[Export Public Key:]
+[Detect User ID:]
+[Encrypt:]
+[Decrypt:]
+[&Reset]
diff --git a/GnuPG/gnupg.sln b/GnuPG/gnupg.sln new file mode 100644 index 0000000..7ff7293 --- /dev/null +++ b/GnuPG/gnupg.sln @@ -0,0 +1,20 @@ +
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual C++ Express 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gnupg", "gnupg.vcproj", "{557E83A7-2B96-4088-9CD6-452D4FDC9290}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {557E83A7-2B96-4088-9CD6-452D4FDC9290}.Debug|Win32.ActiveCfg = Debug|Win32
+ {557E83A7-2B96-4088-9CD6-452D4FDC9290}.Debug|Win32.Build.0 = Debug|Win32
+ {557E83A7-2B96-4088-9CD6-452D4FDC9290}.Release|Win32.ActiveCfg = Release|Win32
+ {557E83A7-2B96-4088-9CD6-452D4FDC9290}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/GnuPG/gnupg.vcproj b/GnuPG/gnupg.vcproj new file mode 100644 index 0000000..6f11526 --- /dev/null +++ b/GnuPG/gnupg.vcproj @@ -0,0 +1,351 @@ +<?xml version="1.0" encoding="windows-1251"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8,00"
+ Name="gnupg"
+ ProjectGUID="{557E83A7-2B96-4088-9CD6-452D4FDC9290}"
+ RootNamespace="gnupg"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="0"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\include"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ UsePrecompiledHeader="1"
+ PrecompiledHeaderThrough="gnupgplugin.h"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ ForcedIncludeFiles=""
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="kernel32.lib user32.lib comdlg32.lib advapi32.lib $(NoInherit)"
+ LinkIncremental="2"
+ AdditionalLibraryDirectories=""C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib""
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ UseOfMFC="0"
+ ATLMinimizesCRunTimeLibraryUsage="true"
+ CharacterSet="0"
+ ManagedExtensions="0"
+ WholeProgramOptimization="0"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ UseUnicodeResponseFiles="true"
+ FavorSizeOrSpeed="0"
+ AdditionalIncludeDirectories="..\..\include"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
+ StringPooling="false"
+ ExceptionHandling="1"
+ RuntimeLibrary="0"
+ StructMemberAlignment="0"
+ BufferSecurityCheck="true"
+ UsePrecompiledHeader="1"
+ PrecompiledHeaderThrough="gnupgplugin.h"
+ AssemblerOutput="4"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkLibraryDependencies="true"
+ UseUnicodeResponseFiles="true"
+ AdditionalDependencies="kernel32.lib user32.lib comdlg32.lib advapi32.lib $(NoInherit)"
+ LinkIncremental="0"
+ AdditionalLibraryDirectories=""C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib""
+ GenerateDebugInformation="true"
+ GenerateMapFile="true"
+ MapExports="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ OptimizeForWindows98="1"
+ LinkTimeCodeGeneration="0"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ EmbedManifest="false"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\contactmenu.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\gpg.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\keys.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\language.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\main.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\options.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\passdialog.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\passphrases.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\pipeexec.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\sendrecv.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\tools.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\userinfo.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\contactmenu.h"
+ >
+ </File>
+ <File
+ RelativePath=".\gnupgplugin.h"
+ >
+ </File>
+ <File
+ RelativePath=".\gpg.h"
+ >
+ </File>
+ <File
+ RelativePath=".\keys.h"
+ >
+ </File>
+ <File
+ RelativePath=".\language.h"
+ >
+ </File>
+ <File
+ RelativePath=".\main.h"
+ >
+ </File>
+ <File
+ RelativePath=".\options.h"
+ >
+ </File>
+ <File
+ RelativePath=".\passdialog.h"
+ >
+ </File>
+ <File
+ RelativePath=".\passphrases.h"
+ >
+ </File>
+ <File
+ RelativePath=".\pipeexec.h"
+ >
+ </File>
+ <File
+ RelativePath=".\resource.h"
+ >
+ </File>
+ <File
+ RelativePath=".\sendrecv.h"
+ >
+ </File>
+ <File
+ RelativePath=".\size.h"
+ >
+ </File>
+ <File
+ RelativePath=".\tools.h"
+ >
+ </File>
+ <File
+ RelativePath=".\userinfo.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ <File
+ RelativePath=".\resource.rc"
+ >
+ </File>
+ </Filter>
+ <File
+ RelativePath=".\docs\copyright.txt"
+ >
+ </File>
+ <File
+ RelativePath=".\gnupg-langpack.txt"
+ >
+ </File>
+ <File
+ RelativePath=".\docs\gnupg.txt"
+ >
+ </File>
+ <File
+ RelativePath=".\docs\history.txt"
+ >
+ </File>
+ <File
+ RelativePath=".\docs\license.txt"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/GnuPG/gnupgplugin.h b/GnuPG/gnupgplugin.h new file mode 100644 index 0000000..e27a33d --- /dev/null +++ b/GnuPG/gnupgplugin.h @@ -0,0 +1,68 @@ +// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#ifndef __GNUPGPLUGIN_H__
+#define __GNUPGPLUGIN_H__
+
+// #pragma once
+
+#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
+#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
+#endif
+
+// #include <stdio.h>
+// #include <tchar.h>
+
+// TODO: reference additional headers your program requires here
+
+#include <windows.h>
+#include <windef.h>
+#include <stdio.h>
+#include <time.h>
+#include <commctrl.h>
+
+// miranda includes
+#include "newpluginapi.h"
+#include "m_system.h"
+#include "m_options.h"
+#include "m_langpack.h"
+#include "m_database.h"
+#include "m_userinfo.h"
+#include "m_protocols.h"
+#include "m_protosvc.h"
+#include "m_protomod.h"
+#include "m_clist.h"
+#include "m_message.h"
+
+#ifdef UNICODE
+ typedef LPWSTR LPTSTR;
+ typedef LPCWSTR LPCTSTR;
+#else
+ typedef LPSTR LPTSTR;
+ typedef LPCSTR LPCTSTR;
+#endif
+
+// konstanten aus den resourcen
+#include "resource.h"
+
+// gnupg plugin
+#include "size.h"
+#include "language.h"
+#include "pipeexec.h"
+#include "options.h"
+#include "userinfo.h"
+#include "main.h"
+#include "gpg.h"
+#include "tools.h"
+#include "sendrecv.h"
+#include "contactmenu.h"
+#include "passphrases.h"
+#include "passdialog.h"
+#include "keys.h"
+
+// debug macro
+#define debugout(mtext) MessageBox(NULL,(mtext),"GnuPG Plugin - Debug",MB_OK)
+
+#endif // __GNUPGPLUGIN_H__
diff --git a/GnuPG/gpg.cpp b/GnuPG/gpg.cpp new file mode 100644 index 0000000..c258ea1 --- /dev/null +++ b/GnuPG/gpg.cpp @@ -0,0 +1,386 @@ +#include "gnupgplugin.h"
+#include <stdio.h>
+
+char *txtgpgargslistpublickeys=
+"--homedir \"%home%\""
+" --with-colon" // felder durch : voneinander abgetrennt
+" --list-public-keys"; // oeffentliche schluessel auflisten
+char *txtgpgargslistsecretkeys=
+"--homedir \"%home%\""
+" --with-colon"
+" --list-secret-keys"; // geheime schluessel auflisten
+char *txtgpgargsimportpublickey=
+"--homedir \"%home%\""
+" --import \"%keyfile%\""; // schluessel importieren
+char *txtgpgargsexportpublickey=
+"--homedir \"%home%\""
+" --batch"
+" --yes" // abfragen mit ja beantworten
+" --armor" // ausgabe als text
+" --comment \"\"" // kommentar unterdruecken ("Comment: For info see http://www.gnupg.org")
+" --no-version" // ausgabe der version unterdruecken ("Version: GnuPG v1.0.6 (MingW32)")
+" --export \"%userid%\""; // export des schluessels %userid%
+char *txtgpgargsdetectuserid=
+"--homedir \"%home%\""
+" --batch" // interaktion verhindern (daraus folgt fehler)
+" --decrypt \"%cipherfile%\""; // datei %cipherfile% entschluesseln
+char *txtgpgargsencrypt=
+"--homedir \"%home%\""
+" --batch"
+" --yes" // abfragen mit ja beantworten
+" --armor" // textausgabe
+" --comment \"\"" // kein kommentar hinzufuegen
+" --no-version" // keine versions informationen hinzufuegen
+" --recipient \"%userid%\"" // %userid% des empfaengers
+" --output \"%cipherfile%\"" // ausgabe in datei %cipherfile%
+" --encrypt \"%plainfile%\""; // eingabe kommt aus %plainfile%
+char *txtgpgargsdecrypt=
+"--homedir \"%home%\""
+" --yes" // abfragen mit ja beantworten
+" --passphrase-fd 0" // passphrase von stdin
+" --output \"%plainfile%\"" // ausgabe in datei %plainfile%
+" --decrypt \"%cipherfile%\""; // eingabe kommt aus %cipherfile%
+char *txtgpgtempdir="C:\\TEMP";
+char *txtgpgexecutable="";
+char *txtgpghomedirectory="";
+
+// oeffentliche zeichenketten
+char gpgArgsListPublicKeys[argumentsize];
+char gpgArgsListSecretKeys[argumentsize];
+char gpgArgsImportPublicKey[argumentsize];
+char gpgArgsExportPublicKey[argumentsize];
+char gpgArgsDetectUserID[argumentsize];
+char gpgArgsEncrypt[argumentsize];
+char gpgArgsDecrypt[argumentsize];
+char gpgTempdir[fullfilenamesize];
+char gpgExecutable[fullfilenamesize];
+char gpgHomeDirectory[argumentsize];
+
+// zeichenketten fuer den internen gebrauch
+char *txtpub="pub";
+char *txtsec="sec";
+char *txtcrlf="\r\n";
+char *txtcolon=":";
+char *txtquotationmark="\"";
+char *txtgpgcolon="gpg:";
+char *txtplainfile="%plainfile%";
+char *txtcipherfile="%cipherfile%";
+char *txtuserid="%userid%";
+char *txtkeyfile="%keyfile%";
+char *txthome="%home%";
+char *txtidseparator=", ";
+
+void assembleCommandLine(char *aresult, const char *aexecutable, const char *aargs)
+{
+ strcpy(aresult,aexecutable);
+ strcat(aresult," ");
+ strcat(aresult,aargs);
+}
+
+void detectKeys(char **aresult, char *aoutput, const char *alabel)
+{
+ char line[linesize];
+ char part[linesize];
+ char *linepos;
+ char *partpos;
+ long i;
+
+ if (!aresult)
+ {
+ LogMessage("--- GnuPG.detectKeys: Illegal function call: ","aresult==NULL","\n");
+ return;
+ }
+ if (!*aresult)
+ *aresult=(char*)mir_alloc(1);
+ if (!*aresult)
+ return;
+
+ strcpy(*aresult,"");
+ linepos=aoutput;
+
+ do {
+ linepos=getNextPart(line,linepos,txtcrlf);
+ if (!linepos)
+ break;
+
+ partpos=line;
+ partpos=getNextPart(part,partpos,txtcolon);
+
+ if (strcmp(part,alabel)==0)
+ {
+ for (i=1; i<=10; i++)
+ {
+ partpos=getNextPart(part,partpos,txtcolon);
+
+ switch (i)
+ {
+ case 4:
+ appendText(aresult,part);
+ appendText(aresult,txtidseparator);
+ break;
+ case 9:
+ appendText(aresult,part);
+ appendText(aresult,txtcrlf);
+ break;
+ }
+ }
+ }
+ } while (linepos);
+
+ replace(*aresult, "\\x3a", ":");
+}
+
+gpgResult gpgListPublicKeys(char **aresult)
+{
+ pxResult pxresult;
+ char commandline[commandlinesize];
+ DWORD exitcode;
+ char *output;
+
+ LogMessage("--- GnuPG.gpgListPublicKeys","","\n");
+ output=(char*)mir_alloc(1);
+ strcpy(output,"");
+ assembleCommandLine(commandline,gpgExecutable,gpgArgsListPublicKeys);
+ replace(commandline,txthome,gpgHomeDirectory);
+ pxresult=pxExecute(commandline,"",&output,&exitcode);
+
+ if ((pxresult!=pxSuccess)||(exitcode!=0))
+ {
+ mir_free(output);
+ return gpgExecuteFailed;
+ }
+
+ detectKeys(aresult,output,txtpub);
+
+ mir_free(output);
+ return gpgSuccess;
+}
+
+gpgResult gpgListSecretKeys(char **aresult)
+{
+ pxResult pxresult;
+ char commandline[commandlinesize];
+ DWORD exitcode;
+ char *output;
+
+ LogMessage("--- GnuPG.gpgListSecretKeys","","\n");
+ output=(char*)mir_alloc(1);
+ strcpy(output,"");
+ assembleCommandLine(commandline,gpgExecutable,gpgArgsListSecretKeys);
+ replace(commandline,txthome,gpgHomeDirectory);
+ pxresult=pxExecute(commandline,"",&output,&exitcode);
+
+ if ((pxresult!=pxSuccess)||(exitcode!=0))
+ {
+ mir_free(output);
+ return gpgExecuteFailed;
+ }
+
+ detectKeys(aresult,output,txtsec);
+
+ mir_free(output);
+ return gpgSuccess;
+}
+
+gpgResult gpgImportPublicKey(const char *akey)
+{
+ pxResult pxresult;
+ char commandline[commandlinesize];
+ char filename[fullfilenamesize];
+ DWORD exitcode;
+ char *output;
+
+ LogMessage("--- GnuPG.gpgImportPublicKey","","\n");
+ if (!writeToFile(filename, akey))
+ return gpgWriteToFileFailed;
+
+ output=(char*)mir_alloc(1);
+ strcpy(output,"");
+ assembleCommandLine(commandline,gpgExecutable,gpgArgsImportPublicKey);
+ replace(commandline,txtkeyfile,filename);
+ replace(commandline,txthome,gpgHomeDirectory);
+ pxresult=pxExecute(commandline,"",&output,&exitcode);
+ remove(filename);
+ mir_free(output);
+
+ if ((pxresult!=pxSuccess)||(exitcode!=0))
+ return gpgExecuteFailed;
+
+ return gpgSuccess;
+}
+
+gpgResult gpgExportPublicKey(char *aresult, const char *auserid)
+{
+ pxResult pxresult;
+ char commandline[commandlinesize];
+ DWORD exitcode;
+ char *output;
+
+ LogMessage("--- GnuPG.gpgExportPublicKey","","\n");
+ output=(char*)mir_alloc(1);
+ strcpy(output,"");
+ assembleCommandLine(commandline,gpgExecutable,gpgArgsExportPublicKey);
+ replace(commandline,txtuserid,auserid);
+ replace(commandline,txthome,gpgHomeDirectory);
+ pxresult=pxExecute(commandline,"",&output,&exitcode);
+
+ if ((pxresult!=pxSuccess)||(exitcode!=0))
+ {
+ strcpy(aresult,"");
+ mir_free(output);
+ return gpgExecuteFailed;
+ }
+
+ strcpy(aresult,output);
+
+ mir_free(output);
+ return gpgSuccess;
+}
+
+gpgResult gpgDetectUserID(char *aresult, const char *aciphertext)
+{
+ pxResult pxresult;
+ char commandline[commandlinesize];
+ char filename[fullfilenamesize];
+ char line[linesize];
+ char part[linesize];
+ char *linepos;
+ char *partpos;
+ DWORD exitcode;
+ char *output;
+
+ LogMessage("--- GnuPG.gpgDetectUserID","","\n");
+ strcpy(aresult,"");
+
+ if (!writeToFile(filename,aciphertext))
+ return gpgWriteToFileFailed;
+
+ output=(char*)mir_alloc(1);
+ strcpy(output,"");
+ assembleCommandLine(commandline,gpgExecutable,gpgArgsDetectUserID);
+ replace(commandline,txtcipherfile,filename);
+ replace(commandline,txthome,gpgHomeDirectory);
+ pxresult=pxExecute(commandline,"",&output,&exitcode);
+ remove(filename);
+
+ if ((pxresult!=pxSuccess)&&(pxresult!=pxSuccessExitCodeInvalid))
+ {
+ mir_free(output);
+ return gpgExecuteFailed;
+ }
+
+ linepos=output;
+
+ do
+ {
+ linepos=getNextPart(line,linepos,txtcrlf);
+ if (strncmp(line,txtgpgcolon,strlen(txtgpgcolon))!=0)
+ {
+ partpos=line;
+ partpos=getNextPart(part,partpos,txtquotationmark);
+ getNextPart(part,partpos,txtquotationmark);
+ linepos=NULL;
+ }
+ } while (linepos!=NULL);
+
+ strcpy(aresult,part);
+
+ mir_free(output);
+ return gpgSuccess;
+}
+
+gpgResult gpgEncrypt(char **aresult, const char *auserid, const char *aplaintext)
+ // *aresult MUST be NULL of mir_alloc'ated memory block
+ // on return: if *aresult!=NULL => caller MUST later mir_free it by hands
+ // if isUnicode is true, there works "unicode" mode...
+ // i.e. aplaintext is treated as asciiz+ucs2,
+ // it's length is (strlen(aplaintext)+1)*(sizeof(wchar_t)+1)
+ // we encrypt this asciiz+ucs2 mix to asciiz cyphertext...
+ // the asciiz cyphertext we must convert to asciiz+ucs2...
+ // so, *aresult will be our asciiz+ucs2 cyphertext.
+{
+ char commandline[commandlinesize];
+ char plainfile[fullfilenamesize];
+ char cipherfile[fullfilenamesize];
+ DWORD exitcode;
+ char *output;
+
+ if (!aresult)
+ return gpgUnknownError;
+
+ LogMessage("--- GnuPG.gpgEncrypt","","\n");
+
+ if (!writeToFile(plainfile,aplaintext))
+ return gpgWriteToFileFailed;
+
+ output=(char*)mir_alloc(1);
+ strcpy(output,"");
+ getTemporaryFileName(cipherfile);
+ assembleCommandLine(commandline,gpgExecutable,gpgArgsEncrypt);
+ replace(commandline,txtcipherfile,cipherfile);
+ replace(commandline,txtplainfile,plainfile);
+ replace(commandline,txtuserid,auserid);
+ replace(commandline,txthome,gpgHomeDirectory);
+ pxResult pxresult=pxExecute(commandline,"",&output,&exitcode);
+ remove(plainfile);
+
+ if (pxresult!=pxSuccess || exitcode!=0)
+ {
+ mir_free(output);
+ return gpgExecuteFailed;
+ }
+
+ if (!readFromFile(aresult,cipherfile))
+ {
+ mir_free(output);
+ return gpgReadFromFileFailed;
+ }
+
+ remove(cipherfile);
+ mir_free(output);
+
+ return gpgSuccess;
+}
+
+gpgResult gpgDecrypt(char **aresult, const char *aciphertext, const char *apassphrase)
+ // *aresult MUST be NULL of mir_alloc'ated memory block
+ // on return: if *aresult!=NULL => caller MUST later mir_free it by hands
+{
+ pxResult pxresult;
+ char commandline[commandlinesize];
+ char plainfile[fullfilenamesize];
+ char cipherfile[fullfilenamesize];
+ char passphrase[linesize];
+ DWORD exitcode;
+ char *output;
+ BOOL rc;
+
+ LogMessage("--- GnuPG.gpgDecrypt","","\n");
+
+ if (!aresult)
+ return gpgUnknownError;
+
+ if (!writeToFile(cipherfile,aciphertext))
+ return gpgWriteToFileFailed;
+
+ output=(char*)mir_alloc(1);
+ strcpy(output,"");
+ getTemporaryFileName(plainfile);
+ assembleCommandLine(commandline,gpgExecutable,gpgArgsDecrypt);
+ replace(commandline,txtcipherfile,cipherfile);
+ replace(commandline,txtplainfile,plainfile);
+ replace(commandline,txthome,gpgHomeDirectory);
+ strcpy(passphrase,apassphrase);
+ strcat(passphrase,txtcrlf);
+
+ pxresult=pxExecute(commandline,passphrase,&output,&exitcode);
+ remove(cipherfile);
+ mir_free(output);
+
+ if (pxresult!=pxSuccess || exitcode!=0)
+ return gpgExecuteFailed;
+
+ rc=readFromFile(aresult,plainfile);
+ remove(plainfile);
+ return rc?gpgSuccess:gpgReadFromFileFailed;
+}
diff --git a/GnuPG/gpg.h b/GnuPG/gpg.h new file mode 100644 index 0000000..8347b4f --- /dev/null +++ b/GnuPG/gpg.h @@ -0,0 +1,49 @@ +#ifndef __GPG_H__
+#define __GPG_H__
+
+typedef enum {
+ gpgSuccess,
+ gpgUnknownError,
+ gpgWriteToFileFailed,
+ gpgReadFromFileFailed,
+ gpgExecuteFailed
+}
+gpgResult;
+
+// konstanten fuer die initialisierung der parameter
+extern char *txtgpgargslistpublickeys;
+extern char *txtgpgargslistsecretkeys;
+extern char *txtgpgargsimportpublickey;
+extern char *txtgpgargsexportpublickey;
+extern char *txtgpgargsdetectuserid;
+extern char *txtgpgargsencrypt;
+extern char *txtgpgargsdecrypt;
+extern char *txtgpgtempdir;
+extern char *txtgpgexecutable;
+extern char *txtgpghomedirectory;
+
+// sonstige konstanten
+extern char *txtcrlf;
+extern char *txtidseparator;
+
+// zeichenketten
+extern char gpgArgsListPublicKeys[];
+extern char gpgArgsListSecretKeys[];
+extern char gpgArgsImportPublicKey[];
+extern char gpgArgsExportPublicKey[];
+extern char gpgArgsDetectUserID[];
+extern char gpgArgsEncrypt[];
+extern char gpgArgsDecrypt[];
+extern char gpgTempdir[];
+extern char gpgExecutable[];
+extern char gpgHomeDirectory[];
+
+gpgResult gpgListPublicKeys(char **aresult);
+gpgResult gpgListSecretKeys(char **aresult);
+gpgResult gpgImportPublicKey(const char *akey);
+gpgResult gpgExportPublicKey(char *aresult, const char *auserid);
+gpgResult gpgDetectUserID(char *aresult, const char *aciphertext);
+gpgResult gpgEncrypt(char **aresult, const char *auserid, const char *aplaintext);
+gpgResult gpgDecrypt(char **aresult, const char *aciphertext, const char *apassphrase);
+
+#endif // __GPG_H__
diff --git a/GnuPG/keys.cpp b/GnuPG/keys.cpp new file mode 100644 index 0000000..d944927 --- /dev/null +++ b/GnuPG/keys.cpp @@ -0,0 +1,62 @@ +#include "gnupgplugin.h"
+
+typedef char tkeyuserid[keyuseridsize];
+
+tkeyuserid *keyuserids[2];
+int keyuseridcount[2];
+
+void initKeyUserIDs(const int atype)
+{
+ keyuseridcount[atype]=0;
+ keyuserids[atype]=NULL;
+}
+
+void updateKeyUserIDs(const int atype)
+{
+ char *pos;
+ gpgResult gpgresult;
+ char keyuserid[keyuseridsize];
+ char *buffer=NULL;
+
+ releaseKeyUserIDs(atype);
+ initKeyUserIDs(atype);
+
+ gpgresult=(atype==publickeyuserid)
+ ?gpgListPublicKeys(&buffer)
+ :gpgListSecretKeys(&buffer);
+
+ if (gpgresult!=gpgSuccess)
+ {
+ ErrorMessage(txterror,
+ (atype==publickeyuserid
+ ?txtlistpublickeysfailed
+ :txtlistsecretkeysfailed),
+ txtverifyoptions);
+ return;
+ }
+
+ for (pos=buffer; (pos=getNextPart(keyuserid,pos,txtcrlf)); )
+ {
+ keyuseridcount[atype]++;
+ keyuserids[atype]=(char(*)[512])
+ mir_realloc(keyuserids[atype],sizeof(tkeyuserid)*keyuseridcount[atype]);
+ strcpy(keyuserids[atype][keyuseridcount[atype]-1],keyuserid);
+ }
+
+ fnFALSE(&buffer);
+}
+
+void releaseKeyUserIDs(const int atype)
+{
+ mir_free(keyuserids[atype]);
+}
+
+char *getKeyUserID(const int atype, const int aindex)
+{
+ return keyuserids[atype][aindex];
+}
+
+int getKeyUserIDCount(const int atype)
+{
+ return keyuseridcount[atype];
+}
diff --git a/GnuPG/keys.h b/GnuPG/keys.h new file mode 100644 index 0000000..131c6dc --- /dev/null +++ b/GnuPG/keys.h @@ -0,0 +1,13 @@ +#ifndef __KEYS_H__
+#define __KEYS_H__
+
+#define publickeyuserid 0
+#define secretkeyuserid 1
+
+void initKeyUserIDs(const int atype);
+void updateKeyUserIDs(const int atype);
+void releaseKeyUserIDs(const int atype);
+char *getKeyUserID(const int atype, const int aindex);
+int getKeyUserIDCount(const int atype);
+
+#endif // __KEYS_H__
\ No newline at end of file diff --git a/GnuPG/language.cpp b/GnuPG/language.cpp new file mode 100644 index 0000000..be22500 --- /dev/null +++ b/GnuPG/language.cpp @@ -0,0 +1,27 @@ +#include "gnupgplugin.h"
+
+char *txtverifyoptions="Please verify your settings in M->Options->Plugins->GnuPG and GnuPG Advanced."; /*lang*/
+char *txtinvalidexecutable="The GnuPG Plugin requires the GnuPG executable \"gpg.exe\"."; /*lang*/
+char *txtinvaliduserid="Could not obtain the GnuPG user id."; /*lang*/
+char *txtexportpublickeyfailed="The export of your public key failed."; /*lang*/
+char *txtimportpublickeyfailed="The import of the key failed."; /*lang*/
+char *txtlistpublickeysfailed="Could not generate a list of the public GnuPG keys."; /*lang*/
+char *txtlistsecretkeysfailed="Could not generate a list of the secret GnuPG keys."; /*lang*/
+char *txtplugins="Plugins"; /*lang*/
+char *txtgnupgplugin="GnuPG Plugin"; /*lang*/
+char *txtexecutablefiles="Executable Files"; /*lang*/
+char *txtselectexecutable="Select GnuPG Executable"; /*lang*/
+char *txtwarning="GnuPG Plugin - Warning"; /*lang*/
+char *txterror="GnuPG Plugin - Error"; /*lang*/
+char *txtnone="<none>"; /*lang*/
+char *txtuseencryption="Use GnuPG Encryption"; /*lang*/
+char *txtsendpublickey="Send GnuPG Key"; /*lang*/
+char *txtpublickeyreceived="You received a public key."; /*lang*/
+char *txtpublickeyreceivedstored="You received a public key. It was added to your keyring."; /*lang*/
+char *txtdetectuseridfailed="You received an encrypted message. Could not detect the user id of the public key, used to encrypt it."; /*lang*/
+char *txtunknownuserid="Unknown User ID"; /*lang*/
+char *txtencryptfailed="Could not encrypt the message. It wasn't sent."; /*lang*/
+char *txtoptions="GnuPG"; /*lang*/
+char *txtexpertoptions="GnuPG Advanced"; /*lang*/
+
+
diff --git a/GnuPG/language.h b/GnuPG/language.h new file mode 100644 index 0000000..c25deae --- /dev/null +++ b/GnuPG/language.h @@ -0,0 +1,29 @@ +#ifndef __TEXT_H__
+#define __TEXT_H__
+
+// textkonstanten, die uebersetzt werden muessen
+extern char *txtverifyoptions;
+extern char *txtinvalidexecutable;
+extern char *txtinvaliduserid;
+extern char *txtexportpublickeyfailed;
+extern char *txtimportpublickeyfailed;
+extern char *txtlistpublickeysfailed;
+extern char *txtlistsecretkeysfailed;
+extern char *txtplugins;
+extern char *txtgnupgplugin;
+extern char *txtexecutablefiles;
+extern char *txtselectexecutable;
+extern char *txtwarning;
+extern char *txterror;
+extern char *txtnone;
+extern char *txtuseencryption;
+extern char *txtsendpublickey;
+extern char *txtpublickeyreceived;
+extern char *txtpublickeyreceivedstored;
+extern char *txtdetectuseridfailed;
+extern char *txtunknownuserid;
+extern char *txtencryptfailed;
+extern char *txtoptions;
+extern char *txtexpertoptions;
+
+#endif // __TEXT_H__
\ No newline at end of file diff --git a/GnuPG/main.cpp b/GnuPG/main.cpp new file mode 100644 index 0000000..130552d --- /dev/null +++ b/GnuPG/main.cpp @@ -0,0 +1,230 @@ +// main.cpp : main module of the plugin
+//
+
+#include "gnupgplugin.h"
+
+HINSTANCE dllinstance;
+PLUGINLINK *pluginLink;
+PLUGININFO pluginInfo = {
+ sizeof(PLUGININFO),
+ "GnuPG Plugin (Ansi/Unicode)",
+ 0x00070002, // version dword
+ "OpenPGP/GnuPG Plugin v0.7.0.2 by Zakhar V. Bardymov ("__DATE__")\n"
+ " based on GnuPG Plugin v0.0.0.4 by Harald Treder",
+ "Harald Treder, Zakhar V. Bardymov",
+ "harald.treder(at)gmx.de, zvb(at)irkutsk.ru",
+ "GPLv2",
+ "http://www.miranda-im.org",
+ UNICODE_AWARE, // right now the only flag, UNICODE_AWARE, is recognized here
+ 0 // doesn't replace anything built-in
+};
+
+struct MM_INTERFACE mmi;
+struct LIST_INTERFACE li;
+struct UTF8_INTERFACE utfi;
+
+UINT storepassphraseschecked;
+UINT autoimportpublickeyschecked;
+UINT loggingonchecked;
+char starttag[plugintagsize];
+char endtag[plugintagsize];
+char *pluginid="GnuPGPlugin";
+char logfile[fullfilenamesize];
+
+// zeichenketten zur identifizierung von werten in der datenbank
+char *dbexecutable="Executable";
+char *dbhomedirectory="HomeDirectory";
+char *dbstorepassphrases="StorePassphrases";
+char *dbautoimportpublickeys="AutoImportPublicKeys";
+char *dblistpublickeys="ListPublicKeys";
+char *dblistsecretkeys="ListSecretKeys";
+char *dbimportpublickey="ImportPublicKey";
+char *dbexportpublickey="ExportPublicKey";
+char *dbdetectuserid="DetectUserID";
+char *dbencrypt="Encrypt";
+char *dbdecrypt="Decrypt";
+char *dbtempdir="Tempdir";
+char *dbkeyuserid="KeyUserID";
+char *dbkey="Key";
+char *dbkeymodified="KeyModified";
+char *dbuseencryption="UseEncryption";
+char *dbstarttag="StartTag";
+char *dbendtag="EndTag";
+char *dbloggingon="LoggingOn";
+char *dblogfile="LogFile";
+
+void ErrorMessage(const char *alevel, const char *atext, const char *ahint)
+{
+ char buf[errormessagesize];
+ strcpy(buf,Translate(atext));
+ strcat(buf," ");
+ strcat(buf,Translate(ahint));
+ MessageBoxA(NULL,buf,Translate(alevel),MB_OK);
+}
+
+void LogMessage(const char *astart, const char *atext, const char *aend)
+{
+ if (loggingonchecked!=BST_CHECKED)
+ return;
+ FILE *log=fopen(logfile,"a");
+ if (log)
+ {
+ fputs(astart,log);
+ fputs(atext,log);
+ fputs(aend,log);
+ fclose(log);
+ }
+}
+
+// DllMain
+extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+ dllinstance=hinstDLL;
+ return TRUE;
+}
+
+int AddContact(WPARAM wparam, LPARAM lparam)
+{
+ CallService(MS_PROTO_ADDTOCONTACT,wparam,(LPARAM)pluginid);
+ return 0;
+}
+
+void getcontactsetting(char *ostr, const char *key, const char *defstr)
+ // zvb: Created to be used in MainInit.
+{
+ DBVARIANT dbv;
+ int err=DBGetContactSetting(NULL,pluginid,key,&dbv);
+ strcpy(ostr,(!err?dbv.pszVal:defstr));
+ DBFreeVariant(&dbv);
+}
+
+int MainInit(WPARAM wparam, LPARAM lparam)
+{
+ PROTOCOLDESCRIPTOR pd;
+ CLISTMENUITEM cmi;
+ HANDLE hcontact;
+
+ // zvb: slightly more readable now:
+ getcontactsetting(gpgExecutable,dbexecutable,txtgpgexecutable);
+ getcontactsetting(gpgHomeDirectory,dbhomedirectory,txtgpghomedirectory);
+ getcontactsetting(gpgArgsListPublicKeys,dblistpublickeys,txtgpgargslistpublickeys);
+ getcontactsetting(gpgArgsListSecretKeys,dblistsecretkeys,txtgpgargslistsecretkeys);
+ getcontactsetting(gpgArgsImportPublicKey,dbimportpublickey,txtgpgargsimportpublickey);
+ getcontactsetting(gpgArgsExportPublicKey,dbexportpublickey,txtgpgargsexportpublickey);
+ getcontactsetting(gpgArgsDetectUserID,dbdetectuserid,txtgpgargsdetectuserid);
+ getcontactsetting(gpgArgsEncrypt,dbencrypt,txtgpgargsencrypt);
+ getcontactsetting(gpgArgsDecrypt,dbdecrypt,txtgpgargsdecrypt);
+ getcontactsetting(gpgTempdir,dbtempdir,txtgpgtempdir);
+
+ getcontactsetting(starttag,dbstarttag,"<GnuPG Plugin>\r\n");
+ getcontactsetting(endtag,dbendtag,"\r\n</GnuPG Plugin>");
+
+ getcontactsetting(logfile,dblogfile,"c:\\miranda-gnupg.log");
+ loggingonchecked=DBGetContactSettingDword(NULL,pluginid,dbloggingon,BST_UNCHECKED);
+
+ storepassphraseschecked
+ =DBGetContactSettingDword(NULL,pluginid,dbstorepassphrases,BST_CHECKED);
+ autoimportpublickeyschecked
+ =DBGetContactSettingDword(NULL,pluginid,dbautoimportpublickeys,BST_CHECKED);
+
+ if (existsFile(gpgExecutable))
+ {
+ updateKeyUserIDs(publickeyuserid);
+ updateKeyUserIDs(secretkeyuserid);
+ }
+ else
+ ErrorMessage(txtwarning,txtinvalidexecutable,txtverifyoptions);
+
+ HookEvent(ME_OPT_INITIALISE,OptionsInit);
+ HookEvent(ME_USERINFO_INITIALISE,UserInfoInit);
+
+ // register encryption protocol
+ ZeroMemory(&pd,sizeof(pd));
+ pd.cbSize=sizeof(PROTOCOLDESCRIPTOR);
+ pd.szName=pluginid;
+ pd.type=PROTOTYPE_ENCRYPTION;
+ CallService(MS_PROTO_REGISTERMODULE,0,(LPARAM)&pd);
+
+ // send/receive functions registration
+ CreateProtoServiceFunction(pluginid,PSR_MESSAGE,RecvMsgSvc);
+ CreateProtoServiceFunction(pluginid,PSS_MESSAGE,SendMsgSvc);
+ // zvb: let the Unicode calls be served by them too.
+ CreateProtoServiceFunction(pluginid,PSR_MESSAGE"W",RecvMsgSvc);
+ CreateProtoServiceFunction(pluginid,PSS_MESSAGE"W",SendMsgSvc);
+
+ // add the protocol to all contacts found in DB
+ for (
+ hcontact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0);
+ hcontact;
+ hcontact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hcontact,0)
+ )
+ if (!CallService(MS_PROTO_ISPROTOONCONTACT,(WPARAM)hcontact,(LPARAM)pluginid))
+ CallService(MS_PROTO_ADDTOCONTACT,(WPARAM)hcontact,(LPARAM)pluginid);
+
+ // kontakte zur laufzeit in die protokoll kette einhaengen
+ HookEvent(ME_DB_CONTACT_ADDED,AddContact);
+
+ CreateServiceFunction(svcuseencryption,UseEncryptionService);
+ CreateServiceFunction(svcsendpublickey,SendPublicKeyService);
+
+ // set contact menu items
+ ZeroMemory(&cmi,sizeof(cmi));
+ cmi.cbSize=sizeof(CLISTMENUITEM);
+ // encryption menuitem
+ cmi.pszName=Translate(txtuseencryption);
+ cmi.position=menuitemposition;
+ cmi.pszService=svcuseencryption;
+ useencryption=(HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&cmi);
+ // sendpublickey menuitem
+ cmi.pszName=Translate(txtsendpublickey);
+ cmi.position=menuitemposition+1;
+ cmi.pszService=svcsendpublickey;
+ sendpublickey=(HANDLE)CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&cmi);
+ // hook event fuer menumodifikation
+ HookEvent(ME_CLIST_PREBUILDCONTACTMENU,UpdateContactMenu);
+
+ return 0;
+}
+
+// MirandaPluginInfo
+extern "C" __declspec(dllexport) PLUGININFO *MirandaPluginInfo(DWORD mirandaVersion)
+{
+ /*
+ if (mirandaVersion<PLUGIN_MAKE_VERSION(0,7,0,0))
+ {
+ MessageBoxA(NULL,
+ "Failure: GnuPG Plugin requires Miranda IM 0.7.0.0 or later.",
+ "GnuPG Plugin for Miranda IM",MB_OK|MB_ICONWARNING|MB_SETFOREGROUND|MB_TOPMOST);
+ return NULL;
+ }
+ */
+ return &pluginInfo;
+}
+
+// Load
+extern "C" __declspec(dllexport) int Load(PLUGINLINK *link)
+{
+ pluginLink=link;
+
+ // set the memory, lists & utf8 managers
+ mir_getMMI(&mmi);
+ mir_getLI(&li);
+ mir_getUTFI(&utfi);
+
+ HookEvent(ME_SYSTEM_MODULESLOADED,MainInit);
+
+ initPassphrases();
+ initKeyUserIDs(publickeyuserid);
+ initKeyUserIDs(secretkeyuserid);
+
+ return 0;
+}
+
+// Unload
+extern "C" __declspec(dllexport) int Unload(void)
+{
+ releaseKeyUserIDs(secretkeyuserid);
+ releaseKeyUserIDs(publickeyuserid);
+ releasePassphrases();
+ return 0;
+}
diff --git a/GnuPG/main.h b/GnuPG/main.h new file mode 100644 index 0000000..1e1a6cf --- /dev/null +++ b/GnuPG/main.h @@ -0,0 +1,40 @@ +#ifndef __MAIN_H__
+#define __MAIN_H__
+
+// zeichenketten zur identifizierung von werten in der datenbank
+extern char *dbexecutable;
+extern char *dbhomedirectory;
+extern char *dbstorepassphrases;
+extern char *dbautoimportpublickeys;
+extern char *dblistpublickeys;
+extern char *dblistsecretkeys;
+extern char *dbimportpublickey;
+extern char *dbexportpublickey;
+extern char *dbdetectuserid;
+extern char *dbencrypt;
+extern char *dbdecrypt;
+extern char *dbtempdir;
+extern char *dbkeyuserid;
+extern char *dbkey;
+extern char *dbkeymodified;
+extern char *dbuseencryption;
+extern char *dbstarttag;
+extern char *dbendtag;
+extern char *dbloggingon;
+extern char *dblogfile;
+
+// main global variables
+extern HINSTANCE dllinstance;
+extern PLUGINLINK *pluginLink;
+extern char *pluginid;
+extern UINT storepassphraseschecked;
+extern UINT autoimportpublickeyschecked;
+extern UINT loggingonchecked;
+extern char starttag[plugintagsize];
+extern char endtag[plugintagsize];
+extern char logfile[fullfilenamesize];
+
+void ErrorMessage(const char *alevel, const char *atext, const char *ahint);
+void LogMessage(const char *astart, const char *atext, const char *aend);
+
+#endif // __MAIN_H__
\ No newline at end of file diff --git a/GnuPG/options.cpp b/GnuPG/options.cpp new file mode 100644 index 0000000..5d4d18f --- /dev/null +++ b/GnuPG/options.cpp @@ -0,0 +1,390 @@ +#include "gnupgplugin.h"
+
+char *column[]={"Contact","Key and User ID"}; /*lang*/
+int columnwidth[]={150, 368};
+
+int OptionsInit(WPARAM wparam, LPARAM lparam)
+{
+ OPTIONSDIALOGPAGE odp;
+
+ ZeroMemory(&odp,sizeof(odp));
+ odp.cbSize=sizeof(odp);
+ odp.hInstance=dllinstance;
+ odp.pszGroup=Translate(txtplugins);
+ odp.pszTitle=Translate(txtoptions);
+ odp.pszTemplate=(char*)MAKEINTRESOURCE(IDD_OPTIONS_DLG);
+ odp.pfnDlgProc=OptionsDialogProcedure;
+ odp.expertOnlyControls=NULL;
+ odp.nExpertOnlyControls=0;
+ odp.flags=ODPF_BOLDGROUPS;
+ CallService(MS_OPT_ADDPAGE,wparam,(LPARAM)&odp);
+
+ ZeroMemory(&odp,sizeof(odp));
+ odp.cbSize=sizeof(odp);
+ odp.hInstance=dllinstance;
+ odp.pszGroup=Translate(txtplugins);
+ odp.pszTitle=Translate(txtexpertoptions);
+ odp.pszTemplate=(char*)MAKEINTRESOURCE(IDD_EXPERTOPTIONS_DLG);
+ odp.pfnDlgProc=ExpertOptionsDialogProcedure;
+ odp.expertOnlyControls=NULL;
+ odp.nExpertOnlyControls=0;
+ odp.flags=ODPF_BOLDGROUPS|ODPF_EXPERTONLY;
+ CallService(MS_OPT_ADDPAGE,wparam,(LPARAM)&odp);
+
+ return 0;
+}
+
+void fillKeyDropdown(HWND hdlg, int atype)
+{
+ int index;
+ HWND hwnd;
+
+ if (atype==publickeyuserid) hwnd=GetDlgItem(hdlg,IDC_PUBLICKEY_DDOWN);
+ else hwnd=GetDlgItem(hdlg,IDC_SECRETKEY_DDOWN);
+
+ SendMessage(hwnd,CB_RESETCONTENT,0,0);
+ SendMessage(hwnd,CB_ADDSTRING,0,(LPARAM)Translate(txtnone));
+ SendMessage(hwnd,CB_SELECTSTRING,-1,(LPARAM)Translate(txtnone));
+
+ for (index=0; index<getKeyUserIDCount(atype); index++)
+ SendMessage(hwnd,CB_ADDSTRING,0,(LPARAM)getKeyUserID(atype,index));
+}
+
+void synchronizePublicKeyUserID(HWND hdlg)
+{
+ int item;
+ HWND hwnd;
+ char keyuserid[keyuseridsize];
+ LRESULT result;
+
+ hwnd=GetDlgItem(hdlg,IDC_KEY_LIST);
+ item=ListView_GetNextItem(hwnd,-1,LVNI_SELECTED);
+ ListView_GetItemText(hwnd,item,1,(LPTSTR)keyuserid,sizeof(keyuserid));
+
+ hwnd=GetDlgItem(hdlg,IDC_PUBLICKEY_DDOWN);
+ result=SendMessage(hwnd,CB_SELECTSTRING,-1,(LPARAM)keyuserid);
+ if (result==CB_ERR)
+ SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
+}
+
+void setSecretKeyUserID(HWND hdlg)
+{
+ int error;
+ DBVARIANT dbv;
+ char keyuserid[keyuseridsize];
+ HWND hwnd;
+
+ error=DBGetContactSetting(NULL,pluginid,dbkeyuserid,&dbv);
+ if(! error) strcpy(keyuserid,dbv.pszVal);
+ else strcpy(keyuserid,"");
+ DBFreeVariant(&dbv);
+
+ if(strlen(keyuserid)==0) strcpy(keyuserid, Translate(txtnone));
+
+ hwnd=GetDlgItem(hdlg,IDC_SECRETKEY_DDOWN);
+ error=SendMessage(hwnd,CB_SELECTSTRING,-1,(LPARAM)keyuserid);
+ if (error==CB_ERR)
+ SendMessage(GetParent(hdlg),PSM_CHANGED,0,0);
+}
+
+BOOL CALLBACK OptionsDialogProcedure(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ char *pos;
+ char gpgexe[256];
+ char filter[128];
+ OPENFILENAME ofn;
+ HWND hwnd;
+ int index, error, item, count;
+ LV_COLUMN lvc;
+ LV_ITEM lvi;
+ HANDLE hcontact;
+ DBVARIANT dbv;
+ char keyuserid[keyuseridsize];
+ NM_LISTVIEW *nmlv;
+
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hdlg);
+ // dialog aktualisieren
+ SetDlgItemText(hdlg,IDC_GPGEXECUTABLE_EDIT,(LPCTSTR)gpgExecutable);
+ SetDlgItemText(hdlg,IDC_GPGHOME_EDIT,(LPCTSTR)gpgHomeDirectory);
+
+ // keys
+ fillKeyDropdown(hdlg, publickeyuserid);
+ fillKeyDropdown(hdlg, secretkeyuserid);
+ setSecretKeyUserID(hdlg);
+
+ hwnd=GetDlgItem(hdlg, IDC_KEY_LIST);
+
+ for (index=0; index<2; index++)
+ {
+ ZeroMemory(&lvc, sizeof(lvc)); // LV_COLUMN
+ lvc.iSubItem=index;
+ lvc.mask=LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
+ lvc.fmt=LVCFMT_LEFT;
+ lvc.pszText=(LPTSTR)Translate(column[index]);
+ lvc.cx=columnwidth[index];
+ ListView_InsertColumn(hwnd, index, &lvc);
+ }
+
+ index=0;
+ for (
+ hcontact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0);
+ hcontact;
+ hcontact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hcontact,0)
+ )
+ {
+ ZeroMemory(&lvi,sizeof(lvi)); // LV_ITEM
+ lvi.iItem=++index;
+ lvi.mask=LVIF_TEXT|LVIF_PARAM;
+ lvi.pszText=(LPTSTR)CallService(MS_CLIST_GETCONTACTDISPLAYNAME,(WPARAM)hcontact,0);
+ lvi.lParam=(LPARAM)hcontact;
+ if (
+ !lvi.pszText
+ || !strlen((const char*)lvi.pszText)
+ || !strcmp((const char*)lvi.pszText,Translate("(Unknown Contact)"))
+ )
+ continue;
+ item=ListView_InsertItem(hwnd,&lvi);
+
+ error=DBGetContactSetting(hcontact,pluginid,dbkeyuserid,&dbv);
+ strcpy(keyuserid,(!error?dbv.pszVal:""));
+ DBFreeVariant(&dbv);
+ if (strlen(keyuserid)==0)
+ strcpy(keyuserid,Translate(txtnone));
+ ListView_SetItemText(hwnd,item,1,(LPTSTR)keyuserid);
+ }
+
+ ListView_SetExtendedListViewStyle(hwnd,LVS_EX_FULLROWSELECT);
+ ListView_SetItemState(hwnd,0,LVIS_SELECTED|LVIS_FOCUSED,LVIS_SELECTED|LVIS_FOCUSED);
+ synchronizePublicKeyUserID(hdlg);
+ break;
+ case WM_COMMAND:
+ // benutzereingaben feststellen
+ if (GetFocus()==(HWND)lparam) // ist der dialog fokussiert?
+ {
+ if ((HIWORD(wparam)==EN_CHANGE) // wurde ein text veraendert?
+ ||(HIWORD(wparam)==CBN_SELCHANGE)) // dropdowns
+ SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); // aktiviere apply button
+ }
+
+ switch (HIWORD(wparam))
+ {
+ case CBN_SELCHANGE:
+ if (LOWORD(wparam)==IDC_PUBLICKEY_DDOWN)
+ {
+ GetDlgItemText(hdlg,IDC_PUBLICKEY_DDOWN,(LPTSTR)keyuserid,sizeof(keyuserid));
+
+ hwnd=GetDlgItem(hdlg,IDC_KEY_LIST);
+ item=ListView_GetNextItem(hwnd,-1,LVNI_SELECTED);
+ ListView_SetItemText(hwnd,item,1,(LPTSTR)keyuserid);
+ }
+ break;
+ }
+
+ switch (LOWORD(wparam))
+ {
+ case IDC_BROWSEEXECUTABLE_BTN: // browse button click
+ GetDlgItemText(hdlg,IDC_GPGEXECUTABLE_EDIT,(LPTSTR)gpgexe,sizeof(gpgexe));
+
+ // filter zusammensetzen
+ ZeroMemory(&filter, sizeof(filter));
+ strcpy(filter, Translate(txtexecutablefiles));
+ strcat(filter, " (*.exe)");
+ pos=filter+strlen(filter)+1;
+ strcpy(pos, "*.exe");
+
+ // OPENFILENAME initialisieren
+ ZeroMemory(&ofn, sizeof(ofn));
+ ofn.lStructSize=sizeof(ofn);
+ ofn.hwndOwner=hdlg;
+ ofn.lpstrFilter=(LPCTSTR)filter;
+ ofn.lpstrFile=(LPTSTR)gpgexe;
+ ofn.nMaxFile=sizeof(gpgexe);
+ ofn.lpstrTitle=(LPCTSTR)Translate((LPCTSTR)txtselectexecutable);
+ ofn.Flags=OFN_FILEMUSTEXIST|OFN_LONGNAMES|OFN_HIDEREADONLY;
+
+ if (GetOpenFileName(&ofn))
+ {
+ SetDlgItemText(hdlg, IDC_GPGEXECUTABLE_EDIT, ofn.lpstrFile);
+ SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); // aktiviere apply button
+ }
+ break;
+ case IDC_PUBLICREFRESH_BTN:
+ updateKeyUserIDs(publickeyuserid);
+ fillKeyDropdown(hdlg, publickeyuserid);
+ synchronizePublicKeyUserID(hdlg);
+ break;
+ case IDC_SECRETREFRESH_BTN:
+ updateKeyUserIDs(secretkeyuserid);
+ fillKeyDropdown(hdlg, secretkeyuserid);
+ setSecretKeyUserID(hdlg);
+ break;
+ }
+ break;
+ case WM_NOTIFY:
+ switch (((LPNMHDR)lparam)->code)
+ {
+ case LVN_ITEMCHANGED:
+ nmlv=(NM_LISTVIEW *)lparam;
+ if (nmlv->uNewState&LVIS_SELECTED!=0)
+ synchronizePublicKeyUserID(hdlg);
+ break;
+ case PSN_APPLY:
+ // eingaben in der datenbank abspeichern
+ GetDlgItemText(hdlg,IDC_GPGEXECUTABLE_EDIT,(LPTSTR)gpgExecutable,fullfilenamesize);
+ DBWriteContactSettingString(NULL,pluginid,dbexecutable,gpgExecutable);
+ GetDlgItemText(hdlg,IDC_GPGHOME_EDIT,(LPTSTR)gpgHomeDirectory,argumentsize);
+ DBWriteContactSettingString(NULL, pluginid, dbhomedirectory, gpgHomeDirectory);
+
+ hwnd=GetDlgItem(hdlg, IDC_KEY_LIST);
+ count=ListView_GetItemCount(hwnd);
+
+ for (index=0; index<count; index++)
+ {
+ ZeroMemory(&lvi, sizeof(lvi)); // LV_ITEM
+ lvi.iItem=index;
+ lvi.iSubItem=1;
+ lvi.mask=LVIF_TEXT|LVIF_PARAM;
+ lvi.pszText=(LPTSTR)keyuserid;
+ lvi.cchTextMax=sizeof(keyuserid);
+ ListView_GetItem(hwnd, &lvi);
+
+ if (strcmp(keyuserid,Translate(txtnone))==0)
+ strcpy(keyuserid,"");
+ DBWriteContactSettingString((HANDLE)lvi.lParam, pluginid, dbkeyuserid, keyuserid);
+ }
+
+ GetDlgItemText(hdlg,IDC_SECRETKEY_DDOWN,(LPTSTR)keyuserid,sizeof(keyuserid));
+ if (strcmp(keyuserid,Translate(txtnone))==0)
+ strcpy(keyuserid,"");
+ DBWriteContactSettingString(NULL, pluginid, dbkeyuserid, keyuserid);
+ break;
+ }
+ break;
+ }
+
+ return 0;
+}
+
+BOOL CALLBACK ExpertOptionsDialogProcedure(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ char tag[plugintagsize];
+
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hdlg);
+
+ CheckDlgButton(hdlg, IDC_STOREPASSPHRASES_CBOX, storepassphraseschecked);
+ CheckDlgButton(hdlg, IDC_IMPORTPUBLICKEYS_CBOX, autoimportpublickeyschecked);
+
+ strcpy(tag, starttag);
+ quoteEscapeSequences(tag);
+ SetDlgItemText(hdlg,IDC_STARTTAG_EDIT,(LPCTSTR)tag);
+ strcpy(tag, endtag);
+ quoteEscapeSequences(tag);
+ SetDlgItemText(hdlg,IDC_ENDTAG_EDIT,(LPCTSTR)tag);
+
+ SetDlgItemText(hdlg,IDC_LISTPUBLICKEYS_EDIT,(LPCTSTR)gpgArgsListPublicKeys);
+ SetDlgItemText(hdlg,IDC_LISTSECRETKEYS_EDIT,(LPCTSTR)gpgArgsListSecretKeys);
+ SetDlgItemText(hdlg,IDC_IMPORTPUBLICKEY_EDIT,(LPCTSTR)gpgArgsImportPublicKey);
+ SetDlgItemText(hdlg,IDC_EXPORTPUBLICKEY_EDIT,(LPCTSTR)gpgArgsExportPublicKey);
+ SetDlgItemText(hdlg,IDC_DETECTUSERID_EDIT,(LPCTSTR)gpgArgsDetectUserID);
+ SetDlgItemText(hdlg,IDC_ENCRYPT_EDIT,(LPCTSTR)gpgArgsEncrypt);
+ SetDlgItemText(hdlg,IDC_DECRYPT_EDIT,(LPCTSTR)gpgArgsDecrypt);
+ SetDlgItemText(hdlg,IDC_TEMPDIR_EDIT,(LPCTSTR)gpgTempdir);
+
+ CheckDlgButton(hdlg,IDC_LOGGINGON_CBOX,loggingonchecked);
+ SetDlgItemText(hdlg,IDC_LOGFILE_EDIT,(LPCTSTR)logfile);
+ break;
+
+ case WM_NOTIFY:
+ switch (((LPNMHDR)lparam)->code)
+ {
+ case PSN_APPLY:
+ storepassphraseschecked=IsDlgButtonChecked(hdlg, IDC_STOREPASSPHRASES_CBOX);
+ DBWriteContactSettingDword(NULL, pluginid, dbstorepassphrases, storepassphraseschecked);
+ autoimportpublickeyschecked=IsDlgButtonChecked(hdlg, IDC_IMPORTPUBLICKEYS_CBOX);
+ DBWriteContactSettingDword(NULL, pluginid, dbautoimportpublickeys, autoimportpublickeyschecked);
+
+ // alle passphrasen loeschen
+ if(storepassphraseschecked==BST_UNCHECKED)
+ {
+ releasePassphrases();
+ initPassphrases();
+ }
+
+ GetDlgItemText(hdlg,IDC_STARTTAG_EDIT,(LPTSTR)starttag,sizeof(starttag));
+ unquoteEscapeSequences(starttag);
+ DBWriteContactSettingString(NULL,pluginid,dbstarttag,starttag);
+ GetDlgItemText(hdlg,IDC_ENDTAG_EDIT,(LPTSTR)endtag,sizeof(endtag));
+ unquoteEscapeSequences(endtag);
+ DBWriteContactSettingString(NULL,pluginid,dbendtag,endtag);
+
+ GetDlgItemText(hdlg,IDC_LISTPUBLICKEYS_EDIT,(LPTSTR)gpgArgsListPublicKeys,argumentsize);
+ DBWriteContactSettingString(NULL,pluginid,dblistpublickeys,gpgArgsListPublicKeys);
+ GetDlgItemText(hdlg,IDC_LISTSECRETKEYS_EDIT,(LPTSTR)gpgArgsListSecretKeys,argumentsize);
+ DBWriteContactSettingString(NULL,pluginid,dblistsecretkeys,gpgArgsListSecretKeys);
+ GetDlgItemText(hdlg,IDC_IMPORTPUBLICKEY_EDIT,(LPTSTR)gpgArgsImportPublicKey,argumentsize);
+ DBWriteContactSettingString(NULL,pluginid,dbimportpublickey,gpgArgsImportPublicKey);
+ GetDlgItemText(hdlg,IDC_EXPORTPUBLICKEY_EDIT,(LPTSTR)gpgArgsExportPublicKey,argumentsize);
+ DBWriteContactSettingString(NULL,pluginid,dbexportpublickey,gpgArgsExportPublicKey);
+ GetDlgItemText(hdlg,IDC_DETECTUSERID_EDIT,(LPTSTR)gpgArgsDetectUserID,argumentsize);
+ DBWriteContactSettingString(NULL,pluginid,dbdetectuserid,gpgArgsDetectUserID);
+ GetDlgItemText(hdlg,IDC_ENCRYPT_EDIT,(LPTSTR)gpgArgsEncrypt,argumentsize);
+ DBWriteContactSettingString(NULL,pluginid,dbencrypt,gpgArgsEncrypt);
+ GetDlgItemText(hdlg,IDC_DECRYPT_EDIT,(LPTSTR)gpgArgsDecrypt,argumentsize);
+ DBWriteContactSettingString(NULL,pluginid,dbdecrypt,gpgArgsDecrypt);
+ GetDlgItemText(hdlg,IDC_TEMPDIR_EDIT,(LPTSTR)gpgTempdir,fullfilenamesize);
+ DBWriteContactSettingString(NULL,pluginid,dbtempdir,gpgTempdir);
+
+ loggingonchecked=IsDlgButtonChecked(hdlg,IDC_LOGGINGON_CBOX);
+ DBWriteContactSettingDword(NULL,pluginid,dbloggingon,loggingonchecked);
+ GetDlgItemText(hdlg,IDC_LOGFILE_EDIT,(LPTSTR)logfile,fullfilenamesize);
+ DBWriteContactSettingString(NULL,pluginid,dblogfile,logfile);
+ break;
+ }
+ break;
+
+ case WM_COMMAND:
+ if (GetFocus()==(HWND)lparam)
+ {
+ if((HIWORD(wparam)==EN_CHANGE) // text verändert
+ ||((HIWORD(wparam)==BN_CLICKED)&&(LOWORD(wparam)==IDC_STOREPASSPHRASES_CBOX)) // check box
+ ||((HIWORD(wparam)==BN_CLICKED)&&(LOWORD(wparam)==IDC_IMPORTPUBLICKEYS_CBOX)) // check box
+ ||((HIWORD(wparam)==BN_CLICKED)&&(LOWORD(wparam)==IDC_LOGGINGON_CBOX))) // check box
+ SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); // aktiviere apply button
+ }
+
+ switch (LOWORD(wparam))
+ {
+ case IDC_RESET_BTN:
+ // restaurieren der default werte
+ strcpy(gpgArgsListPublicKeys, txtgpgargslistpublickeys);
+ strcpy(gpgArgsListSecretKeys, txtgpgargslistsecretkeys);
+ strcpy(gpgArgsImportPublicKey, txtgpgargsimportpublickey);
+ strcpy(gpgArgsExportPublicKey, txtgpgargsexportpublickey);
+ strcpy(gpgArgsDetectUserID, txtgpgargsdetectuserid);
+ strcpy(gpgArgsEncrypt, txtgpgargsencrypt);
+ strcpy(gpgArgsDecrypt, txtgpgargsdecrypt);
+ strcpy(gpgTempdir, txtgpgtempdir);
+
+ // dialog aktualisieren
+ SetDlgItemText(hdlg,IDC_LISTPUBLICKEYS_EDIT,(LPCTSTR)gpgArgsListPublicKeys);
+ SetDlgItemText(hdlg,IDC_LISTSECRETKEYS_EDIT,(LPCTSTR)gpgArgsListSecretKeys);
+ SetDlgItemText(hdlg,IDC_IMPORTPUBLICKEY_EDIT,(LPCTSTR)gpgArgsImportPublicKey);
+ SetDlgItemText(hdlg,IDC_EXPORTPUBLICKEY_EDIT,(LPCTSTR)gpgArgsExportPublicKey);
+ SetDlgItemText(hdlg,IDC_DETECTUSERID_EDIT,(LPCTSTR)gpgArgsDetectUserID);
+ SetDlgItemText(hdlg,IDC_ENCRYPT_EDIT,(LPCTSTR)gpgArgsEncrypt);
+ SetDlgItemText(hdlg,IDC_DECRYPT_EDIT,(LPCTSTR)gpgArgsDecrypt);
+ SetDlgItemText(hdlg,IDC_TEMPDIR_EDIT,(LPCTSTR)gpgTempdir);
+
+ SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); // aktiviere apply button
+ break;
+ }
+ break;
+ }
+ return 0;
+}
diff --git a/GnuPG/options.h b/GnuPG/options.h new file mode 100644 index 0000000..8869a55 --- /dev/null +++ b/GnuPG/options.h @@ -0,0 +1,8 @@ +#ifndef __OPTIONS_H__
+#define __OPTIONS_H__
+
+int OptionsInit(WPARAM wparam, LPARAM lparam);
+BOOL CALLBACK OptionsDialogProcedure(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam);
+BOOL CALLBACK ExpertOptionsDialogProcedure(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam);
+
+#endif // __OPTIONS_H__
\ No newline at end of file diff --git a/GnuPG/passdialog.cpp b/GnuPG/passdialog.cpp new file mode 100644 index 0000000..b93e3fa --- /dev/null +++ b/GnuPG/passdialog.cpp @@ -0,0 +1,28 @@ +#include "gnupgplugin.h"
+
+char dlgpassphrase[passphrasesize];
+
+BOOL CALLBACK PassphraseDialogProcedure(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hdlg);
+ SetDlgItemText(hdlg,IDC_USERID_STATIC,(LPCTSTR)lparam);
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wparam))
+ {
+ case IDOK:
+ ZeroMemory(dlgpassphrase,sizeof(dlgpassphrase));
+ GetDlgItemText(hdlg,IDC_PASSPHRASE_EDIT,(LPTSTR)dlgpassphrase,sizeof(dlgpassphrase));
+ case IDCANCEL:
+ EndDialog(hdlg,wparam);
+ return TRUE;
+ break;
+ }
+ break;
+ }
+
+ return FALSE;
+}
diff --git a/GnuPG/passdialog.h b/GnuPG/passdialog.h new file mode 100644 index 0000000..0a961d2 --- /dev/null +++ b/GnuPG/passdialog.h @@ -0,0 +1,8 @@ +#ifndef __PASSDIALOG_H__
+#define __PASSDIALOG_H__
+
+extern char dlgpassphrase[];
+
+BOOL CALLBACK PassphraseDialogProcedure(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam);
+
+#endif // __PASSDIALOG_H__
\ No newline at end of file diff --git a/GnuPG/passphrases.cpp b/GnuPG/passphrases.cpp new file mode 100644 index 0000000..1b93e95 --- /dev/null +++ b/GnuPG/passphrases.cpp @@ -0,0 +1,72 @@ +#include "gnupgplugin.h"
+
+// passphrase typ
+struct passphrase_s
+{
+ char keyuserid[keyuseridsize];
+ char passphrase[passphrasesize];
+};
+
+// globale variablen
+struct passphrase_s *passphrases;
+int passphrasecount;
+
+void initPassphrases(void)
+{
+ passphrasecount=0;
+ passphrases=NULL;
+}
+
+void releasePassphrases(void)
+{
+ for (int i=0; i<passphrasecount; i++)
+ ZeroMemory(passphrases[i].passphrase,sizeof(passphrases[i].passphrase));
+
+ mir_free(passphrases);
+}
+
+void addPassphrase(const char *akeyuserid, const char *apassphrase)
+{
+ if (!akeyuserid || !apassphrase)
+ return;
+
+ if (getPassphrase(akeyuserid))
+ return;
+
+ passphrasecount++;
+
+ passphrase_s *ps=(passphrase_s*)mir_alloc(sizeof(passphrase_s)*passphrasecount);
+ if (!ps)
+ {
+ --passphrasecount;
+ return;
+ }
+
+ if (passphrasecount>1)
+ {
+ int prevsiz=sizeof(passphrase_s)*(passphrasecount-1);
+ memcpy(ps,passphrases,prevsiz);
+ ZeroMemory(passphrases,prevsiz);
+ mir_free(passphrases);
+ }
+
+ passphrases=ps;
+
+ strncpy(passphrases[passphrasecount-1].keyuserid,akeyuserid,keyuseridsize);
+ strncpy(passphrases[passphrasecount-1].passphrase,apassphrase,passphrasesize);
+ passphrases[passphrasecount-1].keyuserid[keyuseridsize-1]='\0';
+ passphrases[passphrasecount-1].passphrase[passphrasesize-1]='\0';
+}
+
+char *getPassphrase(const char *akeyuserid)
+{
+ char *result=NULL;
+
+ for (int i=0; i<passphrasecount; i++)
+ {
+ if (strcmp(passphrases[i].keyuserid,akeyuserid)==0)
+ result=passphrases[i].passphrase;
+ }
+
+ return result;
+}
diff --git a/GnuPG/passphrases.h b/GnuPG/passphrases.h new file mode 100644 index 0000000..d521b9c --- /dev/null +++ b/GnuPG/passphrases.h @@ -0,0 +1,9 @@ +#ifndef __PASSPHRASES_H__
+#define __PASSPHRASES_H__
+
+void initPassphrases(void);
+void releasePassphrases(void);
+void addPassphrase(const char *akeyuserid, const char *apassphrase);
+char *getPassphrase(const char *akeyuserid);
+
+#endif // __PASSPHRASES_H__
\ No newline at end of file diff --git a/GnuPG/pipeexec.cpp b/GnuPG/pipeexec.cpp new file mode 100644 index 0000000..facb7aa --- /dev/null +++ b/GnuPG/pipeexec.cpp @@ -0,0 +1,133 @@ +#include "gnupgplugin.h"
+
+BOOL isWindowsNT(void)
+{
+ OSVERSIONINFO ovi;
+
+ ZeroMemory(&ovi,sizeof(ovi));
+ ovi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
+ GetVersionEx(&ovi);
+
+ return (ovi.dwPlatformId==VER_PLATFORM_WIN32_NT)?TRUE:FALSE;
+}
+
+void storeOutput(HANDLE ahandle, char **aoutput)
+{
+ BOOL success;
+ char readbuffer[10];
+ unsigned long transfered, available;
+
+ do {
+ PeekNamedPipe(ahandle,NULL,0,NULL,&available,NULL);
+ if (!available)
+ continue;
+ success=ReadFile(ahandle,readbuffer,sizeof(readbuffer),&transfered,NULL);
+ if (success && transfered)
+ appendText(aoutput,readbuffer,transfered);
+ } while (available>0);
+}
+
+pxResult pxExecute(char *acommandline, char *ainput, char **aoutput, LPDWORD aexitcode)
+{
+ BOOL success;
+ STARTUPINFO startupinfo;
+ SECURITY_ATTRIBUTES securityattributes;
+ SECURITY_DESCRIPTOR securitydescriptor;
+ PROCESS_INFORMATION processinformation;
+ HANDLE newstdin, newstdout, readstdout, writestdin;
+ char *inputpos;
+ unsigned long transfered;
+ int size;
+
+ LogMessage("--- GnuPG.pxExecute: commandline:\n",acommandline,"\n");
+
+ ZeroMemory(&securityattributes,sizeof(securityattributes));
+ securityattributes.nLength=sizeof(SECURITY_ATTRIBUTES);
+ securityattributes.bInheritHandle=TRUE;
+
+ if (isWindowsNT())
+ {
+ InitializeSecurityDescriptor(&securitydescriptor,SECURITY_DESCRIPTOR_REVISION);
+ SetSecurityDescriptorDacl(&securitydescriptor,TRUE,NULL,FALSE);
+ securityattributes.lpSecurityDescriptor=&securitydescriptor;
+ }
+ else securityattributes.lpSecurityDescriptor=NULL;
+
+ success=CreatePipe(&newstdin,&writestdin,&securityattributes,0);
+ if (!success)
+ {
+ LogMessage("--- GnuPG.pxExecute: ","stdin create pipe failed","\n");
+ return pxCreatePipeFailed;
+ }
+
+ success=CreatePipe(&readstdout,&newstdout,&securityattributes,0);
+ if (!success)
+ {
+ LogMessage("--- GnuPG.pxExecute: ","stdout create pipe failed","\n");
+ CloseHandle(newstdin);
+ CloseHandle(writestdin);
+ return pxCreatePipeFailed;
+ }
+
+ GetStartupInfo(&startupinfo);
+ startupinfo.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
+ startupinfo.wShowWindow=SW_HIDE;
+ startupinfo.hStdOutput=newstdout;
+ startupinfo.hStdError=newstdout;
+ startupinfo.hStdInput=newstdin;
+
+ success=CreateProcess
+ (
+ NULL,
+ (LPTSTR)acommandline,
+ NULL,
+ NULL,
+ TRUE,
+ CREATE_NEW_CONSOLE,
+ NULL,
+ NULL,
+ &startupinfo,
+ &processinformation
+ );
+
+ if (!success)
+ {
+ LogMessage("--- GnuPG.pxExecute: ", "create process failed", "\n");
+ CloseHandle(newstdin);
+ CloseHandle(writestdin);
+ CloseHandle(newstdout);
+ CloseHandle(readstdout);
+ return pxCreateProcessFailed;
+ }
+
+ inputpos=ainput;
+
+ while (TRUE)
+ {
+ success=GetExitCodeProcess(processinformation.hProcess,aexitcode);
+ if (success && *aexitcode!=STILL_ACTIVE)
+ break;
+
+ storeOutput(readstdout,aoutput);
+
+ if (*inputpos!='\0') size=1;
+ else size=0;
+
+ success=WriteFile(writestdin,inputpos,size,&transfered,NULL);
+ inputpos+=transfered;
+ }
+
+ storeOutput(readstdout,aoutput);
+ WaitForSingleObject(processinformation.hProcess,INFINITE);
+
+ LogMessage("--- GnuPG.pxExecute: output:\n",*aoutput,"");
+
+ CloseHandle(processinformation.hThread);
+ CloseHandle(processinformation.hProcess);
+ CloseHandle(newstdin);
+ CloseHandle(newstdout);
+ CloseHandle(readstdout);
+ CloseHandle(writestdin);
+
+ return pxSuccess;
+}
diff --git a/GnuPG/pipeexec.h b/GnuPG/pipeexec.h new file mode 100644 index 0000000..9d81fda --- /dev/null +++ b/GnuPG/pipeexec.h @@ -0,0 +1,23 @@ +#ifndef __PIPEEXEC_H__
+#define __PIPEEXEC_H__
+
+#include <windows.h>
+
+typedef enum {
+ pxSuccess,
+ pxSuccessExitCodeInvalid,
+ pxCreatePipeFailed,
+ pxDuplicateHandleFailed,
+ pxCloseHandleFailed,
+ pxCreateProcessFailed,
+ pxThreadWaitFailed,
+ pxReadFileFailed,
+ pxBufferOverflow
+}
+pxResult;
+
+pxResult pxExecute(char *acommandline, char *ainput, char **aoutput, LPDWORD aexitcode);
+
+#endif // __PIPEEXEC_H__
+
+
\ No newline at end of file diff --git a/GnuPG/resource.h b/GnuPG/resource.h new file mode 100644 index 0000000..a0b6171 --- /dev/null +++ b/GnuPG/resource.h @@ -0,0 +1,68 @@ +//{{NO_DEPENDENCIES}}
+// Microsoft Developer Studio generated include file.
+// Used by resource.rc
+//
+#define IDD_USERINFO_DLG 102
+#define IDD_PASSPHRASE_DLG 103
+#define IDD_KEYOPTIONS_DLG 104
+#define IDD_GNUPGOPTIONS_DLG 106
+#define IDD_EXPERTOPTIONS_DLG 107
+#define IDD_OPTIONS_DLG 108
+#define IDC_KEY_EDIT 1000
+#define IDC_PASSPHRASE_EDIT 1002
+#define IDC_USERID_STATIC 1003
+#define IDC_IMPORT_BTN 1005
+#define IDC_EXPORT_BTN 1006
+#define IDC_BROWSEEXECUTABLE_BTN 1007
+#define IDC_STOREPASSPHRASES_CBOX 1009
+#define IDC_GNUPGARGUMENTS_GBOX 1011
+#define IDC_IMPORTPUBLICKEY_STATIC 1012
+#define IDC_EXPORTPUBLICKEY_STATIC 1014
+#define IDC_DETECTUSERID_STATIC 1015
+#define IDC_DETECTUSERID_EDIT 1016
+#define IDC_LISTPUBLICKEYS_EDIT 1017
+#define IDC_LISTSECRETKEYS_EDIT 1018
+#define IDC_ENCRYPT_STATIC 1019
+#define IDC_ENCRYPT_EDIT 1020
+#define IDC_DECRYPT_EDIT 1021
+#define IDC_GPGEXECUTABLE_EDIT 1022
+#define IDC_TEMPDIR_EDIT 1022
+#define IDC_LISTPUBLICKEYS_STATIC 1023
+#define IDC_LISTSECRETKEYS_STATIC 1024
+#define IDC_DECRYPT_STATIC 1025
+#define IDC_IMPORTPUBLICKEY_EDIT 1026
+#define IDC_EXPORTPUBLICKEY_EDIT 1027
+#define IDC_TEMPDIR_STATIC 1028
+#define IDC_GPGHOME_EDIT 1029
+#define IDC_RESET_BTN 1031
+#define IDC_IMPORTPUBLICKEYS_CBOX 1032
+#define IDC_SECRETKEY_DDOWN 1034
+#define IDC_KEY_LIST 1036
+#define IDC_PUBLICKEY_DDOWN 1037
+#define IDC_PUBLICREFRESH_BTN 1041
+#define IDC_SECRETREFRESH_BTN 1042
+#define IDC_PLUGINBEHAVIOR_STATIC 1043
+#define IDC_KEYRECEIVED_STATIC 1046
+#define IDC_USERID_EDIT 1048
+#define IDC_KEYID_EDIT 1049
+#define IDC_KEYRECEIVED_EDIT 1050
+#define IDC_EDIT1 1051
+#define IDC_STARTTAG_EDIT 1051
+#define IDC_EDIT2 1052
+#define IDC_ENDTAG_EDIT 1052
+#define IDC_HR 1053
+#define IDC_GNUPG_GBOX 1053
+#define IDC_LOGGINGON_CBOX 1054
+#define IDC_HR2 1055
+#define IDC_LOGFILE_EDIT 1055
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 109
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1056
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/GnuPG/resource.rc b/GnuPG/resource.rc new file mode 100644 index 0000000..eea941c --- /dev/null +++ b/GnuPG/resource.rc @@ -0,0 +1,272 @@ +//Microsoft Developer Studio generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include <mfc/afxres.h>
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// Russian resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
+#ifdef _WIN32
+LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
+#pragma code_page(1251)
+#endif //_WIN32
+
+#ifndef _MAC
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 0,0,1,3
+ PRODUCTVERSION 0,0,1,3
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "041904b0"
+ BEGIN
+ VALUE "Comments", "\0"
+ VALUE "CompanyName", " \0"
+ VALUE "FileDescription", "gnupg\0"
+ VALUE "FileVersion", "0, 0, 1, 3\0"
+ VALUE "InternalName", "gnupg\0"
+ VALUE "LegalCopyright", "Copyright © 2007\0"
+ VALUE "LegalTrademarks", "\0"
+ VALUE "OriginalFilename", "gnupg.dll\0"
+ VALUE "PrivateBuild", "\0"
+ VALUE "ProductName", " gnupg\0"
+ VALUE "ProductVersion", "0, 0, 1, 3\0"
+ VALUE "SpecialBuild", "\0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x419, 1200
+ END
+END
+
+#endif // !_MAC
+
+#endif // Russian resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+/////////////////////////////////////////////////////////////////////////////
+// German (Germany) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_DEU)
+#ifdef _WIN32
+LANGUAGE LANG_GERMAN, SUBLANG_GERMAN
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_USERINFO_DLG DIALOG DISCARDABLE 0, 0, 222, 132
+STYLE DS_3DLOOK | DS_CONTROL | WS_CHILD
+FONT 8, "MS Shell Dlg"
+BEGIN
+ LTEXT "User ID:",IDC_STATIC,5,6,49,8
+ EDITTEXT IDC_USERID_EDIT,58,6,159,8,ES_AUTOHSCROLL | ES_READONLY |
+ NOT WS_BORDER | NOT WS_TABSTOP
+ LTEXT "Key ID:",IDC_STATIC,5,16,49,8
+ EDITTEXT IDC_KEYID_EDIT,58,16,159,8,ES_AUTOHSCROLL | ES_READONLY |
+ NOT WS_BORDER | NOT WS_TABSTOP
+ LTEXT "Key received:",IDC_KEYRECEIVED_STATIC,5,26,49,8
+ EDITTEXT IDC_KEYRECEIVED_EDIT,58,26,159,8,ES_AUTOHSCROLL |
+ ES_READONLY | NOT WS_BORDER | NOT WS_TABSTOP
+ EDITTEXT IDC_KEY_EDIT,5,38,212,72,ES_MULTILINE | ES_AUTOVSCROLL |
+ ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL |
+ NOT WS_TABSTOP
+ PUSHBUTTON "&Import",IDC_IMPORT_BTN,167,114,50,14
+END
+
+IDD_PASSPHRASE_DLG DIALOG DISCARDABLE 0, 0, 238, 46
+STYLE DS_SYSMODAL | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION |
+ WS_SYSMENU
+CAPTION "GnuPG Plugin - Passphrase"
+FONT 8, "MS Shell Dlg"
+BEGIN
+ EDITTEXT IDC_PASSPHRASE_EDIT,6,24,168,12,ES_PASSWORD |
+ ES_AUTOHSCROLL
+ DEFPUSHBUTTON "Ok",IDOK,181,7,50,14
+ PUSHBUTTON "Cancel",IDCANCEL,181,24,50,14
+ LTEXT "Enter passphrase for the secret key of user:",
+ IDC_STATIC,6,4,168,8
+ LTEXT "User ID",IDC_USERID_STATIC,6,14,168,8
+END
+
+IDD_OPTIONS_DLG DIALOGEX 0, 0, 314, 240
+STYLE DS_3DLOOK | WS_CHILD
+EXSTYLE WS_EX_CONTROLPARENT
+FONT 8, "MS Shell Dlg", 0, 0, 0x1
+BEGIN
+ GROUPBOX "Basic",IDC_GNUPG_GBOX,0,0,314,48
+ LTEXT "Executable:",IDC_STATIC,8,16,58,8
+ EDITTEXT IDC_GPGEXECUTABLE_EDIT,68,12,219,12,ES_AUTOHSCROLL
+ PUSHBUTTON "...",IDC_BROWSEEXECUTABLE_BTN,292,12,14,12
+ LTEXT "Home Directory:",IDC_STATIC,8,32,58,8
+ EDITTEXT IDC_GPGHOME_EDIT,68,28,238,12,ES_AUTOHSCROLL
+ GROUPBOX "Key Assignment",IDC_STATIC,0,53,314,187
+ LTEXT "Your Key",IDC_STATIC,8,68,58,8
+ COMBOBOX IDC_SECRETKEY_DDOWN,68,64,183,76,CBS_DROPDOWNLIST |
+ CBS_SORT | WS_VSCROLL | WS_TABSTOP
+ PUSHBUTTON "&Refresh",IDC_SECRETREFRESH_BTN,256,64,50,14
+ CONTROL "",IDC_HR2,"Static",SS_ETCHEDHORZ,4,85,305,1
+ CONTROL "List1",IDC_KEY_LIST,"SysListView32",LVS_REPORT |
+ LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_SORTASCENDING |
+ LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,8,93,298,123
+ LTEXT "Contact Key",IDC_STATIC,8,225,58,8
+ COMBOBOX IDC_PUBLICKEY_DDOWN,68,221,183,78,CBS_DROPDOWNLIST |
+ CBS_SORT | WS_VSCROLL | WS_TABSTOP
+ PUSHBUTTON "R&efresh",IDC_PUBLICREFRESH_BTN,256,221,50,14
+END
+
+IDD_EXPERTOPTIONS_DLG DIALOGEX 0, 0, 313, 232
+STYLE DS_3DLOOK | WS_CHILD
+EXSTYLE WS_EX_CONTROLPARENT
+FONT 8, "MS Shell Dlg"
+BEGIN
+ GROUPBOX "Options",IDC_STATIC,0,0,128,48
+ CONTROL "Store Passphrases Temporary",IDC_STOREPASSPHRASES_CBOX,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,14,113,10
+ CONTROL "Import Public Keys Automatically",
+ IDC_IMPORTPUBLICKEYS_CBOX,"Button",BS_AUTOCHECKBOX |
+ WS_TABSTOP,8,30,113,10
+ GROUPBOX "Tags",IDC_STATIC,136,0,177,48
+ LTEXT "Start Tag",IDC_STATIC,143,16,29,8
+ EDITTEXT IDC_STARTTAG_EDIT,178,12,128,12,ES_AUTOHSCROLL
+ LTEXT "End Tag",IDC_STATIC,143,32,29,8
+ EDITTEXT IDC_ENDTAG_EDIT,178,28,128,12,ES_AUTOHSCROLL
+ GROUPBOX "Commandline Arguments",IDC_GNUPGARGUMENTS_GBOX,0,53,313,
+ 144
+ LTEXT "List Public Keys:",IDC_LISTPUBLICKEYS_STATIC,8,68,55,8
+ EDITTEXT IDC_LISTPUBLICKEYS_EDIT,68,64,238,12,ES_AUTOHSCROLL
+ LTEXT "List Secret Keys:",IDC_LISTSECRETKEYS_STATIC,8,84,55,8
+ EDITTEXT IDC_LISTSECRETKEYS_EDIT,68,80,238,12,ES_AUTOHSCROLL
+ LTEXT "Import Public Key:",IDC_IMPORTPUBLICKEY_STATIC,8,100,55,
+ 8
+ EDITTEXT IDC_IMPORTPUBLICKEY_EDIT,68,96,238,12,ES_AUTOHSCROLL
+ LTEXT "Export Public Key:",IDC_EXPORTPUBLICKEY_STATIC,8,116,55,
+ 8
+ EDITTEXT IDC_EXPORTPUBLICKEY_EDIT,68,112,238,12,ES_AUTOHSCROLL
+ LTEXT "Detect User ID:",IDC_DETECTUSERID_STATIC,8,132,55,8
+ EDITTEXT IDC_DETECTUSERID_EDIT,68,128,238,12,ES_AUTOHSCROLL
+ LTEXT "Encrypt:",IDC_ENCRYPT_STATIC,8,148,55,8
+ EDITTEXT IDC_ENCRYPT_EDIT,68,144,238,12,ES_AUTOHSCROLL
+ LTEXT "Decrypt:",IDC_DECRYPT_STATIC,8,164,55,8
+ EDITTEXT IDC_DECRYPT_EDIT,68,160,238,12,ES_AUTOHSCROLL
+ PUSHBUTTON "&Reset",IDC_RESET_BTN,256,178,50,14
+ GROUPBOX "Debug",IDC_STATIC,0,202,313,30
+ CONTROL "Log to File",IDC_LOGGINGON_CBOX,"Button",
+ BS_AUTOCHECKBOX | WS_TABSTOP,8,215,46,10
+ EDITTEXT IDC_LOGFILE_EDIT,68,213,238,12,ES_AUTOHSCROLL
+ EDITTEXT IDC_TEMPDIR_EDIT,39,179,210,12,ES_AUTOHSCROLL
+ LTEXT "Tempdir:",IDC_TEMPDIR_STATIC,7,181,29,8
+END
+
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO DISCARDABLE
+BEGIN
+ IDD_USERINFO_DLG, DIALOG
+ BEGIN
+ VERTGUIDE, 5
+ VERTGUIDE, 54
+ VERTGUIDE, 58
+ VERTGUIDE, 217
+ HORZGUIDE, 14
+ HORZGUIDE, 24
+ HORZGUIDE, 34
+ HORZGUIDE, 110
+ HORZGUIDE, 128
+ END
+
+ IDD_OPTIONS_DLG, DIALOG
+ BEGIN
+ VERTGUIDE, 6
+ VERTGUIDE, 66
+ VERTGUIDE, 68
+ END
+
+ IDD_EXPERTOPTIONS_DLG, DIALOG
+ BEGIN
+ VERTGUIDE, 178
+ VERTGUIDE, 306
+ HORZGUIDE, 48
+ HORZGUIDE, 53
+ HORZGUIDE, 197
+ HORZGUIDE, 202
+ HORZGUIDE, 225
+ END
+END
+#endif // APSTUDIO_INVOKED
+
+#endif // German (Germany) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/GnuPG/sendrecv.cpp b/GnuPG/sendrecv.cpp new file mode 100644 index 0000000..f59f35b --- /dev/null +++ b/GnuPG/sendrecv.cpp @@ -0,0 +1,406 @@ +#include "gnupgplugin.h"
+
+char PGP_PUBKEY_PROLOG[]="-----BEGIN PGP PUBLIC KEY BLOCK-----";
+char PGP_PUBKEY_EPILOG[]="-----END PGP PUBLIC KEY BLOCK-----";
+char PGP_MSG_PROLOG[]="-----BEGIN PGP MESSAGE-----";
+char PGP_MSG_EPILOG[]="-----END PGP MESSAGE-----";
+
+int SendMsgSvc(WPARAM wParam, LPARAM lParam)
+ // ANSI mode:
+ // ANSI source message is encrypted to ANSI cyphertext, then sent.
+ // UNICODE mode:
+ // ANSI part of source ANSI+UCS2 message is encrypted to ANSI cyphertext,
+ // then the cyphertext is appended by UCS2 version of the ANSI
+ // cyphertext, then the resulting ANSI+UCS2 cyphertext is sent.
+ // Note: the UCS2 part of the source message is lost! This is a feature.
+{
+ CCSDATA *ccs=(CCSDATA*)lParam;
+ if (!ccs)
+ {
+ LogMessage("--- GnuPG.SendMsgSvc: ","ccs==NULL, not our case.","\n");
+ return CallService(MS_PROTO_CHAINSEND,wParam,lParam);
+ }
+ char *msg=(char*)(ccs->lParam);
+ if (!msg)
+ {
+ LogMessage("--- GnuPG.SendMsgSvc: ","msg==NULL, not our case.","\n");
+ return CallService(MS_PROTO_CHAINSEND,wParam,lParam);
+ }
+
+ bool isUnicode=(bool)(ccs->wParam&PREF_UNICODE);
+ LogMessage("--- GnuPG.SendMsgSvc: mode: ",(isUnicode?"UNICODE":"ANSI"),"\n");
+ LogMessage("--- GnuPG.SendMsgSvc: msg (ANSI part):\n",msg,"\n--- EOM ---\n");
+
+ #if defined(__GPG_DEBUG__)
+ int binsiz=strlen(msg)+1;
+ if (isUnicode) binsiz*=(sizeof(wchar_t)+1);
+ FILE *fp=fopen("C:\\mir_SendMsgSvc_preenc.asc","wb");
+ if (fp)
+ {
+ fwrite(msg,1,binsiz,fp);
+ fclose(fp);
+ }
+ #endif
+
+ char keyuserid[keyuseridsize];
+
+ // get keyuserid
+ {
+ DBVARIANT dbv;
+ strcpy(keyuserid,(
+ DBGetContactSetting(ccs->hContact,pluginid,dbkeyuserid,&dbv)==0
+ ?dbv.pszVal
+ :""));
+ DBFreeVariant(&dbv);
+ }
+
+ UINT useencryptionchecked
+ =DBGetContactSettingByte(ccs->hContact,pluginid,dbuseencryption,FALSE);
+
+ char *buf=NULL;
+
+ if (useencryptionchecked && strlen(keyuserid))
+ {
+ char keyid[keyidsize];
+ ZeroMemory(keyid,sizeof(keyid));
+ getNextPart(keyid,keyuserid,txtidseparator);
+
+ if (gpgEncrypt(&buf,keyid,msg)!=gpgSuccess)
+ {
+ ErrorMessage(txterror,txtencryptfailed,txtverifyoptions);
+ return 0;
+ }
+ // *** ENCRYPT
+
+ if (buf) // now buf allocated and filled by encrypted message.
+ {
+ int binsiz=strlen(buf)+1;
+ if (isUnicode)
+ {
+ char *mix=makemix_dup(buf);
+ if (mix)
+ {
+ fnFALSE(&buf);
+ buf=mix;
+ binsiz*=(sizeof(wchar_t)+1);
+ }
+ else
+ LogMessage("--- GnuPG.SendMsgSvc: MIX: ","FAILED.","\n");
+ }
+
+ LogMessage("--- GnuPG.SendMsgSvc: Encrypted: \n",buf,"\n--- EOM ---\n");
+
+ #if defined(__GPG_DEBUG__)
+ FILE *fp=fopen("C:\\mir_SendMsgSvc_encbuf.asc","wb");
+ if (fp)
+ {
+ fwrite(buf,1,binsiz,fp);
+ fclose(fp);
+ }
+ #endif
+
+ ccs->lParam=(LPARAM)buf;
+
+// *** THIS IS A FEATURE HACK FOR JABBERG CODE... ***
+ ccs->wParam&=~PREF_UNICODE; // *** GO ANSI WAY!
+ LogMessage("--- GnuPG.SendMsgSvc: ANSI MODE FORCED: ","JabberG feature hack.","\n");
+// *** THIS IS A FEATURE HACK FOR JABBERG CODE... ***
+
+ int rc=CallService(MS_PROTO_CHAINSEND,wParam,(LPARAM)ccs);
+ // *** SEND ENCRYPTED!
+ fnFALSE(&buf);
+ ccs->lParam=(LPARAM)msg;
+ return rc;
+ }
+ // buf not allocated, so... send unencrypted.
+ }
+
+ LogMessage("--- GnuPG.SendMsgSvc: sending: ","UNENCRYPTED.","\n");
+
+ return CallService(MS_PROTO_CHAINSEND,wParam,lParam);
+
+} // int SendMsgSvc(WPARAM wParam, LPARAM lParam)
+
+enum recv_event_type { re_undefined, re_pgpmessage, re_pgppublickey, re_unknown };
+
+enum recv_event_type get_recv_event_type(const char *msg)
+{
+ char *prolog,*epilog;
+ prolog=(char*)strstr(msg,PGP_MSG_PROLOG);
+ epilog=(char*)strstr(msg,PGP_MSG_EPILOG);
+ if (prolog && epilog)
+ {
+ LogMessage("--- GnuPG.get_recv_event_type: ","re_pgpmessage","\n");
+ return re_pgpmessage;
+ }
+ prolog=(char*)strstr(msg,PGP_PUBKEY_PROLOG);
+ epilog=(char*)strstr(msg,PGP_PUBKEY_EPILOG);
+ if (prolog && epilog)
+ {
+ LogMessage("--- GnuPG.get_recv_event_type: ","re_pgppublickey","\n");
+ return re_pgppublickey;
+ }
+ LogMessage("--- GnuPG.get_recv_event_type: ","re_unknown","\n");
+ return re_unknown;
+}
+
+int parse_pgp_message(WPARAM wParam, CCSDATA *ccs)
+{
+ PROTORECVEVENT *pre=(PROTORECVEVENT*)(ccs->lParam);
+ char *msg=pre->szMessage;
+ if (!msg)
+ return CallService(MS_PROTO_CHAINRECV,wParam,(LPARAM)ccs);
+
+ bool isUnicode=(bool)(pre->flags&PREF_UNICODE);
+ bool isUtf=(bool)(pre->flags&PREF_UTF);
+
+ LogMessage("--- GnuPG.parse_pgp_message: pre->flags: ",
+ (isUnicode?"UNICODE":"ANSI"),
+ (isUtf?"+UTF\n":"\n"));
+
+ char *OrigMessage=msg;
+ char *tmp=fixcrlf_dup(msg);
+ if (tmp)
+ msg=tmp;
+ else
+ LogMessage("--- GnuPG.parse_pgp_message: CR/LF: ","FAILED.","\n");
+
+ char keyuserid[keyuseridsize]; ZeroMemory(keyuserid,sizeof(keyuserid));
+ bool useridvalid=(gpgDetectUserID(keyuserid,msg)==gpgSuccess);
+
+ char *storedpassphrase=NULL;
+ char passphrase[passphrasesize];
+
+ if (useridvalid)
+ {
+ if (storepassphraseschecked==BST_CHECKED)
+ storedpassphrase=getPassphrase(keyuserid);
+ }
+ else
+ {
+ ErrorMessage(txtwarning,txtdetectuseridfailed,txtverifyoptions);
+ strcpy(keyuserid,txtunknownuserid);
+ }
+
+ gpgResult gpgresult=gpgUnknownError;
+ char *decrypteddata=NULL;
+
+ LogMessage("--- GnuPG.parse_pgp_message: keyuserid: ",keyuserid,"\n");
+
+ if (storedpassphrase)
+ {
+ strcpy(passphrase,storedpassphrase);
+ gpgresult=gpgDecrypt(&decrypteddata,msg,passphrase);
+ // *** DECRYPT
+ }
+
+ int dlgresult=IDOK;
+ while (gpgresult!=gpgSuccess && dlgresult!=IDCANCEL)
+ // if there were no stored passphrase or we just failed to decrypt...
+ {
+ dlgresult=DialogBoxParam(dllinstance,MAKEINTRESOURCE(IDD_PASSPHRASE_DLG),
+ NULL,PassphraseDialogProcedure,(LPARAM)keyuserid);
+
+ if (dlgresult==IDOK) // if some passphrase given...
+ {
+ strcpy(passphrase,dlgpassphrase); ZeroMemory(dlgpassphrase,passphrasesize);
+ strcat(passphrase,txtcrlf); // wtf
+ gpgresult=gpgDecrypt(&decrypteddata,msg,passphrase);
+ // *** DECRYPT
+ }
+ }
+ // here on cancel or successful decryption
+
+ if (gpgresult==gpgSuccess) // if successfully decrypted
+ {
+ if (useridvalid && storepassphraseschecked==BST_CHECKED)
+ addPassphrase(keyuserid,passphrase); // cache passphrase
+ }
+
+ if (decrypteddata)
+ {
+ // 0. not utf? => decode from utf to ANSI
+ if (!isUtf) // !!! QUICK'N'DIRTY HACK for 0.7 <-> 0.7 only
+ mir_utf8decode(decrypteddata,NULL);
+
+ // We have some decrypted data, so let's:
+ // 1. embrace 'em with tags.
+ // 2. replace original message with the embraced decrypted data.
+ char *tmp=(char*)mir_alloc(strlen(starttag)+strlen(decrypteddata)+strlen(endtag)+1);
+ if (tmp)
+ {
+ strcpy(tmp,starttag);
+ strcat(tmp,decrypteddata);
+ strcat(tmp,endtag);
+ mir_free(decrypteddata);
+ decrypteddata=tmp;
+ } // *** start and end tags added if possible
+
+ LogMessage("--- GnuPG.parse_pgp_message: decrypteddata:\n",
+ decrypteddata,"\n--- EOM ---\n");
+
+ pre->szMessage=decrypteddata; // swap for decrypted
+ if (msg!=OrigMessage) fnFALSE(&msg); // throw away msg if not OrigMessage
+ }
+ else
+ pre->szMessage=msg; // no decrypted, so show the cyphertext
+
+ if (isUnicode && pre->szMessage!=OrigMessage)
+ // in Unicode mode, only for mir_allocated message
+ {
+ char *mix=makemix_dup(pre->szMessage);
+ if (mix)
+ {
+ mir_free(pre->szMessage);
+ pre->szMessage=mix; // mix done
+ }
+ else
+ {
+ LogMessage("--- GnuPG.parse_pgp_message: MIX: ","FAILED.","\n");
+ mir_free(pre->szMessage); // *** whatever there were...
+ pre->szMessage=OrigMessage;
+ // failed to mix => original cyphertext!
+ }
+ } // Unicode mode? => we should use mix! ...or original message.
+
+ ZeroMemory(passphrase,sizeof(passphrase)); // security kid
+
+ int rc=CallService(MS_PROTO_CHAINRECV,wParam,(LPARAM)ccs);
+ // RECEIVE IT FINALLY
+
+ if (pre->szMessage!=OrigMessage)
+ {
+ mir_free(pre->szMessage);
+ pre->szMessage=OrigMessage; // swap back to original encrypted
+ }
+ return rc;
+}
+
+int parse_pgp_public_key(WPARAM wParam, CCSDATA *ccs)
+{
+ PROTORECVEVENT *pre=(PROTORECVEVENT*)(ccs->lParam);
+ char *key=pre->szMessage;
+ if (!key)
+ return CallService(MS_PROTO_CHAINRECV,wParam,(LPARAM)ccs);
+
+ bool isUnicode=(pre->flags&PREF_UNICODE)?true:false;
+
+ char *OrigMessage=key;
+ char *tmp=fixcrlf_dup(key);
+ if (tmp)
+ key=tmp;
+ else
+ LogMessage("--- GnuPG.parse_pgp_public_key: CR/LF: ","FAILED.","\n");
+
+ time_t now; time(&now); struct tm tms=*localtime(&now);
+ const int ASCTIMESIZ=26; // *** as defined in asctime description. Dangerous?
+ char atstr[ASCTIMESIZ];
+ strcpy(atstr,asctime(&tms)); replace(atstr,"\n",""); replace(atstr,"\r","");
+ DBWriteContactSettingString(ccs->hContact,pluginid,dbkeymodified,atstr);
+
+ gpgResult gpgresult=gpgUnknownError;
+ char *atprolog=strstr(key,PGP_PUBKEY_PROLOG);
+ if (atprolog)
+ {
+ DBWriteContactSettingString(ccs->hContact,pluginid,dbkey,atprolog);
+ if (autoimportpublickeyschecked==BST_CHECKED)
+ gpgresult=gpgImportPublicKey(atprolog);
+ // *** PUBKEY MAYBE IMPORTED
+ }
+
+ if (key && key!=OrigMessage)
+ mir_free(key);
+
+ // let's try to save some human-readable words for history!
+
+ char *buf=(char*)mir_alloc(
+ strlen(starttag)
+ +strlen(Translate(txtpublickeyreceivedstored))
+ +strlen(Translate(txtpublickeyreceived))
+ +strlen(Translate(txtimportpublickeyfailed))
+ +strlen(Translate(txtverifyoptions))
+ +strlen(endtag)
+ +3 // two ' ' and one '\0'
+ );
+
+ if (buf)
+ {
+ strcpy(buf,starttag);
+
+ if (gpgresult==gpgSuccess)
+ strcat(buf,Translate(txtpublickeyreceivedstored));
+ else
+ {
+ strcat(buf,Translate(txtpublickeyreceived));
+ if (autoimportpublickeyschecked==BST_CHECKED)
+ {
+ strcat(buf," ");
+ strcat(buf,Translate(txtimportpublickeyfailed));
+ strcat(buf," ");
+ strcat(buf,Translate(txtverifyoptions));
+ }
+ }
+
+ strcat(buf,endtag);
+
+ pre->flags&=~PREF_UNICODE; // no reason for Unicode here!
+ pre->szMessage=buf; // for history
+
+ int rc=CallService(MS_PROTO_CHAINRECV,wParam,(LPARAM)ccs);
+ // *** some words for history should be written to db now.
+ if (pre->szMessage!=OrigMessage)
+ {
+ mir_free(pre->szMessage);
+ pre->szMessage=OrigMessage; // swap back...
+ }
+ return rc;
+ }
+
+ return CallService(MS_PROTO_CHAINRECV,wParam,(LPARAM)ccs);
+ // as far as we have no chance to save our words for history,
+ // let it be the original data.
+}
+
+int RecvMsgSvc(WPARAM wParam, LPARAM lParam)
+ // wParam - used to call proto recv chain, not used internally.
+ // lParam - points to CCSDATA structure
+ // returns result of CallService(MS_PROTO_CHAINRECV,wParam,lParam)
+{
+ CCSDATA *ccs=(CCSDATA*)lParam;
+ if (!ccs) // ccs==NULL => not our case!
+ return CallService(MS_PROTO_CHAINRECV,wParam,lParam);
+
+ PROTORECVEVENT *pre=(PROTORECVEVENT*)(ccs->lParam);
+ if (!pre) // pre==NULL => not our case!
+ return CallService(MS_PROTO_CHAINRECV,wParam,lParam);
+
+ char *msg=pre->szMessage;
+ if (!msg) // No message => not our case!
+ return CallService(MS_PROTO_CHAINRECV,wParam,lParam);
+
+ bool isUnicode=(bool)(pre->flags&PREF_UNICODE);
+ LogMessage("--- GnuPG.RecvMsgSvc: mode: ",(isUnicode?"UNICODE":"ANSI"),"\n");
+ LogMessage("--- GnuPG.RecvMsgSvc: msg (ANSI part):\n",msg,"\n--- EOM ---\n");
+
+ #if defined(__GPG_DEBUG__)
+ FILE *fp=fopen("C:\\mir_RecvMsgSvc.bin","wb");
+ if (fp)
+ {
+ int binlen=strlen(msg)+1;
+ if (isUnicode)
+ binlen*=(sizeof(wchar_t)+1);
+ fwrite(msg,1,binlen,fp);
+ fclose(fp);
+ }
+ #endif
+
+ switch (get_recv_event_type(msg))
+ {
+ case re_pgpmessage: return parse_pgp_message(wParam,ccs);
+ case re_pgppublickey: return parse_pgp_public_key(wParam,ccs);
+ default: break; // unknown event type, so not our case!
+ }
+
+ return CallService(MS_PROTO_CHAINRECV,wParam,lParam);
+ // not our case...
+} // int RecvMsgSvc(WPARAM wParam, LPARAM lParam)
diff --git a/GnuPG/sendrecv.h b/GnuPG/sendrecv.h new file mode 100644 index 0000000..4c6ad5c --- /dev/null +++ b/GnuPG/sendrecv.h @@ -0,0 +1,7 @@ +#ifndef __SENDRECV_H__
+#define __SENDRECV_H__
+
+int SendMsgSvc(WPARAM wParam, LPARAM lParam);
+int RecvMsgSvc(WPARAM wParam, LPARAM lParam);
+
+#endif // __SENDRECV_H__
\ No newline at end of file diff --git a/GnuPG/size.h b/GnuPG/size.h new file mode 100644 index 0000000..607b904 --- /dev/null +++ b/GnuPG/size.h @@ -0,0 +1,22 @@ +#ifndef __SIZE_H__
+#define __SIZE_H__
+
+/// zvb: evil here...
+// array groessen
+#define contactsize 256
+#define passphrasesize 256
+#define errormessagesize 512
+#define keybuffersize 8192
+#define fullfilenamesize 1024
+#define argumentsize 512
+#define commandlinesize 2048
+#define linesize 512
+#define filenamesize L_tmpnam
+#define ciphertextsize 16384
+#define plaintextsize 16384
+#define plugintagsize 128
+#define keyuseridsize 512
+#define keyidsize 80
+#define largebuffersize 16384
+
+#endif // __SIZE_H__
\ No newline at end of file diff --git a/GnuPG/tools.cpp b/GnuPG/tools.cpp new file mode 100644 index 0000000..fc54142 --- /dev/null +++ b/GnuPG/tools.cpp @@ -0,0 +1,316 @@ +#include "gnupgplugin.h"
+
+// escape sequence type
+struct escapesequence
+{
+ char *sequence;
+ char *code;
+};
+
+// supported escape sequences
+struct escapesequence escsequence[]=
+{
+ {"\\n", "\n"},
+ {"\\r", "\r"},
+ {"\\t", "\t"}
+};
+
+// number of supported escape sequences
+int escsequencecount=sizeof(escsequence)/sizeof(struct escapesequence);
+
+void replace(char *atext, const char *apattern, const char *areplacement)
+{
+ char *pos, *last;
+ long textsize;
+ long patternsize;
+ long replacementsize;
+
+ if (!atext || !apattern || !areplacement)
+ return;
+
+ pos=atext;
+ patternsize=strlen(apattern);
+ replacementsize=strlen(areplacement);
+
+ while (pos)
+ {
+ // textstelle suchen
+ last=pos;
+ pos=strstr(pos,apattern);
+ // etwas gefunden?
+ if (!pos)
+ break;
+ // laenge des textes ermitteln
+ textsize=strlen(last);
+ // platz schaffen
+ memmove
+ (
+ pos+replacementsize,
+ pos+patternsize,
+ textsize-((pos-last)+patternsize)+1
+ );
+ // ersetzen
+ strncpy(pos,areplacement,replacementsize);
+ pos+=replacementsize;
+ }
+}
+
+char *replace_dup(const char *atext, const char *apattern, const char *areplacement)
+{
+ if (!atext || !apattern || !areplacement)
+ return NULL;
+ size_t patlen=strlen(apattern);
+ const char *pos=atext;
+ const char *ent;
+ int i;
+ for (i=0; (ent=strstr(pos,apattern)); (pos=ent+patlen),i++);
+ size_t srcsiz=strlen(atext)+1;
+ size_t replen=strlen(areplacement);
+ size_t dstsiz=srcsiz+(replen>patlen?(replen-patlen)*i:0);
+ char *dtext=(char*)mir_alloc(dstsiz);
+ if (!dtext)
+ return NULL;
+ memcpy(dtext,atext,srcsiz);
+ replace(dtext,apattern,areplacement);
+ return dtext;
+}
+
+char *getNextPart(char *aresult, char *atext, const char *aseparator)
+ // adds to aresult an item from atext up to aseparator
+ // returns pointer to next item (or NULL)
+{
+ char *pos;
+
+ if (!aresult || !atext || !aseparator)
+ return NULL;
+
+ strcpy(aresult,"");
+ pos=strstr(atext,aseparator);
+
+ if (pos)
+ {
+ strncat(aresult,atext,pos-atext);
+ pos+=strlen(aseparator);
+ }
+ else
+ strcpy(aresult,atext);
+
+ return pos;
+}
+
+void getLastPart(char *aresult, char *atext)
+{
+ if (aresult && atext)
+ strcpy(aresult,atext);
+}
+
+void appendText(char **abuffer, const char *atext, int atextsize)
+{
+ int size;
+
+ if (!abuffer || !atext) return;
+
+ size=(*abuffer==NULL)?0:strlen(*abuffer);
+ size++; // abschliessende 0
+ if (atextsize==0)
+ atextsize=strlen(atext);
+ size+=atextsize;
+
+ *abuffer=(char*)mir_realloc(*abuffer,size);
+ strncat(*abuffer,atext,atextsize);
+}
+
+
+BOOL existsFile(const char *afilename)
+{
+ if (!afilename || strlen(afilename)==0)
+ return FALSE;
+
+ FILE *handle=fopen(afilename,"r");
+ if (!handle)
+ return FALSE;
+
+ fclose(handle);
+ return TRUE;
+}
+
+BOOL writeToFile(char *afilename, const char *atext, bool isUnicode)
+{
+ getTemporaryFileName(afilename);
+
+ FILE *handle=fopen(afilename,"wb");
+
+ if (!handle)
+ {
+ LogMessage("--- GnuPG.writeToFile: filename:",afilename,"\n");
+ return FALSE;
+ }
+
+ size_t binlen=strlen(atext)+1;
+ if (isUnicode) binlen*=(sizeof(wchar_t)+1);
+ size_t written=fwrite(atext,sizeof(char),binlen,handle);
+
+ fclose(handle);
+
+ return (written==binlen)? TRUE: FALSE;
+}
+
+long get_file_size(const char *afilename)
+{
+ FILE *handle=fopen(afilename,"rb");
+ if (!handle)
+ return -1L;
+ fseek(handle,0,SEEK_END);
+ long filesize=ftell(handle);
+ fclose(handle);
+ return filesize;
+}
+
+BOOL fnFALSE(char **ppc) // free, nullify and return FALSE
+{
+ if (!ppc) return FALSE;
+ if (*ppc) mir_free(*ppc);
+ *ppc=NULL;
+ return FALSE;
+}
+
+BOOL readFromFile(char **aresult, const char *afilename)
+ // *aresult MUST be mir_alloc memory block or NULL
+ // on error returns FALSE, frees and nullifies *aresult
+ // on success returns TRUE, caller later MUST free *aresult by hands.
+ // reads even binary files.
+ // *aresult contains the file contents appended by a byte set to 0.
+{
+ if (!aresult) return FALSE;
+ if (!afilename) return fnFALSE(aresult);
+ if (!*aresult) *aresult=(char*)mir_alloc(1);
+ if (!*aresult) return FALSE;
+
+ FILE *handle=fopen(afilename,"rb");
+ if (!handle)
+ {
+ LogMessage("--- GnuPG.readFromFile: couldn't open handle for:\n",afilename,"\n");
+ return fnFALSE(aresult);
+ }
+
+ fseek(handle,0,SEEK_END);
+ size_t filesize=ftell(handle);
+
+ if (filesize==-1L)
+ {
+ LogMessage("--- GnuPG.readFromFile: couldn't get filesize for:\n",afilename,"\n");
+ return fnFALSE(aresult);
+ }
+
+ fseek(handle,0,SEEK_SET);
+
+ *aresult=(char*)mir_realloc(*aresult,filesize+1);
+ if (!*aresult)
+ {
+ LogMessage("--- GnuPG.readFromFile: memory reallocation error for:\n",afilename,"\n");
+ return fnFALSE(aresult);
+ }
+ size_t read=fread(*aresult,sizeof(char),filesize,handle);
+ fclose(handle);
+ (*aresult)[filesize]='\0';
+
+ if (read!=filesize)
+ return fnFALSE(aresult);
+
+ return TRUE;
+}
+
+void getTemporaryFileName(char *aresult)
+{
+ char name[filenamesize];
+
+ if (!aresult) return;
+
+ strcpy(aresult,gpgTempdir);
+ tmpnam(name);
+ strcat(aresult,name);
+}
+
+void quoteEscapeSequences(char *atext)
+{
+ if (!atext) return;
+ for (int i=0; i<escsequencecount; i++)
+ replace(atext,escsequence[i].code,escsequence[i].sequence);
+}
+
+void unquoteEscapeSequences(char *atext)
+{
+ if (!atext) return;
+ for (int i=0; i<escsequencecount; i++)
+ replace(atext,escsequence[i].sequence,escsequence[i].code);
+}
+
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Unicode functions
+
+char* u2a(const wchar_t *src)
+{
+ int codepage=CallService(MS_LANGPACK_GETCODEPAGE,0,0);
+
+ int cbLen=WideCharToMultiByte(codepage,0,src,-1,NULL,0,NULL,NULL);
+ char *result=(char*)mir_alloc(cbLen+1);
+ if (!result)
+ return NULL;
+
+ WideCharToMultiByte(codepage,0,src,-1,result,cbLen,NULL,NULL);
+ result[cbLen]=0;
+ return result;
+}
+
+wchar_t* a2u(const char *src)
+{
+ int codepage=CallService(MS_LANGPACK_GETCODEPAGE,0,0);
+
+ int cbLen=MultiByteToWideChar(codepage,0,src,-1,NULL,0);
+ wchar_t *result=(wchar_t*)mir_alloc(sizeof(wchar_t)*(cbLen+1));
+ if (!result)
+ return NULL;
+
+ MultiByteToWideChar(codepage,0,src,-1,result,cbLen);
+ result[cbLen]=0;
+ return result;
+}
+
+char *fixcrlf_dup(const char *buf)
+{
+ if (!buf) return NULL;
+ char *freeofr=replace_dup(buf,"\r","");
+ if (freeofr)
+ {
+ char *tmp=replace_dup(freeofr,"\n",txtcrlf);
+ fnFALSE(&freeofr);
+ if (tmp)
+ return tmp;
+ }
+ return NULL;
+}
+
+char *makemix_dup(const char *buf)
+ // buf should be ASCIIZ
+ // returns newly allocated ASCIIZ+UCS2
+{
+ if (!buf) return NULL;
+ int binsiz=strlen(buf)+1;
+ int ascsiz=binsiz;
+ binsiz=ascsiz*(sizeof(wchar_t)+1);
+ char *mix=(char*)mir_alloc(binsiz);
+ if (mix)
+ {
+ memcpy(mix,buf,ascsiz);
+ wchar_t *wc=a2u(mix);
+ if (!wc)
+ {
+ fnFALSE(&mix);
+ return NULL;
+ }
+ memcpy(mix+ascsiz,wc,ascsiz*sizeof(wchar_t));
+ mir_free(wc);
+ }
+ return mix;
+}
diff --git a/GnuPG/tools.h b/GnuPG/tools.h new file mode 100644 index 0000000..fd92086 --- /dev/null +++ b/GnuPG/tools.h @@ -0,0 +1,31 @@ +#ifndef __TOOLS_H__
+#define __TOOLS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void replace(char *atext, const char *apattern, const char *areplacement);
+char *replace_dup(const char *atext, const char *apattern, const char *areplacement);
+char *getNextPart(char *aresult, char *atext, const char *aseparator);
+void getLastPart(char *aresult, char *atext);
+void appendText(char **abuffer, const char *atext, int atextsize=0);
+void quoteEscapeSequences(char *atext);
+void unquoteEscapeSequences(char *atext);
+
+BOOL existsFile(const char *afilename);
+BOOL writeToFile(char *afilename, const char *atext, bool isUnicode=false);
+BOOL fnFALSE(char **ppc); // mir_free *ppc, *ppc=NULL, return FALSE.
+BOOL readFromFile(char **aresult, const char *afilename);
+void getTemporaryFileName(char *aresult);
+
+char* u2a(const wchar_t *src);
+wchar_t* a2u(const char *src);
+char *fixcrlf_dup(const char *buf);
+char *makemix_dup(const char *buf);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __TOOLS_H__
diff --git a/GnuPG/userinfo.cpp b/GnuPG/userinfo.cpp new file mode 100644 index 0000000..badda80 --- /dev/null +++ b/GnuPG/userinfo.cpp @@ -0,0 +1,104 @@ +#include "gnupgplugin.h"
+
+int UserInfoInit(WPARAM wparam, LPARAM lparam)
+{
+ OPTIONSDIALOGPAGE odp;
+
+ ZeroMemory(&odp,sizeof(odp));
+ odp.cbSize=sizeof(odp);
+ odp.hInstance=dllinstance;
+ odp.pszTemplate=(char*)MAKEINTRESOURCE(IDD_USERINFO_DLG);
+ odp.pfnDlgProc=UserInfoDialogProcedure;
+ odp.pszTitle=Translate(txtgnupgplugin);
+ CallService(MS_USERINFO_ADDPAGE,wparam,(LPARAM)&odp);
+
+ return 0;
+}
+
+BOOL CALLBACK UserInfoDialogProcedure(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ char *pos;
+ HANDLE hcontact;
+ char buffer[keybuffersize];
+ char keyuserid[keyuseridsize];
+ gpgResult gpgresult;
+ DBVARIANT dbv;
+ int error;
+
+ switch (msg)
+ {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hdlg);
+
+ hcontact=(HANDLE)lparam;
+ if (hcontact==NULL)
+ {
+ ShowWindow(GetDlgItem(hdlg,IDC_KEYRECEIVED_STATIC),SW_HIDE);
+ ShowWindow(GetDlgItem(hdlg,IDC_KEYRECEIVED_EDIT),SW_HIDE);
+ ShowWindow(GetDlgItem(hdlg,IDC_KEY_EDIT),SW_HIDE);
+ ShowWindow(GetDlgItem(hdlg,IDC_IMPORT_BTN),SW_HIDE);
+ }
+ break;
+ case WM_NOTIFY:
+ switch (((LPNMHDR)lparam)->code)
+ {
+ case PSN_INFOCHANGED:
+ hcontact=(HANDLE)((PSHNOTIFY *)lparam)->lParam;
+
+ error=DBGetContactSetting(hcontact,pluginid,dbkeyuserid,&dbv);
+ if (!error) strcpy(keyuserid,dbv.pszVal);
+ else strcpy(keyuserid,"");
+ DBFreeVariant(&dbv);
+
+ if (strlen(keyuserid)!=0)
+ {
+ pos=getNextPart(buffer,keyuserid,txtidseparator);
+ SetDlgItemText(hdlg,IDC_KEYID_EDIT,(LPCTSTR)buffer);
+ getLastPart(buffer,pos);
+ SetDlgItemText(hdlg,IDC_USERID_EDIT,(LPCTSTR)buffer);
+ }
+ else
+ {
+ SetDlgItemText(hdlg,IDC_KEYID_EDIT,(LPCTSTR)Translate(txtnone));
+ EnableWindow(GetDlgItem(hdlg,IDC_KEYID_EDIT),FALSE);
+ SetDlgItemText(hdlg,IDC_USERID_EDIT,(LPCTSTR)Translate(txtnone));
+ EnableWindow(GetDlgItem(hdlg,IDC_USERID_EDIT),FALSE);
+ }
+
+ error=DBGetContactSetting(hcontact,pluginid,dbkeymodified,&dbv);
+ if (!error) strcpy(buffer,dbv.pszVal);
+ else strcpy(buffer,"");
+ DBFreeVariant(&dbv);
+ if (strlen(buffer)==0)
+ {
+ SetDlgItemText(hdlg,IDC_KEYRECEIVED_EDIT,(LPCTSTR)Translate(txtnone));
+ EnableWindow(GetDlgItem(hdlg,IDC_KEYRECEIVED_EDIT),FALSE);
+ }
+ else SetDlgItemText(hdlg,IDC_KEYRECEIVED_EDIT,(LPCTSTR)buffer);
+
+ error=DBGetContactSetting(hcontact,pluginid,dbkey,&dbv);
+ if (!error) strcpy(buffer,dbv.pszVal);
+ else strcpy(buffer,"");
+ DBFreeVariant(&dbv);
+
+ SetDlgItemText(hdlg,IDC_KEY_EDIT,(LPCTSTR)buffer);
+ if (strlen(buffer)==0)
+ EnableWindow(GetDlgItem(hdlg,IDC_IMPORT_BTN),FALSE);
+ break;
+ }
+ break;
+ case WM_COMMAND:
+ switch (LOWORD(wparam))
+ {
+ case IDC_IMPORT_BTN:
+ GetDlgItemText(hdlg,IDC_KEY_EDIT,(LPTSTR)buffer,sizeof(buffer));
+ gpgresult=gpgImportPublicKey(buffer);
+
+ if (gpgresult!=gpgSuccess)
+ ErrorMessage(txterror,txtimportpublickeyfailed,txtverifyoptions);
+ break;
+ }
+ break;
+ }
+ return 0;
+}
diff --git a/GnuPG/userinfo.h b/GnuPG/userinfo.h new file mode 100644 index 0000000..9deac88 --- /dev/null +++ b/GnuPG/userinfo.h @@ -0,0 +1,7 @@ +#ifndef __USERINFO_H__
+#define __USERINFO_H__
+
+int UserInfoInit(WPARAM wparam, LPARAM lparam);
+BOOL CALLBACK UserInfoDialogProcedure(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam);
+
+#endif // __USERINFO_H__
\ No newline at end of file |