ssh_connection.c File Reference

SSH connection protocol. More...

#include "ssh/ssh.h"
#include "ssh/ssh_connection.h"
#include "ssh/ssh_channel.h"
#include "ssh/ssh_packet.h"
#include "ssh/ssh_misc.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   SSH_TRACE_LEVEL
 

Functions

error_t sshSendChannelOpen (SshChannel *channel, const char_t *channelType, const void *channelParams)
 Send SSH_MSG_CHANNEL_OPEN message. More...
 
error_t sshSendChannelOpenConfirmation (SshChannel *channel)
 Send SSH_MSG_CHANNEL_OPEN_CONFIRMATION message. More...
 
error_t sshSendChannelOpenFailure (SshConnection *connection, uint32_t recipientChannel, uint32_t reasonCode, const char_t *description)
 Format SSH_MSG_CHANNEL_OPEN_FAILURE message. More...
 
error_t sshSendChannelWindowAdjust (SshChannel *channel, size_t windowSizeInc)
 Send SSH_MSG_CHANNEL_WINDOW_ADJUST message. More...
 
error_t sshSendChannelData (SshChannel *channel, size_t dataLen)
 Send SSH_MSG_CHANNEL_DATA message. More...
 
error_t sshSendChannelEof (SshChannel *channel)
 Send SSH_MSG_CHANNEL_EOF message. More...
 
error_t sshSendChannelClose (SshChannel *channel)
 Send SSH_MSG_CHANNEL_CLOSE message. More...
 
error_t sshFormatChannelOpen (SshChannel *channel, const char_t *channelType, const void *channelParams, uint8_t *p, size_t *length)
 Format SSH_MSG_CHANNEL_OPEN message. More...
 
error_t sshFormatForwardedTcpIpParams (const SshForwardedTcpIpParams *params, uint8_t *p, size_t *written)
 Format "forwarded-tcpip" channel parameters. More...
 
error_t sshFormatDirectTcpIpParams (const SshDirectTcpIpParams *params, uint8_t *p, size_t *written)
 Format "direct-tcpip" channel parameters. More...
 
error_t sshFormatChannelOpenConfirmation (SshChannel *channel, uint8_t *p, size_t *length)
 Format SSH_MSG_CHANNEL_OPEN_CONFIRMATION message. More...
 
error_t sshFormatChannelOpenFailure (SshConnection *connection, uint32_t recipientChannel, uint32_t reasonCode, const char_t *description, uint8_t *p, size_t *length)
 Format SSH_MSG_CHANNEL_OPEN_FAILURE message. More...
 
error_t sshFormatChannelWindowAdjust (SshChannel *channel, size_t windowSizeInc, uint8_t *p, size_t *length)
 Format SSH_MSG_CHANNEL_WINDOW_ADJUST message. More...
 
error_t sshFormatChannelData (SshChannel *channel, size_t dataLen, uint8_t *p, size_t *length)
 Format SSH_MSG_CHANNEL_DATA message. More...
 
error_t sshFormatChannelEof (SshChannel *channel, uint8_t *p, size_t *length)
 Format SSH_MSG_CHANNEL_EOF message. More...
 
error_t sshFormatChannelClose (SshChannel *channel, uint8_t *p, size_t *length)
 Format SSH_MSG_CHANNEL_CLOSE message. More...
 
error_t sshParseChannelOpen (SshConnection *connection, const uint8_t *message, size_t length)
 Parse SSH_MSG_CHANNEL_OPEN message. More...
 
error_t sshParseForwardedTcpIpParams (const uint8_t *p, size_t length, SshForwardedTcpIpParams *params)
 Parse "forwarded-tcpip" channel parameters. More...
 
error_t sshParseDirectTcpIpParams (const uint8_t *p, size_t length, SshDirectTcpIpParams *params)
 Parse "direct-tcpip" channel parameters. More...
 
error_t sshParseChannelOpenConfirmation (SshConnection *connection, const uint8_t *message, size_t length)
 Parse SSH_MSG_CHANNEL_OPEN_CONFIRMATION message. More...
 
error_t sshParseChannelOpenFailure (SshConnection *connection, const uint8_t *message, size_t length)
 Parse SSH_MSG_CHANNEL_OPEN_FAILURE message. More...
 
