views:

100

answers:

2

Hey all, I have this code:

 $fp = fopen($unenc_path, "w");
 fwrite($fp, $msg);
 fclose($fp);

 $easy_access_emails = 'person@##.com';
 $headers =   "From: support@##.com <support@##.com>\n" . 
              "Reply-to: support@##.com\n" . 
              "Subject: " . $subject . "\n";

 $key = implode("", file("../newcert.pem"));

 $ArrayMessageProperties = explode("\n", $headers);

 $unenc_path = '..\\tmp\\'. preg_replace('/[^0-9]/','', microtime()) . rand(0,1000) . "msg.txt";
 $enc_path = '..\\tmp\\'. preg_replace('/[^0-9]/','', microtime()) . rand(0,1000) . "enc.txt";

 if (openssl_pkcs7_encrypt($unenc_path, $enc_path, $key, $ArrayMessageProperties))
 {
    $info = file_get_contents($enc_path);

    foreach ($easy_access_emails as $email)
    {
         mail($email, $subject, $info, $headers);
    }
} else {
    die("Failed Encryption");
}

Which works correctly on my local dev environment (Macbook running LAMP). I moved it to a windows server for testing and now openssl_pkcs7_encrypt fails every time. I assume this is a permissions issue, since the function needs to write to $enc_path; but I've made the directory on the windows server about as open as is possible. (set full control to just about every user / group that might have something to do with it. Anyone know a good method to debug this? It appears the function simply returns false when it fails with no indication as to why.

Upon further investigation it appears the script has write access the directory. It writes to the $unenc_path no problem, just fails on the call to openssl_pkcs7_encrypt.

Another update: I'm using filemon to watch the request some in and i see it opening and writing to the unencrypted file but there's no output for it even trying to write to the encrypted file.

Also added the line that loads the key. I've verified it's loading by echoing it out and it seems to be good.

Another update: Watching filemon again, around the time it should be calling openssq_pkcs7_encrypt I'm seeing an entry that it's looking for the unencrypted message in the windows tmp directory.

w3wp.exe:4172  C:\windows\system32\tmp\04277530010012336..msg.txt    PATH NOT FOUND  Options: Open Access: Read
+1  A: 

Are you loading the key in $key somewhere in your code? I can't see it on the snippet

EndelWar
Thanks for the reply. I've added the line it's being pulled in, and some notes regarding my current progress.
Electronic Zebra
+2  A: 

Turned out Windows / Openssl_pkcs7_encrypt didn't like that relative path, giving a full path after messing with forward and backslashes (/. \) for a bit fixed it.

Electronic Zebra