[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/passphrase/keys/ -> PassphraseSSHKey.php (source)

   1  <?php
   2  
   3  final class PassphraseSSHKey extends PassphraseAbstractKey {
   4  
   5    private $keyFile;
   6  
   7    public static function loadFromPHID($phid, PhabricatorUser $viewer) {
   8      $key = new PassphraseSSHKey();
   9      return $key->loadAndValidateFromPHID(
  10        $phid,
  11        $viewer,
  12        PassphraseCredentialTypeSSHPrivateKey::PROVIDES_TYPE);
  13    }
  14  
  15    public function getKeyfileEnvelope() {
  16      $credential = $this->requireCredential();
  17  
  18      $file_type = PassphraseCredentialTypeSSHPrivateKeyFile::CREDENTIAL_TYPE;
  19      if ($credential->getCredentialType() != $file_type) {
  20        // If the credential does not store a file, write the key text out to a
  21        // temporary file so we can pass it to `ssh`.
  22        if (!$this->keyFile) {
  23          $secret = $credential->getSecret();
  24          if (!$secret) {
  25            throw new Exception(
  26              pht(
  27                'Attempting to use a credential ("%s") but the credential '.
  28                'secret has been destroyed!',
  29                $credential->getMonogram()));
  30          }
  31  
  32          $temporary_file = new TempFile('passphrase-ssh-key');
  33          Filesystem::changePermissions($temporary_file, 0600);
  34          Filesystem::writeFile($temporary_file, $secret->openEnvelope());
  35  
  36          $this->keyFile = $temporary_file;
  37        }
  38  
  39        return new PhutilOpaqueEnvelope((string)$this->keyFile);
  40      }
  41  
  42      return $credential->getSecret();
  43    }
  44  
  45  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1