summaryrefslogtreecommitdiffstats
path: root/mutt-gpg-time-check
blob: 4203ef2125c7c6c99e610885eb6cced40764cf72 (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
#!/usr/bin/perl

use strict;
use warnings;

use Date::Parse;

my $gpg_verification_line_distance = 0;

while (<STDIN>) {
	my $in_header =   1  .. /^$/;
	my $in_body   = /^$/ .. eof;

	if ($in_header) {
		print $_;
	} else {
		print;
		$gpg_verification_line_distance++;
		if (m/PGP output follows \(current time: (?<time>[^(]+)\)/) {
			my $timestamp = str2time($+{time});
			if (abs(time() - $timestamp) > 2) {
				print "WARNING: GPG signature verification time is different from current time\n";
				print "WARNING: The signature may be a fake!\n";
			} else {
				$gpg_verification_line_distance = 0;
			}
		}

		if (m/^gpg: Signature made .*/) {
			if ($gpg_verification_line_distance != 1) {
				print "WARNING: GPG signature without valid verification timestamp!\n";
				print "WARNING: The signature may be a fake!\n";
			}
		}

		if (m/^gpg:\s+issuer ".*"$/) {
			if ($gpg_verification_line_distance == 3) {
				$gpg_verification_line_distance--;
			}
		}

		if (m/^gpg: Good signature from .*/) {
			if ($gpg_verification_line_distance != 3) {
				print "WARNING: GPG signature without valid verification timestamp!\n";
				print "WARNING: The signature may be a fake!\n";
			}
		}

	}
}

# vim:set ft=perl: