signed xml file with digital certificate .p12 in ubuntu

45 Views Asked by At

I´m trying sign xml file with php, with this code:

//se firma el XML con el certificado
shell_exec( 'xmlsec1  --sign --output /home/usuario/pruebas_PHP/signed.xml --pkcs12 /home/usuario/pruebas_PHP/demousuario.p12 --pwd logalty /home/usuario/pruebas_PHP/request_PHP.xml');

//se elimina primera línea del XML que contiene <?xml version="1.0" encoding="utf-8"?\>
shell_exec( 'sed \'1d\' signed.xml > signed_send.xml');
shell_exec( 'rm signed.xml');

//se añade cabeceras SOAP
shell_exec( 'echo \'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body>\' > SOAP.xml ');
shell_exec( 'cat SOAP.xml signed_send.xml > signed_SOAP.xml');
shell_exec( 'rm signed_send.xml');
shell_exec( 'rm SOAP.xml');
shell_exec( 'sed -e \'$a </soapenv:Body> </soapenv:Envelope>\' signed_SOAP.xml > signed_SOAP_send.xml');
shell_exec( 'rm signed_SOAP.xml');

$FECHA=date("YmdHis");
//se obtiene el XML firmado
$INPUTData = file_get_contents("/home/usuario/pruebas_PHP/signed_SOAP_send.xml");
$filenameIN='/home/usuario/pruebas_PHP/PHP-in-'.$FECHA.'-'.getmypid().'.txt';
$filenameOUT='/home/usuario/pruebas_PHP/PHP-out-'.$FECHA.'-'.getmypid().'.txt';
$filenamePOST='/home/usuario/pruebas_PHP/PHP-post-'.$FECHA.'-'.getmypid().'.txt';
$LOG='/home/usuario/pruebas_PHP/PHP.log';

    $handle = fopen($filenameIN, 'w');
    if ($handle )
    {
        $writelog=fwrite($handle, $INPUTData) ;
        fclose($handle);
    }

My problem it´s that I tried in windows to execute xmlsec1 and apache return that this command not found. I has searching but i haven´t got any result.

Now i´m trying in ubuntu, i installed a virtual machine, i installed xmlsec1 and i try to execute this command:

xmlsec1 --sign --output ~/signed.xml --pkcs12 ~/GrupoDeLuxe_Demo_7305.p12 --pwd logalty ~/request_PHP.xml

But my result now it´s:

    func=xmlSecOpenSSLAppPkcs12LoadBIO:file=app.c:line=776:obj=unknown:subj=PKCS12_parse:error=4:crypto library function failed:openssl error: 50856204: digital envelope routines: NULL unsupported
    
func=xmlSecOpenSSLAppKeyLoadBIO:file=app.c:line=358:obj=unknown:subj=xmlSecOpenSSLAppPkcs12LoadBIO:error=1:xmlsec library function failed: 
      func=xmlSecOpenSSLAppKeyLoad:file=app.c:line=217:obj=unknown:subj=xmlSecOpenSSLAppKeyLoadBIO:error=1:xmlsec library function failed:filename=/home/pruebas-123456/GrupoDeLuxe_Demo_7305.p12
    
    Error: xmlSecCryptoAppKeyLoad failed: filename=/home/pruebas-123456/GrupoDeLuxe_Demo_7305.p12
    
    Error: failed to load pkcs12 key from "/home/pruebas-123456/GrupoDeLuxe_Demo_7305.p12".
    
    Error: keys manager creation failed
    
    Unknown command
    Usage: xmlsec <command> [<options>] [<files>]    
    xmlsec is a command line tool for signing, verifying, encrypting and
    
    decrypting XML documents. The allowed <command> values are:
    
      --help        display this help information and exit
    
      --help-all    display help information for all commands/options and exit
    
      --help-<cmd>  display help information for command <cmd> and exit
    
      --version     print version information and exit
    
      --keys        keys XML file manipulation
    
      --sign        sign data and output XML document
    
      --verify      verify signed document
    
      --sign-tmpl   create and sign dynamicaly generated signature template
    
      --encrypt     encrypt data and output XML document
    
      --decrypt     decrypt data from XML document
    
    
    
    
    
    Report bugs to http://www.aleksey.com/xmlsec/bugs.html
    
    
    
    Written by Aleksey Sanin <[email protected]>.
    
    
    
    Copyright (C) 2002-2016 Aleksey Sanin <[email protected]>. All Rights Reserved..
    
    This is free software: see the source for copying information.

I don´t know very well what it´s my problem, i know that say that not found my digital certificate, but i have ok my path.

enter image description here enter image description here enter image description here enter image description here

0

There are 0 best solutions below