Path: blob/master/src/applications/passphrase/keys/PassphraseSSHKey.php
12256 views
<?php12final class PassphraseSSHKey extends PassphraseAbstractKey {34private $keyFile;56public static function loadFromPHID($phid, PhabricatorUser $viewer) {7$key = new PassphraseSSHKey();8return $key->loadAndValidateFromPHID(9$phid,10$viewer,11PassphraseSSHPrivateKeyCredentialType::PROVIDES_TYPE);12}1314public function getKeyfileEnvelope() {15$credential = $this->requireCredential();1617$file_type = PassphraseSSHPrivateKeyFileCredentialType::CREDENTIAL_TYPE;18if ($credential->getCredentialType() != $file_type) {19// If the credential does not store a file, write the key text out to a20// temporary file so we can pass it to `ssh`.21if (!$this->keyFile) {22$secret = $credential->getSecret();23if (!$secret) {24throw new Exception(25pht(26'Attempting to use a credential ("%s") but the credential '.27'secret has been destroyed!',28$credential->getMonogram()));29}3031$temporary_file = new TempFile('passphrase-ssh-key');32Filesystem::changePermissions($temporary_file, 0600);33Filesystem::writeFile($temporary_file, $secret->openEnvelope());3435$this->keyFile = $temporary_file;36}3738return new PhutilOpaqueEnvelope((string)$this->keyFile);39}4041return $credential->getSecret();42}4344}454647