Skip to content

Commit fa10dfc

Browse files
kesselbbukka
authored andcommitted
Add PKCS7_NOOLDMIMETYPE and OPENSSL_CMS_OLDMIMETYPE
PKCS7_NOOLDMIMETYPE to use Content-Type application/pkcs7-mime OPENSSL_CMS_OLDMIMETYPE to use Content-Type application/x-pkcs7-mime SMIME_write_PKCS7 and SMIME_write_CMS are using SMIME_write_ASN1_ex. The Content-Type application/x-pkcs7-mime is generated with the flag SMIME_OLDMIME (0x400).[^1] SMIME_write_PKCS7 set SMIME_OLDMIME by default.[^2] SMIME_write_CMS does not.[^3] I picked OPENSSL_CMS_OLDMIMETYPE over OPENSSL_CMS_NOOLDMIMETYPE because that's what the flag actually does. [^1]: https://github.com/openssl/openssl/blob/9a2f78e14a67eeaadefc77d05f0778fc9684d26c/crypto/asn1/asn_mime.c#L248-L251 [^2]: https://github.com/openssl/openssl/blob/9a2f78e14a67eeaadefc77d05f0778fc9684d26c/crypto/pkcs7/pk7_mime.c#L41-L43 [^3]: https://github.com/openssl/openssl/blob/9a2f78e14a67eeaadefc77d05f0778fc9684d26c/crypto/cms/cms_io.c#L93 Signed-off-by: Daniel Kesselberg <[email protected]>
1 parent f18a038 commit fa10dfc

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ PHP NEWS
115115
. Added memfd api usage, on Linux, for zend_shared_alloc_create_lock()
116116
to create an abstract anonymous file for the opcache's lock. (Max Kellermann)
117117

118+
- OpenSSL:
119+
. Added OPENSSL_CMS_OLDMIMETYPE and PKCS7_NOOLDMIMETYPE contants to switch
120+
between mime content types. (Daniel Kesselberg)
121+
118122
- PCNTL:
119123
. SA_ONSTACK is now set for pcntl_signal. (Kévin Dunglas)
120124
. Added SIGINFO constant. (David Carlier)

UPGRADING

+4
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ PHP 8.3 UPGRADE NOTES
214214
. MIXED_NUMBERS (Spoofchecker).
215215
. HIDDEN_OVERLAY (Spoofchecker).
216216

217+
- OpenSSL:
218+
. OPENSSL_CMS_OLDMIMETYPE
219+
. PKCS7_NOOLDMIMETYPE
220+
217221
- PCNTL:
218222
. SIGINFO
219223

ext/openssl/openssl.stub.php

+10
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@
161161
* @cvalue PKCS7_NOSIGS
162162
*/
163163
const PKCS7_NOSIGS = UNKNOWN;
164+
/**
165+
* @var int
166+
* @cvalue PKCS7_NOOLDMIMETYPE
167+
*/
168+
const PKCS7_NOOLDMIMETYPE = UNKNOWN;
164169

165170
/**
166171
* @var int
@@ -202,6 +207,11 @@
202207
* @cvalue CMS_NOSIGS
203208
*/
204209
const OPENSSL_CMS_NOSIGS = UNKNOWN;
210+
/**
211+
* @var int
212+
* @cvalue CMS_NOOLDMIMETYPE
213+
*/
214+
const OPENSSL_CMS_OLDMIMETYPE = UNKNOWN;
205215

