|
@@ -16,10 +16,10 @@ discard block |
|
|
block discarded – undo |
|
16
|
16
|
class CertificationAuthorityEmbeddedECDSA extends EntityWithDBProperties implements CertificationAuthorityInterface |
|
17
|
17
|
{ |
|
18
|
18
|
|
|
19
|
|
- private const LOCATION_ROOT_CA = ROOT . "/config/SilverbulletClientCerts/rootca-ECDSA.pem"; |
|
20
|
|
- private const LOCATION_ISSUING_CA = ROOT . "/config/SilverbulletClientCerts/real-ECDSA.pem"; |
|
21
|
|
- private const LOCATION_ISSUING_KEY = ROOT . "/config/SilverbulletClientCerts/real-ECDSA.key"; |
|
22
|
|
- private const LOCATION_CONFIG = ROOT . "/config/SilverbulletClientCerts/openssl-ECDSA.cnf"; |
|
|
19
|
+ private const LOCATION_ROOT_CA = ROOT."/config/SilverbulletClientCerts/rootca-ECDSA.pem"; |
|
|
20
|
+ private const LOCATION_ISSUING_CA = ROOT."/config/SilverbulletClientCerts/real-ECDSA.pem"; |
|
|
21
|
+ private const LOCATION_ISSUING_KEY = ROOT."/config/SilverbulletClientCerts/real-ECDSA.key"; |
|
|
22
|
+ private const LOCATION_CONFIG = ROOT."/config/SilverbulletClientCerts/openssl-ECDSA.cnf"; |
|
23
|
23
|
|
|
24
|
24
|
/** |
|
25
|
25
|
* string with the PEM variant of the root CA |
|
@@ -66,27 +66,27 @@ discard block |
|
|
block discarded – undo |
|
66
|
66
|
parent::__construct(); |
|
67
|
67
|
$this->rootPem = file_get_contents(CertificationAuthorityEmbeddedECDSA::LOCATION_ROOT_CA); |
|
68
|
68
|
if ($this->rootPem === FALSE) { |
|
69
|
|
- throw new Exception("Root CA PEM file not found: " . CertificationAuthorityEmbeddedECDSA::LOCATION_ROOT_CA); |
|
|
69
|
+ throw new Exception("Root CA PEM file not found: ".CertificationAuthorityEmbeddedECDSA::LOCATION_ROOT_CA); |
|
70
|
70
|
} |
|
71
|
71
|
$this->issuingCertRaw = file_get_contents(CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA); |
|
72
|
72
|
if ($this->issuingCertRaw === FALSE) { |
|
73
|
|
- throw new Exception("Issuing CA PEM file not found: " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA); |
|
|
73
|
+ throw new Exception("Issuing CA PEM file not found: ".CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_CA); |
|
74
|
74
|
} |
|
75
|
75
|
$rootParsed = openssl_x509_read($this->rootPem); |
|
76
|
76
|
$this->issuingCert = openssl_x509_read($this->issuingCertRaw); |
|
77
|
|
- if ($this->issuingCert === FALSE || is_resource($this->issuingCert)|| $rootParsed === FALSE) { |
|
|
77
|
+ if ($this->issuingCert === FALSE || is_resource($this->issuingCert) || $rootParsed === FALSE) { |
|
78
|
78
|
throw new Exception("At least one CA PEM file did not parse correctly (or not a PHP8 resource)!"); |
|
79
|
79
|
} |
|
80
|
80
|
if (stat(CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY) === FALSE) { |
|
81
|
|
- throw new Exception("Private key not found: " . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY); |
|
|
81
|
+ throw new Exception("Private key not found: ".CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY); |
|
82
|
82
|
} |
|
83
|
|
- $issuingKeyTemp = openssl_pkey_get_private("file://" . CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY); |
|
|
83
|
+ $issuingKeyTemp = openssl_pkey_get_private("file://".CertificationAuthorityEmbeddedECDSA::LOCATION_ISSUING_KEY); |
|
84
|
84
|
if ($issuingKeyTemp === FALSE || is_resource($issuingKeyTemp)) { |
|
85
|
85
|
throw new Exception("The private key did not parse correctly (or not a PHP8 resource)!"); |
|
86
|
86
|
} |
|
87
|
87
|
$this->issuingKey = $issuingKeyTemp; |
|
88
|
88
|
if (stat(CertificationAuthorityEmbeddedECDSA::LOCATION_CONFIG) === FALSE) { |
|
89
|
|
- throw new Exception("openssl configuration not found: " . CertificationAuthorityEmbeddedECDSA::LOCATION_CONFIG); |
|
|
89
|
+ throw new Exception("openssl configuration not found: ".CertificationAuthorityEmbeddedECDSA::LOCATION_CONFIG); |
|
90
|
90
|
} |
|
91
|
91
|
$this->conffile = CertificationAuthorityEmbeddedECDSA::LOCATION_CONFIG; |
|
92
|
92
|
} |
|
@@ -129,27 +129,27 @@ discard block |
|
|
block discarded – undo |
|
129
|
129
|
// generate stub index.txt file |
|
130
|
130
|
$tempdirArray = \core\common\Entity::createTemporaryDirectory("test"); |
|
131
|
131
|
$tempdir = $tempdirArray['dir']; |
|
132
|
|
- $nowIndexTxt = (new \DateTime())->format("ymdHis") . "Z"; |
|
133
|
|
- $expiryIndexTxt = $originalExpiry->format("ymdHis") . "Z"; |
|
|
132
|
+ $nowIndexTxt = (new \DateTime())->format("ymdHis")."Z"; |
|
|
133
|
+ $expiryIndexTxt = $originalExpiry->format("ymdHis")."Z"; |
|
134
|
134
|
// serials for our CA are always integers |
|
135
|
135
|
$serialHex = strtoupper(dechex((int) $cert->serial)); |
|
136
|
136
|
if (strlen($serialHex) % 2 == 1) { |
|
137
|
|
- $serialHex = "0" . $serialHex; |
|
|
137
|
+ $serialHex = "0".$serialHex; |
|
138
|
138
|
} |
|
139
|
139
|
|
|
140
|
|
- $indexStatement = "$certstatus\t$expiryIndexTxt\t" . ($certstatus == "R" ? "$nowIndexTxt,unspecified" : "") . "\t$serialHex\tunknown\t/O=" . \config\ConfAssistant::CONSORTIUM['name'] . "/OU=$federation/CN=$cert->username\n"; |
|
|
140
|
+ $indexStatement = "$certstatus\t$expiryIndexTxt\t".($certstatus == "R" ? "$nowIndexTxt,unspecified" : "")."\t$serialHex\tunknown\t/O=".\config\ConfAssistant::CONSORTIUM['name']."/OU=$federation/CN=$cert->username\n"; |
|
141
|
141
|
$this->loggerInstance->debug(4, "index.txt contents-to-be: $indexStatement"); |
|
142
|
|
- if (!file_put_contents($tempdir . "/index.txt", $indexStatement)) { |
|
|
142
|
+ if (!file_put_contents($tempdir."/index.txt", $indexStatement)) { |
|
143
|
143
|
$this->loggerInstance->debug(1, "Unable to write openssl index.txt file for revocation handling!"); |
|
144
|
144
|
} |
|
145
|
145
|
// index.txt.attr is dull but needs to exist |
|
146
|
|
- file_put_contents($tempdir . "/index.txt.attr", "unique_subject = yes\n"); |
|
|
146
|
+ file_put_contents($tempdir."/index.txt.attr", "unique_subject = yes\n"); |
|
147
|
147
|
// call "openssl ocsp" to manufacture our own OCSP statement |
|
148
|
148
|
// adding "-rmd sha1" to the following command-line makes the |
|
149
|
149
|
// choice of signature algorithm for the response explicit |
|
150
|
150
|
// but it's only available from openssl-1.1.0 (which we do not |
|
151
|
151
|
// want to require just for that one thing). |
|
152
|
|
- $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"; |
|
|
152
|
+ $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"; |
|
153
|
153
|
$this->loggerInstance->debug(2, "Calling openssl ocsp with following cmdline: $execCmd\n"); |
|
154
|
154
|
$output = []; |
|
155
|
155
|
$return = 999; |
|
@@ -157,11 +157,11 @@ discard block |
|
|
block discarded – undo |
|
157
|
157
|
if ($return !== 0) { |
|
158
|
158
|
throw new Exception("Non-zero return value from openssl ocsp!"); |
|
159
|
159
|
} |
|
160
|
|
- $ocsp = file_get_contents($tempdir . "/$serialHex.response.der"); |
|
|
160
|
+ $ocsp = file_get_contents($tempdir."/$serialHex.response.der"); |
|
161
|
161
|
// remove the temp dir! |
|
162
|
|
- unlink($tempdir . "/$serialHex.response.der"); |
|
163
|
|
- unlink($tempdir . "/index.txt.attr"); |
|
164
|
|
- unlink($tempdir . "/index.txt"); |
|
|
162
|
+ unlink($tempdir."/$serialHex.response.der"); |
|
|
163
|
+ unlink($tempdir."/index.txt.attr"); |
|
|
164
|
+ unlink($tempdir."/index.txt"); |
|
165
|
165
|
rmdir($tempdir); |
|
166
|
166
|
$this->databaseHandle->exec("UPDATE silverbullet_certificate SET OCSP = ?, OCSP_timestamp = NOW() WHERE serial_number = ?", "si", $ocsp, $cert->serial); |
|
167
|
167
|
return $ocsp; |