7ae33deebfbf80fde9235c3cea37c80930fe1f77
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

1) <?php
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

2) /*
3) This file belongs to the Webinterface of schokokeks.org Hosting
4) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

5) Written by schokokeks.org Hosting, namely
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

6)   Bernd Wurst <bernd@schokokeks.org>
7)   Hanno Böck <hanno@schokokeks.org>
8) 
Hanno Böck Change license from CC0 to...

Hanno Böck authored 1 year ago

9) This code is published under a 0BSD license.
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

10) 
11) Nevertheless, in case you use a significant part of this code, we ask (but not require, see the license) that you keep the authors' names in place and return your changes to the public. We would be especially happy if you tell us what you're going to do with this code.
12) */
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

13) 
14) require_once("certs.php");
Hanno Böck Fix XSS when deleting cert

Hanno Böck authored 1 year ago

15) require_once("inc/security.php");
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

16) require_role(ROLE_SYSTEMUSER);
17) 
18) $section = 'vhosts_certs';
19) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

20) if ($_GET['action'] == 'new') {
21)     check_form_token('vhosts_certs_new');
22)     if (! isset($_POST['cert'])) {
23)         system_failure("Es wurde kein Zertifikat eingegeben");
24)     }
25)     $cert = $_POST['cert'];
26)     $oldcert = null;
27)     if (isset($_REQUEST['replace']) && is_numeric($_REQUEST['replace'])) {
28)         $oldcert = cert_details($_REQUEST['replace']);
29)         DEBUG('altes cert:');
30)         DEBUG($oldcert);
31)     }
32)     $key = null;
33)     if (! isset($_POST['key']) && isset($_REQUEST['csr'])) {
34)         $csr = csr_details($_REQUEST['csr']);
35)         $key = $csr['key'];
36)     } elseif (isset($_POST['key']) and $_POST['key']) {
37)         $key = $_POST['key'];
38)     } elseif ($oldcert) {
39)         $key = $oldcert['key'];
40)     }
41) 
42)     if (! $cert or ! $key) {
43)         system_failure('Es muss ein Zertifikat und der dazu passende private Schlüssel eingetragen werden');
44)     }
45) 
46)     $result = validate_certificate($cert, $key);
47)     switch ($result) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 1 year ago

48)         case CERT_OK:
49)             $certinfo = parse_cert_details($cert);
50)             if ($oldcert) {
51)                 refresh_cert($oldcert['id'], $certinfo, $cert, $key);
52)             } else {
53)                 save_cert($certinfo, $cert, $key);
54)             }
55)             if (isset($_REQUEST['csr'])) {
56)                 delete_csr($_REQUEST['csr']);
57)             }
58)             header('Location: certs');
59)             die();
60)             break;
61)         case CERT_INVALID:
62)             system_failure("Das Zertifikat konnte nicht gelesen werden. Eventuell ist der private Schlüssel mit einem Paswort versehen?");
63)             break;
64)         case CERT_NOCHAIN:
65)             warning('Ihr Zertifikat konnte nicht mit einer Zertifikats-Kette validiert werden. Dies wird zu Problemen beim Betrachten der damit betriebenen Websites führen. Dies kann daran liegen dass es abgelaufen ist oder wenn kein passendes CA-Bundle hinterlegt wurde. Die Admins können Ihr Zertifikats-Bundle auf dem System eintragen. Das Zertifikat wurde dennoch gespeichert.');
66)             $certinfo = parse_cert_details($cert);
67)             if ($oldcert) {
68)                 refresh_cert($oldcert['id'], $certinfo, $cert, $key);
69)             } else {
70)                 save_cert($certinfo, $cert, $key);
71)             }
72)             output('<p>'.internal_link('certs', 'Zurück zur Übersicht').'</p>');
73)             if (isset($_REQUEST['csr'])) {
74)                 delete_csr($_REQUEST['csr']);
75)             }
76)             break;
77)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

78) } elseif ($_GET['action'] == 'refresh') {
79)     check_form_token('vhosts_certs_refresh');
80)     $cert = $_POST['cert'];
81)     $oldcert = cert_details($_REQUEST['id']);
82)     $key = $oldcert['key'];
83)     $id = (int) $_REQUEST['id'];
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

84) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

85)     if (! $cert) {
86)         system_failure('Es muss ein Zertifikat eingetragen werden');
87)     }
bernd Cert-Refresh

bernd authored 14 years ago

88) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

89)     $result = validate_certificate($cert, $key);
90)     switch ($result) {
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 1 year ago

91)         case CERT_OK:
92)             $certinfo = parse_cert_details($cert);
93)             if ($certinfo['cn'] != $oldcert['cn']) {
94)                 system_failure("Das neue Zertifikat enthält abweichende Daten. Legen Sie bitte ein neues Zertifikat an.");
95)             }
bernd Cert-Refresh

bernd authored 14 years ago

96) 
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 1 year ago

97)             refresh_cert($id, $certinfo, $cert);
98)             header('Location: certs');
99)             die();
100)             break;
101)         case CERT_INVALID:
102)             system_failure("Das Zertifikat konnte nicht gelesen werden. Eventuell ist es nicht wirklich eine neue Version des bisherigen Zertifikats.");
103)             break;
104)         case CERT_NOCHAIN:
105)             warning('Ihr Zertifikat konnte nicht mit einer Zertifikats-Kette validiert werden. Dies wird zu Problemen beim Betrachten der damit betriebenen Websites führen. Meist liegt dies an einem nicht hinterlegten CA-Bundle. Die Admins können Ihr Zertifikats-Bundle auf dem System eintragen. Das Zertifikat wurde dennoch gespeichert.');
106)             $certinfo = parse_cert_details($cert);
107)             if ($certinfo['cn'] != $oldcert['cn']) {
108)                 system_failure("Das neue Zertifikat enthält abweichende Daten. Legen Sie bitte ein neues Zertifikat an.");
109)             }
bernd Cert-Refresh

bernd authored 14 years ago

110) 
Hanno Böck more strict codingstyle wit...

Hanno Böck authored 1 year ago

111)             refresh_cert($id, $certinfo, $cert);
112)             output('<p>'.internal_link('certs', 'Zurück zur Übersicht').'</p>');
113)             break;
114)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

115) } elseif ($_GET['action'] == 'delete') {
116)     $cert = cert_details($_GET['id']);
117)     $sure = user_is_sure();
118)     if ($sure === null) {
Hanno Böck Fix XSS when deleting cert

Hanno Böck authored 1 year ago

119)         are_you_sure("action=delete&id={$cert['id']}", "Soll das Zertifikat für »".filter_output_html($cert['subject'])."« (gültig von {$cert['valid_from']} bis {$cert['valid_until']}) wirklich entfernt werden?");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

120)     } elseif ($sure === false) {
121)         header('Location: certs');
122)         die();
123)     } elseif ($sure === true) {
124)         delete_cert($cert['id']);
125)         header('Location: certs');
126)         die();
127)     }
128) } elseif ($_GET['action'] == 'deletecsr') {
129)     $csr = csr_details($_GET['id']);
130)     $sure = user_is_sure();
131)     if ($sure === null) {
132)         are_you_sure("action=deletecsr&id={$csr['id']}", "Soll der CSR für »{$csr['hostname']}« ({$csr['bits']} Bits, erstellt am {$csr['created']}) wirklich entfernt werden?");
133)     } elseif ($sure === false) {
134)         header('Location: certs');
135)         die();
136)     } elseif ($sure === true) {
137)         delete_csr($csr['id']);
138)         header('Location: certs');
139)         die();
140)     }
141) } elseif ($_GET['action'] == 'newcsr') {
142)     $replace = null;
143)     if (isset($_REQUEST['replace'])) {
144)         $replace = $_REQUEST['replace'];
145)     }
146)     $cn = urldecode($_REQUEST['commonname']);
147)     $bitlength = 4096;
148)     if (isset($_REQUEST['bitlength'])) {
149)         $bitlength = $_REQUEST['bitlength'];
150)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

151) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

152)     $id = save_csr($cn, $bitlength, $replace);
bernd CSR-Erstellung

bernd authored 14 years ago

153) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

154)     header("Location: showcert?mode=csr&id={$id}");
155)     die();
156) } else {
157)     system_failure('not implemented');