 * Crossposted to areas PUBLIC_KEYS, MUFFIN, TUB


 For anybody who is interested, I've just recently developed some macros/batch files to get PGP and msgedsq to operate together quite nicely...

 These are the macros:  One to decrypt, and one to encrypt:

This one is to decrypt a message.

_ _ _ O / _ _ C_U_T_ H_E_R_E_ _ _ _
      O \
function 31 
\0x11^xH:\\TMP\\MSGED.TXT^m!DECRYPT^m^m\0x2e^m^m^m^my^m^m^m^m\0x77\0x1e\0x75\0x 2e\0x17^xH:\\TMP\\PGPOUT.TMP^m\0x20\0x20^m\0x75\0x48\0x20\0x17^xH:\\TMP\\MSGED^ m\0x77\0x1f
_ _ _ O / _ _ C_U_T_ H_E_R_E_ _ _ _
      O \

This one is to encrypt/sign a message (the batch file ENCRYPT presents the options of signing, encrypting, or both):

_ _ _ O / _ _ C_U_T_ H_E_R_E_ _ _ _
      O \
function 32 \0x11^xH:\\TMP\\MSGED.TXT^m!ENCRYPT^m^m\0x2e^m^m^m^my^m^m^m^m\0 x77\0x1e\0x75\0x2e\0x17^xH:\\TMP\\MSGED.ASC^m\0x1f
_ _ _ O / _ _ C_U_T_ H_E_R_E_ _ _ _
      O \

Now for an explanation of exactly what these macros do, step by step:

\0x11 - ALT-W:  Invokes the write command to export the message
^xH:\\TMP\\MSGED.TXT^m: Selects the file to write the message to.  The ^x
                        clears to the beginning of the line so that a new
                        filename can be entered.  Note that the double-slashes
                        are also necessary, since a single slash is interpreted
                        as a key-code prefix.
!DECRYPT / !ENCRYPT     Invokes a DOS batch file to perform the PGP work.  The
                        two CR's (^M^M) are necessary in order to enter the
                        command, and return to msged afterwards.
\0x2e^m^m^m^my^m^m^m^m: Invokes the Change-message routine (ALT-C).  The reason
                        for all the carriage returns is to bypass the header.
                        These are repeated twice in case msged prompts you to
                        confirm editing an already-sent message.  Extraneous
                        lines that end up in the message text because of this
                        are cleared out next.
\0x77\0x1e\0x75\0x2e:   This sequence is CTRL-HOME, ALT-A, CTRL-END, and ALT-C.
                        This will cut the existing text, from beginning to end
                        from the message.
\0x17^xH:\\TMP\\MSGED^m This invokes the ALT-I function to import a file
                        into the editor.  The file that is imported is either
                        the plaintext (MSGED), or the armored ASCII text after
                        signing/encrypting (MSGED.ASC).
\0x1f                   This is the ALT-S (Save Message) function.

 Note also that in the decryption routine, another file, PGPOUT.TMP, is imported before the decrypted message, and some editing functions are performed on it in order to just leave a block at the top of the message that indicates that the sender's signature has been verified.  \0x20 is ALT-D (Delete line), \0x75 is CTRL-END (end of message), and \0x48 is the UP arrow.  The resulting content of PGPOUT.TMP that is left in the message looks as follows:

_ _ _ O / _ _ C_U_T_ H_E_R_E_ _ _ _
      O \
Good signature from user "Jesse David Hollington <1:225/1.1@fidonet.org>".
Signature made 1992/11/07 23:46 GMT

------------ P L A I N   T E X T   F O L L O W S ------------
_ _ _ O / _ _ C_U_T_ H_E_R_E_ _ _ _
      O \

 Note also that the separator line is a function of the batch file, and may be easily changed.

 Now for the batch files:

 Here is DECRYPT.BTM (note that commands are 4DOS/NDOS specific, with some
 editing, they can probably be made to work with normal MS-DOS). 

_ _ _ O / _ _ C_U_T_ H_E_R_E_ _ _ _
      O \
CLS

REM This is a 4DOS/NDOS Command that saves the current directory.
PUSHD

REM This is a 4DOS/NDOS command that changes both current drive and directory
CDD H:\TMP

REM These two commands clean up any files left over in the work directory
IF EXIST MSGED ZAP MSGED /Q >NUL
IF EXIST MSGED.PGP ZAP MSGED.PGP /Q >NUL

