Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make whitespace in created signature node configurable option because of C# DOTNET signature validation #248

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
# guycalledseven xmlseclib fork

This fork has one small but **very important** change in `XMLSecurityDSig` class. order to make signatures verifiable on C#.

Adding of signatures is done via predefined template string constant which contains whitespaces. If signed xml should not contain whitespaces - this will break signature and it won't validate (on eg. c#).

To fix this, constructor now accepts optional parameters `$preserveWhiteSpace` and `$formatOutput` which now default both to false.


```
/**
* Added preserveWhiteSpace = false since validating signature in C# fails because
* signature base template contains & inserts whitespaces on it's own
* @param string $prefix
* @param boolean $preserveWhiteSpace
* @param boolean $formatOutput
*/
public function __construct($prefix='ds', $preserveWhiteSpace = false, $formatOutput = false)
{

...

$sigdoc = new DOMDocument();
$sigdoc->preserveWhiteSpace = $preserveWhiteSpace;
$sigdoc->formatOutput = $formatOutput;

$sigdoc->loadXML($template);
$this->sigNode = $sigdoc->documentElement;
}


```

#xmlseclibs

xmlseclibs is a library written in PHP for working with XML Encryption and Signatures.
Expand Down
9 changes: 8 additions & 1 deletion src/XMLSecurityDSig.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ class XMLSecurityDSig
private $validatedNodes = null;

/**
* Added preserveWhiteSpace = false since validating signature in C# fails because
* signature base template contains & inserts whitespaces on it's own
* @param string $prefix
* @param boolean $preserveWhiteSpace
* @param boolean $formatOutput
*/
public function __construct($prefix='ds')
public function __construct($prefix='ds', $preserveWhiteSpace = false, $formatOutput = false)
{
$template = self::BASE_TEMPLATE;
if (! empty($prefix)) {
Expand All @@ -117,6 +121,9 @@ public function __construct($prefix='ds')
$template = str_replace($search, $replace, $template);
}
$sigdoc = new DOMDocument();
$sigdoc->preserveWhiteSpace = $preserveWhiteSpace;
$sigdoc->formatOutput = $formatOutput;

$sigdoc->loadXML($template);
$this->sigNode = $sigdoc->documentElement;
}
Expand Down