206216
/**
207217
* @var int

ext/openssl/openssl_arginfo.h

+3-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/openssl/tests/openssl_cms_encrypt_basic.phpt

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ $outfile = tempnam(sys_get_temp_dir(), "cms_enc_basic");
99
if ($outfile === false)
1010
die("failed to get a temporary filename!");
1111
$outfile2 = $outfile . ".out";
12+
$outfile3 = tempnam(sys_get_temp_dir(), "cms_enc_basic");
13+
if ($outfile3 === false)
14+
die("failed to get a temporary filename!");
1215
$single_cert = "file://" . __DIR__ . "/cert.crt";
1316
$privkey = "file://" . __DIR__ . "/private_rsa_1024.key";
1417
$wrongkey = "file://" . __DIR__ . "/private_rsa_2048.key";
@@ -33,6 +36,7 @@ var_dump(openssl_cms_encrypt($infile, $outfile, $wrong, $headers, cipher_algo: $
3336
var_dump(openssl_cms_encrypt($infile, $outfile, $empty, $headers, cipher_algo: $cipher));
3437
var_dump(openssl_cms_encrypt($infile, $outfile, $multi_certs, $headers, cipher_algo: $cipher));
3538
var_dump(openssl_cms_encrypt($infile, $outfile, array_map('openssl_x509_read', $multi_certs), $headers, cipher_algo: $cipher));
39+
var_dump(openssl_cms_encrypt($infile, $outfile3, $single_cert, $headers, flags: OPENSSL_CMS_OLDMIMETYPE, cipher_algo: $cipher));
3640

3741
if (file_exists($outfile)) {
3842
echo "true\n";
@@ -42,6 +46,15 @@ if (file_exists($outfile2)) {
4246
echo "true\n";
4347
unlink($outfile2);
4448
}
49+
50+
if (file_exists($outfile3)) {
51+
$content = file_get_contents($outfile3, false, null, 0, 256);
52+
if (str_contains($content, 'Content-Type: application/x-pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"')) {
53+
echo "true\n";
54+
}
55+
unset($content);
56+
unlink($outfile3);
57+
}
4558
?>
4659
--EXPECT--
4760
bool(true)
@@ -57,5 +70,7 @@ bool(false)
5770
bool(false)
5871
bool(true)
5972
bool(true)
73+
bool(true)
74+
true
6075
true
6176
true

ext/openssl/tests/openssl_pkcs7_encrypt_basic.phpt

+15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ if ($outfile === false)
1111
$outfile2 = tempnam(sys_get_temp_dir(), "ssl");
1212
if ($outfile2 === false)
1313
die("failed to get a temporary filename!");
14+
$outfile3 = tempnam(sys_get_temp_dir(), "ssl");
15+
if ($outfile3 === false)
16+
die("failed to get a temporary filename!");
1417

1518
$single_cert = "file://" . __DIR__ . "/cert.crt";
1619
$privkey = "file://" . __DIR__ . "/private_rsa_1024.key";
@@ -34,6 +37,7 @@ var_dump(openssl_pkcs7_encrypt($infile, $outfile, $wrong, $headers, 0, $cipher))
3437
var_dump(openssl_pkcs7_encrypt($infile, $outfile, $empty, $headers, 0, $cipher));
3538
var_dump(openssl_pkcs7_encrypt($infile, $outfile, $multi_certs, $headers, 0, $cipher));
3639
var_dump(openssl_pkcs7_encrypt($infile, $outfile, array_map('openssl_x509_read', $multi_certs), $headers, 0, $cipher));
40+
var_dump(openssl_pkcs7_encrypt($infile, $outfile3, $single_cert, $headers, PKCS7_NOOLDMIMETYPE, $cipher));
3741

3842
if (file_exists($outfile)) {
3943
echo "true\n";
@@ -43,6 +47,15 @@ if (file_exists($outfile2)) {
4347
echo "true\n";
4448
unlink($outfile2);
4549
}
50+
51+
if (file_exists($outfile3)) {
52+
$content = file_get_contents($outfile3, false, null, 0, 256);
53+
if (str_contains($content, 'Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"')) {
54+
echo "true\n";
55+
}
56+
unset($content);
57+
unlink($outfile3);
58+
}
4659
?>
4760
--EXPECT--
4861
bool(true)
@@ -57,5 +70,7 @@ bool(false)
5770
bool(false)
5871
bool(true)
5972
bool(true)
73+
bool(true)
74+
true
6075
true
6176
true

0 commit comments

Comments
 (0)