setName('backup:key:kit') ->setDescription('Write the recovery kit (passphrase-protected key) to a file or stdout') ->addOption('output', 'o', InputOption::VALUE_REQUIRED, 'File to write (default: stdout)'); } protected function execute(InputInterface $input, OutputInterface $output): int { if (!$this->keys->isInitialized()) { $output->writeln('No backup key yet: run occ backup:key:init first.'); return 1; } $this->alerts->securityEvent('kit_downloaded'); $json = json_encode($this->keys->recoveryKit(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR) . "\n"; $file = $input->getOption('output'); if ($file === null) { $output->write($json, false, OutputInterface::OUTPUT_RAW); return 0; } if (file_put_contents($file, $json) === false) { $output->writeln("Cannot write $file"); return 1; } @chmod($file, 0600); $output->writeln("Recovery kit written to $file. Copy it off this server, then run occ backup:key:confirm."); return 0; } }