error_t sshParseChannelWindowAdjust (SshConnection *connection, const uint8_t *message, size_t length)
 Parse SSH_MSG_CHANNEL_WINDOW_ADJUST message. More...
 
error_t sshParseChannelData (SshConnection *connection, const uint8_t *message, size_t length)
 Parse SSH_MSG_CHANNEL_DATA message. More...
 
error_t sshParseChannelExtendedData (SshConnection *connection, const uint8_t *message, size_t length)
 Parse SSH_MSG_CHANNEL_EXTENDED_DATA message. More...
 
error_t sshParseChannelEof (SshConnection *connection, const uint8_t *message, size_t length)
 Parse SSH_MSG_CHANNEL_EOF message. More...
 
error_t sshParseChannelClose (SshConnection *connection, const uint8_t *message, size_t length)
 Parse SSH_MSG_CHANNEL_CLOSE message. More...
 

Detailed Description

SSH connection protocol.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneSSH Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.0

Definition in file ssh_connection.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   SSH_TRACE_LEVEL

Definition at line 32 of file ssh_connection.c.

Function Documentation

◆ sshFormatChannelClose()

error_t sshFormatChannelClose ( SshChannel channel,
uint8_t *  p,
size_t *  length 
)

Format SSH_MSG_CHANNEL_CLOSE message.

Parameters
[in]channelHandle referencing an SSH channel
[out]pBuffer where to format the message
[out]lengthLength of the resulting message, in bytes
Returns
Error code

Definition at line 835 of file ssh_connection.c.

◆ sshFormatChannelData()

error_t sshFormatChannelData ( SshChannel channel,
size_t  dataLen,
uint8_t *  p,
size_t *  length 
)

Format SSH_MSG_CHANNEL_DATA message.

Parameters
[in]channelHandle referencing an SSH channel
[in]dataLenLength of the payload data, in bytes
[out]pBuffer where to format the message
[out]lengthLength of the resulting message, in bytes
Returns
Error code

Definition at line 734 of file ssh_connection.c.

◆ sshFormatChannelEof()

error_t sshFormatChannelEof ( SshChannel channel,
uint8_t *  p,
size_t *  length 
)

Format SSH_MSG_CHANNEL_EOF message.

Parameters
[in]channelHandle referencing an SSH channel
[out]pBuffer where to format the message
[out]lengthLength of the resulting message, in bytes
Returns
Error code

Definition at line 804 of file ssh_connection.c.

◆ sshFormatChannelOpen()

error_t sshFormatChannelOpen ( SshChannel channel,
const char_t channelType,
const void *  channelParams,
uint8_t *  p,
size_t *  length 
)

Format SSH_MSG_CHANNEL_OPEN message.

Parameters
[in]channelHandle referencing an SSH channel
[in]channelTypeNULL-terminated string containing the channel type
[in]channelParamsPointer to the channel specific parameters
[out]pBuffer where to format the message
[out]lengthLength of the resulting message, in bytes
Returns
Error code

Definition at line 359 of file ssh_connection.c.

◆ sshFormatChannelOpenConfirmation()

error_t sshFormatChannelOpenConfirmation ( SshChannel channel,
uint8_t *  p,
size_t *  length 
)

Format SSH_MSG_CHANNEL_OPEN_CONFIRMATION message.

Parameters
[in]channelHandle referencing an SSH channel
[out]pBuffer where to format the message
[out]lengthLength of the resulting message, in bytes
Returns
Error code

Definition at line 574 of file ssh_connection.c.

◆ sshFormatChannelOpenFailure()

error_t sshFormatChannelOpenFailure ( SshConnection connection,
uint32_t  recipientChannel,
uint32_t  reasonCode,
const char_t description,
uint8_t *  p,
size_t *  length 
)

Format SSH_MSG_CHANNEL_OPEN_FAILURE message.

Parameters
[in]connectionPointer to the SSH connection
[in]recipientChannelChannel number given in the original open request
[in]reasonCodeReason code value
[in]descriptionNULL-terminating description string
[out]pBuffer where to format the message
[out]lengthLength of the resulting message, in bytes
Returns
Error code

Definition at line 630 of file ssh_connection.c.

