note 53798 added to function.openssl-pkcs7-verify

From: Date: Mon, 13 Jun 2005 19:09:41 +0000
Subject: note 53798 added to function.openssl-pkcs7-verify
Groups: php.notes 
Request: Send a blank email to php-notes+get-90371@lists.php.net to get a copy of this message
Sorry, my note above is incorrect -- I was fooled by the -1 return value for error not being false.... take care not to test if(!openssl_pkcs7_verify(... since this will not catch the "error" condition and accept the untested signature!!! openssl_pkcs7_verify() just uses normal filepaths throughout. It's openssl_pkcs7_sign() that uses the file:/// method. Here are a couple of working examples to clarify this confusion. Signing... if ( openssl_pkcs7_sign( $filepathHeader, $filepathHeaderSigned, "file:///path/to/your/cert/signed/by/your/CA.pem", // signing cert array("file:///path/to/your/private/key",""), // private key array() ) ) { echo "okay - in ".$filepathHeaderSigned."\n"; } else { while ($msg = openssl_error_string()) echo $msg . "<br />\n"; } Verifying.... $ret=openssl_pkcs7_verify ( $filepathSignedFile, PKCS7_DETACHED $output, // set to filepath that is to contain signing certs after successful run array( "/path/to/your/CA/public/certificate.pem" ) ); if($ret !== TRUE) { echo "no\n"; while ($msg = openssl_error_string()) echo $msg . "<br />\n"; } ---- Manual Page -- http://www.php.net/manual/en/function.openssl-pkcs7-verify.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53798 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53798&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53798&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53798&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53798&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53798&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53798&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90371) next »