NetBurner 3.5.0
PDF Version
 
NbWolfSsh.h
Go to the documentation of this file.
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
16#ifndef _NB_SSH_H_
17#define _NB_SSH_H_
18#include <nettypes.h>
19#include <stdio.h>
20#include <basictypes.h>
21
22#ifdef NB_SSH_SUPPORTED
23
24#ifndef WOLFSSL_USER_SETTINGS
25#define WOLFSSL_USER_SETTINGS // This wasn't getting defined in the project source files in NBEclipse
26#endif
27
28#include <ssh/wolfssh/ssh.h>
30#include <ssh/NetBurner/SshSocket.h>
31
32/*
33 ******************************************************************************
34 *
35 * Definitions
36 *
37 ******************************************************************************
38 */
39/* Default SSH Server Port*/
40#define SSH_SECURE_SHELL_IANA_ASSIGNED_PORT (22)
41
42/* Connection timeout */
43#ifdef _DEBUG
44#define SSH_CONNECTION_TIMEOUT_IN_SECS (360)
45#else /* #ifdef _DEBUG */
46#define SSH_CONNECTION_TIMEOUT_IN_SECS (180)
47#endif /* #ifdef _DEBUG */
48
49/* Default static key size, no choice is 1024 */
50/* #define SSH_RSA_KEY_DEFAULT_512 ( 512 ) */
51#define SSH_RSA_KEY_DEFAULT_1024 (1024)
52/* #define SSH_RSA_KEY_DEFAULT_2048 ( 2048 ) */
53
54#define SSH_DSS_KEY_DEFAULT_512 (512)
55/* #define SSH_DSS_KEY_DEFAULT_1024 ( 1024 ) */
56/* #define SSH_DSS_KEY_DEFAULT_2048 ( 2048 ) */
57
63#define SSH_SUCCESS (0)
64#define SSH_ERROR_FAILED_SESSION_FAILED (-300)
65#define SSH_ERROR_FAILED_NEGOTIATION (-301)
66#define SSH_ERROR_FAILED_INITIALIZATION (-302)
67#define SSH_ERROR_FAILED_CONTEXT_INIT (-303)
68#define SSH_ERROR_BAD_KEY (-304)
69#define SSH_ERROR_BAD_ARGUMENT (-305)
70#define SSH_FAILED_KEY_CHECK (-306)
71the onboard generated key is not valid, and auto-cert generation is not enabled or the cert generation function failed.
72
75/* SSH Key */
76#define SSH_KEY_RSA (1)
77#define SSH_KEY_DSS (2)
78#define SSH_KEY_ECC (3)
79
80/*
81 ******************************************************************************
82 *
83 * SSH "C" Library Interface
84 *
85 ******************************************************************************
86 */
87#ifdef __cplusplus
88extern "C"
89{
90#endif
91
92 /*Functions:*/
93 /*Group:SSH functions*/
94
95 // Server
96 // Deprecated, only left for backwards compatibility. Should use sshUserAuthenticateWithTypeFn instead.
107 typedef int (*sshUserAuthenticateFn)(const char *usernamePtr, const char *passwordPtr);
108
119 typedef int (*sshUserAuthenticateWithTypeFn)(const char *usernamePtr, const char *authValPtr, AuthType authType);
120
121 // Client
131 typedef int (*sshGetUserPwFn)(const NBString &usernamePtr, NBString &passwordPtr);
132
144 typedef int (*sshGetUserKeyFn)(const NBString &usernamePtr, NBString &publicKey, NBString &privateKey, NBString &keyType);
145
146 // Server Callbacks
154 void SshSetUserAuthenticate(sshUserAuthenticateFn sshUserAuthenticateFnPtr);
155
164
173
182
183 // Client Callbacks
195
207
218
229
243 typedef int (*sshUserGetKeyFn)(int keyRequested, const unsigned char **keyBufferPtr, int *keyLengthPtr);
244
253 void SshSetUserGetKey(sshUserGetKeyFn sshUserGetKeyFnPtr);
254
264
276 bool SshValidateKey(const char *candidateKey, int candidateKeySize, int *keyTypePtr, int keyFormat = WOLFSSH_FORMAT_ASN1);
277
288 bool SshWritePublicKey(int publicKeyFd, unsigned char *candidateKey, int candidateKeySize);
289
303
318 int SshAccept(int listenFd, IPADDR *clientAddress, uint16_t *securePort, uint16_t timeout);
319
337 int SshConnect(IPADDR clientAddress, uint16_t securePort, uint16_t localPort, uint16_t timeout, const char *username);
338
346 SshSocket *SshNegotiateSession(int fd);
347
356 SshSocket *SshNegotiateSessionClient(int secureFd, const char *username);
357
363 void SshPrintStatistics(int secureFd);
364
371
380 int SshSetBannerText(const char *banner);
381
393 int SshSetSockOption(int fd, int option);
394
406 int SshClrSockOption(int fd, int option);
407
418 int SshGetSockOption(int fd);
419
420
421#ifdef __cplusplus
422};
423#endif
424
425#endif /* NB_SSH_SUPPORTED */
426#endif /* _NB_SSH_H_ */
427
NetBurner User Authorization Manager.
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
Lightweight alternative to C++ CString class.
Definition nbstring.h:118
bool SshValidateKey(const char *candidateKey, int candidateKeySize, int *keyTypePtr, int keyFormat=WOLFSSH_FORMAT_ASN1)
Takes a key and returns if it's valid or not.
void SshSetUserAuthenticateWithType(sshUserAuthenticateWithTypeFn sshUserAuthenticateFnPtr)
Sets the user defined server authentication function.
int SshSetBannerText(const char *banner)
Sets the banner text displayed by the SSH server on connection.
sshUserGetKeyFn SshGetUserGetKey(void)
Gets the user defined callback method to provide the server key.
void SshPrintStatistics(int secureFd)
Negotiates an SSH client session on an open file descriptor.
int SshGetKeySize()
Determins and returns SSH's installed key size.
int NbSshInit()
Initializes the underlying SSH framework. This will start a background task used to handle negotiatio...
void SshClientSetGetUserPaswordFn(sshGetUserPwFn sshGetUserPwFnPtr)
Sets the user defined client authentication function for getting user passwords during SSH authentica...
int(* sshUserAuthenticateWithTypeFn)(const char *usernamePtr, const char *authValPtr, AuthType authType)
User provided SSH user authenticate routine for a server.
Definition NbWolfSsh.h:119
sshGetUserPwFn SshClientGetUserPaswordFn(void)
Gets the user defined client authentication function for getting a user password during authenticatio...
void SshClientSetGetUserKeyFn(sshGetUserKeyFn sshGetUserKeyFnPtr)
Sets the user defined client authentication function for getting user keys during SSH authentication.
void SshSetUserAuthenticate(sshUserAuthenticateFn sshUserAuthenticateFnPtr)
[DEPRECATED] Sets the user defined server authentication function. Please consider sshUserAuthenticat...
int SshSetSockOption(int fd, int option)
Set SSH TCP socket options.
SshSocket * SshNegotiateSessionClient(int secureFd, const char *username)
Negotiates an SSH client session on an open file descriptor.
int(* sshGetUserPwFn)(const NBString &usernamePtr, NBString &passwordPtr)
User provided SSH user password authentication routine for clients.
Definition NbWolfSsh.h:131
sshUserAuthenticateWithTypeFn SshGetUserAuthenticateWithType(void)
Gets the user defined server authentication function..
int(* sshUserAuthenticateFn)(const char *usernamePtr, const char *passwordPtr)
[DEPRECATED] User provided SSH username and password authenticate routine for a server....
Definition NbWolfSsh.h:107
int SshConnect(IPADDR clientAddress, uint16_t securePort, uint16_t localPort, uint16_t timeout, const char *username)
Issues a connect request to negotiates an SSH session. Automatically calls NbSshInit() if required.
sshGetUserKeyFn SshClientGetUserKeyFn(void)
Gets the user defined client authentication function for getting a user key during authentication.
sshUserAuthenticateFn SshGetUserAuthenticate(void)
[DEPRECATED] Gets the user defined server authentication function. Please consider SshGetUserAuthenti...
int SshGetSockOption(int fd)
Returns the options for the specified SSH TCP socket.
int SshAccept(int listenFd, IPADDR *clientAddress, uint16_t *securePort, uint16_t timeout)
Accepts and negotiates SSH session. Automatically calls NbSshInit() if required.
int(* sshGetUserKeyFn)(const NBString &usernamePtr, NBString &publicKey, NBString &privateKey, NBString &keyType)
User provided SSH user key authenticate routine for clients.
Definition NbWolfSsh.h:144
int SshClrSockOption(int fd, int option)
Clear SSH TCP socket options.
bool SshWritePublicKey(int publicKeyFd, unsigned char *candidateKey, int candidateKeySize)
Write public key to file descriptor. Takes both PEM and ANS1 formats.
int(* sshUserGetKeyFn)(int keyRequested, const unsigned char **keyBufferPtr, int *keyLengthPtr)
The user defined callback to get the server key used during the initial SSH negotiation.
Definition NbWolfSsh.h:243
SshSocket * SshNegotiateSession(int fd)
Negotiates an SSH server session on an open file descriptor.
void SshSetUserGetKey(sshUserGetKeyFn sshUserGetKeyFnPtr)
Sets the user defined callback method to provide the server key.
AuthType
The types of authorization requests that are managed. These just indicate what the has value is,...
Definition UserAuthManager.h:44
NetBurner IPADDR4 Class. See the IPADDR4 Class page for complete documentation.