@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorSSHKeyGenerator extends Phobject {
4
5 public static function assertCanGenerateKeypair() {
6 $binary = 'ssh-keygen';
7 if (!Filesystem::resolveBinary($binary)) {
8 throw new Exception(
9 pht(
10 'Can not generate keys: unable to find "%s" in PATH!',
11 $binary));
12 }
13 }
14
15 public static function generateKeypair() {
16 self::assertCanGenerateKeypair();
17
18 $tempfile = new TempFile();
19 $keyfile = dirname($tempfile).DIRECTORY_SEPARATOR.'keytext';
20
21 execx(
22 'ssh-keygen -t rsa -N %s -f %s',
23 '',
24 $keyfile);
25
26 $public_key = Filesystem::readFile($keyfile.'.pub');
27 $private_key = Filesystem::readFile($keyfile);
28
29 return array($public_key, $private_key);
30 }
31
32}