File tree Expand file tree Collapse file tree
apps/files_external/lib/Lib/Auth/PublicKey Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414use OCP \IConfig ;
1515use OCP \IL10N ;
1616use OCP \IUser ;
17+ use phpseclib3 \Crypt \PublicKeyLoader ;
1718use phpseclib3 \Crypt \RSA as RSACrypt ;
1819
1920/**
@@ -46,15 +47,19 @@ public function __construct(
4647 #[\Override]
4748 public function manipulateStorageConfig (StorageConfig &$ storage , ?IUser $ user = null ) {
4849 try {
49- $ auth = RSACrypt:: loadPrivateKey (
50+ $ auth = PublicKeyLoader:: load (
5051 $ storage ->getBackendOption ('private_key ' ),
5152 $ this ->config ->getSystemValue ('secret ' , '' )
5253 );
5354 } catch (\Throwable ) {
5455 // Add fallback routine for a time where secret was not enforced to be exists
55- $ auth = RSACrypt:: loadPrivateKey ($ storage ->getBackendOption ('private_key ' ));
56+ $ auth = PublicKeyLoader:: load ($ storage ->getBackendOption ('private_key ' ));
5657 }
5758
59+ if (!$ auth instanceof RSACrypt \PrivateKey) {
60+ throw new \RuntimeException ('Loaded key is not a private key ' );
61+ }
62+ $ auth = $ auth ->withPassword ('' );
5863 $ storage ->setBackendOption ('public_key_auth ' , $ auth );
5964 }
6065
Original file line number Diff line number Diff line change 1313use OCP \IConfig ;
1414use OCP \IL10N ;
1515use OCP \IUser ;
16+ use phpseclib3 \Crypt \PublicKeyLoader ;
1617use phpseclib3 \Crypt \RSA ;
1718use phpseclib3 \Exception \NoKeyLoadedException ;
1819
@@ -46,17 +47,23 @@ public function __construct(
4647 public function manipulateStorageConfig (StorageConfig &$ storage , ?IUser $ user = null ) {
4748
4849 try {
49- $ auth = RSA \PrivateKey:: loadPrivateKey (
50+ $ auth = PublicKeyLoader:: load (
5051 $ storage ->getBackendOption ('private_key ' ),
5152 $ this ->config ->getSystemValue ('secret ' , '' ),
5253 );
5354 } catch (NoKeyLoadedException ) {
5455 // Add fallback routine for a time where secret was not enforced to be exists
55- $ auth = RSA \PrivateKey:: loadPrivateKey (
56+ $ auth = PublicKeyLoader:: load (
5657 $ storage ->getBackendOption ('private_key ' ),
5758 '' ,
5859 );
5960 }
61+
62+ if (!$ auth instanceof RSA \PrivateKey) {
63+ throw new \RuntimeException ('Loaded key is not a private key ' );
64+ }
65+
66+ $ auth = $ auth ->withPassword ('' );
6067 $ storage ->setBackendOption ('public_key_auth ' , $ auth );
6168 }
6269}
You can’t perform that action at this time.
0 commit comments