Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
453ca4a
Rewrite signed elements structure
tvdijen Jan 11, 2021
5fb279d
Add toUnsignedXML to the SignableElementTrait
tvdijen Jan 11, 2021
b877b16
Any signed element should have a signature set
tvdijen Jan 11, 2021
c7c4ab8
Further finalize abstract
tvdijen Jan 11, 2021
2224498
Add testable CustomSignable and CustomSigned
tvdijen Jan 11, 2021
bb29c97
Test signable
tvdijen Jan 16, 2021
747a70e
Remove getter/setter for element
tvdijen Jan 16, 2021
5ad95cd
Remove unnecessary SignableElementTrait
tvdijen Jan 16, 2021
de5a171
Fix
tvdijen Jan 16, 2021
72fe857
Fix
tvdijen Jan 16, 2021
df18f2c
Make SignedElement*::fromXML generic
tvdijen Mar 29, 2021
e0f111f
Change parent
tvdijen Mar 29, 2021
a0a04d0
Use SerializableXMLTestTrait
tvdijen Mar 29, 2021
f23834c
Return unsigned element
tvdijen Mar 30, 2021
6155eb3
Remove getStructure and use toXML instead
tvdijen Mar 30, 2021
b24899e
Fix class-name
tvdijen Mar 30, 2021
3b8db4f
Fix CustomSignedTest
tvdijen Mar 30, 2021
222e566
Fix return value
tvdijen Mar 30, 2021
f43c3b8
Mess up
tvdijen Mar 30, 2021
a49b61e
Fix
tvdijen Mar 30, 2021
aada76d
Leave the Chunk in the trunk
tvdijen Mar 30, 2021
aceb715
Make Signed classes serializable
tvdijen Mar 30, 2021
35ca698
s/self/static
tvdijen Mar 31, 2021
0e2f523
Improve tests
tvdijen Mar 31, 2021
d2ea288
Make sure to ignore extra whitespaces in InclusiveNamespaces@PrefixList
jaimeperez Jul 19, 2021
b920d5c
Minor fixes to ds:XPath implementation
jaimeperez Jul 19, 2021
4052d1b
Remove closure from InclusiveNamespaces
jaimeperez Jul 19, 2021
e85ed90
Nitpicks
jaimeperez Jul 20, 2021
509fe99
Make SignatureAlgorithmFactory reusable for custom algs
jaimeperez Jul 20, 2021
0a89123
Move the hash() function to our Security utility
jaimeperez Jul 20, 2021
77e5310
Add new XML utility class
jaimeperez Jul 20, 2021
6935a68
First attempt to implement signing in XML objects
jaimeperez Jul 20, 2021
9504114
Use the local XML-related constants
jaimeperez Jul 20, 2021
40b63da
Add CanonicalizableInterface
jaimeperez Jul 21, 2021
129de50
Use array constants
tvdijen Jul 21, 2021
cbda623
Fix typos
tvdijen Jul 21, 2021
db79a57
Fix booboo
tvdijen Jul 21, 2021
73b05c8
Rename Canonicalize* interface and trait
jaimeperez Jul 21, 2021
f57790f
Bugfix
jaimeperez Jul 21, 2021
c3381c7
Bump xml-common
tvdijen Jul 21, 2021
e1532e4
Unrelated; cleanup
tvdijen Jul 21, 2021
cf47709
Add CipherValue XML-class
tvdijen Jul 21, 2021
cc99918
Implement CipherValue XML element
tvdijen Jul 21, 2021
a0c0897
Add CarriedKeyName XML-class
tvdijen Jul 21, 2021
15d7924
Implement CarriedKeyName XML-class
tvdijen Jul 21, 2021
db73305
Add missing @covers
tvdijen Jul 21, 2021
4fa1e79
Remove overhead
tvdijen Jul 21, 2021
753866e
Start cleaning up old code with hooks to xmlseclibs
tvdijen Jul 21, 2021
c184d07
Default to empty string; Scrutinizer warns us to do additional type …
tvdijen Jul 22, 2021
801ed71
Add constants for ASN tags and sizes to improve readability
tvdijen Jul 22, 2021
9f9cf63
Use assertion instead of returning null for string out-of-bounds
tvdijen Jul 22, 2021
135bf21
Silence Scrutinizer; the syntax is just fine, but Scrutinizer doesn'…
tvdijen Jul 22, 2021
3dd2911
Fix implicit array to bool cast
tvdijen Jul 22, 2021
e23ada2
Remove array test; the properties are always an array
tvdijen Jul 22, 2021
fa7d627
Fix phpdoc
tvdijen Jul 22, 2021
9349424
Fix parentheses
tvdijen Jul 22, 2021
8d45f60
Fix incorrect return type
tvdijen Jul 22, 2021
40658ba
Fix phpdoc
tvdijen Jul 22, 2021
c9a2951
Add a method to SignatureAlgorithm to get the key
jaimeperez Jul 23, 2021
35b1ab9
Fix DOMXPath use
tvdijen Jul 23, 2021
bbfbf60
Add use-statements for builtins
tvdijen Jul 23, 2021
05b928b
Add constants for X509 certificate header/footer
jaimeperez Jul 23, 2021
7215435
Use our own Assert in SignableElementTrait
jaimeperez Jul 23, 2021
6bbe2ef
Phpdoc fixes
jaimeperez Jul 23, 2021
b582541
Make SignableElementInterface extend CanonicalizableElementInterface
jaimeperez Jul 23, 2021
49ee59c
Minor fixes
jaimeperez Jul 24, 2021
eeb15ef
Add a method to ds:Reference to determine if it's an XPointer
jaimeperez Jul 24, 2021
20dd0c8
Add more signed documents
jaimeperez Jul 24, 2021
df435c2
Signable elements should call toXML()
jaimeperez Jul 24, 2021
5fa57da
Use short name for Constants class
jaimeperez Jul 24, 2021
4137de0
Fix wrong package name
jaimeperez Jul 24, 2021
4073c66
No longer override c14n alg
jaimeperez Jul 24, 2021
20bcbd0
Implement signature verification, refactor signing
jaimeperez Jul 24, 2021
ed8ca90
Fix nits
tvdijen Jul 24, 2021
60939ab
Fix nits
tvdijen Jul 24, 2021
0f1f17c
Fix file name
tvdijen Jul 24, 2021
8123f41
Fix phpcs issues
tvdijen Jul 24, 2021
32ac524
Fix psalm issue
tvdijen Jul 24, 2021
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
15 changes: 15 additions & 0 deletions bin/generate_CustomSignable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require_once('../vendor/autoload.php');

