pssht  latest
SSH server library written in PHP
fpoirotte\Pssht\Transport Class Reference

Public Member Functions

 __construct (array $serverKeys,\fpoirotte\Pssht\Handlers\SERVICE\REQUEST $authMethods,\fpoirotte\Pssht\Wire\Encoder $encoder=null,\fpoirotte\Pssht\Wire\Decoder $decoder=null, $rekeyingBytes=1073741824, $rekeyingTime=3600)
 
 getAddress ()
 
 getApplicationFactory ()
 
 getBanner ()
 
 getCompressor ()
 
 getDecoder ()
 
 getDecryptor ()
 
 getEncoder ()
 
 getEncryptor ()
 
 getHandler ($type)
 
 getInputMAC ()
 
 getOutputMAC ()
 
 getUncompressor ()
 
 isConnected ()
 
 readMessage ()
 
 setAddress ($address)
 
 setApplicationFactory ($factory)
 
 setBanner ($message)
 
 setCompressor (CompressionInterface $compressor)
 
 setDecryptor (\fpoirotte\Pssht\Encryption\EncryptionInterface $decryptor)
 
 setEncryptor (\fpoirotte\Pssht\Encryption\EncryptionInterface $encryptor)
 
 setHandler ($type,\fpoirotte\Pssht\Handlers\HandlerInterface $handler)
 
 setInputMAC (\fpoirotte\Pssht\MAC\MACInterface $inputMAC)
 
 setOutputMAC (\fpoirotte\Pssht\MAC\MACInterface $outputMAC)
 
 setUncompressor (CompressionInterface $uncompressor)
 
 unsetHandler ($type,\fpoirotte\Pssht\Handlers\HandlerInterface $handler)
 
 updateWriteStats ($written)
 
 writeMessage (\fpoirotte\Pssht\Messages\MessageInterface $message)
 

Protected Attributes

 $address
 Address (ip:port) of the client.
 
 $appFactory
 Factory for the application.
 
 $banner
 SSH banner.
 
 $compressor
 Output compression.
 
 $connected
 Whether this client is still connected or not.
 
 $context
 Context for this SSH connection.
 
 $decoder
 SSH decoder.
 
 $decryptor
 Input cipher.
 
 $encoder
 SSH encoder.
 
 $encryptor
 Output cipher.
 
 $handlers
 Registered handlers for this SSH connection.
 
 $inMAC
 Input MAC.
 
 $inSeqNo
 Input sequence number.
 
 $outMAC
 Output MAC.
 
 $outSeqNo
 Output sequence number.
 
 $rekeyingBytes
 Maximum number of bytes exchanged before rekeying.
 
 $rekeyingTime
 Maximum duration before rekeying.
 
 $uncompressor
 Input compression.
 

Detailed Description

Transport layer for the SSH protocol (RFC 4253).

Definition at line 19 of file Transport.php.

Constructor & Destructor Documentation

fpoirotte\Pssht\Transport::__construct ( array  $serverKeys,
\fpoirotte\Pssht\Handlers\SERVICE\REQUEST  $authMethods,
\fpoirotte\Pssht\Wire\Encoder  $encoder = null,
\fpoirotte\Pssht\Wire\Decoder  $decoder = null,
  $rekeyingBytes = 1073741824,
  $rekeyingTime = 3600 
)

Construct a new SSH transport layer.

Parameters
array$serverKeysKeys presented by the server as an associated array where:
  • keys indicate the key's algorithm (eg. "ssh-dss")
  • values are an associative array with the following keys:
    • "file": a PEM-encoded private key or path to a PEM-encoded private key, in "file:///path/to/key.pem" format
    • "passphrase": (optional) passphrase for the key
fpoirotte::Pssht::Handlers::SERVICE::REQUEST$authMethodsAllowed authentication methods.
fpoirotte::Pssht::Wire::Encoder$encoder(optional) Encoder to use when sending SSH messages. If omitted, a new encoder is automatically created.
fpoirotte::Pssht::Wire::Decoder$decoder(optional) Decoder to use when sending SSH messages. If omitted, a new decoder is automatically created.
int$rekeyingBytes(optional) Maximum number of bytes that may be exchanged before key re-exchange (aka. rekeying) is requested.
int$rekeyingTime(optional) Maximum duration (in seconds) before key re-exchange (aka. rekeying) is requested.
Note
Once this class' constructor has been called, you are advised to call the setAddress() method to register the client's IP address. This is required for some authentication methods to work properly.

Definition at line 113 of file Transport.php.

References fpoirotte\Pssht\Transport\$decoder, fpoirotte\Pssht\Transport\$encoder, fpoirotte\Pssht\Transport\$rekeyingBytes, fpoirotte\Pssht\Transport\$rekeyingTime, fpoirotte\Pssht\Algorithms\factory(), fpoirotte\Pssht\Compression\CompressionInterface\MODE_COMPRESS, and fpoirotte\Pssht\Compression\CompressionInterface\MODE_UNCOMPRESS.

