mirror of https://github.com/wolfSSL/wolfssh.git
Moved the handshake data into its own structure so it can be freed when
the handshake completes.pull/1/head
parent
f07f623ad6
commit
0feaaab922
|
@ -537,7 +537,7 @@ static int DoKexInit(WOLFSSH* ssh, uint8_t* buf, uint32_t len, uint32_t* idx)
|
||||||
begin += 4 + skipSz;
|
begin += 4 + skipSz;
|
||||||
|
|
||||||
/* First KEX Packet Follows */
|
/* First KEX Packet Follows */
|
||||||
ssh->kexPacketFollows = buf[begin];
|
ssh->handshake->kexPacketFollows = buf[begin];
|
||||||
begin += 1;
|
begin += 1;
|
||||||
|
|
||||||
/* Skip the "for future use" length. */
|
/* Skip the "for future use" length. */
|
||||||
|
@ -656,15 +656,15 @@ int ProcessClientVersion(WOLFSSH* ssh)
|
||||||
return WS_VERSION_E;
|
return WS_VERSION_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssh->peerId = (char*)WMALLOC(ssh->inputBuffer.length-1, ssh->ctx->heap, WOLFSSH_ID_TYPE);
|
ssh->handshake->peerId = (char*)WMALLOC(ssh->inputBuffer.length-1, ssh->ctx->heap, WOLFSSH_ID_TYPE);
|
||||||
if (ssh->peerId == NULL) {
|
if (ssh->handshake->peerId == NULL) {
|
||||||
return WS_MEMORY_E;
|
return WS_MEMORY_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
WMEMCPY(ssh->peerId, ssh->inputBuffer.buffer, ssh->inputBuffer.length-2);
|
WMEMCPY(ssh->handshake->peerId, ssh->inputBuffer.buffer, ssh->inputBuffer.length-2);
|
||||||
ssh->peerId[ssh->inputBuffer.length - 1] = 0;
|
ssh->handshake->peerId[ssh->inputBuffer.length - 1] = 0;
|
||||||
ssh->inputBuffer.idx += ssh->inputBuffer.length;
|
ssh->inputBuffer.idx += ssh->inputBuffer.length;
|
||||||
WLOG(WS_LOG_DEBUG, "%s", ssh->peerId);
|
WLOG(WS_LOG_DEBUG, "%s", ssh->handshake->peerId);
|
||||||
|
|
||||||
return WS_SUCCESS;
|
return WS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
29
src/ssh.c
29
src/ssh.c
|
@ -114,12 +114,21 @@ void wolfSSH_CTX_free(WOLFSSH_CTX* ctx)
|
||||||
|
|
||||||
static WOLFSSH* SshInit(WOLFSSH* ssh, WOLFSSH_CTX* ctx)
|
static WOLFSSH* SshInit(WOLFSSH* ssh, WOLFSSH_CTX* ctx)
|
||||||
{
|
{
|
||||||
|
HandshakeInfo* handshake;
|
||||||
|
|
||||||
WLOG(WS_LOG_DEBUG, "Enter SshInit()");
|
WLOG(WS_LOG_DEBUG, "Enter SshInit()");
|
||||||
|
|
||||||
if (ssh == NULL)
|
if (ssh == NULL)
|
||||||
return ssh;
|
return ssh;
|
||||||
|
|
||||||
|
handshake = (HandshakeInfo*)WMALLOC(sizeof(HandshakeInfo), ctx->heap, WOLFSSH_HANDSHAKE_TYPE);
|
||||||
|
if (handshake == NULL) {
|
||||||
|
wolfSSH_free(ssh);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
WMEMSET(ssh, 0, sizeof(WOLFSSH)); /* default init to zeros */
|
WMEMSET(ssh, 0, sizeof(WOLFSSH)); /* default init to zeros */
|
||||||
|
WMEMSET(handshake, 0, sizeof(HandshakeInfo));
|
||||||
|
|
||||||
ssh->ctx = ctx;
|
ssh->ctx = ctx;
|
||||||
ssh->rfd = -1; /* set to invalid */
|
ssh->rfd = -1; /* set to invalid */
|
||||||
|
@ -131,12 +140,16 @@ static WOLFSSH* SshInit(WOLFSSH* ssh, WOLFSSH_CTX* ctx)
|
||||||
ssh->publicKeyId = ID_NONE;
|
ssh->publicKeyId = ID_NONE;
|
||||||
ssh->encryptionId = ID_NONE;
|
ssh->encryptionId = ID_NONE;
|
||||||
ssh->integrityId = ID_NONE;
|
ssh->integrityId = ID_NONE;
|
||||||
ssh->pendingKeyExchangeId = ID_NONE;
|
ssh->handshake = handshake;
|
||||||
ssh->pendingPublicKeyId = ID_NONE;
|
handshake->keyExchangeId = ID_NONE;
|
||||||
ssh->pendingEncryptionId = ID_NONE;
|
handshake->publicKeyId = ID_NONE;
|
||||||
ssh->pendingIntegrityId = ID_NONE;
|
handshake->encryptionId = ID_NONE;
|
||||||
|
handshake->integrityId = ID_NONE;
|
||||||
|
|
||||||
if (BufferInit(&ssh->inputBuffer, 0, ctx->heap) != WS_SUCCESS ||
|
if (BufferInit(&ssh->inputBuffer, 0, ctx->heap) != WS_SUCCESS ||
|
||||||
BufferInit(&ssh->outputBuffer, 0, ctx->heap) != WS_SUCCESS) {
|
BufferInit(&ssh->outputBuffer, 0, ctx->heap) != WS_SUCCESS ||
|
||||||
|
InitSha(&ssh->handshake->hash) != 0) {
|
||||||
|
|
||||||
wolfSSH_free(ssh);
|
wolfSSH_free(ssh);
|
||||||
ssh = NULL;
|
ssh = NULL;
|
||||||
}
|
}
|
||||||
|
@ -174,9 +187,13 @@ static void SshResourceFree(WOLFSSH* ssh, void* heap)
|
||||||
(void)heap;
|
(void)heap;
|
||||||
|
|
||||||
WLOG(WS_LOG_DEBUG, "Enter sshResourceFree()");
|
WLOG(WS_LOG_DEBUG, "Enter sshResourceFree()");
|
||||||
WFREE(ssh->peerId, heap, WOLFSSH_ID_TYPE);
|
|
||||||
ShrinkBuffer(&ssh->inputBuffer, 1);
|
ShrinkBuffer(&ssh->inputBuffer, 1);
|
||||||
ShrinkBuffer(&ssh->outputBuffer, 1);
|
ShrinkBuffer(&ssh->outputBuffer, 1);
|
||||||
|
if (ssh->handshake) {
|
||||||
|
XFREE(ssh->handshake->peerId, heap, WOLFSSH_ID_TYPE);
|
||||||
|
XMEMSET(ssh->handshake, 0, sizeof(HandshakeInfo));
|
||||||
|
XFREE(ssh->handshake, heap, WOLFSSH_HANDSHAKE_TYPE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -121,6 +121,19 @@ struct WOLFSSH_CTX {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct HandshakeInfo {
|
||||||
|
char* peerId;
|
||||||
|
uint8_t keyExchangeId;
|
||||||
|
uint8_t publicKeyId;
|
||||||
|
uint8_t encryptionId;
|
||||||
|
uint8_t integrityId;
|
||||||
|
uint8_t kexPacketFollows;
|
||||||
|
|
||||||
|
Sha hash;
|
||||||
|
uint8_t session_id[SHA_DIGEST_SIZE];
|
||||||
|
} HandshakeInfo;
|
||||||
|
|
||||||
|
|
||||||
/* our wolfSSH session */
|
/* our wolfSSH session */
|
||||||
struct WOLFSSH {
|
struct WOLFSSH {
|
||||||
WOLFSSH_CTX* ctx; /* owner context */
|
WOLFSSH_CTX* ctx; /* owner context */
|
||||||
|
@ -146,21 +159,13 @@ struct WOLFSSH {
|
||||||
uint8_t publicKeyId;
|
uint8_t publicKeyId;
|
||||||
uint8_t encryptionId;
|
uint8_t encryptionId;
|
||||||
uint8_t integrityId;
|
uint8_t integrityId;
|
||||||
uint8_t kexPacketFollows;
|
|
||||||
|
|
||||||
char* peerId;
|
|
||||||
|
|
||||||
uint8_t pendingKeyExchangeId;
|
|
||||||
uint8_t pendingPublicKeyId;
|
|
||||||
uint8_t pendingEncryptionId;
|
|
||||||
uint8_t pendingIntegrityId;
|
|
||||||
|
|
||||||
Buffer inputBuffer;
|
Buffer inputBuffer;
|
||||||
Buffer outputBuffer;
|
Buffer outputBuffer;
|
||||||
|
|
||||||
Sha handshakeHash;
|
|
||||||
uint8_t session_id[SHA_DIGEST_SIZE];
|
|
||||||
uint8_t H[SHA_DIGEST_SIZE];
|
uint8_t H[SHA_DIGEST_SIZE];
|
||||||
|
|
||||||
|
HandshakeInfo* handshake;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -87,10 +87,11 @@ enum WS_EndpointTypes {
|
||||||
|
|
||||||
/* dynamic memory types */
|
/* dynamic memory types */
|
||||||
enum WS_DynamicTypes {
|
enum WS_DynamicTypes {
|
||||||
WOLFSSH_CTX_TYPE = 1,
|
WOLFSSH_CTX_TYPE = 1,
|
||||||
WOLFSSH_TYPE = 2,
|
WOLFSSH_TYPE = 2,
|
||||||
WOLFSSH_TYPE_BUFFER = 3,
|
WOLFSSH_TYPE_BUFFER = 3,
|
||||||
WOLFSSH_ID_TYPE = 4
|
WOLFSSH_ID_TYPE = 4,
|
||||||
|
WOLFSSH_HANDSHAKE_TYPE = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue