note 32206 added to function.openssl-pkcs7-encrypt
| From: | php-general at lists dot php dot net | Date: | Tue, 20 May 2003 13:16:00 +0000 |
| Subject: | note 32206 added to function.openssl-pkcs7-encrypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-48663@lists.php.net to get a copy of this message | ||
It is a bit scary to use only RC2/40bit considering that has been already so exposed as vulnerable
to brute-force cracking (see for example www.distributed.net)
Here is an alternate method which allows stronger encryption (128bit.) This works on Solaris 8 but
could be adapted for e.g. Linux by removing the "-rand" parameter and its randomfile name.
-------------snippet-------------------
$execstring= "echo \"" . $yourbodytext . "\" | /usr/local/ssl/bin/openssl
smime -encrypt -rc2-128 -rand /usr/local/apache/yoursecuredir/randomfile -text -to " .
$recipient . " -from someuser@example.com -subject \"" . $subject . "\"
/usr/local/apache/yoursecuredir/usercerts/someuser.pem | /usr/lib/sendmail -t";
exec($execstring,$returndata,$resultcode);
-------------snippet-------------------
It requires the .pem format for the user certificate. Assuming you already got a certificate from a
commercial CA such as www.thawte.com then it is fairly simple to export it from your browser WITHOUT
--REPEAT-- WITHOUT its private key and copy it to the PHP/web server. The export process is
browser-specific but assuming MS Internet Explorer you require the menu selection tools ->
internet options -> content -> certificates -> (highlight your cert in the list) ->
export wizard.
The exported file will probably be in DER-encoded binary
with a name like "whatever.CER" and you need to convert it to Privacy Enhanced message
(PEM) format. Typically you would now transfer the file to the *nix machine and the command for
doing this conversion is, for example:
/usr/local/ssl/bin/openssl x509 -inform DER -outform PEM -in someuser.cer -out someuser.pem
When adapting this code it is of course as always vital to ensure that the values ($recipient etc.)
being passed into the system call are acquired in a clean way that avoids trusting user-supplied
data.
----
Manual Page -- http://www.php.net/manual/en/function.openssl-pkcs7-encrypt.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32206
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32206&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32206&report=yes