You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl-cvs@perl.apache.org by ri...@apache.org on 2001/09/07 15:07:20 UTC

cvs commit: embperl/crypto epcrypto.h Makefile epcrypto.c epcrypto_config.h

richter     01/09/07 06:07:20

  Modified:    .        Makefile.PL epio.c
               crypto   Makefile epcrypto.c epcrypto_config.h
  Added:       crypto   epcrypto.h
  Log:
  source crypto
  
  Revision  Changes    Path
  1.52      +19 -5     embperl/Makefile.PL
  
  Index: Makefile.PL
  ===================================================================
  RCS file: /home/cvs/embperl/Makefile.PL,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- Makefile.PL	2001/07/18 07:27:50	1.51
  +++ Makefile.PL	2001/09/07 13:07:20	1.52
  @@ -255,7 +255,7 @@
   
       while (<FH>)
           {
  -        return $1 if (/^$key\s*=\s*(.*?)$/) ;
  +        return $1 if (/^$key\s*(?:=|\s)\s*(.*?)$/) ;
           }
   
       close FH ;
  @@ -756,7 +756,9 @@
       require Apache::src;
       $dynlib->{'OTHERLDFLAGS'} = Apache::src->new->otherldflags if (defined (&Apache::src::otherldflags)) ;
   
  -    
  +
  +    my $sslbase ;
  +        
       if ($EPSTRONGHOLD) 
           {
           $i .= " -I$apache_src/../ssl/include" ;
  @@ -770,9 +772,8 @@
           }
       elsif ($EPMOD_SSL)
           {
  -        my $sslbase = search_config ('SSL_BASE', "$apache_src/Configuration.apaci") ;
  +        $sslbase = search_config ('SSL_BASE', "$apache_src/Configuration.apaci") ;
           $sslbase = search_config ('SSL_BASE', "$apache_src/Configuration") if (!$sslbase) ;
  -        $i .= " -I$sslbase/include" ;
           print " + found mod_ssl\n" ;
           $EPSSLDISABLE = !start_errcode ("$EPHTTPD -t -f $EPPATH/test/conf/ssldisable.conf") ;
           }
  @@ -802,6 +803,19 @@
           $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" 
  +        }
   
       print "Test start $EPHTTPD\n" ;
       print "Test httpd will run as user $EPUSER and group $EPGROUP\n" if (!$win32) ;
  @@ -981,7 +995,7 @@
       'VERSION_FROM' => 'Embperl.pm', 		# finds $VERSION
       'OBJECT'       => 'Embperl$(OBJ_EXT) epmain$(OBJ_EXT) epio$(OBJ_EXT) epchar$(OBJ_EXT) epcmd$(OBJ_EXT) eputil$(OBJ_EXT) epeval$(OBJ_EXT) epapinit$(OBJ_EXT) ' . 
                          ($EP2?'epcmd2$(OBJ_EXT) epparse$(OBJ_EXT) epdom$(OBJ_EXT) epcomp$(OBJ_EXT)':'') . $o,
  -    'LIBS'	   => [''],   			 
  +    'LIBS'	   => [$libs || ''],   			 
       'DEFINE'	   => "$d \$(DEFS)", 			 
       'INC'	   => $i,     			 
       'EXE_FILES'    => [ 'embpexec.pl' ],
  
  
  
  1.20      +44 -13    embperl/epio.c
  
  Index: epio.c
  ===================================================================
  RCS file: /home/cvs/embperl/epio.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- epio.c	2001/08/16 07:50:15	1.19
  +++ epio.c	2001/09/07 13:07:20	1.20
  @@ -10,18 +10,16 @@
   #   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
   #   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
   #
  -#   $Id: epio.c,v 1.19 2001/08/16 07:50:15 richter Exp $
  +#   $Id: epio.c,v 1.20 2001/09/07 13:07:20 richter Exp $
   #
   ###################################################################################*/
   
   
   #include "ep.h"
  -#include "epmacro.h"
  +#include "epmacro.h"
  +#include "crypto/epcrypto.h"
   
   
  -
  -
  -
   static char sLogFilename [512] = "" ;
   
   #ifndef PerlIO
  @@ -39,7 +37,8 @@
   #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)
   #define PerlIO_write(f,buf,cnt) fwrite(buf,1,cnt,f)
  @@ -579,13 +578,45 @@
   
       if ((long)nFileSize < 0)
   	return rcFileOpenErr ;
  -    
  -    pBufSV = sv_2mortal (newSV(*nFileSize + 1)) ;
  -    pData = SvPVX(pBufSV) ;
  -
  -    if (*nFileSize)
  -        *nFileSize = PerlIO_read (ifd, pData, *nFileSize) ;
  -
  +
  +
  +    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
  +
       PerlIO_close (ifd) ;
       
       pData [*nFileSize] = '\0' ;
  
  
  
  1.2       +2 -2      embperl/crypto/Makefile
  
  Index: Makefile
  ===================================================================
  RCS file: /home/cvs/embperl/crypto/Makefile,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Makefile	2001/09/07 06:51:29	1.1
  +++ Makefile	2001/09/07 13:07:20	1.2
  @@ -1,5 +1,5 @@
   
   SSL_BASE=/usr/local/ssl
   
  -epcrypto: epcrypto.c epcrypto_config.h
  -	gcc   -Wall   -I$(SSL_BASE)/include -L$(SSL_BASE)/lib  -o epcrypto epcrypto.c   -lcrypto
  +epcrypto: epcrypto.c epcrypto_config.h epcrypto.h
  +	gcc  -Wall   -I$(SSL_BASE)/include -L$(SSL_BASE)/lib  -o epcrypto epcrypto.c   -lcrypto
  
  
  
  1.3       +123 -62   embperl/crypto/epcrypto.c
  
  Index: epcrypto.c
  ===================================================================
  RCS file: /home/cvs/embperl/crypto/epcrypto.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- epcrypto.c	2001/09/07 06:51:29	1.2
  +++ epcrypto.c	2001/09/07 13:07:20	1.3
  @@ -1,84 +1,122 @@
   #include <stdlib.h>
   #include <stdio.h>
  -#include <errno.h>
  +#include <errno.h>
  +#include <string.h>
  +#include "epcrypto.h"
  +
  +#if EPC_ENABLE
  +
   #include <openssl/evp.h>
  -#include "epcrypto_config.h"
   
    
   
   
  +int do_crypt_file(FILE *    in, 
  +                  FILE *    out, 
  +                  char *    output, 
  +                  int       outsize, 
  +                  int       do_encrypt, 
  +                  unsigned char * begin, 
  +                  unsigned char * header)
   
  -int do_crypt_file(FILE *in, FILE *out, int do_encrypt)
  -
       {
       char inbuf[1024], outbuf[1024 + 8192];  /*EVP_MAX_BLOCK_LENGTH*/
       int inlen, outlen;
  -    
  +    int blen = 0 ;
  +    int outcnt = 0 ;    
       unsigned char * key = EPC_KEY ;
  -    unsigned char * iv  = "12345678";
  -    
  -    EVP_CIPHER_CTX  ctx ;
  +    unsigned char * iv  = "\0x01\0x02\0x03\0x04\0x05\0x06\0x07\0x08" ;
  +    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 (!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) ;
  -        fwrite(outbuf, 1, outlen, out);
  +        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(!EVP_CipherFinal(&ctx, outbuf, &outlen))
  -        return 0;
  -    fwrite(outbuf, 1, outlen, out);
  +        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 ;
   
       EVP_CIPHER_CTX_cleanup(&ctx);
  -    return 1;
  +    return outcnt ;
       }
       
  -
  -int do_crypt_mem(char * inbuf, int inlen, char * outbuf, int do_encrypt, int type)
  -
  -    {
  -    /* inbuf[1024], outbuf[1024 + EVP_MAX_BLOCK_LENGTH]; */
  -    int outlen;
  -    
  -    unsigned char * key = EPC_KEY ;
  -    unsigned char * iv  = "12345678";
  -    
  -    EVP_CIPHER_CTX  ctx ;
  -
  -    
  -    if(inlen <= 0) 
  -        return 0;
  -
  -    if (type > 0)
  -        {
  -        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 (type < 2)
  -        {
  -        EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen) ;
  -        }
  -    else
  -        {
  -        if(!EVP_CipherFinal(&ctx, outbuf, &outlen))
  -            {
  -            return 0;
  -            }
  -        EVP_CIPHER_CTX_cleanup(&ctx);
  -        }
   
  -    return outlen ;
  -    }
  -    
  +#endif
  +  
               
   
   #ifndef XS_VERSION
  @@ -86,13 +124,24 @@
   int main (int argc, char *argv[])
   
       {
  +#if EPC_ENABLE
       FILE * ifd ;
       FILE * ofd ;
  +    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
  +
   
  -    puts ("Embperl encryption tool / Vers. 1.0 / (c) 2001 G.Richter ecos gmbh\n") ;
  -    
  -    //OpenSSL_add_all_algorithums () ;
  -
       if (argc < 3)
           {
           puts ("Usage: epcrypto <inputfile> <outputfile> [<syntax>] [<decrypt>]") ;
  @@ -100,28 +149,40 @@
           puts ("       decrypt defaults to false") ;
           exit (1) ;
           }
  -
  +
  +    if (argc > 3)
  +        syntax = argv[3] ;
   
       if (!(ifd = fopen (argv[1], "r")))
           {
  -        printf ("Cannot open %s for reading (%s)\n", argv[1], strerror( errno ) ) ;
  +        printf ("Cannot open '%s' for reading (%s)\n", argv[1], strerror( errno ) ) ;
           exit (1) ;
           }
   
   
  -    if (!(ofd = fopen (argv[1], "w")))
  +    if (!(ofd = fopen (argv[2], "w")))
           {
  -        printf ("Cannot open %s for writing (%s)\n", argv[1], strerror( errno ) ) ;
  +        printf ("Cannot open '%s' for writing (%s)\n", argv[2], strerror( errno ) ) ;
           exit (1) ;
           }
   
  -    if (!do_crypt_file (ifd, ofd, argc > 3 && argv[4][0] != '\0' && argv[4][0] != '0'?0:1))
  +    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)
           {
  -        printf ("Error while processing (%s)\n", argv[1], strerror( errno ) ) ;
  +        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
   
       }
   
  
  
  
  1.3       +3 -4      embperl/crypto/epcrypto_config.h
  
  Index: epcrypto_config.h
  ===================================================================
  RCS file: /home/cvs/embperl/crypto/epcrypto_config.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- epcrypto_config.h	2001/09/04 19:24:13	1.2
  +++ epcrypto_config.h	2001/09/07 13:07:20	1.3
  @@ -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.2 2001/09/04 19:24:13 richter Exp $
  +#   $Id: epcrypto_config.h,v 1.3 2001/09/07 13:07:20 richter Exp $
   #
   ###################################################################################*/
   
  @@ -35,7 +35,7 @@
   *
   * -------------------------------------------------------------------------- */
   
  -#define EPC_ENABLE 0
  +#define EPC_ENABLE 1
   
   
   /* ----------------------------------------------------------------------------
  @@ -124,7 +124,7 @@
   * 
   * -------------------------------------------------------------------------- */
   
  -#define EPC_KEY "\0x88\0x56\0xff\0x78\0xbc\0xaa\0x94\0x1a\0xfe" 
  +#define EPC_KEY "\x88\0x56\xff\x78\xbc\xaa\x94\x1a\xfe" 
   #define EPC_KEYLEN (sizeof (EPC_KEY) - 1)
   
   
  @@ -137,5 +137,4 @@
   * -------------------------------------------------------------------------- */
   
   #define EPC_UNENCYRPTED 1
  -
   
  
  
  
  1.1                  embperl/crypto/epcrypto.h
  
  Index: epcrypto.h
  ===================================================================
  /*###################################################################################
  #
  #   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
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-cvs-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-cvs-help@perl.apache.org