summaryrefslogtreecommitdiff
path: root/scripts/scanforexponents.php
blob: 713672376520b0e12c24bd9021a21d74ab45a588 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/php -q
<? /*
    LibreSSL - CAcert web application
    Copyright (C) 2004-2008  CAcert Inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; version 2 of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
	include_once("../includes/mysql.php");

	$fp = fopen("exp-report.txt", "w");

	$d = dir("../crt/");
	while (false !== ($entry = $d->read()))
	{
		if(substr($entry, 0, 3) == "gpg")
			continue;
		$file = "../crt/$entry";
		if(!is_file($file))
			continue;

		if(substr($file, -3) == "der")
			$do = trim(`openssl x509 -inform der -in $file -text -noout 2>&1 |grep 'Exponent'`);
		else
			$do = trim(`openssl x509 -in $file -text -noout 2>&1 |grep 'Exponent'`);

		if($do == "")
			continue;

		list($crud, $exp, $crud) = explode(" ", $do);
		if($exp >= 65537)
			continue;

		list($a, $crud) = explode(".", $entry, 2);
		list($type, $id) = explode("-", $a);

		$id = intval($id);

		if($type == "client")
		{
			$query = "select `memid`,`serial`,`CN`,`subject`,`keytype`,`emailcerts`.`codesign` as `codesign`,`crt_name`,
					`emailcerts`.`created` as `created`,`emailcerts`.`revoked` as `revoked`,
					`emailcerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
					from `emailcerts`,`users` where `emailcerts`.`id`='$id' and `users`.`id`=`emailcerts`.`memid`";
			$res = mysql_query($query);
			if(mysql_num_rows($res) <= 0)
			{
				echo $query."\n";
				echo "$file: $do\n";
				continue;
			}

			$row = mysql_fetch_assoc($res);
			$email = $row['email'];
		} else if($type == "orgclient") {
			$query = "select `memid`,`serial`,`CN`,`subject`,`keytype`,`orgemailcerts`.`codesign` as `codesign`,`crt_name`,
					`orgemailcerts`.`created` as `created`,`orgemailcerts`.`revoked` as `revoked`,
					`orgemailcerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
					from `orgemailcerts`,`org`,`users` where `orgemailcerts`.`id`='$id' and
							`orgemailcerts`.`orgid`=`org`.`id` and `users`.`id`=`org`.`memid`";
			$res = mysql_query($query);
			if(mysql_num_rows($res) <= 0)
			{
				echo $query."\n";
				echo "$file: $do\n";
				continue;
			}

			$row = mysql_fetch_assoc($res);
			$email = $row['email'];
		} else if($type == "server") {
			$query = "select `memid`,`serial`,`CN`,`subject`,`crt_name`,
					`domaincerts`.`created` as `created`,`domaincerts`.`revoked` as `revoked`,
					`domaincerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
					from `domaincerts`,`domains`,`users` where `domaincerts`.`id`='$id' and
							`domains`.`id`=`domaincerts`.`domid` and `users`.`id`=`domains`.`memid`";
			$res = mysql_query($query);
			if(mysql_num_rows($res) <= 0)
			{
				echo $query."\n";
				echo "$file: $do\n";
				continue;
			}

			$row = mysql_fetch_assoc($res);
			$email = $row['email'];
		} else if($type == "orgserver") {
			$query = "select `memid`,`serial`,`CN`,`subject`,`crt_name`,
					`orgdomaincerts`.`created` as `created`,`orgdomaincerts`.`revoked` as `revoked`,
					`orgdomaincerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
					from `orgdomaincerts`,`org`,`users` where `orgdomaincerts`.`id`='$id' and
							`orgdomaincerts`.`orgid`=`org`.`id` and `users`.`id`=`org`.`memid`";
			$res = mysql_query($query);
			if(mysql_num_rows($res) <= 0)
			{
				echo $query."\n";
				echo "$file: $do\n";
				continue;
			}

			$row = mysql_fetch_assoc($res);
			$email = $row['email'];
		} else {
			echo "$file: $do\n";
			continue;
		}

		$body = "New Report:\n\n$do\n";

		foreach($row as $key => $val)
			$body .= "$key: $val\n";

		$body .= "\n\n".file_get_contents($file);
		fputs($fp, $body."\n\n===============================================================\n\n");
		echo "$file: $do\n";
	}
?>