home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / gcppgp12.zip / gcppgpfe.zip / gcppgpfe.e < prev   
Text File  |  1996-04-22  |  78KB  |  2,017 lines

  1. /***************************************************************************
  2.  
  3.   Program:      GCPPGPFE.E Version 1.2
  4.  
  5.   Author:       John C. Frickson
  6.  
  7.   Copyright:    Copyright (c) 1994-1996 by Gibbon Computer Products
  8.                 All rights reserved.
  9.  
  10.   Description:
  11.  
  12.         Front end for PGP (Pretty Good Privacy) 2.6.x
  13.  
  14.         This E macro will build a menu containing various options for
  15.         executing PGP.  When a menu item is selected, the corresponding
  16.         command is run.
  17.  
  18.   Notes for the Security Conscious:
  19.  
  20.         Uses temporary files
  21.         Passphrase stored in memory
  22.  
  23.   Not Implemented:
  24.  
  25.         see if wipefile (-w) does any good
  26.         sign and conventionally encrypt?
  27.         the esoteric commands           ???????
  28.  
  29. r = WinMessageBox('Debug', 'Message', 16416)
  30.  
  31.  ***************************************************************************/
  32.  
  33. include 'stdconst.e'
  34.  
  35. /************
  36.   Constants
  37. ************/
  38. const
  39.    Copyright = 'GCP PGP Front-End'\10 ||
  40.                'Copyright 1994-1996 by Gibbon Computer Products'\10 ||
  41.                'All rights reserved'\10
  42.    PGP_P  = \1'PGP operations'
  43.    ENCN_P = \1'Encryption operations'
  44.    ENCR_P = \1'Encrypt the selected text'
  45.    ENCS_P = \1'Encrypt and sign the selected text'
  46.    ENCC_P = \1'Encrypt the selected text using Conventional encryption'
  47.    INCL_P = \1'Operations to include public key or fingerprint'
  48.    IKEY_P = \1'Include public key at the current cursor position'
  49.    IFNG_P = \1'Include fingerprint at the current cursor position'
  50.    SIGN_P = \1'Sign the selected text'
  51.    DECR_P = \1'Decrypt and display the message'
  52.    CSIG_P = \1'Check for a valid signature'
  53.    DFLT_P = \1'Toggle default settings on or off'
  54.    CLPW_P = \1'Erase Password from EPM memory'
  55.    SLCT_P = \1'Select which public and secret keyrings will be used'
  56.    SELS_P = \1'Select which secret keyring to use'
  57.    SELP_P = \1'Select which public keyring to use'
  58.    VIEW_P = \1'View the contents of your keyrings'
  59.    VPRN_P = \1'View the contents of your public keyring'
  60.    VPRV_P = \1'Verbose view the contents of your public keyring'
  61.    VPRT_P = \1'View public keyring IDs, signatures, trust, and validity'
  62.    VPRF_P = \1'View fingerprints from your public keyring'
  63.    VSRN_P = \1'View the contents of your secret keyring'
  64.    VSRV_P = \1'Verbose view the contents of your secret keyring'
  65.    VSRT_P = \1'View public keyring IDs, signatures, trust, and validity'
  66.    VSRF_P = \1'View fingerprints from your secret keyring'
  67.    MGMT_P = \1'Key management operations'
  68.    KADD_P = \1'Add the currently displayed key to your public keyring'
  69.    KGEN_P = \1'Generate public/secret key pair (OS/2 Command Shell)'
  70.    KRED_P = \1'Edit your user id or secret ring passphrase (OS/2 Command Shell)'
  71.    TRST_P = \1'Edit trust parameters for a public key (OS/2 Command Shell)'
  72.    REMV_P = \1'Remove a key from your keyring (OS/2 Command Shell)'
  73.    KSGN_P = \1'Sign and certify a key on public ring (OS/2 Command Shell)'
  74.    RMSG_P = \1'Remove selected signatures from a key (OS/2 Command Shell)'
  75.    REVK_P = \1'Permantly revoke your key (OS/2 Command Shell)'
  76.    KDBL_P = \1'Enable or Disable a key on public ring (OS/2 Command Shell)'
  77.    HELP_P = \1'PGP Help operations'
  78.    PHLP_P = \1'Display the PGP Help file'
  79.    ABOT_P = \1'Display the "About" dialog'
  80.  
  81.  
  82. /*********************************
  83.   Execute this on initialization
  84. *********************************/
  85. definit
  86.    universal vTEMP_PATH                             -- Path for temporary file - Predefined
  87.    universal activemenu, defaultmenu
  88.    universal pgp_armor, pgp_textmode,
  89.              pgp_clearsig, pgp_uselang
  90.    universal sec_name, sec_keyid, sec_pswd, pub_keyid, pub_name
  91.    universal pgp_pubring, pgp_curpubring
  92.    universal pgp_secring
  93.    universal pgp_randseed, pgp_config
  94.    universal pgp_path, pgp_found
  95.    universal pgp_cmd, pgp_opts
  96.  
  97.    sec_keyid = ''
  98.    sec_name  = ''
  99.    sec_pswd = ''
  100.    pub_keyid = ''
  101.    pub_name  = ''
  102.    pgp_path = Strip(Get_Env('PGPPATH'))
  103.    sec_pswd = Strip(Get_Env('PGPPASS'))
  104.    pgp_found = 1
  105.    if RightStr(pgp_path,1) = '\' then
  106.       pgp_path = LeftStr(pgp_path, Length(pgp_path) - 1)
  107.     endif
  108.    pgp_cmd = 'PGP +bat +int=off +pa=cat +verb=0'
  109.    pgp_opts = '+la=en +cl -at'
  110.  
  111.    pgp_armor       = 1                  -- -a option
  112.    pgp_textmode    = 1                  -- -t option
  113.    pgp_clearsig    = 1                  -- +clearsig
  114.    pgp_uselang     = 1                  -- +la=en
  115.  
  116.    pgp_pubring     = pgp_path'\pubring.pgp'
  117.    pgp_curpubring  = pgp_path'\pubring.pgp'
  118.    pgp_secring     = pgp_path'\secring.pgp'
  119.    pgp_randseed    = pgp_path'\randseed.bin'
  120.    pgp_config      = ''
  121.  
  122.    deletemenu defaultmenu, 6, 0, 0  -- delete the existing Help menu
  123.                                     -- (we want it to stay at the right)
  124.  
  125. ; ****> Create the PGP menu
  126.  
  127.    buildsubmenu  defaultmenu,    70,      'P~GP',                              PGP_P,                  0, 0
  128.    buildmenuitem defaultmenu,    70, 710, '~Encrypt or Sign',                  ENCN_P,                17, 0
  129.       buildmenuitem defaultmenu, 70, 711, '~Encrypt Text'\9'-e',               'PGPEncr -e'ENCR_P,     0, 0
  130.       buildmenuitem defaultmenu, 70, 712, '~Sign Text'\9'-s',                  'PGPEncr -s'SIGN_P,     0, 0
  131.       buildmenuitem defaultmenu, 70, 713, 'Encrypt ~and Sign'\9'-se',          'PGPEncr -se'ENCS_P,    0, 0
  132.       buildmenuitem defaultmenu, 70, 714, '~Conventional Encryption'\9'-c',    'PGPEncr -c'ENCC_P, 32769, 0
  133.    buildmenuitem defaultmenu,    70, 720, '~Include Key or Fingerprint',       INCL_P,                17, 0
  134.       buildmenuitem defaultmenu, 70, 721, 'Include ~Public Key'\9'-kx',        'PGPIncKey x'IKEY_P,    0, 0
  135.       buildmenuitem defaultmenu, 70, 722, 'Include Key ~Fingerprint'\9'-kvc',  'PGPIncKey vc'IFNG_P,32769,0
  136.    buildmenuitem defaultmenu,    70, 729,  \0,                                 '',                     4, 0
  137.    buildmenuitem defaultmenu,    70, 730, '~Decrypt Message',                  'PGPDecr d'DECR_P,      0, 0
  138.    buildmenuitem defaultmenu,    70, 731, '~Check Signature',                  'PGPDecr c'CSIG_P,      0, 0
  139.    buildmenuitem defaultmenu,    70, 739,  \0,                                 '',                     4, 0
  140.    buildmenuitem defaultmenu,    70, 740, 'Cha~nge Defaults',                  'PGPDflt'DFLT_P,        0, 0
  141.    buildmenuitem defaultmenu,    70, 741, 'Clear ~Password',                   'PGPClrPw'CLPW_P,       0, 0
  142.    buildmenuitem defaultmenu,    70, 750, 'Select ~Keyrings',                  SLCT_P,                17, 0
  143.       buildmenuitem defaultmenu, 70, 751, '~Secret Keyring',                   'PGPRing s'SELS_P,      0, 0
  144.       buildmenuitem defaultmenu, 70, 752, '~Public Keyring',                   'PGPRing p'SELP_P,  32769, 0
  145.    buildmenuitem defaultmenu,    70, 759,  \0,                                 '',                     4, 0
  146.    buildmenuitem defaultmenu,    70, 760, '~View Keyring',                     VIEW_P,                17, 0
  147.       buildmenuitem defaultmenu, 70, 761, 'Pubring ~Normal'\9'-kv',            'PGPKV p v'VPRN_P,      0, 0
  148.       buildmenuitem defaultmenu, 70, 762, 'Pubring ~Verbose'\9'-kvv',          'PGPKV p vv'VPRV_P,     0, 0
  149.       buildmenuitem defaultmenu, 70, 763, 'Pubring ~Trust/Validity'\9'-kc',    'PGPKV p c'VPRT_P,      0, 0
  150.       buildmenuitem defaultmenu, 70, 764, 'Pubring ~Fingerprint'\9'-kvc',      'PGPKV p vc'VPRF_P,     0, 0
  151.       buildmenuitem defaultmenu, 70, 765, 'Secring Nor~mal'\9'-kv',            'PGPKV s v'VSRN_P,      0, 0
  152.       buildmenuitem defaultmenu, 70, 766, 'Secring Ver~bose'\9'-kvv',          'PGPKV s vv'VSRV_P,     0, 0
  153.       buildmenuitem defaultmenu, 70, 767, 'Secring Fing~erprint'\9'-kvc',      'PGPKV s vc'VSRF_P, 32769, 0
  154.    buildmenuitem defaultmenu,    70, 770, 'Key ~Management',                   MGMT_P,                17, 0
  155.       buildmenuitem defaultmenu, 70, 771, '~Add Key to Pubring'\9'-ka',        'PGPAddKey a'KADD_P,    0, 0
  156.       buildmenuitem defaultmenu, 70, 772, '(S) ~Generate a Key'\9'-kg',        'PGPKMgt s g'KGEN_P,    0, 0
  157.       buildmenuitem defaultmenu, 70, 773, '(S) ~Edit UserID or Passphrase'\9'-ke','PGPKMgt s e'KRED_P, 0, 0
  158.       buildmenuitem defaultmenu, 70, 774, '(S) Edit ~Trust Parameters'\9'-ke', 'PGPKMgt p e'TRST_P,    0, 0
  159.       buildmenuitem defaultmenu, 70, 775, '(S) ~Remove a Key'\9'-kr',          'PGPKMgt p r'REMV_P,    0, 0
  160.       buildmenuitem defaultmenu, 70, 776, '(S) ~Sign and certify a Key'\9'-ks','PGPKMgt p s'KSGN_P,    0, 0
  161.       buildmenuitem defaultmenu, 70, 777, '(S) Re~move signatures'\9'-krs',    'PGPKMgt p rs'RMSG_P,   0, 0
  162.       buildmenuitem defaultmenu, 70, 778, '(S) Revo~ke your key'\9'-kd',       'PGPKMgt s d'REVK_P,    0, 0
  163.       buildmenuitem defaultmenu, 70, 779, '(S) ~Disable/enable a key'\9'-kd',  'PGPKMgt p d'KDBL_P,32769, 0
  164.    buildmenuitem defaultmenu,    70, 780,  \0,                                 '',                     4, 0
  165.    buildmenuitem defaultmenu,    70, 781, '~Help',                              HELP_P,               17, 0
  166.       buildmenuitem defaultmenu, 70, 782, 'PGP ~Help',                         'PGPHelp'PHLP_P,        0, 0
  167.       buildmenuitem defaultmenu, 70, 783, '~About...',                         'PGPAbout'ABOT_P,   32769, 0
  168.  
  169.    call readd_help_menu()           -- Add the Help menu back in
  170.  
  171.    showmenu defaultmenu             -- Ta da!
  172.  
  173.  
  174. /******************************
  175.   Execute this on termination
  176. ******************************/
  177. defexit
  178.    universal defaultmenu, activemenu
  179.    deletemenu defaultmenu,700,0,0
  180.    call maybe_show_menu()
  181.  
  182.  
  183. /************************
  184.   Display PGP Help (-h)
  185. ************************/
  186. defc PGPHelp=
  187.    if pgp_checkrings() = 0 then
  188.       return
  189.    endif
  190.    sayerror 'Getting help.  Please wait...'  -- Information message
  191.    refresh                                   -- Make sure the message is displayed
  192.    r = pgp_redirect('-h')               -- pass commands to routine the does the work
  193.    if r = 'ERROR' then
  194.       return
  195.    endif
  196.    .filename='/PGP Help/'                    -- change the title line
  197.    if .last=0 then                           -- if the output window
  198.       'q'                                    --    has no lines, then quit
  199.       sayerror 'Unable to display help!'     --    and give a message
  200.    endif
  201.  
  202.  
  203. /***************************
  204.   Display the About dialog
  205. ***************************/
  206. defc PGPAbout=
  207.  
  208.    r = WinMessageBox('About Gibbon PGP Front End v1.2',
  209.                         'Copyright (c) 1994-1996 by ' ||
  210.                         'Gibbon Computer Products'\10 ||
  211.                         'All rights reserved'\10\10 ||
  212.                         'Gibbon PGP Front End v1.2'\10 ||
  213.                         'EPM, Lamail, and NR/2 interface '||
  214.                         'to PGP Version 2.6.x.  See the ' ||
  215.                         'README for more information.'\10\10 ||
  216.                         'John C. Frickson <frickson@gibbon.com>', 16432)
  217. ; MB_OK           = 0
  218. ; MB_ICONASTERISK = 48
  219. ; MB_INFORMATION  = MB_ICONASTERISK
  220. ; MB_MOVEABLE     = 16384
  221.    x = pgp_checkrings()
  222.  
  223.  
  224. /******************************************************************************
  225.   View either public or secret keyring, normal (-kv) or verbose (-kvv) or
  226.   trust/validity (-kc) or fingerprints (-kvc)
  227. ******************************************************************************/
  228. defc PGPKV=
  229.    universal pgp_curpubring, pgp_secring
  230.  
  231.    arg1 = Word(arg(1),1)
  232.    arg2 = Word(arg(1),2)
  233.  
  234.    switch = '-k'arg2
  235.  
  236.    if pgp_checkrings() = 0 then
  237.       return
  238.    endif
  239.  
  240.    user = EntryBox('Enter user id, key id or "*" for all', '', '*', 30, 128)
  241.    if user = '' then
  242.       Return
  243.    endif
  244.    if LeftStr(user,1) <> '"' then
  245.       user = '"' || user || '"'
  246.    endif
  247.  
  248.    sayerror 'Getting Keyring Information.  Please wait...'  -- Information message
  249.    refresh                                   -- Make sure the message is displayed
  250.  
  251.    if arg1 = 'p' then
  252.       pubsec = 'Public'
  253.       r = pgp_redirect(switch user pgp_curpubring)  -- pass commands to routine the does the work
  254.       if r = 'ERROR' then
  255.          return
  256.       endif
  257.    else
  258.       pubsec = 'Secret'
  259.       r = pgp_redirect(switch user pgp_secring)  -- pass commands to routine the does the work
  260.       if r = 'ERROR' then
  261.          return
  262.       endif
  263.    endif
  264.  
  265.    If arg2 = 'vv' then
  266.       temp = '/Verbose'
  267.    elseif arg2 = 'vc' then
  268.       temp = '/Fingerprint'
  269.    elseif arg2 = 'c' then
  270.       temp = '/Trust and Validity'
  271.    else
  272.       temp = '/Normal'
  273.    endif
  274.  
  275.    .filename=temp 'Listing of' pubsec 'Keyring/'      -- change the title line
  276.    if .last=0 then                           -- if the output window
  277.       'q'                                    --    has no lines, then quit
  278.       sayerror 'Unable to view keyring!'     --    and give a message
  279.    endif
  280.  
  281.  
  282. /***********************************************
  283.   Select which public or secret keyring to use
  284. ***********************************************/
  285. defc PGPRing=
  286.    universal pgp_curpubring, pgp_secring
  287.  
  288.    message = 'Changing public or secret keyrings will ' ||
  289.              'NOT change which keyrings are used for '  ||
  290.              'encryption.  This is only for key '       ||
  291.              'management and viewing purposes!'
  292.    r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  293. ;                                      MB_INFORMATION = 48
  294. ;                                      MB_MOVEABLE    = 16384
  295.  
  296.    if arg(1) = 'p' then
  297.       temp1 = pgp_curpubring
  298.       temp2 = 'Public'
  299.    else
  300.       temp1 = pgp_secring
  301.       temp2 = 'Secret'
  302.    endif
  303.  
  304.    kr = EntryBox('Enter' temp2 'Keyring Filename', '/~OK/~Cancel', temp1, 30, 128)
  305.    if kr <> '' then
  306.       if pgp_checkrings() = 0 then
  307.          return
  308.       endif
  309.       if arg(1) = 'p' then
  310.          pgp_curpubring = kr
  311.       else
  312.          pgp_secring = kr
  313.       endif
  314.       if pgp_checkrings() = 0 then
  315.          if arg(1) = 'p' then
  316.             pgp_curpubring = temp1
  317.          else
  318.             pgp_secring = temp1
  319.          endif
  320.          return
  321.       endif
  322.       if arg(1) = 's' then
  323.          pgp_get_sec_id()
  324.       endif
  325.       sayerror temp2 'Keyring is now:' kr
  326.    endif
  327.  
  328.  
  329. /************************************************************
  330.   Put up a listbox that allows toggling of default settings
  331. ************************************************************/
  332. defc PGPDflt=
  333.  
  334.    universal pgp_armor, pgp_textmode,
  335.              pgp_clearsig, pgp_uselang
  336.    universal pgp_cmd, pgp_opts
  337.  
  338.    if pgp_checkrings() = 0 then
  339.       return
  340.    endif
  341.  
  342.    message = 'By default, Gibbon PGP Front End turns on ' ||
  343.              'Armor, Textmode and Clearsig, and sets the '||
  344.              'language to English.  If you toggle these ' ||
  345.              'OFF, the defaults from your CONFIG.TXT '    ||
  346.              'file will be used.'                         ||
  347.              \10\10'This may not mean these options are ' ||
  348.              'OFF!  Check your CONFIG.TXT for the '       ||
  349.              'default status.'
  350.    r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  351. ;                                      MB_INFORMATION = 48
  352. ;                                      MB_MOVEABLE    = 16384
  353.  
  354.    one = atoi(1)
  355.    zero = atoi(0)
  356.  
  357.    tpgp_armor       = pgp_armor
  358.    tpgp_textmode    = pgp_textmode
  359.    tpgp_clearsig    = pgp_clearsig
  360.    tpgp_uselang     = pgp_uselang
  361.  
  362.    Do Forever
  363.  
  364.       if tpgp_armor then
  365.          pgpoptn = '^ASCII Armor (-a) is ON'
  366.       else
  367.          pgpoptn = '^ASCII Armor (-a) is OFF'
  368.       endif
  369.       if tpgp_textmode then
  370.          pgpoptn = pgpoptn || '^Text mode (-t) is ON'
  371.       else
  372.          pgpoptn = pgpoptn || '^Text mode (-t) is OFF'
  373.       endif
  374.       if tpgp_clearsig then
  375.          pgpoptn = pgpoptn || '^Clear sig (+clearsig) is ON'
  376.       else
  377.          pgpoptn = pgpoptn || '^Clear sig (+clearsig) is OFF'
  378.       endif
  379.       if tpgp_uselang then
  380.          pgpoptn = pgpoptn || '^Language (+la=en) is ON'
  381.       else
  382.          pgpoptn = pgpoptn || '^Language (+la=en) is OFF'
  383.       endif
  384.  
  385.       parse value listbox('Gibbon PGP Processing Defaults',
  386.                            pgpoptn,
  387.                           '/~OK/~Cancel/~Toggle',
  388.                           0, 0, 4, 40,
  389.                           compile if EVERSION >= 5.60 --gethwndc(APP_HANDLE)
  390.                              zero || zero || one || one || zero ||
  391.                           compile else                --gethwndc(APP_HANDLE)
  392.                              one || one || zero || zero || zero ||
  393.                           compile endif
  394.                           'Toggle Options On or Off -- CAREFULLY!!') with button 2 text \0
  395.  
  396.       btn = itoa(button || \0, 10)
  397.  
  398.       if btn < '3' then
  399.          leave
  400.       endif
  401.  
  402.       test = Word(text,1) || Word(text,Words(text))
  403.  
  404.       if test = 'ASCIION' then
  405.          tpgp_armor = 0
  406.       elseif test = 'ASCIIOFF' then
  407.          tpgp_armor = 1
  408.       elseif test = 'TextON' then
  409.          tpgp_textmode = 0
  410.       elseif test = 'TextOFF' then
  411.          tpgp_textmode = 1
  412.       elseif test = 'ClearON' then
  413.          tpgp_clearsig = 0
  414.       elseif test = 'ClearOFF' then
  415.          tpgp_clearsig = 1
  416.       elseif test = 'LanguageON' then
  417.          tpgp_uselang = 0
  418.       elseif test = 'LanguageOFF' then
  419.          tpgp_uselang = 1
  420.       endif
  421.  
  422.    EndDo
  423.  
  424.    if btn = '1' then
  425.       pgp_armor       = tpgp_armor
  426.       pgp_textmode    = tpgp_textmode
  427.       pgp_clearsig    = tpgp_clearsig
  428.       pgp_uselang     = tpgp_uselang
  429.       if pgp_clearsig then
  430.          pgp_opts = '+cl'
  431.       else
  432.          pgp_opts = '+cl=off'
  433.       endif
  434.       if pgp_armor then
  435.          pgp_opts = pgp_opts '-a'
  436.       endif
  437.       if pgp_textmode then
  438.          if pgp_armor then
  439.             pgp_opts = pgp_opts || 't'
  440.          else
  441.             pgp_opts = pgp_opts '-t'
  442.          endif
  443.       endif
  444.       if pgp_uselang then
  445.          pgp_opts = pgp_opts '+la=en'
  446.       endif
  447.    endif
  448.  
  449.  
  450. /***************************************
  451.    Clear Password from memory
  452. ***************************************/
  453. defc PGPClrPW=
  454.    universal sec_name, sec_pswd
  455.    sec_name = ''
  456.    sec_pswd = ''
  457.    message = 'Password has been cleared from memory'
  458.    r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  459. ;                                      MB_INFORMATION = 48
  460. ;                                      MB_MOVEABLE    = 16384
  461.  
  462.  
  463. /****************************************************
  464.   Include public key or fingerprint in message text
  465.   arg   vc  fingerprint
  466.         x   public key
  467. ****************************************************/
  468. defc PGPIncKey=
  469.    universal pgp_curpubring, pgp_secring
  470.    universal sec_name, pub_keyid, pub_name
  471.    universal pgp_cmd, pgp_opts
  472.  
  473.    if pgp_checkrings() = 0 then
  474.       return
  475.    endif
  476.  
  477.    switch = '-k'arg(1)
  478.  
  479. /* select public key */
  480.    pgp_get_pub_id(0)
  481.    if pub_keyid = '' then
  482.       return
  483.    endif
  484.  
  485.    sayerror 'Getting Keyring Information.  Please wait...'  -- Information message
  486.    refresh                                   -- Make sure the message is displayed
  487.  
  488.    Display -3                                -- turn off display updates and error messages
  489.    GetFileID msgFileID                       -- get fileid of current message
  490.  
  491.    r = pgp_redirect(pgp_opts switch pub_keyid pgp_curpubring)
  492.    if r = 'ERROR' then
  493.       Display 3                              -- enable display updates and messages
  494.       return
  495.    endif
  496.    GetFileID tempFileID                    -- get fileid of processed text file
  497.  
  498. /* Here we parse stderr looking for errors and warnings */
  499.    lastline = .last
  500.    Do line = 1 to lastline
  501.       GetLine viewline, line, tempFileID
  502.       if rc < 0 then
  503.          Display 3                           -- enable display updates and messages
  504.          sayerror 'unexpected EOF during parse of stderr'
  505.          Return
  506.       endif
  507.  
  508. -- handle case of unknown error, we search for the error flag \007
  509.       if Pos('', viewline) > 0 then
  510.          message = viewline
  511.          'q'                               -- leave stderr
  512.          ActivateFile msgFileID            -- activate the original file
  513.          Display 3                         -- enable display updates and messages
  514.          refresh
  515.          r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  516. ;                                            MB_INFORMATION = 48
  517. ;                                            MB_MOVEABLE    = 16384
  518.          Return
  519.  
  520. -- else, get next line of stderr
  521.       else
  522.          iterate
  523.       endif
  524.    EndDo /* getline */
  525.  
  526. -- Normally we exit this way if no errors found in stderr
  527.  
  528.    if .last=0 then                           -- if the output window
  529.       'q'                                    --    has no lines, then quit
  530.       Display 3                              --    enable display updates and messages
  531.       sayerror 'PGP returned nothing for the selected key!'  --    and give a message
  532.       Return
  533.    endif
  534.  
  535.    ActivateFile msgFileID                    -- activate the original file
  536.    EndLine                                   -- Go to the end of the line
  537.    Split                                     -- Start a new line
  538.    Down                                      -- Move down one line
  539.  
  540.    copyflag = 0
  541.  
  542.    do lnum = 1 to tempFileID.last            -- Copy the lines from the temp file
  543.       Getline xferline, lnum, tempFileID     --    output from PGP command
  544.       if LeftStr(xferline,10) = '-----BEGIN' then
  545.          copyflag = 1
  546.       endif
  547.       if copyflag then
  548.          InsertLine xferline                 --  into the current file
  549.       endif
  550.       if LeftStr(xferline,10) = 'Type bits/' then
  551.          InsertLine xferline                 --  into the current file
  552.       endif
  553.       if LeftStr(xferline,4) = 'pub ' then
  554.          InsertLine xferline                 --  into the current file
  555.       endif
  556.       if Pos('Key fingerprint', xferline) > 0 then
  557.          xferline = strip(xferline)      --  strip off leading spaces
  558.          InsertLine xferline                 --  into the current file
  559.       endif
  560.       if LeftStr(xferline,8) = '-----END' then
  561.          copyflag = 0
  562.       endif
  563.    EndDo
  564.  
  565.    ActivateFile tempFileID                   -- activate the temp file
  566.    'q'                                       -- quit the file
  567.    ActivateFile msgFileID                    -- activate the original file
  568.    display 3                                 -- turn updates & messages on
  569.    refresh
  570.  
  571.    message = 'Inserted'
  572.    if arg(1) = 'vc' then
  573.       message = message 'fingerprint'
  574.    else
  575.       message = message 'public key'
  576.    endif
  577.    message = message ' for' pub_name
  578.    r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  579. ;                                      MB_INFORMATION = 48
  580. ;                                      MB_MOVEABLE    = 16384
  581.  
  582.  
  583. /************************************
  584.   Encrypt or Sign the selected text
  585.   -s sign
  586.   -e encrypt
  587.   -se sign and encrypt
  588.   -c conventional encrypt
  589. ************************************/
  590. defc PGPEncr=
  591.    universal vTEMP_PATH
  592.    universal pgp_pubring, pgp_secring
  593.    universal pgp_armor, pgp_textmode,
  594.              pgp_clearsig
  595.    universal sec_name, sec_keyid, sec_pswd, pub_keyid, pub_name
  596.    universal pgp_opts
  597.  
  598.    if pgp_checkrings() = 0 then
  599.       return
  600.    endif
  601.  
  602.    bad_pswd = 0
  603.  
  604.    switch = arg(1)
  605.  
  606.    if switch = '-s' then
  607.       function = 'Sign'
  608.    else
  609.       function = 'Encrypt'
  610.    endif
  611.    message = function'ing in progress -- Please wait...'
  612.  
  613. -- check if user marked text to encrypt/sign
  614.    PSAVE_MARK(savemark)
  615.    parse value savemark with firstl lastl firstc lastc fileid marktyp
  616.    SETMARK firstl, lastl, 1, LongestLine(), 1, fileid
  617.  
  618.    if (marktyp = '') then
  619.       r = WinMessageBox('Gibbon PGP Front End',
  620.                         'I can''t' function 'anything without knowing what ' ||
  621.                         'to' function'.  Please mark the appropriate text.', 16416)
  622. ;                                                                MB_CUAWARNING = 32
  623. ;                                                                MB_MOVEABLE   = 16384
  624.       return
  625.    endif
  626.  
  627.    if (.line = 0) then
  628.       .line = 1
  629.    endif
  630.  
  631. -- get secret key if signing
  632.    if Pos('s', switch) > 0 then
  633.       -- Always get the secret key id (changed from v1.0) --
  634.       pgp_get_sec_id()            -- sets global variables sec_keyid and sec_name
  635.       if sec_keyid = '' then      -- make sure didn't fail
  636.          return
  637.       endif
  638.    endif
  639.  
  640. -- get public key if encrypting
  641.    if Pos('e', switch) > 0 then
  642.       pgp_get_pub_id(1)           -- sets global variables pub_keyid and pub_name
  643.       if pub_keyid = '' then      -- make sure didn't fail
  644.          return
  645.       endif
  646.    endif
  647.  
  648. -- check for a revoked key
  649.    if pub_name = '*** KEY REVOKED ***' then
  650.       message = 'Key ID:' pub_keyid || \10\10
  651.       message = message || 'This key has been *REVOKED*' || \10
  652.       message = message || 'so you can not use this key!'
  653.       r = WinMessageBox('Gibbon PGP Front End', message, 16416)
  654. ;                                        MB_CUAWARNING = 32
  655. ;                                        MB_MOVEABLE   = 16384
  656.       return
  657.    endif
  658.  
  659. -- get passphrase if signing
  660.    if Pos('s', switch) > 0 then
  661.       if sec_pswd = '' then
  662. compile if EVERSION > 6.01
  663.          pass = EntryBox('Enter your passphrase', '/OK/Cancel', '', 30, 1024, '', 140)
  664. compile else
  665.          pass = EntryBox('Enter your passphrase', '/OK/Cancel', '', 30, 1024)
  666. compile endif
  667.          if pass = '' then
  668.             Return
  669.          endif
  670.          sec_pswd = pass
  671.       endif
  672.    endif
  673.  
  674. -- get passphrase if encrypting conventionally
  675.    if switch = '-c' then
  676. compile if EVERSION > 6.01
  677.       pgp_convpswd = EntryBox('Enter passphrase for conventional encryption',
  678.                             '/~OK/~Cancel', '', 30, 1024, '', 140)
  679. compile else
  680.       pgp_convpswd = EntryBox('Enter passphrase for conventional encryption',
  681.                             '/~OK/~Cancel', '', 30, 1024)
  682. compile endif
  683.       if pgp_convpswd = '' then
  684.          Return
  685.       endif
  686.     endif
  687.  
  688.    sayerror message
  689.  
  690.    Display -3                              -- turn off display updates and error messages
  691.    GetFileID msgFileID                     -- get fileid of current message
  692.    save_modify = msgFileID.modify          -- save the modified flag
  693.    outfile=vTEMP_PATH || 'pgpfe.out'       -- Build the file name for the temp file
  694.    call erasetemp(outfile)                 -- clear out any leftover temp file
  695.    'e' outfile                             -- open it
  696.    MoveMark                                -- move the marked text to the outfile window
  697.    's'                                     -- save the temporary file
  698.    GetFileID outFileID
  699.  
  700.    sayerror message
  701.  
  702. -- switch can have values -e -se -s -c (encrypt, sign&encrypt, sign, conventional)
  703.    cmdline = switch
  704.    if Pos('c', switch) > 0 then
  705.       cmdline = cmdline '-z"'pgp_convpswd'" '
  706.    endif
  707.    if Pos('s', switch) > 0 then
  708.       cmdline = cmdline '-z"'sec_pswd'" '
  709.    endif
  710.    if Pos('e', switch) > 0 then
  711.       cmdline = cmdline  pub_keyid || ' '
  712.    endif
  713.    if Pos('s', switch) > 0 then
  714.       cmdline = cmdline || '-u 'sec_keyid' '
  715.    endif
  716.  
  717.    cmdline = cmdline || '<' outfile
  718.  
  719.    r = pgp_redirect(pgp_opts cmdline)
  720.    call erasetemp(outfile)                 -- and delete the temp file
  721.  
  722.    sayerror 'Processing complete.'
  723.  
  724.    if r = 'ERROR' then
  725.       UnMark
  726.       ActivateFile outFileID
  727.       SETMARK 1, .last, 1, LongestLine(), 1, outFileID
  728.       ActivateFile msgFileID               -- activate the original file
  729.       CopyMark                             -- restore the moved text
  730.       ActivateFile outFileID
  731.       'q'                                  -- quit the file
  732.       ActivateFile msgFileID               -- activate the original file
  733.       Display 3                            -- enable display updates and messages
  734.       refresh
  735.       return
  736.    endif
  737.  
  738.    GetFileID tempFileID                    -- get fileid of processed text file
  739.    lastline = .last
  740.    ActivateFile msgFileID                  -- activate the original file
  741.  
  742.    copyflag = 0
  743.    copied = 0
  744.  
  745. -- this routine copies message portion of stdout to original message file
  746.    Do line = 1 to lastline
  747.       GetLine xferline, line, tempFileID
  748.       if LeftStr(xferline,10) = '-----BEGIN' then
  749.          copyflag = 1
  750.       endif
  751.       if copyflag then
  752.          InsertLine xferline
  753.          copied = 1
  754.       endif
  755.       if LeftStr(xferline,8) = '-----END' then
  756.          copyflag = 0
  757.       endif
  758.    End
  759.  
  760. -- if message was not copied from stdout file, then something bad happened,
  761. -- most likely a bad passphrase was given
  762. -- first thing we do is restore message file back to original condition
  763.    if copied = 0 then
  764.       UnMark
  765.       ActivateFile outFileID
  766.       SETMARK 1, .last, 1, LongestLine(), 1, outFileID
  767.       ActivateFile msgFileID               -- activate the original file
  768.       CopyMark                             -- restore the text
  769.       msgFileID.modify = save_modify       -- reset modified flag
  770.    end
  771.  
  772.    ActivateFile outFileID
  773.    'q'                                     -- quit the file
  774.    ActivateFile msgFileID                  -- activate the original file
  775.    Unmark
  776.  
  777.    Display 3                               -- enable display updates and messages
  778.    refresh
  779.  
  780. -- summarize what was accomplished...
  781. -- if copied=0 then some error occurred
  782.    if copied = 0 then
  783.       errlineno = 2
  784.       GetLine errorline, errlineno, tempFileID
  785.       chkline = UpCase(errorline)
  786.       if Pos('ERROR',chkline) then
  787.          message = 'PGP Detected an error while attempting ' ||
  788.                    'to encrypt or sign this message.  The '  ||
  789.                    'error message is:'\10\10
  790.          While Length(errorline) > 3 Do
  791.             if LeftStr(errorline,1) = \7 then
  792.                errorline = RightStr(errorline, Length(errorline) - 1)
  793.             endif
  794.             if LeftStr(errorline,24) = "Error:  Bad pass phrase." then
  795.                sec_pswd = ''
  796.                bad_pswd = 1
  797.             endif
  798.             message = message || errorline || \10
  799.             errlineno = errlineno + 1
  800.             if errlineno > tempFileID.last then
  801.                Leave
  802.             endif
  803.             GetLine errorline, errlineno, tempFileID
  804.          EndWhile
  805.  
  806.       else
  807.          message = 'The requested action was not performed, and ' ||
  808.                    'the reason is unknown.  Make sure you are '   ||
  809.                    'executing an OS/2 version of PGP, that your ' ||
  810.                    'PATH/PGPPATH are correct, and your keyrings ' ||
  811.                    'are valid.  If you can''t figure out the '    ||
  812.                    'problem, contact frickson@gibbon.com.'
  813.       endif
  814.  -- copied != 0 so pgp was successful at something
  815.    else
  816.       message = 'This message has been'
  817.       if Pos('s', switch) > 0 then
  818.          if Pos('e', switch) then
  819.             message = message || \10
  820.          endif
  821.          message = message 'signed by' sec_name
  822.       endif
  823.       if Pos('e', switch) then
  824.          if Pos('s', switch) > 0 then
  825.             message = message || \10\10'and'
  826.          endif
  827.          message = message 'encrypted using the public key for' pub_name
  828.       endif
  829.       if switch = '-c' then
  830.          message = message \10'conventionally encrypted.'
  831.       endif
  832.    endif
  833.    ActivateFile tempFileID                 -- activate the temporary file
  834.    'q'                                     -- quit the file
  835.    ActivateFile msgFileID                  -- activate the original file
  836.    refresh
  837.    if bad_pswd then
  838.       message = message || \10\10 || 'Please try again.'
  839.    endif
  840.    r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  841. ;                                      MB_INFORMATION = 48
  842. ;                                      MB_MOVEABLE    = 16384
  843.  
  844.  
  845. /***************************************
  846.   Decrypt message or check a signature
  847.     -c  check signature
  848.     -d  decrypt
  849. ***************************************/
  850. defc PGPDecr=
  851.    universal vTEMP_PATH
  852.    universal pgp_pubring, pgp_secring
  853.    universal pgp_armor, pgp_textmode,
  854.              pgp_clearsig
  855.    universal sec_name, sec_keyid, sec_pswd
  856.  
  857.    if pgp_checkrings() = 0 then
  858.       return
  859.    endif
  860.  
  861.    needconvpswd = 0
  862.    needpswd = 0
  863.  
  864.    Display -3                              -- turn off display updates and error messages
  865.  
  866.    Do Forever
  867.  
  868.       -- This would only happen on the 2nd go-around (or 3rd...) and
  869.       -- would happen because the message being decrypted was conventionally
  870.       -- encrypted and needs a pass phrase, or because the message was
  871.       -- encrypted with a public key.  On the 3rd+ time, it would be
  872.       -- needed because an incorrect pass phrase was entered.
  873.  
  874.       if needconvpswd then
  875. compile if EVERSION > 6.01
  876.          pgp_convpswd = EntryBox('Enter passphrase for conventional encryption',
  877.                                '/~OK/~Cancel', '', 30, 1024, '', 140)
  878. compile else
  879.          pgp_convpswd = EntryBox('Enter passphrase for conventional encryption',
  880.                                '/~OK/~Cancel', '', 30, 1024)
  881. compile endif
  882.          if pgp_convpswd = '' then
  883.             Display 3                      -- enable display updates and messages
  884.             Return
  885.          endif
  886.       endif
  887.  
  888.       if needpswd then
  889.          if sec_pswd = '' then
  890. compile if EVERSION > 6.01
  891.             pass = EntryBox('Enter your passphrase', '/OK/Cancel', '',
  892.                             30, 1024, '', 140)
  893. compile else
  894.             pass = EntryBox('Enter your passphrase', '/OK/Cancel', '', 30, 1024)
  895. compile endif
  896.             if pass = '' then
  897.                Display 3                      -- enable display updates and messages
  898.                Return
  899.             endif
  900.             sec_pswd = pass
  901.          endif
  902.       endif
  903.  
  904.       GetFileID msgFileID                     -- get fileid of current message
  905.  
  906.       lastline = .last
  907.       Do line = 1 to lastline
  908.          GetLine curline, line
  909.          startcol = Pos('-----BEGIN PGP', curline)
  910.          if startcol > 0 then
  911.             leave
  912.          endif
  913.       End
  914.  
  915.       if startcol = 0 then
  916.          r = WinMessageBox('Gibbon PGP Front End',
  917.                            'This does not appear to be a PGP ' ||
  918.                            'encrypted or signed message', 16432)
  919. ;                                            MB_INFORMATION = 48
  920. ;                                            MB_MOVEABLE    = 16384
  921.          Display 3                      -- enable display updates and messages
  922.          Return
  923.       endif
  924.  
  925. --      SETMARK 1, .last, 1, LongestLine(), 1, msgFileID  -- Mark the whole message
  926.       SETMARK line, .last, startcol, LongestLine(), 2, msgFileID  -- Mark the whole message
  927.       outfile=vTEMP_PATH || 'pgpfe.out'       -- Build the file name for the temp file
  928.       'e' outfile                             -- open it
  929.       CopyMark                                -- copy the marked text to the outfile window
  930.       's'                                     -- save the temporary file
  931.       'q'                                     -- exit the temporary window
  932.       sayerror 'Processing in progress...'
  933.  
  934. -- conventional decryption
  935.       if needconvpswd then
  936.          cmdline = '-z"'pgp_convpswd'" <' outfile
  937. -- public key decryption
  938.       elseif needpswd then
  939.          cmdline = '-z"'sec_pswd'" <' outfile
  940. -- signature check
  941.       else
  942.          cmdline = ' <' outfile
  943.       endif
  944.  
  945. -- option -t for textmode files
  946.       r = pgp_redirect('+la=en -t' cmdline)   -- pass commands to routine that does the work
  947.       sayerror 'Processing complete.'
  948.       call erasetemp(outfile)                 -- and delete the temp file
  949.       if r = 'ERROR' then
  950.          ActivateFile msgFileID               -- activate the original file
  951.          Display 3                            -- enable display updates and messages
  952.          return
  953.       endif
  954.       GetFileID tempFileID                    -- get fileid of processed text file
  955.  
  956.       .filename='/Unencrypted Message/'       -- change the title line
  957.       viewline=""
  958.       GetLine viewline, 2, tempFileID         -- get line 2 (error or 'good sig' message)
  959.  
  960. /* Here we are looking for success, or errors and warnings
  961.    The types of information we look for are as follows...
  962.  
  963.   1) good signature:
  964.      'Good signature from user'
  965.   2) Can't check signature cause we don't have the key
  966.      'Key matching expected Key ID'
  967.   3) encrypted so passphrase needed
  968.      'You need a pass phrase to unlock your RSA secret key.'
  969.   4) bad pass phrase
  970.      'Error:  Bad pass phrase." then
  971.   5) missing secret key to decrypt
  972.      ' You do not have the secret key'
  973.   6) bad signature:
  974.      'Bad signature from user '
  975.   7) damaged file:
  976.      'Error: Transport armor stripping failed'
  977.   8) Unknown error decrypting file:
  978.      'Error:'
  979. */
  980.  
  981. -- handle case of good signature
  982.       if LeftStr(viewline,24) = 'Good signature from user' then
  983.          message = viewline
  984.          GetLine viewline, 3, tempFileID
  985.          message = message || \10viewline
  986.          if arg(1) = 'c' then                 -- if we're only checking the sig
  987.             'q'                               -- leave the file
  988.             ActivateFile msgFileID            -- activate the original file
  989.          endif
  990.          if arg(1) <> 'c' then                -- if we're not only checking the sig
  991.             Do line = 1 to 3
  992.                DeleteLine 1, tempFileID
  993.             End
  994.             tempFileID.modify = 0             -- reset the modified flag
  995.          endif
  996.          Display 3                            -- enable display updates and messages
  997.          refresh
  998.          r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  999. ;                                            MB_INFORMATION = 48
  1000. ;                                            MB_MOVEABLE    = 16384
  1001.          Return
  1002.  
  1003. -- handle case of not having key to check for valid signature
  1004.       elseif LeftStr(viewline, 29) = 'Key matching expected Key ID' then
  1005.          message = RightStr(viewline, Length(viewline) - 1)
  1006.          GetLine viewline, 6, tempFileID
  1007.          Do line = 1 to 6
  1008.             DeleteLine 1, tempFileID
  1009.          End
  1010.          tempFileID.Modify = 0                -- reset the modified flag
  1011.          message = message || \10\10viewline
  1012.          if arg(1) = 'c' then                 -- if we're only checking the sig
  1013.             'q'                               -- leave the file
  1014.             ActivateFile msgFileID            -- activate the original file
  1015.          endif
  1016.          r = WinMessageBox('Gibbon PGP Front End', message, 16416)
  1017. ;                                            MB_CUAWARNING = 32
  1018. ;                                            MB_MOVEABLE   = 16384
  1019.          Display 3                            -- enable display updates and messages
  1020.          Return
  1021.  
  1022. -- handle case of needing a passphrase to continue
  1023. -- (this will be the case for any encrypted file)
  1024.       elseif LeftStr(viewline,22) = 'You need a pass phrase' then
  1025.          'q'                                  -- leave the file
  1026.          ActivateFile msgFileID               -- activate the original file
  1027.          if needconvpswd then
  1028.             message = 'Apparently, the pass phrase you entered ' ||
  1029.                       'didn''t work.'
  1030.          else
  1031.             message = 'This is a conventionally encrypted file.  ' ||
  1032.                       'A pass phrase must be entered to decrypt '  ||
  1033.                       'it.'
  1034.          endif
  1035.          message = message ||
  1036.                    \10\10'Enter the pass phrase in the next '   ||
  1037.                    'dialog, or press the Cancel button if you ' ||
  1038.                    'don''t want to try to decrypt the file.'
  1039.  
  1040.          r = WinMessageBox('Gibbon PGP Front End', message, 16416)
  1041. ;                                           MB_CUAWARNING = 32
  1042. ;                                           MB_MOVEABLE   = 16384
  1043.          needconvpswd = 1
  1044.  
  1045. -- handle the case of a bad pass phrase
  1046.       elseif LeftStr(viewline,25) = "Error:  Bad pass phrase." then
  1047.          'q'                                  -- leave the file
  1048.          ActivateFile msgFileID               -- activate the original file
  1049.          if needpswd then
  1050.             message = 'Apparently, the pass phrase you entered didn''t work.' ||
  1051.                       \10\10'Enter the pass phrase in the next '   ||
  1052.                       'dialog, or press the Cancel button if you ' ||
  1053.                       'don''t want to try to decrypt the file.'
  1054.  
  1055.             r = WinMessageBox('Gibbon PGP Front End', message, 16416)
  1056. ;                                              MB_CUAWARNING = 32
  1057. ;                                              MB_MOVEABLE   = 16384
  1058.             sec_pswd = ''
  1059.          endif
  1060.          needpswd = 1
  1061.  
  1062. -- handle case of not having the necessary secret key to decrypt
  1063.       elseif LeftStr(viewline,33) = 'This message can only be read by:' then
  1064.          GetLine vl2, 3, tempFileID
  1065.          message = viewline || vl2
  1066.          GetLine vl2, 5, tempFileID
  1067.          message = message || \10\10 || vl2
  1068.          'q'                                  -- leave the file
  1069.          ActivateFile msgFileID               -- activate the original file
  1070.          Display 3                            -- enable display updates and messages
  1071.          refresh
  1072.          r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  1073. ;                                               MB_INFORMATION = 48
  1074. ;                                               MB_MOVEABLE    = 16384
  1075.          Return
  1076.  
  1077. -- handle case of bad signature
  1078.       elseif LeftStr(viewline,23) = 'Bad signature from user' then
  1079.          message = 'WARNING: ' || viewline
  1080.          GetLine viewline, 3, tempFileID      -- get line 3 ("signature made" message)
  1081.          message = message || \10viewline
  1082.          if arg(1) = 'c' then                 -- if we're only checking the sig
  1083.             'q'                               -- leave the file
  1084.             ActivateFile msgFileID            -- activate the original file
  1085.          endif
  1086.          Display 3                            -- enable display updates and messages
  1087.          refresh
  1088.          r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  1089. ;                                               MB_INFORMATION = 48
  1090. ;                                               MB_MOVEABLE    = 16384
  1091.          Return
  1092.  
  1093. -- handle case of damaged file
  1094.       elseif LeftStr(viewline,40) = 'Error: Transport armor stripping failed' then
  1095.          message = 'ERROR: file has been damaged or tampered with and PGP could not continue.'
  1096.          'q'                                  -- leave the file
  1097.          ActivateFile msgFileID               -- activate the original file
  1098.          Display 3                            -- enable display updates and messages
  1099.          refresh
  1100.          r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  1101. ;                                               MB_INFORMATION = 48
  1102. ;                                               MB_MOVEABLE    = 16384
  1103.          Return
  1104.  
  1105. -- handle case of unknown error
  1106.       elseif LeftStr(viewline,7) = 'Error:' or LeftStr(viewline,6) = 'Error:' then
  1107.          message = 'ERROR: an unexpected error has occurred:'
  1108.          viewline = RightStr(viewline,Length(viewline) - 1)
  1109.          message = message || \10 || viewline
  1110.          'q'                               -- leave the file
  1111.          ActivateFile msgFileID            -- activate the original file
  1112.          Display 3                            -- enable display updates and messages
  1113.          refresh
  1114.          r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  1115. ;                                               MB_INFORMATION = 48
  1116. ;                                               MB_MOVEABLE    = 16384
  1117.          Return
  1118.  
  1119. -- Normally we exit this way after decrypting a file
  1120. -- that has not been signed, but we need to trap the
  1121. -- case where we only wanted to check the signature
  1122. -- and the file turns out to be unsigned.
  1123.       else
  1124.          if arg(1) = 'c' then                 -- if we're only checking the sig
  1125.             'q'                               -- leave the file
  1126.             ActivateFile msgFileID            -- activate the original file
  1127.             message = 'WARNING: File has not been signed, could not verify ' ||
  1128.                       'signature'
  1129.             Display 3                         -- enable display updates and messages
  1130.             refresh
  1131.             r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  1132. ;                                               MB_INFORMATION = 48
  1133. ;                                               MB_MOVEABLE    = 16384
  1134.          endif
  1135.  
  1136.          Display 3                            -- enable display updates and messages
  1137.          Return
  1138.       endif
  1139.  
  1140.    EndDo
  1141.    Display 3                                  -- enable display updates and messages
  1142.  
  1143.  
  1144. /****************************
  1145.   Add key to public Keyring
  1146. ****************************/
  1147. defc PGPAddKey=
  1148.    universal vTEMP_PATH
  1149.    universal pgp_pubring, pgp_secring,
  1150.              pgp_curpubring
  1151.    universal pgp_armor, pgp_textmode,
  1152.              pgp_clearsig
  1153.    universal sec_name, sec_pswd
  1154.    universal pgp_cmd, pgp_opts
  1155.  
  1156.    if pgp_checkrings() = 0 then
  1157.       return
  1158.    endif
  1159.  
  1160.    switch = '-k'arg(1)
  1161.    GetFileID msgFileID                     -- get fileid of current message
  1162.  
  1163.    Display -3                              -- turn off display updates and error messages
  1164.  
  1165.    if arg(1) = 'a' then
  1166.       lastline = .last
  1167.       startkey = 0
  1168.       endkey   = 0
  1169.       Do line = 1 to lastline
  1170.          GetLine curline, line
  1171.          if curline = '-----BEGIN PGP PUBLIC KEY BLOCK-----' then
  1172.             startkey = line
  1173.          elseif curline = '-----END PGP PUBLIC KEY BLOCK-----' then
  1174.             endkey = line
  1175.          endif
  1176.       End
  1177.  
  1178.       if startkey = 0 or endkey = 0 then
  1179.          message = 'I couldn''t find a public key ' ||
  1180.                    'block anywhere in this message!'
  1181.          r = WinMessageBox('Gibbon PGP Front End', message, 16416)
  1182. ;                                           MB_CUAWARNING = 32
  1183. ;                                           MB_MOVEABLE   = 16384
  1184.          Display 3                            -- enable display updates and messages
  1185.          return
  1186.       else
  1187.          message = 'WARNING: All new keys and signatures will ' ||
  1188.                    'be added to your public key ring WITHOUT '  ||
  1189.                    'asking if you want to add each key.'\10\10  ||
  1190.                    'ALSO, any *existing* bad or malformed '     ||
  1191.                    'signatures will be DELETED!'
  1192.          r = WinMessageBox('Gibbon PGP Front End', message, 16416)
  1193. ;                                           MB_CUAWARNING = 32
  1194. ;                                           MB_MOVEABLE   = 16384
  1195.          message = 'Keys and signatures will be added to ' ||
  1196.                    pgp_curpubring \10\10'Do you want to continue?'
  1197.          r = WinMessageBox('Gibbon PGP Front End', message, 16404)
  1198. ;                                           MB_YESNO        = 4
  1199. ;                                           MB_ICONQUESTION = 16
  1200. ;                                           MB_MOVEABLE     = 16384
  1201.          if r = 7 then   -- MBID_NO is 7
  1202.             Display 3                            -- enable display updates and messages
  1203.             return
  1204.          endif
  1205.  
  1206. ;         SETMARK startkey, endkey, 1, 65, 2, msgFileID  -- Mark the key block
  1207.          SETMARK startkey, endkey, 1, 65, 1, msgFileID  -- Mark the key block
  1208.          outfile=vTEMP_PATH || 'pgpfe.out'    -- Build the file name for the temp file
  1209.          'e' outfile                             -- open it
  1210.          CopyMark                                -- copy the key block to the outfile window
  1211.          's'                                     -- save the temporary file
  1212.          'q'                                     -- exit the temporary window
  1213.  
  1214.          cmdline = switch pgp_curpubring '<' outfile
  1215.          r = pgp_redirect(pgp_opts cmdline)
  1216.          call erasetemp(outfile)                 -- and delete the temp file
  1217.          if r = 'ERROR' then
  1218.             ActivateFile msgFileID               -- activate the original file
  1219.             Display 3                            -- enable display updates and messages
  1220.             return
  1221.          endif
  1222.  
  1223.          GetFileID tempFileID                    -- get fileid of results file
  1224.          ActivateFile msgFileID                  -- activate the original file
  1225.          UnMark
  1226.  
  1227.          ActivateFile tempFileID                 -- activate the temporary file
  1228.          .filename = '/Results of Key Add (-ka) Processing/'
  1229.          GetLine curline, 3
  1230.          If curline = 'No new keys or signatures in keyfile.' then
  1231.             'q'                                  -- quit the file
  1232.             ActivateFile msgFileID               -- activate the original file
  1233.             r = WinMessageBox('Gibbon PGP Front End', curline, 16416)
  1234. ;                                              MB_CUAWARNING = 32
  1235. ;                                              MB_MOVEABLE   = 16384
  1236.             Display 3                            -- enable display updates and messages
  1237.             return
  1238.          endif
  1239.  
  1240.          GetLine curline, 1
  1241.          if LeftStr(curline,6) = 'ERROR:' then
  1242.             message = 'PGP Detected an error while attempting ' ||
  1243.                       'to add this key to' pgp_curpubring'.'\10 ||
  1244.                       \10'The error message is:'\10\10          ||
  1245.                       RightStr(curline, Length(curline) - 7)
  1246.             'q'                                  -- quit the file
  1247.             ActivateFile msgFileID               -- activate the original file
  1248.             r = WinMessageBox('Gibbon PGP Front End', message, 16416)
  1249. ;                                              MB_CUAWARNING = 32
  1250. ;                                              MB_MOVEABLE   = 16384
  1251.             Display 3                            -- enable display updates and messages
  1252.             return
  1253.          endif
  1254.  
  1255.  
  1256.       endif
  1257.  
  1258.    Endif
  1259.  
  1260.    Display 3                            -- enable display updates and messages
  1261.  
  1262.  
  1263. /**************************
  1264.   Key Management Commands
  1265. **************************/
  1266. defc PGPKMgt=
  1267.    universal vTEMP_PATH
  1268.    universal pgp_pubring, pgp_secring,
  1269.              pgp_curpubring
  1270.    universal pgp_armor, pgp_textmode,
  1271.              pgp_clearsig
  1272.    universal sec_name, sec_pswd, pub_keyid, pub_name
  1273.  
  1274.    arg1 = Word(arg(1),1)
  1275.    arg2 = Word(arg(1),2)
  1276.  
  1277.    if arg2 <> 'g' then
  1278.       if pgp_checkrings() = 0 then
  1279.          return
  1280.       endif
  1281.    endif
  1282.  
  1283.    switch = '-k'arg2
  1284.  
  1285.    if arg1 = 'p' then                      -- Public key ring management commands
  1286.       pgp_get_pub_id(0)
  1287.       if pub_keyid = '' then
  1288.          return
  1289.       endif
  1290.  
  1291.       if arg2 = 'e' then
  1292.          message = 'Edit Trust Parameters for'
  1293.       elseif arg2 = 'r' then
  1294.          message = 'Remove the key for'
  1295.       elseif arg2 = 's' then
  1296.          message = 'Sign and Certify the key for'
  1297.       elseif arg2 = 'rs' then
  1298.          message = 'Remove a signature from'
  1299.       elseif arg2 = 'd' then
  1300.          message = 'Disable or Enable the key for'
  1301.       endif
  1302.  
  1303.       message = 'You are about to' message pub_name ||
  1304.                 ' on your public keyring:' pgp_curpubring
  1305.  
  1306.    else
  1307.  
  1308.       if arg2 = 'g' then
  1309.          message = 'Generate a new public/secret key pair.'
  1310.       elseif arg2 = 'e' then
  1311.          message = 'Edit your userid or passphrase.'
  1312.       elseif arg2 = 'd' then
  1313.          message = 'REVOKE YOUR KEY and ISSUE A KEY COMPROMISE CERTIFICATE.'
  1314.       endif
  1315.  
  1316.       message = 'You are about to' message
  1317.  
  1318.    endif
  1319.  
  1320.    message = message || \10\10'This action will DIRECTLY affect your keyring!' ||
  1321.                         \10\10'Are you SURE you want to continue?'
  1322.  
  1323.    r = WinMessageBox('Gibbon PGP Front End', message, 16404)
  1324. ;                                     MB_YESNO        = 4
  1325. ;                                     MB_ICONQUESTION = 16
  1326. ;                                     MB_MOVEABLE     = 16384
  1327.  
  1328.    if r = 7 then   -- MBID_NO is 7
  1329.       return
  1330.    endif
  1331.  
  1332.    if arg1 = 's' then
  1333.       sec_name = ''
  1334.       sec_pswd = ''
  1335.    endif
  1336.  
  1337.    if arg2 <> 'g' then
  1338.       pgp_get_sec_id()
  1339.    endif
  1340.  
  1341.    cmd = switch
  1342.  
  1343.    if arg1 = 'p' then
  1344.       cmd = cmd pub_keyid '-u "' || sec_name || '"' pgp_curpubring
  1345.    else
  1346.       if arg2 = 'e' then
  1347.          cmd = cmd '"'sec_name'"' pgp_secring
  1348.       elseif arg2 = 'd' then
  1349.          cmd = cmd '"'sec_name'"'
  1350.       endif
  1351.    endif
  1352.  
  1353.    'OS2 /C PGP' cmd
  1354.  
  1355. /*
  1356.  
  1357. MB_OK                =        0  -- Pick one of the following for the
  1358. MB_OKCANCEL          =        1  -- buttons you want on the message box
  1359. MB_RETRYCANCEL       =        2
  1360. MB_ABORTRETRYIGNORE  =        3
  1361. MB_YESNO             =        4
  1362. MB_YESNOCANCEL       =        5
  1363. MB_CANCEL            =        6
  1364. MB_ENTER             =        7
  1365. MB_ENTERCANCEL       =        8
  1366.  
  1367. MB_NOICON            =        0  -- Add one of the following for the
  1368. MB_CUANOTIFICATION   =        0  -- icon you want in the message box
  1369. MB_ICONQUESTION      =       16
  1370. MB_ICONEXCLAMATION   =       32
  1371. MB_CUAWARNING        =       32
  1372. MB_ICONASTERISK      =       48
  1373. MB_ICONHAND          =       64
  1374. MB_CUACRITICAL       =       64
  1375. MB_QUERY             =     MB_ICONQUESTION
  1376. MB_WARNING           =     MB_CUAWARNING
  1377. MB_INFORMATION       =     MB_ICONASTERISK
  1378. MB_CRITICAL          =     MB_CUACRITICAL
  1379. MB_ERROR             =     MB_CRITICAL
  1380.  
  1381. MB_DEFBUTTON1        =          0  -- This specifies which button is the
  1382. MB_DEFBUTTON2        =        256  -- default if Enter is pressed.
  1383. MB_DEFBUTTON3        =        512
  1384.  
  1385. MB_APPLMODAL         =       0000  -- Application modal
  1386. MB_SYSTEMMODAL       =       4096  -- System modal
  1387. MB_HELP              =       8192
  1388. MB_MOVEABLE          =      16384  -- The message box can be moved.
  1389.  
  1390. MBID_OK              =     1  -- Message box return codes
  1391. MBID_CANCEL          =     2  -- (correspond with the button pressed)
  1392. MBID_ABORT           =     3
  1393. MBID_RETRY           =     4
  1394. MBID_IGNORE          =     5
  1395. MBID_YES             =     6
  1396. MBID_NO              =     7
  1397. MBID_HELP            =     8
  1398. MBID_ENTER           =     9
  1399. MBID_ERROR           =     65535
  1400.  
  1401. */
  1402.  
  1403.  
  1404. /****************************************
  1405.   get_sec_id gets the secret key to use
  1406. *****************************************/
  1407. defproc pgp_get_sec_id()
  1408.    universal vTEMP_PATH
  1409.    universal pgp_pubring, pgp_secring
  1410.    universal sec_name, sec_keyid, sec_pswd
  1411.  
  1412.    if pgp_checkrings() = 0 then
  1413.       return
  1414.    endif
  1415.  
  1416.    one = atoi(1)
  1417.    zero = atoi(0)
  1418.  
  1419. ;   Display -3                              -- turn off display updates and error messages
  1420.    GetFileID msgFileID                     -- get fileid of current message
  1421.    r = pgp_redirect('-kv *' pgp_secring)  -- pass commands to routine the does the work
  1422.    if r = 'ERROR' then
  1423. ;      Display 3                            -- enable display updates and messages
  1424.       return
  1425.    endif
  1426.    GetFileID tempFileID
  1427.  
  1428.    uidlist = ''
  1429.    lastline = .last
  1430.    numhits = 0
  1431.  
  1432.    Do line = 1 to lastline
  1433.       GetLine viewline, line, tempFileID
  1434.       if Word(viewline,1) = 'sec' then
  1435.          numhits = numhits + 1
  1436.          parse value viewline with . temp1 . temp2
  1437.          -- strip off key length from keyid  (eg. 1024/18CC6311)
  1438.          temp1 = '0x' || SubStr(temp1, Pos('/',temp1)+1)
  1439.          uidlist = uidlist || '^' || temp1' 'temp2
  1440.       endif
  1441.    End
  1442.  
  1443.    ActivateFile tempFileID                 -- activate the temporary file
  1444.    'q'                                     -- quit the file
  1445.    ActivateFile msgFileID                  -- activate the original file
  1446.  
  1447. /* no secret keys were found so punt */
  1448.    if numhits = 0 then
  1449.       r = WinMessageBox('Gibbon PGP Front End',
  1450.                         'I could not find any secret keys in' pgp_secring'!', 16416)
  1451. ;                                                        MB_CUAWARNING = 32
  1452. ;                                                        MB_MOVEABLE   = 16384
  1453.       sec_name = ''
  1454.       sec_keyid = ''
  1455. ;      Display 3                            -- enable display updates and messages
  1456.       return ''
  1457.    endif
  1458.  
  1459. /* If only 1 secret key is found, don't display the list */
  1460.    if numhits = 1 then
  1461.       if temp1 <> sec_keyid then
  1462.          sec_pswd = ''
  1463.       endif
  1464.       sec_keyid = temp1
  1465.       sec_name = temp2
  1466.       return ''
  1467.    endif
  1468.  
  1469. /* otherwise, display secret keys for selection */
  1470.    parse value listbox('Gibbon PGP Key Selection',
  1471.                         uidlist,
  1472.                        '/~OK/~Cancel',
  1473.                        0, 0, 4, 60,
  1474.                        compile if EVERSION >= 5.60 --gethwndc(APP_HANDLE)
  1475.                           zero || zero || one || one || zero ||
  1476.                        compile else                --gethwndc(APP_HANDLE)
  1477.                           one || one || zero || zero || zero ||
  1478.                        compile endif
  1479.                        'Select which secret key you want to use') with button 2 text \0
  1480.    btn = itoa(button || \0, 10)
  1481.    if btn = '2' then
  1482.       sec_keyid = ''
  1483.       sec_name = ''
  1484.       return ''
  1485.    endif
  1486.    parse value text with sec_keyid sec_name
  1487. ;   Display 3                               -- enable display updates and messages
  1488.  
  1489.  
  1490.  
  1491. /*****************************************
  1492.   get_pub_id gets the public key(s) to use
  1493. ******************************************/
  1494. defproc pgp_get_pub_id(mult)
  1495.    universal vTEMP_PATH
  1496.    universal pgp_pubring, pgp_secring
  1497.    universal pub_keyid, pub_name
  1498.  
  1499.    if pgp_checkrings() = 0 then
  1500.       return ''
  1501.    endif
  1502.  
  1503.    one = atoi(1)
  1504.    zero = atoi(0)
  1505.  
  1506.    uid = ''
  1507.    pub_keyid = ''
  1508.    pub_name = ''
  1509.  
  1510.    lastline = .last
  1511.    if lastline > 30 then
  1512.       lastline = 30
  1513.    endif
  1514.    hival = 0
  1515.  
  1516. /*
  1517.    search the message file for email headers To:,  Reply-To:,  or From:
  1518.    and snag email address if found.  Note that if more than one of the
  1519.    above headers is found, priority is to use 'To:', then  'Reply-To:',
  1520.    and then finally 'From:'.  This is controlled by hival.
  1521. */
  1522.    do line = 1 to lastline
  1523.       GetLine viewline, line
  1524.       test = Word(viewline,1)
  1525.       if test <> 'Reply-To:' and test <> 'From:' and test <> 'To:' then
  1526.          iterate
  1527.       endif
  1528.  
  1529. /* From: is the lowest priority */
  1530.       if test = 'From:' then
  1531.          if hival > 1 then
  1532.             iterate
  1533.          else
  1534.             hival = 1
  1535.          endif
  1536.       endif
  1537. /* Reply-To: is next lowest priority */
  1538.       if test = 'Reply-To:' then
  1539.          if hival > 2 then
  1540.             iterate
  1541.          else
  1542.             hival = 2
  1543.          endif
  1544.       endif
  1545. /* To: is highest priority */
  1546.       if test = 'To:' then
  1547.          hival = 3
  1548.       endif
  1549.  
  1550. /* if we get here, then we found a header and need to extract address  */
  1551.       found = 0
  1552.       do numword = 2 to Words(viewline)
  1553.          if Pos('@',Word(viewline,numword)) > 1 then
  1554.             uid = Word(viewline,numword)
  1555.             found = 1
  1556.             leave
  1557.          endif
  1558.       enddo
  1559.  
  1560. /* if we can't find internet style address, then use first word after keyword */
  1561.       if found = 0 then
  1562.          uid = Word(viewline,2)
  1563.       endif
  1564.  
  1565. /* strip off '<' or '(' from email address */
  1566.       if LeftStr(uid,1) = '<' or LeftStr(uid,1) = '(' then
  1567.          uid = RightStr(uid, Length(uid) - 1)
  1568.       endif
  1569.       if RightStr(uid,1) = '>' or RightStr(uid,1) = ')' then
  1570.          uid = LeftStr(uid, Length(uid) - 1)
  1571.       endif
  1572.  
  1573.    enddo /* end search for email headers */
  1574.  
  1575. /* uid contains the email address from header search, if any  */
  1576.    if uid = '' then
  1577.       uid = '*'
  1578.    endif
  1579.  
  1580. /* if mult set, then multiple public keys can be selected simultaneously */
  1581.    if mult then
  1582.       entrytitle = 'Enter public key user id, "*" for a list, or "+" for multiple users'
  1583.    else
  1584.       entrytitle = 'Enter public key user id or "*" for a list'
  1585.    endif
  1586.    mask = EntryBox(entrytitle, '/~OK/~Cancel', uid, 5, 72)
  1587.  
  1588. /* punt if nothing selected */
  1589.    if mask = '' then
  1590.       Return ''
  1591.    endif
  1592.  
  1593. /* trap attempt to mult when mult=0 */
  1594.    if mask = '+' and mult = 0 then
  1595.       mask = '*'
  1596.    endif
  1597.  
  1598.    if mask = '+' then
  1599.       mask = '*'
  1600.       doingmult = 1
  1601.    else
  1602.       doingmult = 0
  1603.    endif
  1604.  
  1605. ;   Display -3                              -- turn off display updates and error messages
  1606.    GetFileID msgFileID                     -- get fileid of current message
  1607. /* search public keyring */
  1608.    r = pgp_redirect('-kv "'mask'"' pgp_pubring)  -- pass commands to routine the does the work
  1609.    if r = 'ERROR' then
  1610. ;      Display 3                            -- enable display updates and messages
  1611.       return
  1612.    endif
  1613.    GetFileID tempFileID
  1614.  
  1615.    lastline = .last
  1616.    numhits = 0
  1617.  
  1618. /* we build a list of public keys found saving only the user name and keyid */
  1619.    listfile=vTEMP_PATH || 'Listbuf.out'    -- Build the file name for the list file
  1620.    'e' listfile                            -- open it
  1621.    GetFileID ListFileID                    -- Get its fileid
  1622.    ActivateFile tempFileID                 -- activate the temporary file
  1623.  
  1624. /* search the raw data for pub keys, and parse out key id and user name */
  1625.    Do line = 1 to lastline
  1626.       GetLine viewline, line
  1627.       if Word(viewline,1) = 'pub' then
  1628.          numhits = numhits + 1
  1629.          parse value viewline with . temp1 . temp2
  1630.          /* strip off key length from keyid  (eg. 1024/18CC6311) */
  1631.          temp1 = '0x' || SubStr(temp1, Pos('/',temp1)+1)
  1632.          temp = \255 || temp1' 'temp2
  1633.          Insertline temp, ListFileID.last, ListFileID -- Add it to the list
  1634.       endif
  1635.    End
  1636.  
  1637.    ListFileID.Modify = 0                   -- reset the modified flag for quit
  1638.  
  1639.    ActivateFile tempFileID                 -- activate the temporary file
  1640.    'q'                                     -- quit the file
  1641.    ActivateFile msgFileID                  -- activate the original file
  1642.  
  1643. /* here only one pub key was found so go ahead and use it */
  1644.    if numhits = 1 then
  1645.       getline pub_key, 1, ListFileID
  1646.       parse value pub_key with pub_keyid pub_name
  1647.       /* strip off \255 character on left side */
  1648.       pub_keyid = RightStr(pub_keyid, Length(pub_keyid) - 1)
  1649.       ActivateFile ListFileID              -- activate the list file
  1650.       'q'                                  -- quit the file
  1651.       ActivateFile msgFileID               -- activate the original file
  1652. ;      Display 3                            -- enable display updates and messages
  1653.       return
  1654.    endif
  1655.  
  1656. /* no matching public keys were found so punt */
  1657.    if numhits = 0 then
  1658.       r = WinMessageBox('Gibbon PGP Front End',
  1659.                         'I could not find any keys matching 'mask' in 'pgp_pubring'!', 16416)
  1660. ;                                                        MB_CUAWARNING = 32
  1661. ;                                                        MB_MOVEABLE   = 16384
  1662.       ActivateFile ListFileID              -- activate the list file
  1663.       'q'                                  -- quit the file
  1664.       ActivateFile msgFileID               -- activate the original file
  1665. ;      Display 3                            -- enable display updates and messages
  1666.       return ''
  1667.    endif
  1668.  
  1669. /* here more than one pub key was found so need user to select from list box */
  1670.  
  1671.    Deleteline ListFileID.last, ListFileID  -- Delete blank line at the end
  1672.  
  1673.    if doingmult then
  1674.       buttons = '/~OK/~Cancel/~Add to List'
  1675.    else
  1676.       buttons = '/~OK/~Cancel'
  1677.    endif
  1678.  
  1679.    temp_keyid = ''
  1680.    temp_name = ''
  1681.  
  1682.    Do Forever
  1683.       ActivateFile ListFileID              -- activate the list file
  1684.       ListHndl = Buffer(CREATEBUF, 'ListBuffer', MAXBUFSIZE, 1)
  1685.       if ListHndl = 0 then
  1686.           sayerror 'ERROR: could not create buffer'
  1687.           return ''
  1688.       endif
  1689.       noflines = buffer(PUTBUF, ListHndl, 1, 0, APPENDCR)
  1690. --      noflines = Buffer(PUTBUF, ListHndl, 1, .last)
  1691.       bufsize = Buffer(USEDSIZEBUF, ListHndl) -- get the size of the buffer
  1692.       ListFileID.Modify = 0                -- reset the modified flag for quit
  1693.       parse value listbox('Gibbon PGP Key Selection',
  1694.                   compile if EPM32  -- Or, if not including STDCONST, "if EVERSION >= 6"
  1695.                            \0 || atol(bufsize) || atoi(32) || atoi(ListHndl),
  1696.                   compile else
  1697.                            \0 || atoi(bufsize) || atoi(ListHndl) || atoi(32),
  1698.                   compile endif
  1699.                            buttons,
  1700.                            0, 0, 10, 72,
  1701.                   compile if EVERSION >= 5.60 --gethwndc(APP_HANDLE)
  1702.                            zero || zero || one || one || zero ||
  1703.                   compile else                --gethwndc(APP_HANDLE)
  1704.                            one || one || zero || zero || zero ||
  1705.                   compile endif
  1706.                            'Select a public key') with button 2 pub_key \0
  1707.  
  1708.       Call Buffer(FREEBUF, ListHndl)       -- Free the buffer
  1709.       btn = itoa(button || \0, 10)
  1710.  
  1711. /* cancel button pressed */
  1712.       if btn = '2' or pub_key = '' then
  1713.          ActivateFile ListFileID           -- activate the list file
  1714.          'q'                               -- quit the file
  1715.          ActivateFile msgFileID            -- activate the original file
  1716.          pub_keyid = ''
  1717.          pub_name = ''
  1718. ;         Display 3                         -- enable display updates and messages
  1719.          return
  1720.       endif
  1721.  
  1722. /* strip off funny note symbol at end of pub_key and parse */
  1723.       if Length(pub_key) > 1 then
  1724.          pub_key = LeftStr(pub_key, Length(pub_key) - 1)
  1725.          parse value pub_key with pub_keyid pub_name
  1726.       endif
  1727.  
  1728. /* OK button pressed */
  1729.       if btn = '1' then
  1730.          if doingmult then
  1731.             pub_keyid = temp_keyid
  1732.             pub_name = temp_name
  1733.             if pub_keyid = '' then
  1734.                message = 'You selected "OK" but haven''t added ' ||
  1735.                          'any public keys yet!  Either use the '  ||
  1736.                          '"Cancel" or "Add to List" buttons.'
  1737.                r = WinMessageBox('Gibbon PGP Front End', message, 16432)
  1738. ;                                                MB_INFORMATION = 48
  1739. ;                                                MB_MOVEABLE    = 16384
  1740.                iterate
  1741.             endif
  1742.          endif
  1743.          ActivateFile ListFileID           -- activate the list file
  1744.          'q'                               -- quit the file
  1745.          ActivateFile msgFileID            -- activate the original file
  1746. ;         Display 3                         -- enable display updates and messages
  1747.          return
  1748.       endif
  1749.  
  1750. /*
  1751.    Add-to-List button pressed  (for multiple keys only)
  1752.          Note: we need to trap the case where the same user is selected
  1753.          twice by checking for pub_keyid = *
  1754. */
  1755.       if btn = '3' and pub_keyid <> '*' then
  1756.          if temp_name = '' then
  1757.             temp_name = pub_name
  1758.             temp_keyid = pub_keyid
  1759.          else
  1760.             temp_name = temp_name' and 'pub_name
  1761.             temp_keyid = temp_keyid' 'pub_keyid
  1762.          endif
  1763.          ActivateFile ListFileID           -- activate the list file
  1764.          for curline = 1 to .last
  1765.             getline chgline, curline
  1766.             if Length(chgline) > 1 then
  1767.                chgline = RightStr(chgline, Length(chgline) - 1)
  1768.             endif
  1769.             if chgline = pub_key then
  1770.                chgline = \255 || '* ' || chgline
  1771.                replaceline chgline, curline
  1772.             endif
  1773.          endfor
  1774.          ActivateFile msgFileID            -- activate the original file
  1775.       endif
  1776.  
  1777.    EndDo
  1778. ;   Display 3                               -- enable display updates and messages
  1779.  
  1780.  
  1781.  
  1782. /***************************************************
  1783.   pgp_checkrings makes sure the keyrings are there
  1784. ***************************************************/
  1785. defproc pgp_checkrings()
  1786.    universal vTEMP_PATH
  1787.    universal pgp_curpubring, pgp_pubring, pgp_secring
  1788.    universal pgp_path, pgp_found, pgp_config
  1789.    universal pgp_randseed, pgp_cmd
  1790.  
  1791.    if pgp_path = '' then
  1792.       r = WinMessageBox('Gibbon PGP Front End',
  1793.                         'Your PGPPATH environment variable has not been set!', 16416)
  1794. ;                                                        MB_CUAWARNING = 32
  1795. ;                                                        MB_MOVEABLE   = 16384
  1796.       Return 0
  1797.     endif
  1798.  
  1799.    if pgp_config = '' then                        -- Has the config file been read yet?
  1800.       v_PATH = Get_Env('TEMP')
  1801.       if v_PATH = '' then
  1802.          v_PATH = Get_Env('TMP')
  1803.       endif
  1804.       if v_PATH <> '' then
  1805.          vTEMP_PATH = v_PATH
  1806.       endif
  1807.  
  1808.       pgp_config = pgp_path'\config.txt'          -- No - set the path
  1809.       if not Exist(pgp_config) then
  1810.          pgp_config = pgp_path'\pgp.ini'
  1811.          if not Exist(pgp_config) then
  1812.             pgp_config = pgp_path'\.pgprc'
  1813.          endif
  1814.       endif
  1815.       if Exist(pgp_config) then                   -- Read it only if it exists
  1816.          GetFileID msgFileID                      -- get fileid of current message
  1817.          'e' pgp_config                           -- Edit it
  1818.          Do line = 1 to .last
  1819.             GetLine viewline, line                -- Get a line
  1820.             if LeftStr(viewline,1) = '#' then     -- Check for comments
  1821.                iterate
  1822.             endif
  1823.             if Words(viewline) < 1 then           -- Check for blank lines
  1824.                iterate
  1825.             endif
  1826.             Parse Value viewline with keyword '=' text '#' .
  1827.             Do Forever
  1828.                test = LeftStr(text,1)
  1829.                if test = ' ' or test = '"' or test = "'" then
  1830.                   text = RightStr(text, Length(text) - 1)
  1831.                else
  1832.                   leave
  1833.                endif
  1834.             EndDo
  1835.             Do Forever
  1836.                test = RightStr(text,1)
  1837.                if test = ' ' or test = '"' or test = "'" then
  1838.                   text = LeftStr(text, Length(text) - 1)
  1839.                else
  1840.                   leave
  1841.                endif
  1842.             EndDo
  1843.             keyword = UpCase(keyword)
  1844.             if keyword = 'MYNAME' then
  1845.                sec_name = Strip(text)
  1846.             elseif keyword = 'TMP' then
  1847.                vTEMP_PATH = Strip(text)
  1848.             elseif keyword = 'PUBRING' then
  1849.                pgp_pubring = Strip(text)
  1850.                pgp_curpubring = Strip(text)
  1851.             elseif keyword = 'SECRING' then
  1852.                pgp_secring = Strip(text)
  1853.             elseif keyword = 'RANDSEED' then
  1854.                pgp_randseed = Strip(text)
  1855.             endif
  1856.  
  1857.          EndDo
  1858.          'q'
  1859.          ActivateFile msgFileID                   -- activate the original file
  1860.       endif
  1861.  
  1862.       if RightStr(vTEMP_PATH,1) <> '\' and RightStr(vTEMP_PATH,1) <> ':' then
  1863.          vTEMP_PATH = vTEMP_PATH || '\'
  1864.       Endif
  1865.  
  1866. /* make sure we can find pgp.exe, if not in path then make pgp_cmd fully qualified
  1867.    pgp_found = -1 -> PGP.EXE is not an OS/2 executable
  1868.    pgp_found = 0  -> cannot find pgp in PATH or pgp_path
  1869.    pgp_found = 1  -> pgp is in PATH
  1870.    pgp_found = 2  -> pgp is in pgp_path but not PATH
  1871. */
  1872.       findfile cmdline, 'PGP', 'PATH', 'P'
  1873.       If cmdline = '' then
  1874.          pgp_cmd = pgp_path || '\' || pgp_cmd
  1875.          findfile cmdline, pgp_path || '\PGP', '', 'P'
  1876.          If cmdline = '' then
  1877.             pgp_found = 0
  1878.          else
  1879.             pgp_found = 2
  1880.          endif
  1881.       endif
  1882.  
  1883. compile if EVERSION >= 5.60
  1884.       if pgp_found = 1 then
  1885.          'e' cmdline
  1886.          lth = 0
  1887.          Do line = 1 to .last
  1888.             GetLine viewline, line                -- Get a line
  1889.             if (Pos("LX", viewline) > 0) then
  1890.                leave
  1891.             endif
  1892.             lth = lth + Length(viewline)
  1893.             if (lth > 300) then
  1894.                pgp_found = -1
  1895.                leave
  1896.             endif
  1897.          EndDo
  1898.          'q'
  1899.          if pgp_found = 0 then
  1900.             Return 0
  1901.          endif
  1902.       endif
  1903. compile endif
  1904.  
  1905.    endif
  1906.  
  1907.    if pgp_found = -1 then
  1908.        r = WinMessageBox('Gibbon PGP Front End',
  1909.                           'Unable to run PGP.EXE because the program ' ||
  1910.                           'found is not an OS/2 executable.' , 16416)
  1911. ;                                              MB_CUAWARNING = 32
  1912. ;                                              MB_MOVEABLE   = 16384
  1913.       Return 0
  1914.    endif
  1915.  
  1916.    if pgp_found = 0 then
  1917.       r = WinMessageBox('Gibbon PGP Front End',
  1918.                         'Unable to run PGP.EXE because it could not ' ||
  1919.                         'be found in either the PATH or in PGPPATH!'  ||
  1920.                          \10\10 || 'Make sure the directory that '    ||
  1921.                         'contains PGP is in your PATH.'    , 16416)
  1922. ;                                                        MB_CUAWARNING = 32
  1923. ;                                                        MB_MOVEABLE   = 16384
  1924.       Return 0
  1925.    endif
  1926.  
  1927. compile if EVERSION < 5.60
  1928.    if pgp_found > 1 and pgp_found < 4 then
  1929.       message = 'PGP.EXE was not in the path, but was found in' pgp_path'.' ||
  1930.                 \10\10 || 'Make sure the directory that contains PGP is in your PATH.'
  1931.       r = WinMessageBox('Gibbon PGP Front End', message, 16416)
  1932. ;                                                     MB_CUAWARNING = 32
  1933. ;                                                     MB_MOVEABLE   = 16384
  1934.       pgp_found = pgp_found + 1
  1935.    endif
  1936. compile endif
  1937.  
  1938.    ranseedok = Exist(pgp_randseed)
  1939.    pubringok = Exist(pgp_pubring)
  1940.    curpubok  = Exist(pgp_curpubring)
  1941.    secringok = Exist(pgp_secring)
  1942.  
  1943.    if pubringok = 0 then
  1944.       message = 'Could not find PUBRING.PGP!'
  1945.    endif
  1946.    if curpubok = 0 then
  1947.       if pubringok then
  1948.          message = 'Could not find public key ring' pgp_curpubring'!'
  1949.       else
  1950.          message = message || \10'Or public key ring' pgp_curpubring'!'
  1951.       endif
  1952.    endif
  1953.    if secringok = 0 then
  1954.       if pubringok + curpubok = 2 then
  1955.          message = 'Could not find your secret key ring!'
  1956.       else
  1957.          message = message || \10 || 'Or your secret key ring, either!'
  1958.       endif
  1959.    endif
  1960.    if ranseedok = 0 then
  1961.       if pubringok + curpubok + secringok = 3 then
  1962.          message = 'Could not find RANDSEED.BIN!'
  1963.       else
  1964.          message = message || \10 || 'Or RANDSEED.BIN, either!'
  1965.       endif
  1966.    endif
  1967.  
  1968.    if (pubringok + curpubok + secringok + ranseedok) < 4 then
  1969.       r = WinMessageBox('Gibbon PGP Front End', message, 16416)
  1970. ;                                                        MB_CUAWARNING = 32
  1971. ;                                                        MB_MOVEABLE   = 16384
  1972.       Return 0
  1973.    endif
  1974.  
  1975.    Return 1
  1976.  
  1977.  
  1978. /*********************************************************************
  1979.   redirect invokes PGP and redirects the output to a temproary file.
  1980.   It then loads the file into an edit window, and deletes the file.
  1981. *********************************************************************/
  1982. defproc pgp_redirect(cmdline)
  1983.    universal vTEMP_PATH                             -- Path for temporary file - Predefined
  1984.    universal pgp_armor, pgp_textmode,
  1985.              pgp_clearsig
  1986.    universal pgp_cmd, pgp_opts
  1987.  
  1988.    outfile=vTEMP_PATH || 'pgpfe.tmp'                -- Build the file name for the temp file
  1989.  
  1990.    -- The output is redirected to pgpfe.tmp so it can be picked up
  1991.  
  1992.    lth = Length(pgp_cmd) + Length(cmdline) + Length(outfile) + 11
  1993. compile if EVERSION >= 5.60
  1994.    if lth > 1590 then
  1995.       message = 'Unable to complete the requested action.  ' ||
  1996.                 'The command line length (' || lth || ') '   ||
  1997.                 'exceeds the limit of 1590 characters.'
  1998. compile else
  1999.    if lth > 248 then
  2000.       message = 'Unable to complete the requested action.  ' ||
  2001.                 'The command line length (' || lth || ') '   ||
  2002.                 'exceeds the limit of 248 characters.'
  2003. compile endif
  2004.       r = WinMessageBox('Gibbon PGP Front End', message, 16448)
  2005. ;                                         MB_CUACRITICAL = 64
  2006. ;                                         MB_MOVEABLE    = 16384
  2007.       return 'ERROR'
  2008.    endif
  2009.    cmd = pgp_cmd '-f' cmdline '>'outfile '2>&1'
  2010.    quietshell cmd
  2011.  
  2012.    if RC = sayerror('Insufficient memory') or
  2013.       RC = sayerror('File Not found') then stop; endif
  2014.    'e' outfile                                      -- bring up the output
  2015. --   'MONOFONT'                                       -- set font to monospaced
  2016.    call erasetemp(outfile)                          -- and delete the temp file
  2017.