use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XMLSecurity\Test\XML\CustomSignable;
use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock;
use SimpleSAML\XMLSecurity\XMLSecurityKey;

$chunk = DOMDocumentFactory::fromString('<ssp:Some>Chunk</ssp:Some>')->documentElement;
$signable = new CustomSignable($chunk);

$privateKey = PEMCertificatesMock::getPrivateKey(XMLSecurityKey::RSA_SHA256, PEMCertificatesMock::SELFSIGNED_PRIVATE_KEY);
$x = $signable->sign($privateKey);
echo $x;
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

"robrichards/xmlseclibs": "^3.1.1",
"simplesamlphp/assert": "~0.2.6",
"simplesamlphp/xml-common": "^0.7.1"
"simplesamlphp/xml-common": "^0.8.0"
},
"require-dev": {
"simplesamlphp/simplesamlphp-test-framework": "^1.0.5"
Expand Down
47 changes: 42 additions & 5 deletions src/Alg/Signature/AbstractSigner.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\Alg\Signature;

use SimpleSAML\Assert\Assert;
use SimpleSAML\XMLSecurity\Alg\SignatureAlgorithm;
use SimpleSAML\XMLSecurity\Backend\SignatureBackend;
use SimpleSAML\XMLSecurity\Exception\RuntimeException;
use SimpleSAML\XMLSecurity\Key\AbstractKey;

/**
* An abstract class that implements a generic digital signature algorithm.
*
* @package SimpleSAML\XMLSecurity\\Alg\Signature
* @package simplesamlphp/xml-security
*/
abstract class AbstractSigner implements SignatureAlgorithm
{
/** @var \SimpleSAML\XMLSecurity\Key\AbstractKey */
protected AbstractKey $key;
private AbstractKey $key;

/** @var \SimpleSAML\XMLSecurity\Backend\SignatureBackend */
protected SignatureBackend $backend;
Expand All @@ -25,22 +29,46 @@ abstract class AbstractSigner implements SignatureAlgorithm
/** @var string */
protected string $digest;

/** @var string */
protected string $algId;


/**
* Build a signature algorithm.
*
* Extend this class to implement your own signers.
*
* WARNING: remember to adjust the type of the key to the one that works with your algorithm!
*
* @param \SimpleSAML\XMLSecurity\Key\AbstractKey $key The signing key.
* @param string $algId The identifier of this algorithm.
* @param string $digest The identifier of the digest algorithm to use.
*/
public function __construct(AbstractKey $key, string $digest)
public function __construct(AbstractKey $key, string $algId, string $digest)
{
Assert::oneOf(
$algId,
static::getSupportedAlgorithms(),
'Unsupported algorithm for ' . static::class,
RuntimeException::class
);
$this->key = $key;
$this->algId = $algId;
$this->digest = $digest;
$this->backend = new $this->default_backend();
$this->backend->setDigestAlg($digest);
}


/**
* @return string
*/
public function getAlgorithmId(): string
{
return $this->algId;
}


/**
* @return string
*/
Expand All @@ -50,6 +78,15 @@ public function getDigest(): string
}


/**
* @return AbstractKey
*/
public function getKey(): AbstractKey
{
return $this->key;
}


/**
* @param \SimpleSAML\XMLSecurity\Backend\SignatureBackend $backend
*/
Expand All @@ -67,7 +104,7 @@ public function setBackend(SignatureBackend $backend): void
*
* @return string The (binary) signature corresponding to the given plaintext.
*/
public function sign(string $plaintext): string
final public function sign(string $plaintext): string
{
return $this->backend->sign($this->key, $plaintext);
}
Expand All @@ -81,7 +118,7 @@ public function sign(string $plaintext): string
*
* @return boolean True if the signature can be verified, false otherwise.
*/
public function verify(string $plaintext, string $signature): bool
final public function verify(string $plaintext, string $signature): bool
{
return $this->backend->verify($this->key, $plaintext, $signature);
}
Expand Down
23 changes: 17 additions & 6 deletions src/Alg/Signature/HMAC.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\Alg\Signature;

use SimpleSAML\XMLSecurity\Alg\SignatureAlgorithm;
use SimpleSAML\XMLSecurity\Backend\HMAC as HMAC_Backend;
use SimpleSAML\XMLSecurity\Constants;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\Key\SymmetricKey;

/**
* Class implementing the HMAC signature algorithm
*
* @package SimpleSAML\XMLSecurity\Alg\Signature
* @package simplesamlphp/xml-security
*/
class HMAC extends AbstractSigner implements SignatureAlgorithm
final class HMAC extends AbstractSigner implements SignatureAlgorithm
{
/** @var string */
protected string $default_backend = HMAC_Backend::class;
Expand All @@ -22,10 +24,19 @@ class HMAC extends AbstractSigner implements SignatureAlgorithm
* HMAC constructor.
*
* @param \SimpleSAML\XMLSecurity\Key\SymmetricKey $key The symmetric key to use.
* @param string $digest The identifier of the digest algorithm to use.
* @param string $algId The identifier of this algorithm.
*/
public function __construct(SymmetricKey $key, string $algId = C::SIG_HMAC_SHA256)
{
parent::__construct($key, $algId, C::$HMAC_DIGESTS[$algId]);
}


/**
* @inheritDoc
*/
public function __construct(SymmetricKey $key, string $digest = Constants::DIGEST_SHA1)
public static function getSupportedAlgorithms(): array
{
parent::__construct($key, $digest);
return array_keys(C::$HMAC_DIGESTS);
}
}
23 changes: 17 additions & 6 deletions src/Alg/Signature/RSA.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\Alg\Signature;

use SimpleSAML\XMLSecurity\Alg\SignatureAlgorithm;
use SimpleSAML\XMLSecurity\Backend\OpenSSL;
use SimpleSAML\XMLSecurity\Constants;
use SimpleSAML\XMLSecurity\Constants as C;
use SimpleSAML\XMLSecurity\Key\AsymmetricKey;

/**
* Class implementing the RSA signature algorithm.
*
* @package SimpleSAML\XMLSecurity\Alg\Signature
* @package simplesamlphp/xml-security
*/
class RSA extends AbstractSigner implements SignatureAlgorithm
final class RSA extends AbstractSigner implements SignatureAlgorithm
{
/** @var string */
protected string $default_backend = OpenSSL::class;
Expand All @@ -22,10 +24,19 @@ class RSA extends AbstractSigner implements SignatureAlgorithm
* RSA constructor.
*
* @param \SimpleSAML\XMLSecurity\Key\AsymmetricKey $key The asymmetric key (either public or private) to use.
* @param string $digest The identifier of the digest algorithm to use.
* @param string $algId The identifier of this algorithm.
*/
public function __construct(AsymmetricKey $key, string $algId = C::SIG_RSA_SHA256)
{
parent::__construct($key, $algId, C::$RSA_DIGESTS[$algId]);
}


/**
* @inheritDoc
*/
public function __construct(AsymmetricKey $key, string $digest = Constants::DIGEST_SHA1)
public static function getSupportedAlgorithms(): array
{
parent::__construct($key, $digest);
return array_keys(C::$RSA_DIGESTS);
}
}
Loading