Hello

I am new to this newsgroup, additionally new to openssl.

I would like to encrypt messages sent from server to client, after
reading through various documents on the Internet I have figured out a
process that _appears_ to work.

I would appreciate if someone could verify that it is indeed correct and
secure, at least in theory ;-)

The server is linux or freebsd based and the client will be MS Windows
based.

1) Create a "ca" certificate
        openssl genrsa -des3 -out ca.key 1024
        openssl req -new -x509 -days 365 -key ca.key -out ca.crt

2) Create new certficate request for client using CA.sh
        sh CA.sh -newreq (CN is Full Name)

3) Sign the certificate using "sign.sh" from modssl distribution and
extract key into separate file.
        sh sign.sh newreq.pem
        openssl rsa < newreq.pem > newkey.pem

4) Export to pkcs12 format
        openssl pkcs12 -export -in newreq.pem.crt -inkey newkey.pem -out
client.p12

5) Export ca to pkcs12 format
        openssl pkcs12 -export -in ca.crt -inkey ca.key -out ca.p12

6) Import client.p12 into Internet Explorer at Tools/Internet
Options/Content/Certificates on "Personal" tab and import ca.p12 on
"Trusted Root Certification Authorities" tab.

7) Copy certificate from bottom of newreq.pem.crt into new file
"client.pem". Not sure if this is correct, or if there is a better way
to extract than copy/paste - but pkcs7 routine wouldn't work until I
separated the certificate.

8) Use a php script that uses the openssl pkcs7 routine to encrypt and
email a message.

        <?php

        $data = <<<EOD

        Testing 123
        This is a test
        TEST

        EOD;

        $key = implode("",file("client.pem"));
        $fp = fopen("msg.txt","w");
        fwrite($fp,$data);
        fclose($fp);
        if (openssl_pkcs7_encrypt("msg.txt", "enc.txt", $key,
                array("To" => "Waitman Gobble <[EMAIL PROTECTED]>",
                        "From" => "Waitman Gobble <[EMAIL PROTECTED]>",
                        "Subject" => "Shake Ya Booty")))
        {
                exec(ini_get("sendmail_path")." < enc.txt");
        }
        ?>

This process appears to work, I am curious if it is actually correct! 

One question I have, after the certs expire in one year, will previously
received messages that are encrypted STILL be able to be decrypted? I am
not sure how to handle the situation of expiring certificates.

The other question I have is regarding an article written by Don Davis
entitled "Defective Sign & Encrypt in S/MIME, PKCS#7, Moss, PEM, PGP and
XML" available at

http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.ps

Mr. Davis states that simple asymmetric encryption ~ sign and encrypt is
insecure practice because the recipient cannot be sure who encrypted
(and essentially "wrote") the message, even if it is signed.

He suggests that an alternative method of sign/encrypt/sign again is
more secure because the recipient can then truly verify the authenticity
of the message.

I am curious to know if the sign/encrypt/sign is preferred, or in use -
I haven't seen documentation supporting this elsewhere. Additionally, I
am not sure what Outlook Express would make of the message.

I realize that I haven't even signed my message in the example above,
that is the next thing for me to work out.

Thanks for your help, I appreciate it!


-- 
Waitman Gobble         EMK Design     Buena Park, California
http://emkdesign.com   +1.7145222528   [EMAIL PROTECTED]
Public Key                          http://pgp.emkdesign.com

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to