Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Increasing Script Security - Licence expiration date

Status
Not open for further replies.

dmazzini

Programmer
Jan 20, 2004
480
US
Hi guys

I have created a perl executable file, that just specific window usernames can run it. I basically distributed individual XML licenses per user, which contains a "key" which is produced by another script based in window username and some kind of algorithm. (just me run it)

So, executable script reads "xml License" and based on windows username, generate key (it has same algorithm as the other script), if generated key is equal to key found in the "xml licence file" then script runs, otherwise script gives a message to the user that licence is not valid or is belong to someone else.

Now, I would like to be able to set "expiration dates" to these licences, like many commercial program does.
For instance from the first time that someone use script, give a 1 month period to use. I was thinking to write a hidden file in the PC where it will write date and time (just for first time), then everytime that someone use the script, it will look for that "hidden file" and check the remaining dates. For instance 28 valid days..etc

Could you guys offer me another alternatives to do it?

XML Licence example

Code:
<?xml version="1.0" encoding="UTF-8"?>
    <!-- Licence File -->
    <Licence version="1.0" Author="dmazzini" standalone="yes">   
    	<p name="LastName">XXXXX </p>
    	<p name="FirstName">YYYYY</p>
    	<p name="Email">XXXX@YYY.com</p>
    	<p name="Licence">793rboyyuxuNOE8039</p>   
    </Licence>






dmazzini
GSM/UMTS System and Telecomm Consultant

 
My suggestion would be to use Perls time function. Then save the value produced (i.e. to a .txt file)...

my ($time1)=time;

open (LOG, ">/Path_To_The_.Txt_File") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG "$time1";
close (LOG);

Perls time function simply prints the number of seconds since 1970. Therefore you may wish to change seconds to days, so you would want to convert the $time1 variable to days like this...

my ($time1)=time;
my $time2 = $time1/60/60/24;

open (LOG, ">/Path_To_The_.Txt_File") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG "$time2";
close (LOG);


As you can see, by /60 gives time in minutes, another /60 gives time in hours, then /24 gives time in days...

Now, you need a second script so that if the user logs in after 28 days then there username has expired...

my $expiredays = 28;
my ($time1)=time;
my $time2 = $time1/60/60/24;

open (LOG, "</Path_To_The_.Txt_File") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
my @time3 = <LOG>;
close (LOG) || Error ('close', 'file');

my $time4 = $time3+$expiredays;

if ($time2 > $time4) {
print "EXPIRED";
}

else {
print "NOT EXPIRED";
}


Hope this is of some help
 
You could put it in the expiration time (in epoch) in the xml file when generated BUT (some type of obfusication or encryption?) you will need to hide it in some way if you really want to expire the program. A lot of programs require internet access and talk to a authentication server before they will run. Just remember that everyone tries to do this but it is almost always gotten around.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
I wasn't sure if dmazzini wanted to use a perl script, considering hes in the perl forum :s
 
Thanks for all replies.

Regarding put expiration date in the XML license file, it's something that I don't want to do since user knows the existence of this file and they could modify it. Actually it's located in a specific folder known by the user.

Regarding the time calculation, it's no a problem for me since I have been manipulating some Perl Modules in the past.

What I would like to know is, if there is a way around to "set program expiration date" without use a "file to read/write" in the pc.

Now, came to my mind, if we have a perl script and you have at the bottom of script

Code:
__DATA__

write first time the Date and time

Should it be possible to manipulate some datainfo, open and writing in the same script under __DATA__. But, since it's in an executable I don't think is gonna be possible.

More comments are welcome.








dmazzini
GSM/UMTS System and Telecomm Consultant

 
Thoughts:
You could include the expiration time as part of the license key and encrypt them both or maybe put it in the registry?
You could maybe do it from the timestamp of the .exe file (is there a created timestamp?) but then you'd be limiting it to X amount of time for everyone who download the program and not different amounts for different people.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Hi

ok thanks for all advices.

Cheers

dmazzini
GSM/UMTS System and Telecomm Consultant

 
Hi guys

I have found the solution using PDK (Actually I use it).

PerlApp::get_bound_file function allows you to pass an string or file to the executable file. here an example passing a date as string.


Code:
use strict;
use Date::Format;
if( defined $PerlApp::VERSION ) {    # if we are in a perlapp executable 
my $timeout = PerlApp::get_bound_file('timeout'); 
my $str_timeout = time2str('%c', $timeout);    
if(time() > $timeout) {      
  print "this executable expired on $str_timeout - please buy a license!";
  exit;    } else { 
  print "still good! this executable will expire on $str_timeout"; 
  }
}

dmazzini
GSM/UMTS System and Telecomm Consultant

 
Of course to provide a license to use for a month, you could use:

Code:
perl -e "print (time() + ((60*60*24*365)/12))" > expirationdate.txt

[code]

it will create a file with current date + 1 month. Then I can create hidden file in the pc, like registry or even add it as part of xml licence file.

Thanks

dmazzini
GSM/UMTS System and Telecomm Consultant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top