44
55namespace SimpleSAML \SAML2 \Certificate ;
66
7- use SimpleSAML \SAML2 \Certificate \PrivateKey ;
87use SimpleSAML \SAML2 \Configuration \DecryptionProvider ;
98use SimpleSAML \SAML2 \Configuration \PrivateKey as PrivateKeyConfiguration ;
10- use SimpleSAML \SAML2 \Constants as C ;
119use SimpleSAML \SAML2 \Utilities \ArrayCollection ;
12- use SimpleSAML \SAML2 \ Utilities \ File ;
13- use SimpleSAML \XMLSecurity \XMLSecurityKey ;
10+ use SimpleSAML \XMLSecurity \ Key \ PrivateKey ;
11+ use SimpleSAML \XMLSecurity \Key \ SymmetricKey ;
1412
1513class PrivateKeyLoader
1614{
1715 /**
1816 * Loads a private key based on the configuration given.
1917 *
2018 * @param \SimpleSAML\SAML2\Configuration\PrivateKey $key
21- * @return \SimpleSAML\SAML2\Certificate \PrivateKey
19+ * @return \SimpleSAML\XMLSecurity\Key \PrivateKey
2220 */
2321 public function loadPrivateKey (PrivateKeyConfiguration $ key ): PrivateKey
2422 {
25- if ($ key ->isFile ()) {
26- $ privateKey = File::getFileContents ($ key ->getFilePath ());
27- } else {
28- $ privateKey = $ key ->getContents ();
29- }
30-
31- return PrivateKey::create ($ privateKey , $ key ->getPassPhrase ());
23+ return PrivateKey::fromFile (
24+ $ key ->isFile () ? $ key ->getFilePath () : $ key ->getContents (),
25+ $ key ->getPassPhrase (),
26+ );
3227 }
3328
3429
@@ -46,8 +41,7 @@ public function loadDecryptionKeys(
4641
4742 $ senderSharedKey = $ identityProvider ->getSharedKey ();
4843 if ($ senderSharedKey !== null ) {
49- $ key = new XMLSecurityKey (C::BLOCK_ENC_AES128 );
50- $ key ->loadKey ($ senderSharedKey );
44+ $ key = new SymmetricKey ($ senderSharedKey );
5145 $ decryptionKeys ->add ($ key );
5246
5347 return $ decryptionKeys ;
@@ -56,32 +50,13 @@ public function loadDecryptionKeys(
5650 $ newPrivateKey = $ serviceProvider ->getPrivateKey (PrivateKeyConfiguration::NAME_NEW );
5751 if ($ newPrivateKey instanceof PrivateKeyConfiguration) {
5852 $ loadedKey = $ this ->loadPrivateKey ($ newPrivateKey );
59- $ decryptionKeys ->add ($ this -> convertPrivateKeyToRsaKey ( $ loadedKey) );
53+ $ decryptionKeys ->add ($ loadedKey );
6054 }
6155
6256 $ privateKey = $ serviceProvider ->getPrivateKey (PrivateKeyConfiguration::NAME_DEFAULT , true );
6357 $ loadedKey = $ this ->loadPrivateKey ($ privateKey );
64- $ decryptionKeys ->add ($ this -> convertPrivateKeyToRsaKey ( $ loadedKey) );
58+ $ decryptionKeys ->add ($ loadedKey );
6559
6660 return $ decryptionKeys ;
6761 }
68-
69-
70- /**
71- * @param \SimpleSAML\SAML2\Certificate\PrivateKey $privateKey
72- * @throws \Exception
73- * @return \SimpleSAML\XMLSecurity\XMLSecurityKey
74- */
75- private function convertPrivateKeyToRsaKey (PrivateKey $ privateKey ): XMLSecurityKey
76- {
77- $ key = new XMLSecurityKey (XMLSecurityKey::RSA_1_5 , ['type ' => 'private ' ]);
78- $ passphrase = $ privateKey ->getPassphrase ();
79- if ($ passphrase ) {
80- $ key ->passphrase = $ passphrase ;
81- }
82-
83- $ key ->loadKey ($ privateKey ->getKeyAsString ());
84-
85- return $ key ;
86- }
8762}
0 commit comments