ssh

Dependents:   OS

Committer:
sPymbed
Date:
Mon Nov 25 14:24:05 2019 +0000
Revision:
0:c4152c628df5
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sPymbed 0:c4152c628df5 1 /* ssh.h
sPymbed 0:c4152c628df5 2 *
sPymbed 0:c4152c628df5 3 * Copyright (C) 2014-2016 wolfSSL Inc.
sPymbed 0:c4152c628df5 4 *
sPymbed 0:c4152c628df5 5 * This file is part of wolfSSH.
sPymbed 0:c4152c628df5 6 *
sPymbed 0:c4152c628df5 7 * wolfSSH is free software; you can redistribute it and/or modify
sPymbed 0:c4152c628df5 8 * it under the terms of the GNU General Public License as published by
sPymbed 0:c4152c628df5 9 * the Free Software Foundation; either version 3 of the License, or
sPymbed 0:c4152c628df5 10 * (at your option) any later version.
sPymbed 0:c4152c628df5 11 *
sPymbed 0:c4152c628df5 12 * wolfSSH is distributed in the hope that it will be useful,
sPymbed 0:c4152c628df5 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sPymbed 0:c4152c628df5 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
sPymbed 0:c4152c628df5 15 * GNU General Public License for more details.
sPymbed 0:c4152c628df5 16 *
sPymbed 0:c4152c628df5 17 * You should have received a copy of the GNU General Public License
sPymbed 0:c4152c628df5 18 * along with wolfSSH. If not, see <http://www.gnu.org/licenses/>.
sPymbed 0:c4152c628df5 19 */
sPymbed 0:c4152c628df5 20
sPymbed 0:c4152c628df5 21
sPymbed 0:c4152c628df5 22 /*
sPymbed 0:c4152c628df5 23 * The ssh module contains the public API for wolfSSH.
sPymbed 0:c4152c628df5 24 */
sPymbed 0:c4152c628df5 25
sPymbed 0:c4152c628df5 26
sPymbed 0:c4152c628df5 27 #pragma once
sPymbed 0:c4152c628df5 28
sPymbed 0:c4152c628df5 29 #include <wolfssl/options.h>
sPymbed 0:c4152c628df5 30 #include <wolfcrypt/types.h>
sPymbed 0:c4152c628df5 31 #include <wolfssh/settings.h>
sPymbed 0:c4152c628df5 32 #include <wolfssh/version.h>
sPymbed 0:c4152c628df5 33 #include <wolfssh/port.h>
sPymbed 0:c4152c628df5 34 #include <wolfssh/error.h>
sPymbed 0:c4152c628df5 35
sPymbed 0:c4152c628df5 36 #ifdef __cplusplus
sPymbed 0:c4152c628df5 37 extern "C" {
sPymbed 0:c4152c628df5 38 #endif
sPymbed 0:c4152c628df5 39
sPymbed 0:c4152c628df5 40
sPymbed 0:c4152c628df5 41 typedef struct WOLFSSH_CTX WOLFSSH_CTX;
sPymbed 0:c4152c628df5 42 typedef struct WOLFSSH WOLFSSH;
sPymbed 0:c4152c628df5 43 typedef struct WOLFSSH_CHANNEL WOLFSSH_CHANNEL;
sPymbed 0:c4152c628df5 44
sPymbed 0:c4152c628df5 45
sPymbed 0:c4152c628df5 46 WOLFSSH_API int wolfSSH_Init(void);
sPymbed 0:c4152c628df5 47 WOLFSSH_API int wolfSSH_Cleanup(void);
sPymbed 0:c4152c628df5 48
sPymbed 0:c4152c628df5 49 /* debugging output functions */
sPymbed 0:c4152c628df5 50 WOLFSSH_API void wolfSSH_Debugging_ON(void);
sPymbed 0:c4152c628df5 51 WOLFSSH_API void wolfSSH_Debugging_OFF(void);
sPymbed 0:c4152c628df5 52
sPymbed 0:c4152c628df5 53 /* context functions */
sPymbed 0:c4152c628df5 54 WOLFSSH_API WOLFSSH_CTX* wolfSSH_CTX_new(byte, void*);
sPymbed 0:c4152c628df5 55 WOLFSSH_API void wolfSSH_CTX_free(WOLFSSH_CTX*);
sPymbed 0:c4152c628df5 56
sPymbed 0:c4152c628df5 57 /* ssh session functions */
sPymbed 0:c4152c628df5 58 WOLFSSH_API WOLFSSH* wolfSSH_new(WOLFSSH_CTX*);
sPymbed 0:c4152c628df5 59 WOLFSSH_API void wolfSSH_free(WOLFSSH*);
sPymbed 0:c4152c628df5 60
sPymbed 0:c4152c628df5 61 WOLFSSH_API int wolfSSH_set_fd(WOLFSSH*, int);
sPymbed 0:c4152c628df5 62 WOLFSSH_API int wolfSSH_get_fd(const WOLFSSH*);
sPymbed 0:c4152c628df5 63
sPymbed 0:c4152c628df5 64 /* data high water mark functions */
sPymbed 0:c4152c628df5 65 WOLFSSH_API int wolfSSH_SetHighwater(WOLFSSH*, word32);
sPymbed 0:c4152c628df5 66 WOLFSSH_API word32 wolfSSH_GetHighwater(WOLFSSH*);
sPymbed 0:c4152c628df5 67
sPymbed 0:c4152c628df5 68 typedef int (*WS_CallbackHighwater)(byte, void*);
sPymbed 0:c4152c628df5 69 WOLFSSH_API void wolfSSH_SetHighwaterCb(WOLFSSH_CTX*, word32,
sPymbed 0:c4152c628df5 70 WS_CallbackHighwater);
sPymbed 0:c4152c628df5 71 WOLFSSH_API void wolfSSH_SetHighwaterCtx(WOLFSSH*, void*);
sPymbed 0:c4152c628df5 72 WOLFSSH_API void* wolfSSH_GetHighwaterCtx(WOLFSSH*);
sPymbed 0:c4152c628df5 73
sPymbed 0:c4152c628df5 74
sPymbed 0:c4152c628df5 75 WOLFSSH_API int wolfSSH_get_error(const WOLFSSH*);
sPymbed 0:c4152c628df5 76 WOLFSSH_API const char* wolfSSH_get_error_name(const WOLFSSH*);
sPymbed 0:c4152c628df5 77
sPymbed 0:c4152c628df5 78 /* I/O callbacks */
sPymbed 0:c4152c628df5 79 typedef int (*WS_CallbackIORecv)(WOLFSSH*, void*, word32, void*);
sPymbed 0:c4152c628df5 80 typedef int (*WS_CallbackIOSend)(WOLFSSH*, void*, word32, void*);
sPymbed 0:c4152c628df5 81 WOLFSSH_API void wolfSSH_SetIORecv(WOLFSSH_CTX*, WS_CallbackIORecv);
sPymbed 0:c4152c628df5 82 WOLFSSH_API void wolfSSH_SetIOSend(WOLFSSH_CTX*, WS_CallbackIOSend);
sPymbed 0:c4152c628df5 83 WOLFSSH_API void wolfSSH_SetIOReadCtx(WOLFSSH*, void*);
sPymbed 0:c4152c628df5 84 WOLFSSH_API void wolfSSH_SetIOWriteCtx(WOLFSSH*, void*);
sPymbed 0:c4152c628df5 85 WOLFSSH_API void* wolfSSH_GetIOReadCtx(WOLFSSH*);
sPymbed 0:c4152c628df5 86 WOLFSSH_API void* wolfSSH_GetIOWriteCtx(WOLFSSH*);
sPymbed 0:c4152c628df5 87
sPymbed 0:c4152c628df5 88 /* User Authentication callback */
sPymbed 0:c4152c628df5 89 typedef struct WS_UserAuthData_Password {
sPymbed 0:c4152c628df5 90 byte* password;
sPymbed 0:c4152c628df5 91 word32 passwordSz;
sPymbed 0:c4152c628df5 92 /* The following are present for future use. */
sPymbed 0:c4152c628df5 93 byte hasNewPassword;
sPymbed 0:c4152c628df5 94 byte* newPassword;
sPymbed 0:c4152c628df5 95 word32 newPasswordSz;
sPymbed 0:c4152c628df5 96 } WS_UserAuthData_Password;
sPymbed 0:c4152c628df5 97
sPymbed 0:c4152c628df5 98 typedef struct WS_UserAuthData_PublicKey {
sPymbed 0:c4152c628df5 99 byte* dataToSign;
sPymbed 0:c4152c628df5 100 byte* publicKeyType;
sPymbed 0:c4152c628df5 101 word32 publicKeyTypeSz;
sPymbed 0:c4152c628df5 102 byte* publicKey;
sPymbed 0:c4152c628df5 103 word32 publicKeySz;
sPymbed 0:c4152c628df5 104 byte hasSignature;
sPymbed 0:c4152c628df5 105 byte* signature;
sPymbed 0:c4152c628df5 106 word32 signatureSz;
sPymbed 0:c4152c628df5 107 } WS_UserAuthData_PublicKey;
sPymbed 0:c4152c628df5 108
sPymbed 0:c4152c628df5 109 typedef struct WS_UserAuthData {
sPymbed 0:c4152c628df5 110 byte type;
sPymbed 0:c4152c628df5 111 byte* username;
sPymbed 0:c4152c628df5 112 word32 usernameSz;
sPymbed 0:c4152c628df5 113 byte* serviceName;
sPymbed 0:c4152c628df5 114 word32 serviceNameSz;
sPymbed 0:c4152c628df5 115 byte* authName;
sPymbed 0:c4152c628df5 116 word32 authNameSz;
sPymbed 0:c4152c628df5 117 union {
sPymbed 0:c4152c628df5 118 WS_UserAuthData_Password password;
sPymbed 0:c4152c628df5 119 WS_UserAuthData_PublicKey publicKey;
sPymbed 0:c4152c628df5 120 } sf;
sPymbed 0:c4152c628df5 121 } WS_UserAuthData;
sPymbed 0:c4152c628df5 122
sPymbed 0:c4152c628df5 123 typedef int (*WS_CallbackUserAuth)(byte, WS_UserAuthData*, void*);
sPymbed 0:c4152c628df5 124 WOLFSSH_API void wolfSSH_SetUserAuth(WOLFSSH_CTX*, WS_CallbackUserAuth);
sPymbed 0:c4152c628df5 125 WOLFSSH_API void wolfSSH_SetUserAuthCtx(WOLFSSH*, void*);
sPymbed 0:c4152c628df5 126 WOLFSSH_API void* wolfSSH_GetUserAuthCtx(WOLFSSH*);
sPymbed 0:c4152c628df5 127
sPymbed 0:c4152c628df5 128 WOLFSSH_API int wolfSSH_SetUsername(WOLFSSH*, const char*);
sPymbed 0:c4152c628df5 129
sPymbed 0:c4152c628df5 130 WOLFSSH_API int wolfSSH_CTX_SetBanner(WOLFSSH_CTX*, const char*);
sPymbed 0:c4152c628df5 131 WOLFSSH_API int wolfSSH_CTX_UsePrivateKey_buffer(WOLFSSH_CTX*,
sPymbed 0:c4152c628df5 132 const byte*, word32, int);
sPymbed 0:c4152c628df5 133
sPymbed 0:c4152c628df5 134 WOLFSSH_API int wolfSSH_accept(WOLFSSH*);
sPymbed 0:c4152c628df5 135 WOLFSSH_API int wolfSSH_connect(WOLFSSH*);
sPymbed 0:c4152c628df5 136 WOLFSSH_API int wolfSSH_shutdown(WOLFSSH*);
sPymbed 0:c4152c628df5 137 WOLFSSH_API int wolfSSH_stream_read(WOLFSSH*, byte*, word32);
sPymbed 0:c4152c628df5 138 WOLFSSH_API int wolfSSH_stream_send(WOLFSSH*, byte*, word32);
sPymbed 0:c4152c628df5 139 WOLFSSH_API int wolfSSH_TriggerKeyExchange(WOLFSSH*);
sPymbed 0:c4152c628df5 140
sPymbed 0:c4152c628df5 141 WOLFSSH_API void wolfSSH_GetStats(WOLFSSH*,
sPymbed 0:c4152c628df5 142 word32*, word32*, word32*, word32*);
sPymbed 0:c4152c628df5 143
sPymbed 0:c4152c628df5 144 WOLFSSH_API int wolfSSH_KDF(byte, byte, byte*, word32, const byte*, word32,
sPymbed 0:c4152c628df5 145 const byte*, word32, const byte*, word32);
sPymbed 0:c4152c628df5 146
sPymbed 0:c4152c628df5 147
sPymbed 0:c4152c628df5 148 enum WS_HighwaterSide {
sPymbed 0:c4152c628df5 149 WOLFSSH_HWSIDE_TRANSMIT,
sPymbed 0:c4152c628df5 150 WOLFSSH_HWSIDE_RECEIVE
sPymbed 0:c4152c628df5 151 };
sPymbed 0:c4152c628df5 152
sPymbed 0:c4152c628df5 153
sPymbed 0:c4152c628df5 154 enum WS_EndpointTypes {
sPymbed 0:c4152c628df5 155 WOLFSSH_ENDPOINT_SERVER,
sPymbed 0:c4152c628df5 156 WOLFSSH_ENDPOINT_CLIENT
sPymbed 0:c4152c628df5 157 };
sPymbed 0:c4152c628df5 158
sPymbed 0:c4152c628df5 159
sPymbed 0:c4152c628df5 160 enum WS_FormatTypes {
sPymbed 0:c4152c628df5 161 WOLFSSH_FORMAT_ASN1,
sPymbed 0:c4152c628df5 162 WOLFSSH_FORMAT_PEM,
sPymbed 0:c4152c628df5 163 WOLFSSH_FORMAT_RAW
sPymbed 0:c4152c628df5 164 };
sPymbed 0:c4152c628df5 165
sPymbed 0:c4152c628df5 166
sPymbed 0:c4152c628df5 167 enum WS_UserAuthTypes {
sPymbed 0:c4152c628df5 168 WOLFSSH_USERAUTH_PASSWORD,
sPymbed 0:c4152c628df5 169 WOLFSSH_USERAUTH_PUBLICKEY
sPymbed 0:c4152c628df5 170 };
sPymbed 0:c4152c628df5 171
sPymbed 0:c4152c628df5 172
sPymbed 0:c4152c628df5 173 enum WS_UserAuthResults {
sPymbed 0:c4152c628df5 174 WOLFSSH_USERAUTH_SUCCESS,
sPymbed 0:c4152c628df5 175 WOLFSSH_USERAUTH_FAILURE,
sPymbed 0:c4152c628df5 176 WOLFSSH_USERAUTH_INVALID_AUTHTYPE,
sPymbed 0:c4152c628df5 177 WOLFSSH_USERAUTH_INVALID_USER,
sPymbed 0:c4152c628df5 178 WOLFSSH_USERAUTH_INVALID_PASSWORD,
sPymbed 0:c4152c628df5 179 WOLFSSH_USERAUTH_INVALID_PUBLICKEY
sPymbed 0:c4152c628df5 180 };
sPymbed 0:c4152c628df5 181
sPymbed 0:c4152c628df5 182
sPymbed 0:c4152c628df5 183 enum WS_DisconnectReasonCodes {
sPymbed 0:c4152c628df5 184 WOLFSSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT = 1,
sPymbed 0:c4152c628df5 185 WOLFSSH_DISCONNECT_PROTOCOL_ERROR = 2,
sPymbed 0:c4152c628df5 186 WOLFSSH_DISCONNECT_KEY_EXCHANGE_FAILED = 3,
sPymbed 0:c4152c628df5 187 WOLFSSH_DISCONNECT_RESERVED = 4,
sPymbed 0:c4152c628df5 188 WOLFSSH_DISCONNECT_MAC_ERROR = 5,
sPymbed 0:c4152c628df5 189 WOLFSSH_DISCONNECT_COMPRESSION_ERROR = 6,
sPymbed 0:c4152c628df5 190 WOLFSSH_DISCONNECT_SERVICE_NOT_AVAILABLE = 7,
sPymbed 0:c4152c628df5 191 WOLFSSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED = 8,
sPymbed 0:c4152c628df5 192 WOLFSSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE = 9,
sPymbed 0:c4152c628df5 193 WOLFSSH_DISCONNECT_CONNECTION_LOST = 10,
sPymbed 0:c4152c628df5 194 WOLFSSH_DISCONNECT_BY_APPLICATION = 11,
sPymbed 0:c4152c628df5 195 WOLFSSH_DISCONNECT_TOO_MANY_CONNECTIONS = 12,
sPymbed 0:c4152c628df5 196 WOLFSSH_DISCONNECT_AUTH_CANCELLED_BY_USER = 13,
sPymbed 0:c4152c628df5 197 WOLFSSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE = 14,
sPymbed 0:c4152c628df5 198 WOLFSSH_DISCONNECT_ILLEGAL_USER_NAME = 15
sPymbed 0:c4152c628df5 199 };
sPymbed 0:c4152c628df5 200
sPymbed 0:c4152c628df5 201
sPymbed 0:c4152c628df5 202 #ifdef __cplusplus
sPymbed 0:c4152c628df5 203 }
sPymbed 0:c4152c628df5 204 #endif
sPymbed 0:c4152c628df5 205