Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

secure storage

by wertert (Sexton)
on Nov 23, 2001 at 15:59 UTC ( [id://127099]=perlquestion: print w/replies, xml ) Need Help??

wertert has asked for the wisdom of the Perl Monks concerning the following question:

I've done a few searches and haven't had any luck as yet. I am writing a bit of monitoring software that loads it's rules in from a file on disk. The rules are made up of regex patterns and functions which are eval'd and called when needed. I use storable.pl to save and retieve this rule file. The only problem is that if I view the file on disk I can basically see all the contents. I need a way of encrypting the file on the disk and decrypting it as I read it in using storable. What I would really like is a way of pre-compiling the functions within the rule file so that the native perl code is never actually seen, even by the running script. Something, i fear, that is beyond my brain at the moment ...... any ideas ??

Replies are listed 'Best First'.
Re: secure storage
by ask (Pilgrim) on Nov 23, 2001 at 16:02 UTC
    If people can read your script they can also trivially read the rule file no matter how you encrypt it.

    What are your goals? What security issues are you trying to deal with? It's easier to help if you tell about what you are trying to do instead of how you would like to do it. :-)

     - ask

    -- 
    ask bjoern hansen, http://ask.netcetera.dk/   !try; do();
    
      That's not true. If the file is encrypted using a password that must be given to the script by the user when the script is started up, then the password information is stored only in RAM, not in any place someone reading the script or the rules files can get to as easily. I'm sure it's possible to find it in the RAM, but I think a password approach manages the risk of a more casual reader getting at the file quite well. If the script is such that it must be started and stopped frequently (like a non mod_perl CGI), then this approach becomes less attractive.
      This is true - anyone with basic perl knowledge can look at the script and workout how to pull out the original info. I am not after total security but only want to stop anyone cat'ing out the file. Other ideas I have had are using the perlapp ( active perl ) to produce a stand alone executable and embeding the rule file within the script or running the whole thing from a web server so the script in question is not directly accessable ( other than by web master ). Thanks for you reply.
        You still didn't tell us what it really is that you are trying to do. ;-)

        If you just want a bit of obfuscation, maybe a simple tr/// before you save and after you read the file could do.

         - ask

        -- 
        ask bjoern hansen, http://ask.netcetera.dk/   !try; do();
        
Re: secure storage
by tachyon (Chancellor) on Nov 23, 2001 at 17:00 UTC

    First eval is a dangerous function to be using as a modification of one of the evaled expressions could be ahmm...interesting. Instead why not have all your rules ( regex pattern or not) wrapped in accessor methods in a file called say rules.pl:

    package Rules; sub rule1 { shift =~ m/some_pattern/; }

    This will return true or false depending on whether the passed argument matches /some_pattern/. You use it like this:

    require rules.pl &do_something() if Rule::rule1($match_this_data);

    Then set it up so that your script is part of a unique group called say 'foo' Your rules file can then be made readable only by this group and no one else, hence the only access is via the script and no one except root, the owner(you) and the script can read it.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: secure storage
by {NULE} (Hermit) on Nov 23, 2001 at 19:06 UTC
    Hi,

    As has been pointed out already, there is a difference between being able to stop someone from casually being able to see in a file and stopping someone with intent and ability.

    To stop the former, my favorite technique is using Acme::Bleach (by our own TheDamian). It removes all printable ascii and when it's done only white-space characters remain. It performs the "encryption" the first time it runs, the next time will actually run the file.

    Filter::Decrypt runs in much the same way. Make sure to check out the warnings in the documentation, though. It gives a good explanation about why this isn't real security.

    I'm not sure how storable fits in to all this. I imagine something like the following:

    #! /usr/bin/perl -w use strict; use Acme::Bleach; @main::data = <DATA> __DATA__ #Contents of storable output #go in this section.
    Then from a program that requires this code (and defines @main::data), this snippet could populate that array with the data for storable to work on. That may mean when storable generates its data you could just prepend it with those five lines, save it to disk, execute it once (since the first time it just performs the "bleaching") and be done with it.

    That's untested and probably won't work as written (I haven't had a chance to play with storable yet). But I hope it will give you some ideas.

    Update: ++Tachyon - like I said, this technique is only enough to stop the most easily discouraged folks from getting your data.

    Good luck,
    {NULE}
    --
    http://www.nule.org

      To stop the former, my favorite technique is using Acme::Bleach (by our own TheDamian).

      Sadly source filters are about as bulletproof as fairy floss:

      unbleach.pl

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://127099]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-18 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found