REM This line decrypts the message (if it's encrypted) but leaves the
REM signature block intact.  This is necessary so that the signature
REM certification message can be added to the plaintext.  If the message
REM is not encrypted, but only signed, the MSGED.PGP file will still be
REM created.  Note that MSGED.PGP is created as a binary (non-armored) file.
REM Obviously if the message is neither signed nor encrypted, nothing will
REM occur.
PGP -d MSGED.TXT MSGED.PGP

REM This line will then validate the signature on the message.  It takes
REM MSGED.PGP as input (which is produced by the last command), and output
REM is redirected to PGPOUT.TMP, to later be included with the plaintext.
REM The final product of this command is a file called MSGED (no extension).
REM If the file MSGED.PGP contains no signature, MSGED will not be produced.
PGP MSGED.PGP >PGPOUT.TMP

REM This will delete the PGPOUT.TMP file if no signature was present on the
REM message, since the only purpose of PGPOUT.TMP is to add the text validation
REM block to the plaintext output.
IF NOT EXIST MSGED ZAP PGPOUT.TMP /Q >NUL

REM This nested IFF statement will copy either the decrypted plaintext, or the
REM original text, in the event that either no signature is present, or the
REM message wasn't encrypted to begin with.  This is necessary since there is
REM no way to check within msged as to what kind of operation PGP has performed REM (therefore msged will run the change-message routine and try to import the
REM file MSGED regardless of outcome of PGP's operation).
IFF NOT EXIST MSGED THEN 
    IF EXIST MSGED.PGP COPY MSGED.PGP MSGED >NUL
    IF NOT EXIST MSGED.PGP COPY MSGED.TXT MSGED >NUL
ENDIFF

REM This line adds a tear line between the validation text and the plain text. IF EXIST PGPOUT.TMP ECHO ------------ P L A I N   T E X T   F O L L O W S ------------ >>PGPOUT.TMP

REM This is a 4DOS/NDOS command to restore the current directory. POPD 
_ _ _ O / _ _ C_U_T_ H_E_R_E_ _ _ _
      O \

 Here is ENCRYPT.BTM (again note the 4DOS/NDOS specific commands.  This one
 would be a little more difficult to run with MS-DOS because of the menu it
 uses).

_ _ _ O / _ _ C_U_T_ H_E_R_E_ _ _ _
      O \

CLS

REM TEXT and ENDTEXT define the menu to be displayed.
TEXT

  S) Sign Message
  E) Encrypt Message
  B) Sign & Encrypt
  Q) Quit back to msged
        
ENDTEXT

REM This is actually a Norton BE command that prompts the user for a choice
REM and returns an errorlevel based upon the user's choice.
BE ASK "Choice:",SEBQ

REM These errorlevels set the command-line switches for PGP based upon the
REM user's choice.
IF ERRORLEVEL 1 SET SW=-SW
IF ERRORLEVEL 2 SET SW=-EW
IF ERRORLEVEL 3 SET SW=-SEW
IF ERRORLEVEL 4 GOTO END

CLS
PUSHD
CDD H:\TMP
REM This line erases the old MSGED.ASC output file, if it exists.
IF EXIST MSGED.ASC ZAP MSGED.ASC /Q >NUL
REM This runs PGP with the options defined above in the SW environment var.
PGP %SW MSGED.TXT

REM This end routing is used if the user selects the Q)uit option, or if 
REM PGP didn't produce a MSGED.ASC file for whatever other reason.  It copies
REM the original plaintext into the MSGED.ASC file so that the original message
REM will be preserved.
:END
IF NOT EXIST MSGED.ASC COPY MSGED.TXT MSGED.ASC >NUL
POPD

_ _ _ O / _ _ C_U_T_ H_E_R_E_ _ _ _
      O \

 It should be noted that there are a couple other important things that must be done for this to work properly.  Obviously, PGP, DECRYPT.BTM, and ENCRYPT.BTM have to be available on the DOS path.  It is also recommended that a RAM drive be used for the intermediate files, as this will speed up operation a bit.  Most importantly, however, the kludge lines have to be turned off before the macro runs.  Since the kludge option is toggled with ALT-V (keycode \0x2f) in msgedsq, there is no way to definitely determine whether they are on or off before the macro is executed.  I run mine off by default using a startup macro in msgedsq, but if you want your kludge lines *on* by default, then the "\0x2f" sequence should be added at the beginning and end of the macro.  If the kludge lines are on, it doesn't really create any problem beyond a minor nuisance (they'll be encrypted with the rest of the plaintext).

 It is also important to note that only the PGP block from a message will be included in the output.  If there is any text before or after the PGP block, it will be lost.  Unfortunately, I haven't found a way to deal with this yet.  If anybody else finds a way, I'd appreciate hearing about it.

 Lastly, the DECRYPT sequence can also be used to import public keys or keyrings from the PKEY_DROP area (or wherever else) onto your keyring. 

 I hope this is useful to those of you who run PGP and msgedsq together.  Feel free to expand upon these and let me know how they work.  I'd also appreciate hearing any problems so I can clear them up.

Cheers,
 Jesse.
 

--- msgedsq 2.1
 * Origin: Net 225 Command Post (1:225/1.1)
