summaryrefslogtreecommitdiffstats
path: root/config/chroot_local-includes/usr/local/lib/tails-virt-notify-user
blob: 41ecc419e1f1178729dde71938e88c571e6b7615 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl

use strict;
use warnings;

#man{{{

=head1 NAME

tails-virt-notify-user

=head1 VERSION

Version X.XX

=head1 AUTHOR

Tails dev team <amnesia@boum.org>
See https://tails.boum.org/.

=cut

#}}}

use Desktop::Notify;
use English '-no_match_vars';
use IPC::System::Simple qw{capturex $EXITVAL};
use Locale::gettext;
use Net::DBus::Reactor;
use POSIX;

### initialization
setlocale(LC_MESSAGES, "");
textdomain("tails");

### callbacks

sub action_cb {
    my $reactor = shift;
    unless (fork) {
        exec(
            '/usr/local/bin/tails-documentation',
            'doc/advanced_topics/virtualization',
            'security'
        );
    }
    $reactor->shutdown;
}

### main

# both 0 and 1 are acceptable exit values:
#  - 0 means that we're running in a virtualized environment
#  - 1 means that we're not running in a virtualized environment
#  - anything else means there is a problem, and capturex will throw an exception
my $vm_name = capturex([0, 1], qw{/usr/bin/systemd-detect-virt --vm});
exit 0 if $EXITVAL == 1;

my @whitelist = qw(bochs kvm qemu uml virtualbox xen);

my $reactor = Net::DBus::Reactor->main;

my $notify  = Desktop::Notify->new();
$notify->action_callback(sub { action_cb($reactor, @_) });
$notify->close_callback(sub { $reactor->shutdown; });

my ($body, $summary);

chomp($vm_name);
if (grep {$_ eq $vm_name} @whitelist) {
    $summary = gettext("Warning: virtual machine detected!");
    $body    =
        gettext("Both the host operating system and the virtualization software are able to monitor what you are doing in Tails.");
}
else {
    $summary = gettext("Warning: non-free virtual machine detected!");
    $body    =
        gettext("Both the host operating system and the virtualization software are able to monitor what you are doing in Tails. Only free software can be considered trustworthy, for both the host operating system and the virtualization software.");
}

$notify->create(summary => $summary,
                body    => $body,
                actions => { "moreinfo_$PID" => gettext('Learn more'), },
                hints   => { 'transient' => 1, },
                timeout => 0)->show();

$reactor->run;