739b264ec7afb11011279a150a7b1cbcabb13258
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) 
Bernd Wurst Copyright year update

Bernd Wurst authored 6 years ago

5) Written 2008-2018 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) 
9) To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
10) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

11) You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see
Bernd Wurst Added license tags for CC0,...

Bernd Wurst authored 12 years ago

12) http://creativecommons.org/publicdomain/zero/1.0/
13) 
14) 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.
15) */
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

16) 
17) require_once('inc/base.php');
bernd CSR-Erstellung

bernd authored 14 years ago

18) require_once('inc/security.php');
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

19) 
20) define("CERT_OK", 0);
21) define("CERT_INVALID", 1);
22) define("CERT_NOCHAIN", 2);
23) 
24) function user_certs()
25) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

26)     $uid = (int) $_SESSION['userinfo']['uid'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

27)     $result = db_query("SELECT id, valid_from, valid_until, subject, cn FROM vhosts.certs WHERE uid=? ORDER BY cn", [$uid]);
28)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

29)     while ($i = $result->fetch()) {
30)         $ret[] = $i;
31)     }
32)     #DEBUG($ret);
33)     return $ret;
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

34) }
35) 
bernd CSR-Erstellung

bernd authored 14 years ago

36) function user_csr()
37) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

38)     $uid = (int) $_SESSION['userinfo']['uid'];
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

39)     $result = db_query("SELECT id, created, hostname, bits FROM vhosts.csr WHERE uid=? ORDER BY hostname", [$uid]);
40)     $ret = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

41)     while ($i = $result->fetch()) {
42)         $ret[] = $i;
43)     }
44)     #DEBUG($ret);
45)     return $ret;
bernd CSR-Erstellung

bernd authored 14 years ago

46) }
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

47) 
Bernd Wurst Interface für Zertifikate i...

Bernd Wurst authored 7 years ago

48) function user_has_manual_certs()
49) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

50)     foreach (user_certs() as $c) {
51)         if (!cert_is_letsencrypt($c['id'])) {
52)             return true;
53)         }
54)     }
55)     foreach (user_csr() as $c) {
56)         return true;
Bernd Wurst Interface für Zertifikate i...

Bernd Wurst authored 7 years ago

57)     }
58) }
59) 
60) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

61) function cert_details($id)
62) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

63)     $id = (int) $id;
64)     $uid = (int) $_SESSION['userinfo']['uid'];
Hanno remove whitespace in empty...

Hanno authored 5 years ago

65) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

66)     $result = db_query("SELECT id, lastchange, valid_from, valid_until, subject, cn, chain, cert, `key` FROM vhosts.certs WHERE uid=:uid AND id=:id", [":uid" => $uid, ":id" => $id]);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

67)     if ($result->rowCount() != 1) {
68)         system_failure("Ungültiges Zertifikat #{$id}");
69)     }
70)     return $result->fetch();
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

71) }
72) 
Bernd Wurst Status der letsencrypt-Opti...

Bernd Wurst authored 8 years ago

73) function cert_is_letsencrypt($id)
74) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

75)     $details = cert_details($id);
76)     #DEBUG($details);
77)     if (strpos($details['subject'], "Let's Encrypt autogenerated") > 0) {
78)         return true;
79)     }
80)     return false;
Bernd Wurst Status der letsencrypt-Opti...

Bernd Wurst authored 8 years ago

81) }
82) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

83) 
bernd CSR-Erstellung

bernd authored 14 years ago

84) function csr_details($id)
85) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

86)     $id = (int) $id;
87)     $uid = (int) $_SESSION['userinfo']['uid'];
Hanno remove whitespace in empty...

Hanno authored 5 years ago

88) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

89)     $result = db_query("SELECT id, created, hostname, bits, `replace`, csr, `key` FROM vhosts.csr WHERE uid=:uid AND id=:id", [":uid" => $uid, ":id" => $id]);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

90)     if ($result->rowCount() != 1) {
91)         system_failure("Ungültiger CSR");
92)     }
93)     return $result->fetch();
bernd CSR-Erstellung

bernd authored 14 years ago

94) }
95) 
96) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

97) function get_available_CAs()
98) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

99)     $path = '/etc/apache2/certs/cabundle/';
100)     $ret = glob($path.'*.pem');
101)     if (! $ret) {
102)         system_failure("Konnte die CA-Zertifikate nicht laden");
103)     }
104)     DEBUG($ret);
105)     return $ret;
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

106) }
107) 
108) 
bernd Cert-Chain erkennen und ben...

bernd authored 13 years ago

109) function get_chain($cert)
110) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

111)     $certdata = openssl_x509_parse($cert, true);
112)     if ($certdata === false) {
113)         system_failure("Das Zertifikat konnte nicht gelesen werden");
114)     }
115)     if (! isset($certdata['issuer']['CN'])) {
116)         return null;
117)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

118)     $result = db_query("SELECT id FROM vhosts.certchain WHERE cn=?", [$certdata['issuer']['CN']]);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

119)     if ($result->rowCount() > 0) {
120)         $c = $result->fetch();
121)         //$chainfile = '/etc/apache2/certs/chains/'.$c['id'].'.pem';
122)         DEBUG("identified fitting certificate chain #".$c['id']);
123)         return $c['id'];
124)     }
bernd Cert-Chain erkennen und ben...

bernd authored 13 years ago

125) }
126) 
127) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

128) function validate_certificate($cert, $key)
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

129) {
130)     // Lade private key
131)     $seckey = openssl_get_privatekey($key);
132)     if ($seckey === false) {
133)         system_failure("Der private Schlüssel konnte (ohne Passwort) nicht gelesen werden.");
134)     }
135)     // Lade public key
136)     $pubkey = openssl_get_publickey($cert);
137)     if ($pubkey === false) {
138)         system_failure("In dem eingetragenen Zertifikat wurde kein öffentlicher Schlüssel gefunden.");
139)     }
140)     // Parse Details über den pubkey
Hanno Böck deutlich striktere Checks b...

Hanno Böck authored 3 years ago

141)     $pubkeyinfo = openssl_pkey_get_details($pubkey);
142)     DEBUG($pubkeyinfo);
143)     if ($pubkeyinfo === false) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

144)         system_failure("Der öffentliche Schlüssel des Zertifikats konnte nicht gelesen werden");
145)     }
146) 
147)     // Apache unterstützt nur Schlüssel vom Typ RSA oder DSA
Hanno Böck deutlich striktere Checks b...

Hanno Böck authored 3 years ago

148)     if ($pubkeyinfo['type'] !== OPENSSL_KEYTYPE_RSA) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

149)         system_failure("Dieser Schlüssel nutzt einen nicht unterstützten Algorithmus.");
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)     // Bei ECC-Keys treten kürzere Schlüssellängen auf, die können wir aktuell aber sowieso nicht unterstützen
Hanno Böck deutlich striktere Checks b...

Hanno Böck authored 3 years ago

153)     // Wir blockieren zu kurze und zu lange Schlüssel hart, da Apache sonst nicht startet
154)     if ($pubkeyinfo['bits'] < 2048) {
155)         system_failure("Schlüssellänge ist zu kurz");
156)     }
157)     if ($pubkeyinfo['bits'] > 4096) {
158)         system_failure("Schlüssellänge ist zu lang");
159)     }
160) 
161)     $x509info = openssl_x509_parse($cert);
162)     if ($x509info === false) {
163)         system_failure("Zertifikat konnte nicht verarbeitet werden");
164)     }
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

165)     if (!in_array($x509info['signatureTypeSN'], ["RSA-SHA256", "RSA-SHA385", "RSA-SHA512"])) {
Hanno Böck deutlich striktere Checks b...

Hanno Böck authored 3 years ago

166)         system_failure("Nicht unterstützer Signatur-Hashalgorithmus!");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

167)     }
168) 
169)     // Prüfe ob Key und Zertifikat zusammen passen
170)     if (openssl_x509_check_private_key($cert, $key) !== true) {
171)         DEBUG("Zertifikat und Key passen nicht zusammen: ".openssl_x509_check_private_key($cert, $key));
172)         return CERT_INVALID;
173)     }
174) 
Hanno Böck deutlich striktere Checks b...

Hanno Böck authored 3 years ago

175)     // Check von openssl_x509_check_private_key() ist leider nicht ausreichend
176)     $testdata = base64_encode(random_bytes(32));
177)     if (openssl_sign($testdata, $signature, $seckey) !== true) {
178)         system_failure("Kann keine Testsignatur erstellen, Key ungültig!");
179)     }
180)     if (openssl_verify($testdata, $signature, $pubkey) !== 1) {
181)         system_failure("Testsignatur ungültig, Key vermutlich fehlerhaft!");
182)     }
183) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

