@@ -79,104 +79,103 @@ public function testUnmarshalling(): void
7979 $ this ->signedDocument ->ownerDocument ->saveXML ($ this ->signedDocument ),
8080 strval ($ customSigned )
8181 );
82- }
82+ }
8383
8484
8585 /**
8686 * Test the verification of a signature with a given key.
8787 */
88- public function testSuccessfulVerifyingWithGivenKey (): void
89- {
90- $ customSigned = CustomSignable::fromXML ($ this ->signedDocument );
91-
92- $ this ->assertTrue ($ customSigned ->isSigned ());
93- $ signature = $ customSigned ->getSignature ();
94- $ this ->assertInstanceOf (Signature::class, $ signature );
95- $ sigAlg = $ signature ->getSignedInfo ()->getSignatureMethod ()->getAlgorithm ();
96- $ this ->assertEquals (Constants::SIG_RSA_SHA256 , $ sigAlg );
97- $ factory = new SignatureAlgorithmFactory ();
98- $ certificate = new X509Certificate ($ this ->certificate );
99- $ verifier = $ factory ->getAlgorithm ($ sigAlg , $ certificate );
100-
101- $ verified = $ customSigned ->verify ($ verifier );
102- $ this ->assertInstanceOf (CustomSignable::class, $ verified );
103- $ this ->assertFalse ($ verified ->isSigned ());
104- $ this ->assertEquals (
105- '<ssp:CustomSignable xmlns:ssp="urn:ssp:custom"><ssp:Some>Chunk</ssp:Some></ssp:CustomSignable> ' ,
106- strval ($ verified )
107- );
108- $ this ->assertEquals ($ certificate , $ verified ->getValidatingKey ());
109- }
88+ public function testSuccessfulVerifyingWithGivenKey (): void
89+ {
90+ $ customSigned = CustomSignable::fromXML ($ this ->signedDocument );
91+
92+ $ this ->assertTrue ($ customSigned ->isSigned ());
93+ $ signature = $ customSigned ->getSignature ();
94+ $ this ->assertInstanceOf (Signature::class, $ signature );
95+ $ sigAlg = $ signature ->getSignedInfo ()->getSignatureMethod ()->getAlgorithm ();
96+ $ this ->assertEquals (Constants::SIG_RSA_SHA256 , $ sigAlg );
97+ $ factory = new SignatureAlgorithmFactory ();
98+ $ certificate = new X509Certificate ($ this ->certificate );
99+ $ verifier = $ factory ->getAlgorithm ($ sigAlg , $ certificate );
100+
101+ $ verified = $ customSigned ->verify ($ verifier );
102+ $ this ->assertInstanceOf (CustomSignable::class, $ verified );
103+ $ this ->assertFalse ($ verified ->isSigned ());
104+ $ this ->assertEquals (
105+ '<ssp:CustomSignable xmlns:ssp="urn:ssp:custom"><ssp:Some>Chunk</ssp:Some></ssp:CustomSignable> ' ,
106+ strval ($ verified )
107+ );
108+ $ this ->assertEquals ($ certificate , $ verified ->getValidatingKey ());
109+ }
110110
111111
112112 /**
113113 * Test the verification of a signature without passing a key, just what's in KeyInfo
114114 */
115- public function testSuccessfulVerifyingWithoutKey (): void
116- {
117- $ customSigned = CustomSignable::fromXML ($ this ->signedDocument );
118-
119- $ this ->assertTrue ($ customSigned ->isSigned ());
120- $ signature = $ customSigned ->getSignature ();
121- $ this ->assertInstanceOf (Signature::class, $ signature );
122- $ sigAlg = $ signature ->getSignedInfo ()->getSignatureMethod ()->getAlgorithm ();
123- $ this ->assertEquals (Constants::SIG_RSA_SHA256 , $ sigAlg );
124- $ certificate = new X509Certificate ($ this ->certificate );
125-
126- $ verified = $ customSigned ->verify ();
127- $ this ->assertInstanceOf (CustomSignable::class, $ verified );
128- $ this ->assertFalse ($ verified ->isSigned ());
129- $ this ->assertEquals (
130- '<ssp:CustomSignable xmlns:ssp="urn:ssp:custom"><ssp:Some>Chunk</ssp:Some></ssp:CustomSignable> ' ,
131- strval ($ verified )
132- );
133- $ validatingKey = $ verified ->getValidatingKey ();
134- $ this ->assertInstanceOf (X509Certificate::class, $ validatingKey );
135- /** @var \SimpleSAML\XMLSecurity\Key\X509Certificate $validatingKey */
136- $ this ->assertEquals ($ certificate ->getCertificate (), $ validatingKey ->getCertificate ());
137- }
115+ public function testSuccessfulVerifyingWithoutKey (): void
116+ {
117+ $ customSigned = CustomSignable::fromXML ($ this ->signedDocument );
118+
119+ $ this ->assertTrue ($ customSigned ->isSigned ());
120+ $ signature = $ customSigned ->getSignature ();
121+ $ this ->assertInstanceOf (Signature::class, $ signature );
122+ $ sigAlg = $ signature ->getSignedInfo ()->getSignatureMethod ()->getAlgorithm ();
123+ $ this ->assertEquals (Constants::SIG_RSA_SHA256 , $ sigAlg );
124+ $ certificate = new X509Certificate ($ this ->certificate );
125+
126+ $ verified = $ customSigned ->verify ();
127+ $ this ->assertInstanceOf (CustomSignable::class, $ verified );
128+ $ this ->assertFalse ($ verified ->isSigned ());
129+ $ this ->assertEquals (
130+ '<ssp:CustomSignable xmlns:ssp="urn:ssp:custom"><ssp:Some>Chunk</ssp:Some></ssp:CustomSignable> ' ,
131+ strval ($ verified )
132+ );
133+ $ validatingKey = $ verified ->getValidatingKey ();
134+ $ this ->assertInstanceOf (X509Certificate::class, $ validatingKey );
135+ /** @var \SimpleSAML\XMLSecurity\Key\X509Certificate $validatingKey */
136+ $ this ->assertEquals ($ certificate ->getCertificate (), $ validatingKey ->getCertificate ());
137+ }
138138
139139
140140 /**
141141 * Test that verifying a tampered signature, without giving a key for verification, fails as expected.
142142 */
143- public function testVerifyingTamperedSignatureWithoutKeyFails (): void
144- {
145- $ customSigned = CustomSignable::fromXML ($ this ->tamperedDocument );
143+ public function testVerifyingTamperedSignatureWithoutKeyFails (): void
144+ {
145+ $ customSigned = CustomSignable::fromXML ($ this ->tamperedDocument );
146146
147- $ this ->assertTrue ($ customSigned ->isSigned ());
148- $ signature = $ customSigned ->getSignature ();
149- $ this ->assertInstanceOf (Signature::class, $ signature );
150- $ sigAlg = $ signature ->getSignedInfo ()->getSignatureMethod ()->getAlgorithm ();
151- $ this ->assertEquals (Constants::SIG_RSA_SHA256 , $ sigAlg );
147+ $ this ->assertTrue ($ customSigned ->isSigned ());
148+ $ signature = $ customSigned ->getSignature ();
149+ $ this ->assertInstanceOf (Signature::class, $ signature );
150+ $ sigAlg = $ signature ->getSignedInfo ()->getSignatureMethod ()->getAlgorithm ();
151+ $ this ->assertEquals (Constants::SIG_RSA_SHA256 , $ sigAlg );
152152
153- $ this ->expectException (RuntimeException::class);
154- $ this ->expectDeprecationMessage ('Failed to validate signature. ' );
155- $ customSigned ->verify ();
156- }
153+ $ this ->expectException (RuntimeException::class);
154+ $ this ->expectDeprecationMessage ('Failed to validate signature. ' );
155+ $ customSigned ->verify ();
156+ }
157157
158158
159159 /**
160160 * Test that verifying a tampered signature with a given key fails as expected.
161161 */
162- public function testVerifyingTamperedSignatureWithKeyFails (): void
163- {
164- $ customSigned = CustomSignable::fromXML ($ this ->tamperedDocument );
165-
162+ public function testVerifyingTamperedSignatureWithKeyFails (): void
163+ {
164+ $ customSigned = CustomSignable::fromXML ($ this ->tamperedDocument );
166165
167- $ this ->assertTrue ($ customSigned ->isSigned ());
168- $ signature = $ customSigned ->getSignature ();
169- $ this ->assertInstanceOf (Signature::class, $ signature );
170- $ sigAlg = $ signature ->getSignedInfo ()->getSignatureMethod ()->getAlgorithm ();
171- $ this ->assertEquals (Constants::SIG_RSA_SHA256 , $ sigAlg );
172- $ factory = new SignatureAlgorithmFactory ();
173- $ certificate = new X509Certificate ($ this ->certificate );
174- $ verifier = $ factory ->getAlgorithm ($ sigAlg , $ certificate );
166+ $ this ->assertTrue ($ customSigned ->isSigned ());
167+ $ signature = $ customSigned ->getSignature ();
168+ $ this ->assertInstanceOf (Signature::class, $ signature );
169+ $ sigAlg = $ signature ->getSignedInfo ()->getSignatureMethod ()->getAlgorithm ();
170+ $ this ->assertEquals (Constants::SIG_RSA_SHA256 , $ sigAlg );
171+ $ factory = new SignatureAlgorithmFactory ();
172+ $ certificate = new X509Certificate ($ this ->certificate );
173+ $ verifier = $ factory ->getAlgorithm ($ sigAlg , $ certificate );
175174
176- $ this ->expectException (RuntimeException::class);
177- $ this ->expectDeprecationMessage ('Failed to validate signature. ' );
178- $ customSigned ->verify ($ verifier );
179- }
175+ $ this ->expectException (RuntimeException::class);
176+ $ this ->expectDeprecationMessage ('Failed to validate signature. ' );
177+ $ customSigned ->verify ($ verifier );
178+ }
180179
181180
182181
@@ -215,4 +214,3 @@ public function testSuccessfulVerifyingDocumentWithComments(): void
215214 $ this ->assertEquals ($ certificate , $ verified ->getValidatingKey ());
216215 }
217216}
218-
0 commit comments