pssht  latest
SSH server library written in PHP
PublicKey.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 
13 
19 {
21  protected $algorithm;
22 
24  protected $key;
25 
27  protected $signature;
28 
29 
46  {
47  if (!is_string($algorithm)) {
48  throw new \InvalidArgumentException();
49  }
50 
51  if (!is_string($key)) {
52  throw new \InvalidArgumentException();
53  }
54 
55  if (!is_string($signature) && $signature !== null) {
56  throw new \InvalidArgumentException();
57  }
58 
59  parent::__construct($user, $service, $method);
60  $this->algorithm = $algorithm;
61  $this->key = $key;
62  $this->signature = $signature;
63  }
64 
65  public function serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
66  {
67  parent::serialize($encoder);
68  $encoder->encodeBoolean($this->signature !== null);
69  $encoder->encodeString($this->algorithm);
70  $encoder->encodeString($this->key);
71  if ($this->signature !== null) {
72  $encoder2 = new \fpoirotte\Pssht\Wire\Encoder();
73  $encoder2->encodeString($this->algorithm);
74  $encoder2->encodeString($this->signature);
75  $encoder->encodeString($encoder2->getBuffer()->get(0));
76  }
77  return $this;
78  }
79 
80  protected static function unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
81  {
82  $signature = $decoder->decodeBoolean();
83  $algorithm = $decoder->decodeString();
84  $res = array(
85  $algorithm,
86  $decoder->decodeString(), // key
87  );
88 
89  if ($signature === true) {
90  $decoder2 = new \fpoirotte\Pssht\Wire\Decoder(
91  new \fpoirotte\Pssht\Buffer($decoder->decodeString())
92  );
93  if ($decoder2->decodeString() !== $algorithm) {
94  throw new \InvalidArgumentException();
95  }
96  $res[] = $decoder2->decodeString();
97  }
98  return $res;
99  }
100 
107  public function getAlgorithm()
108  {
109  return $this->algorithm;
110  }
111 
118  public function getKey()
119  {
120  return $this->key;
121  }
122 
137  public function getSignature()
138  {
139  return $this->signature;
140  }
141 }
$algorithm
Public key algorithm in use (eg. "ssh-rsa" or "ssh-dss").
Definition: PublicKey.php:21
$user
User being authenticated.
Definition: Base.php:22
$signature
Signature to prove key ownership.
Definition: PublicKey.php:27
serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
Definition: PublicKey.php:65
__construct($user, $service, $method, $algorithm, $key, $signature=null)
Definition: PublicKey.php:45
$service
Service to start after authentication.
Definition: Base.php:25