mirror of https://github.com/wolfSSL/wolfssh.git
1. Removed some unneeded functions and data types.
2. Added some new data for sequence numbering and for key exchange.pull/1/head
parent
b331ff9cba
commit
e03a1011d2
76
src/ssh.c
76
src/ssh.c
|
@ -130,6 +130,14 @@ static WOLFSSH* SshInit(WOLFSSH* ssh, WOLFSSH_CTX* ctx)
|
|||
ssh->ioReadCtx = &ssh->rfd; /* prevent invalid access if not correctly */
|
||||
ssh->ioWriteCtx = &ssh->wfd; /* set */
|
||||
ssh->blockSz = 8;
|
||||
ssh->keyExchangeId = ID_NONE;
|
||||
ssh->publicKeyId = ID_NONE;
|
||||
ssh->encryptionId = ID_NONE;
|
||||
ssh->integrityId = ID_NONE;
|
||||
ssh->pendingKeyExchangeId = ID_NONE;
|
||||
ssh->pendingPublicKeyId = ID_NONE;
|
||||
ssh->pendingEncryptionId = ID_NONE;
|
||||
ssh->pendingIntegrityId = ID_NONE;
|
||||
ssh->inputBuffer = BufferNew(0, ctx->heap);
|
||||
ssh->outputBuffer = BufferNew(0, ctx->heap);
|
||||
|
||||
|
@ -180,70 +188,6 @@ void wolfSSH_free(WOLFSSH* ssh)
|
|||
}
|
||||
|
||||
|
||||
static WOLFSSH_CHAN* SshChanInit(WOLFSSH_CHAN* chan, WOLFSSH* ssh)
|
||||
{
|
||||
WLOG(WS_LOG_DEBUG, "Enter SshChanInit()");
|
||||
|
||||
if (chan == NULL)
|
||||
return chan;
|
||||
|
||||
WMEMSET(chan, 0, sizeof(WOLFSSH_CHAN)); /* default init to zeros */
|
||||
|
||||
if (ssh) {
|
||||
chan->ssh = ssh;
|
||||
chan->ctx = ssh->ctx;
|
||||
}
|
||||
else {
|
||||
WLOG(WS_LOG_ERROR, "Trying to init a wolfSSH_CHAN w/o wolfSSH");
|
||||
wolfSSH_CHAN_free(chan);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return chan;
|
||||
}
|
||||
|
||||
|
||||
WOLFSSH_CHAN* wolfSSH_CHAN_new(WOLFSSH* ssh)
|
||||
{
|
||||
WOLFSSH_CHAN* chan;
|
||||
void* heap = NULL;
|
||||
|
||||
WLOG(WS_LOG_DEBUG, "Enter wolfSSH_CHAN_new()");
|
||||
|
||||
if (ssh != NULL && ssh->ctx != NULL)
|
||||
heap = ssh->ctx->heap;
|
||||
|
||||
chan = (WOLFSSH_CHAN*)WMALLOC(sizeof(WOLFSSH_CHAN),
|
||||
heap, WOLFSSH_CHAN_TYPE);
|
||||
|
||||
chan = SshChanInit(chan, ssh);
|
||||
|
||||
WLOG(WS_LOG_DEBUG, "Leaving wolfSSH_CHAN_new(), chan = %p", chan);
|
||||
|
||||
return chan;
|
||||
}
|
||||
|
||||
|
||||
static void SshChanResourceFree(WOLFSSH_CHAN* chan)
|
||||
{
|
||||
/* when ssh channel holds resources, free here */
|
||||
(void)chan;
|
||||
|
||||
WLOG(WS_LOG_DEBUG, "Enter SshChanResourceFree()");
|
||||
}
|
||||
|
||||
|
||||
void wolfSSH_CHAN_free(WOLFSSH_CHAN* chan)
|
||||
{
|
||||
WLOG(WS_LOG_DEBUG, "Enter wolfSCEP_free()");
|
||||
|
||||
if (chan) {
|
||||
SshChanResourceFree(chan);
|
||||
WFREE(chan, chan->ctx ? chan->ctx->heap : NULL, WOLFSCEP_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int wolfSSH_set_fd(WOLFSSH* ssh, int fd)
|
||||
{
|
||||
WLOG(WS_LOG_DEBUG, "Enter wolfSSH_set_fd()");
|
||||
|
@ -523,12 +467,12 @@ static int DoKexInit(WOLFSSH* ssh, uint8_t* buf, uint32_t len, uint32_t* idx)
|
|||
* uint32 0 (reserved for future extension)
|
||||
*/
|
||||
|
||||
/* Save the peer's cookie. */
|
||||
/* Check that the cookie exists inside the message */
|
||||
if (begin + COOKIE_SZ > len) {
|
||||
/* error, out of bounds */
|
||||
return -1;
|
||||
}
|
||||
WMEMCPY(ssh->peerCookie, buf + begin, COOKIE_SZ);
|
||||
/* Move past the cookie. */
|
||||
begin += COOKIE_SZ;
|
||||
|
||||
/* KEX Algorithms */
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <wolfssh/ssh.h>
|
||||
#include <cyassl/ctaocrypt/sha.h>
|
||||
|
||||
|
||||
#if !defined (ALIGN16)
|
||||
|
@ -98,12 +99,14 @@ struct WOLFSSH {
|
|||
void* ioWriteCtx; /* I/O Write Context handle */
|
||||
int rflags; /* optional read flags */
|
||||
int wflags; /* optional write flags */
|
||||
WOLFSSH_CHAN* channel; /* single data channel */
|
||||
uint32_t curSz;
|
||||
uint32_t seq;
|
||||
uint32_t peerSeq;
|
||||
uint8_t blockSz;
|
||||
uint8_t acceptState;
|
||||
uint8_t clientState;
|
||||
uint8_t processReplyState;
|
||||
|
||||
uint8_t connReset;
|
||||
uint8_t isClosed;
|
||||
|
||||
|
@ -115,19 +118,17 @@ struct WOLFSSH {
|
|||
|
||||
char* peerId;
|
||||
|
||||
uint8_t peerCookie[COOKIE_SZ];
|
||||
uint8_t myCookie[COOKIE_SZ];
|
||||
uint8_t pendingKeyExchangeId;
|
||||
uint8_t pendingPublicKeyId;
|
||||
uint8_t pendingEncryptionId;
|
||||
uint8_t pendingIntegrityId;
|
||||
|
||||
struct Buffer* inputBuffer;
|
||||
struct Buffer* outputBuffer;
|
||||
};
|
||||
|
||||
|
||||
/* wolfSSH channel */
|
||||
struct WOLFSSH_CHAN {
|
||||
WOLFSSH_CTX* ctx;
|
||||
WOLFSSH* ssh;
|
||||
int id;
|
||||
Sha handshakeHash;
|
||||
uint8_t session_id[SHA_DIGEST_SIZE];
|
||||
uint8_t H[SHA_DIGEST_SIZE];
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -31,9 +31,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct WOLFSSH_CTX WOLFSSH_CTX;
|
||||
typedef struct WOLFSSH WOLFSSH;
|
||||
typedef struct WOLFSSH_CHAN WOLFSSH_CHAN;
|
||||
|
||||
|
||||
WOLFSSH_API int wolfSSH_Init(void);
|
||||
WOLFSSH_API int wolfSSH_Cleanup(void);
|
||||
|
@ -50,10 +51,6 @@ WOLFSSH_API void wolfSSH_CTX_free(WOLFSSH_CTX*);
|
|||
WOLFSSH_API WOLFSSH* wolfSSH_new(WOLFSSH_CTX*);
|
||||
WOLFSSH_API void wolfSSH_free(WOLFSSH*);
|
||||
|
||||
/* ssh channel functions */
|
||||
WOLFSSH_API WOLFSSH_CHAN* wolfSSH_CHAN_new(WOLFSSH*);
|
||||
WOLFSSH_API void wolfSSH_CHAN_free(WOLFSSH_CHAN*);
|
||||
|
||||
WOLFSSH_API int wolfSSH_set_fd(WOLFSSH*, int);
|
||||
WOLFSSH_API int wolfSSH_get_fd(const WOLFSSH*);
|
||||
|
||||
|
@ -63,10 +60,6 @@ WOLFSSH_API const char* wolfSSH_get_error(int);
|
|||
typedef int (*WS_CallbackIORecv)(WOLFSSH*, void*, uint32_t, void*);
|
||||
typedef int (*WS_CallbackIOSend)(WOLFSSH*, void*, uint32_t, void*);
|
||||
|
||||
/* Channel I/O callbacks */
|
||||
typedef int (*WSH_CallbackChanRecv)(WOLFSSH*, void*, uint32_t, void*);
|
||||
typedef int (*WSH_CallbackChanSend)(WOLFSSH*, void*, uint32_t, void*);
|
||||
|
||||
WOLFSSH_API void wolfSSH_SetIORecv(WOLFSSH_CTX*, WS_CallbackIORecv);
|
||||
WOLFSSH_API void wolfSSH_SetIOSend(WOLFSSH_CTX*, WS_CallbackIOSend);
|
||||
|
||||
|
@ -83,9 +76,8 @@ WOLFSSH_API int wolfSSH_accept(WOLFSSH* ssh);
|
|||
enum WS_DynamicTypes {
|
||||
WOLFSSH_CTX_TYPE = 1,
|
||||
WOLFSSH_TYPE = 2,
|
||||
WOLFSSH_CHAN_TYPE = 3,
|
||||
WOLFSSH_TYPE_BUFFER = 4,
|
||||
WOLFSSH_ID_TYPE = 5
|
||||
WOLFSSH_TYPE_BUFFER = 3,
|
||||
WOLFSSH_ID_TYPE = 4
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue