1--TEST-- 2openssl_cms_encrypt() tests 3--EXTENSIONS-- 4openssl 5--FILE-- 6<?php 7$infile = __DIR__ . "/plain.txt"; 8$outfile = tempnam(sys_get_temp_dir(), "cms_enc_basic"); 9if ($outfile === false) 10 die("failed to get a temporary filename!"); 11$outfile2 = $outfile . ".out"; 12$outfile3 = tempnam(sys_get_temp_dir(), "cms_enc_basic"); 13if ($outfile3 === false) 14 die("failed to get a temporary filename!"); 15$single_cert = "file://" . __DIR__ . "/cert.crt"; 16$privkey = "file://" . __DIR__ . "/private_rsa_1024.key"; 17$wrongkey = "file://" . __DIR__ . "/private_rsa_2048.key"; 18$multi_certs = array($single_cert, $single_cert); 19$assoc_headers = array("To" => "test@test", "Subject" => "testing openssl_cms_encrypt()"); 20$headers = array("test@test", "testing openssl_cms_encrypt()"); 21$empty_headers = array(); 22$wrong = "wrong"; 23$empty = ""; 24$cipher = OPENSSL_CIPHER_AES_128_CBC; 25 26var_dump(openssl_cms_encrypt($infile, $outfile, $single_cert, $headers, cipher_algo: $cipher)); 27var_dump(openssl_cms_encrypt($infile, $outfile, openssl_x509_read($single_cert), $headers, cipher_algo: $cipher)); 28var_dump(openssl_cms_decrypt($outfile, $outfile2, $single_cert, $privkey)); 29readfile($outfile2); 30var_dump(openssl_cms_encrypt($infile, $outfile, $single_cert, $assoc_headers, cipher_algo: $cipher)); 31var_dump(openssl_cms_encrypt($infile, $outfile, $single_cert, $empty_headers, cipher_algo: $cipher)); 32var_dump(openssl_cms_encrypt($wrong, $outfile, $single_cert, $headers, cipher_algo: $cipher)); 33var_dump(openssl_cms_encrypt($empty, $outfile, $single_cert, $headers, cipher_algo: $cipher)); 34var_dump(openssl_cms_encrypt($infile, $empty, $single_cert, $headers, cipher_algo: $cipher)); 35var_dump(openssl_cms_encrypt($infile, $outfile, $wrong, $headers, cipher_algo: $cipher)); 36var_dump(openssl_cms_encrypt($infile, $outfile, $empty, $headers, cipher_algo: $cipher)); 37var_dump(openssl_cms_encrypt($infile, $outfile, $multi_certs, $headers, cipher_algo: $cipher)); 38var_dump(openssl_cms_encrypt($infile, $outfile, array_map('openssl_x509_read', $multi_certs), $headers, cipher_algo: $cipher)); 39var_dump(openssl_cms_encrypt($infile, $outfile3, $single_cert, $headers, flags: OPENSSL_CMS_OLDMIMETYPE, cipher_algo: $cipher)); 40 41if (file_exists($outfile)) { 42 echo "true\n"; 43 unlink($outfile); 44} 45if (file_exists($outfile2)) { 46 echo "true\n"; 47 unlink($outfile2); 48} 49 50if (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} 58?> 59--EXPECT-- 60bool(true) 61bool(true) 62bool(true) 63Now is the winter of our discontent. 64bool(true) 65bool(true) 66bool(false) 67bool(false) 68bool(false) 69bool(false) 70bool(false) 71bool(true) 72bool(true) 73bool(true) 74true 75true 76true 77