Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/revoker/PhabricatorAuthSSHRevoker.php
12256 views
1
<?php
2
3
final class PhabricatorAuthSSHRevoker
4
extends PhabricatorAuthRevoker {
5
6
const REVOKERKEY = 'ssh';
7
8
public function getRevokerName() {
9
return pht('SSH Keys');
10
}
11
12
public function getRevokerDescription() {
13
return pht(
14
"Revokes all SSH public keys.\n\n".
15
"SSH public keys are revoked, not just removed. Users will need to ".
16
"generate and upload new, unique keys before they can access ".
17
"repositories or other services over SSH.");
18
}
19
20
public function revokeAllCredentials() {
21
$query = new PhabricatorAuthSSHKeyQuery();
22
return $this->revokeWithQuery($query);
23
}
24
25
public function revokeCredentialsFrom($object) {
26
$query = id(new PhabricatorAuthSSHKeyQuery())
27
->withObjectPHIDs(array($object->getPHID()));
28
29
return $this->revokeWithQuery($query);
30
}
31
32
private function revokeWithQuery(PhabricatorAuthSSHKeyQuery $query) {
33
$viewer = $this->getViewer();
34
35
// We're only going to revoke keys which have not already been revoked.
36
37
$ssh_keys = $query
38
->setViewer($viewer)
39
->withIsActive(true)
40
->execute();
41
42
$content_source = PhabricatorContentSource::newForSource(
43
PhabricatorDaemonContentSource::SOURCECONST);
44
45
$auth_phid = id(new PhabricatorAuthApplication())->getPHID();
46
foreach ($ssh_keys as $ssh_key) {
47
$xactions = array();
48
$xactions[] = $ssh_key->getApplicationTransactionTemplate()
49
->setTransactionType(PhabricatorAuthSSHKeyTransaction::TYPE_DEACTIVATE)
50
->setNewValue(1);
51
52
$editor = $ssh_key->getApplicationTransactionEditor()
53
->setActor($viewer)
54
->setActingAsPHID($auth_phid)
55
->setContinueOnNoEffect(true)
56
->setContinueOnMissingFields(true)
57
->setContentSource($content_source)
58
->setIsAdministrativeEdit(true)
59
->applyTransactions($ssh_key, $xactions);
60
}
61
62
return count($ssh_keys);
63
}
64
65
}
66
67