◆ sshFormatChannelWindowAdjust()

error_t sshFormatChannelWindowAdjust ( SshChannel channel,
size_t  windowSizeInc,
uint8_t *  p,
size_t *  length 
)

Format SSH_MSG_CHANNEL_WINDOW_ADJUST message.

Parameters
[in]channelHandle referencing an SSH channel
[in]windowSizeIncNumber of bytes to add
[out]pBuffer where to format the message
[out]lengthLength of the resulting message, in bytes
Returns
Error code

Definition at line 694 of file ssh_connection.c.

◆ sshFormatDirectTcpIpParams()

error_t sshFormatDirectTcpIpParams ( const SshDirectTcpIpParams params,
uint8_t *  p,
size_t *  written 
)

Format "direct-tcpip" channel parameters.

Parameters
[in]paramsPointer to the channel specific parameters
[out]pOutput stream where to write the channel specific data
[out]writtenTotal number of bytes that have been written
Returns
Error code

Definition at line 509 of file ssh_connection.c.

◆ sshFormatForwardedTcpIpParams()

error_t sshFormatForwardedTcpIpParams ( const SshForwardedTcpIpParams params,
uint8_t *  p,
size_t *  written 
)

Format "forwarded-tcpip" channel parameters.

Parameters
[in]paramsPointer to the channel specific parameters
[out]pOutput stream where to write the channel specific data
[out]writtenTotal number of bytes that have been written
Returns
Error code

Definition at line 448 of file ssh_connection.c.

◆ sshParseChannelClose()

error_t sshParseChannelClose ( SshConnection connection,
const uint8_t *  message,
size_t  length 
)

Parse SSH_MSG_CHANNEL_CLOSE message.

Parameters
[in]connectionPointer to the SSH connection
[in]messagePointer to message
[in]lengthLength of the message, in bytes
Returns
Error code

Definition at line 1830 of file ssh_connection.c.

◆ sshParseChannelData()

error_t sshParseChannelData ( SshConnection connection,
const uint8_t *  message,
size_t  length 
)

Parse SSH_MSG_CHANNEL_DATA message.

Parameters
[in]connectionPointer to the SSH connection
[in]messagePointer to message
[in]lengthLength of the message, in bytes
Returns
Error code

Definition at line 1544 of file ssh_connection.c.

◆ sshParseChannelEof()

error_t sshParseChannelEof ( SshConnection connection,
const uint8_t *  message,
size_t  length 
)

Parse SSH_MSG_CHANNEL_EOF message.

Parameters
[in]connectionPointer to the SSH connection
[in]messagePointer to message
[in]lengthLength of the message, in bytes
Returns
Error code

Definition at line 1747 of file ssh_connection.c.

◆ sshParseChannelExtendedData()

error_t sshParseChannelExtendedData ( SshConnection connection,
const uint8_t *  message,
size_t  length 
)

Parse SSH_MSG_CHANNEL_EXTENDED_DATA message.

Parameters
[in]connectionPointer to the SSH connection
[in]messagePointer to message
[in]lengthLength of the message, in bytes
Returns
Error code

Definition at line 1639 of file ssh_connection.c.

◆ sshParseChannelOpen()

error_t sshParseChannelOpen ( SshConnection connection,
const uint8_t *  message,
size_t  length 
)

Parse SSH_MSG_CHANNEL_OPEN message.

Parameters
[in]connectionPointer to the SSH connection
[in]messagePointer to message
[in]lengthLength of the message, in bytes
Returns
Error code

Definition at line 866 of file ssh_connection.c.

◆ sshParseChannelOpenConfirmation()

error_t sshParseChannelOpenConfirmation ( SshConnection connection,
const uint8_t *  message,
size_t  length 
)

Parse SSH_MSG_CHANNEL_OPEN_CONFIRMATION message.

Parameters
[in]connectionPointer to the SSH connection
[in]messagePointer to message
[in]lengthLength of the message, in bytes
Returns
Error code

Definition at line 1170 of file ssh_connection.c.

◆ sshParseChannelOpenFailure()

error_t sshParseChannelOpenFailure ( SshConnection connection,
const uint8_t *  message,
size_t  length 
)

Parse SSH_MSG_CHANNEL_OPEN_FAILURE message.

Parameters
[in]connectionPointer to the SSH connection
[in]messagePointer to message
[in]lengthLength of the message, in bytes
Returns
Error code

Definition at line 1312 of file ssh_connection.c.

◆ sshParseChannelWindowAdjust()

error_t sshParseChannelWindowAdjust ( SshConnection connection,
const uint8_t *  message,
size_t  length 
)

Parse SSH_MSG_CHANNEL_WINDOW_ADJUST message.

Parameters
[in]connectionPointer to the SSH connection
[in]messagePointer to message
[in]lengthLength of the message, in bytes
Returns
Error code

Definition at line 1436 of file ssh_connection.c.

◆ sshParseDirectTcpIpParams()

error_t sshParseDirectTcpIpParams ( const uint8_t *  p,
size_t  length,
SshDirectTcpIpParams params 
)

Parse "direct-tcpip" channel parameters.

Parameters
[in]pPointer to the channel specific data
[in]lengthLength of the channel specific data, in bytes
[out]paramsInformation resulting from the parsing process
Returns
Error code

Definition at line 1102 of file ssh_connection.c.

◆ sshParseForwardedTcpIpParams()

error_t sshParseForwardedTcpIpParams ( const uint8_t *  p,
size_t  length,
SshForwardedTcpIpParams params 
)

Parse "forwarded-tcpip" channel parameters.

Parameters
[in]pPointer to the channel specific data
[in]lengthLength of the channel specific data, in bytes
[out]paramsInformation resulting from the parsing process
Returns
Error code

Definition at line 1038 of file ssh_connection.c.

◆ sshSendChannelClose()

error_t sshSendChannelClose ( SshChannel channel)

Send SSH_MSG_CHANNEL_CLOSE message.

Parameters
[in]channelHandle referencing an SSH channel
Returns
Error code

Definition at line 302 of file ssh_connection.c.

◆ sshSendChannelData()

error_t sshSendChannelData ( SshChannel channel,
size_t  dataLen 
)

Send SSH_MSG_CHANNEL_DATA message.

Parameters
[in]channelHandle referencing an SSH channel
[in]dataLenLength of the payload data, in bytes
Returns
Error code

Definition at line 218 of file ssh_connection.c.

◆ sshSendChannelEof()

error_t sshSendChannelEof ( SshChannel channel)

Send SSH_MSG_CHANNEL_EOF message.

Parameters
[in]channelHandle referencing an SSH channel
Returns
Error code

Definition at line 256 of file ssh_connection.c.

◆ sshSendChannelOpen()

error_t sshSendChannelOpen ( SshChannel channel,
const char_t channelType,
const void *  channelParams 
)

Send SSH_MSG_CHANNEL_OPEN message.

Parameters
[in]channelHandle referencing an SSH channel
[in]channelTypeNULL-terminated string containing the channel type
[in]channelParamsPointer to the channel specific parameters
Returns
Error code

Definition at line 54 of file ssh_connection.c.

◆ sshSendChannelOpenConfirmation()

error_t sshSendChannelOpenConfirmation ( SshChannel channel)

Send SSH_MSG_CHANNEL_OPEN_CONFIRMATION message.

Parameters
[in]channelHandle referencing an SSH channel
Returns
Error code

Definition at line 94 of file ssh_connection.c.

◆ sshSendChannelOpenFailure()

error_t sshSendChannelOpenFailure ( SshConnection connection,
uint32_t  recipientChannel,
uint32_t  reasonCode,
const char_t description 
)

Format SSH_MSG_CHANNEL_OPEN_FAILURE message.

Parameters
[in]connectionPointer to the SSH connection
[in]recipientChannelChannel number given in the original open request
[in]reasonCodeReason code value
[in]descriptionNULL-terminating description string
Returns
Error code

Definition at line 142 of file ssh_connection.c.

◆ sshSendChannelWindowAdjust()

error_t sshSendChannelWindowAdjust ( SshChannel channel,
size_t  windowSizeInc 
)

Send SSH_MSG_CHANNEL_WINDOW_ADJUST message.

Parameters
[in]channelHandle referencing an SSH channel
[in]windowSizeIncNumber of bytes to add
Returns
Error code

Definition at line 179 of file ssh_connection.c.