PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.23.3
JetBackup – Backup, Restore & Migrate v3.1.23.3
3.1.23.5 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 / PuTTY.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
PuTTY.php
98 lines
1 <?php
2
3 /**
4 * PuTTY Formatted DSA Key Handler
5 *
6 * puttygen does not generate DSA keys with an N of anything other than 160, however,
7 * it can still load them and convert them. PuTTY will load them, too, but SSH servers
8 * won't accept them. Since PuTTY formatted keys are primarily used with SSH this makes
9 * keys with N > 160 kinda useless, hence this handlers not supporting such keys.
10 *
11 * PHP version 5
12 *
13 * @author Jim Wigginton <terrafrost@php.net>
14 * @copyright 2015 Jim Wigginton
15 * @license http://www.opensource.org/licenses/mit-license.html MIT License
16 * @link http://phpseclib.sourceforge.net
17 */
18
19 declare(strict_types=1);
20
21 namespace phpseclib3\Crypt\DSA\Formats\Keys;
22
23 use phpseclib3\Common\Functions\Strings;
24 use phpseclib3\Crypt\Common\Formats\Keys\PuTTY as Progenitor;
25 use phpseclib3\Exception\InvalidArgumentException;
26 use phpseclib3\Math\BigInteger;
27
28 /**
29 * PuTTY Formatted DSA Key Handler
30 *
31 * @author Jim Wigginton <terrafrost@php.net>
32 */
33 abstract class PuTTY extends Progenitor
34 {
35 /**
36 * Public Handler
37 *
38 * @var string
39 */
40 public const PUBLIC_HANDLER = 'phpseclib3\Crypt\DSA\Formats\Keys\OpenSSH';
41
42 /**
43 * Algorithm Identifier
44 *
45 * @var array
46 */
47 protected static $types = ['ssh-dss'];
48
49 /**
50 * Break a public or private key down into its constituent components
51 *
52 * @param array|string $key
53 * @param string|false $password
54 * @return array|false
55 */
56 public static function load($key, $password)
57 {
58 $components = parent::load($key, $password);
59 if (!isset($components['private'])) {
60 return $components;
61 }
62 extract($components);
63 unset($components['public'], $components['private']);
64
65 [$p, $q, $g, $y] = Strings::unpackSSH2('iiii', $public);
66 [$x] = Strings::unpackSSH2('i', $private);
67
68 return compact('p', 'q', 'g', 'y', 'x', 'comment');
69 }
70
71 /**
72 * Convert a private key to the appropriate format.
73 */
74 public static function savePrivateKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, BigInteger $x, ?string $password = null, array $options = []): string
75 {
76 if ($q->getLength() != 160) {
77 throw new InvalidArgumentException('SSH only supports keys with an N (length of Group Order q) of 160');
78 }
79
80 $public = Strings::packSSH2('iiii', $p, $q, $g, $y);
81 $private = Strings::packSSH2('i', $x);
82
83 return self::wrapPrivateKey($public, $private, 'ssh-dss', $password, $options);
84 }
85
86 /**
87 * Convert a public key to the appropriate format
88 */
89 public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y): string
90 {
91 if ($q->getLength() != 160) {
92 throw new InvalidArgumentException('SSH only supports keys with an N (length of Group Order q) of 160');
93 }
94
95 return self::wrapPublicKey(Strings::packSSH2('iiii', $p, $q, $g, $y), 'ssh-dss');
96 }
97 }
98