+ # produces 40 characters
+ my $sig = unpack("H*", Digest::SHA::sha1($plain, &$get_csrfr_secret()));
+
+ #my $sig = unpack("H*", $rsa_priv->sign($plain)); # this produce too long strings (512)
+
+ my $proxyticket = $plain . "::" . $sig;
+
+ return ($ticket, $proxyticket);
+}
+
+sub verify_spice_connect_url {
+ my ($connect_str) = @_;
+
+ # Note: we pass the spice ticket as 'host', so the
+ # spice viewer connects with "$ticket:$port"
+
+ return undef if !$connect_str;
+
+ if ($connect_str =~m/^pvespiceproxy:([a-z0-9]{8}):(\d+):(\S+)::([a-z0-9]{40}):(\d+)$/) {
+ my ($timestamp, $vmid, $node, $hexsig, $port) = ($1, $2, $3, $4, $5, $6);
+ my $ttime = hex($timestamp);
+ my $age = time() - $ttime;
+
+ # use very limited lifetime - is this enough?
+ return undef if !(($age > -20) && ($age < 40));
+
+ my $plain = "pvespiceproxy:$timestamp:$vmid:$node";
+ my $sig = unpack("H*", Digest::SHA::sha1($plain, &$get_csrfr_secret()));
+
+ if ($sig eq $hexsig) {
+ return ($vmid, $node, $port);
+ }
+ }
+
+ return undef;