Merge remote-tracking branch 'origin/bug-1213' into release
[cacert-devel.git] / scripts / scanforexponents.php
1 #!/usr/bin/php -q
2 <? /*
3 LibreSSL - CAcert web application
4 Copyright (C) 2004-2008 CAcert Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; version 2 of the License.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 include_once("../includes/mysql.php");
20
21 $fp = fopen("exp-report.txt", "w");
22
23 $d = dir("../crt/");
24 while (false !== ($entry = $d->read()))
25 {
26 if(substr($entry, 0, 3) == "gpg")
27 continue;
28 $file = "../crt/$entry";
29 if(!is_file($file))
30 continue;
31
32 if(substr($file, -3) == "der")
33 $do = trim(`openssl x509 -inform der -in $file -text -noout 2>&1 |grep 'Exponent'`);
34 else
35 $do = trim(`openssl x509 -in $file -text -noout 2>&1 |grep 'Exponent'`);
36
37 if($do == "")
38 continue;
39
40 list($crud, $exp, $crud) = explode(" ", $do);
41 if($exp >= 65537)
42 continue;
43
44 list($a, $crud) = explode(".", $entry, 2);
45 list($type, $id) = explode("-", $a);
46
47 $id = intval($id);
48
49 if($type == "client")
50 {
51 $query = "select `memid`,`serial`,`CN`,`subject`,`keytype`,`emailcerts`.`codesign` as `codesign`,`crt_name`,
52 `emailcerts`.`created` as `created`,`emailcerts`.`revoked` as `revoked`,
53 `emailcerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
54 from `emailcerts`,`users` where `emailcerts`.`id`='$id' and `users`.`id`=`emailcerts`.`memid`";
55 $res = mysql_query($query);
56 if(mysql_num_rows($res) <= 0)
57 {
58 echo $query."\n";
59 echo "$file: $do\n";
60 continue;
61 }
62
63 $row = mysql_fetch_assoc($res);
64 $email = $row['email'];
65 } else if($type == "orgclient") {
66 $query = "select `memid`,`serial`,`CN`,`subject`,`keytype`,`orgemailcerts`.`codesign` as `codesign`,`crt_name`,
67 `orgemailcerts`.`created` as `created`,`orgemailcerts`.`revoked` as `revoked`,
68 `orgemailcerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
69 from `orgemailcerts`,`org`,`users` where `orgemailcerts`.`id`='$id' and
70 `orgemailcerts`.`orgid`=`org`.`id` and `users`.`id`=`org`.`memid`";
71 $res = mysql_query($query);
72 if(mysql_num_rows($res) <= 0)
73 {
74 echo $query."\n";
75 echo "$file: $do\n";
76 continue;
77 }
78
79 $row = mysql_fetch_assoc($res);
80 $email = $row['email'];
81 } else if($type == "server") {
82 $query = "select `memid`,`serial`,`CN`,`subject`,`crt_name`,
83 `domaincerts`.`created` as `created`,`domaincerts`.`revoked` as `revoked`,
84 `domaincerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
85 from `domaincerts`,`domains`,`users` where `domaincerts`.`id`='$id' and
86 `domains`.`id`=`domaincerts`.`domid` and `users`.`id`=`domains`.`memid`";
87 $res = mysql_query($query);
88 if(mysql_num_rows($res) <= 0)
89 {
90 echo $query."\n";
91 echo "$file: $do\n";
92 continue;
93 }
94
95 $row = mysql_fetch_assoc($res);
96 $email = $row['email'];
97 } else if($type == "orgserver") {
98 $query = "select `memid`,`serial`,`CN`,`subject`,`crt_name`,
99 `orgdomaincerts`.`created` as `created`,`orgdomaincerts`.`revoked` as `revoked`,
100 `orgdomaincerts`.`expire` as `expire`, `rootcert`, `md`, `fname`, `lname`, `language`
101 from `orgdomaincerts`,`org`,`users` where `orgdomaincerts`.`id`='$id' and
102 `orgdomaincerts`.`orgid`=`org`.`id` and `users`.`id`=`org`.`memid`";
103 $res = mysql_query($query);
104 if(mysql_num_rows($res) <= 0)
105 {
106 echo $query."\n";
107 echo "$file: $do\n";
108 continue;
109 }
110
111 $row = mysql_fetch_assoc($res);
112 $email = $row['email'];
113 } else {
114 echo "$file: $do\n";
115 continue;
116 }
117
118 $body = "New Report:\n\n$do\n";
119
120 foreach($row as $key => $val)
121 $body .= "$key: $val\n";
122
123 $body .= "\n\n".file_get_contents($file);
124 fputs($fp, $body."\n\n===============================================================\n\n");
125 echo "$file: $do\n";
126 }
127 ?>