SSH helper functions. More...
#include "ssh/ssh.h"
#include "ssh/ssh_algorithms.h"
#include "ssh/ssh_extensions.h"
#include "ssh/ssh_transport.h"
#include "ssh/ssh_kex.h"
#include "ssh/ssh_kex_rsa.h"
#include "ssh/ssh_kex_dh.h"
#include "ssh/ssh_kex_dh_gex.h"
#include "ssh/ssh_kex_ecdh.h"
#include "ssh/ssh_kex_hybrid.h"
#include "ssh/ssh_auth.h"
#include "ssh/ssh_channel.h"
#include "ssh/ssh_packet.h"
#include "ssh/ssh_key_material.h"
#include "ssh/ssh_key_import.h"
#include "ssh/ssh_key_format.h"
#include "ssh/ssh_cert_import.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 | |
SshConnection * | sshOpenConnection (SshContext *context, Socket *socket) |
Open a new SSH connection. More... | |
void | sshCloseConnection (SshConnection *connection) |
Close SSH connection. More... | |
void | sshRegisterConnectionEvents (SshContext *context, SshConnection *connection, SocketEventDesc *eventDesc) |
Register connection events. More... | |
error_t | sshProcessConnectionEvents (SshContext *context, SshConnection *connection) |
Connection event handler. More... | |
void | sshRegisterUserEvents (SshChannel *channel, OsEvent *event, uint_t eventMask) |
Subscribe to the specified channel events. More... | |
void | sshUnregisterUserEvents (SshChannel *channel) |
Unsubscribe previously registered events. More... | |
uint_t | sshGetUserEvents (SshChannel *channel) |
Retrieve event flags for a specified channel. More... | |
void | sshNotifyEvent (SshContext *context) |
Notify the SSH context that event is occurring. More... | |
SshHostKey * | sshGetHostKey (SshConnection *connection) |
Get the currently selected host key. More... | |
int_t | sshSelectHostKey (SshContext *context, const char_t *hostKeyAlgo) |
Select a host key that matches then specified algorithm. More... | |
int_t | sshSelectNextHostKey (SshConnection *connection) |
Select the next acceptable host key. More... | |
error_t | sshFormatHostKey (SshConnection *connection, uint8_t *p, size_t *written) |
Format host key structure. More... | |
const EcCurveInfo * | sshGetCurveInfo (const SshString *keyFormatId, const SshString *curveName) |
Get the elliptic curve that matches the specified key format identifier. More... | |
error_t | sshParseString (const uint8_t *p, size_t length, SshString *string) |
Parse a string. More... | |
error_t | sshParseBinaryString (const uint8_t *p, size_t length, SshBinaryString *string) |
Parse a binary string. More... | |
error_t | sshParseNameList (const uint8_t *p, size_t length, SshNameList *nameList) |
Parse a comma-separated list of names. More... | |
int_t | sshFindName (const SshNameList *nameList, const char_t *name) |
Search a name list for a given name. More... | |
bool_t | sshGetName (const SshNameList *nameList, uint_t index, SshString *name) |
Get the element at specified index. More... | |
error_t | sshFormatString (const char_t *value, uint8_t *p, size_t *written) |
Format a string. More... | |
error_t | sshFormatBinaryString (const void *value, size_t valueLen, uint8_t *p, size_t *written) |
Format a binary string. More... | |
error_t | sshFormatNameList (const char_t *const nameList[], uint_t nameListLen, uint8_t *p, size_t *written) |
Format a comma-separated list of names. More... | |
error_t | sshFormatMpint (const Mpi *value, uint8_t *p, size_t *written) |
Format a multiple precision integer. More... | |
error_t | sshConvertArrayToMpint (const uint8_t *value, size_t length, uint8_t *p, size_t *written) |
Convert a binary string to mpint representation. More... | |
bool_t | sshCompareString (const SshString *string, const char_t *value) |
Compare a binary string against the supplied value. More... | |
bool_t | sshCompareStrings (const SshString *string1, const SshString *string2) |
Compare binary strings. More... | |
bool_t | sshCompareAlgo (const char_t *name1, const char_t *name2) |
Compare algorithm names. More... | |
Detailed Description
SSH helper functions.
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.
- Version
- 2.4.4
Definition in file ssh_misc.c.
Macro Definition Documentation
◆ TRACE_LEVEL
#define TRACE_LEVEL SSH_TRACE_LEVEL |
Definition at line 32 of file ssh_misc.c.
Function Documentation
◆ sshCloseConnection()
void sshCloseConnection | ( | SshConnection * | connection | ) |
Close SSH connection.
- Parameters
-
[in] connection Pointer to the SSH connection
Definition at line 172 of file ssh_misc.c.
◆ sshCompareAlgo()
Compare algorithm names.
- Parameters
-
[in] name1 Name of the first algorithm [in] name2 Name of the second algorithm
- Returns
- Comparison result
Definition at line 1653 of file ssh_misc.c.
◆ sshCompareString()
Compare a binary string against the supplied value.
- Parameters
-
[in] string Pointer to the binary string [in] value NULL-terminated string
- Returns
- Comparison result
Definition at line 1586 of file ssh_misc.c.
◆ sshCompareStrings()
Compare binary strings.
- Parameters
-
[in] string1 Pointer to the first binary string [in] string2 Pointer to the second binary string
- Returns
- Comparison result
Definition at line 1623 of file ssh_misc.c.
◆ sshConvertArrayToMpint()
error_t sshConvertArrayToMpint | ( | const uint8_t * | value, |
size_t | length, | ||
uint8_t * | p, | ||
size_t * | written | ||
) |
Convert a binary string to mpint representation.
- Parameters
-
[in] value Pointer to the binary string (MSB first encoded) [out] length Length of the binary string, in bytes [out] p Output stream where to write the mpint representation [out] written Total number of bytes that have been written
- Returns
- Error code
Definition at line 1531 of file ssh_misc.c.
◆ sshFindName()
int_t sshFindName | ( | const SshNameList * | nameList, |
const char_t * | name | ||
) |
Search a name list for a given name.
- Parameters
-
[in] nameList List of names [in] name NULL-terminated string containing the name
- Returns
- The index of the name, or -1 if the name does not appear in the name list
Definition at line 1287 of file ssh_misc.c.
◆ sshFormatBinaryString()
error_t sshFormatBinaryString | ( | const void * | value, |
size_t | valueLen, | ||
uint8_t * | p, | ||
size_t * | written | ||
) |
Format a binary string.
- Parameters
-
[in] value Pointer to the binary string [in] valueLen Length of the binary string, in bytes [out] p Output stream where to write the binary string [out] written Total number of bytes that have been written
- Returns
- Error code
Definition at line 1415 of file ssh_misc.c.
◆ sshFormatHostKey()
error_t sshFormatHostKey | ( | SshConnection * | connection, |
uint8_t * | p, | ||
size_t * | written | ||
) |
Format host key structure.
- Parameters
-
[in] connection Pointer to the SSH connection [out] p Output stream where to write the host key [out] written Total number of bytes that have been written
- Returns
- Error code
Definition at line 863 of file ssh_misc.c.
◆ sshFormatMpint()
Format a multiple precision integer.
- Parameters
-
[in] value Pointer to a multiple precision integer [out] p Output stream where to write the multiple precision integer [out] written Total number of bytes that have been written
- Returns
- Error code
Definition at line 1487 of file ssh_misc.c.
◆ sshFormatNameList()
error_t sshFormatNameList | ( | const char_t *const | nameList[], |
uint_t | nameListLen, | ||
uint8_t * | p, | ||
size_t * | written | ||
) |
Format a comma-separated list of names.
- Parameters
-
[in] nameList List of names [in] nameListLen Number of items in the list [out] p Output stream where to write the name list [out] written Total number of bytes that have been written
- Returns
- Error code
Definition at line 1442 of file ssh_misc.c.
◆ sshFormatString()
Format a string.
- Parameters
-
[in] value NULL-terminating string [out] p Output stream where to write the string [out] written Total number of bytes that have been written
- Returns
- Error code
Definition at line 1384 of file ssh_misc.c.
◆ sshGetCurveInfo()
const EcCurveInfo* sshGetCurveInfo | ( | const SshString * | keyFormatId, |
const SshString * | curveName | ||
) |
Get the elliptic curve that matches the specified key format identifier.
- Parameters
-
[in] keyFormatId Key format identifier [in] curveName Curve name
- Returns
- Elliptic curve domain parameters
Definition at line 1073 of file ssh_misc.c.
◆ sshGetHostKey()
SshHostKey* sshGetHostKey | ( | SshConnection * | connection | ) |
Get the currently selected host key.
- Parameters
-
[in] connection Pointer to the SSH connection
- Returns
- Pointer to the selected host key
Definition at line 722 of file ssh_misc.c.
◆ sshGetName()
bool_t sshGetName | ( | const SshNameList * | nameList, |
uint_t | index, | ||
SshString * | name | ||
) |
Get the element at specified index.
- Parameters
-
[in] nameList List of names [in] index Zero-based index of the element to get [out] name Value of the element
- Returns
- TRUE if the index is valid, else FALSE
Definition at line 1338 of file ssh_misc.c.
◆ sshGetUserEvents()
uint_t sshGetUserEvents | ( | SshChannel * | channel | ) |
Retrieve event flags for a specified channel.
- Parameters
-
[in] channel Handle referencing an SSH channel
- Returns
- Logic OR of events in the signaled state
Definition at line 677 of file ssh_misc.c.
◆ sshNotifyEvent()
void sshNotifyEvent | ( | SshContext * | context | ) |
Notify the SSH context that event is occurring.
- Parameters
-
[in] context Pointer to the SSH context
Definition at line 709 of file ssh_misc.c.
◆ sshOpenConnection()
SshConnection* sshOpenConnection | ( | SshContext * | context, |
Socket * | socket | ||
) |
Open a new SSH connection.
- Parameters
-
[in] context Pointer to the SSH context [in] socket Handle that identifies a socket
- Returns
- Handle referencing the newly created SSH connection
Definition at line 66 of file ssh_misc.c.
◆ sshParseBinaryString()
error_t sshParseBinaryString | ( | const uint8_t * | p, |
size_t | length, | ||
SshBinaryString * | string | ||
) |
Parse a binary string.
- Parameters
-
[in] p Input stream where to read the string [in] length Number of bytes available in the input stream [out] string Binary string resulting from the parsing process
- Returns
- Error code
Definition at line 1189 of file ssh_misc.c.
◆ sshParseNameList()
error_t sshParseNameList | ( | const uint8_t * | p, |
size_t | length, | ||
SshNameList * | nameList | ||
) |
Parse a comma-separated list of names.
- Parameters
-
[in] p Input stream where to read the list [in] length Number of bytes available in the input stream [out] nameList Name list resulting from the parsing process
- Returns
- Error code
Definition at line 1227 of file ssh_misc.c.
◆ sshParseString()
Parse a string.
- Parameters
-
[in] p Input stream where to read the string [in] length Number of bytes available in the input stream [out] string String resulting from the parsing process
- Returns
- Error code
Definition at line 1152 of file ssh_misc.c.
◆ sshProcessConnectionEvents()
error_t sshProcessConnectionEvents | ( | SshContext * | context, |
SshConnection * | connection | ||
) |
Connection event handler.
- Parameters
-
[in] context Pointer to the SSH context [in] connection Pointer to the SSH connection
- Returns
- Error code
Definition at line 372 of file ssh_misc.c.
◆ sshRegisterConnectionEvents()
void sshRegisterConnectionEvents | ( | SshContext * | context, |
SshConnection * | connection, | ||
SocketEventDesc * | eventDesc | ||
) |
Register connection events.
- Parameters
-
[in] context Pointer to the SSH context [in] connection Pointer to the SSH connection [in] eventDesc Socket events to be registered
Definition at line 280 of file ssh_misc.c.
◆ sshRegisterUserEvents()
void sshRegisterUserEvents | ( | SshChannel * | channel, |
OsEvent * | event, | ||
uint_t | eventMask | ||
) |
Subscribe to the specified channel events.
- Parameters
-
[in] channel Handle referencing an SSH channel [in] event Event object used to receive notifications [in] eventMask Logic OR of the requested socket events
Definition at line 619 of file ssh_misc.c.
◆ sshSelectHostKey()
int_t sshSelectHostKey | ( | SshContext * | context, |
const char_t * | hostKeyAlgo | ||
) |
Select a host key that matches then specified algorithm.
- Parameters
-
[in] context Pointer to the SSH context [in] hostKeyAlgo Selected host key algorithm name
- Returns
- Index of the selected host key, if any
Definition at line 757 of file ssh_misc.c.
◆ sshSelectNextHostKey()
int_t sshSelectNextHostKey | ( | SshConnection * | connection | ) |
Select the next acceptable host key.
- Parameters
-
[in] connection Pointer to the SSH connection
- Returns
- Index of the next acceptable host key, if any
Definition at line 808 of file ssh_misc.c.
◆ sshUnregisterUserEvents()
void sshUnregisterUserEvents | ( | SshChannel * | channel | ) |
Unsubscribe previously registered events.
- Parameters
-
[in] channel Handle referencing an SSH channel
Definition at line 654 of file ssh_misc.c.