pssht  latest
SSH server library written in PHP
KEXINIT.php
1 <?php
2 
3 /*
4 * This file is part of pssht.
5 *
6 * (c) François Poirotte <clicky@erebot.net>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 
12 namespace fpoirotte\Pssht\Messages;
13 
17 class KEXINIT implements MessageInterface
18 {
20  protected $cookie;
21 
23  protected $kexAlgos;
24 
27 
29  protected $encAlgosC2S;
30 
32  protected $encAlgosS2C;
33 
35  protected $MACAlgosC2S;
36 
38  protected $MACAlgosS2C;
39 
41  protected $compAlgosC2S;
42 
44  protected $compAlgosS2C;
45 
47  protected $langC2S;
48 
50  protected $langS2C;
51 
53  protected $firstKexPacket;
54 
55 
106  public function __construct(
107  \fpoirotte\Pssht\Random\RandomInterface $rng,
108  array $kexAlgos,
109  array $serverHostKeyAlgos,
110  array $encAlgosC2S,
111  array $encAlgosS2C,
112  array $macAlgosC2S,
113  array $macAlgosS2C,
114  array $compAlgosC2S,
115  array $compAlgosS2C,
116  array $langC2S = array(),
117  array $langS2C = array(),
118  $firstKexPacket = false
119  ) {
120  if (!is_bool($firstKexPacket)) {
121  throw new \InvalidArgumentException();
122  }
123 
124  $this->cookie = $rng->getBytes(16);
125  $this->kexAlgos = $kexAlgos;
126  $this->serverHostKeyAlgos = $serverHostKeyAlgos;
127  $this->encAlgosC2S = $encAlgosC2S;
128  $this->encAlgosS2C = $encAlgosS2C;
129  $this->macAlgosC2S = $macAlgosC2S;
130  $this->macAlgosS2C = $macAlgosS2C;
131  $this->compAlgosC2S = $compAlgosC2S;
132  $this->compAlgosS2C = $compAlgosS2C;
133  $this->langC2S = $langC2S;
134  $this->langS2C = $langS2C;
135  $this->firstKexPacket = $firstKexPacket;
136  }
137 
138  public static function getMessageId()
139  {
140  return 20;
141  }
142 
143  public function serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
144  {
145  $encoder->encodeBytes($this->cookie);
146  $encoder->encodeNameList($this->kexAlgos);
147  $encoder->encodeNameList($this->serverHostKeyAlgos);
148  $encoder->encodeNameList($this->encAlgosC2S);
149  $encoder->encodeNameList($this->encAlgosS2C);
150  $encoder->encodeNameList($this->macAlgosC2S);
151  $encoder->encodeNameList($this->macAlgosS2C);
152  $encoder->encodeNameList($this->compAlgosC2S);
153  $encoder->encodeNameList($this->compAlgosS2C);
154  $encoder->encodeNameList($this->langC2S);
155  $encoder->encodeNameList($this->langS2C);
156  $encoder->encodeBoolean($this->firstKexPacket);
157  $encoder->encodeUint32(0); // Reserved for future extension.
158  return $this;
159  }
160 
161  public static function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
162  {
163  $res = new static(
164  new \fpoirotte\Pssht\Random\Fixed(
165  $decoder->decodeBytes(16) // cookie
166  ),
167  $decoder->decodeNameList(), // keyAlgos
168  $decoder->decodeNameList(), // serverHostKeyAlgos
169  $decoder->decodeNameList(), // encAlgosC2S
170  $decoder->decodeNameList(), // encAlgosS2C
171  $decoder->decodeNameList(), // macAlgosC2S
172  $decoder->decodeNameList(), // macAlgosS2C
173  $decoder->decodeNameList(), // compAlgosC2S
174  $decoder->decodeNameList(), // compAlgosS2C
175  $decoder->decodeNameList(), // langC2S
176  $decoder->decodeNameList(), // langS2C
177  $decoder->decodeBoolean() // firstKexPacket
178  );
179  $decoder->decodeUint32(); // Reserved
180  return $res;
181  }
182 
189  public function getKEXAlgos()
190  {
191  return $this->kexAlgos;
192  }
193 
200  public function getServerHostKeyAlgos()
201  {
203  }
204 
212  public function getC2SEncryptionAlgos()
213  {
214  return $this->encAlgosC2S;
215  }
216 
224  public function getC2SMACAlgos()
225  {
226  return $this->macAlgosC2S;
227  }
228 
236  public function getC2SCompressionAlgos()
237  {
238  return $this->compAlgosC2S;
239  }
240 
248  public function getS2CEncryptionAlgos()
249  {
250  return $this->encAlgosS2C;
251  }
252 
260  public function getS2CMACAlgos()
261  {
262  return $this->macAlgosS2C;
263  }
264 
272  public function getS2CCompressionAlgos()
273  {
274  return $this->compAlgosS2C;
275  }
276 }
serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
Definition: KEXINIT.php:143
$langC2S
Supported languages (client to server) in RFC 3066 format.
Definition: KEXINIT.php:47
static unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder)
Definition: KEXINIT.php:161
$MACAlgosS2C
Supported MAC algorithms (server to client).
Definition: KEXINIT.php:38
$serverHostKeyAlgos
Supported server host key algorithms.
Definition: KEXINIT.php:26
$compAlgosC2S
Supported compression algorithms (client to server).
Definition: KEXINIT.php:41
$encAlgosC2S
Supported encryption algorithms (client to server).
Definition: KEXINIT.php:29
$firstKexPacket
Indicates whether a KEX packet was sent right after this one.
Definition: KEXINIT.php:53
$kexAlgos
Supported key exchange algorithms.
Definition: KEXINIT.php:23
$langS2C
Supported languages (server to client) in RFC 3066 format.
Definition: KEXINIT.php:50
$compAlgosS2C
Supported compression algorithms (server to client).
Definition: KEXINIT.php:44
__construct(\fpoirotte\Pssht\Random\RandomInterface $rng, array $kexAlgos, array $serverHostKeyAlgos, array $encAlgosC2S, array $encAlgosS2C, array $macAlgosC2S, array $macAlgosS2C, array $compAlgosC2S, array $compAlgosS2C, array $langC2S=array(), array $langS2C=array(), $firstKexPacket=false)
Definition: KEXINIT.php:106
$encAlgosS2C
Supported encryption algorithms (server to client).
Definition: KEXINIT.php:32
$cookie
Random cookie for the Key Exchange.
Definition: KEXINIT.php:20
$MACAlgosC2S
Supported MAC algorithms (client to server).
Definition: KEXINIT.php:35