184)     $cacerts = ['/etc/ssl/certs'];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

185)     $chain = (int) get_chain($cert);
186)     if ($chain) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

187)         $result = db_query("SELECT content FROM vhosts.certchain WHERE id=?", [$chain]);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

188)         $tmp = $result->fetch();
189)         $chaincert = $tmp['content'];
190)         $chainfile = tempnam(sys_get_temp_dir(), 'webinterface');
191)         $f = fopen($chainfile, "w");
192)         fwrite($f, $chaincert);
193)         fclose($f);
194)         $cacerts[] = $chainfile;
195)     }
196) 
197)     $valid = openssl_x509_checkpurpose($cert, X509_PURPOSE_SSL_SERVER, $cacerts);
198)     if ($chain) {
199)         unlink($chainfile);
200)     }
201)     if ($valid !== true) {
202)         DEBUG('certificate was not validated as a server certificate with the available chain');
203)         return CERT_NOCHAIN;
204)     }
205) 
206)     return CERT_OK;
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

207) }
208) 
209) 
210) function parse_cert_details($cert)
211) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

212)     $certdata = openssl_x509_parse($cert, true);
213)     DEBUG($certdata);
Hanno Böck handle empty SAN properly

Hanno Böck authored 1 year ago

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

Hanno authored 5 years ago

215)     $issuer = $certdata['issuer']['CN'];
216)     if (isset($certdata['issuer']['O'])) {
217)         $issuer = $certdata['issuer']['O'];
218)     }
Hanno Böck handle empty SAN properly

Hanno Böck authored 1 year ago

219)     if (isset($certdata['extensions']['subjectAltName'])) {
220)         DEBUG("SAN: ".$certdata['extensions']['subjectAltName']);
221)         $san = [];
222)         $raw_san = explode(', ', $certdata['extensions']['subjectAltName']);
223)         foreach ($raw_san as $name) {
224)             if (! substr($name, 0, 4) == 'DNS:') {
225)                 warning('Unparsable SAN: '.$name);
226)                 continue;
227)             }
228)             $san[] = str_replace('DNS:', '', $name);
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

229)         }
Hanno Böck handle empty SAN properly

Hanno Böck authored 1 year ago

230)         $san = implode("\n", $san);
231)     } else {
232)         $san = "\n";
Bernd Wurst Verarbeite und Speichere SA...

Bernd Wurst authored 7 years ago

233)     }
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

234)     DEBUG("SAN: <pre>".$san."</pre>");
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

235)     return ['subject' => $certdata['subject']['CN'].' / '.$issuer, 'cn' => $certdata['subject']['CN'], 'valid_from' => date('Y-m-d', $certdata['validFrom_time_t']), 'valid_until' => date('Y-m-d', $certdata['validTo_time_t']), 'issuer' => $certdata['issuer']['CN'], 'san' => $san];
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

236) }
237) 
238) 
239) function save_cert($info, $cert, $key)
240) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

241)     openssl_pkey_export($key, $key);
242)     openssl_x509_export($cert, $cert);
243)     $uid = (int) $_SESSION['userinfo']['uid'];
244) 
245)     db_query(
Hanno Update codingstyle accordin...

Hanno authored 5 years ago

246)         "INSERT INTO vhosts.certs (uid, subject, cn, san, valid_from, valid_until, chain, cert, `key`) VALUES (:uid, :subject, :cn, :san, :valid_from, :valid_until, :chain, :cert, :key)",
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

247)         [":uid" => $uid, ":subject" => filter_input_oneline($info['subject']), ":cn" => filter_input_oneline($info['cn']), ":san" => $info['san'], ":valid_from" => $info['valid_from'],
248)               ":valid_until" => $info['valid_until'], ":chain" => get_chain($cert), ":cert" => $cert, ":key" => $key, ]
Hanno Fix codingstyle

Hanno authored 4 years ago

249)     );
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

250) }
251) 
bernd Cert-Refresh

bernd authored 14 years ago

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

Hanno authored 5 years ago

253) function refresh_cert($id, $info, $cert, $key = null)
bernd Cert-Refresh

