Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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";
    }
};
?> 
share|improve this question
    
Are you trying to include a script? Not sure what it is you're trying to do. –  gravyface Jul 13 '10 at 18:31
    
I am trying to call my openssl directory within PHP –  JM4 Jul 13 '10 at 19:10
    
Is PHP in safe mode? –  user47994 Jul 13 '10 at 19:20
    
@industro - no it is not –  JM4 Jul 13 '10 at 19:22

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
can you show the fixed code? I am not sure exactly how to fix mine... –  user99927 Nov 4 '11 at 6:16
    
@RRR not sure I follow entirely but I've update the code somewhat to give you a better idea. –  JM4 Dec 7 '11 at 21:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.