return wantarray ? ($tokenid) : $tokenid;
}
-
-# VNC tickets
-# - they do not contain the username in plain text
-# - they are restricted to a specific resource path (example: '/vms/100')
-sub assemble_vnc_ticket {
- my ($username, $path) = @_;
+my $assemble_short_lived_ticket = sub {
+ my ($prefix, $username, $path) = @_;
my $rsa_priv = get_privkey();
my $secret_data = "$username:$path";
return PVE::Ticket::assemble_rsa_ticket(
- $rsa_priv, 'PVEVNC', undef, $secret_data);
-}
+ $rsa_priv, $prefix, undef, $secret_data);
+};
-sub verify_vnc_ticket {
- my ($ticket, $username, $path, $noerr) = @_;
+my $verify_short_lived_ticket = sub {
+ my ($ticket, $prefix, $username, $path, $noerr) = @_;
+
+ $path = normalize_path($path);
my $secret_data = "$username:$path";
return undef;
} else {
# raise error via undef ticket
- PVE::Ticket::verify_rsa_ticket($rsa_pub, 'PVEVNC');
+ PVE::Ticket::verify_rsa_ticket($rsa_pub, $prefix);
}
}
return PVE::Ticket::verify_rsa_ticket(
- $rsa_pub, 'PVEVNC', $ticket, $secret_data, -20, 40, $noerr);
+ $rsa_pub, $prefix, $ticket, $secret_data, -20, 40, $noerr);
+};
+
+# VNC tickets
+# - they do not contain the username in plain text
+# - they are restricted to a specific resource path (example: '/vms/100')
+sub assemble_vnc_ticket {
+ my ($username, $path) = @_;
+
+ return $assemble_short_lived_ticket->('PVEVNC', $username, $path);
+}
+
+sub verify_vnc_ticket {
+ my ($ticket, $username, $path, $noerr) = @_;
+
+ return $verify_short_lived_ticket->($ticket, 'PVEVNC', $username, $path, $noerr);
+}
+
+# Tunnel tickets
+# - they do not contain the username in plain text
+# - they are restricted to a specific resource path (example: '/vms/100', '/socket/run/qemu-server/123.storage')
+sub assemble_tunnel_ticket {
+ my ($username, $path) = @_;
+
+ return $assemble_short_lived_ticket->('PVETUNNEL', $username, $path);
+}
+
+sub verify_tunnel_ticket {
+ my ($ticket, $username, $path, $noerr) = @_;
+
+ return $verify_short_lived_ticket->($ticket, 'PVETUNNEL', $username, $path, $noerr);
}
sub assemble_spice_ticket {
my ($type, $tfa_data) = user_get_tfa($username, $realm, 0);
if ($type) {
- if ($type eq 'u2f') {
+ if ($type eq 'incompatible') {
+ die "old login api disabled, user has incompatible TFA entries\n";
+ } elsif ($type eq 'u2f') {
# Note that if the user did not manage to complete the initial u2f registration
# challenge we have a hash containing a 'challenge' entry in the user's tfa.cfg entry:
$tfa_data = undef if exists $tfa_data->{challenge};
my $version_info = PVE::Cluster::get_node_kv('version-info');
die "cannot update tfa config, please make sure all cluster nodes are up to date\n"
if !$version_info;
- my $members = PVE::Cluster::get_members();
+ my $members = PVE::Cluster::get_members() or return; # get_members returns undef on no cluster
my $old = '';
foreach my $node (keys $members->%*) {
my $info = $version_info->{$node};
if (!$info) {
- $old .= "cluster node '$node' is too old, did not broadcast its version info\n";
+ $old .= " cluster node '$node' is too old, did not broadcast its version info\n";
next;
}
$info = from_json($info);
my $ver = $info->{version};
if ($ver !~ /^(\d+\.\d+)-(\d+)/) {
- $old .= "cluster node '$node' provided an invalid version string: '$ver'\n";
+ $old .= " cluster node '$node' provided an invalid version string: '$ver'\n";
next;
}
my ($maj, $rel) = ($1, $2);
if (!($maj > 7.0 || ($maj == 7.0 && $rel >= 15))) {
- $old .= "cluster node '$node' is too old\n";
+ $old .= " cluster node '$node' is too old ($ver < 7.0-15)\n";
next;
}
}
- die $old if length($old);
+ die "cannot update tfa config, following nodes are not up to date:\n$old" if length($old);
}
sub user_remove_tfa : prototype($) {