Skip to content

Commit 2b4a47c

Browse files
ramseybukka
andcommitted
Merge changes to CertificateGenerator.inc from PHP-8.2
This pulls only the changes made to CertificateGenerator.inc in the PHP-8.2 branch from commit 505e8d2. Co-authored-by: Jakub Zelenka <bukka@php.net>
1 parent 243fa9c commit 2b4a47c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

ext/openssl/tests/CertificateGenerator.inc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ class CertificateGenerator
8585
openssl_x509_export_to_file($this->ca, $file);
8686
}
8787

88-
public function saveNewCertAsFileWithKey(
89-
$commonNameForCert, $file, $keyLength = null, $subjectAltName = null
88+
public function saveNewCertAndKey(
89+
$commonNameForCert, $certFile, $keyFile, $keyLength = null, $subjectAltName = null
9090
) {
9191
$dn = [
9292
'countryName' => 'BY',
@@ -117,7 +117,7 @@ $subjectAltNameConfig
117117
basicConstraints = CA:FALSE
118118
$subjectAltNameConfig
119119
CONFIG;
120-
$configFile = $file . '.cnf';
120+
$configFile = $certFile . '.cnf';
121121
file_put_contents($configFile, $configCode);
122122

123123
try {
@@ -146,12 +146,24 @@ CONFIG;
146146
$keyText = '';
147147
openssl_pkey_export($this->lastKey, $keyText, null, $config);
148148

149-
file_put_contents($file, $certText . PHP_EOL . $keyText);
149+
if ($certFile === $keyFile) {
150+
file_put_contents($certFile, $certText . PHP_EOL . $keyText);
151+
} else {
152+
file_put_contents($certFile, $certText);
153+
file_put_contents($keyFile, $keyText);
154+
}
150155
} finally {
151156
unlink($configFile);
152157
}
153158
}
154159

160+
161+
public function saveNewCertAsFileWithKey(
162+
$commonNameForCert, $file, $keyLength = null, $subjectAltName = null
163+
) {
164+
$this->saveNewCertAndKey($commonNameForCert, $file, $file, $keyLength, $subjectAltName);
165+
}
166+
155167
public function getCertDigest($algo)
156168
{
157169
return openssl_x509_fingerprint($this->lastCert, $algo);

0 commit comments

Comments
 (0)