richter     01/09/08 06:23:22

  Modified:    .        Changes.pod Embperl.pm MANIFEST Makefile.PL README
                        embperl.h epio.c epmain.c test.pl
               crypto   epcrypto.c epcrypto.h epcrypto_config.h
  Added:       crypto   README
               test/cmp crypto.htm
  Log:
     - Embperl can now use encrypted sourcefiles. See crypto/README for
       details.
  
  Revision  Changes    Path
  1.184     +2 -0      embperl/Changes.pod
  
  Index: Changes.pod
  ===================================================================
  RCS file: /home/cvs/embperl/Changes.pod,v
  retrieving revision 1.183
  retrieving revision 1.184
  diff -u -r1.183 -r1.184
  --- Changes.pod       2001/09/02 18:06:08     1.183
  +++ Changes.pod       2001/09/08 13:23:21     1.184
  @@ -32,6 +32,8 @@
        optAllFormdata is set.
      - Cleanup of DBIx::Recordset objects now honors the setting in %CLEANUP.
        Problem reported by Kee Hinckley.
  +   - Embperl can now use encrypted sourcefiles. See crypto/README for
  +     details.
   
   =head1 1.3.3 (RELEASE)   6. Juni 2001
   
  
  
  
  1.171     +2 -2      embperl/Embperl.pm
  
  Index: Embperl.pm
  ===================================================================
  RCS file: /home/cvs/embperl/Embperl.pm,v
  retrieving revision 1.170
  retrieving revision 1.171
  diff -u -r1.170 -r1.171
  --- Embperl.pm        2001/09/02 18:06:08     1.170
  +++ Embperl.pm        2001/09/08 13:23:21     1.171
  @@ -10,7 +10,7 @@
   #   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   #   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   #
  -#   $Id: Embperl.pm,v 1.170 2001/09/02 18:06:08 richter Exp $
  +#   $Id: Embperl.pm,v 1.171 2001/09/08 13:23:21 richter Exp $
   #
   ###################################################################################
   
  @@ -64,7 +64,7 @@
   @ISA = qw(Exporter DynaLoader);
   
   
  -$VERSION = '1.3.4_dev-3';
  +$VERSION = '1.3.4_dev-4';
   
   # HTML::Embperl cannot be bootstrapped in nonlazy mode except
   # under mod_perl, because its dependencies import symbols like ap_palloc
  
  
  
  1.70      +6 -0      embperl/MANIFEST
  
  Index: MANIFEST
  ===================================================================
  RCS file: /home/cvs/embperl/MANIFEST,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- MANIFEST  2001/08/14 04:28:07     1.69
  +++ MANIFEST  2001/09/08 13:23:21     1.70
  @@ -22,6 +22,11 @@
   IntroEmbperlObject.pod
   TipsAndTricks.pod
   typemap
  +crypto/README
  +crypto/epcrypto_config.h
  +crypto/epcrypto.c
  +crypto/epcrypto.h
  +crypto/Makefile
   eg/README
   eg/images/jazzbkgd.gif
   eg/x/neu.htm
  @@ -303,6 +308,7 @@
   test/cmp/getsdaturlsess.htm
   test/cmp/inctext.htm
   test/cmp/execnotfound.htm
  +test/cmp/crypto.htm
   test/conf/httpd.conf.src
   test/conf/startup.pl
   test/conf/startup_dso.pl
  
  
  
  1.53      +40 -16    embperl/Makefile.PL
  
  Index: Makefile.PL
  ===================================================================
  RCS file: /home/cvs/embperl/Makefile.PL,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- Makefile.PL       2001/09/07 13:07:20     1.52
  +++ Makefile.PL       2001/09/08 13:23:21     1.53
  @@ -164,6 +164,29 @@
           return $txt ;
        }
        
  +sub MY::dynamic 
  +     {
  +     my $self = shift ;
  +        
  +        my $txt = $self -> MM::dynamic (@_) ;
  +
  +        $txt .= "\tcd crypto && \$(MAKE) SSL_BASE=$sslbase\n" if ($epc_enable) ;
  +        
  +        return $txt ;
  +     }
  +
  +sub MY::c_o
  +     {
  +     my $self = shift ;
  +        
  +        my $txt = $self -> MM::c_o (@_) ;
  +
  +        $txt =~ s/\$\*/-o \$*.o \$*/ ;
  +
  +        return $txt ;
  +     }
  +
  +
   sub MY::cflags 
        {
        my $self = shift ;
  @@ -756,9 +779,7 @@
       require Apache::src;
       $dynlib->{'OTHERLDFLAGS'} = Apache::src->new->otherldflags if (defined 
(&Apache::src::otherldflags)) ;
   
  -
  -    my $sslbase ;
  -        
  +
       if ($EPSTRONGHOLD) 
           {
           $i .= " -I$apache_src/../ssl/include" ;
  @@ -803,19 +824,21 @@
           $EPSTRONGHOLDKEY = '' ;
           }
   
  -    my $epc_enable = search_config ('EPC_ENABLE', "crypto/epcrypto_config.h") ;
  -    if ($epc_enable)
  -        {
  -        $sslbase = search_config ('SSL_BASE', "$apache_src/Configuration.apaci") if 
(!$sslbase) ;
  -        $sslbase = search_config ('SSL_BASE', "$apache_src/Configuration") if 
(!$sslbase) ;
  -        $sslbase = '/usr/local/ssl' if (!$sslbase) ;
  -        $libs .= " -L$sslbase/lib -lcrypto" ;
  -        }
  -
  -    if ($sslbase) 
  -        {
  -        $i .= " -I$sslbase/include" 
  -        }
  +    $epc_enable = search_config ('\s*#define\s+EPC_ENABLE', 
"crypto/epcrypto_config.h") ;
  +    if ($epc_enable)
  +        {
  +        $sslbase = search_config ('SSL_BASE', "$apache_src/Configuration.apaci") if 
(!$sslbase) ;
  +        $sslbase = search_config ('SSL_BASE', "$apache_src/Configuration") if 
(!$sslbase) ;
  +        $sslbase = '/usr/local/ssl' if (!$sslbase) ;
  +        $libs .= " -L$sslbase/lib -lcrypto" ;
  +        $o    .= ' crypto/epcrypto$(OBJ_EXT) ' ;
  +        print "Enable crypted sourcefiles\n" ;
  +        }
  +
  +    if ($sslbase) 
  +        {
  +        $i .= " -I$sslbase/include" 
  +        }
   
       print "Test start $EPHTTPD\n" ;
       print "Test httpd will run as user $EPUSER and group $EPGROUP\n" if (!$win32) ;
  @@ -900,6 +923,7 @@
       print FH "\$EPSESSIONXVERSION='$SessXVer';\n" ;
       print FH "\$EP2='$EP2';\n" ;
       print FH "\$EPMODPERLVERSION='$MPVer';\n" ;
  +    print FH "\$EPC_ENABLE='$epc_enable';\n" ;
       if ($win32)
           {
           print FH "\$EPNULL='nul';\n" ;
  
  
  
  1.29      +2 -1      embperl/README
  
  Index: README
  ===================================================================
  RCS file: /home/cvs/embperl/README,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- README    2001/05/16 05:37:09     1.28
  +++ README    2001/09/08 13:23:21     1.29
  @@ -11,7 +11,7 @@
   WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 
   MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   
  -$Id: README,v 1.28 2001/05/16 05:37:09 richter Exp $
  +$Id: README,v 1.29 2001/09/08 13:23:21 richter Exp $
   
   
   OVERVIEW
  @@ -51,6 +51,7 @@
   Tips and Tricks:                perldoc TipsAndTricks.pod
   Changes:                        perldoc Changes.pod
   Examples:                    eg/x/README
  +Sourcecode encryption:          crypto/README
   
   All the above and further information can be found at the Embperl website 
   
  
  
  
  1.28      +7 -2      embperl/embperl.h
  
  Index: embperl.h
  ===================================================================
  RCS file: /home/cvs/embperl/embperl.h,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- embperl.h 2001/08/12 12:19:32     1.27
  +++ embperl.h 2001/09/08 13:23:21     1.28
  @@ -10,7 +10,7 @@
   #   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   #   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   #
  -#   $Id: embperl.h,v 1.27 2001/08/12 12:19:32 richter Exp $
  +#   $Id: embperl.h,v 1.28 2001/09/08 13:23:21 richter Exp $
   #
   
###################################################################################*/
   
  @@ -72,7 +72,12 @@
       rcNotAllowed,
       rcNotHashRef,
       rcTagMismatch,
  -    rcCleanupErr
  +    rcCleanupErr,
  +    rcCryptoWrongHeader,
  +    rcCryptoWrongSyntax,
  +    rcCryptoNotSupported,
  +    rcCryptoBufferOverflow,
  +    rcCryptoErr
       } ;
   
   
  
  
  
  1.21      +42 -42    embperl/epio.c
  
  Index: epio.c
  ===================================================================
  RCS file: /home/cvs/embperl/epio.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- epio.c    2001/09/07 13:07:20     1.20
  +++ epio.c    2001/09/08 13:23:21     1.21
  @@ -10,13 +10,13 @@
   #   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   #   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   #
  -#   $Id: epio.c,v 1.20 2001/09/07 13:07:20 richter Exp $
  +#   $Id: epio.c,v 1.21 2001/09/08 13:23:21 richter Exp $
   #
   
###################################################################################*/
   
   
   #include "ep.h"
  -#include "epmacro.h"
  +#include "epmacro.h"
   #include "crypto/epcrypto.h"
   
   
  @@ -37,7 +37,7 @@
   #define PerlIO_flush fflush
   #define PerlIO_vprintf vfprintf
   #define PerlIO_fileno fileno
  -#define PerlIO_tell ftell
  +#define PerlIO_tell ftell
   #define PerlIO_seek fseek
   
   #define PerlIO_read(f,buf,cnt) fread(buf,1,cnt,f)
  @@ -578,45 +578,45 @@
   
       if ((long)nFileSize < 0)
        return rcFileOpenErr ;
  -
  -
  -    pBufSV = sv_2mortal (newSV(*nFileSize + 1)) ;
  -    pData = SvPVX(pBufSV) ;
  -
  -#if EPC_ENABLE
  -    
  -    if (*nFileSize)
  -        {
  -        int rc ;
  -        char * syntax ;
  -
  -#ifndef EP2
  -        syntax = r -> pTokenTable?"Text":"Embperl" ;
  -#else
  -        syntax = r -> pTokenTable -> sName ;
  -#endif
  -
  -        if ((rc = do_crypt_file (ifd, NULL, ofd, pData, *nFileSize, 0, syntax, 
EPC_HEADER)) <= 0)
  -            {
  -            if (rc < -1 || !EPC_UNENCYRPTED)
  -                {
  -                sprintf (r -> errdat1, "%d", rc) ;
  -                return rcCryptoErr ;
  -                }
  -
  -            PerlIO_seek (ifd, 0, SEEK_SET) ;
  -            *nFileSize = PerlIO_read (ifd, pData, *nFileSize) ;
  -            }
  -        else
  -            *nFileSize = rc ;
  -        }
  -#else
  -    
  -    if (*nFileSize)
  -        *nFileSize = PerlIO_read (ifd, pData, *nFileSize) ;
  -
  -#endif
  -
  +
  +
  +    pBufSV = sv_2mortal (newSV(*nFileSize + 1)) ;
  +    pData = SvPVX(pBufSV) ;
  +
  +#if EPC_ENABLE
  +    
  +    if (*nFileSize)
  +        {
  +        int rc ;
  +        char * syntax ;
  +
  +#ifndef EP2
  +        syntax = (r -> pTokenTable && strcmp ((char *)r -> pTokenTable, "Text") == 
0)?"Text":"Embperl" ;
  +#else
  +        syntax = r -> pTokenTable -> sName ;
  +#endif
  +
  +        if ((rc = do_crypt_file (ifd, NULL, pData, *nFileSize, 0, syntax, 
EPC_HEADER)) <= 0)
  +            {
  +            if (rc < -1 || !EPC_UNENCYRPTED)
  +                {
  +                sprintf (r -> errdat1, "%d", rc) ;
  +                return rcCryptoWrongHeader + -rc - 1;
  +                }
  +
  +            PerlIO_seek (ifd, 0, SEEK_SET) ;
  +            *nFileSize = PerlIO_read (ifd, pData, *nFileSize) ;
  +            }
  +        else
  +            *nFileSize = rc ;
  +        }
  +#else
  +    
  +    if (*nFileSize)
  +        *nFileSize = PerlIO_read (ifd, pData, *nFileSize) ;
  +
  +#endif
  +
       PerlIO_close (ifd) ;
       
       pData [*nFileSize] = '\0' ;
  
  
  
  1.114     +9 -2      embperl/epmain.c
  
  Index: epmain.c
  ===================================================================
  RCS file: /home/cvs/embperl/epmain.c,v
  retrieving revision 1.113
  retrieving revision 1.114
  diff -u -r1.113 -r1.114
  --- epmain.c  2001/09/01 21:31:10     1.113
  +++ epmain.c  2001/09/08 13:23:21     1.114
  @@ -10,7 +10,7 @@
   #   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   #   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   #
  -#   $Id: epmain.c,v 1.113 2001/09/01 21:31:10 richter Exp $
  +#   $Id: epmain.c,v 1.114 2001/09/08 13:23:21 richter Exp $
   #
   
###################################################################################*/
   
  @@ -140,7 +140,14 @@
        case rcNotAllowed:              msg ="[%d]ERR:  %d: Line %d: Forbidden %s: 
Does not match EMBPERL_ALLOW %s" ; break ;
           case rcNotHashRef:              msg ="[%d]ERR:  %d: Line %d: %s need 
hashref in %s" ; break ; 
        case rcTagMismatch:             msg ="[%d]ERR:  %d: Line %d: Endtag '%s' 
doesn't match starttag '%s'" ; break ; 
  -        default:                        msg ="[%d]ERR:  %d: Line %d: Error %s%s" ; 
break ; 
  +     case rcCleanupErr:              msg ="[%d]ERR:  %d: Line %d: Error in cleanup 
%s%s" ; break ; 
  +     case rcCryptoWrongHeader:       msg ="[%d]ERR:  %d: Line %d: Decrypt-error: 
Not encrypted (%s)%s" ; break ; 
  +     case rcCryptoWrongSyntax:       msg ="[%d]ERR:  %d: Line %d: Decrypt-error: 
Wrong syntax (%s)%s" ; break ; 
  +     case rcCryptoNotSupported:      msg ="[%d]ERR:  %d: Line %d: Decrypt-error: 
Not supported (%s)%s" ; break ; 
  +     case rcCryptoBufferOverflow:    msg ="[%d]ERR:  %d: Line %d: Decrypt-error: 
Buffer overflow (%s)%s" ; break ; 
  +     case rcCryptoErr:               msg ="[%d]ERR:  %d: Line %d: Decrypt-error: 
OpenSSL error (%s)%s" ; break ; 
  +     
  +     default:                        msg ="[%d]ERR:  %d: Line %d: Error %s%s" ; 
break ; 
           }
   
       pSV = newSVpvf (msg, r -> nPid , rc, r -> Buf.nSourceline, r -> errdat1, r -> 
errdat2) ;
  
  
  
  1.115     +17 -2     embperl/test.pl
  
  Index: test.pl
  ===================================================================
  RCS file: /home/cvs/embperl/test.pl,v
  retrieving revision 1.114
  retrieving revision 1.115
  diff -u -r1.114 -r1.115
  --- test.pl   2001/09/01 21:31:10     1.114
  +++ test.pl   2001/09/08 13:23:21     1.115
  @@ -11,7 +11,7 @@
   #   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   #   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   #
  -#   $Id: test.pl,v 1.114 2001/09/01 21:31:10 richter Exp $
  +#   $Id: test.pl,v 1.115 2001/09/08 13:23:21 richter Exp $
   #
   ###################################################################################
   
  @@ -682,6 +682,9 @@
                           { 'adressen_anrede' => 'Frau', 'adressen_name' => 'Weis',   
 'nr' => 22 },
                           ]
           },
  +    'crypto.htm' => { 
  +        'condition'  => '$EPC_ENABLE', 
  +        },
   ) ;
   
   for ($i = 0 ; $i < @testdata; $i += 2)
  @@ -696,7 +699,7 @@
   
   use vars qw ($httpconfsrc $httpconf $EPPORT $EPPORT2 *SAVEERR *ERR $EPHTTPDDLL 
$EPSTARTUP $EPDEBUG
                $testshare
  -            $EPSESSIONDS $EPSESSIONCLASS $EPSESSIONVERSION $EP1COMPAT 
$EPAPACHEVERSION
  +            $EPSESSIONDS $EPSESSIONCLASS $EPSESSIONVERSION $EP1COMPAT 
$EPAPACHEVERSION $EPC_ENABLE
               $opt_offline $opt_ep1 $opt_cgi $opt_modperl $opt_execute $opt_nokill 
$opt_loop
               $opt_multchild $opt_memcheck $opt_exitonmem $opt_exitonsv $opt_config 
$opt_nostart $opt_uniquefn
               $opt_quite $opt_qq $opt_ignoreerror $opt_tests $opt_blib $opt_help 
$opt_dbgbreak $opt_finderr
  @@ -1446,6 +1449,18 @@
   $ENV{EMBPERL_ALLOW} = 'asc|\\.htm$|\\.htm-1$' ;
   
   #HTML::Embperl::log ("Start testing...\n") ; # force logfile open
  +
  +
  +if ($EPC_ENABLE)
  +    {
  +    print "\nCreate crypted source...\n" ;
  +    my $rc = system ("crypto/epcrypto test/html/plain.htm test/html/crypto.htm") ;
  +    if ($rc)
  +        {
  +        print "Source encryption failed\n" ;
  +        exit (1) ;
  +        }
  +    }
   
   do  
       {
  
  
  
  1.4       +125 -107  embperl/crypto/epcrypto.c
  
  Index: epcrypto.c
  ===================================================================
  RCS file: /home/cvs/embperl/crypto/epcrypto.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- epcrypto.c        2001/09/07 13:07:20     1.3
  +++ epcrypto.c        2001/09/08 13:23:22     1.4
  @@ -1,121 +1,139 @@
   #include <stdlib.h>
   #include <stdio.h>
  -#include <errno.h>
  -#include <string.h>
  +#include <errno.h>
  +#include <string.h>
   #include "epcrypto.h"
  -
  -#if EPC_ENABLE
  -
  +
  +#if EPC_ENABLE
  +
   #include <openssl/evp.h>
   
    
   
   
  -int do_crypt_file(FILE *    in, 
  -                  FILE *    out, 
  -                  char *    output, 
  -                  int       outsize, 
  -                  int       do_encrypt, 
  -                  unsigned char * begin, 
  +int do_crypt_file(FILE *    in, 
  +                  FILE *    out, 
  +                  char *    output, 
  +                  int       outsize, 
  +                  int       do_encrypt, 
  +                  unsigned char * begin, 
                     unsigned char * header)
   
       {
       char inbuf[1024], outbuf[1024 + 8192];  /*EVP_MAX_BLOCK_LENGTH*/
       int inlen, outlen;
  -    int blen = 0 ;
  +    int blen = 0 ;
       int outcnt = 0 ;    
       unsigned char * key = EPC_KEY ;
       unsigned char * iv  = "\0x01\0x02\0x03\0x04\0x05\0x06\0x07\0x08" ;
  -    EVP_CIPHER_CTX  ctx ;
  -    
  -    if (output && do_encrypt)
  -        return -3 ; /* not supported */
  -    
  -   
  +    EVP_CIPHER_CTX  ctx ;
  +    
  +    if (output && do_encrypt)
  +        return -3 ; /* not supported */
  +    
  +   
   
       EVP_CipherInit(&ctx, EPC_CHIPER, NULL, NULL, do_encrypt);
       //EVP_CIPHER_CTX_set_key_length(&ctx, EPC_KEYLEN);
       
       EVP_CipherInit(&ctx, NULL, key, iv, do_encrypt);
  +
  +    if (header)
  +        {
  +        int hlen = strlen(header) ;
   
  -    if (header)
  -        {
  -        int hlen = strlen(header) ;
  -
  -        if (!do_encrypt)
  -            {
  -            inlen = fread(inbuf, 1, hlen, in);
  -            if (hlen != inlen || memcmp (inbuf, header, hlen) != 0)
  -                return -1 ; /* wrong header */
  -            }
  -        else
  -            fwrite(header, 1, hlen, out);
  -        }
  -    
  -    if (begin)
  -        {
  -        blen = strlen(begin) ;
  -
  -        if (do_encrypt)
  -            {
  -            EVP_CipherUpdate(&ctx, outbuf, &outlen, begin, blen) ;
  -            fwrite(outbuf, 1, outlen, out);
  -            }
  -        }
  -        
  -    
  +        if (!do_encrypt)
  +            {
  +            inlen = fread(inbuf, 1, hlen, in);
  +            if (hlen != inlen || memcmp (inbuf, header, hlen) != 0)
  +                return -1 ; /* wrong header */
  +            }
  +        else
  +            fwrite(header, 1, hlen, out);
  +        }
  +    
  +    if (begin)
  +        {
  +        blen = strlen(begin) ;
  +
  +        if (do_encrypt)
  +            {
  +            EVP_CipherUpdate(&ctx, outbuf, &outlen, begin, blen) ;
  +            fwrite(outbuf, 1, outlen, out);
  +            }
  +        }
  +        
  +    
       for(;;)
           {
           inlen = fread(inbuf, 1, 1024, in);
  -        if(inlen <= 0) break;
  -        EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen) ;
  -        if (blen && !do_encrypt && blen <= outlen)
  -            {
  -            if (memcmp (outbuf, begin, blen) != 0)
  -                return -2 ; /* wrong begin */
  -            if (blen < outlen)
  -                fwrite(outbuf + blen, 1, outlen - blen, out);
  -            blen = 0 ;
  -            }
  -        else
  -            {
  -            if (output)
  -                {
  -                if (outcnt + outlen > outsize)
  -                    return -4 ; /* buffer overflow */
  -                memcpy(output, outbuf, outlen) ;
  -                output += outlen ;
  -                }
  -            else
  -                {
  -                fwrite(outbuf, 1, outlen, out);
  -                }
  -            outcnt += outlen ;
  -            }
  +        if(inlen <= 0) 
  +         break;
  +        
  +     EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen) ;
  +        
  +     if (blen && !do_encrypt && blen <= outlen)
  +            {
  +            if (memcmp (outbuf, begin, blen) != 0)
  +                return -2 ; /* wrong begin */
  +         
  +         if (blen < outlen)
  +             {
  +             if (output)
  +                 {
  +                 if (outcnt + outlen - blen > outsize)
  +                     return -4 ; /* buffer overflow */
  +                 memcpy(output, outbuf + blen, outlen - blen) ;
  +                 output += outlen - blen ;
  +                 }
  +             else
  +                 {
  +                 if (blen < outlen)
  +                     fwrite(outbuf + blen, 1, outlen - blen, out);
  +                 }
  +             }
  +            outcnt += outlen - blen ;
  +            blen = 0 ;
  +            }
  +        else
  +            {
  +            if (output)
  +                {
  +                if (outcnt + outlen > outsize)
  +                    return -4 ; /* buffer overflow */
  +                memcpy(output, outbuf, outlen) ;
  +                output += outlen ;
  +                }
  +            else
  +                {
  +                fwrite(outbuf, 1, outlen, out);
  +                }
  +            outcnt += outlen ;
  +            }
   
           }
       if(!EVP_CipherFinal(&ctx, outbuf, &outlen))
           return -5; /* error */
  -
  -    if (output)
  -        {
  -        if (outcnt + outlen > outsize)
  -            return -4 ; /* buffer overflow */
  -        memcpy(output, outbuf, outlen) ;
  -        output += outlen ;
  -        }
  -    else
  -        {
  -        fwrite(outbuf, 1, outlen, out);
  -        }
  -    outcnt += outlen ;
   
  +    if (output)
  +        {
  +        if (outcnt + outlen > outsize)
  +            return -4 ; /* buffer overflow */
  +        memcpy(output, outbuf, outlen) ;
  +        output += outlen ;
  +        }
  +    else
  +        {
  +        fwrite(outbuf, 1, outlen, out);
  +        }
  +    outcnt += outlen ;
  +
       EVP_CIPHER_CTX_cleanup(&ctx);
       return outcnt ;
       }
       
   
  -#endif
  +#endif
     
               
   
  @@ -124,24 +142,24 @@
   int main (int argc, char *argv[])
   
       {
  -#if EPC_ENABLE
  +#if EPC_ENABLE
       FILE * ifd ;
       FILE * ofd ;
  -    char * syntax = "Embperl" ;
  -    int rc ;
  -#endif
  +    char * syntax = "Embperl" ;
  +    int rc ;
  +#endif
   
       puts ("\nEmbperl encryption tool / Vers. 1.0 / (c) 2001 G.Richter ecos gmbh\n") 
;
       
  -
  -#if EPC_ENABLE == 0
  -
  -    puts ("\nEncryption not enabled! see crypto/epcrypt_config.h\n") ;
  -    exit (1) ;
  -
  -#else
  -
   
  +#if EPC_ENABLE == 0
  +
  +    puts ("\nEncryption not enabled! see crypto/epcrypt_config.h\n") ;
  +    exit (1) ;
  +
  +#else
  +
  +
       if (argc < 3)
           {
           puts ("Usage: epcrypto <inputfile> <outputfile> [<syntax>] [<decrypt>]") ;
  @@ -149,8 +167,8 @@
           puts ("       decrypt defaults to false") ;
           exit (1) ;
           }
  -
  -    if (argc > 3)
  +
  +    if (argc > 3)
           syntax = argv[3] ;
   
       if (!(ifd = fopen (argv[1], "r")))
  @@ -168,21 +186,21 @@
   
       if ((rc = do_crypt_file (ifd, ofd, NULL, 0, argc > 4 && argv[4][0] != '\0' && 
argv[4][0] != '0'?0:1, syntax, EPC_HEADER)) <= 0)
           {
  -        if (rc == -1)
  -            {
  -            printf ("'%s' is not an Embperl encrypted file\n", argv[1]) ;
  -            }
  -        else if (rc == -2)
  -            {
  -            printf ("'%s' is wrong Syntax for '%s'\n", syntax, argv[1]) ;
  -            }
  +        if (rc == -1)
  +            {
  +            printf ("'%s' is not an Embperl encrypted file\n", argv[1]) ;
  +            }
  +        else if (rc == -2)
  +            {
  +            printf ("'%s' is wrong Syntax for '%s'\n", syntax, argv[1]) ;
  +            }
           printf ("Error while processing '%s' (%s)\n", argv[1], strerror( errno ) ) ;
           exit (1) ;
           }
  -    
  +    
   
       return 0 ;
  -#endif
  +#endif
   
       }
   
  
  
  
  1.2       +45 -45    embperl/crypto/epcrypto.h
  
  Index: epcrypto.h
  ===================================================================
  RCS file: /home/cvs/embperl/crypto/epcrypto.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- epcrypto.h        2001/09/07 13:07:20     1.1
  +++ epcrypto.h        2001/09/08 13:23:22     1.2
  @@ -1,45 +1,45 @@
  
-/*###################################################################################
  -#
  -#   Embperl - Copyright (c) 1997-2001 Gerald Richter / ECOS
  -#
  -#   You may distribute under the terms of either the GNU General Public
  -#   License or the Artistic License, as specified in the Perl README file.
  -#   For use with Apache httpd and mod_perl, see also Apache copyright.
  -#
  -#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  -#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  -#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  -#
  -#   $Id: epcrypto.h,v 1.1 2001/09/07 13:07:20 richter Exp $
  -#
  
-###################################################################################*/
  -
  -#include "epcrypto_config.h"
  -
  -#ifdef EPC_ENABLE
  -
  -/* ----------------------------------------------------------------------------
  -*
  -* File Signature 
  -*
  -* -------------------------------------------------------------------------- */
  -
  -#define EPC_HEADER "\x55\xAA\xFF\x01EPCPRYT\x55\xAA\xFF\x01"
  -
  -/* ----------------------------------------------------------------------------
  -*
  -* Functions
  -*
  -* -------------------------------------------------------------------------- */
  -
  -int do_crypt_file(FILE *    in, 
  -                  FILE *    out, 
  -                  char *    output, 
  -                  int       outsize, 
  -                  int       do_encrypt, 
  -                  unsigned char * begin, 
  -                  unsigned char * header) ;
  -
  -
  -#endif
  -
  
+/*###################################################################################
  +#
  +#   Embperl - Copyright (c) 1997-2001 Gerald Richter / ECOS
  +#
  +#   You may distribute under the terms of either the GNU General Public
  +#   License or the Artistic License, as specified in the Perl README file.
  +#   For use with Apache httpd and mod_perl, see also Apache copyright.
  +#
  +#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  +#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  +#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  +#
  +#   $Id: epcrypto.h,v 1.2 2001/09/08 13:23:22 richter Exp $
  +#
  
+###################################################################################*/
  +
  +#include "epcrypto_config.h"
  +
  +#ifdef EPC_ENABLE
  +
  +/* ----------------------------------------------------------------------------
  +*
  +* File Signature 
  +*
  +* -------------------------------------------------------------------------- */
  +
  +#define EPC_HEADER "\x55\xAA\xFF\x01EPCPRYT\x55\xAA\xFF\x01"
  +
  +/* ----------------------------------------------------------------------------
  +*
  +* Functions
  +*
  +* -------------------------------------------------------------------------- */
  +
  +int do_crypt_file(FILE *    in, 
  +                  FILE *    out, 
  +                  char *    output, 
  +                  int       outsize, 
  +                  int       do_encrypt, 
  +                  unsigned char * begin, 
  +                  unsigned char * header) ;
  +
  +
  +#endif
  +
  
  
  
  1.4       +2 -2      embperl/crypto/epcrypto_config.h
  
  Index: epcrypto_config.h
  ===================================================================
  RCS file: /home/cvs/embperl/crypto/epcrypto_config.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- epcrypto_config.h 2001/09/07 13:07:20     1.3
  +++ epcrypto_config.h 2001/09/08 13:23:22     1.4
  @@ -10,7 +10,7 @@
   #   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   #   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   #
  -#   $Id: epcrypto_config.h,v 1.3 2001/09/07 13:07:20 richter Exp $
  +#   $Id: epcrypto_config.h,v 1.4 2001/09/08 13:23:22 richter Exp $
   #
   
###################################################################################*/
   
  @@ -35,7 +35,7 @@
   *
   * -------------------------------------------------------------------------- */
   
  -#define EPC_ENABLE 1
  +#define EPC_ENABLE 0
   
   
   /* ----------------------------------------------------------------------------
  
  
  
  1.1                  embperl/crypto/README
  
  Index: README
  ===================================================================
  
  HTML::Embperl - Building dynamic Websites with Perl
  ---------------------------------------------------
  
  Copyright (c) 1997-2001 Gerald Richter / ecos gmbh
  
  You may distribute under the terms of either the GNU General Public 
  License or the Artistic License, as specified in the Perl README file.
  
  THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED 
  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 
  MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  
  $Id: README,v 1.1 2001/09/08 13:23:22 richter Exp $
  
  
  Sourcecode encryption
  =====================
  
  Embperl has the possibility to use encrypted sourcefiles. This allows
  to hide your code from curious people or make sure nobody can modify 
  your code.
  
  To enable encrypted sourcefile, go to the crypto directory and edit
  the epcrypto_config.h file. Here you can enable/disable encryption,
  choose which algorithmus to use, the encryption key and whenever
  Embperl should still work with unencrypted files. Make sure to use a 
  unique encryption key. Addtionaly OpenSSL must be already installed
  on your system. Now install Embperl as usual, by running
  
  perl Makefile.PL
  make
  make test
  make install
  
  To encrypt your source files go to the crypto directory and start the
  epcrypto program. It takes a source and a destination filename. If you 
  are using Embperl 2.x, you have to specify the syntax the sourcefile
  uses as third parameter, if it is any other then "Embperl".
  
  IMPORTANT:  Make sure to not distribute any files from the crypto
              directory, because it contains the key. Anybody who
              has access to the crypto directory, can decrypt your
              sourcefiles.
  
              The encrytion key is compiled into the binary, because
              Embperl needs it to do the decryption, so anybody who
              has access to the binary _and_ is able to disassemble
              the binary code, will be able to retrieve the key.
              So sourcecode encrytion can hide your source code
              from most people, because it's hard to disasemble the binary
              and get the key, but if anybody really wants your code
              he will get it! To prevent this the key shouldn't be 
              compiled into the binary, but instead a C function
              should be given, that could retrieve the key from a
              save place, e.g. a smart card, even better would
              be to do the decrytion directly on the smart card.
  
  
  
  
  
  
  
  
  1.1                  embperl/test/cmp/crypto.htm
  
  Index: crypto.htm
  ===================================================================
  
  <html>
  <head>
  <title>Some Plain tests for Embperl</title>
  </head>
  
  <!-- Here is a comment -->
  
  <body>
  
  Here it starts with some HTML Text<P>
  
  All values should be undefined:
  
  $a =  <BR>
  $b =  <BR>
  $c =  <BR>
  $d =  <BR>
  $e =  <BR>
  
  ARRAY @d =  num = 0 <BR>
  ARRAY @x =  num = 0 <BR>
  HASH  %a =  num = 0 <BR>
  HASH  %y =  num = 0 <BR>
  
  
  First of all assign a value:
  <BR>
  Now we have some 'Umlaute':
  
  
  Now lets look what we are getting from this:<BR>
  (this is the value in $a) (this is the value in $a) &auml;&ouml;&uuml;<BR>
  
  ARRAY @d = 1 2 3 num = 3 <BR>
  ARRAY @x = 9 8 7 num = 3 <BR>
  HASH  %a = 1 2 3 a b c num = 3 <BR>
  HASH  %y = 7 8 9 x y z num = 3 <BR>
  
  And now a and b together: (this is the value in $a)(this is the value in $a) 
&auml;&ouml;&uuml;<P>
  
  Here we have some HTML tags within the perl code, Embperl will delete them!<BR>
  
  57
  SELECT *  FROM a ORDER BY b USING &lt;; Hi There&gt;
  Here we have something which looks like a HTML tag, but does not start with<br>
  a character, Embperl does not change them!<BR>
  
  SELECT * FROM a ORDER BY b USING &lt;; Hi There&gt;
  Embperl will also translate HMTL escapes to the right characters i.e. $a &amp;lt; 6 
will get the perl expression $a &lt; 6: <BR>
  
  1
  Now they should have a value
  
  $a = (this is the value in $a) <BR>
  $b = (this is the value in $a) &auml;&ouml;&uuml; <BR>
  $c = 57 <BR>
  $d = 1 <BR>
  $e = 2 <BR>
  
  Input Separator = 10<br>
  
  <P>Ok.<P>
  
  
  </body>
  </html>
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to