[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Poco Forums • View topic - GnuPG signing and encrypting script

GnuPG signing and encrypting script

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

GnuPG signing and encrypting script

Postby chgerwig » Wed Sep 15, 2004 9:40 pm

Hi all,

since I posted my verifying and decryting script here is the counterpart my signing and encryting script:
Code: Select all
{ ### GnuPG (Version 1.2.4) sign and encrypt Mail Body
{ by Christian Gerwig <christian@gerwig.com> last change: 16.09.04
{ Script to sign an outgoing message with the ability to control the script via
{ the User Header.
{ By default every message will be signed. If you don't like this feature uncomment line 19
{ If no secret key is available for the address the script aborts
{ If you want to control it go to the optional tab in the compose
{ window and in the "User Header" field enter
{       pgp: n  -> no pgp for the message
{       pgp: s  -> for signing the message
{       pgp: e  -> for encrypting the message
{
{ !!! Make sure to update the path to your gpg.exe in the next line for your system!!!
set $GPGexe "c:\programme\gnupg\gpg.exe"

ReadHeader $pgp "pgp:" %message
If "n" ^ $pgp then end
If "s" ^ $pgp then sign_message
If "e" ^ $pgp then encrypt_message
{Exit

:sign_message
ReadRawBody $a %message
AddStrings $SIGFile $ScriptPath "sigtemp.txt"
SaveBody $a $SIGFile
ReadEmail $From
set $command "--default-key "
AddStrings $command $From " --clearsign " $ScriptPath "sigtemp.txt"
ExecuteAndWait $GPGexe $command #error
if #error > 0 then error_sign
AddStrings $ASCFile $ScriptPath "sigtemp.asc"
OpenBody $a $ASCFile
AssignBody %message $a
DeleteFile $SIGFile
DeleteFile $ASCFile
Exit

:encrypt_message
ReadRawBody $a %message
AddStrings $SIGFile $ScriptPath "sigtemp.txt"
SaveBody $a $SIGFile
ReadTo $t %message
GetLine $To 0 $t
Set $Email $To
set $command "-r "
AddStrings $command $To " -a --encrypt " $ScriptPath "sigtemp.txt"
ExecuteAndWait $GPGexe $command #error
if #error > 0 then error_encrypt
AddStrings $ASCFile $ScriptPath "sigtemp.asc"
OpenBody $a $ASCFile
AssignBody %message $a
DeleteFile $SIGFile
DeleteFile $ASCFile
Exit

:error_sign
Set $e "Signing ERROR! No secret key found for "
AddStrings $e $From
MessageBox $e
DeleteFile $SIGFile
Exit

:error_encrypt
Set $e "Encryting ERROR! No public key found for "
AddStrings $e $To
MessageBox $e
DeleteFile $SIGFile

:end
Exit


You only have to place in the user defined header fields pgp and the letter what you want to do with this message. By default all messages are signed. I think this is a good idea during these days where spam and viruses are filling our mailboxes.
Do not forget to set the filter for all outgoing mails to run this script.

I hope you like it. Suggestions and corrections are welcome.
Bye,
Christian
------------
Reseller of PocoMail in Austria
chgerwig
Poco Tourist
 
Posts: 17
Joined: Tue Aug 24, 2004 12:27 am
Location: Vienna, Austria

Postby Michael » Thu Sep 16, 2004 2:35 am

Two comments:
  1. You could save the user from having to edit the script by changing the Set $GPGexe to use the External command (e.g.,
    Code: Select all
    External $GPGexe "Enter path and name of the GPG executable" "C:\Programme\GNupg\gpg.exe"
    Note: This should be tested, I seem to recall problems with setting path variables in this way, from what I remember the backslashes are treated as escape characters, you could use forward slashes instead.
  2. I notice that you set the "$EMail" variable (line 44) but never actually use it.
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby Hogyt » Thu Sep 16, 2004 3:04 am

It looks good! I like the fact you're examining the return code with ExecuteAndWait. Along similar lines to Michaels comments, you could use an External to control the "By default every message will be signed" option instead of editing the code. You could also add a general error handler using "Set $OnErrorGoTo". I'd use double backslashes instead of using single ones or forward slashes.

Keep up the good work!!
Mat
Hogyt
Poco Enthusiast
 
Posts: 241
Joined: Thu Jul 29, 2004 11:22 am
Location: England

gnupg setting up

Postby evilc77 » Sun Oct 17, 2004 3:39 pm

"You only have to place in the user defined header fields pgp and the letter what you want to do with this message. By default all messages are signed. "

Sorry but you have lost me with the above, I can't get it to work please help .
Clive
evilc77
Drop-in Visitor
 
Posts: 5
Joined: Thu Oct 14, 2004 8:38 am

Postby chgerwig » Mon Oct 18, 2004 12:14 am

Hi evilc77!

Here is my latest script where you have only to put a 'y' in the Setup Script and your path to the gpg.exe than it should work.

Code: Select all
{ ### GnuPG (Version 1.2.4) sign and encrypt Mail Body
{ by Christian Gerwig <christian@gerwig.com> last change: 17.09.04
{ Script to sign or encrypt an outgoing message with the ability to control the script via
{ the User Header.
{
{ !!! Make sure to update the path to your gpg.exe in script setup !!!
{ In the sript setup you can choose if you want to sign every message by default or not.
{
{ If no secret key is available for the address the script aborts and gives you a message
{ If you want to control it go to the optional tab in the compose
{ window and in the "User Header" field enter
{       pgp: n  -> no pgp for this message
{       pgp: s  -> for signing this message
{       pgp: e  -> for encrypting this message
{
External $GPGexe "Enter the path and filename of your gpg.exe" "c:\\programme\\gnupg\\gpg.exe"
External $SignAll "Do you wish to sign all your messages by default? (Yes or No)" "Yes"

ReadHeader $pgp "pgp:" %message
If "n" ^ $pgp then end
If "s" ^ $pgp then sign_message
If "e" ^ $pgp then encrypt_message

:sign_message
If "No" ^ $SignAll then end
ReadRawBody $a %message
AddStrings $SIGFile $ScriptPath "sigtemp.txt"
SaveBody $a $SIGFile
ReadEmail $From
set $command "--default-key "
AddStrings $command $From " --clearsign " $ScriptPath "sigtemp.txt"
ExecuteAndWait $GPGexe $command #error
if #error > 0 then error_sign
AddStrings $ASCFile $ScriptPath "sigtemp.asc"
OpenBody $a $ASCFile
AssignBody %message $a
DeleteFile $SIGFile
DeleteFile $ASCFile
Exit

:encrypt_message
ReadRawBody $a %message
AddStrings $SIGFile $ScriptPath "sigtemp.txt"
SaveBody $a $SIGFile
ReadTo $t %message
GetLine $To 0 $t
set $command "-r "
AddStrings $command $To " -a --encrypt " $ScriptPath "sigtemp.txt"
ExecuteAndWait $GPGexe $command #error
if #error > 0 then error_encrypt
AddStrings $ASCFile $ScriptPath "sigtemp.asc"
OpenBody $a $ASCFile
AssignBody %message $a
DeleteFile $SIGFile
DeleteFile $ASCFile
Exit

:error_sign
Set $e "Signing ERROR! No secret key found for "
AddStrings $e $From
MessageBox $e
DeleteFile $SIGFile
Exit

:error_encrypt
Set $e "Encryting ERROR! No public key found for "
AddStrings $e $To
MessageBox $e
DeleteFile $SIGFile

:end
Exit
Bye,
Christian
------------
Reseller of PocoMail in Austria
chgerwig
Poco Tourist
 
Posts: 17
Joined: Tue Aug 24, 2004 12:27 am
Location: Vienna, Austria

Postby evilc77 » Mon Oct 18, 2004 11:37 am

Thanks the new script seems to work, now all I have to do is figure out why I get "Signing ERROR! No secret key found". I know Gnupg works as I have used it with other email progs.
Thanks again for the quick response.
Clive
evilc77
Drop-in Visitor
 
Posts: 5
Joined: Thu Oct 14, 2004 8:38 am

Postby chgerwig » Mon Oct 18, 2004 7:06 pm

You have to know that the GPG looks at the senders email address and take the relevant key for it.

So you will get this error, when you try to send and sign an email with an email address where you do not have a secret key for it.
Bye,
Christian
------------
Reseller of PocoMail in Austria
chgerwig
Poco Tourist
 
Posts: 17
Joined: Tue Aug 24, 2004 12:27 am
Location: Vienna, Austria

It works, but ....

Postby NoName » Sun Jan 30, 2005 2:42 pm

Hi,

thanks for posting this pocoscript ;-) I need a few minutes to get a Message encrypted and it works.

After I send the message, the message is also encyptet at my sent - box.
For Exampel:

-----BEGIN PGP MESSAGE----- Version: GnuPG v1.2.1 (MingW32) hQIOA2n2CHCaGyZAEAf9Hd3t9+Ubm/OmKh/OxoVVNbYl0SneKFs7hVxrp5qRSE+t h3QeES9whsM9wgtm5cm4O2PUtWDp7jsZMvMHnj3ymkq9aOUxlEqnYB3DmY4ztQJJ bMa5X1C28rKA4MUVPfIf5flz13SqyMA5HsoCUdWg4czRw0Tu24NEjVLBMkxsgbYN Lp+iY7nOncoTqFIuO77Q6CzVUVb7 =75eR -----END PGP MESSAGE-----

The problem is now, if I have to change something or I have to read the message again how can I decrypt the old message ?

Thanks in advance
NoName
New Arrival
 
Posts: 2
Joined: Wed Jan 26, 2005 3:23 pm

Postby tryforsure » Wed Feb 22, 2006 3:23 am

evilc77 wrote:Thanks the new script seems to work, now all I have to do is figure out why I get "Signing ERROR! No secret key found". I know Gnupg works as I have used it with other email progs.
Thanks again for the quick response.


I had this as well and i solved it by using quotes in the long file name thats created

In the script just add escaped quotes ie: change line 31 to
AddStrings $command $From " --clearsign " """ $ScriptPath "sigtemp.txt" """

Also my gpg, 1.4.3-cvs, always creates a new file with these default options i had to change line 34 to
AddStrings $ASCFile $ScriptPath "sigtemp.txt.asc"

note the .asc at the end

sorry forgot to say you have to do this with the encrypt section as well lines 48 and 51!
tryforsure
Drop-in Visitor
 
Posts: 9
Joined: Sun Dec 18, 2005 10:24 pm
Location: Scotland


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 1 guest

cron