Subversion Repositories oidplus

Rev

Rev 846 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 846 Rev 874
Line 5... Line 5...
5
 *
5
 *
6
 * See PuTTY's SSHPUBK.C and https://tartarus.org/~simon/putty-snapshots/htmldoc/AppendixC.html
6
 * See PuTTY's SSHPUBK.C and https://tartarus.org/~simon/putty-snapshots/htmldoc/AppendixC.html
7
 *
7
 *
8
 * PHP version 5
8
 * PHP version 5
9
 *
9
 *
-
 
10
 * @category  Crypt
-
 
11
 * @package   Common
10
 * @author    Jim Wigginton <terrafrost@php.net>
12
 * @author    Jim Wigginton <terrafrost@php.net>
11
 * @copyright 2016 Jim Wigginton
13
 * @copyright 2016 Jim Wigginton
12
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
14
 * @license   http://www.opensource.org/licenses/mit-license.html  MIT License
13
 * @link      http://phpseclib.sourceforge.net
15
 * @link      http://phpseclib.sourceforge.net
14
 */
16
 */
Line 24... Line 26...
24
use phpseclib3\Exception\UnsupportedAlgorithmException;
26
use phpseclib3\Exception\UnsupportedAlgorithmException;
25
 
27
 
26
/**
28
/**
27
 * PuTTY Formatted Key Handler
29
 * PuTTY Formatted Key Handler
28
 *
30
 *
-
 
31
 * @package Common
29
 * @author  Jim Wigginton <terrafrost@php.net>
32
 * @author  Jim Wigginton <terrafrost@php.net>
-
 
33
 * @access  public
30
 */
34
 */
31
abstract class PuTTY
35
abstract class PuTTY
32
{
36
{
33
    /**
37
    /**
34
     * Default comment
38
     * Default comment
35
     *
39
     *
36
     * @var string
40
     * @var string
-
 
41
     * @access private
37
     */
42
     */
38
    private static $comment = 'phpseclib-generated-key';
43
    private static $comment = 'phpseclib-generated-key';
39
 
44
 
40
    /**
45
    /**
41
     * Default version
46
     * Default version
42
     *
47
     *
43
     * @var int
48
     * @var int
-
 
49
     * @access private
44
     */
50
     */
45
    private static $version = 2;
51
    private static $version = 2;
46
 
52
 
47
    /**
53
    /**
48
     * Sets the default comment
54
     * Sets the default comment
49
     *
55
     *
-
 
56
     * @access public
50
     * @param string $comment
57
     * @param string $comment
51
     */
58
     */
52
    public static function setComment($comment)
59
    public static function setComment($comment)
53
    {
60
    {
54
        self::$comment = str_replace(["\r", "\n"], '', $comment);
61
        self::$comment = str_replace(["\r", "\n"], '', $comment);
55
    }
62
    }
56
 
63
 
57
    /**
64
    /**
58
     * Sets the default version
65
     * Sets the default version
59
     *
66
     *
-
 
67
     * @access public
60
     * @param int $version
68
     * @param int $version
61
     */
69
     */
62
    public static function setVersion($version)
70
    public static function setVersion($version)
63
    {
71
    {
64
        if ($version != 2 && $version != 3) {
72
        if ($version != 2 && $version != 3) {
Line 68... Line 76...
68
    }
76
    }
69
 
77
 
70
    /**
78
    /**
71
     * Generate a symmetric key for PuTTY v2 keys
79
     * Generate a symmetric key for PuTTY v2 keys
72
     *
80
     *
-
 
81
     * @access private
73
     * @param string $password
82
     * @param string $password
74
     * @param int $length
83
     * @param int $length
75
     * @return string
84
     * @return string
76
     */
85
     */
77
    private static function generateV2Key($password, $length)
86
    private static function generateV2Key($password, $length)
Line 86... Line 95...
86
    }
95
    }
87
 
96
 
88
    /**
97
    /**
89
     * Generate a symmetric key for PuTTY v3 keys
98
     * Generate a symmetric key for PuTTY v3 keys
90
     *
99
     *
-
 
100
     * @access private
91
     * @param string $password
101
     * @param string $password
92
     * @param string $flavour
102
     * @param string $flavour
93
     * @param int $memory
103
     * @param int $memory
94
     * @param int $passes
104
     * @param int $passes
95
     * @param string $salt
105
     * @param string $salt
Line 123... Line 133...
123
    }
133
    }
124
 
134
 
125
    /**
135
    /**
126
     * Break a public or private key down into its constituent components
136
     * Break a public or private key down into its constituent components
127
     *
137
     *
-
 
138
     * @access public
128
     * @param string $key
139
     * @param string $key
129
     * @param string $password
140
     * @param string $password
130
     * @return array
141
     * @return array
131
     */
142
     */
132
    public static function load($key, $password)
143
    public static function load($key, $password)
Line 274... Line 285...
274
    }
285
    }
275
 
286
 
276
    /**
287
    /**
277
     * Wrap a private key appropriately
288
     * Wrap a private key appropriately
278
     *
289
     *
-
 
290
     * @access private
279
     * @param string $public
291
     * @param string $public
280
     * @param string $private
292
     * @param string $private
281
     * @param string $type
293
     * @param string $type
282
     * @param string $password
294
     * @param string $password
283
     * @param array $options optional
295
     * @param array $options optional
Line 358... Line 370...
358
    /**
370
    /**
359
     * Wrap a public key appropriately
371
     * Wrap a public key appropriately
360
     *
372
     *
361
     * This is basically the format described in RFC 4716 (https://tools.ietf.org/html/rfc4716)
373
     * This is basically the format described in RFC 4716 (https://tools.ietf.org/html/rfc4716)
362
     *
374
     *
-
 
375
     * @access private
363
     * @param string $key
376
     * @param string $key
364
     * @param string $type
377
     * @param string $type
365
     * @return string
378
     * @return string
366
     */
379
     */
367
    protected static function wrapPublicKey($key, $type)
380
    protected static function wrapPublicKey($key, $type)