bernd authored 14 years ago

254) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

255)     openssl_x509_export($cert, $cert);
256)     $chain = get_chain($cert);
bernd Bugfix: Beim Eintragen eine...

bernd authored 13 years ago

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

Hanno authored 5 years ago

258)     $id = (int) $id;
259)     $oldcert = cert_details($id);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

260)     $args = [":subject" => filter_input_oneline($info['subject']),
Bernd Wurst Umstellung von filter_input...

Bernd Wurst authored 4 years ago

261)                 ":cn" => filter_input_oneline($info['cn']),
Bernd Wurst Fix SAN for refreshed certs

Bernd Wurst authored 5 years ago

262)                 ":san" => $info['san'],
Bernd Wurst Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

263)                 ":cert" => $cert,
264)                 ":valid_from" => $info['valid_from'],
265)                 ":valid_until" => $info['valid_until'],
266)                 ":chain" => get_chain($cert),
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

267)                 ":id" => $id, ];
Bernd Wurst Einige Statements auf Prepa...

Bernd Wurst authored 10 years ago

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

Hanno authored 5 years ago

269)     $keyop = '';
270)     if ($key) {
271)         openssl_pkey_export($key, $key);
272)         $keyop = ", `key`=:key";
273)         $args[":key"] = $key;
274)     }
275)     db_query("UPDATE vhosts.certs SET subject=:subject, cn=:cn, san=:san, cert=:cert{$keyop}, valid_from=:valid_from, valid_until=:valid_until, chain=:chain WHERE id=:id", $args);
bernd Cert-Refresh

bernd authored 14 years ago

276) }
277) 
278) 
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

279) function delete_cert($id)
280) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

281)     $uid = (int) $_SESSION['userinfo']['uid'];
282)     $id = (int) $id;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

283) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

284)     db_query("DELETE FROM vhosts.certs WHERE uid=? AND id=?", [$uid, $id]);
bernd Neue Zertifikatsverwaltung

bernd authored 14 years ago

285) }
286) 
bernd CSR-Erstellung

bernd authored 14 years ago

287) function delete_csr($id)
288) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

289)     $uid = (int) $_SESSION['userinfo']['uid'];
290)     $id = (int) $id;
Hanno remove whitespace in empty...

Hanno authored 5 years ago

291) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

292)     db_query("DELETE FROM vhosts.csr WHERE uid=? AND id=?", [$uid, $id]);
bernd CSR-Erstellung

bernd authored 14 years ago

293) }
294) 
295) 
Bernd Wurst * Ermögliche SAN bei CSRs *...

Bernd Wurst authored 8 years ago

296) function split_cn($cn)
297) {
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

298)     $domains = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

299)     if (strstr($cn, ',') or strstr($cn, "\n")) {
300)         $domains = preg_split("/[, \n]+/", $cn);
301)         DEBUG("Domains:");
302)         DEBUG($domains);
303)     } else {
304)         $domains[] = $cn;
305)     }
306)     for ($i=0;$i!=count($domains);$i++) {
307)         $domains[$i] = filter_input_hostname($domains[$i], true);
308)     }
309)     return $domains;
Bernd Wurst * Ermögliche SAN bei CSRs *...

Bernd Wurst authored 8 years ago

310) }
311) 
bernd CSR-Erstellung

bernd authored 14 years ago

312) function create_csr($cn, $bits)
313) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

314)     $domains = split_cn($cn);
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

315)     $tmp = [];
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

316)     foreach ($domains as $dom) {
317)         $tmp[] = 'DNS:'.$dom;
318)     }
319)     $SAN = "[ v3_req ]\nsubjectAltName = ".implode(', ', $tmp);
320)     DEBUG($SAN);
321)     $cn = $domains[0];
322)     $bits = (int) $bits;
323)     if ($bits == 0) {
324)         $bits = 4096;
325)     }
326) 
327)     $keyfile = tempnam(ini_get('upload_tmp_dir'), 'key');
328)     $csrfile = tempnam(ini_get('upload_tmp_dir'), 'csr');
329)     $config = tempnam(ini_get('upload_tmp_dir'), 'config');
330) 
331)     DEBUG("key: ".$keyfile." / csr: ".$csrfile." / config: ".$config);
332) 
333)     $c = fopen($config, "w");
334)     fwrite($c, "[req]
bernd CSR-Erstellung

bernd authored 14 years ago

335) default_bits = {$bits}
336) default_keyfile = {$keyfile}
337) encrypt_key = no
338) distinguished_name      = req_distinguished_name
Bernd Wurst * Ermögliche SAN bei CSRs *...

