I can't sign XML with XMLSECLIBS.PHP The connections are successful by NuSoap are valid. But the XML to be missing a few nodes.
require_once('lib/nusoap/nusoap.php');
require_once('lib/xml_signature/xmlseclibs.php');
$client = new nusoap_client('http://ift.tt/1C7EYR3', false);
$response = $client->call( 'getSeed' );
$xml = simplexml_load_string($response);
$xml->registerXPathNamespace('SII', 'http://ift.tt/1sS9H3o');
$events = $xml->xpath('//SII:RESP_BODY' );
$semilla = $events[0]->SEMILLA;
$xml_semilla = "<getToken>\n\t<item>\n\t\t<semilla>$semilla</semilla>\n\t</item>\n</getToken>";
$doc =new DOMDocument();
$doc->formatOutput = FALSE;
$doc->preserveWhiteSpace = TRUE;
$doc->loadXML($xml_semilla);
$objDSig = new XMLSecurityDSig(FALSE);
$objDSig->setCanonicalMethod(XMLSecurityDSig::C14N);
$options['force_uri'] = TRUE;
$options['id_name'] = 'ID';
$options['overwrite'] = FALSE;
$objDSig->addReference($doc, XMLSecurityDSig::SHA1, array('http://ift.tt/A1C4L2'), $options);
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'private'));
$pfx = file_get_contents(dirname(__FILE__) . "/Enrique.pfx");
$key = array();
openssl_pkcs12_read($pfx, $key, "123456");
$objKey->loadKey($key["pkey"]);
$objDSig->add509Cert($key["cert"],TRUE,FALSE);
$objDSig->sign($objKey, $doc->documentElement);
$doc->save(dirname(__FILE__) . '\archivo_semilla_firmada.xml');
//====================================================================
// SE GENERA TOKEN
//====================================================================
$fsemilla = fopen( 'archivo_semilla_firmada.xml', "r+" );
$fsemilla_firmada = fread( $fsemilla, filesize('archivo_semilla_firmada.xml') );
$client2 = new nusoap_client('http://ift.tt/1zdar78', false);
$respuesta_sii_con_token = $client2->call( 'getToken', array('pszXml' => $fsemilla_firmada) );
echo "<pre>";
print_r($respuesta_sii_con_token);
echo "<pre>";
file_put_contents( 'token.xml', $respuesta_sii_con_token );
And the result is: archivo_semilla_firmada.xml
<?xml version="1.0"?>
<getToken>
<item>
<semilla>001831334930</semilla>
</item>
<ds:Signature xmlns:ds="http://ift.tt/uq6naF">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://ift.tt/y9fQ1c"/>
<ds:SignatureMethod Algorithm="http://ift.tt/zf1Wx4"/>
<ds:Reference URI="">
<ds:Transforms>
<ds:Transform Algorithm="http://ift.tt/A1C4L2"/></ds:Transforms>
<ds:DigestMethod Algorithm="http://ift.tt/yuvO4a"/>
<ds:DigestValue>YGvfqRekWVdBI4emxxOK0LMXNBI=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>QRmnYjrHHDqIXjtuOS+eqQ7z0vhOdrVQeq9hPKFlggvTKuKYaDT2juBY4SmrtW8/nTblKIYUAyC6lfb1/m2W7X4QL94R2FVq5k48Oa61Lfb7tF77BUakfQsR6VbzraKmrSkzvJ0rJdP9kvDz8QpqMvyLVU6BkNYQzKaIIcuGgEM=</ds:SignatureValue>
<ds:KeyInfo>
**[Missing Nodes]**
<ds:X509Data>
<ds:X509Certificate>MIIGNjCCBR6gAwIBAgIKGMEergAAAAFORDANBgkqh--.....---Pw6oGsuxLlnQHhjmAaG4I3HdJWA==</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
</getToken>
But is not create nodes in (Example http://ift.tt/1C7EYRd)
<keyvalue>
<rsakeyvalue>
<modulus>2Pb4kEB19m7NmOUYew9f36325yrTLTPMU7qzYG2A0/BsubxDdgQw2Op0x6zXvOVX
sYI9KkPXtD5orKJMjwxYRv9wUWdyiE776Rv4ljfJO7EQhIK1fDQDnPt0HefBS06Xzg2QLBvLR+pe1vc6C02Dr99v+lnLA8mnZiJlRHndhNU=
</modulus>
<exponent>AQAB</exponent>
</rsakeyvalue>
</keyvalue>
una pregunta, xk no se crea el keyvalue???
ReplyDelete