Member Function Documentation

fpoirotte\Pssht\Transport::getAddress ( )

Get the client's IP address.

Return values
stringThe client's IP address, as set.
nullThe client's IP has not been set yet.

Definition at line 253 of file Transport.php.

References fpoirotte\Pssht\Transport\$address.

fpoirotte\Pssht\Transport::getApplicationFactory ( )

Get the factory used to create instances of the application layer.

Return values
callableFactory for the application layer.

Definition at line 503 of file Transport.php.

fpoirotte\Pssht\Transport::getBanner ( )

Get the SSH banner displayed to clients.

Return values
stringSSH banner.
nullNo SSH banner has been set.

Definition at line 532 of file Transport.php.

References fpoirotte\Pssht\Transport\$banner.

fpoirotte\Pssht\Transport::getCompressor ( )

Get the object used to compress outgoing packets.

Return values
fpoirotte::Pssht::Compression::CompressionInterfaceOutgoing packets' compressor.

Definition at line 339 of file Transport.php.

References fpoirotte\Pssht\Transport\$compressor.

fpoirotte\Pssht\Transport::getDecoder ( )

Get the object used to decode incoming packets.

Return values
fpoirotte::Pssht::Wire::DecoderDecoder used for receiving SSH messages.

Definition at line 328 of file Transport.php.

References fpoirotte\Pssht\Transport\$decoder.

fpoirotte\Pssht\Transport::getDecryptor ( )

Get the object used to decrypt incoming packets.

Return values
fpoirotte::Pssht::Encryption::EncryptionInterfaceIncoming packets' decryptor.

Definition at line 425 of file Transport.php.

References fpoirotte\Pssht\Transport\$decryptor.

fpoirotte\Pssht\Transport::getEncoder ( )

Get the object used to encode outgoing packets.

Return values
fpoirotte::Pssht::Wire::EncoderEncoder used for sending SSH messages.

Definition at line 317 of file Transport.php.

References fpoirotte\Pssht\Transport\$encoder.

fpoirotte\Pssht\Transport::getEncryptor ( )

Get the object used to encrypt outgoing packets.

Return values
fpoirotte::Pssht::Encryption::EncryptionInterfaceOutgoing packets' encryptor.

Definition at line 399 of file Transport.php.

References fpoirotte\Pssht\Transport\$encryptor.

fpoirotte\Pssht\Transport::getHandler (   $type)

Retrieve the current handler for a given message type.

Parameters
int$typeMessage type.
Return values
fpoirotte::Pssht::Handlers::HandlerInterfaceHandler associated with the given message type.
nullThere is no handler currently registered for the given message type.

Definition at line 569 of file Transport.php.

fpoirotte\Pssht\Transport::getInputMAC ( )

Get the object used to check integrity of incoming packets.

Return values
fpoirotte::Pssht::MAC::MACInterfaceIncoming packets' MAC checker.

Definition at line 451 of file Transport.php.

References fpoirotte\Pssht\Transport\$inMAC.

fpoirotte\Pssht\Transport::getOutputMAC ( )

Get the object used to check integrity of outgoing packets.

Return values
fpoirotte::Pssht::MAC::MACInterfaceOutgoing packets' MAC generator.

Definition at line 477 of file Transport.php.

References fpoirotte\Pssht\Transport\$outMAC.

fpoirotte\Pssht\Transport::getUncompressor ( )

Get the object used to uncompress incoming packets.

Return values
fpoirotte::Pssht::Compression::CompressionInterfaceIncoming packets' uncompressor.

Definition at line 369 of file Transport.php.

References fpoirotte\Pssht\Transport\$uncompressor.

fpoirotte\Pssht\Transport::readMessage ( )

Try to read and handle a single SSH message.

Return values
booltrue if a message was successfully read and handled, false otherwise.
Note
Depending on the circumstances, messages may be successfully read but left unhandled (eg. because the message was incomplete). In such cases, the message will be reinjected and false returned, making it possible for a future call to this method to handle the (full) message again.

Definition at line 733 of file Transport.php.

References fpoirotte\Pssht\Transport\$decoder, and fpoirotte\Pssht\Transport\writeMessage().

fpoirotte\Pssht\Transport::setAddress (   $address)

Set the IP address of the client associated with this transport layer.

Parameters
string$addressIP address of the client.
Return values
TransportReturns this transport layer.
Note
This method is intended for use with hostbased authentication methods. Moreover, this method may only be called once. Subsequent calls will result in a RuntimeException being raised.

Definition at line 229 of file Transport.php.

References fpoirotte\Pssht\Transport\$address.

fpoirotte\Pssht\Transport::setApplicationFactory (   $factory)

Set the factory to use to create instances of the application layer.

Parameters
callable$factoryFactory for the application layer.
Return values
TransportReturns this transport layer.

