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

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on encrypting perl code used with mod_perl

Replies are listed 'Best First'.
Re: encrypting perl code used with mod_perl
by ikegami (Patriarch) on Jul 17, 2006 at 07:57 UTC

    It's impossible to prevent the customer from viewing the code. The customer has access to everything perl sees, trivially. Once he can see the code, he can trivially bypass integrity checks by removing the die, allowing him to edit the code freely.

    Perl can understand two kinds of code. Source code and byte code. It might be a bit trickier for the customer if the program was delivered as byte code (encrypted or not), but I suspect it's quite easy to recreate Perl source code from Perl byte code. It's not even necessary to do so.

    I'm telling you this so you realize that any protection you add will be rather easily circumventable. Consider that in your cost analysis.

    On the plus side, using encryption to protect your program — as ineffective as it might be — will grant you an extra legal weapon (and thus an extra bargaining chip) in the USA: The DMCA.

      Perl doesn't know about bytecode either. It only reads source code.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        Core module ByteLoader claims to be able to load bytecode.
Re: encrypting perl code used with mod_perl
by shmem (Chancellor) on Jul 17, 2006 at 07:25 UTC
    You might want to look into B::Bytecode. If your code comprises modules (*.pm files), compile them into *.pmc files, which are preferred over *.pm files by use and require. You can also use ByteLoader.

    Depending on the reasons you want to "encrypt" your source files, you could take several checksums of them and tell your customers that support is lost with any modifications. If you want to prevent them from "stealing" your code, don't deliver it.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: encrypting perl code used with mod_perl
by cwry (Monk) on Jul 17, 2006 at 07:16 UTC
    Have you looked at Filter::Crypto? You might like to thoroughly read through the warning section, which points out why doing this is fairly pointless, and that it only prevents casual viewing.
Re: encrypting perl code used with mod_perl
by CountZero (Bishop) on Jul 17, 2006 at 10:29 UTC
    If your customer is sophisticated enough to edit your scripts, he will not have a hard time decrypting your encrypted or otherwise obfuscated code.

    So you better go and see your lawyers and ask them to draft some strong legal text to stop the customer from messing with your code.

    One thing I have been thinking of (but only in theory as I lack the knowledge to implement it) is to write a compiled XS-module which would check on a regular basis that the scripts which are part of your project are still the same by comparing their MD5-hash with the original MD5-hash. It would not be too difficult to "hide" that XS-module somewhere in your project and have it called regularly from one of your other routines. If it finds any anomalies, it could throw an exception and stop executing the program.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: encrypting perl code used with mod_perl
by perrin (Chancellor) on Jul 17, 2006 at 13:32 UTC
    Sorry, mod_perl doesn't support source filters. You can try using PAR for this, if you just want to make it a little harder.
A reply falls below the community's threshold of quality. You may see it by logging in.