@@ -40,31 +40,58 @@ protected function configure() {
4040 $ this
4141 ->setName ('integrity:check-app ' )
4242 ->setDescription ('Check integrity of an app using a signature. ' )
43- ->addArgument ('appid ' , InputArgument::REQUIRED , 'Application to check ' )
44- ->addOption ('path ' , null , InputOption::VALUE_OPTIONAL , 'Path to application. If none is given it will be guessed. ' );
43+ ->addArgument ('appid ' , InputArgument::OPTIONAL , 'Application to check ' )
44+ ->addOption ('path ' , null , InputOption::VALUE_OPTIONAL , 'Path to application. If none is given it will be guessed. ' )
45+ ->addOption ('all ' , null , InputOption::VALUE_NONE , 'Check integrity of all apps. ' );
4546 }
4647
4748 /**
4849 * {@inheritdoc }
4950 */
5051 protected function execute (InputInterface $ input , OutputInterface $ output ): int {
51- $ appid = $ input ->getArgument ('appid ' );
52- $ path = (string )$ input ->getOption ('path ' );
53- if ($ path === '' ) {
54- $ path = $ this ->appLocator ->getAppPath ($ appid );
52+ if ($ input ->getOption ('all ' ) && $ input ->getArgument ('appid ' )) {
53+ $ output ->writeln ('<error>Option "--all" cannot be combined with an appid</error> ' );
54+ return 1 ;
5555 }
56- if ($ this ->appManager ->isShipped ($ appid ) || $ this ->fileAccessHelper ->file_exists ($ path . '/appinfo/signature.json ' )) {
57- // Only verify if the application explicitly ships a signature.json file
58- $ result = $ this ->checker ->verifyAppSignature ($ appid , $ path , true );
59- $ this ->writeArrayInOutputFormat ($ input , $ output , $ result );
60- if (count ($ result ) > 0 ) {
61- $ output ->writeln ('<error> ' . count ($ result ) . ' errors found</error> ' , OutputInterface::VERBOSITY_VERBOSE );
62- return 1 ;
56+
57+ if (!$ input ->getArgument ('appid ' ) && !$ input ->getOption ('all ' )) {
58+ $ output ->writeln ('<error>Please specify an appid, or "--all" to verify all apps</error> ' );
59+ return 1 ;
60+ }
61+
62+ if ($ input ->getArgument ('appid ' )) {
63+ $ appIds = [$ input ->getArgument ('appid ' )];
64+ } else {
65+ $ appIds = $ this ->appManager ->getAllAppsInAppsFolders ();
66+ }
67+
68+ $ errorsFound = false ;
69+
70+ foreach ($ appIds as $ appId ) {
71+ $ path = (string )$ input ->getOption ('path ' );
72+ if ($ path === '' ) {
73+ $ path = $ this ->appLocator ->getAppPath ($ appId );
6374 }
75+
76+ if ($ this ->appManager ->isShipped ($ appId ) || $ this ->fileAccessHelper ->file_exists ($ path . '/appinfo/signature.json ' )) {
77+ // Only verify if the application explicitly ships a signature.json file
78+ $ result = $ this ->checker ->verifyAppSignature ($ appId , $ path , true );
79+
80+ if (count ($ result ) > 0 ) {
81+ $ output ->writeln ('<error> ' . $ appId . ': ' . count ($ result ) . ' errors found:</error> ' );
82+ $ this ->writeArrayInOutputFormat ($ input , $ output , $ result );
83+ $ errorsFound = true ;
84+ }
85+ } else {
86+ $ output ->writeln ('<comment> ' . $ appId . ': ' . 'App signature not found, skipping app integrity check</comment> ' );
87+ }
88+ }
89+
90+ if (!$ errorsFound ) {
6491 $ output ->writeln ('<info>No errors found</info> ' , OutputInterface::VERBOSITY_VERBOSE );
65- } else {
66- $ output ->writeln ('<comment>App signature not found, skipping app integrity check</comment> ' );
92+ return 0 ;
6793 }
68- return 0 ;
94+
95+ return 1 ;
6996 }
7097}
0 commit comments