1--TEST-- 2openssl_cms_sign() and verify with attached signatures 3--SKIPIF-- 4<?php if (!extension_loaded("openssl")) print "skip"; ?> 5--FILE-- 6<?php 7$infile = __DIR__ . "/plain.txt"; 8$outfile = tempnam(sys_get_temp_dir(), "ssl"); 9$vout= $outfile . ".vout"; 10 11if ($outfile === false) { 12 die("failed to get a temporary filename!"); 13} 14 15$privkey = "file://" . __DIR__ . "/private_rsa_1024.key"; 16$single_cert = "file://" . __DIR__ . "/cert.crt"; 17$assoc_headers = array("To" => "test@test", "Subject" => "testing openssl_cms_sign()"); 18$headers = array("test@test", "testing openssl_cms_sign()"); 19$empty_headers = array(); 20$wrong = "wrong"; 21$empty = ""; 22print("S/MIME attached\nPlain text:\n"); 23readfile($infile); 24var_dump(openssl_cms_sign($infile, $outfile, openssl_x509_read($single_cert), $privkey, $headers)); 25var_dump(openssl_cms_verify($outfile,OPENSSL_CMS_NOVERIFY, NULL, array(), NULL, $vout)); 26print("\nValidated content:\n"); 27readfile($vout); 28 29if (file_exists($outfile)) { 30 echo "true\n"; 31 unlink($outfile); 32} 33 34if (file_exists($vout)) { 35 echo "true\n"; 36 unlink($vout); 37} 38print("\nPEM Attached:\n"); 39var_dump(openssl_cms_sign($infile, $outfile, openssl_x509_read($single_cert), $privkey, $headers, 40 OPENSSL_CMS_BINARY,OPENSSL_ENCODING_PEM)); 41var_dump(openssl_cms_verify($outfile,OPENSSL_CMS_NOVERIFY|OPENSSL_CMS_BINARY, 42 NULL, array(), NULL, $vout, NULL, NULL, OPENSSL_ENCODING_PEM)); 43print("\nValidated content:\n"); 44readfile($vout); 45if (file_exists($outfile)) { 46 echo "true\n"; 47 unlink($outfile); 48} 49 50if (file_exists($vout)) { 51 echo "true\n"; 52 unlink($vout); 53} 54 55// DER next 56 57print("\nDER Attached:\n"); 58var_dump(openssl_cms_sign($infile, $outfile, openssl_x509_read($single_cert), $privkey, $headers, 59 OPENSSL_CMS_BINARY,OPENSSL_ENCODING_DER)); 60var_dump(openssl_cms_verify($outfile,OPENSSL_CMS_NOVERIFY|OPENSSL_CMS_BINARY, 61 NULL, array(), NULL, $vout, NULL, NULL, OPENSSL_ENCODING_DER)); 62print("\nValidated content:\n"); 63readfile($vout); 64// extreme measures to avoid stupid temporary errors for failure to unlink a file. 65if (file_exists($outfile)) { 66 echo "true\n"; 67 unlink($outfile); 68} 69if (file_exists($vout)) { 70 echo "true\n"; 71 unlink($vout); 72} 73 74?> 75--EXPECT-- 76S/MIME attached 77Plain text: 78Now is the winter of our discontent. 79bool(true) 80bool(true) 81 82Validated content: 83Now is the winter of our discontent. 84true 85true 86 87PEM Attached: 88bool(true) 89bool(true) 90 91Validated content: 92Now is the winter of our discontent. 93true 94true 95 96DER Attached: 97bool(true) 98bool(true) 99 100Validated content: 101Now is the winter of our discontent. 102true 103true 104