I have a PHP script which needs to point to my server openssl directory but am lost. I know the directory resides at /usr/bin/openssl while my site pages rest at /var/www/vhosts/domain/httpdocs/test.php.
Within test.php, I try to call the openssl directory using relative paths at /usr/bin/openssl but I know this is causing an issue. Can anybody help?
PHP script which is trying to call openssl for certificate encryption:
<?php
//earlier in the file $operatingos was set to true or false based on the OS.
if(!$operatingos) {
#PRIVATE KEY FILE
$MY_KEY_FILE = "my-prvkey.pem";
#PUBLIC KEY FILE
$MY_CERT_FILE = "my-pubcert.pem";
#PAYPAL PUBLIC CERTIFICATE
if(!$testingservices) {
$PAYPAL_CERT_FILE = "paypal_cert.pem"; //LIVE
} else {
$PAYPAL_CERT_FILE = "paypal_cert_sandbox.pem"; //SANDBOX
}
#PATH TO OPENSSL BINARY
$OPENSSL = "/usr/bin/openssl";
} else {
#PRIVATE KEY FILE
$MY_KEY_FILE = "C:\\xampp\\htdocs\\privkey.pem";
#PUBLIC KEY FILE
$MY_CERT_FILE = "C:\\xampp\\htdocs\\pubcert.pempem";
#PAYPAL PUBLIC CERTIFICATE
if(!$testingservices) {
$PAYPAL_CERT_FILE = "C:\\xampp\\htdocs\\pppubcert.pem";
} else {
$PAYPAL_CERT_FILE = "C:\\xampp\\htdocs\\pppubcert_sandbox.pem";
}
#PATH TO OPENSSL BINARY
$OPENSSL = "C:\\OpenSSL-Win32\\bin\\openssl.exe";
}
$form = array('cmd' => '_xclick',
'business' => 'email',
'cert_id' => 'certid',
'lc' => 'US',
'custom' => 'test',
'invoice' => '',
'currency_code' => 'USD',
'no_shipping' => '1',
'item_name' => 'Donation',
'item_number' => '1',
'amount' => '10'
);
$encrypted = paypal_encrypt($form);
function paypal_encrypt($hash)
{
global $MY_KEY_FILE;
global $MY_CERT_FILE;
global $PAYPAL_CERT_FILE;
global $OPENSSL;
if (!file_exists($MY_KEY_FILE)) {
echo "ERROR: MY_KEY_FILE $MY_KEY_FILE not found\n";
}
if (!file_exists($MY_CERT_FILE)) {
echo "ERROR: MY_CERT_FILE $MY_CERT_FILE not found\n";
}
if (!file_exists($PAYPAL_CERT_FILE)) {
echo "ERROR: PAYPAL_CERT_FILE $PAYPAL_CERT_FILE not found\n";
}
//Assign Build Notation for PayPal Support
$hash['bn']= 'domain.PHP_EWP2';
$data = "";
foreach ($hash as $key => $value) {
if ($value != "") {
//echo "Adding to blob: $key=$value\n";
$data .= "$key=$value\n";
}
}
$openssl_cmd = "($OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " .
"-outform der -nodetach -binary <<_EOF_\n$data\n_EOF_\n) | " .
"$OPENSSL smime -encrypt -des3 -binary -outform pem $PAYPAL_CERT_FILE";
exec($openssl_cmd, $output, $error);
if (!$error) {
return implode("\n",$output);
} else {
return "ERROR: encryption failed";
}
};
?>
The issue laid in the way the directory structures differ between a Windows and Linux system. Quite dumb on my part but the double slashes in a windows directory were required