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-2024 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.4.2
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 EcCurveInfo *sshGetCurveInfo(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 
95 error_t sshConvertArrayToMpint(const uint8_t *value, size_t length, uint8_t *p,
96  size_t *written);
97 
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);
101 
102 //C++ guard
103 #ifdef __cplusplus
104 }
105 #endif
106 
107 #endif
bool_t sshGetName(const SshNameList *nameList, uint_t index, SshString *name)
Get the element at specified index.
Definition: ssh_misc.c:1338
int bool_t
Definition: compiler_port.h:53
Arbitrary precision integer.
Definition: mpi.h:80
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:1623
uint8_t p
Definition: ndp.h:300
SshHostKey * sshGetHostKey(SshConnection *connection)
Get the currently selected host key.
Definition: ssh_misc.c:722
bool_t sshCompareString(const SshString *string, const char_t *value)
Compare a binary string against the supplied value.
Definition: ssh_misc.c:1586
Event object.
uint_t sshGetUserEvents(SshChannel *channel)
Retrieve event flags for a specified channel.
Definition: ssh_misc.c:677
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:1442
error_t sshFormatBinaryString(const void *value, size_t valueLen, uint8_t *p, size_t *written)
Format a binary string.
Definition: ssh_misc.c:1415
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:1531
error_t sshParseBinaryString(const uint8_t *p, size_t length, SshBinaryString *string)
Parse a binary string.
Definition: ssh_misc.c:1189
Structure describing socket events.
Definition: socket.h:401
SshConnection * sshOpenConnection(SshContext *context, Socket *socket)
Open a new SSH connection.
Definition: ssh_misc.c:66
Elliptic curve parameters.
Definition: ec_curves.h:295
#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:1227
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)
const EcCurveInfo * sshGetCurveInfo(const SshString *keyFormatId, const SshString *curveName)
Get the elliptic curve that matches the specified key format identifier.
Definition: ssh_misc.c:1073
void sshCloseConnection(SshConnection *connection)
Close SSH connection.
Definition: ssh_misc.c:172
uint8_t length
Definition: tcp.h:368
String.
Definition: ssh_types.h:56
void sshRegisterConnectionEvents(SshContext *context, SshConnection *connection, SocketEventDesc *eventDesc)
Register connection events.
Definition: ssh_misc.c:280
void sshNotifyEvent(SshContext *context)
Notify the SSH context that event is occurring.
Definition: ssh_misc.c:709
int_t sshSelectNextHostKey(SshConnection *connection)
Select the next acceptable host key.
Definition: ssh_misc.c:808
bool_t sshCompareAlgo(const char_t *name1, const char_t *name2)
Compare algorithm names.
Definition: ssh_misc.c:1653
char char_t
Definition: compiler_port.h:48
#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:619
error_t sshFormatHostKey(SshConnection *connection, uint8_t *p, size_t *written)
Format host key structure.
Definition: ssh_misc.c:863
uint8_t value[]
Definition: tcp.h:369
error_t sshParseString(const uint8_t *p, size_t length, SshString *string)
Parse a string.
Definition: ssh_misc.c:1152
error_t sshFormatString(const char_t *value, uint8_t *p, size_t *written)
Format a string.
Definition: ssh_misc.c:1384
error_t sshFormatMpint(const Mpi *value, uint8_t *p, size_t *written)
Format a multiple precision integer.
Definition: ssh_misc.c:1487
int_t sshSelectHostKey(SshContext *context, const char_t *hostKeyAlgo)
Select a host key that matches then specified algorithm.
Definition: ssh_misc.c:757
unsigned int uint_t
Definition: compiler_port.h:50
error_t sshProcessConnectionEvents(SshContext *context, SshConnection *connection)
Connection event handler.
Definition: ssh_misc.c:372
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:1287
void sshUnregisterUserEvents(SshChannel *channel)
Unsubscribe previously registered events.
Definition: ssh_misc.c:654
#define SshChannel
Definition: ssh.h:878