pssht  latest
SSH server library written in PHP
HostBased.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 $hostname;
28 
30  protected $remoteUser;
31 
33  protected $signature;
34 
35 
54  public function __construct(
55  $user,
56  $service,
57  $method,
58  $algorithm,
59  $key,
60  $hostname,
63  ) {
64  if (!is_string($algorithm)) {
65  throw new \InvalidArgumentException();
66  }
67 
68  if (!is_string($key)) {
69  throw new \InvalidArgumentException();
70  }
71 
72  if (!is_string($hostname)) {
73  throw new \InvalidArgumentException();
74  }
75 
76  if (!is_string($remoteUser)) {
77  throw new \InvalidArgumentException();
78  }
79 
80  if (!is_string($signature)) {
81  throw new \InvalidArgumentException();
82  }
83 
84  parent::__construct($user, $service, $method);
85  $this->algorithm = $algorithm;
86  $this->key = $key;
87  $this->hostname = $hostname;
88  $this->remoteUser = $remoteUser;
89  $this->signature = $signature;
90  }
91 
92  public function serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
93  {
94  parent::serialize($encoder);
95  $encoder->encodeString($this->algorithm);
96  $encoder->encodeString($this->key);
97  $encoder->encodeString($this->hostname);
98  $encoder->encodeString($this->remoteUser);
99 
100  // Special handling of the signature.
101  $encoder2 = new \fpoirotte\Pssht\Wire\Encoder();
102  $encoder2->encodeString($this->algorithm);
103  $encoder2->encodeString($this->signature);
104  $encoder->encodeString($encoder2->getBuffer()->get(0));
105 
106  return $this;
107  }
108 
109  protected static function unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder)
110  {
111  $algorithm = $decoder->decodeString();
112  $res = array(
113  $algorithm,
114  $decoder->decodeString(),
115  $decoder->decodeString(),
116  $decoder->decodeString(),
117  );
118 
119  // Special handling for signature.
120  $decoder2 = new \fpoirotte\Pssht\Wire\Decoder(
121  new \fpoirotte\Pssht\Buffer($decoder->decodeString())
122  );
123  if ($decoder2->decodeString() !== $algorithm) {
124  throw new \InvalidArgumentException();
125  }
126  $res[] = $decoder2->decodeString();
127 
128  return $res;
129  }
130 
137  public function getAlgorithm()
138  {
139  return $this->algorithm;
140  }
141 
148  public function getKey()
149  {
150  return $this->key;
151  }
152 
160  public function getHostname()
161  {
162  return $this->hostname;
163  }
164 
171  public function getRemoteUser()
172  {
173  return $this->remoteUser;
174  }
175 
182  public function getSignature()
183  {
184  return $this->signature;
185  }
186 }
serialize(\fpoirotte\Pssht\Wire\Encoder $encoder)
Definition: HostBased.php:92
$algorithm
Public key algorithm in use (eg. "ssh-rsa" or "ssh-dss").
Definition: HostBased.php:21
$user
User being authenticated.
Definition: Base.php:22
__construct($user, $service, $method, $algorithm, $key, $hostname, $remoteUser, $signature)
Definition: HostBased.php:54
$signature
Signature to prove key ownership.
Definition: HostBased.php:33
$service
Service to start after authentication.
Definition: Base.php:25