Bernd Wurst authored 8 years ago

339) req_extensions = v3_req
bernd CSR-Erstellung

bernd authored 14 years ago

340) 
341) [ req_distinguished_name ]
342) countryName                     = Country Name (2 letter code)
Bernd Wurst Leere Vorgaben für CSR-Details

Bernd Wurst authored 10 years ago

343) countryName_default             = 
bernd CSR-Erstellung

bernd authored 14 years ago

344) stateOrProvinceName             = State or Province Name (full name)
Bernd Wurst Leere Vorgaben für CSR-Details

Bernd Wurst authored 10 years ago

345) stateOrProvinceName_default     = 
bernd CSR-Erstellung

bernd authored 14 years ago

346) localityName                    = Locality Name (eg, city)
Bernd Wurst Leere Vorgaben für CSR-Details

Bernd Wurst authored 10 years ago

347) localityName_default            = 
bernd CSR-Erstellung

bernd authored 14 years ago

348) 0.organizationName              = Organization Name (eg, company)
Bernd Wurst Leere Vorgaben für CSR-Details

Bernd Wurst authored 10 years ago

349) 0.organizationName_default      = 
bernd CSR-Erstellung

bernd authored 14 years ago

350) 
351) commonName = Common Name
352) commonName_default = {$cn}
Bernd Wurst * Ermögliche SAN bei CSRs *...

Bernd Wurst authored 8 years ago

353) {$SAN}
bernd CSR-Erstellung

bernd authored 14 years ago

354) ");
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

355)     fclose($c);
356) 
357)     $output = '';
358)     $cmdline = "openssl req -sha256 -new -batch -config {$config} -out {$csrfile}";
359)     $retval = 0;
360)     exec($cmdline, $output, $retval);
361)     DEBUG($output);
362)     DEBUG($retval);
363)     if ($retval != 0) {
364)         system_failure("Die Erzeugung des CSR ist fehlgeschlagen. Ausgabe des OpenSSL-Befehls: ".print_r($output, true));
365)     }
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

367)     $csr = file_get_contents($csrfile);
368)     $key = file_get_contents($keyfile);
bernd CSR-Erstellung

bernd authored 14 years ago

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

Hanno authored 5 years ago

370)     unlink($csrfile);
371)     unlink($keyfile);
372)     unlink($config);
bernd CSR-Erstellung

bernd authored 14 years ago

373) 
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

374)     return [$csr, $key];
bernd CSR-Erstellung

bernd authored 14 years ago

375) }
376) 
377) 
378) 
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

379) function save_csr($cn, $bits, $replace=null)
bernd CSR-Erstellung

bernd authored 14 years ago

380) {
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

381)     if (! $cn) {
382)         system_failure("Sie müssen einen Domainname eingeben!");
383)     }
384)     $domains = split_cn($cn);
385)     $cn = $domains[0];
386)     $san = implode("\n", $domains);
387)     $csr = null;
388)     $key = null;
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

389)     [$csr, $key] = create_csr(implode(',', $domains), $bits);
Hanno remove whitespace in empty...

Hanno authored 5 years ago

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

Hanno authored 5 years ago

391)     $uid = (int) $_SESSION['userinfo']['uid'];
392)     db_query(
Hanno Update codingstyle accordin...

Hanno authored 5 years ago

393)         "INSERT INTO vhosts.csr (uid, hostname, san, bits, `replace`, csr, `key`) VALUES (:uid, :cn, :san, :bits, :replace, :csr, :key)",
Hanno Böck Codingstyle PSR12 + array s...

Hanno Böck authored 2 years ago

394)         [":uid" => $uid, ":cn" => $cn, ":san" => $san, ":bits" => $bits,
395)                  ":replace" => $replace, ":csr" => $csr, ":key" => $key, ]
Hanno Fix codingstyle

Hanno authored 4 years ago

396)     );
Hanno Fix coding style with php-c...

Hanno authored 5 years ago

397)     $id = db_insert_id();
398)     return $id;