robrichards / xmlseclibs

A PHP library for XML Security
BSD 3-Clause "New" or "Revised" License
388 stars 181 forks source link

KeyInfo empty #217

Open NerijusNoreika opened 4 years ago

NerijusNoreika commented 4 years ago

Upon signing the XML with xmlseclibs, my KeyInfo holds no data (no exponent, no modulus).

Here is the code:

` $doc = new \DOMDocument(); $doc->load('./keys/data.xml');

$sig = new XMLSecurityDSig(); try { $sig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N); } catch (Exception $e) { echo $e->getMessage(); } try { $privateKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, ['type' => 'private']); $privateKey->passphrase = 'testtest'; } catch (Exception $e) { echo $e->getMessage(); }

try { $privateKey->loadKey('file://keys/testKey.pem'); } catch (Exception $e) { echo $e->getMessage(); }

$sig->sign($privateKey); $sig->add509Cert('file://keys/testCert.pem'); $sig->appendSignature($doc->getElementsByTagName('authenticationRequest')[0], false); $doc->save('./keys/test.xml'); `

Signed document: <authentication:authenticationRequest xmlns:authentication="http://www.epaslaugos.lt/services/authentication" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:ns3="http://www.w3.org/2001/10/xml-exc-c14n#" id="uniqueNodeId"><authentication:pid>VSID000000000113</authentication:pid><authentication:serviceTarget>citizen</authentication:serviceTarget><authentication:authenticationProvider>auth.lt.identity.card</authentication:authenticationProvider><authentication:authenticationProvider>auth.lt.bank</authentication:authenticationProvider><authentication:authenticationProvider>auth.signatureProvider</authentication:authenticationProvider><authentication:authenticationProvider>auth.login.pass</authentication:authenticationProvider><authentication:authenticationProvider>auth.lt.government.employee.card</authentication:authenticationProvider><authentication:authenticationProvider>auth.stork</authentication:authenticationProvider><authentication:authenticationProvider>auth.tsl.identity.card</authentication:authenticationProvider><authentication:authenticationAttribute>lt-personal-code</authentication:authenticationAttribute><authentication:authenticationAttribute>lt-company-code</authentication:authenticationAttribute><authentication:userInformation>firstName</authentication:userInformation><authentication:userInformation>lastName</authentication:userInformation><authentication:userInformation>companyName</authentication:userInformation><authentication:userInformation>email</authentication:userInformation><authentication:userInformation>address</authentication:userInformation><authentication:postbackUrl>https://localhost/</authentication:postbackUrl><authentication:customData>correlationData</authentication:customData></authentication:authenticationRequest>

Output:

`<?xml version="1.0"?>

VSID000000000113citizenauth.lt.identity.cardauth.lt.bankauth.signatureProviderauth.login.passauth.lt.government.employee.cardauth.storkauth.tsl.identity.cardlt-personal-codelt-company-codefirstNamelastNamecompanyNameemailaddresshttps://localhost/correlationData XidaQDNo4VKa9MDTfj+wwF2ZmfY=fs6WHyF9oIMIhu0vvVjOo62YOeBQ3fEgBWMno36akyoDySFZuAtDgLLLmfH+ibkSDBL072/pMt8LhWhDk7fPAWu5EE+rd1wAim0Ap28MAKSlmsfvJ6H/9E3bPCDJZ27yPyBZHIpXRR6sk6YiLop7K5mxch323m9BqCsPaxZNyo712gGyyz0fNTM5jTK3Fl8mckB1SJRnB7JVUJduTBnEBRXvR9q3c6tk8VymWngYOGRDe27Uo9YEJQrnHWGGTOfDitYJR6k56uOZd4wXVwmrLdUBL0z76X/Pu20jLQsDZYx6uKcKQi9eSE15Bf6LS8jIdT9F4FsADEmu9fiNYXsWgg== `
robrichards commented 4 years ago

Current codebase does not support this but it looks like there is an old PR #75 which adds support. I will see about getting the support added.