2

I need to access a SOAP service with a certificate protected by password. I'm new in PHP (with PHP 5.4 in CodeIgniter 2) and have tried some options that doesn't work for me.

I have the following constants:

const WSDL  = 'https://sedeapl.dgt.gob.es:8080/WS_IEST_COMP/descargaArchivoMicrodatosService?wsdl';

const XMLNS = 'https://sedeapl.dgt.gob.es:8080/WS_IEST_COMP/descargaArchivoMicrodatosService';

const LOCAL_CERT_PASSWD = 'HERE I HAVE THE PASS OF THE CERT';
const LOCAL_CERT = './certificados/Certificados.p12';

private $client;

I have tried these options:

Option A

$this->client = new SoapClient(self::WSDL, array(
                "trace"         => 1, 
                "exceptions"    => true, 
                "local_cert"    => self::LOCAL_CERT, 
                "uri"           => "urn:xmethods-delayed-quotes",
                "style"         => SOAP_RPC,
                "use"           => SOAP_ENCODED,
                "soap_version"  => SOAP_1_2 ,
                "location"      => self::XMLNS
            )
        );

Options B

$this->$client = new SoapClient(self::WSDL, array('local_cert' => self::LOCAL_CERT));

I have no idea how to add the password. Those solutions are what I found here on StackOverflow. In both examples I get the same error:

SoapClient::SoapClient(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?

I have uncomented the "extension=php_openssl.dll" in php.ini

I've tried with these routes of cert:

const LOCAL_CERT = 'certificados/Certificados.p12';
const LOCAL_CERT = 'Certificados.p12';
const LOCAL_CERT = './certificados/Certificados.p12';

Does anyone have an idea about what can I do. Thank you very much!

0

1 Answer 1

3

first of all you need to convert .p12 to .pem
in Linux you can do it with following command
openssl pkcs12 -in Certificados.p12 -out Certificados.pem -clcerts

then try the following:

$options = array();

$options['trace'] = true;
$options['exceptions'] = true;
$options['local_cert'] = 'path to your .pem file';
$options['passphrase'] = self::LOCAL_CERT_PASSWD;

try {
    $soapClient = new SoapClient(self::WSDL, $options);

    echo '<pre>';        
    // wsdl methods
    print_r($soapClient->__getFunctions());        
    echo '</pre>';
}
catch (Exception $e)
{
    echo $e->getMessage(), '<br />', $e->getTraceAsString();
}
12
  • now I have Certificados.pem in: Proyect Source Files application certificados Certificados.pem controllers Controller with the code to access the service is correct this path? $options['local_cert'] = './certificados/Certificados.pem'; I stil having errors: Message: SoapClient::SoapClient(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? Message: SoapClient::SoapClient(): I/O warning : failed to load external entity "sedeapl.dgt.gob.es:8080/WS_IEST_COMP/…"
    – CVO
    Commented May 4, 2016 at 8:57
  • @Noark did you restart your web server after enabling php_openssl? also try to file_get_contents(self::WSDL); Commented May 4, 2016 at 9:01
  • Yes I restarted Apache in XAAMP server. With file_get_contents(self::WSDL); I have two errors: Message: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? Message: file_get_contents(sedeapl.dgt.gob.es:8080/WS_IEST_COMP/…): failed to open stream: No such file or directory Could be that the WSDL isn´t working? here there is the offitial doc: sedeapl.dgt.gob.es/IEST_INTER/MICRODATOS/webService/… But in spanish... (It have the wsdl)
    – CVO
    Commented May 4, 2016 at 9:05
  • so, at first you have to solve this issue. openssl is not enabled yet. read this stackoverflow.com/questions/5444249/… maybe it will help you Commented May 4, 2016 at 9:10
  • Thank you very much, I will try that.
    – CVO
    Commented May 4, 2016 at 9:11

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