Commit a40fb744 authored by Mike Hibler's avatar Mike Hibler

Change tiplines urlstamp to be an expiration time for the urlhash.

Previously it was the creation stamp for the hash. By making it the
expiration time, we can do different times for different nodes.

Note that there is no serious compatibility issue with re-purposing
the DB field. It is almost always zero (since they are only valid
for 5 minutes) and if it isn't zero when the new code is installed,
the hash will just immediately become invalid. So what? Big deal!
parent 0c3f3fcf
......@@ -3847,17 +3847,27 @@ sub SendApod($$)
# The hash can only be used once and is valid for a short time
# (say, 30 seconds).
#
sub GenTipAclUrl($)
sub GenTipAclUrl($;$)
{
my ($self) = @_;
my ($self,$expstamp) = @_;
my $node_id = $self->node_id();
my $hash = TBGenSecretKey();
if (!defined($hash)) {
print STDERR "Error creating new hash code\n";
return undef;
}
my $now = time();
if (!defined($expstamp)) {
# note: nodetipacl.php3 used 300, not 30
$expstamp = $now + 300;
} elsif ($expstamp && $expstamp < $now) {
print STDERR "Invalid expiration for tip URL\n";
return undef;
}
DBQueryWarn("update tiplines set urlhash='$hash', ".
" urlstamp=UNIX_TIMESTAMP(now()) ".
" urlstamp=$expstamp ".
"where node_id='$node_id'")
or return undef;
......
#!/usr/bin/perl -w
#
# Copyright (c) 2015 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
#
# Generate a tip ACL in the DB for the indicated node and time
#
use English;
use strict;
use lib "/usr/testbed/lib";
use Node;
my $node_id;
my $secs;
if (@ARGV < 1) {
print STDERR "Usage: $0 node [ valid-len-in-sec ]\n";
exit(1);
}
if ($ARGV[0] =~ /^([\w-]+)$/) {
$node_id = $1;
} else {
print STDERR "Invalid node string '$ARGV[0]'\n";
exit(1);
}
if (@ARGV > 1) {
if ($ARGV[1] =~ /^(\d+)$/) {
$secs = $1;
} else {
print STDERR "Invalid time interval '$ARGV[1]'\n";
exit(1);
}
} else {
$secs = 300;
}
my $node = Node->Lookup($node_id);
if (!$node) {
print STDERR "Invalid node '$node_id'\n";
exit(1);
}
my $url = $node->GenTipAclUrl(time() + $secs);
if (!$url) {
print STDERR "Could not generate tipacl for $node_id\n";
exit(1);
}
print "URL: '$url'\n";
print "Good for $secs seconds\n";
exit(0);
<?php
#
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
# Copyright (c) 2000-2015 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -43,13 +43,20 @@ if (isset($key)) {
$safe_key = addslashes($key);
$query_result =
DBQueryFatal("select node_id,urlstamp from tiplines ".
DBQueryFatal("select urlstamp from tiplines ".
"where node_id='$node_id' and urlhash='$safe_key' and ".
" urlstamp!=0 and ".
" (UNIX_TIMESTAMP(now()) - urlstamp) < 300");
" urlstamp!=0");
if (mysql_num_rows($query_result) == 0) {
USERERROR("Invalid node, invalid key or key has expired", 1);
USERERROR("Invalid node or invalid key", 1);
} else {
$row = mysql_fetch_array($query_result);
$stamp = $row['urlstamp'];
if ($stamp <= time()) {
DBQueryFatal("update tiplines set urlhash=NULL,urlstamp=0 ".
"where node_id='$node_id'");
USERERROR("Key is no longer valid", 1);
}
}
# Use once URL. Clear it.
DBQueryFatal("update tiplines set urlhash=NULL,urlstamp=0 ".
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment