From: Jameson Rollins Date: Sat, 30 Oct 2010 20:42:28 +0000 (-0400) Subject: fix context/peer string checking/untainting X-Git-Tag: msva-perl_debian/0.6-1~2^2~5^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=99bf570bab5baf5f8c2357c7f61703b593764799;p=monkeysphere-validation-agent.git fix context/peer string checking/untainting This makes the checking/untainting of the input context and peer strings more similar to the checking of pkc type, and generally makes the checking more straightforward. Also fixes a bug in the failure check (thanks intrigeri). --- diff --git a/Crypt/Monkeysphere/MSVA.pm b/Crypt/Monkeysphere/MSVA.pm index ce838e4..20bd6b1 100755 --- a/Crypt/Monkeysphere/MSVA.pm +++ b/Crypt/Monkeysphere/MSVA.pm @@ -489,17 +489,6 @@ return $key; } - sub getuid { - my $data = shift; - if ($data->{context} =~ /^(https|ssh|smtp|ike)$/) { - $data->{context} = $1; - if ($data->{peer} =~ /^($RE{net}{domain})$/) { - $data->{peer} = $1; - return $data->{context}.'://'.$data->{peer}; - } - } - } - sub get_keyserver_policy { if (exists $ENV{MSVA_KEYSERVER_POLICY} and $ENV{MSVA_KEYSERVER_POLICY} ne '') { if ($ENV{MSVA_KEYSERVER_POLICY} =~ /^(always|never|unlessvalid)$/) { @@ -591,15 +580,31 @@ message => 'Unknown failure', }; - my $uid = getuid($data); - if ($uid eq []) { - msvalog('error', "invalid context/peer: %s/%s\n", $data->{context}, $data->{peer}); - $ret->{message} = sprintf('invalid context/peer'); - return $status, $ret; + # check context string + if ($data->{context} =~ /^(https|ssh|smtp|ike)$/) { + $data->{context} = $1; + } else { + msvalog('error', "invalid context: %s\n", $data->{context}); + $ret->{message} = sprintf("Invalid context: %s", $data->{context}); + return $status,$ret; } msvalog('verbose', "context: %s\n", $data->{context}); + + # checkout peer string + if ($data->{peer} =~ /^($RE{net}{domain})$/) { + $data->{peer} = $1; + } else { + msvalog('error', "invalid peer string: %s\n", $data->{peer}); + $ret->{message} = sprintf("Invalid peer string: %s", $data->{peer}); + return $status,$ret; + } msvalog('verbose', "peer: %s\n", $data->{peer}); + # generate uid string + my $uid = $data->{context}.'://'.$data->{peer}; + msvalog('verbose', "user ID: %s\n", $uid); + + # check pkc type my $key; if (lc($data->{pkc}->{type}) eq 'x509der') { $key = der2key(join('', map(chr, @{$data->{pkc}->{data}})));