PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.23.3
JetBackup – Backup, Restore & Migrate v3.1.23.3
3.1.23.3 3.1.22.4 3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / 3rdparty / phpseclib3 / Crypt / DSA / Formats / Keys / OpenSSH.php
backup / src / JetBackup / 3rdparty / phpseclib3 / Crypt / DSA / Formats / Keys Last commit date
.htaccess 1 year ago OpenSSH.php 1 year ago PKCS1.php 1 year ago PKCS8.php 1 year ago PuTTY.php 1 year ago Raw.php 1 year ago XML.php 1 year ago index.html 1 year ago web.config 1 year ago
OpenSSH.php
107 lines
1 <?php
2
3 /**
4 * OpenSSH Formatted DSA Key Handler
5 *
6 * PHP version 5
7 *
8 * Place in $HOME/.ssh/authorized_keys
9 *
10 * @author Jim Wigginton <terrafrost@php.net>
11 * @copyright 2015 Jim Wigginton
12 * @license http://www.opensource.org/licenses/mit-license.html MIT License
13 * @link http://phpseclib.sourceforge.net
14 */
15
16 declare(strict_types=1);
17
18 namespace phpseclib3\Crypt\DSA\Formats\Keys;
19
20 use phpseclib3\Common\Functions\Strings;
21 use phpseclib3\Crypt\Common\Formats\Keys\OpenSSH as Progenitor;
22 use phpseclib3\Exception\InvalidArgumentException;
23 use phpseclib3\Exception\RuntimeException;
24 use phpseclib3\Math\BigInteger;
25
26 /**
27 * OpenSSH Formatted DSA Key Handler
28 *
29 * @author Jim Wigginton <terrafrost@php.net>
30 */
31 abstract class OpenSSH extends Progenitor
32 {
33 /**
34 * Supported Key Types
35 *
36 * @var array
37 */
38 protected static $types = ['ssh-dss'];
39
40 /**
41 * Break a public or private key down into its constituent components
42 *
43 * @param string|array $key
44 */
45 public static function load($key, ?string $password = null): array
46 {
47 $parsed = parent::load($key, $password);
48
49 if (isset($parsed['paddedKey'])) {
50 [$type] = Strings::unpackSSH2('s', $parsed['paddedKey']);
51 if ($type != $parsed['type']) {
52 throw new RuntimeException("The public and private keys are not of the same type ($type vs $parsed[type])");
53 }
54
55 [$p, $q, $g, $y, $x, $comment] = Strings::unpackSSH2('i5s', $parsed['paddedKey']);
56
57 return compact('p', 'q', 'g', 'y', 'x', 'comment');
58 }
59
60 [$p, $q, $g, $y] = Strings::unpackSSH2('iiii', $parsed['publicKey']);
61
62 $comment = $parsed['comment'];
63
64 return compact('p', 'q', 'g', 'y', 'comment');
65 }
66
67 /**
68 * Convert a public key to the appropriate format
69 *
70 * @param array $options optional
71 */
72 public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, array $options = []): string
73 {
74 if ($q->getLength() != 160) {
75 throw new InvalidArgumentException('SSH only supports keys with an N (length of Group Order q) of 160');
76 }
77
78 // from <http://tools.ietf.org/html/rfc4253#page-15>:
79 // string "ssh-dss"
80 // mpint p
81 // mpint q
82 // mpint g
83 // mpint y
84 $DSAPublicKey = Strings::packSSH2('siiii', 'ssh-dss', $p, $q, $g, $y);
85
86 if ($options['binary'] ?? self::$binary) {
87 return $DSAPublicKey;
88 }
89
90 $comment = $options['comment'] ?? self::$comment;
91 $DSAPublicKey = 'ssh-dss ' . base64_encode($DSAPublicKey) . ' ' . $comment;
92
93 return $DSAPublicKey;
94 }
95
96 /**
97 * Convert a private key to the appropriate format.
98 */
99 public static function savePrivateKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, BigInteger $x, ?string $password = null, array $options = []): string
100 {
101 $publicKey = self::savePublicKey($p, $q, $g, $y, ['binary' => true]);
102 $privateKey = Strings::packSSH2('si5', 'ssh-dss', $p, $q, $g, $y, $x);
103
104 return self::wrapPrivateKey($publicKey, $privateKey, $password, $options);
105 }
106 }
107