Changeset View
Changeset View
Standalone View
Standalone View
scripts/ssh/ssh-auth.php
Show All 30 Lines | |||||
// the path on disk to "ssh-exec" is arbitrarily mutable at runtime. See T12397. | // the path on disk to "ssh-exec" is arbitrarily mutable at runtime. See T12397. | ||||
$cache = PhabricatorCaches::getMutableCache(); | $cache = PhabricatorCaches::getMutableCache(); | ||||
$authstruct_key = PhabricatorAuthSSHKeyQuery::AUTHSTRUCT_CACHEKEY; | $authstruct_key = PhabricatorAuthSSHKeyQuery::AUTHSTRUCT_CACHEKEY; | ||||
$authstruct_raw = $cache->getKey($authstruct_key); | $authstruct_raw = $cache->getKey($authstruct_key); | ||||
$authstruct = null; | $authstruct = null; | ||||
if (strlen($authstruct_raw)) { | if (phutil_nonempty_string($authstruct_raw)) { | ||||
try { | try { | ||||
$authstruct = phutil_json_decode($authstruct_raw); | $authstruct = phutil_json_decode($authstruct_raw); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
// Ignore any issues with the cached data; we'll just rebuild the | // Ignore any issues with the cached data; we'll just rebuild the | ||||
// structure below. | // structure below. | ||||
} | } | ||||
} | } | ||||
Show All 29 Lines | foreach ($keys as $ssh_key) { | ||||
} | } | ||||
$key_argv[] = '--phabricator-ssh-key'; | $key_argv[] = '--phabricator-ssh-key'; | ||||
$key_argv[] = $ssh_key->getID(); | $key_argv[] = $ssh_key->getID(); | ||||
// Strip out newlines and other nonsense from the key type and key body. | // Strip out newlines and other nonsense from the key type and key body. | ||||
$type = $ssh_key->getKeyType(); | $type = $ssh_key->getKeyType(); | ||||
$type = preg_replace('@[\x00-\x20]+@', '', $type); | $type = preg_replace('@[\x00-\x20]+@', '', $type); | ||||
if (!strlen($type)) { | if (!phutil_nonempty_string($type)) { | ||||
continue; | continue; | ||||
} | } | ||||
$key = $ssh_key->getKeyBody(); | $key = $ssh_key->getKeyBody(); | ||||
$key = preg_replace('@[\x00-\x20]+@', '', $key); | $key = preg_replace('@[\x00-\x20]+@', '', $key); | ||||
if (!strlen($key)) { | if (!phutil_nonempty_string($key)) { | ||||
continue; | continue; | ||||
} | } | ||||
$key_list[] = array( | $key_list[] = array( | ||||
'argv' => $key_argv, | 'argv' => $key_argv, | ||||
'type' => $type, | 'type' => $type, | ||||
'key' => $key, | 'key' => $key, | ||||
); | ); | ||||
Show All 30 Lines | |||||
$lines = array(); | $lines = array(); | ||||
foreach ($authstruct['keys'] as $key_struct) { | foreach ($authstruct['keys'] as $key_struct) { | ||||
$key_argv = $key_struct['argv']; | $key_argv = $key_struct['argv']; | ||||
$key = $key_struct['key']; | $key = $key_struct['key']; | ||||
$type = $key_struct['type']; | $type = $key_struct['type']; | ||||
$cmd = csprintf('%s %Ls', $bin, $key_argv); | $cmd = csprintf('%s %Ls', $bin, $key_argv); | ||||
if (strlen($instance)) { | if (phutil_nonempty_string($instance)) { | ||||
$cmd = csprintf('PHABRICATOR_INSTANCE=%s %C', $instance, $cmd); | $cmd = csprintf('PHABRICATOR_INSTANCE=%s %C', $instance, $cmd); | ||||
} | } | ||||
// This is additional escaping for the SSH 'command="..."' string. | // This is additional escaping for the SSH 'command="..."' string. | ||||
$cmd = addcslashes($cmd, '"\\'); | $cmd = addcslashes($cmd, '"\\'); | ||||
$options = array( | $options = array( | ||||
'command="'.$cmd.'"', | 'command="'.$cmd.'"', | ||||
Show All 15 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0