Path: blob/master/src/applications/almanac/management/AlmanacManagementTrustKeyWorkflow.php
12256 views
<?php12final class AlmanacManagementTrustKeyWorkflow3extends AlmanacManagementWorkflow {45protected function didConstruct() {6$this7->setName('trust-key')8->setSynopsis(pht('Mark a public key as trusted.'))9->setArguments(10array(11array(12'name' => 'id',13'param' => 'id',14'help' => pht('ID of the key to trust.'),15),16));17}1819public function execute(PhutilArgumentParser $args) {20$console = PhutilConsole::getConsole();2122$id = $args->getArg('id');23if (!$id) {24throw new PhutilArgumentUsageException(25pht('Specify a public key to trust with --id.'));26}2728$key = id(new PhabricatorAuthSSHKeyQuery())29->setViewer($this->getViewer())30->withIDs(array($id))31->executeOne();32if (!$key) {33throw new PhutilArgumentUsageException(34pht('No public key exists with ID "%s".', $id));35}3637if (!$key->getIsActive()) {38throw new PhutilArgumentUsageException(39pht('Public key "%s" is not an active key.', $id));40}4142if ($key->getIsTrusted()) {43throw new PhutilArgumentUsageException(44pht('Public key with ID %s is already trusted.', $id));45}4647if (!($key->getObject() instanceof AlmanacDevice)) {48throw new PhutilArgumentUsageException(49pht('You can only trust keys associated with Almanac devices.'));50}5152$handle = id(new PhabricatorHandleQuery())53->setViewer($this->getViewer())54->withPHIDs(array($key->getObject()->getPHID()))55->executeOne();5657$console->writeOut(58"**<bg:red> %s </bg>**\n\n%s\n\n%s\n\n%s",59pht('IMPORTANT!'),60phutil_console_wrap(61pht(62'Trusting a public key gives anyone holding the corresponding '.63'private key complete, unrestricted access to all data. The '.64'private key will be able to sign requests that bypass policy and '.65'security checks.')),66phutil_console_wrap(67pht(68'This is an advanced feature which should normally be used only '.69'when building a cluster. This feature is very dangerous if '.70'misused.')),71pht('This key is associated with device "%s".', $handle->getName()));7273$prompt = pht(74'Really trust this key?');75if (!phutil_console_confirm($prompt)) {76throw new PhutilArgumentUsageException(77pht('User aborted workflow.'));78}7980$key->setIsTrusted(1);81$key->save();8283PhabricatorAuthSSHKeyQuery::deleteSSHKeyCache();8485$console->writeOut(86"**<bg:green> %s </bg>** %s\n",87pht('TRUSTED'),88pht('Key %s has been marked as trusted.', $id));89}9091}929394