@@ -708,39 +708,46 @@ public function createAdminUser(string $username = '', string $password = '', st
708
708
public function generateJwtKeys ($ generateKeys = null )
709
709
{
710
710
$ config = new Config ();
711
- echo "You will need the public/private keys for users to login and validate . \n" ;
711
+ echo "You will need the public/private keys for users to login. \n" ;
712
712
echo "These can be automatically generated for you, or you can manually copy them in yourself \n\n" ;
713
713
714
714
$ private_key_path = $ public_key_path = '' ;
715
715
try {
716
716
$ private_key_path = $ config ->__get (['api ' , 'jwt_private_key ' ]);
717
717
$ public_key_path = $ config ->__get (['api ' , 'jwt_public_key ' ]);
718
- echo "Private JWT key path: $ private_key_path \n" ;
719
- echo "Public JWT key path: $ public_key_path \n\n" ;
720
718
} catch (ApiException $ e ) {
721
719
$ this ->handleException ($ e );
722
720
}
723
721
724
722
while (!is_bool ($ generateKeys )) {
725
723
$ prompt = "Automatically generate public/private keys for JWT " ;
726
- $ prompt .= "(WARNING, this will overwrite any existing keys at " ;
724
+ $ prompt .= "(WARNING: this will overwrite any existing keys at " ;
727
725
$ prompt .= "the location defined in settings.yml) [Y/n]: " ;
728
726
$ generateKeys = strtolower ($ this ->readlineTerminal ($ prompt ));
729
727
$ generateKeys = $ generateKeys === 'y ' || $ generateKeys === '' ? true : $ generateKeys ;
730
728
$ generateKeys = $ generateKeys === 'n ' ? false : $ generateKeys ;
731
729
}
732
730
733
731
if ($ generateKeys ) {
734
- echo "Generating keys... \n" ;
735
- $ cmd = "rm $ private_key_path $ public_key_path " ;
736
- shell_exec ($ cmd );
737
- $ cmd = "echo -e 'y \\n' | ssh-keygen -t rsa -b 4096 -P '' -m PEM -f $ private_key_path >/dev/null & sleep 2 " ;
732
+ if (file_exists ($ private_key_path )) {
733
+ echo "Removing existing private key at $ private_key_path \n" ;
734
+ $ cmd = "rm $ private_key_path " ;
735
+ shell_exec ($ cmd );
736
+ }
737
+ if (file_exists ($ public_key_path )) {
738
+ echo "Removing existing public key at $ public_key_path \n" ;
739
+ $ cmd = "rm $ public_key_path " ;
740
+ shell_exec ($ cmd );
741
+ }
742
+ echo "Generating new private key... \n" ;
743
+ $ cmd = "echo -e 'y \\n' | ssh-keygen -t rsa -b 4096 -P '' -m PEM -f $ private_key_path >/dev/null; sleep 1 " ;
738
744
shell_exec ($ cmd );
739
- $ cmd = "echo -e 'y \\n' | openssl rsa -in $ private_key_path -pubout -outform PEM -out $ public_key_path " ;
740
- $ cmd .= " & sleep 2 " ;
745
+ echo "Generating new public key... \n" ;
746
+ $ cmd = "echo -e 'y \\n' | openssl rsa -in $ private_key_path -pubout -outform PEM -out $ public_key_path; " ;
747
+ $ cmd .= "sleep 1 " ;
741
748
shell_exec ($ cmd );
742
749
shell_exec ("chmod 600 $ private_key_path $ public_key_path " );
743
- echo "keys generated \n" ;
750
+ echo "Keys generated at: \n * $ private_key_path \n * $ public_key_path \n" ;
744
751
}
745
752
}
746
753
}
0 commit comments