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!

Rahul Mahadik
  • 11,668
  • 6
  • 41
  • 54
CVO
  • 702
  • 1
  • 13
  • 31

1 Answers1

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();
}
Denis Alimov
  • 2,861
  • 1
  • 18
  • 38
  • 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 "https://sedeapl.dgt.gob.es:8080/WS_IEST_COMP/descargaArchivoMicrodatosService?wsdl" – CVO May 04 '16 at 08:57
  • @Noark did you restart your web server after enabling php_openssl? also try to file_get_contents(self::WSDL); – Denis Alimov May 04 '16 at 09: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(https://sedeapl.dgt.gob.es:8080/WS_IEST_COMP/descargaArchivoMicrodatosService?wsdl): failed to open stream: No such file or directory Could be that the WSDL isn´t working? here there is the offitial doc: https://sedeapl.dgt.gob.es/IEST_INTER/MICRODATOS/webService/IEST_descargaFicheroMicrodatos.pdf But in spanish... (It have the wsdl) – CVO May 04 '16 at 09:05
  • so, at first you have to solve this issue. openssl is not enabled yet. read this http://stackoverflow.com/questions/5444249/unable-to-find-the-wrapper-https-did-you-forget-to-enable-it-when-you-config?rq=1 maybe it will help you – Denis Alimov May 04 '16 at 09:10
  • Thank you very much, I will try that. – CVO May 04 '16 at 09:11
  • It seems like my apache does not load the extension openssl, but I don't know why. I have in php.ini this two lines: extension=php_openssl.dll allow_url_include = On and in httpd.conf this one: LoadModule ssl_module modules/mod_ssl.so And when I ask for extension_loaded with openssl It does not load. – CVO May 04 '16 at 10:22
  • @Noark what OS? do you use XAMPP or WAMP or something? – Denis Alimov May 04 '16 at 10:25
  • I use XAMPP server and win 7 (with codeigniter 2, php 5.4 and .Net Beans 8.1) – CVO May 04 '16 at 10:28
  • @Noark so, when you restart apache is everything fine? do you have php_openssl.dll in \xampp\php\ext directory? what phpinfo says about loaded php.ini? – Denis Alimov May 04 '16 at 10:41
  • yes I have the .dll in that path. I restart XAMPP without problems: 12:43:14 [Apache] Status change detected: stopped 12:43:21 [Apache] Attempting to start Apache app... 12:43:22 [Apache] Status change detected: running In php.info (I didn't know that it exists) I have in section Loaded Modules many modules and this one mod_ssl I have related to ssl this; Apache Version Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.8 SSL Version OpenSSL/1.0.2d and more stuff with ssl. But I have this one disabled: OpenSSL support disabled (install ext/openssl) Can be formated this comments? – CVO May 04 '16 at 10:52
  • @Noark loaded php.ini file I meant look for string Loaded Configuration File – Denis Alimov May 04 '16 at 10:54
  • I tried to conect it to ISS and it works with your code. There might be any kind of problem with Xampp and ssl, but in production I have ISS so no problem. The solution you give me for conect the certificate with password works perfect on ISS. Thanks you very much. – CVO May 04 '16 at 12:27