ssh_misc.h
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-2025 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
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 (www.oryx-embedded.com)
28  * @version 2.5.0
29  **/
30 
31 #ifndef _SSH_MISC_H
32 #define _SSH_MISC_H
33 
34 //Dependencies
35 #include "ssh/ssh.h"
36 #include "mpi/mpi.h"
37 
38 //Maximum port number
39 #define SSH_MAX_PORT_NUM 65535
40 
41 //C++ guard
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 //SSH related functions
48 void sshCloseConnection(SshConnection *connection);
49 
51  SshConnection *connection, SocketEventDesc *eventDesc);
52 
54  SshConnection *connection);
55 
56 void sshRegisterUserEvents(SshChannel *channel, OsEvent *event,
57  uint_t eventMask);
58 
59 void sshUnregisterUserEvents(SshChannel *channel);
61 
62 void sshNotifyEvent(SshContext *context);
63 
65 int_t sshSelectHostKey(SshContext *context, const char_t *hostKeyAlgo);
67 
68 error_t sshFormatHostKey(SshConnection *connection, uint8_t *p,
69  size_t *written);
70 
71 const EcCurve *sshGetCurve(const SshString *keyFormatId,
72  const SshString *curveName);
73 
74 error_t sshParseString(const uint8_t *p, size_t length, SshString *string);
75 
76 error_t sshParseBinaryString(const uint8_t *p, size_t length,
77  SshBinaryString *string);
78 
79 error_t sshParseNameList(const uint8_t *p, size_t length,
80  SshNameList *nameList);
81 
82 int_t sshFindName(const SshNameList *nameList, const char_t *name);
83 bool_t sshGetName(const SshNameList *nameList, uint_t index, SshString *name);
84 
85 error_t sshFormatString(const char_t *value, uint8_t *p, size_t *written);
86 
87 error_t sshFormatBinaryString(const void *value, size_t valueLen, uint8_t *p,
88  size_t *written);
89 
90 error_t sshFormatNameList(const char_t *const nameList[], uint_t nameListLen,
91  uint8_t *p, size_t *written);
92 
93 error_t sshFormatMpint(const Mpi *value, uint8_t *p, size_t *written);
94 
96  uint8_t *p, size_t *written);
97 
98 error_t sshConvertArrayToMpint(const uint8_t *value, size_t length, uint8_t *p,
99  size_t *written);
100 
101 bool_t sshCompareString(const SshString *string, const char_t *value);
102 bool_t sshCompareStrings(const SshString *string1, const SshString *string2);
103 bool_t sshCompareAlgo(const char_t *name1, const char_t *name2);
104 
105 //C++ guard
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif
const EcCurve * sshGetCurve(const SshString *keyFormatId, const SshString *curveName)
Get the elliptic curve that matches the specified key format identifier.
Definition: ssh_misc.c:1069
bool_t sshGetName(const SshNameList *nameList, uint_t index, SshString *name)
Get the element at specified index.
Definition: ssh_misc.c:1334
int bool_t
Definition: compiler_port.h:61
Arbitrary precision integer.
Definition: mpi.h:102
signed int int_t
Definition: compiler_port.h:56
Binary string.
Definition: ssh_types.h:67
bool_t sshCompareStrings(const SshString *string1, const SshString *string2)
Compare binary strings.
Definition: ssh_misc.c:1663
uint8_t p
Definition: ndp.h:300
SshHostKey * sshGetHostKey(SshConnection *connection)
Get the currently selected host key.
Definition: ssh_misc.c:723
bool_t sshCompareString(const SshString *string, const char_t *value)
Compare a binary string against the supplied value.
Definition: ssh_misc.c:1626
Event object.
uint_t sshGetUserEvents(SshChannel *channel)
Retrieve event flags for a specified channel.
Definition: ssh_misc.c:678
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:1438
error_t sshFormatBinaryString(const void *value, size_t valueLen, uint8_t *p, size_t *written)
Format a binary string.
Definition: ssh_misc.c:1411
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:1571
error_t sshParseBinaryString(const uint8_t *p, size_t length, SshBinaryString *string)
Parse a binary string.
Definition: ssh_misc.c:1185
Structure describing socket events.
Definition: socket.h:432
SshConnection * sshOpenConnection(SshContext *context, Socket *socket)
Open a new SSH connection.
Definition: ssh_misc.c:67
error_t sshConvertScalarToMpint(const uint32_t *value, uint_t length, uint8_t *p, size_t *written)
Convert a scalar to mpint representation.
Definition: ssh_misc.c:1527
#define SshContext
Definition: ssh.h:870
error_t
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:1223
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:65
Host key.
Definition: ssh.h:1143
MPI (Multiple Precision Integer Arithmetic)
void sshCloseConnection(SshConnection *connection)
Close SSH connection.
Definition: ssh_misc.c:173
uint8_t length
Definition: tcp.h:375
String.
Definition: ssh_types.h:56
void sshRegisterConnectionEvents(SshContext *context, SshConnection *connection, SocketEventDesc *eventDesc)
Register connection events.
Definition: ssh_misc.c:281
void sshNotifyEvent(SshContext *context)
Notify the SSH context that event is occurring.
Definition: ssh_misc.c:710
int_t sshSelectNextHostKey(SshConnection *connection)
Select the next acceptable host key.
Definition: ssh_misc.c:809
bool_t sshCompareAlgo(const char_t *name1, const char_t *name2)
Compare algorithm names.
Definition: ssh_misc.c:1693
char char_t
Definition: compiler_port.h:55
#define SshConnection
Definition: ssh.h:874
#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:620
error_t sshFormatHostKey(SshConnection *connection, uint8_t *p, size_t *written)
Format host key structure.
Definition: ssh_misc.c:864
uint8_t value[]
Definition: tcp.h:376
error_t sshParseString(const uint8_t *p, size_t length, SshString *string)
Parse a string.
Definition: ssh_misc.c:1148
error_t sshFormatString(const char_t *value, uint8_t *p, size_t *written)
Format a string.
Definition: ssh_misc.c:1380
error_t sshFormatMpint(const Mpi *value, uint8_t *p, size_t *written)
Format a multiple precision integer.
Definition: ssh_misc.c:1483
#define EcCurve
Definition: ec.h:346
int_t sshSelectHostKey(SshContext *context, const char_t *hostKeyAlgo)
Select a host key that matches then specified algorithm.
Definition: ssh_misc.c:758
unsigned int uint_t
Definition: compiler_port.h:57
error_t sshProcessConnectionEvents(SshContext *context, SshConnection *connection)
Connection event handler.
Definition: ssh_misc.c:373
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:1283
void sshUnregisterUserEvents(SshChannel *channel)
Unsubscribe previously registered events.
Definition: ssh_misc.c:655
#define SshChannel
Definition: ssh.h:878