Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encrypt each soap request in php

I'm unable to make an encrypted SOAP request in PHP. As per the documentation, I encrypted each request to the payment gateway. I generated a CSR & sent it to the authority for the certificate. They sent back me the domain certificate & CA certificate. The biggest problem is that the documentation is not meant for PHP. As per the document:

The web service is protected with WS-Security Sign and encryption policy

After searching a long time I found a helper class from Git but whenever I try to connect I get the following error:

General security error (No certificates were found for decryption (KeyId))

FaultCode : wsse:InvalidSecurity

I tried to set SSL header as follows:

$contextOptions = array(
    'ssl' => array(
        'verify_peer'   => false,
        'verify_peer_name'  => false,
        'cafile'        => '../../certs/CA.cer',
        'local_cert'        => '../../certs/server.cer',
        'local_pk'        => '../../certs/private_key.key',
        'verify_depth'  => 0,
        'allow_self_signed'=>true,
    )
);

$sslContext = stream_context_create($contextOptions);

Update

I defined the keys as :

define('PRIVATE_KEY', 'server_prvate_key.key');
define('CERT_FILE', 'domain_cert.cer');
define('SERVICE_CERT', 'CA.cer');

Anything wrong with this definition (please see the above GIT link)?

like image 988
Shan Avatar asked May 03 '17 11:05

Shan


1 Answers

Are you tried using curl?

Use the following option to set your certificate:

    curl_setopt($ch,CURLOPT_CAINFO, 'CA.cer' );
    curl_setopt($ch,CURLOPT_SSLCERT, 'domain_cert.cer' );
    curl_setopt($ch,CURLOPT_SSLKEY, 'server_prvate_key.key' );
    curl_setopt($ch,CURLOPT_SSLCERTPASSWD, 'certificate_password' ); //if have

I use encrypted connection to payment gateways and other services using curl and works like a charm.

like image 165
rafrsr Avatar answered Oct 20 '22 22:10

rafrsr