Go to the documentation of this file.
1 /**
2  * @file ssh_misc.h
3  * @brief SSH helper functions
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2019-2023 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSSH Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (
28  * @version 2.2.4
29  **/
31 #ifndef _SSH_MISC_H
32 #define _SSH_MISC_H
34 //Dependencies
35 #include "ssh/ssh.h"
36 #include "mpi/mpi.h"
38 //Maximum port number
39 #define SSH_MAX_PORT_NUM 65535
41 //C++ guard
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
46 //SSH related functions
48 void sshCloseConnection(SshConnection *connection);
51  SshConnection *connection, SocketEventDesc *eventDesc);
54  SshConnection *connection);
56 void sshRegisterUserEvents(SshChannel *channel, OsEvent *event,
57  uint_t eventMask);
59 void sshUnregisterUserEvents(SshChannel *channel);
62 void sshNotifyEvent(SshContext *context);
65 int_t sshSelectHostKey(SshContext *context, const char_t *hostKeyAlgo);
68 error_t sshFormatHostKey(SshConnection *connection, uint8_t *p,
69  size_t *written);
71 const EcCurveInfo *sshGetCurveInfo(const SshString *keyFormatId,
72  const SshString *curveName);
74 error_t sshParseString(const uint8_t *p, size_t length, SshString *string);
76 error_t sshParseBinaryString(const uint8_t *p, size_t length,
77  SshBinaryString *string);
79 error_t sshParseNameList(const uint8_t *p, size_t length,
80  SshNameList *nameList);
82 int_t sshFindName(const SshNameList *nameList, const char_t *name);
83 bool_t sshGetName(const SshNameList *nameList, uint_t index, SshString *name);
85 error_t sshFormatString(const char_t *value, uint8_t *p, size_t *written);
87 error_t sshFormatBinaryString(const void *value, size_t valueLen, uint8_t *p,
88  size_t *written);
90 error_t sshFormatNameList(const char_t *const nameList[], uint_t nameListLen,
91  uint8_t *p, size_t *written);
93 error_t sshFormatMpint(const Mpi *value, uint8_t *p, size_t *written);
95 error_t sshConvertArrayToMpint(const uint8_t *value, size_t length, uint8_t *p,
96  size_t *written);
98 bool_t sshCompareString(const SshString *string, const char_t *value);
99 bool_t sshCompareStrings(const SshString *string1, const SshString *string2);
100 bool_t sshCompareAlgo(const char_t *name1, const char_t *name2);
102 //C++ guard
103 #ifdef __cplusplus
104 }
105 #endif
107 #endif
uint8_t length
Definition: coap_common.h:193
bool_t sshGetName(const SshNameList *nameList, uint_t index, SshString *name)
Get the element at specified index.
Definition: ssh_misc.c:1327
int bool_t
Definition: compiler_port.h:53
Arbitrary precision integer.
Definition: mpi.h:70
signed int int_t
Definition: compiler_port.h:49
Binary string.
Definition: ssh_types.h:67
bool_t sshCompareStrings(const SshString *string1, const SshString *string2)
Compare binary strings.
Definition: ssh_misc.c:1612
uint8_t p
Definition: ndp.h:298
SshHostKey * sshGetHostKey(SshConnection *connection)
Get the currently selected host key.
Definition: ssh_misc.c:713
bool_t sshCompareString(const SshString *string, const char_t *value)
Compare a binary string against the supplied value.
Definition: ssh_misc.c:1575
Event object.
uint_t sshGetUserEvents(SshChannel *channel)
Retrieve event flags for a specified channel.
Definition: ssh_misc.c:668
error_t sshFormatNameList(const char_t *const nameList[], uint_t nameListLen, uint8_t *p, size_t *written)
Format a comma-separated list of names.
Definition: ssh_misc.c:1431
error_t sshFormatBinaryString(const void *value, size_t valueLen, uint8_t *p, size_t *written)
Format a binary string.
Definition: ssh_misc.c:1404
char_t name[]
error_t sshConvertArrayToMpint(const uint8_t *value, size_t length, uint8_t *p, size_t *written)
Convert a binary string to mpint representation.
Definition: ssh_misc.c:1520
error_t sshParseBinaryString(const uint8_t *p, size_t length, SshBinaryString *string)
Parse a binary string.
Definition: ssh_misc.c:1178
Structure describing socket events.
Definition: socket.h:365
SshConnection * sshOpenConnection(SshContext *context, Socket *socket)
Open a new SSH connection.
Definition: ssh_misc.c:65
Elliptic curve parameters.
Definition: ec_curves.h:293
#define SshContext
Definition: ssh.h:838
Error codes.
Definition: error.h:43
String containing a comma-separated list of names.
Definition: ssh_types.h:78
error_t sshParseNameList(const uint8_t *p, size_t length, SshNameList *nameList)
Parse a comma-separated list of names.
Definition: ssh_misc.c:1216
int_t socket(int_t family, int_t type, int_t protocol)
Create a socket that is bound to a specific transport service provider.
Definition: bsd_socket.c:63
uint8_t value[]
Definition: tcp.h:367
Host key.
Definition: ssh.h:1109
MPI (Multiple Precision Integer Arithmetic)
const EcCurveInfo * sshGetCurveInfo(const SshString *keyFormatId, const SshString *curveName)
Get the elliptic curve that matches the specified key format identifier.
Definition: ssh_misc.c:1064
void sshCloseConnection(SshConnection *connection)
Close SSH connection.
Definition: ssh_misc.c:167
Definition: ssh_types.h:56
void sshRegisterConnectionEvents(SshContext *context, SshConnection *connection, SocketEventDesc *eventDesc)
Register connection events.
Definition: ssh_misc.c:271
void sshNotifyEvent(SshContext *context)
Notify the SSH context that event is occurring.
Definition: ssh_misc.c:700
int_t sshSelectNextHostKey(SshConnection *connection)
Select the next acceptable host key.
Definition: ssh_misc.c:799
bool_t sshCompareAlgo(const char_t *name1, const char_t *name2)
Compare algorithm names.
Definition: ssh_misc.c:1642
char char_t
Definition: compiler_port.h:48
#define SshConnection
Definition: ssh.h:842
#define Socket
Definition: socket.h:36
void sshRegisterUserEvents(SshChannel *channel, OsEvent *event, uint_t eventMask)
Subscribe to the specified channel events.
Definition: ssh_misc.c:610
error_t sshFormatHostKey(SshConnection *connection, uint8_t *p, size_t *written)
Format host key structure.
Definition: ssh_misc.c:854
error_t sshParseString(const uint8_t *p, size_t length, SshString *string)
Parse a string.
Definition: ssh_misc.c:1141
error_t sshFormatString(const char_t *value, uint8_t *p, size_t *written)
Format a string.
Definition: ssh_misc.c:1373
error_t sshFormatMpint(const Mpi *value, uint8_t *p, size_t *written)
Format a multiple precision integer.
Definition: ssh_misc.c:1476
int_t sshSelectHostKey(SshContext *context, const char_t *hostKeyAlgo)
Select a host key that matches then specified algorithm.
Definition: ssh_misc.c:748
unsigned int uint_t
Definition: compiler_port.h:50
error_t sshProcessConnectionEvents(SshContext *context, SshConnection *connection)
Connection event handler.
Definition: ssh_misc.c:363
Secure Shell (SSH)
int_t sshFindName(const SshNameList *nameList, const char_t *name)
Search a name list for a given name.
Definition: ssh_misc.c:1276
void sshUnregisterUserEvents(SshChannel *channel)
Unsubscribe previously registered events.
Definition: ssh_misc.c:645
#define SshChannel
Definition: ssh.h:846