Passed
Push — master ( 917895...d3c8c9 )
by Stefan
13:02
created
core/CertificationAuthorityEmbeddedECDSA.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -15,10 +15,10 @@  discard block
 block discarded – undo
15 15
 
16 16
 class CertificationAuthorityEmbeddedECDSA extends EntityWithDBProperties implements CertificationAuthorityInterface {
17 17
 
18
-    private const LOCATION_ROOT_CA = ROOT . "/config/SilverbulletClientCerts/rootca-ECDSA.pem";
19
-    private const LOCATION_ISSUING_CA = ROOT . "/config/SilverbulletClientCerts/real-ECDSA.pem";
20
-    private const LOCATION_ISSUING_KEY = ROOT . "/config/SilverbulletClientCerts/real-ECDSA.key";
21
-    private const LOCATION_CONFIG = ROOT . "/config/SilverbulletClientCerts/openssl-ECDSA.cnf";
18
+    private const LOCATION_ROOT_CA = ROOT."/config/SilverbulletClientCerts/rootca-ECDSA.pem";
19
+    private const LOCATION_ISSUING_CA = ROOT."/config/SilverbulletClientCerts/real-ECDSA.pem";
20
+    private const LOCATION_ISSUING_KEY = ROOT."/config/SilverbulletClientCerts/real-ECDSA.key";
21
+    private const LOCATION_CONFIG = ROOT."/config/SilverbulletClientCerts/openssl-ECDSA.cnf";
22 22
 
23 23
     /**
24 24
      * string with the PEM variant of the root CA
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
         parent::__construct();
65 65
         $this->rootPem = file_get_contents(CertificationAuthorityEmbeddedECDSA::LOCATION_ROOT_CA);
66 66
         if ($this->rootPem === FALSE) {
67
-            throw new Exception("Root CA PEM file not found: " . CertificationAuthorityEmbeddedECDSA::LOCATION_ROOT_CA);
67
+            throw new Exception("Root CA PEM file not found: ".CertificationAuthorityEmbeddedECDSA::LOCATION_ROOT_CA);
68 68
         }
69 69
         $this->issuingCertRaw = file_get_contents(CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA);
70 70
         if ($this->issuingCertRaw === FALSE) {
71
-            throw new Exception("Issuing CA PEM file not found: " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA);
71
+            throw new Exception("Issuing CA PEM file not found: ".CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA);
72 72
         }
73 73
         $rootParsed = openssl_x509_read($this->rootPem);
74 74
         $this->issuingCert = openssl_x509_read($this->issuingCertRaw);
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
             throw new Exception("At least one CA PEM file did not parse correctly!");
77 77
         }
78 78
         if (stat(CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY) === FALSE) {
79
-            throw new Exception("Private key not found: " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY);
79
+            throw new Exception("Private key not found: ".CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY);
80 80
         }
81
-        $issuingKeyTemp = openssl_pkey_get_private("file://" . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY);
81
+        $issuingKeyTemp = openssl_pkey_get_private("file://".CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY);
82 82
         if ($issuingKeyTemp === FALSE) {
83 83
             throw new Exception("The private key did not parse correctly!");
84 84
         }
85 85
         $this->issuingKey = $issuingKeyTemp;
86 86
         if (stat(CertificationAuthorityEmbeddedECDSA::LOCATION_CONFIG) === FALSE) {
87
-            throw new Exception("openssl configuration not found: " . CertificationAuthorityEmbeddedECDSA::LOCATION_CONFIG);
87
+            throw new Exception("openssl configuration not found: ".CertificationAuthorityEmbeddedECDSA::LOCATION_CONFIG);
88 88
         }
89 89
         $this->conffile = CertificationAuthorityEmbeddedECDSA::LOCATION_CONFIG;
90 90
     }
@@ -126,27 +126,27 @@  discard block
 block discarded – undo
126 126
         // generate stub index.txt file
127 127
         $tempdirArray = \core\common\Entity::createTemporaryDirectory("test");
128 128
         $tempdir = $tempdirArray['dir'];
129
-        $nowIndexTxt = (new \DateTime())->format("ymdHis") . "Z";
130
-        $expiryIndexTxt = $originalExpiry->format("ymdHis") . "Z";
129
+        $nowIndexTxt = (new \DateTime())->format("ymdHis")."Z";
130
+        $expiryIndexTxt = $originalExpiry->format("ymdHis")."Z";
131 131
         // serials for our CA are always integers
132
-        $serialHex = strtoupper(dechex((int)$cert->serial));
132
+        $serialHex = strtoupper(dechex((int) $cert->serial));
133 133
         if (strlen($serialHex) % 2 == 1) {
134
-            $serialHex = "0" . $serialHex;
134
+            $serialHex = "0".$serialHex;
135 135
         }
136 136
 
137
-        $indexStatement = "$certstatus\t$expiryIndexTxt\t" . ($certstatus == "R" ? "$nowIndexTxt,unspecified" : "") . "\t$serialHex\tunknown\t/O=" . \config\ConfAssistant::CONSORTIUM['name'] . "/OU=$federation/CN=$cert->username\n";
137
+        $indexStatement = "$certstatus\t$expiryIndexTxt\t".($certstatus == "R" ? "$nowIndexTxt,unspecified" : "")."\t$serialHex\tunknown\t/O=".\config\ConfAssistant::CONSORTIUM['name']."/OU=$federation/CN=$cert->username\n";
138 138
         $this->loggerInstance->debug(4, "index.txt contents-to-be: $indexStatement");
139
-        if (!file_put_contents($tempdir . "/index.txt", $indexStatement)) {
139
+        if (!file_put_contents($tempdir."/index.txt", $indexStatement)) {
140 140
             $this->loggerInstance->debug(1, "Unable to write openssl index.txt file for revocation handling!");
141 141
         }
142 142
         // index.txt.attr is dull but needs to exist
143
-        file_put_contents($tempdir . "/index.txt.attr", "unique_subject = yes\n");
143
+        file_put_contents($tempdir."/index.txt.attr", "unique_subject = yes\n");
144 144
         // call "openssl ocsp" to manufacture our own OCSP statement
145 145
         // adding "-rmd sha1" to the following command-line makes the
146 146
         // choice of signature algorithm for the response explicit
147 147
         // but it's only available from openssl-1.1.0 (which we do not
148 148
         // want to require just for that one thing).
149
-        $execCmd = \config\Master::PATHS['openssl'] . " ocsp -issuer " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA . " -sha1 -ndays 10 -no_nonce -serial 0x$serialHex -CA " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA . " -rsigner " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA . " -rkey " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY . " -index $tempdir/index.txt -no_cert_verify -respout $tempdir/$serialHex.response.der";
149
+        $execCmd = \config\Master::PATHS['openssl']." ocsp -issuer ".CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA." -sha1 -ndays 10 -no_nonce -serial 0x$serialHex -CA ".CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA." -rsigner ".CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA." -rkey ".CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY." -index $tempdir/index.txt -no_cert_verify -respout $tempdir/$serialHex.response.der";
150 150
         $this->loggerInstance->debug(2, "Calling openssl ocsp with following cmdline: $execCmd\n");
151 151
         $output = [];
152 152
         $return = 999;
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
         if ($return !== 0) {
155 155
             throw new Exception("Non-zero return value from openssl ocsp!");
156 156
         }
157
-        $ocsp = file_get_contents($tempdir . "/$serialHex.response.der");
157
+        $ocsp = file_get_contents($tempdir."/$serialHex.response.der");
158 158
         // remove the temp dir!
159
-        unlink($tempdir . "/$serialHex.response.der");
160
-        unlink($tempdir . "/index.txt.attr");
161
-        unlink($tempdir . "/index.txt");
159
+        unlink($tempdir."/$serialHex.response.der");
160
+        unlink($tempdir."/index.txt.attr");
161
+        unlink($tempdir."/index.txt");
162 162
         rmdir($tempdir);
163 163
         $this->databaseHandle->exec("UPDATE silverbullet_certificate SET OCSP = ?, OCSP_timestamp = NOW() WHERE serial_number = ?", "si", $ocsp, $cert->serial);
164 164
         return $ocsp;
Please login to merge, or discard this patch.
core/CertificationAuthorityEduPki.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
 
17 17
 class CertificationAuthorityEduPki extends EntityWithDBProperties implements CertificationAuthorityInterface {
18 18
 
19
-    private const LOCATION_RA_CERT = ROOT . "/config/SilverbulletClientCerts/edupki-test-ra.pem";
20
-    private const LOCATION_RA_KEY = ROOT . "/config/SilverbulletClientCerts/edupki-test-ra.clearkey";
21
-    private const LOCATION_WEBROOT = ROOT . "/config/SilverbulletClientCerts/eduPKI-webserver-root.pem";
19
+    private const LOCATION_RA_CERT = ROOT."/config/SilverbulletClientCerts/edupki-test-ra.pem";
20
+    private const LOCATION_RA_KEY = ROOT."/config/SilverbulletClientCerts/edupki-test-ra.clearkey";
21
+    private const LOCATION_WEBROOT = ROOT."/config/SilverbulletClientCerts/eduPKI-webserver-root.pem";
22 22
     private const EDUPKI_RA_ID = 700;
23 23
     private const EDUPKI_CERT_PROFILE = "User SOAP";
24 24
     private const EDUPKI_RA_PKEY_PASSPHRASE = "...";
@@ -33,13 +33,13 @@  discard block
 block discarded – undo
33 33
         parent::__construct();
34 34
 
35 35
         if (stat(CertificationAuthorityEduPki::LOCATION_RA_CERT) === FALSE) {
36
-            throw new Exception("RA operator PEM file not found: " . CertificationAuthorityEduPki::LOCATION_RA_CERT);
36
+            throw new Exception("RA operator PEM file not found: ".CertificationAuthorityEduPki::LOCATION_RA_CERT);
37 37
         }
38 38
         if (stat(CertificationAuthorityEduPki::LOCATION_RA_KEY) === FALSE) {
39
-            throw new Exception("RA operator private key file not found: " . CertificationAuthorityEduPki::LOCATION_RA_KEY);
39
+            throw new Exception("RA operator private key file not found: ".CertificationAuthorityEduPki::LOCATION_RA_KEY);
40 40
         }
41 41
         if (stat(CertificationAuthorityEduPki::LOCATION_WEBROOT) === FALSE) {
42
-            throw new Exception("CA website root CA file not found: " . CertificationAuthorityEduPki::LOCATION_WEBROOT);
42
+            throw new Exception("CA website root CA file not found: ".CertificationAuthorityEduPki::LOCATION_WEBROOT);
43 43
         }
44 44
     }
45 45
 
@@ -68,19 +68,19 @@  discard block
 block discarded – undo
68 68
         // initialise connection to eduPKI CA / eduroam RA and send the request to them
69 69
         try {
70 70
             $altArray = [# Array mit den Subject Alternative Names
71
-                "email:" . $csr["USERNAME"]
71
+                "email:".$csr["USERNAME"]
72 72
             ];
73 73
             $soapPub = $this->initEduPKISoapSession("PUBLIC");
74 74
             $this->loggerInstance->debug(5, "FIRST ACTUAL SOAP REQUEST (Public, newRequest)!\n");
75
-            $this->loggerInstance->debug(5, "PARAM_1: " . CertificationAuthorityEduPki::EDUPKI_RA_ID . "\n");
76
-            $this->loggerInstance->debug(5, "PARAM_2: " . $csr["CSR"] . "\n");
75
+            $this->loggerInstance->debug(5, "PARAM_1: ".CertificationAuthorityEduPki::EDUPKI_RA_ID."\n");
76
+            $this->loggerInstance->debug(5, "PARAM_2: ".$csr["CSR"]."\n");
77 77
             $this->loggerInstance->debug(5, "PARAM_3: ");
78 78
             $this->loggerInstance->debug(5, $altArray);
79
-            $this->loggerInstance->debug(5, "PARAM_4: " . CertificationAuthorityEduPki::EDUPKI_CERT_PROFILE . "\n");
80
-            $this->loggerInstance->debug(5, "PARAM_5: " . sha1("notused") . "\n");
81
-            $this->loggerInstance->debug(5, "PARAM_6: " . $csr["USERNAME"] . "\n");
82
-            $this->loggerInstance->debug(5, "PARAM_7: " . $csr["USERNAME"] . "\n");
83
-            $this->loggerInstance->debug(5, "PARAM_8: " . ProfileSilverbullet::PRODUCTNAME . "\n");
79
+            $this->loggerInstance->debug(5, "PARAM_4: ".CertificationAuthorityEduPki::EDUPKI_CERT_PROFILE."\n");
80
+            $this->loggerInstance->debug(5, "PARAM_5: ".sha1("notused")."\n");
81
+            $this->loggerInstance->debug(5, "PARAM_6: ".$csr["USERNAME"]."\n");
82
+            $this->loggerInstance->debug(5, "PARAM_7: ".$csr["USERNAME"]."\n");
83
+            $this->loggerInstance->debug(5, "PARAM_8: ".ProfileSilverbullet::PRODUCTNAME."\n");
84 84
             $this->loggerInstance->debug(5, "PARAM_9: false\n");
85 85
             $soapNewRequest = $soapPub->newRequest(
86 86
                     CertificationAuthorityEduPki::EDUPKI_RA_ID, # RA-ID
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
         } catch (Exception $e) {
103 103
             // PHP 7.1 can do this much better
104 104
             if (is_soap_fault($e)) {
105
-                throw new Exception("Error when sending SOAP request: " . "{$e->faultcode}:  {
105
+                throw new Exception("Error when sending SOAP request: "."{$e->faultcode}:  {
106 106
                     $e->faultstring
107 107
                 }\n");
108 108
             }
109
-            throw new Exception("Something odd happened while doing the SOAP request:" . $e->getMessage());
109
+            throw new Exception("Something odd happened while doing the SOAP request:".$e->getMessage());
110 110
         }
111 111
         try {
112 112
             $soap = $this->initEduPKISoapSession("RA");
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
                     $soapReqnum, [
119 119
                 "RaID" => CertificationAuthorityEduPki::EDUPKI_RA_ID,
120 120
                 "Role" => CertificationAuthorityEduPki::EDUPKI_CERT_PROFILE,
121
-                "Subject" => "DC=eduroam,DC=test,DC=test,C=" . $csr["FED"] . ",O=" . \config\ConfAssistant::CONSORTIUM['name'] . ",OU=" . $csr["FED"] . ",CN=" . $csr['USERNAME'] . ",emailAddress=" . $csr['USERNAME'],
122
-                "SubjectAltNames" => ["email:" . $csr["USERNAME"]],
121
+                "Subject" => "DC=eduroam,DC=test,DC=test,C=".$csr["FED"].",O=".\config\ConfAssistant::CONSORTIUM['name'].",OU=".$csr["FED"].",CN=".$csr['USERNAME'].",emailAddress=".$csr['USERNAME'],
122
+                "SubjectAltNames" => ["email:".$csr["USERNAME"]],
123 123
                 "NotBefore" => (new \DateTime())->format('c'),
124 124
                 "NotAfter" => $expiry->format('c'),
125 125
                     ]
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
             // for obnoxious reasons, we have to dump the request into a file and let pkcs7_sign read from the file
139 139
             // rather than just using the string. Grr.
140 140
             $tempdir = \core\common\Entity::createTemporaryDirectory("test");
141
-            file_put_contents($tempdir['dir'] . "/content.txt", $soapCleartext);
141
+            file_put_contents($tempdir['dir']."/content.txt", $soapCleartext);
142 142
             // retrieve our RA cert from filesystem                    
143 143
             // the RA certificates are not needed right now because we
144 144
             // have resorted to S/MIME signatures with openssl command-line
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
             // sign the data, using cmdline because openssl_pkcs7_sign produces strange results
151 151
             // -binary didn't help, nor switch -md to sha1 sha256 or sha512
152 152
             $this->loggerInstance->debug(5, "Actual content to be signed is this:\n  $soapCleartext\n");
153
-            $execCmd = \config\Master::PATHS['openssl'] . " smime -sign -binary -in " . $tempdir['dir'] . "/content.txt -out " . $tempdir['dir'] . "/signature.txt -outform pem -inkey " . ROOT . "/config/SilverbulletClientCerts/edupki-test-ra.clearkey -signer " . ROOT . "/config/SilverbulletClientCerts/edupki-test-ra.pem";
153
+            $execCmd = \config\Master::PATHS['openssl']." smime -sign -binary -in ".$tempdir['dir']."/content.txt -out ".$tempdir['dir']."/signature.txt -outform pem -inkey ".ROOT."/config/SilverbulletClientCerts/edupki-test-ra.clearkey -signer ".ROOT."/config/SilverbulletClientCerts/edupki-test-ra.pem";
154 154
             $this->loggerInstance->debug(2, "Calling openssl smime with following cmdline:   $execCmd\n");
155 155
             $output = [];
156 156
             $return = 999;
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
                 throw new Exception("Non-zero return value from openssl smime!");
160 160
             }
161 161
             // and get the signature blob back from the filesystem
162
-            $detachedSig = trim(file_get_contents($tempdir['dir'] . "/signature.txt"));
162
+            $detachedSig = trim(file_get_contents($tempdir['dir']."/signature.txt"));
163 163
             $this->loggerInstance->debug(5, "Request for server approveRequest has parameters:\n");
164
-            $this->loggerInstance->debug(5, $soapReqnum . "\n");
165
-            $this->loggerInstance->debug(5, $soapCleartext . "\n"); // PHP magically encodes this as base64 while sending!
166
-            $this->loggerInstance->debug(5, $detachedSig . "\n");
164
+            $this->loggerInstance->debug(5, $soapReqnum."\n");
165
+            $this->loggerInstance->debug(5, $soapCleartext."\n"); // PHP magically encodes this as base64 while sending!
166
+            $this->loggerInstance->debug(5, $detachedSig."\n");
167 167
             $soapIssueCert = $soap->approveRequest($soapReqnum, $soapCleartext, $detachedSig);
168
-            $this->loggerInstance->debug(5, "approveRequest Request was: \n" . $soap->__getLastRequest());
169
-            $this->loggerInstance->debug(5, "approveRequest Response was: \n" . $soap->__getLastResponse());
168
+            $this->loggerInstance->debug(5, "approveRequest Request was: \n".$soap->__getLastRequest());
169
+            $this->loggerInstance->debug(5, "approveRequest Response was: \n".$soap->__getLastResponse());
170 170
             if ($soapIssueCert === FALSE) {
171 171
                 throw new Exception("The locally approved request was NOT processed by the CA.");
172 172
             }
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
                 throw new Exception("CAInfo has no root certificate for us!");
204 204
             }
205 205
         } catch (SoapFault $e) {
206
-            throw new Exception("SoapFault: Error when sending or receiving SOAP message: " . "{$e->faultcode}: {$e->faultname}: {$e->faultstring}: {$e->faultactor}: {$e->detail}: {$e->headerfault}\n");
206
+            throw new Exception("SoapFault: Error when sending or receiving SOAP message: "."{$e->faultcode}: {$e->faultname}: {$e->faultstring}: {$e->faultactor}: {$e->detail}: {$e->headerfault}\n");
207 207
         } catch (Exception $e) {
208
-            throw new Exception("Exception: Something odd happened between the SOAP requests:" . $e->getMessage());
208
+            throw new Exception("Exception: Something odd happened between the SOAP requests:".$e->getMessage());
209 209
         }
210 210
         return [
211 211
             "CERT" => openssl_x509_read($parsedCert['pem']),
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
             // for obnoxious reasons, we have to dump the request into a file and let pkcs7_sign read from the file
238 238
             // rather than just using the string. Grr.
239 239
             $tempdir = \core\common\Entity::createTemporaryDirectory("test");
240
-            file_put_contents($tempdir['dir'] . "/content.txt", $soapRawRevRequest);
240
+            file_put_contents($tempdir['dir']."/content.txt", $soapRawRevRequest);
241 241
             // retrieve our RA cert from filesystem
242 242
             // sign the data, using cmdline because openssl_pkcs7_sign produces strange results
243 243
             // -binary didn't help, nor switch -md to sha1 sha256 or sha512
244 244
             $this->loggerInstance->debug(5, "Actual content to be signed is this:\n$soapRawRevRequest\n");
245
-            $execCmd = \config\Master::PATHS['openssl'] . " smime -sign -binary -in " . $tempdir['dir'] . "/content.txt -out " . $tempdir['dir'] . "/signature.txt -outform pem -inkey " . CertificationAuthorityEduPki::LOCATION_RA_KEY . " -signer " . CertificationAuthorityEduPki::LOCATION_RA_CERT;
245
+            $execCmd = \config\Master::PATHS['openssl']." smime -sign -binary -in ".$tempdir['dir']."/content.txt -out ".$tempdir['dir']."/signature.txt -outform pem -inkey ".CertificationAuthorityEduPki::LOCATION_RA_KEY." -signer ".CertificationAuthorityEduPki::LOCATION_RA_CERT;
246 246
             $this->loggerInstance->debug(2, "Calling openssl smime with following cmdline: $execCmd\n");
247 247
             $output = [];
248 248
             $return = 999;
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
                 throw new Exception("Non-zero return value from openssl smime!");
252 252
             }
253 253
             // and get the signature blob back from the filesystem
254
-            $detachedSig = trim(file_get_contents($tempdir['dir'] . "/signature.txt"));
254
+            $detachedSig = trim(file_get_contents($tempdir['dir']."/signature.txt"));
255 255
             $soapIssueRev = $soap->approveRevocationRequest($soapRevocationSerial, $soapRawRevRequest, $detachedSig);
256 256
             if ($soapIssueRev === FALSE) {
257 257
                 throw new Exception("The locally approved revocation request was NOT processed by the CA.");
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
         } catch (Exception $e) {
260 260
             // PHP 7.1 can do this much better
261 261
             if (is_soap_fault($e)) {
262
-                throw new Exception("Error when sending SOAP request: " . "{$e->faultcode}: {$e->faultstring}\n");
262
+                throw new Exception("Error when sending SOAP request: "."{$e->faultcode}: {$e->faultstring}\n");
263 263
             }
264
-            throw new Exception("Something odd happened while doing the SOAP request:" . $e->getMessage());
264
+            throw new Exception("Something odd happened while doing the SOAP request:".$e->getMessage());
265 265
         }
266 266
     }
267 267
 
@@ -358,9 +358,9 @@  discard block
 block discarded – undo
358 358
      * @return string the integer as string in an XML fragment
359 359
      */
360 360
     public function soapToXmlInteger($x) {
361
-        return '<' . $x[0] . '>'
361
+        return '<'.$x[0].'>'
362 362
                 . htmlentities($x[1], ENT_NOQUOTES | ENT_XML1)
363
-                . '</' . $x[0] . '>';
363
+                . '</'.$x[0].'>';
364 364
     }
365 365
 
366 366
     /**
@@ -378,9 +378,9 @@  discard block
 block discarded – undo
378 378
         // dump private key into directory
379 379
         $outstring = "";
380 380
         openssl_pkey_export($privateKey, $outstring);
381
-        file_put_contents($tempdir . "/pkey.pem", $outstring);
381
+        file_put_contents($tempdir."/pkey.pem", $outstring);
382 382
         // PHP can only do one DC in the Subject. But we need three.
383
-        $execCmd = \config\Master::PATHS['openssl'] . " req -new -sha256 -key $tempdir/pkey.pem -out $tempdir/request.csr -subj /DC=test/DC=test/DC=eduroam/C=$fed/O=" . \config\ConfAssistant::CONSORTIUM['name'] . "/OU=$fed/CN=$username/emailAddress=$username";
383
+        $execCmd = \config\Master::PATHS['openssl']." req -new -sha256 -key $tempdir/pkey.pem -out $tempdir/request.csr -subj /DC=test/DC=test/DC=eduroam/C=$fed/O=".\config\ConfAssistant::CONSORTIUM['name']."/OU=$fed/CN=$username/emailAddress=$username";
384 384
         $this->loggerInstance->debug(2, "Calling openssl req with following cmdline: $execCmd\n");
385 385
         $output = [];
386 386
         $return = 999;
Please login to merge, or discard this patch.
core/CertificationAuthorityEmbeddedRSA.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -15,10 +15,10 @@  discard block
 block discarded – undo
15 15
 
16 16
 class CertificationAuthorityEmbeddedRSA extends EntityWithDBProperties implements CertificationAuthorityInterface {
17 17
 
18
-    private const LOCATION_ROOT_CA = ROOT . "/config/SilverbulletClientCerts/rootca-RSA.pem";
19
-    private const LOCATION_ISSUING_CA = ROOT . "/config/SilverbulletClientCerts/real-RSA.pem";
20
-    private const LOCATION_ISSUING_KEY = ROOT . "/config/SilverbulletClientCerts/real-RSA.key";
21
-    private const LOCATION_CONFIG = ROOT . "/config/SilverbulletClientCerts/openssl-RSA.cnf";
18
+    private const LOCATION_ROOT_CA = ROOT."/config/SilverbulletClientCerts/rootca-RSA.pem";
19
+    private const LOCATION_ISSUING_CA = ROOT."/config/SilverbulletClientCerts/real-RSA.pem";
20
+    private const LOCATION_ISSUING_KEY = ROOT."/config/SilverbulletClientCerts/real-RSA.key";
21
+    private const LOCATION_CONFIG = ROOT."/config/SilverbulletClientCerts/openssl-RSA.cnf";
22 22
 
23 23
     /**
24 24
      * string with the PEM variant of the root CA
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
         parent::__construct();
65 65
         $this->rootPem = file_get_contents(CertificationAuthorityEmbeddedRSA::LOCATION_ROOT_CA);
66 66
         if ($this->rootPem === FALSE) {
67
-            throw new Exception("Root CA PEM file not found: " . CertificationAuthorityEmbeddedRSA::LOCATION_ROOT_CA);
67
+            throw new Exception("Root CA PEM file not found: ".CertificationAuthorityEmbeddedRSA::LOCATION_ROOT_CA);
68 68
         }
69 69
         $this->issuingCertRaw = file_get_contents(CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_CA);
70 70
         if ($this->issuingCertRaw === FALSE) {
71
-            throw new Exception("Issuing CA PEM file not found: " . CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_CA);
71
+            throw new Exception("Issuing CA PEM file not found: ".CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_CA);
72 72
         }
73 73
         $rootParsed = openssl_x509_read($this->rootPem);
74 74
         $this->issuingCert = openssl_x509_read($this->issuingCertRaw);
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
             throw new Exception("At least one CA PEM file did not parse correctly!");
77 77
         }
78 78
         if (stat(CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_KEY) === FALSE) {
79
-            throw new Exception("Private key not found: " . CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_KEY);
79
+            throw new Exception("Private key not found: ".CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_KEY);
80 80
         }
81
-        $issuingKeyTemp = openssl_pkey_get_private("file://" . CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_KEY);
81
+        $issuingKeyTemp = openssl_pkey_get_private("file://".CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_KEY);
82 82
         if ($issuingKeyTemp === FALSE) {
83 83
             throw new Exception("The private key did not parse correctly!");
84 84
         }
85 85
         $this->issuingKey = $issuingKeyTemp;
86 86
         if (stat(CertificationAuthorityEmbeddedRSA::LOCATION_CONFIG) === FALSE) {
87
-            throw new Exception("openssl configuration not found: " . CertificationAuthorityEmbeddedRSA::LOCATION_CONFIG);
87
+            throw new Exception("openssl configuration not found: ".CertificationAuthorityEmbeddedRSA::LOCATION_CONFIG);
88 88
         }
89 89
         $this->conffile = CertificationAuthorityEmbeddedRSA::LOCATION_CONFIG;
90 90
     }
@@ -126,27 +126,27 @@  discard block
 block discarded – undo
126 126
         // generate stub index.txt file
127 127
         $tempdirArray = \core\common\Entity::createTemporaryDirectory("test");
128 128
         $tempdir = $tempdirArray['dir'];
129
-        $nowIndexTxt = (new \DateTime())->format("ymdHis") . "Z";
130
-        $expiryIndexTxt = $originalExpiry->format("ymdHis") . "Z";
129
+        $nowIndexTxt = (new \DateTime())->format("ymdHis")."Z";
130
+        $expiryIndexTxt = $originalExpiry->format("ymdHis")."Z";
131 131
         // serials for our CA are always integers
132
-        $serialHex = strtoupper(dechex((int)$cert->serial));
132
+        $serialHex = strtoupper(dechex((int) $cert->serial));
133 133
         if (strlen($serialHex) % 2 == 1) {
134
-            $serialHex = "0" . $serialHex;
134
+            $serialHex = "0".$serialHex;
135 135
         }
136 136
 
137
-        $indexStatement = "$certstatus\t$expiryIndexTxt\t" . ($certstatus == "R" ? "$nowIndexTxt,unspecified" : "") . "\t$serialHex\tunknown\t/O=" . \config\ConfAssistant::CONSORTIUM['name'] . "/OU=$federation/CN=$cert->username\n";
137
+        $indexStatement = "$certstatus\t$expiryIndexTxt\t".($certstatus == "R" ? "$nowIndexTxt,unspecified" : "")."\t$serialHex\tunknown\t/O=".\config\ConfAssistant::CONSORTIUM['name']."/OU=$federation/CN=$cert->username\n";
138 138
         $this->loggerInstance->debug(4, "index.txt contents-to-be: $indexStatement");
139
-        if (!file_put_contents($tempdir . "/index.txt", $indexStatement)) {
139
+        if (!file_put_contents($tempdir."/index.txt", $indexStatement)) {
140 140
             $this->loggerInstance->debug(1, "Unable to write openssl index.txt file for revocation handling!");
141 141
         }
142 142
         // index.txt.attr is dull but needs to exist
143
-        file_put_contents($tempdir . "/index.txt.attr", "unique_subject = yes\n");
143
+        file_put_contents($tempdir."/index.txt.attr", "unique_subject = yes\n");
144 144
         // call "openssl ocsp" to manufacture our own OCSP statement
145 145
         // adding "-rmd sha1" to the following command-line makes the
146 146
         // choice of signature algorithm for the response explicit
147 147
         // but it's only available from openssl-1.1.0 (which we do not
148 148
         // want to require just for that one thing).
149
-        $execCmd = \config\Master::PATHS['openssl'] . " ocsp -issuer " . CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_CA . " -sha1 -ndays 10 -no_nonce -serial 0x$serialHex -CA " . CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_CA . " -rsigner " . CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_CA . " -rkey " . CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_KEY . " -index $tempdir/index.txt -no_cert_verify -respout $tempdir/$serialHex.response.der";
149
+        $execCmd = \config\Master::PATHS['openssl']." ocsp -issuer ".CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_CA." -sha1 -ndays 10 -no_nonce -serial 0x$serialHex -CA ".CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_CA." -rsigner ".CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_CA." -rkey ".CertificationAuthorityEmbeddedRSA::LOCATION_ISSUING_KEY." -index $tempdir/index.txt -no_cert_verify -respout $tempdir/$serialHex.response.der";
150 150
         $this->loggerInstance->debug(2, "Calling openssl ocsp with following cmdline: $execCmd\n");
151 151
         $output = [];
152 152
         $return = 999;
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
         if ($return !== 0) {
155 155
             throw new Exception("Non-zero return value from openssl ocsp!");
156 156
         }
157
-        $ocsp = file_get_contents($tempdir . "/$serialHex.response.der");
157
+        $ocsp = file_get_contents($tempdir."/$serialHex.response.der");
158 158
         // remove the temp dir!
159
-        unlink($tempdir . "/$serialHex.response.der");
160
-        unlink($tempdir . "/index.txt.attr");
161
-        unlink($tempdir . "/index.txt");
159
+        unlink($tempdir."/$serialHex.response.der");
160
+        unlink($tempdir."/index.txt.attr");
161
+        unlink($tempdir."/index.txt");
162 162
         rmdir($tempdir);
163 163
         $this->databaseHandle->exec("UPDATE silverbullet_certificate SET OCSP = ?, OCSP_timestamp = NOW() WHERE serial_number = ?", "si", $ocsp, $cert->serial);
164 164
         return $ocsp;
Please login to merge, or discard this patch.