Definition at line 517 of file Transport.php.

fpoirotte\Pssht\Transport::setBanner (   $message)

Set the SSH banner presented by the server.

Parameters
string$messageSSH banner to display during connection.
Return values
TransportReturns this transport layer.

Definition at line 546 of file Transport.php.

fpoirotte\Pssht\Transport::setCompressor ( CompressionInterface  $compressor)

Set the object used to compress outgoing packets.

Parameters
fpoirotte::Pssht::Compression::CompressionInterface$compressorOutgoing packets' compressor.
Return values
TransportReturn this transport layer.

Definition at line 353 of file Transport.php.

References fpoirotte\Pssht\Transport\$compressor, fpoirotte\Pssht\Compression\CompressionInterface\getMode(), and fpoirotte\Pssht\Compression\CompressionInterface\MODE_COMPRESS.

fpoirotte\Pssht\Transport::setDecryptor ( \fpoirotte\Pssht\Encryption\EncryptionInterface  $decryptor)

Set the object used to decrypt incoming packets.

Parameters
fpoirotte::Pssht::Encryption::EncryptionInterface$decryptorIncoming packets' decryptor.
Return values
TransportReturn this transport layer.

Definition at line 439 of file Transport.php.

References fpoirotte\Pssht\Transport\$decryptor.

fpoirotte\Pssht\Transport::setEncryptor ( \fpoirotte\Pssht\Encryption\EncryptionInterface  $encryptor)

Set the object used to encrypt outgoing packets.

Parameters
fpoirotte::Pssht::Encryption::EncryptionInterface$encryptorOutgoing packets' encryptor.
Return values
TransportReturn this transport layer.

Definition at line 413 of file Transport.php.

References fpoirotte\Pssht\Transport\$encryptor.

fpoirotte\Pssht\Transport::setHandler (   $type,
\fpoirotte\Pssht\Handlers\HandlerInterface  $handler 
)

Register a handler for a specific SSH message type.

Parameters
int$typeMessage type.
fpoirotte::Pssht::Handlers::HandlerInterface$handlerHandler to register for that message type.
Return values
TransportReturns this transport layer.
Note
The given handler will overwrite any previously registered handler for that message type.

Definition at line 597 of file Transport.php.

fpoirotte\Pssht\Transport::setInputMAC ( \fpoirotte\Pssht\MAC\MACInterface  $inputMAC)

Set the object used to check integrity of incoming packets.

Parameters
fpoirotte::Pssht::MAC::MACInterface$inputMACIncoming packets' MAC checker.
Return values
TransportReturn this transport layer.

Definition at line 465 of file Transport.php.

fpoirotte\Pssht\Transport::setOutputMAC ( \fpoirotte\Pssht\MAC\MACInterface  $outputMAC)

Set the object used to generate MACs for outgoing packets.

Parameters
fpoirotte::Pssht::MAC::MACInterface$outputMACOutgoing packets' MAC generator.
Return values
TransportReturn this transport layer.

Definition at line 491 of file Transport.php.

fpoirotte\Pssht\Transport::setUncompressor ( CompressionInterface  $uncompressor)

Set the object used to uncompress incoming packets.

Parameters
fpoirotte::Pssht::Compression::CompressionInterface$uncompressorIncoming packets' uncompressor.
Return values
TransportReturn this transport layer.

Definition at line 383 of file Transport.php.

References fpoirotte\Pssht\Transport\$uncompressor, fpoirotte\Pssht\Compression\CompressionInterface\getMode(), and fpoirotte\Pssht\Compression\CompressionInterface\MODE_UNCOMPRESS.

fpoirotte\Pssht\Transport::unsetHandler (   $type,
\fpoirotte\Pssht\Handlers\HandlerInterface  $handler 
)

Unregister a handler for a specific SSH message type.

Parameters
int$typeMessage type.
fpoirotte::Pssht::Handlers::HandlerInterface$handlerHandler to unregister for that message type.
Return values
TransportReturns this transport layer.

Definition at line 619 of file Transport.php.

fpoirotte\Pssht\Transport::updateWriteStats (   $written)

Update statistics about the number of bytes written to the client.

Parameters
int$writtenNumber of additional bytes written.
Returns
This method does not return anything.

Definition at line 268 of file Transport.php.

References fpoirotte\Pssht\Transport\$connected, and fpoirotte\Pssht\Transport\$rekeyingTime.

fpoirotte\Pssht\Transport::writeMessage ( \fpoirotte\Pssht\Messages\MessageInterface  $message)

Write an SSH message into the output buffer.

Parameters
fpoirotte::Pssht::Messages::MessageInterface$messageMessage to write into the output buffer.
Return values
TransportReturns this transport layer.

Definition at line 640 of file Transport.php.

References fpoirotte\Pssht\Transport\$encoder.

Referenced by fpoirotte\Pssht\Transport\readMessage().


The documentation for this class was generated from the following file: