44
55namespace SimpleSAML \SAML2 \Certificate ;
66
7- use SimpleSAML \SAML2 \Certificate \PrivateKey ;
87use SimpleSAML \SAML2 \Configuration \DecryptionProvider ;
98use SimpleSAML \SAML2 \Configuration \PrivateKey as PrivateKeyConfiguration ;
109use SimpleSAML \SAML2 \Utilities \ArrayCollection ;
11- use SimpleSAML \SAML2 \ Utilities \ File ;
12- use SimpleSAML \XMLSecurity \XMLSecurityKey ;
10+ use SimpleSAML \XMLSecurity \ Key \ PrivateKey ;
11+ use SimpleSAML \XMLSecurity \Key \ SymmetricKey ;
1312
1413class PrivateKeyLoader
1514{
1615 /**
1716 * Loads a private key based on the configuration given.
1817 *
1918 * @param \SimpleSAML\SAML2\Configuration\PrivateKey $key
20- * @return \SimpleSAML\SAML2\Certificate \PrivateKey
19+ * @return \SimpleSAML\XMLSecurity\Key \PrivateKey
2120 */
2221 public function loadPrivateKey (PrivateKeyConfiguration $ key ): PrivateKey
2322 {
24- if ($ key ->isFile ()) {
25- $ privateKey = File::getFileContents ($ key ->getFilePath ());
26- } else {
27- $ privateKey = $ key ->getContents ();
28- }
29-
30- return PrivateKey::create ($ privateKey , $ key ->getPassPhrase ());
23+ return PrivateKey::fromFile (
24+ $ key ->isFile () ? $ key ->getFilePath () : $ key ->getContents (),
25+ $ key ->getPassPhrase (),
26+ );
3127 }
3228
3329
@@ -45,8 +41,7 @@ public function loadDecryptionKeys(
4541
4642 $ senderSharedKey = $ identityProvider ->getSharedKey ();
4743 if ($ senderSharedKey !== null ) {
48- $ key = new XMLSecurityKey (XMLSecurityKey::AES128_CBC );
49- $ key ->loadKey ($ senderSharedKey );
44+ $ key = new SymmetricKey ($ senderSharedKey );
5045 $ decryptionKeys ->add ($ key );
5146
5247 return $ decryptionKeys ;
@@ -55,32 +50,13 @@ public function loadDecryptionKeys(
5550 $ newPrivateKey = $ serviceProvider ->getPrivateKey (PrivateKeyConfiguration::NAME_NEW );
5651 if ($ newPrivateKey instanceof PrivateKeyConfiguration) {
5752 $ loadedKey = $ this ->loadPrivateKey ($ newPrivateKey );
58- $ decryptionKeys ->add ($ this -> convertPrivateKeyToRsaKey ( $ loadedKey) );
53+ $ decryptionKeys ->add ($ loadedKey );
5954 }
6055
6156 $ privateKey = $ serviceProvider ->getPrivateKey (PrivateKeyConfiguration::NAME_DEFAULT , true );
6257 $ loadedKey = $ this ->loadPrivateKey ($ privateKey );
63- $ decryptionKeys ->add ($ this -> convertPrivateKeyToRsaKey ( $ loadedKey) );
58+ $ decryptionKeys ->add ($ loadedKey );
6459
6560 return $ decryptionKeys ;
6661 }
67-
68-
69- /**
70- * @param \SimpleSAML\SAML2\Certificate\PrivateKey $privateKey
71- * @throws \Exception
72- * @return \SimpleSAML\XMLSecurity\XMLSecurityKey
73- */
74- private function convertPrivateKeyToRsaKey (PrivateKey $ privateKey ): XMLSecurityKey
75- {
76- $ key = new XMLSecurityKey (XMLSecurityKey::RSA_1_5 , ['type ' => 'private ' ]);
77- $ passphrase = $ privateKey ->getPassphrase ();
78- if ($ passphrase ) {
79- $ key ->passphrase = $ passphrase ;
80- }
81-
82- $ key ->loadKey ($ privateKey ->getKeyAsString ());
83-
84- return $ key ;
85- }
8662}
0 commit comments