ssh_misc.h File Reference

SSH helper functions. More...

#include "ssh/ssh.h"
#include "mpi/mpi.h"

Go to the source code of this file.

Macros

#define SSH_MAX_PORT_NUM   65535
 

Functions

SshConnectionsshOpenConnection (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...
 
SshHostKeysshGetHostKey (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 EcCurveInfosshGetCurveInfo (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.

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

Definition in file ssh_misc.h.

Macro Definition Documentation

◆ SSH_MAX_PORT_NUM

#define SSH_MAX_PORT_NUM   65535

Definition at line 39 of file ssh_misc.h.

Function Documentation

◆ sshCloseConnection()

void sshCloseConnection ( SshConnection connection)

Close SSH connection.

Parameters
[in]connectionPointer to the SSH connection

Definition at line 172 of file ssh_misc.c.

◆ sshCompareAlgo()

bool_t sshCompareAlgo ( const char_t name1,
const char_t name2 
)

Compare algorithm names.

Parameters
[in]name1Name of the first algorithm
[in]name2Name of the second algorithm
Returns
Comparison result

Definition at line 1653 of file ssh_misc.c.

◆ sshCompareString()

bool_t sshCompareString ( const SshString string,
const char_t value 
)

Compare a binary string against the supplied value.

Parameters
[in]stringPointer to the binary string
[in]valueNULL-terminated string
Returns
Comparison result

Definition at line 1586 of file ssh_misc.c.

◆ sshCompareStrings()

bool_t sshCompareStrings ( const SshString string1,
const SshString string2 
)

Compare binary strings.

Parameters
[in]string1Pointer to the first binary string
[in]string2Pointer 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]valuePointer to the binary string (MSB first encoded)
[out]lengthLength of the binary string, in bytes
[out]pOutput stream where to write the mpint representation
[out]writtenTotal 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]nameListList of names
[in]nameNULL-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]valuePointer to the binary string
[in]valueLenLength of the binary string, in bytes
[out]pOutput stream where to write the binary string
[out]writtenTotal 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]connectionPointer to the SSH connection
[out]pOutput stream where to write the host key
[out]writtenTotal number of bytes that have been written
Returns
Error code

Definition at line 863 of file ssh_misc.c.

◆ sshFormatMpint()

error_t sshFormatMpint ( const Mpi value,
uint8_t *  p,
size_t *  written 
)

Format a multiple precision integer.

Parameters
[in]valuePointer to a multiple precision integer
[out]pOutput stream where to write the multiple precision integer
[out]writtenTotal 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]nameListList of names
[in]nameListLenNumber of items in the list
[out]pOutput stream where to write the name list
[out]writtenTotal number of bytes that have been written
Returns
Error code

Definition at line 1442 of file ssh_misc.c.

◆ sshFormatString()

error_t sshFormatString ( const char_t value,
uint8_t *  p,
size_t *  written 
)

Format a string.

Parameters
[in]valueNULL-terminating string
[out]pOutput stream where to write the string
[out]writtenTotal 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]keyFormatIdKey format identifier
[in]curveNameCurve 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]connectionPointer 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]nameListList of names
[in]indexZero-based index of the element to get
[out]nameValue 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]channelHandle 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]contextPointer 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]contextPointer to the SSH context
[in]socketHandle 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]pInput stream where to read the string
[in]lengthNumber of bytes available in the input stream
[out]stringBinary 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]pInput stream where to read the list
[in]lengthNumber of bytes available in the input stream
[out]nameListName list resulting from the parsing process
Returns
Error code

Definition at line 1227 of file ssh_misc.c.

◆ sshParseString()

error_t sshParseString ( const uint8_t *  p,
size_t  length,
SshString string 
)

Parse a string.

Parameters
[in]pInput stream where to read the string
[in]lengthNumber of bytes available in the input stream
[out]stringString 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]contextPointer to the SSH context
[in]connectionPointer 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]contextPointer to the SSH context
[in]connectionPointer to the SSH connection
[in]eventDescSocket 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]channelHandle referencing an SSH channel
[in]eventEvent object used to receive notifications
[in]eventMaskLogic 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]contextPointer to the SSH context
[in]hostKeyAlgoSelected 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]connectionPointer 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]channelHandle referencing an SSH channel

Definition at line 654 of file ssh_misc.c.