mirror of
https://github.com/libssh2/libssh2.git
synced 2026-10-24 03:48:58 +03:00
src: shorten namespace for private functions and macros
From `_libssh2_*` to `ssh2_*`, `LIBSSH2_*` -> `SSH2_*`. To make the code easier to read, write, to fit more into the maximum line width without folding, and to avoid using reserved namespace (`_*`). Namespacing after this patch: - `libssh2_`, `LIBSSH2_` (rarely preceded with `_`): public API. - `ssh2_`, `SSH2_`: private API. - `ssh2_<crypto-backend>_`: non-static crypto functions. where `<crypto-backend>` is: lgcr, mbed, ossl, wcng, os400qc3 - local macros and static functions try to be short, descriptive of their scope, without strict namespacing. They also avoid namespaces used above for clarity. Also: - reflow using clang-format (and manually where necessary.) - merge split error strings where possible (manually). - shorten `_libssh2_debug()` to `ssh2_deb()`. - shorten `_libssh2_error()` to `ssh2_err()`. - move `libssh2_*` internal symbols to the `ssh2_*` namespace. - shorten local macro/enum prefixes from `LIBSSH2_` to `SSH2_`. - mbedtls, wincng: move static functions to the local namespace, where missing. - drop stray no-op `ssh2_init_aes_ctr()` symbols (libgcrypt, mbedtls). - move crypto primitives to crypto-local namespace `ssh2_(lgcr|mbed|ossl|wcng)_`, where missing. - normalize crypo-local and crypto-static function namespace to: `mbed_*`, `ssh2_mbed_,*` `wcng_*`, `ssh2_wcng_*`. - `LIBSSH2_CIPHER_T()` -> `SSH2_CIPHER_T()` Follow-up to689b202320#1923 - rename `ssh2_store_bignum2_bytes()` -> `ssh2_store_bignum_bytes()`. - drop redundant `void *` cast from `SSH2_UNCONST()` values. - os400qc3: drop unused static `ssh2_bn_from_bn()`. - os400qc3: move static `ssh2_bn_resize()` off the ssh2 namespace. - libssh2.rpgle.in: drop private macros `LIBSSH2_DH_GEX*`. - rename `ARRAY_SIZE()` to `SSH2_ARRAYSIZE()` for uniqueness. - agent: drop unused/commented `SSH_AGENTC_*` protocol 1 macros. - fix stray symbol references found in comments. - minor whitespace fixes along the way. Note: - `ssh2` as a namespace has the minor downside of potential confusion with SSH protocol 2 (vs 1). In practice I think this is fine. - `SSH2_` prefix has been used in two places before this patch: 4 `SSH2_AGENT*` macros in `agent.c` and 2 `SSH2_MSG_KEX_ECDH_*` macros in `libssh2_priv.h`. The latter is coming from https://datatracker.ietf.org/doc/html/rfc9941. If this ever creates confusion they can be moved under an `IETF_` namespace for example. - libssh2_userauth_publickey_sk: the public man page says the callbacks needs to be using `LIBSSH2_ALLOC()` for allocation and responsible for freeing. It's an internal macro and should not be mentioned or necessary in public docs. Ref:ed439a29bb#698 Follow-up to8c9b7771ee#1931 Follow-up to689b202320#1923 Ref: #1949 Closes #1961
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -128,13 +128,13 @@ to the callback.
|
||||
*sig_r* - For Ed25519 signatures, this contains the entire signature, as
|
||||
returned directly from the authenticator. For ECDSA signatures, this contains
|
||||
the r component of the signature in a big-endian binary representation. For
|
||||
both algorithms, use LIBSSH2_ALLOC to allocate memory. It is freed by the
|
||||
both algorithms, use SSH2_ALLOC to allocate memory. It is freed by the
|
||||
caller.
|
||||
|
||||
*sig_r_len* - The length of the sig_r parameter.
|
||||
|
||||
*sig_s* - For ECDSA signatures, this contains the s component of the
|
||||
signature in a big-endian binary representation. Use LIBSSH2_ALLOC to allocate
|
||||
signature in a big-endian binary representation. Use SSH2_ALLOC to allocate
|
||||
memory. It is freed by the caller. For Ed25519 signatures, set this to
|
||||
NULL.
|
||||
|
||||
|
||||
@@ -57,9 +57,9 @@
|
||||
|
||||
#define OFFSET_OF(t, f) ((size_t) ((char *) &((t *) 0)->f - (char *) 0))
|
||||
|
||||
#define ALLOC(s, sz) ((s) ? LIBSSH2_ALLOC(s, sz) : malloc(sz))
|
||||
#define REALLOC(s, p, sz) ((s) ? LIBSSH2_REALLOC(s, p, sz) : realloc(p, sz))
|
||||
#define FREE(s, p) ((s) ? LIBSSH2_FREE(s, p) : free(p))
|
||||
#define ALLOC(s, sz) ((s) ? SSH2_ALLOC(s, sz) : malloc(sz))
|
||||
#define REALLOC(s, p, sz) ((s) ? SSH2_REALLOC(s, p, sz) : realloc(p, sz))
|
||||
#define FREE(s, p) ((s) ? SSH2_FREE(s, p) : free(p))
|
||||
|
||||
struct _libssh2_string_cache {
|
||||
libssh2_string_cache * next;
|
||||
|
||||
@@ -177,15 +177,6 @@
|
||||
d LIBSSH2_SSH_DEFAULT_BANNER...
|
||||
d c 'SSH-2.0-libssh2_@LIBSSH2_VERSION@'
|
||||
|
||||
* Default generate and safe prime sizes for
|
||||
* diffie-hellman-group-exchange-sha1.
|
||||
d LIBSSH2_DH_GEX_MINGROUP...
|
||||
d c 1024
|
||||
d LIBSSH2_DH_GEX_OPTGROUP...
|
||||
d c 1536
|
||||
d LIBSSH2_DH_GEX_MAXGROUP...
|
||||
d c 2048
|
||||
|
||||
* Defaults for pty requests.
|
||||
d LIBSSH2_TERM_WIDTH...
|
||||
d c 80
|
||||
|
||||
321
src/agent.c
321
src/agent.c
@@ -60,16 +60,6 @@
|
||||
#include "userauth.h"
|
||||
#include "session.h"
|
||||
|
||||
#if 0
|
||||
/* Requests from client to agent for protocol 1 key operations */
|
||||
#define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1
|
||||
#define SSH_AGENTC_RSA_CHALLENGE 3
|
||||
#define SSH_AGENTC_ADD_RSA_IDENTITY 7
|
||||
#define SSH_AGENTC_REMOVE_RSA_IDENTITY 8
|
||||
#define SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9
|
||||
#define SSH_AGENTC_ADD_RSA_ID_CONSTRAINED 24
|
||||
#endif
|
||||
|
||||
/* Requests from client to agent for protocol 2 key operations */
|
||||
#define SSH2_AGENTC_REQUEST_IDENTITIES 11
|
||||
#define SSH2_AGENTC_SIGN_REQUEST 13
|
||||
@@ -262,25 +252,19 @@ static int agent_connect_openssh(LIBSSH2_AGENT *agent)
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
pipe = CreateFileA(
|
||||
path,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
NULL,
|
||||
OPEN_EXISTING,
|
||||
/* Non-blocking mode for agent connections is not implemented at
|
||||
* the point this was implemented. The code for Win32 OpenSSH
|
||||
* should support non-blocking IO, but the code calling it does not
|
||||
* support it as of yet.
|
||||
* When non-blocking I/O is implemented for the surrounding code,
|
||||
* uncomment the following line to enable support within the Win32
|
||||
* OpenSSH code.
|
||||
*/
|
||||
/* FILE_FLAG_OVERLAPPED | */
|
||||
SECURITY_SQOS_PRESENT |
|
||||
SECURITY_IDENTIFICATION,
|
||||
NULL
|
||||
);
|
||||
/* Non-blocking mode for agent connections is not implemented at
|
||||
* the point this was implemented. The code for Win32 OpenSSH
|
||||
* should support non-blocking IO, but the code calling it does not
|
||||
* support it as of yet.
|
||||
* When non-blocking I/O is implemented for the surrounding code,
|
||||
* uncomment the following line to enable support within the Win32
|
||||
* OpenSSH code.
|
||||
*/
|
||||
pipe = CreateFileA(path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
|
||||
OPEN_EXISTING,
|
||||
/* FILE_FLAG_OVERLAPPED | */
|
||||
SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION,
|
||||
NULL);
|
||||
|
||||
if(pipe != INVALID_HANDLE_VALUE)
|
||||
break;
|
||||
@@ -293,21 +277,21 @@ static int agent_connect_openssh(LIBSSH2_AGENT *agent)
|
||||
}
|
||||
|
||||
if(pipe == INVALID_HANDLE_VALUE) {
|
||||
ret = _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"unable to connect to agent pipe");
|
||||
ret = ssh2_err(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"unable to connect to agent pipe");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if(SetHandleInformation(pipe, HANDLE_FLAG_INHERIT, 0) == FALSE) {
|
||||
ret = _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"unable to set handle information of agent pipe");
|
||||
ret = ssh2_err(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"unable to set handle information of agent pipe");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
event = CreateEventA(NULL, TRUE, FALSE, NULL);
|
||||
if(!event) {
|
||||
ret = _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"unable to create async I/O event");
|
||||
ret = ssh2_err(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"unable to create async I/O event");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@@ -382,14 +366,14 @@ static int agent_transact_openssh(LIBSSH2_AGENT *agent,
|
||||
|
||||
/* Send the length of the request */
|
||||
if(transctx->state == agent_NB_state_request_created) {
|
||||
_libssh2_htonu32(buf, (uint32_t)transctx->request_len);
|
||||
ssh2_htonu32(buf, (uint32_t)transctx->request_len);
|
||||
rc = win32_openssh_send_all(agent, buf, sizeof(buf),
|
||||
&transctx->send_recv_total);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
else if(rc < 0)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"agent send failed");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"agent send failed");
|
||||
transctx->state = agent_NB_state_request_length_sent;
|
||||
}
|
||||
|
||||
@@ -401,8 +385,8 @@ static int agent_transact_openssh(LIBSSH2_AGENT *agent,
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
else if(rc < 0)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"agent send failed");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"agent send failed");
|
||||
transctx->state = agent_NB_state_request_sent;
|
||||
}
|
||||
|
||||
@@ -413,11 +397,11 @@ static int agent_transact_openssh(LIBSSH2_AGENT *agent,
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
else if(rc < 0)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_RECV,
|
||||
"agent recv failed");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_RECV,
|
||||
"agent recv failed");
|
||||
|
||||
transctx->response_len = _libssh2_ntohu32(buf);
|
||||
transctx->response = LIBSSH2_ALLOC(agent->session,
|
||||
transctx->response_len = ssh2_ntohu32(buf);
|
||||
transctx->response = SSH2_ALLOC(agent->session,
|
||||
transctx->response_len);
|
||||
if(!transctx->response)
|
||||
return LIBSSH2_ERROR_ALLOC;
|
||||
@@ -433,8 +417,8 @@ static int agent_transact_openssh(LIBSSH2_AGENT *agent,
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
else if(rc < 0)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_RECV,
|
||||
"agent recv failed");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_RECV,
|
||||
"agent recv failed");
|
||||
transctx->state = agent_NB_state_response_received;
|
||||
}
|
||||
|
||||
@@ -444,17 +428,17 @@ static int agent_transact_openssh(LIBSSH2_AGENT *agent,
|
||||
static int agent_disconnect_openssh(LIBSSH2_AGENT *agent)
|
||||
{
|
||||
if(!CancelIo(agent->pipe))
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
|
||||
"failed to cancel pending IO of agent pipe");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
|
||||
"failed to cancel pending IO of agent pipe");
|
||||
if(!CloseHandle(agent->overlapped.hEvent))
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
|
||||
"failed to close handle to async I/O event");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
|
||||
"failed to close handle to async I/O event");
|
||||
agent->overlapped.hEvent = NULL;
|
||||
/* let queued APCs (if any) drain */
|
||||
SleepEx(0, TRUE);
|
||||
if(!CloseHandle(agent->pipe))
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
|
||||
"failed to close handle to agent pipe");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
|
||||
"failed to close handle to agent pipe");
|
||||
|
||||
agent->pipe = INVALID_HANDLE_VALUE;
|
||||
agent->fd = LIBSSH2_INVALID_SOCKET;
|
||||
@@ -481,20 +465,20 @@ static int agent_connect_unix(LIBSSH2_AGENT *agent)
|
||||
if(!path) {
|
||||
path = getenv("SSH_AUTH_SOCK");
|
||||
if(!path)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_BAD_USE,
|
||||
"no auth sock variable");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_BAD_USE,
|
||||
"no auth sock variable");
|
||||
}
|
||||
|
||||
agent->fd = socket(PF_UNIX, SOCK_STREAM, 0);
|
||||
if(agent->fd < 0)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_BAD_SOCKET,
|
||||
"failed creating socket");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_BAD_SOCKET,
|
||||
"failed creating socket");
|
||||
|
||||
plen = strlen(path);
|
||||
if(plen >= sizeof(s_un.sun_path)) {
|
||||
close(agent->fd);
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"SSH_AUTH_SOCK path too long");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"SSH_AUTH_SOCK path too long");
|
||||
}
|
||||
|
||||
s_un.sun_family = AF_UNIX;
|
||||
@@ -503,8 +487,8 @@ static int agent_connect_unix(LIBSSH2_AGENT *agent)
|
||||
|
||||
if(connect(agent->fd, (struct sockaddr *)(&s_un), sizeof(s_un)) != 0) {
|
||||
close(agent->fd);
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"failed connecting with agent");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"failed connecting with agent");
|
||||
}
|
||||
|
||||
return LIBSSH2_ERROR_NONE;
|
||||
@@ -532,8 +516,7 @@ static ssize_t _send_all(LIBSSH2_SEND_FUNC(func), libssh2_socket_t socket,
|
||||
const void *buffer, size_t length,
|
||||
int flags, void **abstract)
|
||||
{
|
||||
RECV_SEND_ALL(func, socket, LIBSSH2_UNCONST(buffer), length,
|
||||
flags, abstract);
|
||||
RECV_SEND_ALL(func, socket, SSH2_UNCONST(buffer), length, flags, abstract);
|
||||
}
|
||||
|
||||
static ssize_t _recv_all(LIBSSH2_RECV_FUNC(func), libssh2_socket_t socket,
|
||||
@@ -551,15 +534,15 @@ static int agent_transact_unix(LIBSSH2_AGENT *agent,
|
||||
|
||||
/* Send the length of the request */
|
||||
if(transctx->state == agent_NB_state_request_created) {
|
||||
_libssh2_htonu32(buf, (uint32_t)transctx->request_len);
|
||||
ssh2_htonu32(buf, (uint32_t)transctx->request_len);
|
||||
rc = (int)_send_all(agent->session->send, agent->fd,
|
||||
buf, sizeof(buf), 0,
|
||||
&agent->session->abstract);
|
||||
if(rc == -EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
else if(rc < 0)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"agent send failed");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"agent send failed");
|
||||
transctx->state = agent_NB_state_request_length_sent;
|
||||
}
|
||||
|
||||
@@ -571,8 +554,8 @@ static int agent_transact_unix(LIBSSH2_AGENT *agent,
|
||||
if(rc == -EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
else if(rc < 0)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"agent send failed");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"agent send failed");
|
||||
transctx->state = agent_NB_state_request_sent;
|
||||
}
|
||||
|
||||
@@ -584,11 +567,11 @@ static int agent_transact_unix(LIBSSH2_AGENT *agent,
|
||||
if(rc < 0) {
|
||||
if(rc == -EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_RECV,
|
||||
"agent recv failed");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_RECV,
|
||||
"agent recv failed");
|
||||
}
|
||||
transctx->response_len = _libssh2_ntohu32(buf);
|
||||
transctx->response = LIBSSH2_ALLOC(agent->session,
|
||||
transctx->response_len = ssh2_ntohu32(buf);
|
||||
transctx->response = SSH2_ALLOC(agent->session,
|
||||
transctx->response_len);
|
||||
if(!transctx->response)
|
||||
return LIBSSH2_ERROR_ALLOC;
|
||||
@@ -604,8 +587,8 @@ static int agent_transact_unix(LIBSSH2_AGENT *agent,
|
||||
if(rc < 0) {
|
||||
if(rc == -EAGAIN)
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_RECV,
|
||||
"agent recv failed");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_RECV,
|
||||
"agent recv failed");
|
||||
}
|
||||
transctx->state = agent_NB_state_response_received;
|
||||
}
|
||||
@@ -620,8 +603,8 @@ static int agent_disconnect_unix(LIBSSH2_AGENT *agent)
|
||||
if(ret != -1)
|
||||
agent->fd = LIBSSH2_INVALID_SOCKET;
|
||||
else
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
|
||||
"failed closing the agent socket");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_SOCKET_DISCONNECT,
|
||||
"failed closing the agent socket");
|
||||
return LIBSSH2_ERROR_NONE;
|
||||
}
|
||||
|
||||
@@ -648,8 +631,8 @@ static int agent_connect_pageant(LIBSSH2_AGENT *agent)
|
||||
HWND hwnd;
|
||||
hwnd = FindWindowA("Pageant", "Pageant");
|
||||
if(!hwnd)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"failed connecting agent");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"failed connecting agent");
|
||||
agent->fd = 0; /* Mark as the connection has been established */
|
||||
return LIBSSH2_ERROR_NONE;
|
||||
}
|
||||
@@ -666,13 +649,12 @@ static int agent_transact_pageant(LIBSSH2_AGENT *agent,
|
||||
COPYDATASTRUCT cds;
|
||||
|
||||
if(!transctx || 4 + transctx->request_len > PAGEANT_MAX_MSGLEN)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_INVAL,
|
||||
"illegal input");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_INVAL, "illegal input");
|
||||
|
||||
hwnd = FindWindowA("Pageant", "Pageant");
|
||||
if(!hwnd)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"found no pageant");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"found no pageant");
|
||||
|
||||
snprintf(mapname, sizeof(mapname),
|
||||
"PageantRequest%08x", (unsigned)GetCurrentThreadId());
|
||||
@@ -680,18 +662,18 @@ static int agent_transact_pageant(LIBSSH2_AGENT *agent,
|
||||
0, PAGEANT_MAX_MSGLEN, mapname);
|
||||
|
||||
if(!filemap || filemap == INVALID_HANDLE_VALUE)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"failed setting up pageant filemap");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"failed setting up pageant filemap");
|
||||
|
||||
p2 = p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
|
||||
if(!p || !p2) {
|
||||
CloseHandle(filemap);
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"failed to open pageant filemap for writing");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"failed to open pageant filemap for writing");
|
||||
}
|
||||
|
||||
_libssh2_store_str(&p2, (const char *)transctx->request,
|
||||
transctx->request_len);
|
||||
ssh2_store_str(&p2, (const char *)transctx->request,
|
||||
transctx->request_len);
|
||||
|
||||
cds.dwData = PAGEANT_COPYDATA_ID;
|
||||
cds.cbData = (DWORD)(1 + strlen(mapname));
|
||||
@@ -699,28 +681,28 @@ static int agent_transact_pageant(LIBSSH2_AGENT *agent,
|
||||
|
||||
id = SendMessage(hwnd, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
|
||||
if(id > 0) {
|
||||
transctx->response_len = _libssh2_ntohu32(p);
|
||||
transctx->response_len = ssh2_ntohu32(p);
|
||||
if(transctx->response_len > PAGEANT_MAX_MSGLEN - 4) {
|
||||
UnmapViewOfFile(p);
|
||||
CloseHandle(filemap);
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"agent setup fail");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"agent setup fail");
|
||||
}
|
||||
transctx->response = LIBSSH2_ALLOC(agent->session,
|
||||
transctx->response_len);
|
||||
transctx->response = SSH2_ALLOC(agent->session,
|
||||
transctx->response_len);
|
||||
if(!transctx->response) {
|
||||
UnmapViewOfFile(p);
|
||||
CloseHandle(filemap);
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_ALLOC,
|
||||
"agent malloc");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_ALLOC,
|
||||
"agent malloc");
|
||||
}
|
||||
memcpy(transctx->response, p + 4, transctx->response_len);
|
||||
}
|
||||
else {
|
||||
UnmapViewOfFile(p);
|
||||
CloseHandle(filemap);
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"pageant did not handle message");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_AGENT_PROTOCOL,
|
||||
"pageant did not handle message");
|
||||
}
|
||||
|
||||
UnmapViewOfFile(p);
|
||||
@@ -773,17 +755,16 @@ static int agent_sign(LIBSSH2_SESSION *session,
|
||||
|
||||
/* Create a request to sign the data */
|
||||
if(transctx->state == agent_NB_state_init) {
|
||||
s = transctx->request = LIBSSH2_ALLOC(session, len);
|
||||
s = transctx->request = SSH2_ALLOC(session, len);
|
||||
if(!transctx->request)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"out of memory");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_ALLOC, "out of memory");
|
||||
|
||||
*s++ = SSH2_AGENTC_SIGN_REQUEST;
|
||||
/* key blob */
|
||||
_libssh2_store_str(&s, (const char *)identity->external.blob,
|
||||
identity->external.blob_len);
|
||||
ssh2_store_str(&s, (const char *)identity->external.blob,
|
||||
identity->external.blob_len);
|
||||
/* data */
|
||||
_libssh2_store_str(&s, (const char *)data, data_len);
|
||||
ssh2_store_str(&s, (const char *)data, data_len);
|
||||
|
||||
/* flags */
|
||||
if(session->userauth_pblc_method_len > 0 &&
|
||||
@@ -798,7 +779,7 @@ static int agent_sign(LIBSSH2_SESSION *session,
|
||||
sign_flags = SSH_AGENT_RSA_SHA2_256;
|
||||
}
|
||||
}
|
||||
_libssh2_store_u32(&s, sign_flags);
|
||||
ssh2_store_u32(&s, sign_flags);
|
||||
|
||||
transctx->request_len = s - transctx->request;
|
||||
transctx->send_recv_total = 0;
|
||||
@@ -807,19 +788,17 @@ static int agent_sign(LIBSSH2_SESSION *session,
|
||||
|
||||
/* Make sure to be re-called as a result of EAGAIN. */
|
||||
if(*transctx->request != SSH2_AGENTC_SIGN_REQUEST)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_BAD_USE,
|
||||
"illegal request");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_BAD_USE, "illegal request");
|
||||
|
||||
if(!agent->ops)
|
||||
/* if no agent has been connected, bail out */
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_BAD_USE,
|
||||
"agent not connected");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_BAD_USE, "agent not connected");
|
||||
|
||||
rc = agent->ops->transact(agent, transctx);
|
||||
if(rc) {
|
||||
goto error;
|
||||
}
|
||||
LIBSSH2_FREE(session, transctx->request);
|
||||
SSH2_FREE(session, transctx->request);
|
||||
transctx->request = NULL;
|
||||
|
||||
len = transctx->response_len;
|
||||
@@ -849,7 +828,7 @@ static int agent_sign(LIBSSH2_SESSION *session,
|
||||
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
||||
goto error;
|
||||
}
|
||||
method_len = _libssh2_ntohu32(s);
|
||||
method_len = ssh2_ntohu32(s);
|
||||
s += 4;
|
||||
len -= method_len;
|
||||
if(len < 0) {
|
||||
@@ -858,7 +837,7 @@ static int agent_sign(LIBSSH2_SESSION *session,
|
||||
}
|
||||
|
||||
/* method name */
|
||||
method_name = LIBSSH2_ALLOC(session, method_len);
|
||||
method_name = SSH2_ALLOC(session, method_len);
|
||||
if(!method_name) {
|
||||
rc = LIBSSH2_ERROR_ALLOC;
|
||||
goto error;
|
||||
@@ -873,8 +852,8 @@ static int agent_sign(LIBSSH2_SESSION *session,
|
||||
if(((size_t)method_len != session->userauth_pblc_method_len &&
|
||||
method_len != plain_len) ||
|
||||
memcmp(method_name, session->userauth_pblc_method, method_len)) {
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_KEX, "Agent sign method %.*s",
|
||||
(int)method_len, method_name));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_KEX, "Agent sign method %.*s",
|
||||
(int)method_len, method_name));
|
||||
|
||||
rc = LIBSSH2_ERROR_ALGO_UNSUPPORTED;
|
||||
goto error;
|
||||
@@ -886,7 +865,7 @@ static int agent_sign(LIBSSH2_SESSION *session,
|
||||
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
||||
goto error;
|
||||
}
|
||||
*sig_len = _libssh2_ntohu32(s);
|
||||
*sig_len = ssh2_ntohu32(s);
|
||||
s += 4;
|
||||
len -= *sig_len;
|
||||
if(len < 0) {
|
||||
@@ -894,7 +873,7 @@ static int agent_sign(LIBSSH2_SESSION *session,
|
||||
goto error;
|
||||
}
|
||||
|
||||
*sig = LIBSSH2_ALLOC(session, *sig_len);
|
||||
*sig = SSH2_ALLOC(session, *sig_len);
|
||||
if(!*sig) {
|
||||
rc = LIBSSH2_ERROR_ALLOC;
|
||||
goto error;
|
||||
@@ -904,17 +883,17 @@ static int agent_sign(LIBSSH2_SESSION *session,
|
||||
error:
|
||||
|
||||
if(method_name)
|
||||
LIBSSH2_FREE(session, method_name);
|
||||
SSH2_FREE(session, method_name);
|
||||
|
||||
LIBSSH2_FREE(session, transctx->request);
|
||||
SSH2_FREE(session, transctx->request);
|
||||
transctx->request = NULL;
|
||||
|
||||
LIBSSH2_FREE(session, transctx->response);
|
||||
SSH2_FREE(session, transctx->response);
|
||||
transctx->response = NULL;
|
||||
|
||||
transctx->state = agent_NB_state_init;
|
||||
|
||||
return _libssh2_error(session, rc, "agent sign failure");
|
||||
return ssh2_err(session, rc, "agent sign failure");
|
||||
}
|
||||
|
||||
static int agent_list_identities(LIBSSH2_AGENT *agent)
|
||||
@@ -927,7 +906,7 @@ static int agent_list_identities(LIBSSH2_AGENT *agent)
|
||||
|
||||
/* Create a request to list identities */
|
||||
if(transctx->state == agent_NB_state_init) {
|
||||
transctx->request = LIBSSH2_UNCONST(&c);
|
||||
transctx->request = SSH2_UNCONST(&c);
|
||||
transctx->request_len = 1;
|
||||
transctx->send_recv_total = 0;
|
||||
transctx->state = agent_NB_state_request_created;
|
||||
@@ -935,17 +914,17 @@ static int agent_list_identities(LIBSSH2_AGENT *agent)
|
||||
|
||||
/* Make sure to be re-called as a result of EAGAIN. */
|
||||
if(*transctx->request != SSH2_AGENTC_REQUEST_IDENTITIES)
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_BAD_USE,
|
||||
"illegal agent request");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_BAD_USE,
|
||||
"illegal agent request");
|
||||
|
||||
if(!agent->ops)
|
||||
/* if no agent has been connected, bail out */
|
||||
return _libssh2_error(agent->session, LIBSSH2_ERROR_BAD_USE,
|
||||
"agent not connected");
|
||||
return ssh2_err(agent->session, LIBSSH2_ERROR_BAD_USE,
|
||||
"agent not connected");
|
||||
|
||||
rc = agent->ops->transact(agent, transctx);
|
||||
if(rc) {
|
||||
LIBSSH2_FREE(agent->session, transctx->response);
|
||||
SSH2_FREE(agent->session, transctx->response);
|
||||
transctx->response = NULL;
|
||||
return rc;
|
||||
}
|
||||
@@ -970,7 +949,7 @@ static int agent_list_identities(LIBSSH2_AGENT *agent)
|
||||
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
||||
goto error;
|
||||
}
|
||||
num_identities = _libssh2_ntohu32(s);
|
||||
num_identities = ssh2_ntohu32(s);
|
||||
s += 4;
|
||||
|
||||
while(num_identities--) {
|
||||
@@ -983,27 +962,27 @@ static int agent_list_identities(LIBSSH2_AGENT *agent)
|
||||
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
||||
goto error;
|
||||
}
|
||||
identity = LIBSSH2_ALLOC(agent->session, sizeof(*identity));
|
||||
identity = SSH2_ALLOC(agent->session, sizeof(*identity));
|
||||
if(!identity) {
|
||||
rc = LIBSSH2_ERROR_ALLOC;
|
||||
goto error;
|
||||
}
|
||||
identity->external.blob_len = _libssh2_ntohu32(s);
|
||||
identity->external.blob_len = ssh2_ntohu32(s);
|
||||
s += 4;
|
||||
|
||||
/* Read the blob */
|
||||
len -= identity->external.blob_len;
|
||||
if(len < 0) {
|
||||
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
||||
LIBSSH2_FREE(agent->session, identity);
|
||||
SSH2_FREE(agent->session, identity);
|
||||
goto error;
|
||||
}
|
||||
|
||||
identity->external.blob = LIBSSH2_ALLOC(agent->session,
|
||||
identity->external.blob_len);
|
||||
identity->external.blob = SSH2_ALLOC(agent->session,
|
||||
identity->external.blob_len);
|
||||
if(!identity->external.blob) {
|
||||
rc = LIBSSH2_ERROR_ALLOC;
|
||||
LIBSSH2_FREE(agent->session, identity);
|
||||
SSH2_FREE(agent->session, identity);
|
||||
goto error;
|
||||
}
|
||||
memcpy(identity->external.blob, s, identity->external.blob_len);
|
||||
@@ -1013,41 +992,41 @@ static int agent_list_identities(LIBSSH2_AGENT *agent)
|
||||
len -= 4;
|
||||
if(len < 0) {
|
||||
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
||||
LIBSSH2_FREE(agent->session, identity->external.blob);
|
||||
LIBSSH2_FREE(agent->session, identity);
|
||||
SSH2_FREE(agent->session, identity->external.blob);
|
||||
SSH2_FREE(agent->session, identity);
|
||||
goto error;
|
||||
}
|
||||
comment_len = _libssh2_ntohu32(s);
|
||||
comment_len = ssh2_ntohu32(s);
|
||||
s += 4;
|
||||
|
||||
if(comment_len > (size_t)len) {
|
||||
rc = LIBSSH2_ERROR_AGENT_PROTOCOL;
|
||||
LIBSSH2_FREE(agent->session, identity->external.blob);
|
||||
LIBSSH2_FREE(agent->session, identity);
|
||||
SSH2_FREE(agent->session, identity->external.blob);
|
||||
SSH2_FREE(agent->session, identity);
|
||||
goto error;
|
||||
}
|
||||
/* Read the comment */
|
||||
len -= comment_len;
|
||||
|
||||
identity->external.comment = LIBSSH2_ALLOC(agent->session,
|
||||
comment_len + 1);
|
||||
identity->external.comment = SSH2_ALLOC(agent->session,
|
||||
comment_len + 1);
|
||||
if(!identity->external.comment) {
|
||||
rc = LIBSSH2_ERROR_ALLOC;
|
||||
LIBSSH2_FREE(agent->session, identity->external.blob);
|
||||
LIBSSH2_FREE(agent->session, identity);
|
||||
SSH2_FREE(agent->session, identity->external.blob);
|
||||
SSH2_FREE(agent->session, identity);
|
||||
goto error;
|
||||
}
|
||||
identity->external.comment[comment_len] = '\0';
|
||||
memcpy(identity->external.comment, s, comment_len);
|
||||
s += comment_len;
|
||||
|
||||
_libssh2_list_add(&agent->head, &identity->node);
|
||||
ssh2_list_add(&agent->head, &identity->node);
|
||||
}
|
||||
error:
|
||||
LIBSSH2_FREE(agent->session, transctx->response);
|
||||
SSH2_FREE(agent->session, transctx->response);
|
||||
transctx->response = NULL;
|
||||
|
||||
return _libssh2_error(agent->session, rc, "agent list id failed");
|
||||
return ssh2_err(agent->session, rc, "agent list id failed");
|
||||
}
|
||||
|
||||
static void agent_free_identities(LIBSSH2_AGENT *agent)
|
||||
@@ -1055,13 +1034,13 @@ static void agent_free_identities(LIBSSH2_AGENT *agent)
|
||||
struct agent_publickey *node;
|
||||
struct agent_publickey *next;
|
||||
|
||||
for(node = _libssh2_list_first(&agent->head); node; node = next) {
|
||||
next = _libssh2_list_next(&node->node);
|
||||
LIBSSH2_FREE(agent->session, node->external.blob);
|
||||
LIBSSH2_FREE(agent->session, node->external.comment);
|
||||
LIBSSH2_FREE(agent->session, node);
|
||||
for(node = ssh2_list_first(&agent->head); node; node = next) {
|
||||
next = ssh2_list_next(&node->node);
|
||||
SSH2_FREE(agent->session, node->external.blob);
|
||||
SSH2_FREE(agent->session, node->external.comment);
|
||||
SSH2_FREE(agent->session, node);
|
||||
}
|
||||
_libssh2_list_init(&agent->head);
|
||||
ssh2_list_init(&agent->head);
|
||||
}
|
||||
|
||||
#define AGENT_PUBLICKEY_MAGIC 0x3bdefed2
|
||||
@@ -1087,16 +1066,16 @@ LIBSSH2_AGENT *libssh2_agent_init(LIBSSH2_SESSION *session)
|
||||
{
|
||||
LIBSSH2_AGENT *agent;
|
||||
|
||||
agent = LIBSSH2_CALLOC(session, sizeof(*agent));
|
||||
agent = SSH2_CALLOC(session, sizeof(*agent));
|
||||
if(!agent) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate space for agent connection");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate space for agent connection");
|
||||
return NULL;
|
||||
}
|
||||
agent->fd = LIBSSH2_INVALID_SOCKET;
|
||||
agent->session = session;
|
||||
agent->identity_agent_path = NULL;
|
||||
_libssh2_list_init(&agent->head);
|
||||
ssh2_list_init(&agent->head);
|
||||
|
||||
#ifdef HAVE_WIN32_AGENTS
|
||||
agent->pipe = INVALID_HANDLE_VALUE;
|
||||
@@ -1160,10 +1139,10 @@ int libssh2_agent_get_identity(LIBSSH2_AGENT *agent,
|
||||
struct agent_publickey *prev_node = prev->node;
|
||||
|
||||
/* get the next node in the list */
|
||||
node = _libssh2_list_next(&prev_node->node);
|
||||
node = ssh2_list_next(&prev_node->node);
|
||||
}
|
||||
else
|
||||
node = _libssh2_list_first(&agent->head);
|
||||
node = ssh2_list_first(&agent->head);
|
||||
|
||||
if(!node)
|
||||
/* no (more) node */
|
||||
@@ -1187,18 +1166,18 @@ int libssh2_agent_userauth(LIBSSH2_AGENT *agent,
|
||||
void *abstract = agent;
|
||||
int rc;
|
||||
|
||||
if(agent->session->userauth_pblc_state == libssh2_NB_state_idle) {
|
||||
if(agent->session->userauth_pblc_state == ssh2_NB_state_idle) {
|
||||
memset(&agent->transctx, 0, sizeof(agent->transctx));
|
||||
agent->identity = identity->node;
|
||||
}
|
||||
|
||||
BLOCK_ADJUST(rc, agent->session,
|
||||
_libssh2_userauth_publickey(agent->session, username,
|
||||
strlen(username),
|
||||
identity->blob,
|
||||
identity->blob_len,
|
||||
agent_sign,
|
||||
&abstract));
|
||||
ssh2_userauth_publickey(agent->session, username,
|
||||
strlen(username),
|
||||
identity->blob,
|
||||
identity->blob_len,
|
||||
agent_sign,
|
||||
&abstract));
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1221,7 +1200,7 @@ int libssh2_agent_sign(LIBSSH2_AGENT *agent,
|
||||
int rc;
|
||||
uint32_t key_kind_len;
|
||||
|
||||
if(agent->session->userauth_pblc_state == libssh2_NB_state_idle) {
|
||||
if(agent->session->userauth_pblc_state == ssh2_NB_state_idle) {
|
||||
memset(&agent->transctx, 0, sizeof(agent->transctx));
|
||||
agent->identity = identity->node;
|
||||
}
|
||||
@@ -1230,21 +1209,21 @@ int libssh2_agent_sign(LIBSSH2_AGENT *agent,
|
||||
return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
key_kind_len = _libssh2_ntohu32(identity->blob);
|
||||
key_kind_len = ssh2_ntohu32(identity->blob);
|
||||
|
||||
if(identity->blob_len < sizeof(uint32_t) + key_kind_len) {
|
||||
return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
agent->session->userauth_pblc_method_len = method_len;
|
||||
agent->session->userauth_pblc_method = LIBSSH2_ALLOC(agent->session,
|
||||
method_len);
|
||||
agent->session->userauth_pblc_method = SSH2_ALLOC(agent->session,
|
||||
method_len);
|
||||
|
||||
memcpy(agent->session->userauth_pblc_method, method, method_len);
|
||||
|
||||
rc = agent_sign(agent->session, sig, s_len, data, d_len, &abstract);
|
||||
|
||||
LIBSSH2_FREE(agent->session, agent->session->userauth_pblc_method);
|
||||
SSH2_FREE(agent->session, agent->session->userauth_pblc_method);
|
||||
agent->session->userauth_pblc_method = NULL;
|
||||
agent->session->userauth_pblc_method_len = 0;
|
||||
|
||||
@@ -1277,10 +1256,10 @@ void libssh2_agent_free(LIBSSH2_AGENT *agent)
|
||||
}
|
||||
|
||||
if(agent->identity_agent_path)
|
||||
LIBSSH2_FREE(agent->session, agent->identity_agent_path);
|
||||
SSH2_FREE(agent->session, agent->identity_agent_path);
|
||||
|
||||
agent_free_identities(agent);
|
||||
LIBSSH2_FREE(agent->session, agent);
|
||||
SSH2_FREE(agent->session, agent);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1290,14 +1269,14 @@ LIBSSH2_API
|
||||
void libssh2_agent_set_identity_path(LIBSSH2_AGENT *agent, const char *path)
|
||||
{
|
||||
if(agent->identity_agent_path) {
|
||||
LIBSSH2_FREE(agent->session, agent->identity_agent_path);
|
||||
SSH2_FREE(agent->session, agent->identity_agent_path);
|
||||
agent->identity_agent_path = NULL;
|
||||
}
|
||||
|
||||
if(path) {
|
||||
size_t path_len = strlen(path);
|
||||
if(path_len < SIZE_MAX - 1) {
|
||||
char *path_buf = LIBSSH2_ALLOC(agent->session, path_len + 1);
|
||||
char *path_buf = SSH2_ALLOC(agent->session, path_len + 1);
|
||||
memcpy(path_buf, path, path_len);
|
||||
path_buf[path_len] = '\0';
|
||||
agent->identity_agent_path = path_buf;
|
||||
|
||||
@@ -88,9 +88,9 @@ static void bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out)
|
||||
}
|
||||
|
||||
/* zap */
|
||||
_libssh2_explicit_zero(ciphertext, sizeof(ciphertext));
|
||||
_libssh2_explicit_zero(cdata, sizeof(cdata));
|
||||
_libssh2_explicit_zero(&state, sizeof(state));
|
||||
ssh2_explicit_zero(ciphertext, sizeof(ciphertext));
|
||||
ssh2_explicit_zero(cdata, sizeof(cdata));
|
||||
ssh2_explicit_zero(&state, sizeof(state));
|
||||
}
|
||||
|
||||
static int bcrypt_pbkdf(const char *pass, size_t passlen,
|
||||
@@ -105,7 +105,7 @@ static int bcrypt_pbkdf(const char *pass, size_t passlen,
|
||||
size_t i, j, amt, stride;
|
||||
uint32_t count;
|
||||
size_t origkeylen = keylen;
|
||||
libssh2_sha512_ctx ctx;
|
||||
ssh2_sha512_ctx ctx;
|
||||
|
||||
/* nothing crazy */
|
||||
if(rounds < 1)
|
||||
@@ -124,9 +124,9 @@ static int bcrypt_pbkdf(const char *pass, size_t passlen,
|
||||
memcpy(countsalt, salt, saltlen);
|
||||
|
||||
/* collapse password */
|
||||
if(!libssh2_sha512_init(&ctx) ||
|
||||
!libssh2_sha512_update(ctx, pass, passlen) ||
|
||||
!libssh2_sha512_final(ctx, sha2pass)) {
|
||||
if(!ssh2_sha512_init(&ctx) ||
|
||||
!ssh2_sha512_update(ctx, pass, passlen) ||
|
||||
!ssh2_sha512_final(ctx, sha2pass)) {
|
||||
free(countsalt);
|
||||
return -1;
|
||||
}
|
||||
@@ -139,10 +139,10 @@ static int bcrypt_pbkdf(const char *pass, size_t passlen,
|
||||
countsalt[saltlen + 3] = count & 0xff;
|
||||
|
||||
/* first round, salt is salt */
|
||||
if(!libssh2_sha512_init(&ctx) ||
|
||||
!libssh2_sha512_update(ctx, countsalt, saltlen + 4) ||
|
||||
!libssh2_sha512_final(ctx, sha2salt)) {
|
||||
_libssh2_explicit_zero(out, sizeof(out));
|
||||
if(!ssh2_sha512_init(&ctx) ||
|
||||
!ssh2_sha512_update(ctx, countsalt, saltlen + 4) ||
|
||||
!ssh2_sha512_final(ctx, sha2salt)) {
|
||||
ssh2_explicit_zero(out, sizeof(out));
|
||||
free(countsalt);
|
||||
return -1;
|
||||
}
|
||||
@@ -152,10 +152,10 @@ static int bcrypt_pbkdf(const char *pass, size_t passlen,
|
||||
|
||||
for(i = 1; i < rounds; i++) {
|
||||
/* subsequent rounds, salt is previous output */
|
||||
if(!libssh2_sha512_init(&ctx) ||
|
||||
!libssh2_sha512_update(ctx, tmpout, sizeof(tmpout)) ||
|
||||
!libssh2_sha512_final(ctx, sha2salt)) {
|
||||
_libssh2_explicit_zero(out, sizeof(out));
|
||||
if(!ssh2_sha512_init(&ctx) ||
|
||||
!ssh2_sha512_update(ctx, tmpout, sizeof(tmpout)) ||
|
||||
!ssh2_sha512_final(ctx, sha2salt)) {
|
||||
ssh2_explicit_zero(out, sizeof(out));
|
||||
free(countsalt);
|
||||
return -1;
|
||||
}
|
||||
@@ -168,7 +168,7 @@ static int bcrypt_pbkdf(const char *pass, size_t passlen,
|
||||
/*
|
||||
* pbkdf2 deviation: output the key material non-linearly.
|
||||
*/
|
||||
amt = LIBSSH2_MIN(amt, keylen);
|
||||
amt = SSH2_MIN(amt, keylen);
|
||||
for(i = 0; i < amt; i++) {
|
||||
size_t dest = i * stride + (count - 1);
|
||||
if(dest >= origkeylen) {
|
||||
@@ -180,7 +180,7 @@ static int bcrypt_pbkdf(const char *pass, size_t passlen,
|
||||
}
|
||||
|
||||
/* zap */
|
||||
_libssh2_explicit_zero(out, sizeof(out));
|
||||
ssh2_explicit_zero(out, sizeof(out));
|
||||
free(countsalt);
|
||||
|
||||
return 0;
|
||||
@@ -188,13 +188,13 @@ static int bcrypt_pbkdf(const char *pass, size_t passlen,
|
||||
|
||||
/* Wrapper */
|
||||
|
||||
int _libssh2_bcrypt_pbkdf(const char *pass,
|
||||
size_t passlen,
|
||||
const uint8_t *salt,
|
||||
size_t saltlen,
|
||||
uint8_t *key,
|
||||
size_t keylen,
|
||||
unsigned int rounds)
|
||||
int ssh2_bcrypt_pbkdf(const char *pass,
|
||||
size_t passlen,
|
||||
const uint8_t *salt,
|
||||
size_t saltlen,
|
||||
uint8_t *key,
|
||||
size_t keylen,
|
||||
unsigned int rounds)
|
||||
{
|
||||
return bcrypt_pbkdf(pass,
|
||||
passlen,
|
||||
|
||||
1486
src/channel.c
1486
src/channel.c
File diff suppressed because it is too large
Load Diff
@@ -47,16 +47,16 @@
|
||||
*
|
||||
* Always non-blocking.
|
||||
*/
|
||||
int _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
|
||||
uint32_t adjustment,
|
||||
unsigned char force,
|
||||
unsigned int *store);
|
||||
int ssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel,
|
||||
uint32_t adjustment,
|
||||
unsigned char force,
|
||||
unsigned int *store);
|
||||
|
||||
/*
|
||||
* Flush data from one (or all) stream
|
||||
* Returns number of bytes flushed, or negative on failure
|
||||
*/
|
||||
int _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid);
|
||||
int ssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid);
|
||||
|
||||
/*
|
||||
* Make sure a channel is closed, then remove the channel from the session
|
||||
@@ -64,33 +64,33 @@ int _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid);
|
||||
*
|
||||
* Returns 0 on success, negative on failure
|
||||
*/
|
||||
int _libssh2_channel_free(LIBSSH2_CHANNEL *channel);
|
||||
int ssh2_channel_free(LIBSSH2_CHANNEL *channel);
|
||||
|
||||
int _libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode);
|
||||
int ssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode);
|
||||
|
||||
/*
|
||||
* Send data to a channel
|
||||
*/
|
||||
ssize_t _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
|
||||
const unsigned char *buf, size_t buflen);
|
||||
ssize_t ssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
|
||||
const unsigned char *buf, size_t buflen);
|
||||
|
||||
/*
|
||||
* Establish a generic session channel
|
||||
*/
|
||||
LIBSSH2_CHANNEL *_libssh2_channel_open(LIBSSH2_SESSION *session,
|
||||
const char *channel_type,
|
||||
uint32_t channel_type_len,
|
||||
uint32_t window_size,
|
||||
uint32_t packet_size,
|
||||
const unsigned char *message,
|
||||
size_t message_len);
|
||||
LIBSSH2_CHANNEL *ssh2_channel_open(LIBSSH2_SESSION *session,
|
||||
const char *channel_type,
|
||||
uint32_t channel_type_len,
|
||||
uint32_t window_size,
|
||||
uint32_t packet_size,
|
||||
const unsigned char *message,
|
||||
size_t message_len);
|
||||
|
||||
/*
|
||||
* Primitive for libssh2_channel_(shell|exec|subsystem)
|
||||
*/
|
||||
int _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
|
||||
const char *request, size_t request_len,
|
||||
const char *message, size_t message_len);
|
||||
int ssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
|
||||
const char *request, size_t request_len,
|
||||
const char *message, size_t message_len);
|
||||
|
||||
/*
|
||||
* Read data from a channel
|
||||
@@ -99,18 +99,18 @@ int _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
|
||||
* complete. If we read stuff from the wire but it was no payload data to fill
|
||||
* in the buffer with, we MUST make sure to return PACKET_EAGAIN.
|
||||
*/
|
||||
ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
|
||||
char *buf, size_t buflen);
|
||||
ssize_t ssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
|
||||
char *buf, size_t buflen);
|
||||
|
||||
uint32_t _libssh2_channel_nextid(LIBSSH2_SESSION *session);
|
||||
uint32_t ssh2_channel_nextid(LIBSSH2_SESSION *session);
|
||||
|
||||
LIBSSH2_CHANNEL *_libssh2_channel_locate(LIBSSH2_SESSION *session,
|
||||
uint32_t channel_id);
|
||||
LIBSSH2_CHANNEL *ssh2_channel_locate(LIBSSH2_SESSION *session,
|
||||
uint32_t channel_id);
|
||||
|
||||
size_t _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL *channel,
|
||||
int stream_id);
|
||||
size_t ssh2_channel_packet_data_len(LIBSSH2_CHANNEL *channel,
|
||||
int stream_id);
|
||||
|
||||
int _libssh2_channel_close(LIBSSH2_CHANNEL *channel);
|
||||
int ssh2_channel_close(LIBSSH2_CHANNEL *channel);
|
||||
|
||||
/*
|
||||
* Stop listening on a remote port and free the listener
|
||||
@@ -118,6 +118,6 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL *channel);
|
||||
*
|
||||
* Return 0 on success, LIBSSH2_ERROR_EAGAIN if would block, -1 on error
|
||||
*/
|
||||
int _libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
|
||||
int ssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
|
||||
|
||||
#endif /* LIBSSH2_CHANNEL_H */
|
||||
|
||||
@@ -63,7 +63,7 @@ int chachapoly_crypt(struct chachapoly_ctx *ctx, libssh2_uint64_t seqnr,
|
||||
*/
|
||||
memset(poly_key, 0, sizeof(poly_key));
|
||||
ptr = &seqbuf[0];
|
||||
_libssh2_store_u64(&ptr, seqnr);
|
||||
ssh2_store_u64(&ptr, seqnr);
|
||||
chacha_ivsetup(&ctx->main_ctx, seqbuf, NULL);
|
||||
chacha_encrypt_bytes(&ctx->main_ctx, poly_key, poly_key, sizeof(poly_key));
|
||||
|
||||
@@ -112,10 +112,10 @@ int chachapoly_get_length(struct chachapoly_ctx *ctx, unsigned int *plenp,
|
||||
if(len < 4)
|
||||
return -1;
|
||||
ptr = &seqbuf[0];
|
||||
_libssh2_store_u64(&ptr, seqnr);
|
||||
ssh2_store_u64(&ptr, seqnr);
|
||||
chacha_ivsetup(&ctx->header_ctx, seqbuf, NULL);
|
||||
chacha_encrypt_bytes(&ctx->header_ctx, cp, buf, 4);
|
||||
*plenp = _libssh2_ntohu32(buf);
|
||||
*plenp = ssh2_ntohu32(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
74
src/comp.c
74
src/comp.c
@@ -120,14 +120,14 @@ static voidpf comp_method_zlib_alloc(voidpf opaque, uInt items, uInt size)
|
||||
if(items && (SIZE_MAX / (size_t)items) < (size_t)size)
|
||||
return NULL;
|
||||
|
||||
return (voidpf)LIBSSH2_ALLOC(session, items * (size_t)size);
|
||||
return (voidpf)SSH2_ALLOC(session, items * (size_t)size);
|
||||
}
|
||||
|
||||
static void comp_method_zlib_free(voidpf opaque, voidpf address)
|
||||
{
|
||||
LIBSSH2_SESSION *session = (LIBSSH2_SESSION *)opaque;
|
||||
|
||||
LIBSSH2_FREE(session, address);
|
||||
SSH2_FREE(session, address);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -139,11 +139,11 @@ static int comp_method_zlib_init(LIBSSH2_SESSION *session, int compr,
|
||||
z_stream *strm;
|
||||
int status;
|
||||
|
||||
strm = LIBSSH2_CALLOC(session, sizeof(z_stream));
|
||||
strm = SSH2_CALLOC(session, sizeof(z_stream));
|
||||
if(!strm) {
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"zlib compression/decompression");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"zlib compression/decompression");
|
||||
}
|
||||
|
||||
strm->opaque = (voidpf)session;
|
||||
@@ -159,9 +159,9 @@ static int comp_method_zlib_init(LIBSSH2_SESSION *session, int compr,
|
||||
}
|
||||
|
||||
if(status != Z_OK) {
|
||||
LIBSSH2_FREE(session, strm);
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_TRANS,
|
||||
"unhandled zlib error %d", status));
|
||||
SSH2_FREE(session, strm);
|
||||
ssh2_deb((session, LIBSSH2_TRACE_TRANS, "unhandled zlib error %d",
|
||||
status));
|
||||
return LIBSSH2_ERROR_COMPRESS;
|
||||
}
|
||||
*abstract = strm;
|
||||
@@ -198,10 +198,10 @@ static int comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
||||
return 0;
|
||||
}
|
||||
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_TRANS,
|
||||
"unhandled zlib compression error %d, avail_out %u",
|
||||
status, strm->avail_out));
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB, "compression failure");
|
||||
ssh2_deb((session, LIBSSH2_TRACE_TRANS,
|
||||
"unhandled zlib compression error %d, avail_out %u",
|
||||
status, strm->avail_out));
|
||||
return ssh2_err(session, LIBSSH2_ERROR_ZLIB, "compression failure");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -227,8 +227,8 @@ static int comp_method_zlib_decomp(LIBSSH2_SESSION *session,
|
||||
|
||||
/* If strm is null, then we have not yet been initialized. */
|
||||
if(!strm)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_COMPRESS,
|
||||
"decompression uninitialized");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_COMPRESS,
|
||||
"decompression uninitialized");
|
||||
|
||||
/* In practice they never come smaller than this */
|
||||
if(out_maxlen < 25)
|
||||
@@ -239,12 +239,12 @@ static int comp_method_zlib_decomp(LIBSSH2_SESSION *session,
|
||||
|
||||
strm->next_in = (z_const Bytef *)src;
|
||||
strm->avail_in = (uInt)src_len;
|
||||
strm->next_out = (Bytef *)LIBSSH2_ALLOC(session, (uInt)out_maxlen);
|
||||
strm->next_out = (Bytef *)SSH2_ALLOC(session, (uInt)out_maxlen);
|
||||
out = (char *)strm->next_out;
|
||||
strm->avail_out = (uInt)out_maxlen;
|
||||
if(!strm->next_out)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate decompression buffer");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate decompression buffer");
|
||||
|
||||
/* Loop until it is all inflated or hit error */
|
||||
for(;;) {
|
||||
@@ -265,38 +265,38 @@ static int comp_method_zlib_decomp(LIBSSH2_SESSION *session,
|
||||
|
||||
if((out_maxlen - strm->avail_out) == 0) {
|
||||
/* nothing was decompressed */
|
||||
LIBSSH2_FREE(session, out);
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_TRANS,
|
||||
"zlib empty src error %d", status));
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
|
||||
"decompression failure");
|
||||
SSH2_FREE(session, out);
|
||||
ssh2_deb((session, LIBSSH2_TRACE_TRANS,
|
||||
"zlib empty src error %d", status));
|
||||
return ssh2_err(session, LIBSSH2_ERROR_ZLIB,
|
||||
"decompression failure");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
else {
|
||||
/* error state */
|
||||
LIBSSH2_FREE(session, out);
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_TRANS,
|
||||
"unhandled zlib error %d", status));
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
|
||||
"decompression failure");
|
||||
SSH2_FREE(session, out);
|
||||
ssh2_deb((session, LIBSSH2_TRACE_TRANS, "unhandled zlib error %d",
|
||||
status));
|
||||
return ssh2_err(session, LIBSSH2_ERROR_ZLIB,
|
||||
"decompression failure");
|
||||
}
|
||||
|
||||
if(out_maxlen > payload_limit || out_maxlen > SIZE_MAX / 2) {
|
||||
LIBSSH2_FREE(session, out);
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ZLIB,
|
||||
"Excessive growth in decompression phase");
|
||||
SSH2_FREE(session, out);
|
||||
return ssh2_err(session, LIBSSH2_ERROR_ZLIB,
|
||||
"Excessive growth in decompression phase");
|
||||
}
|
||||
|
||||
/* If we get here we need to grow the output buffer and try again */
|
||||
out_ofs = out_maxlen - strm->avail_out;
|
||||
out_maxlen *= 2;
|
||||
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
|
||||
newout = SSH2_REALLOC(session, out, out_maxlen);
|
||||
if(!newout) {
|
||||
LIBSSH2_FREE(session, out);
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to expand decompression buffer");
|
||||
SSH2_FREE(session, out);
|
||||
return ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to expand decompression buffer");
|
||||
}
|
||||
out = newout;
|
||||
strm->next_out = (Bytef *)out + out_ofs;
|
||||
@@ -322,7 +322,7 @@ static int comp_method_zlib_dtor(LIBSSH2_SESSION *session, int compr,
|
||||
deflateEnd(strm);
|
||||
else
|
||||
inflateEnd(strm);
|
||||
LIBSSH2_FREE(session, strm);
|
||||
SSH2_FREE(session, strm);
|
||||
}
|
||||
|
||||
*abstract = NULL;
|
||||
@@ -367,7 +367,7 @@ static const struct comp_method *no_comp_methods[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
const struct comp_method **_libssh2_comp_methods(LIBSSH2_SESSION *session)
|
||||
const struct comp_method **ssh2_comp_methods(LIBSSH2_SESSION *session)
|
||||
{
|
||||
if(session->flag.compress)
|
||||
return comp_methods;
|
||||
|
||||
@@ -40,6 +40,6 @@
|
||||
|
||||
#include "libssh2_priv.h"
|
||||
|
||||
const struct comp_method **_libssh2_comp_methods(LIBSSH2_SESSION *session);
|
||||
const struct comp_method **ssh2_comp_methods(LIBSSH2_SESSION *session);
|
||||
|
||||
#endif /* LIBSSH2_COMP_H */
|
||||
|
||||
66
src/crypt.c
66
src/crypt.c
@@ -83,8 +83,8 @@ static const struct crypt_method crypt_method_none = {
|
||||
|
||||
struct crypt_ctx {
|
||||
int encrypt;
|
||||
LIBSSH2_CIPHER_T(algo);
|
||||
libssh2_cipher_ctx h;
|
||||
SSH2_CIPHER_T(algo);
|
||||
ssh2_cipher_ctx h;
|
||||
struct chachapoly_ctx chachapoly_ctx;
|
||||
};
|
||||
|
||||
@@ -94,14 +94,14 @@ static int crypt_init(LIBSSH2_SESSION *session,
|
||||
unsigned char *secret, int *free_secret,
|
||||
int encrypt, void **abstract)
|
||||
{
|
||||
struct crypt_ctx *ctx = LIBSSH2_ALLOC(session, sizeof(struct crypt_ctx));
|
||||
struct crypt_ctx *ctx = SSH2_ALLOC(session, sizeof(struct crypt_ctx));
|
||||
if(!ctx)
|
||||
return LIBSSH2_ERROR_ALLOC;
|
||||
|
||||
ctx->encrypt = encrypt;
|
||||
ctx->algo = method->algo;
|
||||
if(_libssh2_cipher_init(&ctx->h, ctx->algo, iv, secret, encrypt)) {
|
||||
LIBSSH2_FREE(session, ctx);
|
||||
if(ssh2_cipher_init(&ctx->h, ctx->algo, iv, secret, encrypt)) {
|
||||
SSH2_FREE(session, ctx);
|
||||
return -1;
|
||||
}
|
||||
*abstract = ctx;
|
||||
@@ -120,16 +120,16 @@ static int crypt_encrypt(LIBSSH2_SESSION *session,
|
||||
struct crypt_ctx *cctx = *(struct crypt_ctx **)abstract;
|
||||
(void)session;
|
||||
(void)seqno;
|
||||
return _libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, buf,
|
||||
buf_len, firstlast);
|
||||
return ssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, buf,
|
||||
buf_len, firstlast);
|
||||
}
|
||||
|
||||
static int crypt_dtor(LIBSSH2_SESSION *session, void **abstract)
|
||||
{
|
||||
struct crypt_ctx **cctx = (struct crypt_ctx **)abstract;
|
||||
if(cctx && *cctx) {
|
||||
_libssh2_cipher_dtor(&(*cctx)->h);
|
||||
LIBSSH2_FREE(session, *cctx);
|
||||
ssh2_cipher_dtor(&(*cctx)->h);
|
||||
SSH2_FREE(session, *cctx);
|
||||
*abstract = NULL;
|
||||
}
|
||||
return 0;
|
||||
@@ -143,12 +143,12 @@ static const struct crypt_method crypt_method_aes256_gcm = {
|
||||
12, /* initial value length */
|
||||
32, /* secret length -- 32*8 == 256bit */
|
||||
16, /* length of the authentication tag */
|
||||
LIBSSH2_CRYPT_FLAG_INTEGRATED_MAC | LIBSSH2_CRYPT_FLAG_PKTLEN_AAD,
|
||||
SSH2_CRYPT_FLAG_INTEGRATED_MAC | SSH2_CRYPT_FLAG_PKTLEN_AAD,
|
||||
&crypt_init,
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_aes256gcm
|
||||
ssh2_cipher_aes256gcm
|
||||
};
|
||||
|
||||
static const struct crypt_method crypt_method_aes128_gcm = {
|
||||
@@ -158,12 +158,12 @@ static const struct crypt_method crypt_method_aes128_gcm = {
|
||||
12, /* initial value length */
|
||||
16, /* secret length -- 16*8 == 128bit */
|
||||
16, /* length of the authentication tag */
|
||||
LIBSSH2_CRYPT_FLAG_INTEGRATED_MAC | LIBSSH2_CRYPT_FLAG_PKTLEN_AAD,
|
||||
SSH2_CRYPT_FLAG_INTEGRATED_MAC | SSH2_CRYPT_FLAG_PKTLEN_AAD,
|
||||
&crypt_init,
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_aes128gcm
|
||||
ssh2_cipher_aes128gcm
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -180,7 +180,7 @@ static const struct crypt_method crypt_method_aes128_ctr = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_aes128ctr
|
||||
ssh2_cipher_aes128ctr
|
||||
};
|
||||
|
||||
static const struct crypt_method crypt_method_aes192_ctr = {
|
||||
@@ -195,7 +195,7 @@ static const struct crypt_method crypt_method_aes192_ctr = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_aes192ctr
|
||||
ssh2_cipher_aes192ctr
|
||||
};
|
||||
|
||||
static const struct crypt_method crypt_method_aes256_ctr = {
|
||||
@@ -210,7 +210,7 @@ static const struct crypt_method crypt_method_aes256_ctr = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_aes256ctr
|
||||
ssh2_cipher_aes256ctr
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -227,7 +227,7 @@ static const struct crypt_method crypt_method_aes128_cbc = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_aes128
|
||||
ssh2_cipher_aes128
|
||||
};
|
||||
|
||||
static const struct crypt_method crypt_method_aes192_cbc = {
|
||||
@@ -242,7 +242,7 @@ static const struct crypt_method crypt_method_aes192_cbc = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_aes192
|
||||
ssh2_cipher_aes192
|
||||
};
|
||||
|
||||
static const struct crypt_method crypt_method_aes256_cbc = {
|
||||
@@ -257,7 +257,7 @@ static const struct crypt_method crypt_method_aes256_cbc = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_aes256
|
||||
ssh2_cipher_aes256
|
||||
};
|
||||
|
||||
/* rijndael-cbc@lysator.liu.se == aes256-cbc */
|
||||
@@ -273,7 +273,7 @@ static const struct crypt_method crypt_method_rijndael_cbc_lysator_liu_se = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_aes256
|
||||
ssh2_cipher_aes256
|
||||
};
|
||||
#endif /* LIBSSH2_AES_CBC */
|
||||
|
||||
@@ -290,7 +290,7 @@ static const struct crypt_method crypt_method_blowfish_cbc = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_blowfish
|
||||
ssh2_cipher_blowfish
|
||||
};
|
||||
#endif /* LIBSSH2_BLOWFISH */
|
||||
|
||||
@@ -307,7 +307,7 @@ static const struct crypt_method crypt_method_arcfour = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_arcfour
|
||||
ssh2_cipher_arcfour
|
||||
};
|
||||
|
||||
static int crypt_init_arcfour128(LIBSSH2_SESSION *session,
|
||||
@@ -325,8 +325,8 @@ static int crypt_init_arcfour128(LIBSSH2_SESSION *session,
|
||||
unsigned char block[8];
|
||||
size_t discard = 1536;
|
||||
for(; discard; discard -= 8)
|
||||
_libssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block,
|
||||
method->blocksize, MIDDLE_BLOCK);
|
||||
ssh2_cipher_crypt(&cctx->h, cctx->algo, cctx->encrypt, block,
|
||||
method->blocksize, MIDDLE_BLOCK);
|
||||
/* Not all middle, but here it does not matter */
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ static const struct crypt_method crypt_method_arcfour128 = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_arcfour
|
||||
ssh2_cipher_arcfour
|
||||
};
|
||||
#endif /* LIBSSH2_RC4 */
|
||||
|
||||
@@ -362,7 +362,7 @@ static const struct crypt_method crypt_method_cast128_cbc = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_cast5
|
||||
ssh2_cipher_cast5
|
||||
};
|
||||
#endif /* LIBSSH2_CAST */
|
||||
|
||||
@@ -379,7 +379,7 @@ static const struct crypt_method crypt_method_3des_cbc = {
|
||||
NULL,
|
||||
&crypt_encrypt,
|
||||
&crypt_dtor,
|
||||
libssh2_cipher_3des
|
||||
ssh2_cipher_3des
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -389,7 +389,7 @@ static int crypt_init_chacha20_poly(LIBSSH2_SESSION *session,
|
||||
unsigned char *secret, int *free_secret,
|
||||
int encrypt, void **abstract)
|
||||
{
|
||||
struct crypt_ctx *ctx = LIBSSH2_ALLOC(session, sizeof(struct crypt_ctx));
|
||||
struct crypt_ctx *ctx = SSH2_ALLOC(session, sizeof(struct crypt_ctx));
|
||||
|
||||
(void)iv;
|
||||
|
||||
@@ -400,7 +400,7 @@ static int crypt_init_chacha20_poly(LIBSSH2_SESSION *session,
|
||||
ctx->algo = method->algo;
|
||||
|
||||
if(chachapoly_init(&ctx->chachapoly_ctx, secret, method->secret_len)) {
|
||||
LIBSSH2_FREE(session, ctx);
|
||||
SSH2_FREE(session, ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ static int crypt_dtor_chacha20_poly(LIBSSH2_SESSION *session, void **abstract)
|
||||
{
|
||||
struct crypt_ctx **cctx = (struct crypt_ctx **)abstract;
|
||||
if(cctx && *cctx) {
|
||||
LIBSSH2_FREE(session, *cctx);
|
||||
SSH2_FREE(session, *cctx);
|
||||
*abstract = NULL;
|
||||
}
|
||||
return 0;
|
||||
@@ -482,12 +482,12 @@ static const struct crypt_method crypt_method_chacha20_poly1305_openssh = {
|
||||
0, /* initial value length */
|
||||
64, /* secret length */
|
||||
16, /* length of the auth_tag */
|
||||
LIBSSH2_CRYPT_FLAG_REQUIRES_FULL_PACKET, /* flags */
|
||||
SSH2_CRYPT_FLAG_REQUIRES_FULL_PACKET, /* flags */
|
||||
&crypt_init_chacha20_poly,
|
||||
&crypt_get_length_chacha20_poly,
|
||||
&crypt_encrypt_chacha20_poly_buffer,
|
||||
&crypt_dtor_chacha20_poly,
|
||||
libssh2_cipher_chacha20 /* not actually used */
|
||||
ssh2_cipher_chacha20 /* not actually used */
|
||||
};
|
||||
|
||||
/* These are the crypt methods that are available to be negotiated. Methods
|
||||
@@ -529,7 +529,7 @@ static const struct crypt_method *crypt_methods[] = {
|
||||
};
|
||||
|
||||
/* Expose to kex.c */
|
||||
const struct crypt_method **libssh2_crypt_methods(void)
|
||||
const struct crypt_method **ssh2_crypt_methods(void)
|
||||
{
|
||||
return crypt_methods;
|
||||
}
|
||||
|
||||
426
src/crypto.h
426
src/crypto.h
@@ -56,218 +56,214 @@
|
||||
#endif
|
||||
|
||||
/* return: success = 1, error = 0 */
|
||||
int _libssh2_hmac_ctx_init(libssh2_hmac_ctx *ctx);
|
||||
int ssh2_hmac_ctx_init(ssh2_hmac_ctx *ctx);
|
||||
#if LIBSSH2_MD5
|
||||
int _libssh2_hmac_md5_init(libssh2_hmac_ctx *ctx,
|
||||
void *key, size_t keylen);
|
||||
int ssh2_hmac_md5_init(ssh2_hmac_ctx *ctx, void *key, size_t keylen);
|
||||
#endif
|
||||
#if LIBSSH2_HMAC_RIPEMD
|
||||
int _libssh2_hmac_ripemd160_init(libssh2_hmac_ctx *ctx,
|
||||
void *key, size_t keylen);
|
||||
int ssh2_hmac_ripemd160_init(ssh2_hmac_ctx *ctx, void *key, size_t keylen);
|
||||
#endif
|
||||
int _libssh2_hmac_sha1_init(libssh2_hmac_ctx *ctx,
|
||||
void *key, size_t keylen);
|
||||
int _libssh2_hmac_sha256_init(libssh2_hmac_ctx *ctx,
|
||||
void *key, size_t keylen);
|
||||
int _libssh2_hmac_sha512_init(libssh2_hmac_ctx *ctx,
|
||||
void *key, size_t keylen);
|
||||
int _libssh2_hmac_update(libssh2_hmac_ctx *ctx,
|
||||
const void *data, size_t datalen);
|
||||
int _libssh2_hmac_final(libssh2_hmac_ctx *ctx, void *data);
|
||||
void _libssh2_hmac_cleanup(libssh2_hmac_ctx *ctx);
|
||||
int ssh2_hmac_sha1_init(ssh2_hmac_ctx *ctx, void *key, size_t keylen);
|
||||
int ssh2_hmac_sha256_init(ssh2_hmac_ctx *ctx, void *key, size_t keylen);
|
||||
int ssh2_hmac_sha512_init(ssh2_hmac_ctx *ctx, void *key, size_t keylen);
|
||||
int ssh2_hmac_update(ssh2_hmac_ctx *ctx, const void *data, size_t datalen);
|
||||
int ssh2_hmac_final(ssh2_hmac_ctx *ctx, void *data);
|
||||
void ssh2_hmac_cleanup(ssh2_hmac_ctx *ctx);
|
||||
|
||||
#define LIBSSH2_ED25519_KEY_LEN 32
|
||||
#define LIBSSH2_ED25519_PRIVATE_KEY_LEN 64
|
||||
#define LIBSSH2_ED25519_SIG_LEN 64
|
||||
#define LIBSSH2_EC_P256_PUBLIC_KEY_LEN 65
|
||||
#define LIBSSH2_EC_P384_PUBLIC_KEY_LEN 97
|
||||
#define LIBSSH2_MLKEM_SHARED_SECRET_LEN 32
|
||||
#define LIBSSH2_MLKEM_512_PRIVATE_KEY_LEN 1632
|
||||
#define LIBSSH2_MLKEM_512_PUBLIC_KEY_LEN 800
|
||||
#define LIBSSH2_MLKEM_512_CIPHERTEXT 768
|
||||
#define LIBSSH2_MLKEM_768_PRIVATE_KEY_LEN 2400
|
||||
#define LIBSSH2_MLKEM_768_PUBLIC_KEY_LEN 1184
|
||||
#define LIBSSH2_MLKEM_768_CIPHERTEXT 1088
|
||||
#define LIBSSH2_MLKEM_1024_PRIVATE_KEY_LEN 3168
|
||||
#define LIBSSH2_MLKEM_1024_PUBLIC_KEY_LEN 1568
|
||||
#define LIBSSH2_MLKEM_1024_CIPHERTEXT 1568
|
||||
#define SSH2_ED25519_KEY_LEN 32
|
||||
#define SSH2_ED25519_PRIVATE_KEY_LEN 64
|
||||
#define SSH2_ED25519_SIG_LEN 64
|
||||
|
||||
#define SSH2_EC_P256_PUBLIC_KEY_LEN 65
|
||||
#define SSH2_EC_P384_PUBLIC_KEY_LEN 97
|
||||
|
||||
#define SSH2_MLKEM_SHARED_SECRET_LEN 32
|
||||
#define SSH2_MLKEM_512_PRIVATE_KEY_LEN 1632
|
||||
#define SSH2_MLKEM_512_PUBLIC_KEY_LEN 800
|
||||
#define SSH2_MLKEM_512_CIPHERTEXT 768
|
||||
#define SSH2_MLKEM_768_PRIVATE_KEY_LEN 2400
|
||||
#define SSH2_MLKEM_768_PUBLIC_KEY_LEN 1184
|
||||
#define SSH2_MLKEM_768_CIPHERTEXT 1088
|
||||
#define SSH2_MLKEM_1024_PRIVATE_KEY_LEN 3168
|
||||
#define SSH2_MLKEM_1024_PUBLIC_KEY_LEN 1568
|
||||
#define SSH2_MLKEM_1024_CIPHERTEXT 1568
|
||||
|
||||
#if LIBSSH2_RSA
|
||||
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
||||
const unsigned char *edata, unsigned long elen,
|
||||
const unsigned char *ndata, unsigned long nlen,
|
||||
const unsigned char *ddata, unsigned long dlen,
|
||||
const unsigned char *pdata, unsigned long plen,
|
||||
const unsigned char *qdata, unsigned long qlen,
|
||||
const unsigned char *e1data, unsigned long e1len,
|
||||
const unsigned char *e2data, unsigned long e2len,
|
||||
const unsigned char *coeffdata, unsigned long coefflen);
|
||||
int _libssh2_rsa_new_private(libssh2_rsa_ctx **rsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase);
|
||||
int ssh2_rsa_new(ssh2_rsa_ctx **rsa,
|
||||
const unsigned char *edata, unsigned long elen,
|
||||
const unsigned char *ndata, unsigned long nlen,
|
||||
const unsigned char *ddata, unsigned long dlen,
|
||||
const unsigned char *pdata, unsigned long plen,
|
||||
const unsigned char *qdata, unsigned long qlen,
|
||||
const unsigned char *e1data, unsigned long e1len,
|
||||
const unsigned char *e2data, unsigned long e2len,
|
||||
const unsigned char *coeffdata, unsigned long coefflen);
|
||||
int ssh2_rsa_new_private(ssh2_rsa_ctx **rsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase);
|
||||
#if LIBSSH2_RSA_SHA1
|
||||
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
||||
libssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len,
|
||||
unsigned char **signature,
|
||||
size_t *signature_len);
|
||||
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *sig,
|
||||
size_t sig_len,
|
||||
const unsigned char *m, size_t m_len);
|
||||
int ssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
||||
ssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len,
|
||||
unsigned char **signature,
|
||||
size_t *signature_len);
|
||||
int ssh2_rsa_sha1_verify(ssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *sig,
|
||||
size_t sig_len,
|
||||
const unsigned char *m, size_t m_len);
|
||||
#endif
|
||||
#if LIBSSH2_RSA_SHA2
|
||||
int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION *session,
|
||||
libssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len,
|
||||
unsigned char **signature,
|
||||
size_t *signature_len);
|
||||
int _libssh2_rsa_sha2_verify(libssh2_rsa_ctx *rsactx,
|
||||
size_t hash_len,
|
||||
const unsigned char *sig,
|
||||
size_t sig_len,
|
||||
const unsigned char *m, size_t m_len);
|
||||
int ssh2_rsa_sha2_sign(LIBSSH2_SESSION *session,
|
||||
ssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len,
|
||||
unsigned char **signature,
|
||||
size_t *signature_len);
|
||||
int ssh2_rsa_sha2_verify(ssh2_rsa_ctx *rsactx,
|
||||
size_t hash_len,
|
||||
const unsigned char *sig,
|
||||
size_t sig_len,
|
||||
const unsigned char *m, size_t m_len);
|
||||
#endif
|
||||
int _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase);
|
||||
int ssh2_rsa_new_private_frommemory(ssh2_rsa_ctx **rsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase);
|
||||
#endif
|
||||
|
||||
#if LIBSSH2_DSA
|
||||
int _libssh2_dsa_new(libssh2_dsa_ctx **dsa,
|
||||
const unsigned char *pdata, unsigned long plen,
|
||||
const unsigned char *qdata, unsigned long qlen,
|
||||
const unsigned char *gdata, unsigned long glen,
|
||||
const unsigned char *ydata, unsigned long ylen,
|
||||
const unsigned char *x, unsigned long x_len);
|
||||
int _libssh2_dsa_new_private(libssh2_dsa_ctx **dsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase);
|
||||
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
||||
const unsigned char *sig,
|
||||
const unsigned char *m, size_t m_len);
|
||||
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len, unsigned char *sig);
|
||||
int _libssh2_dsa_new_private_frommemory(libssh2_dsa_ctx **dsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase);
|
||||
int ssh2_dsa_new(ssh2_dsa_ctx **dsa,
|
||||
const unsigned char *pdata, unsigned long plen,
|
||||
const unsigned char *qdata, unsigned long qlen,
|
||||
const unsigned char *gdata, unsigned long glen,
|
||||
const unsigned char *ydata, unsigned long ylen,
|
||||
const unsigned char *x, unsigned long x_len);
|
||||
int ssh2_dsa_new_private(ssh2_dsa_ctx **dsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase);
|
||||
int ssh2_dsa_sha1_verify(ssh2_dsa_ctx *dsactx,
|
||||
const unsigned char *sig,
|
||||
const unsigned char *m, size_t m_len);
|
||||
int ssh2_dsa_sha1_sign(ssh2_dsa_ctx *dsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len, unsigned char *sig);
|
||||
int ssh2_dsa_new_private_frommemory(ssh2_dsa_ctx **dsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase);
|
||||
#endif
|
||||
|
||||
#if LIBSSH2_ECDSA
|
||||
int _libssh2_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx **ec_ctx,
|
||||
const unsigned char *k,
|
||||
size_t k_len,
|
||||
libssh2_curve_type curve);
|
||||
int ssh2_ecdsa_curve_name_with_octal_new(ssh2_ecdsa_ctx **ec_ctx,
|
||||
const unsigned char *k,
|
||||
size_t k_len,
|
||||
ssh2_curve_type curve);
|
||||
|
||||
int _libssh2_ecdsa_new_private(libssh2_ecdsa_ctx **ec_ctx,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase);
|
||||
int ssh2_ecdsa_new_private(ssh2_ecdsa_ctx **ec_ctx,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase);
|
||||
|
||||
int _libssh2_ecdsa_new_private_sk(libssh2_ecdsa_ctx **ec_ctx,
|
||||
unsigned char *flags,
|
||||
const char **application,
|
||||
const unsigned char **key_handle,
|
||||
size_t *handle_len,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase);
|
||||
int ssh2_ecdsa_new_private_sk(ssh2_ecdsa_ctx **ec_ctx,
|
||||
unsigned char *flags,
|
||||
const char **application,
|
||||
const unsigned char **key_handle,
|
||||
size_t *handle_len,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase);
|
||||
|
||||
int _libssh2_ecdsa_verify(libssh2_ecdsa_ctx *ec_ctx,
|
||||
const unsigned char *r, size_t r_len,
|
||||
const unsigned char *s, size_t s_len,
|
||||
const unsigned char *m, size_t m_len);
|
||||
int ssh2_ecdsa_verify(ssh2_ecdsa_ctx *ec_ctx,
|
||||
const unsigned char *r, size_t r_len,
|
||||
const unsigned char *s, size_t s_len,
|
||||
const unsigned char *m, size_t m_len);
|
||||
|
||||
int _libssh2_ecdsa_create_key(LIBSSH2_SESSION *session,
|
||||
libssh2_ec_key **out_private_key,
|
||||
unsigned char **out_public_key_octal,
|
||||
size_t *out_public_key_octal_len,
|
||||
libssh2_curve_type curve_type);
|
||||
int ssh2_ecdsa_create_key(LIBSSH2_SESSION *session,
|
||||
ssh2_ec_key **out_private_key,
|
||||
unsigned char **out_public_key_octal,
|
||||
size_t *out_public_key_octal_len,
|
||||
ssh2_curve_type curve_type);
|
||||
|
||||
int _libssh2_ecdh_gen_k(libssh2_bn **k, libssh2_ec_key *private_key,
|
||||
const unsigned char *server_public_key,
|
||||
size_t server_public_key_len);
|
||||
int ssh2_ecdh_gen_k(ssh2_bn **k, ssh2_ec_key *private_key,
|
||||
const unsigned char *server_public_key,
|
||||
size_t server_public_key_len);
|
||||
|
||||
int _libssh2_ecdsa_sign(LIBSSH2_SESSION *session, libssh2_ecdsa_ctx *ec_ctx,
|
||||
const unsigned char *hash, size_t hash_len,
|
||||
unsigned char **signature, size_t *signature_len);
|
||||
int ssh2_ecdsa_sign(LIBSSH2_SESSION *session, ssh2_ecdsa_ctx *ec_ctx,
|
||||
const unsigned char *hash, size_t hash_len,
|
||||
unsigned char **signature, size_t *signature_len);
|
||||
|
||||
int _libssh2_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx **ec_ctx,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase);
|
||||
int ssh2_ecdsa_new_private_frommemory(ssh2_ecdsa_ctx **ec_ctx,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase);
|
||||
|
||||
int _libssh2_ecdsa_new_private_frommemory_sk(libssh2_ecdsa_ctx **ec_ctx,
|
||||
unsigned char *flags,
|
||||
const char **application,
|
||||
const unsigned char **key_handle,
|
||||
size_t *handle_len,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase);
|
||||
int ssh2_ecdsa_new_private_frommemory_sk(ssh2_ecdsa_ctx **ec_ctx,
|
||||
unsigned char *flags,
|
||||
const char **application,
|
||||
const unsigned char **key_handle,
|
||||
size_t *handle_len,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase);
|
||||
|
||||
libssh2_curve_type _libssh2_ecdsa_get_curve_type(libssh2_ecdsa_ctx *ec_ctx);
|
||||
ssh2_curve_type ssh2_ecdsa_get_curve_type(ssh2_ecdsa_ctx *ec_ctx);
|
||||
|
||||
int _libssh2_ecdsa_curve_type_from_name(const char *name,
|
||||
libssh2_curve_type *out_type);
|
||||
int ssh2_ecdsa_curve_type_from_name(const char *name,
|
||||
ssh2_curve_type *out_type);
|
||||
|
||||
#endif /* LIBSSH2_ECDSA */
|
||||
|
||||
#if LIBSSH2_ED25519
|
||||
|
||||
int _libssh2_curve25519_new(LIBSSH2_SESSION *session, uint8_t **out_public_key,
|
||||
uint8_t **out_private_key);
|
||||
int ssh2_curve25519_new(LIBSSH2_SESSION *session, uint8_t **out_public_key,
|
||||
uint8_t **out_private_key);
|
||||
|
||||
int _libssh2_curve25519_gen_k(
|
||||
libssh2_bn **k,
|
||||
uint8_t private_key[LIBSSH2_ED25519_KEY_LEN],
|
||||
uint8_t server_public_key[LIBSSH2_ED25519_KEY_LEN]);
|
||||
int ssh2_curve25519_gen_k(
|
||||
ssh2_bn **k,
|
||||
uint8_t private_key[SSH2_ED25519_KEY_LEN],
|
||||
uint8_t server_public_key[SSH2_ED25519_KEY_LEN]);
|
||||
|
||||
int _libssh2_ed25519_verify(libssh2_ed25519_ctx *ctx, const uint8_t *s,
|
||||
size_t s_len, const uint8_t *m, size_t m_len);
|
||||
int ssh2_ed25519_verify(ssh2_ed25519_ctx *ctx, const uint8_t *s,
|
||||
size_t s_len, const uint8_t *m, size_t m_len);
|
||||
|
||||
int _libssh2_ed25519_new_private(libssh2_ed25519_ctx **ed_ctx,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const uint8_t *passphrase);
|
||||
int ssh2_ed25519_new_private(ssh2_ed25519_ctx **ed_ctx,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const uint8_t *passphrase);
|
||||
|
||||
int _libssh2_ed25519_new_private_sk(libssh2_ed25519_ctx **ed_ctx,
|
||||
unsigned char *flags,
|
||||
const char **application,
|
||||
const unsigned char **key_handle,
|
||||
size_t *handle_len,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const uint8_t *passphrase);
|
||||
|
||||
int _libssh2_ed25519_new_public(libssh2_ed25519_ctx **ed_ctx,
|
||||
int ssh2_ed25519_new_private_sk(ssh2_ed25519_ctx **ed_ctx,
|
||||
unsigned char *flags,
|
||||
const char **application,
|
||||
const unsigned char **key_handle,
|
||||
size_t *handle_len,
|
||||
LIBSSH2_SESSION *session,
|
||||
const unsigned char *raw_pub_key,
|
||||
const size_t key_len);
|
||||
const char *filename,
|
||||
const uint8_t *passphrase);
|
||||
|
||||
int _libssh2_ed25519_sign(libssh2_ed25519_ctx *ctx, LIBSSH2_SESSION *session,
|
||||
uint8_t **out_sig, size_t *out_sig_len,
|
||||
const uint8_t *message, size_t message_len);
|
||||
int ssh2_ed25519_new_public(ssh2_ed25519_ctx **ed_ctx,
|
||||
LIBSSH2_SESSION *session,
|
||||
const unsigned char *raw_pub_key,
|
||||
const size_t key_len);
|
||||
|
||||
int _libssh2_ed25519_new_private_frommemory(libssh2_ed25519_ctx **ed_ctx,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase);
|
||||
int ssh2_ed25519_sign(ssh2_ed25519_ctx *ctx, LIBSSH2_SESSION *session,
|
||||
uint8_t **out_sig, size_t *out_sig_len,
|
||||
const uint8_t *message, size_t message_len);
|
||||
|
||||
int _libssh2_ed25519_new_private_frommemory_sk(
|
||||
libssh2_ed25519_ctx **ed_ctx,
|
||||
int ssh2_ed25519_new_private_frommemory(ssh2_ed25519_ctx **ed_ctx,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase);
|
||||
|
||||
int ssh2_ed25519_new_private_frommemory_sk(
|
||||
ssh2_ed25519_ctx **ed_ctx,
|
||||
unsigned char *flags,
|
||||
const char **application,
|
||||
const unsigned char **key_handle,
|
||||
@@ -280,72 +276,68 @@ int _libssh2_ed25519_new_private_frommemory_sk(
|
||||
#endif /* LIBSSH2_ED25519 */
|
||||
|
||||
#if LIBSSH2_MLKEM
|
||||
int _libssh2_mlkem_new(LIBSSH2_SESSION *session,
|
||||
int ml_kem_size,
|
||||
unsigned char **out_public_key,
|
||||
unsigned char **out_private_key);
|
||||
int ssh2_mlkem_new(LIBSSH2_SESSION *session,
|
||||
int ml_kem_size,
|
||||
unsigned char **out_public_key,
|
||||
unsigned char **out_private_key);
|
||||
|
||||
int _libssh2_mlkem_get_sk(unsigned char *out_shared_key,
|
||||
int ml_kem_size,
|
||||
uint8_t *private_key,
|
||||
uint8_t *server_ciphertext);
|
||||
int ssh2_mlkem_get_sk(unsigned char *out_shared_key,
|
||||
int ml_kem_size,
|
||||
uint8_t *private_key,
|
||||
uint8_t *server_ciphertext);
|
||||
|
||||
#endif /* LIBSSH2_MLKEM */
|
||||
|
||||
int _libssh2_cipher_init(libssh2_cipher_ctx *h,
|
||||
LIBSSH2_CIPHER_T(algo),
|
||||
unsigned char *iv,
|
||||
unsigned char *secret, int encrypt);
|
||||
int ssh2_cipher_init(ssh2_cipher_ctx *h, SSH2_CIPHER_T(algo),
|
||||
unsigned char *iv, unsigned char *secret, int encrypt);
|
||||
|
||||
int _libssh2_cipher_crypt(libssh2_cipher_ctx *ctx,
|
||||
LIBSSH2_CIPHER_T(algo),
|
||||
int encrypt, unsigned char *block, size_t blocksize,
|
||||
int firstlast);
|
||||
int ssh2_cipher_crypt(ssh2_cipher_ctx *ctx, SSH2_CIPHER_T(algo),
|
||||
int encrypt, unsigned char *block, size_t blocksize,
|
||||
int firstlast);
|
||||
|
||||
int _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
|
||||
int ssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
|
||||
unsigned char **method,
|
||||
size_t *method_len,
|
||||
unsigned char **pubkeydata,
|
||||
size_t *pubkeydata_len,
|
||||
const char *privatekey,
|
||||
const char *passphrase);
|
||||
|
||||
int ssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
|
||||
unsigned char **method,
|
||||
size_t *method_len,
|
||||
unsigned char **pubkeydata,
|
||||
size_t *pubkeydata_len,
|
||||
const char *privatekeydata,
|
||||
size_t privatekeydata_len,
|
||||
const char *passphrase);
|
||||
|
||||
int ssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session,
|
||||
unsigned char **method,
|
||||
size_t *method_len,
|
||||
unsigned char **pubkeydata,
|
||||
size_t *pubkeydata_len,
|
||||
const char *privatekey,
|
||||
int *algorithm,
|
||||
unsigned char *flags,
|
||||
const char **application,
|
||||
const unsigned char **key_handle,
|
||||
size_t *handle_len,
|
||||
const char *privatekeydata,
|
||||
size_t privatekeydata_len,
|
||||
const char *passphrase);
|
||||
|
||||
int _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
|
||||
unsigned char **method,
|
||||
size_t *method_len,
|
||||
unsigned char **pubkeydata,
|
||||
size_t *pubkeydata_len,
|
||||
const char *privatekeydata,
|
||||
size_t privatekeydata_len,
|
||||
const char *passphrase);
|
||||
|
||||
int _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session,
|
||||
unsigned char **method,
|
||||
size_t *method_len,
|
||||
unsigned char **pubkeydata,
|
||||
size_t *pubkeydata_len,
|
||||
int *algorithm,
|
||||
unsigned char *flags,
|
||||
const char **application,
|
||||
const unsigned char **key_handle,
|
||||
size_t *handle_len,
|
||||
const char *privatekeydata,
|
||||
size_t privatekeydata_len,
|
||||
const char *passphrase);
|
||||
|
||||
/**
|
||||
* @abstract Returns supported algorithms used for upgrading public
|
||||
* key signing RFC 8332
|
||||
* @discussion Based on the incoming key_method value, this function
|
||||
* returns supported algorithms that can upgrade the key method
|
||||
* @related _libssh2_key_sign_algorithm()
|
||||
* @param key_method current key method, usually the default key sig method
|
||||
* @param key_method_len length of the key method buffer
|
||||
* @result comma separated list of supported upgrade options per RFC 8332, if
|
||||
* there is no upgrade option return NULL
|
||||
*/
|
||||
const char *_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session,
|
||||
unsigned char *key_method,
|
||||
size_t key_method_len);
|
||||
const char *ssh2_supported_key_sign_algs(LIBSSH2_SESSION *session,
|
||||
unsigned char *key_method,
|
||||
size_t key_method_len);
|
||||
|
||||
#endif /* LIBSSH2_CRYPTO_H */
|
||||
|
||||
@@ -47,7 +47,7 @@ LIBSSH2_API
|
||||
int libssh2_init(int flags)
|
||||
{
|
||||
if(s_initialized == 0 && !(flags & LIBSSH2_INIT_NO_CRYPTO)) {
|
||||
libssh2_crypto_init();
|
||||
ssh2_crypto_init();
|
||||
}
|
||||
|
||||
s_initialized++;
|
||||
@@ -66,11 +66,11 @@ void libssh2_exit(void)
|
||||
|
||||
if(s_initialized == 0 &&
|
||||
!(s_init_flags & LIBSSH2_INIT_NO_CRYPTO)) {
|
||||
libssh2_crypto_exit();
|
||||
ssh2_crypto_exit();
|
||||
}
|
||||
}
|
||||
|
||||
void _libssh2_init_if_needed(void)
|
||||
void ssh2_init_if_needed(void)
|
||||
{
|
||||
if(s_initialized == 0)
|
||||
(void)libssh2_init(0);
|
||||
|
||||
391
src/hostkey.c
391
src/hostkey.c
@@ -61,7 +61,7 @@ static int hostkey_method_ssh_rsa_init(LIBSSH2_SESSION *session,
|
||||
size_t hostkey_data_len,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_rsa_ctx *rsactx;
|
||||
ssh2_rsa_ctx *rsactx;
|
||||
unsigned char *e, *n, *type;
|
||||
size_t e_len, n_len, type_len;
|
||||
struct string_buf buf;
|
||||
@@ -72,16 +72,15 @@ static int hostkey_method_ssh_rsa_init(LIBSSH2_SESSION *session,
|
||||
}
|
||||
|
||||
if(hostkey_data_len < 19) {
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_ERROR,
|
||||
"host key length too short"));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_ERROR, "host key length too short"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf.data = (unsigned char *)LIBSSH2_UNCONST(hostkey_data);
|
||||
buf.data = (unsigned char *)SSH2_UNCONST(hostkey_data);
|
||||
buf.dataptr = buf.data;
|
||||
buf.len = hostkey_data_len;
|
||||
|
||||
if(_libssh2_get_string(&buf, &type, &type_len)) {
|
||||
if(ssh2_get_string(&buf, &type, &type_len)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -102,25 +101,25 @@ static int hostkey_method_ssh_rsa_init(LIBSSH2_SESSION *session,
|
||||
else
|
||||
#endif
|
||||
{
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_ERROR,
|
||||
"unexpected rsa type: %.*s", (int)type_len, type));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_ERROR, "unexpected rsa type: %.*s",
|
||||
(int)type_len, type));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(_libssh2_get_string(&buf, &e, &e_len))
|
||||
if(ssh2_get_string(&buf, &e, &e_len))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_get_string(&buf, &n, &n_len))
|
||||
if(ssh2_get_string(&buf, &n, &n_len))
|
||||
return -1;
|
||||
|
||||
if(!_libssh2_eob(&buf))
|
||||
if(!ssh2_eob(&buf))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_rsa_new(&rsactx,
|
||||
e, (unsigned long)e_len,
|
||||
n, (unsigned long)n_len,
|
||||
NULL, 0, NULL, 0, NULL, 0,
|
||||
NULL, 0, NULL, 0, NULL, 0)) {
|
||||
if(ssh2_rsa_new(&rsactx,
|
||||
e, (unsigned long)e_len,
|
||||
n, (unsigned long)n_len,
|
||||
NULL, 0, NULL, 0, NULL, 0,
|
||||
NULL, 0, NULL, 0, NULL, 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -137,7 +136,7 @@ static int hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_rsa_ctx *rsactx;
|
||||
ssh2_rsa_ctx *rsactx;
|
||||
int ret;
|
||||
|
||||
if(*abstract) {
|
||||
@@ -145,7 +144,7 @@ static int hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION *session,
|
||||
*abstract = NULL;
|
||||
}
|
||||
|
||||
ret = _libssh2_rsa_new_private(&rsactx, session, privkeyfile, passphrase);
|
||||
ret = ssh2_rsa_new_private(&rsactx, session, privkeyfile, passphrase);
|
||||
if(ret) {
|
||||
return -1;
|
||||
}
|
||||
@@ -165,7 +164,7 @@ static int hostkey_method_ssh_rsa_initPEMFromMemory(
|
||||
const unsigned char *passphrase,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_rsa_ctx *rsactx;
|
||||
ssh2_rsa_ctx *rsactx;
|
||||
int ret;
|
||||
|
||||
if(*abstract) {
|
||||
@@ -173,9 +172,9 @@ static int hostkey_method_ssh_rsa_initPEMFromMemory(
|
||||
*abstract = NULL;
|
||||
}
|
||||
|
||||
ret = _libssh2_rsa_new_private_frommemory(&rsactx, session,
|
||||
privkeyfiledata,
|
||||
privkeyfiledata_len, passphrase);
|
||||
ret = ssh2_rsa_new_private_frommemory(&rsactx, session,
|
||||
privkeyfiledata,
|
||||
privkeyfiledata_len, passphrase);
|
||||
if(ret) {
|
||||
return -1;
|
||||
}
|
||||
@@ -195,7 +194,7 @@ static int hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION *session,
|
||||
const unsigned char *m,
|
||||
size_t m_len, void **abstract)
|
||||
{
|
||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *)(*abstract);
|
||||
ssh2_rsa_ctx *rsactx = (ssh2_rsa_ctx *)(*abstract);
|
||||
(void)session;
|
||||
|
||||
/* Skip past keyname_len(4) + keyname(7){"ssh-rsa"} + signature_len(4) */
|
||||
@@ -204,7 +203,7 @@ static int hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION *session,
|
||||
|
||||
sig += 15;
|
||||
sig_len -= 15;
|
||||
return _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len);
|
||||
return ssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -217,32 +216,31 @@ static int hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION *session,
|
||||
const struct iovec datavec[],
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *)(*abstract);
|
||||
ssh2_rsa_ctx *rsactx = (ssh2_rsa_ctx *)(*abstract);
|
||||
|
||||
#ifdef _libssh2_rsa_sha1_signv
|
||||
return _libssh2_rsa_sha1_signv(session, signature, signature_len,
|
||||
veccount, datavec, rsactx);
|
||||
#ifdef ssh2_rsa_sha1_signv
|
||||
return ssh2_rsa_sha1_signv(session, signature, signature_len,
|
||||
veccount, datavec, rsactx);
|
||||
#else
|
||||
int ret;
|
||||
int i;
|
||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||
libssh2_sha1_ctx ctx;
|
||||
ssh2_sha1_ctx ctx;
|
||||
|
||||
if(!libssh2_sha1_init(&ctx)) {
|
||||
if(!ssh2_sha1_init(&ctx)) {
|
||||
return -1;
|
||||
}
|
||||
for(i = 0; i < veccount; i++) {
|
||||
if(!libssh2_sha1_update(ctx,
|
||||
datavec[i].iov_base, datavec[i].iov_len)) {
|
||||
if(!ssh2_sha1_update(ctx, datavec[i].iov_base, datavec[i].iov_len)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(!libssh2_sha1_final(ctx, hash)) {
|
||||
if(!ssh2_sha1_final(ctx, hash)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = _libssh2_rsa_sha1_sign(session, rsactx, hash, SHA_DIGEST_LENGTH,
|
||||
signature, signature_len);
|
||||
ret = ssh2_rsa_sha1_sign(session, rsactx, hash, SHA_DIGEST_LENGTH,
|
||||
signature, signature_len);
|
||||
if(ret) {
|
||||
return -1;
|
||||
}
|
||||
@@ -264,7 +262,7 @@ static int hostkey_method_ssh_rsa_sha2_256_sig_verify(
|
||||
const unsigned char *m,
|
||||
size_t m_len, void **abstract)
|
||||
{
|
||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *)(*abstract);
|
||||
ssh2_rsa_ctx *rsactx = (ssh2_rsa_ctx *)(*abstract);
|
||||
(void)session;
|
||||
|
||||
/* Skip past keyname_len(4) + keyname(12){"rsa-sha2-256"} +
|
||||
@@ -274,8 +272,8 @@ static int hostkey_method_ssh_rsa_sha2_256_sig_verify(
|
||||
|
||||
sig += 20;
|
||||
sig_len -= 20;
|
||||
return _libssh2_rsa_sha2_verify(rsactx, SHA256_DIGEST_LENGTH, sig, sig_len,
|
||||
m, m_len);
|
||||
return ssh2_rsa_sha2_verify(rsactx, SHA256_DIGEST_LENGTH, sig, sig_len,
|
||||
m, m_len);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -288,32 +286,31 @@ static int hostkey_method_ssh_rsa_sha2_256_signv(LIBSSH2_SESSION *session,
|
||||
const struct iovec datavec[],
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *)(*abstract);
|
||||
ssh2_rsa_ctx *rsactx = (ssh2_rsa_ctx *)(*abstract);
|
||||
|
||||
#ifdef _libssh2_rsa_sha2_256_signv
|
||||
return _libssh2_rsa_sha2_256_signv(session, signature, signature_len,
|
||||
veccount, datavec, rsactx);
|
||||
#ifdef ssh2_rsa_sha2_256_signv
|
||||
return ssh2_rsa_sha2_256_signv(session, signature, signature_len,
|
||||
veccount, datavec, rsactx);
|
||||
#else
|
||||
int ret;
|
||||
int i;
|
||||
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||
libssh2_sha256_ctx ctx;
|
||||
ssh2_sha256_ctx ctx;
|
||||
|
||||
if(!libssh2_sha256_init(&ctx)) {
|
||||
if(!ssh2_sha256_init(&ctx)) {
|
||||
return -1;
|
||||
}
|
||||
for(i = 0; i < veccount; i++) {
|
||||
if(!libssh2_sha256_update(ctx,
|
||||
datavec[i].iov_base, datavec[i].iov_len)) {
|
||||
if(!ssh2_sha256_update(ctx, datavec[i].iov_base, datavec[i].iov_len)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(!libssh2_sha256_final(ctx, hash)) {
|
||||
if(!ssh2_sha256_final(ctx, hash)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = _libssh2_rsa_sha2_sign(session, rsactx, hash, SHA256_DIGEST_LENGTH,
|
||||
signature, signature_len);
|
||||
ret = ssh2_rsa_sha2_sign(session, rsactx, hash, SHA256_DIGEST_LENGTH,
|
||||
signature, signature_len);
|
||||
if(ret) {
|
||||
return -1;
|
||||
}
|
||||
@@ -332,7 +329,7 @@ static int hostkey_method_ssh_rsa_sha2_512_sig_verify(
|
||||
const unsigned char *m,
|
||||
size_t m_len, void **abstract)
|
||||
{
|
||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *)(*abstract);
|
||||
ssh2_rsa_ctx *rsactx = (ssh2_rsa_ctx *)(*abstract);
|
||||
(void)session;
|
||||
|
||||
/* Skip past keyname_len(4) + keyname(12){"rsa-sha2-512"} +
|
||||
@@ -342,8 +339,8 @@ static int hostkey_method_ssh_rsa_sha2_512_sig_verify(
|
||||
|
||||
sig += 20;
|
||||
sig_len -= 20;
|
||||
return _libssh2_rsa_sha2_verify(rsactx, SHA512_DIGEST_LENGTH, sig,
|
||||
sig_len, m, m_len);
|
||||
return ssh2_rsa_sha2_verify(rsactx, SHA512_DIGEST_LENGTH, sig,
|
||||
sig_len, m, m_len);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -356,32 +353,31 @@ static int hostkey_method_ssh_rsa_sha2_512_signv(LIBSSH2_SESSION *session,
|
||||
const struct iovec datavec[],
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *)(*abstract);
|
||||
ssh2_rsa_ctx *rsactx = (ssh2_rsa_ctx *)(*abstract);
|
||||
|
||||
#ifdef _libssh2_rsa_sha2_512_signv
|
||||
return _libssh2_rsa_sha2_512_signv(session, signature, signature_len,
|
||||
veccount, datavec, rsactx);
|
||||
#ifdef ssh2_rsa_sha2_512_signv
|
||||
return ssh2_rsa_sha2_512_signv(session, signature, signature_len,
|
||||
veccount, datavec, rsactx);
|
||||
#else
|
||||
int ret;
|
||||
int i;
|
||||
unsigned char hash[SHA512_DIGEST_LENGTH];
|
||||
libssh2_sha512_ctx ctx;
|
||||
ssh2_sha512_ctx ctx;
|
||||
|
||||
if(!libssh2_sha512_init(&ctx)) {
|
||||
if(!ssh2_sha512_init(&ctx)) {
|
||||
return -1;
|
||||
}
|
||||
for(i = 0; i < veccount; i++) {
|
||||
if(!libssh2_sha512_update(ctx,
|
||||
datavec[i].iov_base, datavec[i].iov_len)) {
|
||||
if(!ssh2_sha512_update(ctx, datavec[i].iov_base, datavec[i].iov_len)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(!libssh2_sha512_final(ctx, hash)) {
|
||||
if(!ssh2_sha512_final(ctx, hash)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = _libssh2_rsa_sha2_sign(session, rsactx, hash, SHA512_DIGEST_LENGTH,
|
||||
signature, signature_len);
|
||||
ret = ssh2_rsa_sha2_sign(session, rsactx, hash, SHA512_DIGEST_LENGTH,
|
||||
signature, signature_len);
|
||||
if(ret) {
|
||||
return -1;
|
||||
}
|
||||
@@ -398,10 +394,10 @@ static int hostkey_method_ssh_rsa_sha2_512_signv(LIBSSH2_SESSION *session,
|
||||
static int hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION *session,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *)(*abstract);
|
||||
ssh2_rsa_ctx *rsactx = (ssh2_rsa_ctx *)(*abstract);
|
||||
(void)session;
|
||||
|
||||
_libssh2_rsa_free(rsactx);
|
||||
ssh2_rsa_free(rsactx);
|
||||
|
||||
*abstract = NULL;
|
||||
|
||||
@@ -514,7 +510,7 @@ static int hostkey_method_ssh_dss_init(LIBSSH2_SESSION *session,
|
||||
size_t hostkey_data_len,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_dsa_ctx *dsactx;
|
||||
ssh2_dsa_ctx *dsactx;
|
||||
unsigned char *p, *q, *g, *y;
|
||||
size_t p_len, q_len, g_len, y_len;
|
||||
struct string_buf buf;
|
||||
@@ -525,39 +521,38 @@ static int hostkey_method_ssh_dss_init(LIBSSH2_SESSION *session,
|
||||
}
|
||||
|
||||
if(hostkey_data_len < 27) {
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_ERROR,
|
||||
"host key length too short"));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_ERROR, "host key length too short"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf.data = (unsigned char *)LIBSSH2_UNCONST(hostkey_data);
|
||||
buf.data = (unsigned char *)SSH2_UNCONST(hostkey_data);
|
||||
buf.dataptr = buf.data;
|
||||
buf.len = hostkey_data_len;
|
||||
|
||||
if(_libssh2_match_string(&buf, "ssh-dss"))
|
||||
if(ssh2_match_string(&buf, "ssh-dss"))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_get_string(&buf, &p, &p_len))
|
||||
if(ssh2_get_string(&buf, &p, &p_len))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_get_string(&buf, &q, &q_len))
|
||||
if(ssh2_get_string(&buf, &q, &q_len))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_get_string(&buf, &g, &g_len))
|
||||
if(ssh2_get_string(&buf, &g, &g_len))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_get_string(&buf, &y, &y_len))
|
||||
if(ssh2_get_string(&buf, &y, &y_len))
|
||||
return -1;
|
||||
|
||||
if(!_libssh2_eob(&buf))
|
||||
if(!ssh2_eob(&buf))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_dsa_new(&dsactx,
|
||||
p, (unsigned long)p_len,
|
||||
q, (unsigned long)q_len,
|
||||
g, (unsigned long)g_len,
|
||||
y, (unsigned long)y_len,
|
||||
NULL, 0)) {
|
||||
if(ssh2_dsa_new(&dsactx,
|
||||
p, (unsigned long)p_len,
|
||||
q, (unsigned long)q_len,
|
||||
g, (unsigned long)g_len,
|
||||
y, (unsigned long)y_len,
|
||||
NULL, 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -574,7 +569,7 @@ static int hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_dsa_ctx *dsactx;
|
||||
ssh2_dsa_ctx *dsactx;
|
||||
int ret;
|
||||
|
||||
if(*abstract) {
|
||||
@@ -582,7 +577,7 @@ static int hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION *session,
|
||||
*abstract = NULL;
|
||||
}
|
||||
|
||||
ret = _libssh2_dsa_new_private(&dsactx, session, privkeyfile, passphrase);
|
||||
ret = ssh2_dsa_new_private(&dsactx, session, privkeyfile, passphrase);
|
||||
if(ret) {
|
||||
return -1;
|
||||
}
|
||||
@@ -602,7 +597,7 @@ static int hostkey_method_ssh_dss_initPEMFromMemory(
|
||||
const unsigned char *passphrase,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_dsa_ctx *dsactx;
|
||||
ssh2_dsa_ctx *dsactx;
|
||||
int ret;
|
||||
|
||||
if(*abstract) {
|
||||
@@ -610,9 +605,9 @@ static int hostkey_method_ssh_dss_initPEMFromMemory(
|
||||
*abstract = NULL;
|
||||
}
|
||||
|
||||
ret = _libssh2_dsa_new_private_frommemory(&dsactx, session,
|
||||
privkeyfiledata,
|
||||
privkeyfiledata_len, passphrase);
|
||||
ret = ssh2_dsa_new_private_frommemory(&dsactx, session,
|
||||
privkeyfiledata,
|
||||
privkeyfiledata_len, passphrase);
|
||||
if(ret) {
|
||||
return -1;
|
||||
}
|
||||
@@ -631,18 +626,18 @@ static int hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION *session,
|
||||
const unsigned char *m,
|
||||
size_t m_len, void **abstract)
|
||||
{
|
||||
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *)(*abstract);
|
||||
ssh2_dsa_ctx *dsactx = (ssh2_dsa_ctx *)(*abstract);
|
||||
|
||||
/* Skip past keyname_len(4) + keyname(7){"ssh-dss"} + signature_len(4) */
|
||||
if(sig_len != 55) {
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Invalid DSS signature length");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Invalid DSS signature length");
|
||||
}
|
||||
|
||||
sig += 15;
|
||||
sig_len -= 15;
|
||||
|
||||
return _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len);
|
||||
return ssh2_dsa_sha1_verify(dsactx, sig, m, m_len);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -655,18 +650,18 @@ static int hostkey_method_ssh_dss_signv(LIBSSH2_SESSION *session,
|
||||
const struct iovec datavec[],
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *)(*abstract);
|
||||
ssh2_dsa_ctx *dsactx = (ssh2_dsa_ctx *)(*abstract);
|
||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||
libssh2_sha1_ctx ctx;
|
||||
ssh2_sha1_ctx ctx;
|
||||
int i;
|
||||
|
||||
if(!libssh2_sha1_init(&ctx)) {
|
||||
if(!ssh2_sha1_init(&ctx)) {
|
||||
*signature = NULL;
|
||||
*signature_len = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*signature = LIBSSH2_CALLOC(session, 2 * SHA_DIGEST_LENGTH);
|
||||
*signature = SSH2_CALLOC(session, 2 * SHA_DIGEST_LENGTH);
|
||||
if(!*signature) {
|
||||
return -1;
|
||||
}
|
||||
@@ -674,17 +669,16 @@ static int hostkey_method_ssh_dss_signv(LIBSSH2_SESSION *session,
|
||||
*signature_len = 2 * SHA_DIGEST_LENGTH;
|
||||
|
||||
for(i = 0; i < veccount; i++) {
|
||||
if(!libssh2_sha1_update(ctx,
|
||||
datavec[i].iov_base, datavec[i].iov_len)) {
|
||||
if(!ssh2_sha1_update(ctx, datavec[i].iov_base, datavec[i].iov_len)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if(!libssh2_sha1_final(ctx, hash)) {
|
||||
if(!ssh2_sha1_final(ctx, hash)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(_libssh2_dsa_sha1_sign(dsactx, hash, SHA_DIGEST_LENGTH, *signature)) {
|
||||
LIBSSH2_FREE(session, *signature);
|
||||
if(ssh2_dsa_sha1_sign(dsactx, hash, SHA_DIGEST_LENGTH, *signature)) {
|
||||
SSH2_FREE(session, *signature);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -697,10 +691,10 @@ static int hostkey_method_ssh_dss_signv(LIBSSH2_SESSION *session,
|
||||
static int hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION *session,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *)(*abstract);
|
||||
ssh2_dsa_ctx *dsactx = (ssh2_dsa_ctx *)(*abstract);
|
||||
(void)session;
|
||||
|
||||
_libssh2_dsa_free(dsactx);
|
||||
ssh2_dsa_free(dsactx);
|
||||
|
||||
*abstract = NULL;
|
||||
|
||||
@@ -737,10 +731,10 @@ static int hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION *session,
|
||||
size_t hostkey_data_len,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_ecdsa_ctx *ec_ctx = NULL;
|
||||
ssh2_ecdsa_ctx *ec_ctx = NULL;
|
||||
unsigned char *type_str, *domain, *public_key;
|
||||
size_t key_len, len;
|
||||
libssh2_curve_type type;
|
||||
ssh2_curve_type type;
|
||||
struct string_buf buf;
|
||||
|
||||
if(abstract && *abstract) {
|
||||
@@ -749,56 +743,55 @@ static int hostkey_method_ssh_ecdsa_init(LIBSSH2_SESSION *session,
|
||||
}
|
||||
|
||||
if(hostkey_data_len < 39) {
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_ERROR,
|
||||
"host key length too short"));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_ERROR, "host key length too short"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf.data = (unsigned char *)LIBSSH2_UNCONST(hostkey_data);
|
||||
buf.data = (unsigned char *)SSH2_UNCONST(hostkey_data);
|
||||
buf.dataptr = buf.data;
|
||||
buf.len = hostkey_data_len;
|
||||
|
||||
if(_libssh2_get_string(&buf, &type_str, &len) || len != 19)
|
||||
if(ssh2_get_string(&buf, &type_str, &len) || len != 19)
|
||||
return -1;
|
||||
|
||||
if(strncmp((char *)type_str, "ecdsa-sha2-nistp256", 19) == 0) {
|
||||
type = LIBSSH2_EC_CURVE_NISTP256;
|
||||
type = SSH2_EC_CURVE_NISTP256;
|
||||
}
|
||||
else if(strncmp((char *)type_str, "ecdsa-sha2-nistp384", 19) == 0) {
|
||||
type = LIBSSH2_EC_CURVE_NISTP384;
|
||||
type = SSH2_EC_CURVE_NISTP384;
|
||||
}
|
||||
else if(strncmp((char *)type_str, "ecdsa-sha2-nistp521", 19) == 0) {
|
||||
type = LIBSSH2_EC_CURVE_NISTP521;
|
||||
type = SSH2_EC_CURVE_NISTP521;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(_libssh2_get_string(&buf, &domain, &len) || len != 8)
|
||||
if(ssh2_get_string(&buf, &domain, &len) || len != 8)
|
||||
return -1;
|
||||
|
||||
if(type == LIBSSH2_EC_CURVE_NISTP256 &&
|
||||
if(type == SSH2_EC_CURVE_NISTP256 &&
|
||||
strncmp((char *)domain, "nistp256", 8) != 0) {
|
||||
return -1;
|
||||
}
|
||||
else if(type == LIBSSH2_EC_CURVE_NISTP384 &&
|
||||
else if(type == SSH2_EC_CURVE_NISTP384 &&
|
||||
strncmp((char *)domain, "nistp384", 8) != 0) {
|
||||
return -1;
|
||||
}
|
||||
else if(type == LIBSSH2_EC_CURVE_NISTP521 &&
|
||||
else if(type == SSH2_EC_CURVE_NISTP521 &&
|
||||
strncmp((char *)domain, "nistp521", 8) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* public key */
|
||||
if(_libssh2_get_string(&buf, &public_key, &key_len))
|
||||
if(ssh2_get_string(&buf, &public_key, &key_len))
|
||||
return -1;
|
||||
|
||||
if(!_libssh2_eob(&buf))
|
||||
if(!ssh2_eob(&buf))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_ecdsa_curve_name_with_octal_new(&ec_ctx, public_key,
|
||||
key_len, type))
|
||||
if(ssh2_ecdsa_curve_name_with_octal_new(&ec_ctx, public_key,
|
||||
key_len, type))
|
||||
return -1;
|
||||
|
||||
if(abstract)
|
||||
@@ -815,7 +808,7 @@ static int hostkey_method_ssh_ecdsa_initPEM(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_ecdsa_ctx *ec_ctx = NULL;
|
||||
ssh2_ecdsa_ctx *ec_ctx = NULL;
|
||||
int ret;
|
||||
|
||||
if(abstract && *abstract) {
|
||||
@@ -823,8 +816,7 @@ static int hostkey_method_ssh_ecdsa_initPEM(LIBSSH2_SESSION *session,
|
||||
*abstract = NULL;
|
||||
}
|
||||
|
||||
ret = _libssh2_ecdsa_new_private(&ec_ctx, session,
|
||||
privkeyfile, passphrase);
|
||||
ret = ssh2_ecdsa_new_private(&ec_ctx, session, privkeyfile, passphrase);
|
||||
|
||||
if(abstract)
|
||||
*abstract = ec_ctx;
|
||||
@@ -842,7 +834,7 @@ static int hostkey_method_ssh_ecdsa_initPEMFromMemory(
|
||||
const unsigned char *passphrase,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_ecdsa_ctx *ec_ctx = NULL;
|
||||
ssh2_ecdsa_ctx *ec_ctx = NULL;
|
||||
int ret;
|
||||
|
||||
if(abstract && *abstract) {
|
||||
@@ -850,10 +842,10 @@ static int hostkey_method_ssh_ecdsa_initPEMFromMemory(
|
||||
*abstract = NULL;
|
||||
}
|
||||
|
||||
ret = _libssh2_ecdsa_new_private_frommemory(&ec_ctx, session,
|
||||
privkeyfiledata,
|
||||
privkeyfiledata_len,
|
||||
passphrase);
|
||||
ret = ssh2_ecdsa_new_private_frommemory(&ec_ctx, session,
|
||||
privkeyfiledata,
|
||||
privkeyfiledata_len,
|
||||
passphrase);
|
||||
if(ret) {
|
||||
return -1;
|
||||
}
|
||||
@@ -877,7 +869,7 @@ static int hostkey_method_ssh_ecdsa_sig_verify(LIBSSH2_SESSION *session,
|
||||
size_t r_len, s_len, name_len;
|
||||
uint32_t len;
|
||||
struct string_buf buf;
|
||||
libssh2_ecdsa_ctx *ctx = (libssh2_ecdsa_ctx *)(*abstract);
|
||||
ssh2_ecdsa_ctx *ctx = (ssh2_ecdsa_ctx *)(*abstract);
|
||||
|
||||
(void)session;
|
||||
|
||||
@@ -886,52 +878,52 @@ static int hostkey_method_ssh_ecdsa_sig_verify(LIBSSH2_SESSION *session,
|
||||
|
||||
/* keyname_len(4) + keyname(19){"ecdsa-sha2-nistp256"} +
|
||||
signature_len(4) */
|
||||
buf.data = (unsigned char *)LIBSSH2_UNCONST(sig);
|
||||
buf.data = (unsigned char *)SSH2_UNCONST(sig);
|
||||
buf.dataptr = buf.data;
|
||||
buf.len = sig_len;
|
||||
|
||||
if(_libssh2_get_string(&buf, &name, &name_len) || name_len != 19)
|
||||
if(ssh2_get_string(&buf, &name, &name_len) || name_len != 19)
|
||||
return -1;
|
||||
|
||||
if(_libssh2_get_u32(&buf, &len) != 0 || len < 8)
|
||||
if(ssh2_get_u32(&buf, &len) != 0 || len < 8)
|
||||
return -1;
|
||||
|
||||
if(_libssh2_get_string(&buf, &r, &r_len))
|
||||
if(ssh2_get_string(&buf, &r, &r_len))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_get_string(&buf, &s, &s_len))
|
||||
if(ssh2_get_string(&buf, &s, &s_len))
|
||||
return -1;
|
||||
|
||||
return _libssh2_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len);
|
||||
return ssh2_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len);
|
||||
}
|
||||
|
||||
#define LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(digest_type) \
|
||||
do { \
|
||||
unsigned char hash[SHA##digest_type##_DIGEST_LENGTH]; \
|
||||
libssh2_sha##digest_type##_ctx ctx; \
|
||||
int i; \
|
||||
if(!libssh2_sha##digest_type##_init(&ctx)) { \
|
||||
ret = -1; \
|
||||
break; \
|
||||
} \
|
||||
for(i = 0; i < veccount; i++) { \
|
||||
if(!libssh2_sha##digest_type##_update(ctx, \
|
||||
datavec[i].iov_base, \
|
||||
datavec[i].iov_len)) { \
|
||||
ret = -1; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
if(ret == -1) { \
|
||||
break; \
|
||||
} \
|
||||
if(!libssh2_sha##digest_type##_final(ctx, hash)) { \
|
||||
ret = -1; \
|
||||
break; \
|
||||
} \
|
||||
ret = _libssh2_ecdsa_sign(session, ec_ctx, hash, \
|
||||
SHA##digest_type##_DIGEST_LENGTH, \
|
||||
signature, signature_len); \
|
||||
#define HOSTKEY_METHOD_EC_SIGNV_HASH(digest_type) \
|
||||
do { \
|
||||
unsigned char hash[SHA##digest_type##_DIGEST_LENGTH]; \
|
||||
ssh2_sha##digest_type##_ctx ctx; \
|
||||
int i; \
|
||||
if(!ssh2_sha##digest_type##_init(&ctx)) { \
|
||||
ret = -1; \
|
||||
break; \
|
||||
} \
|
||||
for(i = 0; i < veccount; i++) { \
|
||||
if(!ssh2_sha##digest_type##_update(ctx, \
|
||||
datavec[i].iov_base, \
|
||||
datavec[i].iov_len)) { \
|
||||
ret = -1; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
if(ret == -1) { \
|
||||
break; \
|
||||
} \
|
||||
if(!ssh2_sha##digest_type##_final(ctx, hash)) { \
|
||||
ret = -1; \
|
||||
break; \
|
||||
} \
|
||||
ret = ssh2_ecdsa_sign(session, ec_ctx, hash, \
|
||||
SHA##digest_type##_DIGEST_LENGTH, \
|
||||
signature, signature_len); \
|
||||
} while(0)
|
||||
|
||||
/*
|
||||
@@ -944,18 +936,18 @@ static int hostkey_method_ssh_ecdsa_signv(LIBSSH2_SESSION *session,
|
||||
const struct iovec datavec[],
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_ecdsa_ctx *ec_ctx = (libssh2_ecdsa_ctx *)(*abstract);
|
||||
libssh2_curve_type type = _libssh2_ecdsa_get_curve_type(ec_ctx);
|
||||
ssh2_ecdsa_ctx *ec_ctx = (ssh2_ecdsa_ctx *)(*abstract);
|
||||
ssh2_curve_type type = ssh2_ecdsa_get_curve_type(ec_ctx);
|
||||
int ret = 0;
|
||||
|
||||
if(type == LIBSSH2_EC_CURVE_NISTP256) {
|
||||
LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(256);
|
||||
if(type == SSH2_EC_CURVE_NISTP256) {
|
||||
HOSTKEY_METHOD_EC_SIGNV_HASH(256);
|
||||
}
|
||||
else if(type == LIBSSH2_EC_CURVE_NISTP384) {
|
||||
LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(384);
|
||||
else if(type == SSH2_EC_CURVE_NISTP384) {
|
||||
HOSTKEY_METHOD_EC_SIGNV_HASH(384);
|
||||
}
|
||||
else if(type == LIBSSH2_EC_CURVE_NISTP521) {
|
||||
LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(512);
|
||||
else if(type == SSH2_EC_CURVE_NISTP521) {
|
||||
HOSTKEY_METHOD_EC_SIGNV_HASH(512);
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
@@ -970,11 +962,11 @@ static int hostkey_method_ssh_ecdsa_signv(LIBSSH2_SESSION *session,
|
||||
static int hostkey_method_ssh_ecdsa_dtor(LIBSSH2_SESSION *session,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_ecdsa_ctx *keyctx = (libssh2_ecdsa_ctx *)(*abstract);
|
||||
ssh2_ecdsa_ctx *keyctx = (ssh2_ecdsa_ctx *)(*abstract);
|
||||
(void)session;
|
||||
|
||||
if(keyctx)
|
||||
_libssh2_ecdsa_free(keyctx);
|
||||
ssh2_ecdsa_free(keyctx);
|
||||
|
||||
*abstract = NULL;
|
||||
|
||||
@@ -1074,7 +1066,7 @@ static int hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION *session,
|
||||
{
|
||||
size_t key_len;
|
||||
unsigned char *key;
|
||||
libssh2_ed25519_ctx *ctx = NULL;
|
||||
ssh2_ed25519_ctx *ctx = NULL;
|
||||
struct string_buf buf;
|
||||
|
||||
if(*abstract) {
|
||||
@@ -1083,26 +1075,25 @@ static int hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION *session,
|
||||
}
|
||||
|
||||
if(hostkey_data_len < 19) {
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_ERROR,
|
||||
"host key length too short"));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_ERROR, "host key length too short"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf.data = (unsigned char *)LIBSSH2_UNCONST(hostkey_data);
|
||||
buf.data = (unsigned char *)SSH2_UNCONST(hostkey_data);
|
||||
buf.dataptr = buf.data;
|
||||
buf.len = hostkey_data_len;
|
||||
|
||||
if(_libssh2_match_string(&buf, "ssh-ed25519"))
|
||||
if(ssh2_match_string(&buf, "ssh-ed25519"))
|
||||
return -1;
|
||||
|
||||
/* public key */
|
||||
if(_libssh2_get_string(&buf, &key, &key_len))
|
||||
if(ssh2_get_string(&buf, &key, &key_len))
|
||||
return -1;
|
||||
|
||||
if(!_libssh2_eob(&buf))
|
||||
if(!ssh2_eob(&buf))
|
||||
return -1;
|
||||
|
||||
if(_libssh2_ed25519_new_public(&ctx, session, key, key_len) != 0) {
|
||||
if(ssh2_ed25519_new_public(&ctx, session, key, key_len) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1114,13 +1105,12 @@ static int hostkey_method_ssh_ed25519_init(LIBSSH2_SESSION *session,
|
||||
/*
|
||||
* Load a Private Key from a PEM file
|
||||
*/
|
||||
static int hostkey_method_ssh_ed25519_initPEM(
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *privkeyfile,
|
||||
const unsigned char *passphrase,
|
||||
void **abstract)
|
||||
static int hostkey_method_ssh_ed25519_initPEM(LIBSSH2_SESSION *session,
|
||||
const char *privkeyfile,
|
||||
const unsigned char *passphrase,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_ed25519_ctx *ec_ctx = NULL;
|
||||
ssh2_ed25519_ctx *ec_ctx = NULL;
|
||||
int ret;
|
||||
|
||||
if(*abstract) {
|
||||
@@ -1128,8 +1118,7 @@ static int hostkey_method_ssh_ed25519_initPEM(
|
||||
*abstract = NULL;
|
||||
}
|
||||
|
||||
ret = _libssh2_ed25519_new_private(&ec_ctx, session,
|
||||
privkeyfile, passphrase);
|
||||
ret = ssh2_ed25519_new_private(&ec_ctx, session, privkeyfile, passphrase);
|
||||
if(ret) {
|
||||
return -1;
|
||||
}
|
||||
@@ -1149,7 +1138,7 @@ static int hostkey_method_ssh_ed25519_initPEMFromMemory(
|
||||
const unsigned char *passphrase,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_ed25519_ctx *ed_ctx = NULL;
|
||||
ssh2_ed25519_ctx *ed_ctx = NULL;
|
||||
int ret;
|
||||
|
||||
if(abstract && *abstract) {
|
||||
@@ -1157,10 +1146,10 @@ static int hostkey_method_ssh_ed25519_initPEMFromMemory(
|
||||
*abstract = NULL;
|
||||
}
|
||||
|
||||
ret = _libssh2_ed25519_new_private_frommemory(&ed_ctx, session,
|
||||
privkeyfiledata,
|
||||
privkeyfiledata_len,
|
||||
passphrase);
|
||||
ret = ssh2_ed25519_new_private_frommemory(&ed_ctx, session,
|
||||
privkeyfiledata,
|
||||
privkeyfiledata_len,
|
||||
passphrase);
|
||||
if(ret) {
|
||||
return -1;
|
||||
}
|
||||
@@ -1180,7 +1169,7 @@ static int hostkey_method_ssh_ed25519_sig_verify(LIBSSH2_SESSION *session,
|
||||
const unsigned char *m,
|
||||
size_t m_len, void **abstract)
|
||||
{
|
||||
libssh2_ed25519_ctx *ctx = (libssh2_ed25519_ctx *)(*abstract);
|
||||
ssh2_ed25519_ctx *ctx = (ssh2_ed25519_ctx *)(*abstract);
|
||||
(void)session;
|
||||
|
||||
if(sig_len < 19)
|
||||
@@ -1191,10 +1180,10 @@ static int hostkey_method_ssh_ed25519_sig_verify(LIBSSH2_SESSION *session,
|
||||
sig += 19;
|
||||
sig_len -= 19;
|
||||
|
||||
if(sig_len != LIBSSH2_ED25519_SIG_LEN)
|
||||
if(sig_len != SSH2_ED25519_SIG_LEN)
|
||||
return -1;
|
||||
|
||||
return _libssh2_ed25519_verify(ctx, sig, sig_len, m, m_len);
|
||||
return ssh2_ed25519_verify(ctx, sig, sig_len, m, m_len);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1207,15 +1196,15 @@ static int hostkey_method_ssh_ed25519_signv(LIBSSH2_SESSION *session,
|
||||
const struct iovec datavec[],
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_ed25519_ctx *ctx = (libssh2_ed25519_ctx *)(*abstract);
|
||||
ssh2_ed25519_ctx *ctx = (ssh2_ed25519_ctx *)(*abstract);
|
||||
|
||||
if(veccount != 1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return _libssh2_ed25519_sign(ctx, session, signature, signature_len,
|
||||
(const uint8_t *)datavec[0].iov_base,
|
||||
datavec[0].iov_len);
|
||||
return ssh2_ed25519_sign(ctx, session, signature, signature_len,
|
||||
(const uint8_t *)datavec[0].iov_base,
|
||||
datavec[0].iov_len);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1224,11 +1213,11 @@ static int hostkey_method_ssh_ed25519_signv(LIBSSH2_SESSION *session,
|
||||
static int hostkey_method_ssh_ed25519_dtor(LIBSSH2_SESSION *session,
|
||||
void **abstract)
|
||||
{
|
||||
libssh2_ed25519_ctx *keyctx = (libssh2_ed25519_ctx *)(*abstract);
|
||||
ssh2_ed25519_ctx *keyctx = (ssh2_ed25519_ctx *)(*abstract);
|
||||
(void)session;
|
||||
|
||||
if(keyctx)
|
||||
_libssh2_ed25519_free(keyctx);
|
||||
ssh2_ed25519_free(keyctx);
|
||||
|
||||
*abstract = NULL;
|
||||
|
||||
@@ -1303,7 +1292,7 @@ static const struct hostkey_method *hostkey_methods[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
const struct hostkey_method **libssh2_hostkey_methods(void)
|
||||
const struct hostkey_method **ssh2_hostkey_methods(void)
|
||||
{
|
||||
return hostkey_methods;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
*/
|
||||
|
||||
#include "libssh2_priv.h"
|
||||
#include "transport.h" /* _libssh2_transport_write */
|
||||
#include "transport.h" /* ssh2_transport_write() */
|
||||
|
||||
/* Keep-alive stuff. */
|
||||
|
||||
@@ -77,12 +77,12 @@ int libssh2_keepalive_send(LIBSSH2_SESSION *session, int *seconds_to_next)
|
||||
|
||||
keepalive_data[len - 1] = (unsigned char)session->keepalive_want_reply;
|
||||
|
||||
rc = _libssh2_transport_send(session, keepalive_data, len, NULL, 0);
|
||||
rc = ssh2_transport_send(session, keepalive_data, len, NULL, 0);
|
||||
/* Silently ignore PACKET_EAGAIN here: if the write buffer is
|
||||
already full, sending another keepalive is not useful. */
|
||||
if(rc && rc != LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"Unable to send keepalive message");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"Unable to send keepalive message");
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
263
src/knownhost.c
263
src/knownhost.c
@@ -70,16 +70,16 @@ static void free_host(LIBSSH2_SESSION *session, struct known_host *entry)
|
||||
{
|
||||
if(entry) {
|
||||
if(entry->comment)
|
||||
LIBSSH2_FREE(session, entry->comment);
|
||||
SSH2_FREE(session, entry->comment);
|
||||
if(entry->key_type_name)
|
||||
LIBSSH2_FREE(session, entry->key_type_name);
|
||||
SSH2_FREE(session, entry->key_type_name);
|
||||
if(entry->key)
|
||||
LIBSSH2_FREE(session, entry->key);
|
||||
SSH2_FREE(session, entry->key);
|
||||
if(entry->salt)
|
||||
LIBSSH2_FREE(session, entry->salt);
|
||||
SSH2_FREE(session, entry->salt);
|
||||
if(entry->name)
|
||||
LIBSSH2_FREE(session, entry->name);
|
||||
LIBSSH2_FREE(session, entry);
|
||||
SSH2_FREE(session, entry->name);
|
||||
SSH2_FREE(session, entry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,18 +90,17 @@ LIBSSH2_API
|
||||
LIBSSH2_KNOWNHOSTS *libssh2_knownhost_init(LIBSSH2_SESSION *session)
|
||||
{
|
||||
LIBSSH2_KNOWNHOSTS *knh =
|
||||
LIBSSH2_ALLOC(session, sizeof(struct _LIBSSH2_KNOWNHOSTS));
|
||||
SSH2_ALLOC(session, sizeof(struct _LIBSSH2_KNOWNHOSTS));
|
||||
|
||||
if(!knh) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for known-hosts "
|
||||
"collection");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for known-hosts collection");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
knh->session = session;
|
||||
|
||||
_libssh2_list_init(&knh->head);
|
||||
ssh2_list_init(&knh->head);
|
||||
|
||||
return knh;
|
||||
}
|
||||
@@ -139,44 +138,41 @@ static int knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
|
||||
/* make sure we have a key type set */
|
||||
if(!(typemask & LIBSSH2_KNOWNHOST_KEY_MASK))
|
||||
return _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
|
||||
"No key type set");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_INVAL,
|
||||
"No key type set");
|
||||
|
||||
entry = LIBSSH2_CALLOC(hosts->session, sizeof(struct known_host));
|
||||
entry = SSH2_CALLOC(hosts->session, sizeof(struct known_host));
|
||||
if(!entry)
|
||||
return _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for known host "
|
||||
"entry");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for known host entry");
|
||||
|
||||
entry->typemask = typemask;
|
||||
|
||||
switch(entry->typemask & LIBSSH2_KNOWNHOST_TYPE_MASK) {
|
||||
case LIBSSH2_KNOWNHOST_TYPE_PLAIN:
|
||||
case LIBSSH2_KNOWNHOST_TYPE_CUSTOM:
|
||||
entry->name = LIBSSH2_ALLOC(hosts->session, hostlen + 1);
|
||||
entry->name = SSH2_ALLOC(hosts->session, hostlen + 1);
|
||||
if(!entry->name) {
|
||||
rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for hostname");
|
||||
rc = ssh2_err(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for hostname");
|
||||
goto error;
|
||||
}
|
||||
memcpy(entry->name, host, hostlen + 1);
|
||||
entry->name_len = hostlen;
|
||||
break;
|
||||
case LIBSSH2_KNOWNHOST_TYPE_SHA1:
|
||||
rc = _libssh2_base64_decode(hosts->session, &ptr, &ptrlen,
|
||||
host, hostlen);
|
||||
rc = ssh2_base64_decode(hosts->session, &ptr, &ptrlen, host, hostlen);
|
||||
if(rc)
|
||||
goto error;
|
||||
|
||||
if(!ptr || ptrlen == 0) {
|
||||
rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
|
||||
"Base64 decoded value is invalid");
|
||||
rc = ssh2_err(hosts->session, LIBSSH2_ERROR_INVAL,
|
||||
"Base64 decoded value is invalid");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if(!salt) {
|
||||
rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
|
||||
"Salt is NULL");
|
||||
rc = ssh2_err(hosts->session, LIBSSH2_ERROR_INVAL, "Salt is NULL");
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -185,14 +181,14 @@ static int knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
|
||||
ptr = NULL;
|
||||
ptrlen = 0;
|
||||
rc = _libssh2_base64_decode(hosts->session, &ptr, &ptrlen,
|
||||
salt, strlen(salt));
|
||||
rc = ssh2_base64_decode(hosts->session, &ptr, &ptrlen, salt,
|
||||
strlen(salt));
|
||||
if(rc)
|
||||
goto error;
|
||||
|
||||
if(!ptr || ptrlen == 0) {
|
||||
rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
|
||||
"Base64 decoded value is invalid");
|
||||
rc = ssh2_err(hosts->session, LIBSSH2_ERROR_INVAL,
|
||||
"Base64 decoded value is invalid");
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -200,8 +196,8 @@ static int knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
entry->salt_len = ptrlen;
|
||||
break;
|
||||
default:
|
||||
rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unknown hostname type");
|
||||
rc = ssh2_err(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unknown hostname type");
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -209,10 +205,10 @@ static int knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
/* the provided key is base64 encoded already */
|
||||
if(!keylen)
|
||||
keylen = strlen(key);
|
||||
entry->key = LIBSSH2_ALLOC(hosts->session, keylen + 1);
|
||||
entry->key = SSH2_ALLOC(hosts->session, keylen + 1);
|
||||
if(!entry->key) {
|
||||
rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for key");
|
||||
rc = ssh2_err(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for key");
|
||||
goto error;
|
||||
}
|
||||
memcpy(entry->key, key, keylen + 1);
|
||||
@@ -220,12 +216,10 @@ static int knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
}
|
||||
else {
|
||||
/* key is raw, we base64 encode it and store it as such */
|
||||
size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen,
|
||||
&ptr);
|
||||
size_t nlen = ssh2_base64_encode(hosts->session, key, keylen, &ptr);
|
||||
if(!nlen) {
|
||||
rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"base64-encoded key");
|
||||
rc = ssh2_err(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for base64-encoded key");
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -234,10 +228,10 @@ static int knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
|
||||
if(key_type_name && ((typemask & LIBSSH2_KNOWNHOST_KEY_MASK) ==
|
||||
LIBSSH2_KNOWNHOST_KEY_UNKNOWN)) {
|
||||
entry->key_type_name = LIBSSH2_ALLOC(hosts->session, key_type_len + 1);
|
||||
entry->key_type_name = SSH2_ALLOC(hosts->session, key_type_len + 1);
|
||||
if(!entry->key_type_name) {
|
||||
rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for key type");
|
||||
rc = ssh2_err(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for key type");
|
||||
goto error;
|
||||
}
|
||||
memcpy(entry->key_type_name, key_type_name, key_type_len);
|
||||
@@ -246,10 +240,10 @@ static int knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
}
|
||||
|
||||
if(comment) {
|
||||
entry->comment = LIBSSH2_ALLOC(hosts->session, commentlen + 1);
|
||||
entry->comment = SSH2_ALLOC(hosts->session, commentlen + 1);
|
||||
if(!entry->comment) {
|
||||
rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for comment");
|
||||
rc = ssh2_err(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for comment");
|
||||
goto error;
|
||||
}
|
||||
memcpy(entry->comment, comment, commentlen + 1);
|
||||
@@ -261,7 +255,7 @@ static int knownhost_add(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
}
|
||||
|
||||
/* add this new host to the big list of known hosts */
|
||||
_libssh2_list_add(&hosts->head, &entry->node);
|
||||
ssh2_list_add(&hosts->head, &entry->node);
|
||||
|
||||
if(store)
|
||||
*store = knownhost_to_external(entry);
|
||||
@@ -381,8 +375,8 @@ static int knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
if(port >= 0) {
|
||||
int len = snprintf(hostbuff, sizeof(hostbuff), "[%s]:%d", hostp, port);
|
||||
if(len < 0 || len >= (int)sizeof(hostbuff)) {
|
||||
_libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
|
||||
"Known-host write buffer too small");
|
||||
ssh2_err(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
|
||||
"Known-host write buffer too small");
|
||||
return LIBSSH2_KNOWNHOST_CHECK_FAILURE;
|
||||
}
|
||||
host = hostbuff;
|
||||
@@ -395,12 +389,11 @@ static int knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
|
||||
if(!(typemask & LIBSSH2_KNOWNHOST_KEYENC_BASE64)) {
|
||||
/* we got a raw key input, convert it to base64 for the checks below */
|
||||
size_t nlen = _libssh2_base64_encode(hosts->session, key, keylen,
|
||||
&keyalloc);
|
||||
size_t nlen = ssh2_base64_encode(hosts->session, key, keylen,
|
||||
&keyalloc);
|
||||
if(!nlen) {
|
||||
_libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for base64-encoded "
|
||||
"key");
|
||||
ssh2_err(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for base64-encoded key");
|
||||
return LIBSSH2_KNOWNHOST_CHECK_FAILURE;
|
||||
}
|
||||
|
||||
@@ -409,7 +402,7 @@ static int knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
}
|
||||
|
||||
do {
|
||||
node = _libssh2_list_first(&hosts->head);
|
||||
node = ssh2_list_first(&hosts->head);
|
||||
while(node) {
|
||||
switch(node->typemask & LIBSSH2_KNOWNHOST_TYPE_MASK) {
|
||||
case LIBSSH2_KNOWNHOST_TYPE_PLAIN:
|
||||
@@ -427,8 +420,8 @@ static int knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
stored hash.
|
||||
*/
|
||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||
libssh2_hmac_ctx ctx;
|
||||
if(!_libssh2_hmac_ctx_init(&ctx))
|
||||
ssh2_hmac_ctx ctx;
|
||||
if(!ssh2_hmac_ctx_init(&ctx))
|
||||
break;
|
||||
|
||||
if(SHA_DIGEST_LENGTH != node->name_len) {
|
||||
@@ -436,15 +429,14 @@ static int knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
we cannot match it */
|
||||
break;
|
||||
}
|
||||
if(!_libssh2_hmac_sha1_init(&ctx,
|
||||
node->salt, node->salt_len))
|
||||
if(!ssh2_hmac_sha1_init(&ctx, node->salt, node->salt_len))
|
||||
break;
|
||||
if(!_libssh2_hmac_update(&ctx, host, strlen(host)) ||
|
||||
!_libssh2_hmac_final(&ctx, hash)) {
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
if(!ssh2_hmac_update(&ctx, host, strlen(host)) ||
|
||||
!ssh2_hmac_final(&ctx, hash)) {
|
||||
ssh2_hmac_cleanup(&ctx);
|
||||
break;
|
||||
}
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
ssh2_hmac_cleanup(&ctx);
|
||||
|
||||
if(!memcmp(hash, node->name, SHA_DIGEST_LENGTH))
|
||||
/* this is a node we are interested in */
|
||||
@@ -485,7 +477,7 @@ static int knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
}
|
||||
match = 0; /* do not count this as a match anymore */
|
||||
}
|
||||
node = _libssh2_list_next(&node->node);
|
||||
node = ssh2_list_next(&node->node);
|
||||
}
|
||||
host = hostp;
|
||||
} while(!match && --numcheck);
|
||||
@@ -498,7 +490,7 @@ static int knownhost_check(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
}
|
||||
|
||||
if(keyalloc)
|
||||
LIBSSH2_FREE(hosts->session, keyalloc);
|
||||
SSH2_FREE(hosts->session, keyalloc);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -570,14 +562,14 @@ int libssh2_knownhost_del(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
|
||||
/* check that this was retrieved the right way or get out */
|
||||
if(!entry || (entry->magic != KNOWNHOST_MAGIC))
|
||||
return _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
|
||||
"Invalid host information");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_INVAL,
|
||||
"Invalid host information");
|
||||
|
||||
/* get the internal node pointer */
|
||||
node = entry->node;
|
||||
|
||||
/* unlink from the list of all hosts */
|
||||
_libssh2_list_remove(&node->node);
|
||||
ssh2_list_remove(&node->node);
|
||||
|
||||
/* clear the struct now since the memory in which it is allocated is
|
||||
about to be freed! */
|
||||
@@ -598,11 +590,11 @@ void libssh2_knownhost_free(LIBSSH2_KNOWNHOSTS *hosts)
|
||||
struct known_host *node;
|
||||
struct known_host *next;
|
||||
|
||||
for(node = _libssh2_list_first(&hosts->head); node; node = next) {
|
||||
next = _libssh2_list_next(&node->node);
|
||||
for(node = ssh2_list_first(&hosts->head); node; node = next) {
|
||||
next = ssh2_list_next(&node->node);
|
||||
free_host(hosts->session, node);
|
||||
}
|
||||
LIBSSH2_FREE(hosts->session, hosts);
|
||||
SSH2_FREE(hosts->session, hosts);
|
||||
}
|
||||
|
||||
/* old style plain text: [name]([,][name])*
|
||||
@@ -621,10 +613,8 @@ static int oldstyle_hostline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
const char *name = host + hostlen;
|
||||
|
||||
if(hostlen < 1)
|
||||
return _libssh2_error(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line "
|
||||
"(no hostnames)");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line (no hostnames)");
|
||||
|
||||
while(name > host) {
|
||||
--name;
|
||||
@@ -638,10 +628,10 @@ static int oldstyle_hostline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
|
||||
/* make sure we do not overflow the buffer */
|
||||
if(namelen >= sizeof(hostbuf) - 1)
|
||||
return _libssh2_error(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line "
|
||||
"(unexpected length)");
|
||||
return ssh2_err(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line "
|
||||
"(unexpected length)");
|
||||
|
||||
/* copy hostname to the temp buffer and null-terminate */
|
||||
memcpy(hostbuf, name, namelen);
|
||||
@@ -688,10 +678,9 @@ static int hashed_hostline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
const char *hash = NULL;
|
||||
size_t saltlen = p - salt;
|
||||
if(saltlen >= (sizeof(saltbuf) - 1)) /* weird length */
|
||||
return _libssh2_error(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line "
|
||||
"(unexpectedly long salt)");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line "
|
||||
"(unexpectedly long salt)");
|
||||
|
||||
memcpy(saltbuf, salt, saltlen);
|
||||
saltbuf[saltlen] = 0; /* null-terminate */
|
||||
@@ -705,10 +694,9 @@ static int hashed_hostline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
|
||||
/* check that the lengths seem sensible */
|
||||
if(hostlen >= sizeof(hostbuf) - 1)
|
||||
return _libssh2_error(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line "
|
||||
"(unexpected length)");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line "
|
||||
"(unexpected length)");
|
||||
|
||||
memcpy(hostbuf, host, hostlen);
|
||||
hostbuf[hostlen] = 0;
|
||||
@@ -744,10 +732,8 @@ static int hostline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
|
||||
/* make some checks that the lengths seem sensible */
|
||||
if(keylen < 20)
|
||||
return _libssh2_error(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line "
|
||||
"(key too short)");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line (key too short)");
|
||||
|
||||
switch(key[0]) {
|
||||
case '0':
|
||||
@@ -883,10 +869,8 @@ int libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
int rc;
|
||||
|
||||
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
|
||||
return _libssh2_error(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unsupported type of known-host information "
|
||||
"store");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unsupported type of known-host information store");
|
||||
|
||||
cp = line;
|
||||
|
||||
@@ -918,9 +902,8 @@ int libssh2_knownhost_readline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
}
|
||||
|
||||
if(!*cp || !len) /* illegal line */
|
||||
return _libssh2_error(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Failed to parse known_hosts line");
|
||||
|
||||
keyp = cp; /* the key starts here */
|
||||
keylen = len;
|
||||
@@ -957,17 +940,15 @@ int libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
char buf[4092];
|
||||
|
||||
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
|
||||
return _libssh2_error(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unsupported type of known-host information "
|
||||
"store");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unsupported type of known-host information store");
|
||||
|
||||
file = fopen(filename, FOPEN_READTEXT);
|
||||
if(file) {
|
||||
while(fgets(buf, sizeof(buf), file)) {
|
||||
if(libssh2_knownhost_readline(hosts, buf, strlen(buf), type)) {
|
||||
num = _libssh2_error(hosts->session, LIBSSH2_ERROR_KNOWN_HOSTS,
|
||||
"Failed to parse known hosts file");
|
||||
num = ssh2_err(hosts->session, LIBSSH2_ERROR_KNOWN_HOSTS,
|
||||
"Failed to parse known hosts file");
|
||||
break;
|
||||
}
|
||||
num++;
|
||||
@@ -975,8 +956,8 @@ int libssh2_knownhost_readfile(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
fclose(file);
|
||||
}
|
||||
else
|
||||
return _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
|
||||
"Failed to open file");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_FILE,
|
||||
"Failed to open file");
|
||||
|
||||
return num;
|
||||
}
|
||||
@@ -1002,10 +983,8 @@ static int knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
/* we only support this single file type for now, bail out on all other
|
||||
attempts */
|
||||
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
|
||||
return _libssh2_error(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unsupported type of known-host information "
|
||||
"store");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unsupported type of known-host information store");
|
||||
|
||||
switch(node->typemask & LIBSSH2_KNOWNHOST_KEY_MASK) {
|
||||
case LIBSSH2_KNOWNHOST_KEY_RSA1:
|
||||
@@ -1045,11 +1024,10 @@ static int knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
break;
|
||||
}
|
||||
/* otherwise fallback to default and error */
|
||||
LIBSSH2_FALLTHROUGH();
|
||||
SSH2_FALLTHROUGH();
|
||||
default:
|
||||
return _libssh2_error(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unsupported type of known-host entry");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unsupported type of known-host entry");
|
||||
}
|
||||
|
||||
/* When putting together the host line there are three aspects to consider:
|
||||
@@ -1086,21 +1064,21 @@ static int knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
char *saltalloc;
|
||||
size_t salt_base64_len;
|
||||
|
||||
name_base64_len = _libssh2_base64_encode(hosts->session, node->name,
|
||||
node->name_len, &namealloc);
|
||||
name_base64_len = ssh2_base64_encode(hosts->session, node->name,
|
||||
node->name_len, &namealloc);
|
||||
if(!name_base64_len)
|
||||
return _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"base64-encoded hostname");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"base64-encoded hostname");
|
||||
|
||||
salt_base64_len = _libssh2_base64_encode(hosts->session,
|
||||
node->salt, node->salt_len,
|
||||
&saltalloc);
|
||||
salt_base64_len = ssh2_base64_encode(hosts->session,
|
||||
node->salt, node->salt_len,
|
||||
&saltalloc);
|
||||
if(!salt_base64_len) {
|
||||
LIBSSH2_FREE(hosts->session, namealloc);
|
||||
return _libssh2_error(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"base64-encoded salt");
|
||||
SSH2_FREE(hosts->session, namealloc);
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"base64-encoded salt");
|
||||
}
|
||||
|
||||
required_size += salt_base64_len + name_base64_len + 7;
|
||||
@@ -1121,8 +1099,8 @@ static int knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
node->key);
|
||||
}
|
||||
|
||||
LIBSSH2_FREE(hosts->session, namealloc);
|
||||
LIBSSH2_FREE(hosts->session, saltalloc);
|
||||
SSH2_FREE(hosts->session, namealloc);
|
||||
SSH2_FREE(hosts->session, saltalloc);
|
||||
}
|
||||
else {
|
||||
required_size += node->name_len + 3;
|
||||
@@ -1149,8 +1127,8 @@ static int knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
if(required_size <= buflen)
|
||||
return LIBSSH2_ERROR_NONE;
|
||||
else
|
||||
return _libssh2_error(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
|
||||
"Known-host write buffer too small");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
|
||||
"Known-host write buffer too small");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1169,8 +1147,8 @@ int libssh2_knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
struct known_host *node;
|
||||
|
||||
if(known->magic != KNOWNHOST_MAGIC)
|
||||
return _libssh2_error(hosts->session, LIBSSH2_ERROR_INVAL,
|
||||
"Invalid host information");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_INVAL,
|
||||
"Invalid host information");
|
||||
|
||||
node = known->node;
|
||||
|
||||
@@ -1192,19 +1170,17 @@ int libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
/* we only support this single file type for now, bail out on all other
|
||||
attempts */
|
||||
if(type != LIBSSH2_KNOWNHOST_FILE_OPENSSH)
|
||||
return _libssh2_error(hosts->session,
|
||||
LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unsupported type of known-host information "
|
||||
"store");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unsupported type of known-host information store");
|
||||
|
||||
file = fopen(filename, FOPEN_WRITETEXT);
|
||||
if(!file)
|
||||
return _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
|
||||
"Failed to open file");
|
||||
return ssh2_err(hosts->session, LIBSSH2_ERROR_FILE,
|
||||
"Failed to open file");
|
||||
|
||||
for(node = _libssh2_list_first(&hosts->head);
|
||||
for(node = ssh2_list_first(&hosts->head);
|
||||
node;
|
||||
node = _libssh2_list_next(&node->node)) {
|
||||
node = ssh2_list_next(&node->node)) {
|
||||
size_t wrote = 0;
|
||||
size_t nwrote;
|
||||
rc = knownhost_writeline(hosts, node, buffer, sizeof(buffer), &wrote,
|
||||
@@ -1215,8 +1191,7 @@ int libssh2_knownhost_writefile(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
nwrote = fwrite(buffer, 1, wrote, file);
|
||||
if(nwrote != wrote) {
|
||||
/* failed to write the whole thing, bail out */
|
||||
rc = _libssh2_error(hosts->session, LIBSSH2_ERROR_FILE,
|
||||
"Write failed");
|
||||
rc = ssh2_err(hosts->session, LIBSSH2_ERROR_FILE, "Write failed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1245,10 +1220,10 @@ int libssh2_knownhost_get(LIBSSH2_KNOWNHOSTS *hosts,
|
||||
struct known_host *prev_node = prev->node;
|
||||
|
||||
/* get the next node in the list */
|
||||
node = _libssh2_list_next(&prev_node->node);
|
||||
node = ssh2_list_next(&prev_node->node);
|
||||
}
|
||||
else
|
||||
node = _libssh2_list_first(&hosts->head);
|
||||
node = ssh2_list_first(&hosts->head);
|
||||
|
||||
if(!node)
|
||||
/* no (more) node */
|
||||
|
||||
348
src/libgcrypt.c
348
src/libgcrypt.c
@@ -42,14 +42,14 @@
|
||||
|
||||
#ifdef LIBSSH2_LIBGCRYPT
|
||||
|
||||
int _libssh2_hmac_ctx_init(libssh2_hmac_ctx *ctx)
|
||||
int ssh2_hmac_ctx_init(ssh2_hmac_ctx *ctx)
|
||||
{
|
||||
*ctx = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if LIBSSH2_MD5
|
||||
int _libssh2_hmac_md5_init(libssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
int ssh2_hmac_md5_init(ssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
{
|
||||
gcry_error_t err;
|
||||
err = gcry_md_open(ctx, GCRY_MD_MD5, GCRY_MD_FLAG_HMAC);
|
||||
@@ -63,8 +63,7 @@ int _libssh2_hmac_md5_init(libssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
#endif
|
||||
|
||||
#if LIBSSH2_HMAC_RIPEMD
|
||||
int _libssh2_hmac_ripemd160_init(libssh2_hmac_ctx *ctx,
|
||||
void *key, size_t keylen)
|
||||
int ssh2_hmac_ripemd160_init(ssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
{
|
||||
gcry_error_t err;
|
||||
err = gcry_md_open(ctx, GCRY_MD_RMD160, GCRY_MD_FLAG_HMAC);
|
||||
@@ -77,7 +76,7 @@ int _libssh2_hmac_ripemd160_init(libssh2_hmac_ctx *ctx,
|
||||
}
|
||||
#endif
|
||||
|
||||
int _libssh2_hmac_sha1_init(libssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
int ssh2_hmac_sha1_init(ssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
{
|
||||
gcry_error_t err;
|
||||
err = gcry_md_open(ctx, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
|
||||
@@ -89,7 +88,7 @@ int _libssh2_hmac_sha1_init(libssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _libssh2_hmac_sha256_init(libssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
int ssh2_hmac_sha256_init(ssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
{
|
||||
gcry_error_t err;
|
||||
err = gcry_md_open(ctx, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC);
|
||||
@@ -101,7 +100,7 @@ int _libssh2_hmac_sha256_init(libssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _libssh2_hmac_sha512_init(libssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
int ssh2_hmac_sha512_init(ssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
{
|
||||
gcry_error_t err;
|
||||
err = gcry_md_open(ctx, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC);
|
||||
@@ -113,14 +112,13 @@ int _libssh2_hmac_sha512_init(libssh2_hmac_ctx *ctx, void *key, size_t keylen)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _libssh2_hmac_update(libssh2_hmac_ctx *ctx,
|
||||
const void *data, size_t datalen)
|
||||
int ssh2_hmac_update(ssh2_hmac_ctx *ctx, const void *data, size_t datalen)
|
||||
{
|
||||
gcry_md_write(*ctx, data, datalen);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int _libssh2_hmac_final(libssh2_hmac_ctx *ctx, void *data)
|
||||
int ssh2_hmac_final(ssh2_hmac_ctx *ctx, void *data)
|
||||
{
|
||||
unsigned char *res = gcry_md_read(*ctx, 0);
|
||||
|
||||
@@ -132,21 +130,21 @@ int _libssh2_hmac_final(libssh2_hmac_ctx *ctx, void *data)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _libssh2_hmac_cleanup(libssh2_hmac_ctx *ctx)
|
||||
void ssh2_hmac_cleanup(ssh2_hmac_ctx *ctx)
|
||||
{
|
||||
gcry_md_close(*ctx);
|
||||
}
|
||||
|
||||
#if LIBSSH2_RSA
|
||||
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
||||
const unsigned char *edata, unsigned long elen,
|
||||
const unsigned char *ndata, unsigned long nlen,
|
||||
const unsigned char *ddata, unsigned long dlen,
|
||||
const unsigned char *pdata, unsigned long plen,
|
||||
const unsigned char *qdata, unsigned long qlen,
|
||||
const unsigned char *e1data, unsigned long e1len,
|
||||
const unsigned char *e2data, unsigned long e2len,
|
||||
const unsigned char *coeffdata, unsigned long coefflen)
|
||||
int ssh2_rsa_new(ssh2_rsa_ctx **rsa,
|
||||
const unsigned char *edata, unsigned long elen,
|
||||
const unsigned char *ndata, unsigned long nlen,
|
||||
const unsigned char *ddata, unsigned long dlen,
|
||||
const unsigned char *pdata, unsigned long plen,
|
||||
const unsigned char *qdata, unsigned long qlen,
|
||||
const unsigned char *e1data, unsigned long e1len,
|
||||
const unsigned char *e2data, unsigned long e2len,
|
||||
const unsigned char *coeffdata, unsigned long coefflen)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -173,11 +171,11 @@ int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _libssh2_rsa_sha2_verify(libssh2_rsa_ctx *rsactx,
|
||||
size_t hash_len,
|
||||
const unsigned char *sig,
|
||||
size_t sig_len,
|
||||
const unsigned char *m, size_t m_len)
|
||||
int ssh2_rsa_sha2_verify(ssh2_rsa_ctx *rsactx,
|
||||
size_t hash_len,
|
||||
const unsigned char *sig,
|
||||
size_t sig_len,
|
||||
const unsigned char *m, size_t m_len)
|
||||
{
|
||||
unsigned char *hash;
|
||||
int ret;
|
||||
@@ -191,15 +189,15 @@ int _libssh2_rsa_sha2_verify(libssh2_rsa_ctx *rsactx,
|
||||
|
||||
if(hash_len == SHA_DIGEST_LENGTH) {
|
||||
algo = "sha1";
|
||||
ret = libssh2_sha1(m, m_len, hash);
|
||||
ret = ssh2_sha1(m, m_len, hash);
|
||||
}
|
||||
else if(hash_len == SHA256_DIGEST_LENGTH) {
|
||||
algo = "sha256";
|
||||
ret = libssh2_sha256(m, m_len, hash);
|
||||
ret = ssh2_sha256(m, m_len, hash);
|
||||
}
|
||||
else if(hash_len == SHA512_DIGEST_LENGTH) {
|
||||
algo = "sha512";
|
||||
ret = libssh2_sha512(m, m_len, hash);
|
||||
ret = ssh2_sha512(m, m_len, hash);
|
||||
}
|
||||
else {
|
||||
ret = 1;
|
||||
@@ -236,24 +234,24 @@ out:
|
||||
}
|
||||
|
||||
#if LIBSSH2_RSA_SHA1
|
||||
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *sig,
|
||||
size_t sig_len,
|
||||
const unsigned char *m, size_t m_len)
|
||||
int ssh2_rsa_sha1_verify(ssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *sig,
|
||||
size_t sig_len,
|
||||
const unsigned char *m, size_t m_len)
|
||||
{
|
||||
return _libssh2_rsa_sha2_verify(rsactx, SHA_DIGEST_LENGTH, sig, sig_len, m,
|
||||
return ssh2_rsa_sha2_verify(rsactx, SHA_DIGEST_LENGTH, sig, sig_len, m,
|
||||
m_len);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIBSSH2_DSA
|
||||
int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
||||
const unsigned char *p, unsigned long p_len,
|
||||
const unsigned char *q, unsigned long q_len,
|
||||
const unsigned char *g, unsigned long g_len,
|
||||
const unsigned char *y, unsigned long y_len,
|
||||
const unsigned char *x, unsigned long x_len)
|
||||
int ssh2_dsa_new(ssh2_dsa_ctx **dsactx,
|
||||
const unsigned char *p, unsigned long p_len,
|
||||
const unsigned char *q, unsigned long q_len,
|
||||
const unsigned char *g, unsigned long g_len,
|
||||
const unsigned char *y, unsigned long y_len,
|
||||
const unsigned char *x, unsigned long x_len)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -278,26 +276,26 @@ int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
||||
#endif
|
||||
|
||||
#if LIBSSH2_RSA
|
||||
int _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx **rsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase)
|
||||
int ssh2_rsa_new_private_frommemory(ssh2_rsa_ctx **rsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase)
|
||||
{
|
||||
(void)rsa;
|
||||
(void)filedata;
|
||||
(void)filedata_len;
|
||||
(void)passphrase;
|
||||
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unable to extract private key from memory: "
|
||||
"Method unimplemented in libgcrypt backend");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unable to extract private key from memory: "
|
||||
"Method unimplemented in libgcrypt backend");
|
||||
}
|
||||
|
||||
int _libssh2_rsa_new_private(libssh2_rsa_ctx **rsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase)
|
||||
int ssh2_rsa_new_private(ssh2_rsa_ctx **rsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase)
|
||||
{
|
||||
FILE *fp;
|
||||
unsigned char *data, *save_data;
|
||||
@@ -311,11 +309,10 @@ int _libssh2_rsa_new_private(libssh2_rsa_ctx **rsa,
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_parse(session,
|
||||
"-----BEGIN RSA PRIVATE KEY-----",
|
||||
"-----END RSA PRIVATE KEY-----",
|
||||
passphrase,
|
||||
fp, &data, &datalen);
|
||||
ret = ssh2_pem_parse(session,
|
||||
"-----BEGIN RSA PRIVATE KEY-----",
|
||||
"-----END RSA PRIVATE KEY-----",
|
||||
passphrase, fp, &data, &datalen);
|
||||
fclose(fp);
|
||||
if(ret) {
|
||||
return -1;
|
||||
@@ -323,68 +320,68 @@ int _libssh2_rsa_new_private(libssh2_rsa_ctx **rsa,
|
||||
|
||||
save_data = data;
|
||||
|
||||
if(_libssh2_pem_decode_sequence(&data, &datalen)) {
|
||||
if(ssh2_pem_decode_sequence(&data, &datalen)) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* First read Version field (should be 0). */
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &n, &nlen);
|
||||
if(ret || (nlen != 1 && *n != '\0')) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &n, &nlen);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &e, &elen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &e, &elen);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &d, &dlen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &d, &dlen);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &p, &plen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &p, &plen);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &q, &qlen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &q, &qlen);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &e1, &e1len);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &e1, &e1len);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &e2, &e2len);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &e2, &e2len);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &coeff, &coefflen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &coeff, &coefflen);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(_libssh2_rsa_new(rsa, e, elen, n, nlen, d, dlen, p, plen,
|
||||
q, qlen, e1, e1len, e2, e2len, coeff, coefflen)) {
|
||||
if(ssh2_rsa_new(rsa, e, elen, n, nlen, d, dlen, p, plen,
|
||||
q, qlen, e1, e1len, e2, e2len, coeff, coefflen)) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
@@ -392,32 +389,32 @@ int _libssh2_rsa_new_private(libssh2_rsa_ctx **rsa,
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
LIBSSH2_FREE(session, save_data);
|
||||
SSH2_FREE(session, save_data);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIBSSH2_DSA
|
||||
int _libssh2_dsa_new_private_frommemory(libssh2_dsa_ctx **dsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase)
|
||||
int ssh2_dsa_new_private_frommemory(ssh2_dsa_ctx **dsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
const unsigned char *passphrase)
|
||||
{
|
||||
(void)dsa;
|
||||
(void)filedata;
|
||||
(void)filedata_len;
|
||||
(void)passphrase;
|
||||
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unable to extract private key from memory: "
|
||||
"Method unimplemented in libgcrypt backend");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unable to extract private key from memory: "
|
||||
"Method unimplemented in libgcrypt backend");
|
||||
}
|
||||
|
||||
int _libssh2_dsa_new_private(libssh2_dsa_ctx **dsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase)
|
||||
int ssh2_dsa_new_private(ssh2_dsa_ctx **dsa,
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *filename,
|
||||
const unsigned char *passphrase)
|
||||
{
|
||||
FILE *fp;
|
||||
unsigned char *data, *save_data;
|
||||
@@ -431,11 +428,10 @@ int _libssh2_dsa_new_private(libssh2_dsa_ctx **dsa,
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_parse(session,
|
||||
"-----BEGIN DSA PRIVATE KEY-----",
|
||||
"-----END DSA PRIVATE KEY-----",
|
||||
passphrase,
|
||||
fp, &data, &datalen);
|
||||
ret = ssh2_pem_parse(session,
|
||||
"-----BEGIN DSA PRIVATE KEY-----",
|
||||
"-----END DSA PRIVATE KEY-----",
|
||||
passphrase, fp, &data, &datalen);
|
||||
fclose(fp);
|
||||
if(ret) {
|
||||
return -1;
|
||||
@@ -443,43 +439,43 @@ int _libssh2_dsa_new_private(libssh2_dsa_ctx **dsa,
|
||||
|
||||
save_data = data;
|
||||
|
||||
if(_libssh2_pem_decode_sequence(&data, &datalen)) {
|
||||
if(ssh2_pem_decode_sequence(&data, &datalen)) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* First read Version field (should be 0). */
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &p, &plen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &p, &plen);
|
||||
if(ret || (plen != 1 && *p != '\0')) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &p, &plen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &p, &plen);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &q, &qlen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &q, &qlen);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &g, &glen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &g, &glen);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &y, &ylen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &y, &ylen);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_decode_integer(&data, &datalen, &x, &xlen);
|
||||
ret = ssh2_pem_decode_integer(&data, &datalen, &x, &xlen);
|
||||
if(ret) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
@@ -490,7 +486,7 @@ int _libssh2_dsa_new_private(libssh2_dsa_ctx **dsa,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(_libssh2_dsa_new(dsa, p, plen, q, qlen, g, glen, y, ylen, x, xlen)) {
|
||||
if(ssh2_dsa_new(dsa, p, plen, q, qlen, g, glen, y, ylen, x, xlen)) {
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
@@ -498,18 +494,18 @@ int _libssh2_dsa_new_private(libssh2_dsa_ctx **dsa,
|
||||
ret = 0;
|
||||
|
||||
fail:
|
||||
LIBSSH2_FREE(session, save_data);
|
||||
SSH2_FREE(session, save_data);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIBSSH2_RSA
|
||||
int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION *session,
|
||||
libssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len,
|
||||
unsigned char **signature,
|
||||
size_t *signature_len)
|
||||
int ssh2_rsa_sha2_sign(LIBSSH2_SESSION *session,
|
||||
ssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len,
|
||||
unsigned char **signature,
|
||||
size_t *signature_len)
|
||||
{
|
||||
const char *algo;
|
||||
gcry_sexp_t s_tmp = NULL;
|
||||
@@ -527,8 +523,8 @@ int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION *session,
|
||||
else if(hash_len == SHA512_DIGEST_LENGTH)
|
||||
algo = "sha512";
|
||||
else {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Unsupported hash digest length");
|
||||
ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Unsupported hash digest length");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -555,7 +551,7 @@ int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION *session,
|
||||
--size;
|
||||
}
|
||||
|
||||
out_sig = LIBSSH2_ALLOC(session, size);
|
||||
out_sig = SSH2_ALLOC(session, size);
|
||||
if(!out_sig)
|
||||
goto out;
|
||||
memcpy(out_sig, s, size);
|
||||
@@ -574,23 +570,23 @@ out:
|
||||
}
|
||||
|
||||
#if LIBSSH2_RSA_SHA1
|
||||
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
||||
libssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len,
|
||||
unsigned char **signature,
|
||||
size_t *signature_len)
|
||||
int ssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
||||
ssh2_rsa_ctx *rsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len,
|
||||
unsigned char **signature,
|
||||
size_t *signature_len)
|
||||
{
|
||||
return _libssh2_rsa_sha2_sign(session, rsactx, hash, hash_len,
|
||||
signature, signature_len);
|
||||
return ssh2_rsa_sha2_sign(session, rsactx, hash, hash_len,
|
||||
signature, signature_len);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LIBSSH2_DSA
|
||||
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len, unsigned char *sig)
|
||||
int ssh2_dsa_sha1_sign(ssh2_dsa_ctx *dsactx,
|
||||
const unsigned char *hash,
|
||||
size_t hash_len, unsigned char *sig)
|
||||
{
|
||||
unsigned char zhash[SHA_DIGEST_LENGTH + 1];
|
||||
gcry_sexp_t sig_sexp;
|
||||
@@ -677,15 +673,15 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
||||
const unsigned char *sig,
|
||||
const unsigned char *m, size_t m_len)
|
||||
int ssh2_dsa_sha1_verify(ssh2_dsa_ctx *dsactx,
|
||||
const unsigned char *sig,
|
||||
const unsigned char *m, size_t m_len)
|
||||
{
|
||||
unsigned char hash[SHA_DIGEST_LENGTH + 1];
|
||||
gcry_sexp_t s_sig, s_hash;
|
||||
int rc = -1;
|
||||
|
||||
if(libssh2_sha1(m, m_len, hash + 1)) {
|
||||
if(ssh2_sha1(m, m_len, hash + 1)) {
|
||||
return -1;
|
||||
}
|
||||
hash[0] = 0;
|
||||
@@ -709,13 +705,12 @@ int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
||||
}
|
||||
#endif
|
||||
|
||||
int _libssh2_cipher_init(libssh2_cipher_ctx *h,
|
||||
LIBSSH2_CIPHER_T(algo),
|
||||
unsigned char *iv, unsigned char *secret, int encrypt)
|
||||
int ssh2_cipher_init(ssh2_cipher_ctx *h, SSH2_CIPHER_T(algo),
|
||||
unsigned char *iv, unsigned char *secret, int encrypt)
|
||||
{
|
||||
int ret;
|
||||
int cipher = _libssh2_gcry_cipher(algo);
|
||||
int mode = _libssh2_gcry_mode(algo);
|
||||
int cipher = ssh2_gcry_cipher(algo);
|
||||
int mode = ssh2_gcry_mode(algo);
|
||||
size_t keylen = gcry_cipher_get_algo_keylen(cipher);
|
||||
|
||||
(void)encrypt;
|
||||
@@ -746,10 +741,10 @@ int _libssh2_cipher_init(libssh2_cipher_ctx *h,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _libssh2_cipher_crypt(libssh2_cipher_ctx *ctx,
|
||||
LIBSSH2_CIPHER_T(algo),
|
||||
int encrypt, unsigned char *block, size_t blocksize,
|
||||
int firstlast)
|
||||
int ssh2_cipher_crypt(ssh2_cipher_ctx *ctx,
|
||||
SSH2_CIPHER_T(algo),
|
||||
int encrypt, unsigned char *block, size_t blocksize,
|
||||
int firstlast)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -765,14 +760,14 @@ int _libssh2_cipher_crypt(libssh2_cipher_ctx *ctx,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
|
||||
unsigned char **method,
|
||||
size_t *method_len,
|
||||
unsigned char **pubkeydata,
|
||||
size_t *pubkeydata_len,
|
||||
const char *privatekeydata,
|
||||
size_t privatekeydata_len,
|
||||
const char *passphrase)
|
||||
int ssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
|
||||
unsigned char **method,
|
||||
size_t *method_len,
|
||||
unsigned char **pubkeydata,
|
||||
size_t *pubkeydata_len,
|
||||
const char *privatekeydata,
|
||||
size_t privatekeydata_len,
|
||||
const char *passphrase)
|
||||
{
|
||||
(void)method;
|
||||
(void)method_len;
|
||||
@@ -782,18 +777,18 @@ int _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
|
||||
(void)privatekeydata_len;
|
||||
(void)passphrase;
|
||||
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unable to extract public key from private key in "
|
||||
"memory: Method unimplemented in libgcrypt backend");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
|
||||
"Unable to extract public key from private key in "
|
||||
"memory: Method unimplemented in libgcrypt backend");
|
||||
}
|
||||
|
||||
int _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
|
||||
unsigned char **method,
|
||||
size_t *method_len,
|
||||
unsigned char **pubkeydata,
|
||||
size_t *pubkeydata_len,
|
||||
const char *privatekey,
|
||||
const char *passphrase)
|
||||
int ssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
|
||||
unsigned char **method,
|
||||
size_t *method_len,
|
||||
unsigned char **pubkeydata,
|
||||
size_t *pubkeydata_len,
|
||||
const char *privatekey,
|
||||
const char *passphrase)
|
||||
{
|
||||
(void)method;
|
||||
(void)method_len;
|
||||
@@ -802,24 +797,24 @@ int _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
|
||||
(void)privatekey;
|
||||
(void)passphrase;
|
||||
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||
"Unable to extract public key from private key "
|
||||
"file: Method unimplemented in libgcrypt backend");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_FILE,
|
||||
"Unable to extract public key from private key "
|
||||
"file: Method unimplemented in libgcrypt backend");
|
||||
}
|
||||
|
||||
int _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session,
|
||||
unsigned char **method,
|
||||
size_t *method_len,
|
||||
unsigned char **pubkeydata,
|
||||
size_t *pubkeydata_len,
|
||||
int *algorithm,
|
||||
unsigned char *flags,
|
||||
const char **application,
|
||||
const unsigned char **key_handle,
|
||||
size_t *handle_len,
|
||||
const char *privatekeydata,
|
||||
size_t privatekeydata_len,
|
||||
const char *passphrase)
|
||||
int ssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session,
|
||||
unsigned char **method,
|
||||
size_t *method_len,
|
||||
unsigned char **pubkeydata,
|
||||
size_t *pubkeydata_len,
|
||||
int *algorithm,
|
||||
unsigned char *flags,
|
||||
const char **application,
|
||||
const unsigned char **key_handle,
|
||||
size_t *handle_len,
|
||||
const char *privatekeydata,
|
||||
size_t privatekeydata_len,
|
||||
const char *passphrase)
|
||||
{
|
||||
(void)method;
|
||||
(void)method_len;
|
||||
@@ -834,23 +829,18 @@ int _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session,
|
||||
(void)privatekeydata_len;
|
||||
(void)passphrase;
|
||||
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||
"Unable to extract public SK key from private key "
|
||||
"file: Method unimplemented in libgcrypt backend");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_FILE,
|
||||
"Unable to extract public SK key from private key "
|
||||
"file: Method unimplemented in libgcrypt backend");
|
||||
}
|
||||
|
||||
void _libssh2_init_aes_ctr(void)
|
||||
{
|
||||
/* no implementation */
|
||||
}
|
||||
|
||||
void _libssh2_dh_init(libssh2_dh_ctx *dhctx)
|
||||
void ssh2_lgcr_dh_init(ssh2_dh_ctx *dhctx)
|
||||
{
|
||||
*dhctx = gcry_mpi_new(0); /* Random from client */
|
||||
}
|
||||
|
||||
int _libssh2_dh_key_pair(libssh2_dh_ctx *dhctx, libssh2_bn *public,
|
||||
libssh2_bn *g, libssh2_bn *p, int group_order)
|
||||
int ssh2_lgcr_dh_key_pair(ssh2_dh_ctx *dhctx, ssh2_bn *public,
|
||||
ssh2_bn *g, ssh2_bn *p, int group_order)
|
||||
{
|
||||
/* Generate x and e */
|
||||
gcry_mpi_randomize(*dhctx, group_order * 8 - 1, GCRY_VERY_STRONG_RANDOM);
|
||||
@@ -858,15 +848,15 @@ int _libssh2_dh_key_pair(libssh2_dh_ctx *dhctx, libssh2_bn *public,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _libssh2_dh_secret(libssh2_dh_ctx *dhctx, libssh2_bn *secret,
|
||||
libssh2_bn *f, libssh2_bn *p)
|
||||
int ssh2_lgcr_dh_secret(ssh2_dh_ctx *dhctx, ssh2_bn *secret,
|
||||
ssh2_bn *f, ssh2_bn *p)
|
||||
{
|
||||
/* Compute the shared secret */
|
||||
gcry_mpi_powm(secret, f, *dhctx, p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _libssh2_dh_dtor(libssh2_dh_ctx *dhctx)
|
||||
void ssh2_lgcr_dh_dtor(ssh2_dh_ctx *dhctx)
|
||||
{
|
||||
gcry_mpi_release(*dhctx);
|
||||
*dhctx = NULL;
|
||||
@@ -875,9 +865,9 @@ void _libssh2_dh_dtor(libssh2_dh_ctx *dhctx)
|
||||
/*
|
||||
* Return supported key hash algo upgrades, see crypto.h
|
||||
*/
|
||||
const char *_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session,
|
||||
unsigned char *key_method,
|
||||
size_t key_method_len)
|
||||
const char *ssh2_supported_key_sign_algs(LIBSSH2_SESSION *session,
|
||||
unsigned char *key_method,
|
||||
size_t key_method_len)
|
||||
{
|
||||
(void)session;
|
||||
|
||||
|
||||
196
src/libgcrypt.h
196
src/libgcrypt.h
@@ -41,7 +41,7 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#define LIBSSH2_CRYPTO_ENGINE libssh2_gcrypt
|
||||
#define SSH2_CRYPTO_ENGINE libssh2_gcrypt
|
||||
|
||||
#include <gcrypt.h>
|
||||
|
||||
@@ -79,157 +79,153 @@
|
||||
|
||||
#define EC_MAX_POINT_LEN ((528 * 2 / 8) + 1)
|
||||
|
||||
#define _libssh2_random(buf, len) \
|
||||
#define ssh2_random(buf, len) \
|
||||
(gcry_randomize(buf, len, GCRY_STRONG_RANDOM), 0)
|
||||
|
||||
#define libssh2_prepare_iovec(vec, len) /* Empty. */
|
||||
#define ssh2_prepare_iovec(vec, len) /* Empty. */
|
||||
|
||||
#define libssh2_sha1_ctx gcry_md_hd_t
|
||||
#define ssh2_sha1_ctx gcry_md_hd_t
|
||||
/* returns 0 in case of failure */
|
||||
#define libssh2_sha1_init(ctx) \
|
||||
#define ssh2_sha1_init(ctx) \
|
||||
(GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA1, 0))
|
||||
#define libssh2_sha1_update(ctx, data, len) \
|
||||
#define ssh2_sha1_update(ctx, data, len) \
|
||||
(gcry_md_write(ctx, data, len), 1)
|
||||
#define libssh2_sha1_final(ctx, out) \
|
||||
#define ssh2_sha1_final(ctx, out) \
|
||||
(memcpy(out, gcry_md_read(ctx, 0), SHA_DIGEST_LENGTH), \
|
||||
gcry_md_close(ctx), 1)
|
||||
#define libssh2_sha1(message, len, out) \
|
||||
#define ssh2_sha1(message, len, out) \
|
||||
(gcry_md_hash_buffer(GCRY_MD_SHA1, out, message, len), 0)
|
||||
|
||||
#define libssh2_sha256_ctx gcry_md_hd_t
|
||||
#define libssh2_sha256_init(ctx) \
|
||||
#define ssh2_sha256_ctx gcry_md_hd_t
|
||||
#define ssh2_sha256_init(ctx) \
|
||||
(GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA256, 0))
|
||||
#define libssh2_sha256_update(ctx, data, len) \
|
||||
#define ssh2_sha256_update(ctx, data, len) \
|
||||
(gcry_md_write(ctx, data, len), 1)
|
||||
#define libssh2_sha256_final(ctx, out) \
|
||||
#define ssh2_sha256_final(ctx, out) \
|
||||
(memcpy(out, gcry_md_read(ctx, 0), SHA256_DIGEST_LENGTH), \
|
||||
gcry_md_close(ctx), 1)
|
||||
#define libssh2_sha256(message, len, out) \
|
||||
#define ssh2_sha256(message, len, out) \
|
||||
(gcry_md_hash_buffer(GCRY_MD_SHA256, out, message, len), 0)
|
||||
|
||||
#define libssh2_sha384_ctx gcry_md_hd_t
|
||||
#define libssh2_sha384_init(ctx) \
|
||||
#define ssh2_sha384_ctx gcry_md_hd_t
|
||||
#define ssh2_sha384_init(ctx) \
|
||||
(GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA384, 0))
|
||||
#define libssh2_sha384_update(ctx, data, len) \
|
||||
#define ssh2_sha384_update(ctx, data, len) \
|
||||
(gcry_md_write(ctx, data, len), 1)
|
||||
#define libssh2_sha384_final(ctx, out) \
|
||||
#define ssh2_sha384_final(ctx, out) \
|
||||
(memcpy(out, gcry_md_read(ctx, 0), SHA384_DIGEST_LENGTH), \
|
||||
gcry_md_close(ctx), 1)
|
||||
#define libssh2_sha384(message, len, out) \
|
||||
#define ssh2_sha384(message, len, out) \
|
||||
(gcry_md_hash_buffer(GCRY_MD_SHA384, out, message, len), 0)
|
||||
|
||||
#define libssh2_sha512_ctx gcry_md_hd_t
|
||||
#define libssh2_sha512_init(ctx) \
|
||||
#define ssh2_sha512_ctx gcry_md_hd_t
|
||||
#define ssh2_sha512_init(ctx) \
|
||||
(GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA512, 0))
|
||||
#define libssh2_sha512_update(ctx, data, len) \
|
||||
#define ssh2_sha512_update(ctx, data, len) \
|
||||
(gcry_md_write(ctx, data, len), 1)
|
||||
#define libssh2_sha512_final(ctx, out) \
|
||||
#define ssh2_sha512_final(ctx, out) \
|
||||
(memcpy(out, gcry_md_read(ctx, 0), SHA512_DIGEST_LENGTH), \
|
||||
gcry_md_close(ctx), 1)
|
||||
#define libssh2_sha512(message, len, out) \
|
||||
#define ssh2_sha512(message, len, out) \
|
||||
(gcry_md_hash_buffer(GCRY_MD_SHA512, out, message, len), 0)
|
||||
|
||||
#if LIBSSH2_MD5 || LIBSSH2_MD5_PEM
|
||||
#define libssh2_md5_ctx gcry_md_hd_t
|
||||
#define libssh2_md5_init(ctx) \
|
||||
#define ssh2_md5_ctx gcry_md_hd_t
|
||||
#define ssh2_md5_init(ctx) \
|
||||
(GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_MD5, 0))
|
||||
#define libssh2_md5_update(ctx, data, len) \
|
||||
#define ssh2_md5_update(ctx, data, len) \
|
||||
(gcry_md_write(ctx, data, len), 1)
|
||||
#define libssh2_md5_final(ctx, out) \
|
||||
#define ssh2_md5_final(ctx, out) \
|
||||
(memcpy(out, gcry_md_read(ctx, 0), MD5_DIGEST_LENGTH), \
|
||||
gcry_md_close(ctx), 1)
|
||||
#endif
|
||||
|
||||
#define libssh2_hmac_ctx gcry_md_hd_t
|
||||
#define ssh2_hmac_ctx gcry_md_hd_t
|
||||
|
||||
#define libssh2_crypto_init() gcry_control(GCRYCTL_DISABLE_SECMEM)
|
||||
#define libssh2_crypto_exit()
|
||||
#define ssh2_crypto_init() gcry_control(GCRYCTL_DISABLE_SECMEM)
|
||||
#define ssh2_crypto_exit()
|
||||
|
||||
#define libssh2_rsa_ctx struct gcry_sexp
|
||||
#define ssh2_rsa_ctx struct gcry_sexp
|
||||
#define ssh2_rsa_free(rsactx) gcry_sexp_release(rsactx)
|
||||
|
||||
#define _libssh2_rsa_free(rsactx) gcry_sexp_release(rsactx)
|
||||
|
||||
#define libssh2_dsa_ctx struct gcry_sexp
|
||||
|
||||
#define _libssh2_dsa_free(dsactx) gcry_sexp_release(dsactx)
|
||||
#define ssh2_dsa_ctx struct gcry_sexp
|
||||
#define ssh2_dsa_free(dsactx) gcry_sexp_release(dsactx)
|
||||
|
||||
#if LIBSSH2_ECDSA
|
||||
#else
|
||||
#define libssh2_ec_key void
|
||||
#define ssh2_ec_key void
|
||||
#endif
|
||||
|
||||
#define LIBSSH2_CIPHER_T(name) int name
|
||||
#define libssh2_cipher_ctx gcry_cipher_hd_t
|
||||
#define SSH2_CIPHER_T(name) int name
|
||||
#define ssh2_cipher_ctx gcry_cipher_hd_t
|
||||
|
||||
#define _libssh2_gcry_ciphermode(c,m) (((c) << 8) | (m))
|
||||
#define _libssh2_gcry_cipher(c) ((c) >> 8)
|
||||
#define _libssh2_gcry_mode(m) ((m) & 0xFF)
|
||||
#define ssh2_gcry_ciphermode(c,m) (((c) << 8) | (m))
|
||||
#define ssh2_gcry_cipher(c) ((c) >> 8)
|
||||
#define ssh2_gcry_mode(m) ((m) & 0xFF)
|
||||
|
||||
#define libssh2_cipher_aes256ctr \
|
||||
_libssh2_gcry_ciphermode(GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CTR)
|
||||
#define libssh2_cipher_aes192ctr \
|
||||
_libssh2_gcry_ciphermode(GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CTR)
|
||||
#define libssh2_cipher_aes128ctr \
|
||||
_libssh2_gcry_ciphermode(GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR)
|
||||
#define libssh2_cipher_aes256 \
|
||||
_libssh2_gcry_ciphermode(GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC)
|
||||
#define libssh2_cipher_aes192 \
|
||||
_libssh2_gcry_ciphermode(GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CBC)
|
||||
#define libssh2_cipher_aes128 \
|
||||
_libssh2_gcry_ciphermode(GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC)
|
||||
#define libssh2_cipher_blowfish \
|
||||
_libssh2_gcry_ciphermode(GCRY_CIPHER_BLOWFISH, GCRY_CIPHER_MODE_CBC)
|
||||
#define libssh2_cipher_arcfour \
|
||||
_libssh2_gcry_ciphermode(GCRY_CIPHER_ARCFOUR, GCRY_CIPHER_MODE_STREAM)
|
||||
#define libssh2_cipher_cast5 \
|
||||
_libssh2_gcry_ciphermode(GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_CBC)
|
||||
#define libssh2_cipher_3des \
|
||||
_libssh2_gcry_ciphermode(GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC)
|
||||
#define libssh2_cipher_chacha20 \
|
||||
_libssh2_gcry_ciphermode(GCRY_CIPHER_CHACHA20, GCRY_CIPHER_MODE_STREAM)
|
||||
#define ssh2_cipher_aes256ctr \
|
||||
ssh2_gcry_ciphermode(GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CTR)
|
||||
#define ssh2_cipher_aes192ctr \
|
||||
ssh2_gcry_ciphermode(GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CTR)
|
||||
#define ssh2_cipher_aes128ctr \
|
||||
ssh2_gcry_ciphermode(GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CTR)
|
||||
#define ssh2_cipher_aes256 \
|
||||
ssh2_gcry_ciphermode(GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_CBC)
|
||||
#define ssh2_cipher_aes192 \
|
||||
ssh2_gcry_ciphermode(GCRY_CIPHER_AES192, GCRY_CIPHER_MODE_CBC)
|
||||
#define ssh2_cipher_aes128 \
|
||||
ssh2_gcry_ciphermode(GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_CBC)
|
||||
#define ssh2_cipher_blowfish \
|
||||
ssh2_gcry_ciphermode(GCRY_CIPHER_BLOWFISH, GCRY_CIPHER_MODE_CBC)
|
||||
#define ssh2_cipher_arcfour \
|
||||
ssh2_gcry_ciphermode(GCRY_CIPHER_ARCFOUR, GCRY_CIPHER_MODE_STREAM)
|
||||
#define ssh2_cipher_cast5 \
|
||||
ssh2_gcry_ciphermode(GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_CBC)
|
||||
#define ssh2_cipher_3des \
|
||||
ssh2_gcry_ciphermode(GCRY_CIPHER_3DES, GCRY_CIPHER_MODE_CBC)
|
||||
#define ssh2_cipher_chacha20 \
|
||||
ssh2_gcry_ciphermode(GCRY_CIPHER_CHACHA20, GCRY_CIPHER_MODE_STREAM)
|
||||
|
||||
#define _libssh2_cipher_dtor(ctx) gcry_cipher_close(*(ctx))
|
||||
#define ssh2_cipher_dtor(ctx) gcry_cipher_close(*(ctx))
|
||||
|
||||
#define libssh2_bn struct gcry_mpi
|
||||
#define libssh2_bn_ctx int
|
||||
#define _libssh2_bn_ctx_new() 0
|
||||
#define _libssh2_bn_ctx_free(bnctx) ((void)0)
|
||||
#define _libssh2_bn_init() gcry_mpi_new(0)
|
||||
#define _libssh2_bn_init_from_bin() NULL /* because gcry_mpi_scan() creates a
|
||||
new bignum */
|
||||
#define _libssh2_bn_set_word(bn, val) gcry_mpi_set_ui(bn, val)
|
||||
#define _libssh2_bn_from_bin(bn, len, val) \
|
||||
#define ssh2_bn struct gcry_mpi
|
||||
#define ssh2_bn_ctx int
|
||||
#define ssh2_bn_ctx_new() 0
|
||||
#define ssh2_bn_ctx_free(bnctx) ((void)0)
|
||||
#define ssh2_bn_init() gcry_mpi_new(0)
|
||||
#define ssh2_bn_init_from_bin() NULL /* because gcry_mpi_scan() creates a
|
||||
new bignum */
|
||||
#define ssh2_bn_set_word(bn, val) gcry_mpi_set_ui(bn, val)
|
||||
#define ssh2_bn_from_bin(bn, len, val) \
|
||||
gcry_mpi_scan(&(bn), GCRYMPI_FMT_USG, val, len, NULL)
|
||||
#define _libssh2_bn_to_bin(bn, val) \
|
||||
gcry_mpi_print(GCRYMPI_FMT_USG, val, _libssh2_bn_bytes(bn), NULL, bn)
|
||||
#define _libssh2_bn_bytes(bn) \
|
||||
(gcry_mpi_get_nbits(bn) / 8 + \
|
||||
((gcry_mpi_get_nbits(bn) % 8 == 0) ? 0 : 1))
|
||||
#define _libssh2_bn_bits(bn) gcry_mpi_get_nbits(bn)
|
||||
#define _libssh2_bn_free(bn) gcry_mpi_release(bn)
|
||||
#define ssh2_bn_to_bin(bn, val) \
|
||||
gcry_mpi_print(GCRYMPI_FMT_USG, val, ssh2_bn_bytes(bn), NULL, bn)
|
||||
#define ssh2_bn_bytes(bn) \
|
||||
(gcry_mpi_get_nbits(bn) / 8 + ((gcry_mpi_get_nbits(bn) % 8 == 0) ? 0 : 1))
|
||||
#define ssh2_bn_bits(bn) gcry_mpi_get_nbits(bn)
|
||||
#define ssh2_bn_free(bn) gcry_mpi_release(bn)
|
||||
|
||||
/* Default generate and safe prime sizes for
|
||||
diffie-hellman-group-exchange-sha1 */
|
||||
#define LIBSSH2_DH_GEX_MINGROUP 2048
|
||||
#define LIBSSH2_DH_GEX_OPTGROUP 4096
|
||||
#define LIBSSH2_DH_GEX_MAXGROUP 8192
|
||||
#define SSH2_DH_GEX_MINGROUP 2048
|
||||
#define SSH2_DH_GEX_OPTGROUP 4096
|
||||
#define SSH2_DH_GEX_MAXGROUP 8192
|
||||
|
||||
#define LIBSSH2_DH_MAX_MODULUS_BITS 16384
|
||||
#define SSH2_DH_MAX_MODULUS_BITS 16384
|
||||
|
||||
#define libssh2_dh_ctx struct gcry_mpi *
|
||||
#define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx)
|
||||
#define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \
|
||||
_libssh2_dh_key_pair(dhctx, public, g, p, group_order)
|
||||
#define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \
|
||||
_libssh2_dh_secret(dhctx, secret, f, p)
|
||||
#define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx)
|
||||
void _libssh2_init_aes_ctr(void);
|
||||
void _libssh2_dh_init(libssh2_dh_ctx *dhctx);
|
||||
int _libssh2_dh_key_pair(libssh2_dh_ctx *dhctx, libssh2_bn *public,
|
||||
libssh2_bn *g, libssh2_bn *p,
|
||||
int group_order);
|
||||
int _libssh2_dh_secret(libssh2_dh_ctx *dhctx, libssh2_bn *secret,
|
||||
libssh2_bn *f, libssh2_bn *p);
|
||||
void _libssh2_dh_dtor(libssh2_dh_ctx *dhctx);
|
||||
#define ssh2_dh_ctx struct gcry_mpi *
|
||||
#define ssh2_dh_init(dhctx) ssh2_lgcr_dh_init(dhctx)
|
||||
#define ssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \
|
||||
ssh2_lgcr_dh_key_pair(dhctx, public, g, p, group_order)
|
||||
#define ssh2_dh_secret(dhctx, secret, f, p, bnctx) \
|
||||
ssh2_lgcr_dh_secret(dhctx, secret, f, p)
|
||||
#define ssh2_dh_dtor(dhctx) ssh2_lgcr_dh_dtor(dhctx)
|
||||
void ssh2_lgcr_dh_init(ssh2_dh_ctx *dhctx);
|
||||
int ssh2_lgcr_dh_key_pair(ssh2_dh_ctx *dhctx, ssh2_bn *public,
|
||||
ssh2_bn *g, ssh2_bn *p,
|
||||
int group_order);
|
||||
int ssh2_lgcr_dh_secret(ssh2_dh_ctx *dhctx, ssh2_bn *secret,
|
||||
ssh2_bn *f, ssh2_bn *p);
|
||||
void ssh2_lgcr_dh_dtor(ssh2_dh_ctx *dhctx);
|
||||
|
||||
#endif /* LIBSSH2_LIBGCRYPT_H */
|
||||
|
||||
@@ -124,53 +124,53 @@
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
#define LIBSSH2_UNCONST(p) ((void *)(libssh2_uint64_t)(const void *)(p))
|
||||
#define SSH2_UNCONST(p) ((void *)(libssh2_uint64_t)(const void *)(p))
|
||||
#elif defined(_MSC_VER)
|
||||
#define LIBSSH2_UNCONST(p) ((void *)(unsigned int)(const void *)(p))
|
||||
#define SSH2_UNCONST(p) ((void *)(unsigned int)(const void *)(p))
|
||||
#else
|
||||
#define LIBSSH2_UNCONST(p) ((void *)(uintptr_t)(const void *)(p))
|
||||
#define SSH2_UNCONST(p) ((void *)(uintptr_t)(const void *)(p))
|
||||
#endif
|
||||
|
||||
#if (defined(__GNUC__) || defined(__clang__)) && \
|
||||
defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
|
||||
!defined(LIBSSH2_NO_FMT_CHECKS)
|
||||
#ifdef __MINGW_PRINTF_FORMAT
|
||||
#define LIBSSH2_PRINTF(fmt, arg) \
|
||||
#define SSH2_PRINTF(fmt, arg) \
|
||||
__attribute__((format(__MINGW_PRINTF_FORMAT, fmt, arg)))
|
||||
#elif !defined(__MINGW32__)
|
||||
#define LIBSSH2_PRINTF(fmt, arg) \
|
||||
#define SSH2_PRINTF(fmt, arg) \
|
||||
__attribute__((format(printf, fmt, arg)))
|
||||
#endif
|
||||
#endif
|
||||
#ifndef LIBSSH2_PRINTF
|
||||
#define LIBSSH2_PRINTF(fmt, arg)
|
||||
#ifndef SSH2_PRINTF
|
||||
#define SSH2_PRINTF(fmt, arg)
|
||||
#endif
|
||||
|
||||
/* Use local implementation when not available */
|
||||
#ifndef HAVE_SNPRINTF
|
||||
#undef snprintf
|
||||
#define snprintf _libssh2_snprintf
|
||||
#define snprintf ssh2_snprintf
|
||||
#define LIBSSH2_SNPRINTF
|
||||
int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...)
|
||||
LIBSSH2_PRINTF(3, 4);
|
||||
int ssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...)
|
||||
SSH2_PRINTF(3, 4);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETTIMEOFDAY
|
||||
#define HAVE_GETTIMEOFDAY
|
||||
#undef gettimeofday
|
||||
#define gettimeofday _libssh2_gettimeofday
|
||||
#define gettimeofday ssh2_gettimeofday
|
||||
#define LIBSSH2_GETTIMEOFDAY
|
||||
int _libssh2_gettimeofday(struct timeval *tp, void *tzp);
|
||||
int ssh2_gettimeofday(struct timeval *tp, void *tzp);
|
||||
#elif defined(HAVE_SYS_TIME_H)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifndef LIBSSH2_FALLTHROUGH
|
||||
#ifndef SSH2_FALLTHROUGH
|
||||
#if (defined(__GNUC__) && __GNUC__ >= 7) || \
|
||||
(defined(__clang__) && __clang_major__ >= 10)
|
||||
# define LIBSSH2_FALLTHROUGH() __attribute__((fallthrough))
|
||||
# define SSH2_FALLTHROUGH() __attribute__((fallthrough))
|
||||
#else
|
||||
# define LIBSSH2_FALLTHROUGH() do {} while(0)
|
||||
# define SSH2_FALLTHROUGH() do {} while(0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -212,8 +212,8 @@ struct iovec {
|
||||
#define UINT_MAX 0xFFFFFFFF
|
||||
#endif
|
||||
|
||||
#define LIBSSH2_MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||
#define LIBSSH2_MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
#define SSH2_MAX(x, y) ((x) > (y) ? (x) : (y))
|
||||
#define SSH2_MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
#define MAX_BLOCKSIZE 32 /* MUST fit biggest crypto block size we use/get */
|
||||
#define MAX_MACSIZE 64 /* MUST fit biggest MAC length we support */
|
||||
@@ -228,89 +228,90 @@ struct iovec {
|
||||
#define MAX_SSH_PACKET_LEN 35000
|
||||
#define MAX_SHA_DIGEST_LEN SHA512_DIGEST_LENGTH
|
||||
|
||||
#define LIBSSH2_ALLOC(session, count) \
|
||||
#define SSH2_ALLOC(session, count) \
|
||||
session->alloc(count, &(session)->abstract)
|
||||
#define LIBSSH2_CALLOC(session, count) _libssh2_calloc(session, count)
|
||||
#define LIBSSH2_REALLOC(session, ptr, count) \
|
||||
#define SSH2_CALLOC(session, count) ssh2_calloc(session, count)
|
||||
#define SSH2_REALLOC(session, ptr, count) \
|
||||
((ptr) ? (session)->realloc(ptr, count, &(session)->abstract) : \
|
||||
(session)->alloc(count, &(session)->abstract))
|
||||
#define LIBSSH2_FREE(session, ptr) \
|
||||
#define SSH2_FREE(session, ptr) \
|
||||
session->free(ptr, &(session)->abstract)
|
||||
#define LIBSSH2_IGNORE(session, data, datalen) \
|
||||
#define SSH2_IGNORE(session, data, datalen) \
|
||||
session->ssh_msg_ignore(session, data, (int)(datalen), \
|
||||
&(session)->abstract)
|
||||
#define LIBSSH2_DEBUG(session, always_display, message, message_len, \
|
||||
language, language_len) \
|
||||
#define SSH2_DEBUG(session, always_display, message, message_len, \
|
||||
language, language_len) \
|
||||
session->ssh_msg_debug(session, always_display, \
|
||||
message, (int)(message_len), \
|
||||
language, (int)(language_len), \
|
||||
&(session)->abstract)
|
||||
#define LIBSSH2_DISCONNECT(session, reason, message, message_len, \
|
||||
language, language_len) \
|
||||
#define SSH2_DISCONNECT(session, reason, message, message_len, \
|
||||
language, language_len) \
|
||||
session->ssh_msg_disconnect(session, reason, \
|
||||
message, (int)(message_len), \
|
||||
language, (int)(language_len), \
|
||||
&(session)->abstract)
|
||||
|
||||
#define LIBSSH2_MACERROR(session, data, datalen) \
|
||||
#define SSH2_MACERROR(session, data, datalen) \
|
||||
session->macerror(session, data, (int)(datalen), &(session)->abstract)
|
||||
#define LIBSSH2_X11_OPEN(channel, shost, sport) \
|
||||
#define SSH2_X11_OPEN(channel, shost, sport) \
|
||||
channel->session->x11((channel)->session, channel, \
|
||||
shost, sport, &(channel)->session->abstract)
|
||||
|
||||
#define LIBSSH2_AUTHAGENT(channel) \
|
||||
#define SSH2_AUTHAGENT(channel) \
|
||||
channel->session->authagent((channel)->session, channel, \
|
||||
&(channel)->session->abstract)
|
||||
|
||||
#define LIBSSH2_ADD_IDENTITIES(session, buffer, agentPath) \
|
||||
#define SSH2_ADD_IDENTITIES(session, buffer, agentPath) \
|
||||
session->addLocalIdentities(session, buffer, \
|
||||
agentPath, &(session)->abstract)
|
||||
|
||||
#define LIBSSH2_AUTHAGENT_SIGN(session, blob, blen, \
|
||||
data, dlen, sig, sigLen, \
|
||||
agentPath) \
|
||||
#define SSH2_AUTHAGENT_SIGN(session, blob, blen, \
|
||||
data, dlen, sig, sigLen, \
|
||||
agentPath) \
|
||||
session->agentSignCallback(session, blob, blen, \
|
||||
data, dlen, sig, sigLen, \
|
||||
agentPath, &(session)->abstract)
|
||||
|
||||
#define LIBSSH2_CHANNEL_CLOSE(session, channel) \
|
||||
#define SSH2_CHANNEL_CLOSE(session, channel) \
|
||||
channel->close_cb(session, &(session)->abstract, \
|
||||
channel, &(channel)->abstract)
|
||||
|
||||
#define LIBSSH2_SEND_FD(session, fd, buffer, length, flags) \
|
||||
#define SSH2_SEND_FD(session, fd, buffer, length, flags) \
|
||||
((session)->send)(fd, buffer, length, flags, &(session)->abstract)
|
||||
#define LIBSSH2_RECV_FD(session, fd, buffer, length, flags) \
|
||||
#define SSH2_RECV_FD(session, fd, buffer, length, flags) \
|
||||
((session)->recv)(fd, buffer, length, flags, &(session)->abstract)
|
||||
|
||||
#define LIBSSH2_SEND(session, buffer, length, flags) \
|
||||
LIBSSH2_SEND_FD(session, (session)->socket_fd, buffer, length, flags)
|
||||
#define LIBSSH2_RECV(session, buffer, length, flags) \
|
||||
LIBSSH2_RECV_FD(session, (session)->socket_fd, buffer, length, flags)
|
||||
#define SSH2_SEND(session, buffer, length, flags) \
|
||||
SSH2_SEND_FD(session, (session)->socket_fd, buffer, length, flags)
|
||||
#define SSH2_RECV(session, buffer, length, flags) \
|
||||
SSH2_RECV_FD(session, (session)->socket_fd, buffer, length, flags)
|
||||
|
||||
/* non-blocking states */
|
||||
typedef enum {
|
||||
libssh2_NB_state_idle = 0,
|
||||
libssh2_NB_state_allocated,
|
||||
libssh2_NB_state_created,
|
||||
libssh2_NB_state_sent,
|
||||
libssh2_NB_state_sent1,
|
||||
libssh2_NB_state_sent2,
|
||||
libssh2_NB_state_sent3,
|
||||
libssh2_NB_state_sent4,
|
||||
libssh2_NB_state_sent5,
|
||||
libssh2_NB_state_sent6,
|
||||
libssh2_NB_state_sent7,
|
||||
libssh2_NB_state_jump1,
|
||||
libssh2_NB_state_jump2,
|
||||
libssh2_NB_state_jump3,
|
||||
libssh2_NB_state_jump4,
|
||||
libssh2_NB_state_jump5,
|
||||
libssh2_NB_state_error_closing,
|
||||
libssh2_NB_state_end,
|
||||
libssh2_NB_state_jumpauthagent
|
||||
} libssh2_nonblocking_states;
|
||||
ssh2_NB_state_idle = 0,
|
||||
ssh2_NB_state_allocated,
|
||||
ssh2_NB_state_created,
|
||||
ssh2_NB_state_sent,
|
||||
ssh2_NB_state_sent1,
|
||||
ssh2_NB_state_sent2,
|
||||
ssh2_NB_state_sent3,
|
||||
ssh2_NB_state_sent4,
|
||||
ssh2_NB_state_sent5,
|
||||
ssh2_NB_state_sent6,
|
||||
ssh2_NB_state_sent7,
|
||||
ssh2_NB_state_jump1,
|
||||
ssh2_NB_state_jump2,
|
||||
ssh2_NB_state_jump3,
|
||||
ssh2_NB_state_jump4,
|
||||
ssh2_NB_state_jump5,
|
||||
ssh2_NB_state_error_closing,
|
||||
ssh2_NB_state_end,
|
||||
ssh2_NB_state_jumpauthagent
|
||||
} ssh2_NB_states;
|
||||
|
||||
struct packet_require_state {
|
||||
libssh2_nonblocking_states state;
|
||||
ssh2_NB_states state;
|
||||
time_t start;
|
||||
};
|
||||
|
||||
@@ -319,7 +320,7 @@ struct packet_requirev_state {
|
||||
};
|
||||
|
||||
struct kmdhgGPshakex_state {
|
||||
libssh2_nonblocking_states state;
|
||||
ssh2_NB_states state;
|
||||
unsigned char *e_packet;
|
||||
unsigned char *s_packet;
|
||||
unsigned char *tmp;
|
||||
@@ -328,11 +329,11 @@ struct kmdhgGPshakex_state {
|
||||
size_t e_packet_len;
|
||||
size_t s_packet_len;
|
||||
size_t tmp_len;
|
||||
libssh2_bn_ctx *ctx;
|
||||
libssh2_dh_ctx x;
|
||||
libssh2_bn *e;
|
||||
libssh2_bn *f;
|
||||
libssh2_bn *k;
|
||||
ssh2_bn_ctx *ctx;
|
||||
ssh2_dh_ctx x;
|
||||
ssh2_bn *e;
|
||||
ssh2_bn *f;
|
||||
ssh2_bn *k;
|
||||
unsigned char *f_value;
|
||||
unsigned char *k_value;
|
||||
unsigned char *h_sig;
|
||||
@@ -340,22 +341,22 @@ struct kmdhgGPshakex_state {
|
||||
size_t k_value_len;
|
||||
size_t h_sig_len;
|
||||
struct packet_require_state req_state;
|
||||
libssh2_nonblocking_states burn_state;
|
||||
ssh2_NB_states burn_state;
|
||||
};
|
||||
|
||||
struct key_exchange_state_low {
|
||||
libssh2_nonblocking_states state;
|
||||
ssh2_NB_states state;
|
||||
struct packet_require_state req_state;
|
||||
struct kmdhgGPshakex_state exchange_state;
|
||||
libssh2_bn *p; /* SSH2 defined value (p_value) */
|
||||
libssh2_bn *g; /* SSH2 defined value (2) */
|
||||
ssh2_bn *p; /* SSH2 defined value (p_value) */
|
||||
ssh2_bn *g; /* SSH2 defined value (2) */
|
||||
/* Request must fit mlkem1024nistp384 keys + 5 bytes overhead */
|
||||
unsigned char request[LIBSSH2_MLKEM_1024_PUBLIC_KEY_LEN +
|
||||
LIBSSH2_EC_P384_PUBLIC_KEY_LEN + 5];
|
||||
unsigned char request[SSH2_MLKEM_1024_PUBLIC_KEY_LEN +
|
||||
SSH2_EC_P384_PUBLIC_KEY_LEN + 5];
|
||||
unsigned char *data;
|
||||
size_t request_len;
|
||||
size_t data_len;
|
||||
libssh2_ec_key *private_key; /* SSH2 ecdh private key */
|
||||
ssh2_ec_key *private_key; /* SSH2 ecdh private key */
|
||||
unsigned char *public_key_oct; /* SSH2 ecdh public key octal value */
|
||||
size_t public_key_oct_len; /* SSH2 ecdh public key octal value
|
||||
length */
|
||||
@@ -368,7 +369,7 @@ struct key_exchange_state_low {
|
||||
};
|
||||
|
||||
struct key_exchange_state {
|
||||
libssh2_nonblocking_states state;
|
||||
ssh2_NB_states state;
|
||||
struct packet_require_state req_state;
|
||||
struct key_exchange_state_low key_state_low;
|
||||
unsigned char *data;
|
||||
@@ -380,7 +381,7 @@ struct key_exchange_state {
|
||||
#define FwdNotReq "Forward not requested"
|
||||
|
||||
struct packet_queue_listener_state {
|
||||
libssh2_nonblocking_states state;
|
||||
ssh2_NB_states state;
|
||||
unsigned char packet[17 + (sizeof(FwdNotReq) - 1)];
|
||||
unsigned char *host;
|
||||
unsigned char *shost;
|
||||
@@ -397,7 +398,7 @@ struct packet_queue_listener_state {
|
||||
#define X11FwdUnAvil "X11 Forward Unavailable"
|
||||
|
||||
struct packet_x11_open_state {
|
||||
libssh2_nonblocking_states state;
|
||||
ssh2_NB_states state;
|
||||
unsigned char packet[17 + (sizeof(X11FwdUnAvil) - 1)];
|
||||
unsigned char *shost;
|
||||
uint32_t sender_channel;
|
||||
@@ -411,7 +412,7 @@ struct packet_x11_open_state {
|
||||
#define AuthAgentUnavail "Auth Agent unavailable"
|
||||
|
||||
struct packet_authagent_state {
|
||||
libssh2_nonblocking_states state;
|
||||
ssh2_NB_states state;
|
||||
unsigned char packet[17 + (sizeof(AuthAgentUnavail) - 1)];
|
||||
uint32_t sender_channel;
|
||||
uint32_t initial_window_size;
|
||||
@@ -466,7 +467,7 @@ struct _LIBSSH2_CHANNEL {
|
||||
LIBSSH2_CHANNEL_CLOSE_FUNC(*close_cb);
|
||||
|
||||
/* State variables used in libssh2_channel_setenv_ex() */
|
||||
libssh2_nonblocking_states setenv_state;
|
||||
ssh2_NB_states setenv_state;
|
||||
unsigned char *setenv_packet;
|
||||
size_t setenv_packet_len;
|
||||
unsigned char setenv_local_channel[4];
|
||||
@@ -474,73 +475,73 @@ struct _LIBSSH2_CHANNEL {
|
||||
|
||||
/* State variables used in libssh2_channel_request_pty_ex()
|
||||
libssh2_channel_request_pty_size_ex() */
|
||||
libssh2_nonblocking_states reqPTY_state;
|
||||
ssh2_NB_states reqPTY_state;
|
||||
unsigned char reqPTY_packet[41 + 256];
|
||||
size_t reqPTY_packet_len;
|
||||
unsigned char reqPTY_local_channel[4];
|
||||
struct packet_requirev_state reqPTY_packet_requirev_state;
|
||||
|
||||
/* State variables used in libssh2_channel_x11_req_ex() */
|
||||
libssh2_nonblocking_states reqX11_state;
|
||||
ssh2_NB_states reqX11_state;
|
||||
unsigned char *reqX11_packet;
|
||||
size_t reqX11_packet_len;
|
||||
unsigned char reqX11_local_channel[4];
|
||||
struct packet_requirev_state reqX11_packet_requirev_state;
|
||||
|
||||
/* State variables used in libssh2_channel_process_startup() */
|
||||
libssh2_nonblocking_states process_state;
|
||||
ssh2_NB_states process_state;
|
||||
unsigned char *process_packet;
|
||||
size_t process_packet_len;
|
||||
unsigned char process_local_channel[4];
|
||||
struct packet_requirev_state process_packet_requirev_state;
|
||||
|
||||
/* State variables used in libssh2_channel_flush_ex() */
|
||||
libssh2_nonblocking_states flush_state;
|
||||
ssh2_NB_states flush_state;
|
||||
size_t flush_refund_bytes;
|
||||
size_t flush_flush_bytes;
|
||||
|
||||
/* State variables used in libssh2_channel_receive_window_adjust2() */
|
||||
libssh2_nonblocking_states adjust_state;
|
||||
ssh2_NB_states adjust_state;
|
||||
unsigned char adjust_adjust[9]; /* packet_type(1) + channel(4) +
|
||||
adjustment(4) */
|
||||
|
||||
/* State variables used in libssh2_channel_read_ex() */
|
||||
libssh2_nonblocking_states read_state;
|
||||
ssh2_NB_states read_state;
|
||||
|
||||
uint32_t read_local_id;
|
||||
|
||||
/* State variables used in libssh2_channel_write_ex() */
|
||||
libssh2_nonblocking_states write_state;
|
||||
ssh2_NB_states write_state;
|
||||
unsigned char write_packet[13];
|
||||
size_t write_packet_len;
|
||||
size_t write_bufwrite;
|
||||
|
||||
/* State variables used in libssh2_channel_close() */
|
||||
libssh2_nonblocking_states close_state;
|
||||
ssh2_NB_states close_state;
|
||||
unsigned char close_packet[5];
|
||||
|
||||
/* State variables used in libssh2_channel_wait_closedeof() */
|
||||
libssh2_nonblocking_states wait_eof_state;
|
||||
ssh2_NB_states wait_eof_state;
|
||||
|
||||
/* State variables used in libssh2_channel_wait_closed() */
|
||||
libssh2_nonblocking_states wait_closed_state;
|
||||
ssh2_NB_states wait_closed_state;
|
||||
|
||||
/* State variables used in libssh2_channel_free() */
|
||||
libssh2_nonblocking_states free_state;
|
||||
ssh2_NB_states free_state;
|
||||
|
||||
/* State variables used in libssh2_channel_handle_extended_data2() */
|
||||
libssh2_nonblocking_states extData2_state;
|
||||
ssh2_NB_states extData2_state;
|
||||
|
||||
/* State variables used in libssh2_channel_request_auth_agent() */
|
||||
libssh2_nonblocking_states req_auth_agent_try_state;
|
||||
libssh2_nonblocking_states req_auth_agent_state;
|
||||
ssh2_NB_states req_auth_agent_try_state;
|
||||
ssh2_NB_states req_auth_agent_state;
|
||||
unsigned char req_auth_agent_packet[36];
|
||||
size_t req_auth_agent_packet_len;
|
||||
unsigned char req_auth_agent_local_channel[4];
|
||||
struct packet_requirev_state req_auth_agent_requirev_state;
|
||||
|
||||
/* State variables used in libssh2_channel_signal_ex() */
|
||||
libssh2_nonblocking_states sendsignal_state;
|
||||
ssh2_NB_states sendsignal_state;
|
||||
unsigned char *sendsignal_packet;
|
||||
size_t sendsignal_packet_len;
|
||||
};
|
||||
@@ -560,7 +561,7 @@ struct _LIBSSH2_LISTENER {
|
||||
int queue_maxsize;
|
||||
|
||||
/* State variables used in libssh2_channel_forward_cancel() */
|
||||
libssh2_nonblocking_states chanFwdCncl_state;
|
||||
ssh2_NB_states chanFwdCncl_state;
|
||||
unsigned char *chanFwdCncl_data;
|
||||
size_t chanFwdCncl_data_len;
|
||||
};
|
||||
@@ -609,7 +610,7 @@ struct transportpacket {
|
||||
number of bytes. A full package is
|
||||
packet_length + padding_length + 4 +
|
||||
mac_length. */
|
||||
unsigned char *payload; /* this is a pointer to a LIBSSH2_ALLOC()
|
||||
unsigned char *payload; /* this is a pointer to a SSH2_ALLOC()
|
||||
area to which we write incoming packet data
|
||||
which is not yet decrypted in etm mode. */
|
||||
unsigned char *wptr; /* write pointer into the payload to where we
|
||||
@@ -629,30 +630,30 @@ struct _LIBSSH2_PUBLICKEY {
|
||||
LIBSSH2_CHANNEL *channel;
|
||||
uint32_t version;
|
||||
|
||||
/* State variables used in libssh2_publickey_packet_receive() */
|
||||
libssh2_nonblocking_states receive_state;
|
||||
/* State variables used in publickey_packet_receive() */
|
||||
ssh2_NB_states receive_state;
|
||||
unsigned char *receive_packet;
|
||||
size_t receive_packet_len;
|
||||
|
||||
/* State variables used in libssh2_publickey_add_ex() */
|
||||
libssh2_nonblocking_states add_state;
|
||||
ssh2_NB_states add_state;
|
||||
unsigned char *add_packet;
|
||||
unsigned char *add_s;
|
||||
|
||||
/* State variables used in libssh2_publickey_remove_ex() */
|
||||
libssh2_nonblocking_states remove_state;
|
||||
ssh2_NB_states remove_state;
|
||||
unsigned char *remove_packet;
|
||||
unsigned char *remove_s;
|
||||
|
||||
/* State variables used in libssh2_publickey_list_fetch() */
|
||||
libssh2_nonblocking_states listFetch_state;
|
||||
ssh2_NB_states listFetch_state;
|
||||
unsigned char *listFetch_s;
|
||||
unsigned char listFetch_buffer[12];
|
||||
unsigned char *listFetch_data;
|
||||
size_t listFetch_data_len;
|
||||
};
|
||||
|
||||
#define LIBSSH2_SCP_RESPONSE_BUFLEN 256
|
||||
#define SSH2_SCP_RESPONSE_BUFLEN 256
|
||||
|
||||
struct flags {
|
||||
int sigpipe; /* LIBSSH2_FLAG_SIGPIPE */
|
||||
@@ -770,17 +771,17 @@ struct _LIBSSH2_SESSION {
|
||||
#endif
|
||||
|
||||
/* State variables used in libssh2_banner_send() */
|
||||
libssh2_nonblocking_states banner_TxRx_state;
|
||||
ssh2_NB_states banner_TxRx_state;
|
||||
char banner_TxRx_banner[8192];
|
||||
ssize_t banner_TxRx_total_send;
|
||||
|
||||
/* State variables used in libssh2_kexinit() */
|
||||
libssh2_nonblocking_states kexinit_state;
|
||||
/* State variables used in kexinit() */
|
||||
ssh2_NB_states kexinit_state;
|
||||
unsigned char *kexinit_data;
|
||||
size_t kexinit_data_len;
|
||||
|
||||
/* State variables used in libssh2_session_handshake() */
|
||||
libssh2_nonblocking_states startup_state;
|
||||
ssh2_NB_states startup_state;
|
||||
unsigned char *startup_data;
|
||||
size_t startup_data_len;
|
||||
unsigned char startup_service[sizeof("ssh-userauth") + 5 - 1];
|
||||
@@ -789,26 +790,26 @@ struct _LIBSSH2_SESSION {
|
||||
struct key_exchange_state startup_key_state;
|
||||
|
||||
/* State variables used in libssh2_session_free() */
|
||||
libssh2_nonblocking_states free_state;
|
||||
ssh2_NB_states free_state;
|
||||
|
||||
/* State variables used in libssh2_session_disconnect_ex() */
|
||||
libssh2_nonblocking_states disconnect_state;
|
||||
ssh2_NB_states disconnect_state;
|
||||
unsigned char disconnect_data[256 + 13];
|
||||
size_t disconnect_data_len;
|
||||
|
||||
/* State variables used in libssh2_packet_read() */
|
||||
libssh2_nonblocking_states readPack_state;
|
||||
/* State variables used in ssh2_packet_add() */
|
||||
ssh2_NB_states readPack_state;
|
||||
int readPack_encrypted;
|
||||
|
||||
/* State variables used in libssh2_userauth_list() */
|
||||
libssh2_nonblocking_states userauth_list_state;
|
||||
ssh2_NB_states userauth_list_state;
|
||||
unsigned char *userauth_list_data;
|
||||
size_t userauth_list_data_len;
|
||||
char *userauth_banner;
|
||||
struct packet_requirev_state userauth_list_packet_requirev_state;
|
||||
|
||||
/* State variables used in libssh2_userauth_password_ex() */
|
||||
libssh2_nonblocking_states userauth_pswd_state;
|
||||
ssh2_NB_states userauth_pswd_state;
|
||||
unsigned char *userauth_pswd_data;
|
||||
unsigned char userauth_pswd_data0;
|
||||
size_t userauth_pswd_data_len;
|
||||
@@ -817,7 +818,7 @@ struct _LIBSSH2_SESSION {
|
||||
struct packet_requirev_state userauth_pswd_packet_requirev_state;
|
||||
|
||||
/* State variables used in libssh2_userauth_hostbased_fromfile_ex() */
|
||||
libssh2_nonblocking_states userauth_host_state;
|
||||
ssh2_NB_states userauth_host_state;
|
||||
unsigned char *userauth_host_data;
|
||||
size_t userauth_host_data_len;
|
||||
unsigned char *userauth_host_packet;
|
||||
@@ -828,7 +829,7 @@ struct _LIBSSH2_SESSION {
|
||||
struct packet_requirev_state userauth_host_packet_requirev_state;
|
||||
|
||||
/* State variables used in libssh2_userauth_publickey_fromfile_ex() */
|
||||
libssh2_nonblocking_states userauth_pblc_state;
|
||||
ssh2_NB_states userauth_pblc_state;
|
||||
unsigned char *userauth_pblc_data;
|
||||
size_t userauth_pblc_data_len;
|
||||
unsigned char *userauth_pblc_packet;
|
||||
@@ -840,7 +841,7 @@ struct _LIBSSH2_SESSION {
|
||||
struct packet_requirev_state userauth_pblc_packet_requirev_state;
|
||||
|
||||
/* State variables used in libssh2_userauth_keyboard_interactive_ex() */
|
||||
libssh2_nonblocking_states userauth_kybd_state;
|
||||
ssh2_NB_states userauth_kybd_state;
|
||||
unsigned char *userauth_kybd_data;
|
||||
size_t userauth_kybd_data_len;
|
||||
unsigned char *userauth_kybd_packet;
|
||||
@@ -856,7 +857,7 @@ struct _LIBSSH2_SESSION {
|
||||
struct packet_requirev_state userauth_kybd_packet_requirev_state;
|
||||
|
||||
/* State variables used in libssh2_channel_open_ex() */
|
||||
libssh2_nonblocking_states open_state;
|
||||
ssh2_NB_states open_state;
|
||||
struct packet_requirev_state open_packet_requirev_state;
|
||||
LIBSSH2_CHANNEL *open_channel;
|
||||
unsigned char *open_packet;
|
||||
@@ -866,21 +867,21 @@ struct _LIBSSH2_SESSION {
|
||||
uint32_t open_local_channel;
|
||||
|
||||
/* State variables used in libssh2_channel_direct_tcpip_ex() */
|
||||
libssh2_nonblocking_states direct_state;
|
||||
ssh2_NB_states direct_state;
|
||||
unsigned char *direct_message;
|
||||
size_t direct_host_len;
|
||||
size_t direct_shost_len;
|
||||
size_t direct_message_len;
|
||||
|
||||
/* State variables used in libssh2_channel_forward_listen_ex() */
|
||||
libssh2_nonblocking_states fwdLstn_state;
|
||||
ssh2_NB_states fwdLstn_state;
|
||||
unsigned char *fwdLstn_packet;
|
||||
uint32_t fwdLstn_host_len;
|
||||
uint32_t fwdLstn_packet_len;
|
||||
struct packet_requirev_state fwdLstn_packet_requirev_state;
|
||||
|
||||
/* State variables used in libssh2_publickey_init() */
|
||||
libssh2_nonblocking_states pkeyInit_state;
|
||||
ssh2_NB_states pkeyInit_state;
|
||||
LIBSSH2_PUBLICKEY *pkeyInit_pkey;
|
||||
LIBSSH2_CHANNEL *pkeyInit_channel;
|
||||
unsigned char *pkeyInit_data;
|
||||
@@ -889,8 +890,8 @@ struct _LIBSSH2_SESSION {
|
||||
unsigned char pkeyInit_buffer[19];
|
||||
size_t pkeyInit_buffer_sent; /* how much of buffer that has been sent */
|
||||
|
||||
/* State variables used in libssh2_packet_add() */
|
||||
libssh2_nonblocking_states packAdd_state;
|
||||
/* State variables used in ssh2_packet_add() */
|
||||
ssh2_NB_states packAdd_state;
|
||||
LIBSSH2_CHANNEL *packAdd_channelp; /* keeper of the channel during EAGAIN
|
||||
states */
|
||||
struct packet_queue_listener_state packAdd_Qlstn_state;
|
||||
@@ -898,14 +899,14 @@ struct _LIBSSH2_SESSION {
|
||||
struct packet_authagent_state packAdd_authagent_state;
|
||||
|
||||
/* State variables used in fullpacket() */
|
||||
libssh2_nonblocking_states fullpacket_state;
|
||||
ssh2_NB_states fullpacket_state;
|
||||
int fullpacket_macstate;
|
||||
size_t fullpacket_payload_len;
|
||||
int fullpacket_packet_type;
|
||||
uint32_t fullpacket_required_type;
|
||||
|
||||
/* State variables used in libssh2_sftp_init() */
|
||||
libssh2_nonblocking_states sftpInit_state;
|
||||
ssh2_NB_states sftpInit_state;
|
||||
LIBSSH2_SFTP *sftpInit_sftp;
|
||||
LIBSSH2_CHANNEL *sftpInit_channel;
|
||||
unsigned char sftpInit_buffer[9]; /* sftp_header(5){excludes request_id}
|
||||
@@ -914,10 +915,10 @@ struct _LIBSSH2_SESSION {
|
||||
sent */
|
||||
|
||||
/* State variables used in libssh2_scp_recv2() */
|
||||
libssh2_nonblocking_states scpRecv_state;
|
||||
ssh2_NB_states scpRecv_state;
|
||||
unsigned char *scpRecv_command;
|
||||
size_t scpRecv_command_len;
|
||||
unsigned char scpRecv_response[LIBSSH2_SCP_RESPONSE_BUFLEN];
|
||||
unsigned char scpRecv_response[SSH2_SCP_RESPONSE_BUFLEN];
|
||||
size_t scpRecv_response_len;
|
||||
long scpRecv_mode;
|
||||
libssh2_int64_t scpRecv_size;
|
||||
@@ -926,10 +927,10 @@ struct _LIBSSH2_SESSION {
|
||||
LIBSSH2_CHANNEL *scpRecv_channel;
|
||||
|
||||
/* State variables used in libssh2_scp_send_ex() */
|
||||
libssh2_nonblocking_states scpSend_state;
|
||||
ssh2_NB_states scpSend_state;
|
||||
unsigned char *scpSend_command;
|
||||
size_t scpSend_command_len;
|
||||
unsigned char scpSend_response[LIBSSH2_SCP_RESPONSE_BUFLEN];
|
||||
unsigned char scpSend_response[SSH2_SCP_RESPONSE_BUFLEN];
|
||||
size_t scpSend_response_len;
|
||||
LIBSSH2_CHANNEL *scpSend_channel;
|
||||
|
||||
@@ -943,22 +944,22 @@ struct _LIBSSH2_SESSION {
|
||||
};
|
||||
|
||||
/* session.state bits */
|
||||
#define LIBSSH2_STATE_INITIAL_KEX 0x00000001
|
||||
#define LIBSSH2_STATE_EXCHANGING_KEYS 0x00000002
|
||||
#define LIBSSH2_STATE_NEWKEYS 0x00000004
|
||||
#define LIBSSH2_STATE_AUTHENTICATED 0x00000008
|
||||
#define LIBSSH2_STATE_KEX_ACTIVE 0x00000010
|
||||
#define SSH2_STATE_INITIAL_KEX 0x00000001
|
||||
#define SSH2_STATE_EXCHANGING_KEYS 0x00000002
|
||||
#define SSH2_STATE_NEWKEYS 0x00000004
|
||||
#define SSH2_STATE_AUTHENTICATED 0x00000008
|
||||
#define SSH2_STATE_KEX_ACTIVE 0x00000010
|
||||
|
||||
/* session.flag helpers */
|
||||
#ifdef MSG_NOSIGNAL
|
||||
#define LIBSSH2_SOCKET_SEND_FLAGS(session) \
|
||||
#define SSH2_SOCKET_SEND_FLAGS(session) \
|
||||
((session)->flag.sigpipe ? 0 : MSG_NOSIGNAL)
|
||||
#define LIBSSH2_SOCKET_RECV_FLAGS(session) \
|
||||
#define SSH2_SOCKET_RECV_FLAGS(session) \
|
||||
((session)->flag.sigpipe ? 0 : MSG_NOSIGNAL)
|
||||
#else
|
||||
/* If MSG_NOSIGNAL is not defined we are SOL on blocking SIGPIPE */
|
||||
#define LIBSSH2_SOCKET_SEND_FLAGS(session) 0
|
||||
#define LIBSSH2_SOCKET_RECV_FLAGS(session) 0
|
||||
#define SSH2_SOCKET_SEND_FLAGS(session) 0
|
||||
#define SSH2_SOCKET_RECV_FLAGS(session) 0
|
||||
#endif
|
||||
|
||||
/* --------- */
|
||||
@@ -1032,27 +1033,27 @@ struct crypt_method {
|
||||
int firstlast);
|
||||
int (*dtor)(LIBSSH2_SESSION *session, void **abstract);
|
||||
|
||||
LIBSSH2_CIPHER_T(algo);
|
||||
SSH2_CIPHER_T(algo);
|
||||
};
|
||||
|
||||
/* Bit flags for struct crypt_method */
|
||||
|
||||
/* Crypto method has integrated message authentication */
|
||||
#define LIBSSH2_CRYPT_FLAG_INTEGRATED_MAC 1
|
||||
#define SSH2_CRYPT_FLAG_INTEGRATED_MAC 1
|
||||
/* Crypto method does not encrypt the packet length */
|
||||
#define LIBSSH2_CRYPT_FLAG_PKTLEN_AAD 2
|
||||
#define SSH2_CRYPT_FLAG_PKTLEN_AAD 2
|
||||
/* Crypto method must encrypt and decrypt entire messages */
|
||||
#define LIBSSH2_CRYPT_FLAG_REQUIRES_FULL_PACKET 4
|
||||
#define SSH2_CRYPT_FLAG_REQUIRES_FULL_PACKET 4
|
||||
|
||||
/* Convenience macros for accessing crypt flags */
|
||||
/* Local crypto flags */
|
||||
#define CRYPT_FLAG_L(session, flag) \
|
||||
((session)->local.crypt && \
|
||||
((session)->local.crypt->flags & LIBSSH2_CRYPT_FLAG_##flag))
|
||||
#define CRYPT_FLAG_L(session, flag) \
|
||||
((session)->local.crypt && \
|
||||
((session)->local.crypt->flags & SSH2_CRYPT_FLAG_##flag))
|
||||
/* Remote crypto flags */
|
||||
#define CRYPT_FLAG_R(session, flag) \
|
||||
((session)->remote.crypt && \
|
||||
((session)->remote.crypt->flags & LIBSSH2_CRYPT_FLAG_##flag))
|
||||
#define CRYPT_FLAG_R(session, flag) \
|
||||
((session)->remote.crypt && \
|
||||
((session)->remote.crypt->flags & SSH2_CRYPT_FLAG_##flag))
|
||||
|
||||
/* Values for firstlast */
|
||||
#define FIRST_BLOCK 1
|
||||
@@ -1085,28 +1086,28 @@ struct comp_method {
|
||||
};
|
||||
|
||||
#ifdef LIBSSH2DEBUG
|
||||
void _libssh2_debug_low(LIBSSH2_SESSION *session, int context,
|
||||
const char *format, ...) LIBSSH2_PRINTF(3, 4);
|
||||
#define _libssh2_debug(x) _libssh2_debug_low x
|
||||
void ssh2_deb_low(LIBSSH2_SESSION *session, int context,
|
||||
const char *format, ...) SSH2_PRINTF(3, 4);
|
||||
#define ssh2_deb(x) ssh2_deb_low x
|
||||
#else
|
||||
#define _libssh2_debug(x) do {} while(0)
|
||||
#define ssh2_deb(x) do {} while(0)
|
||||
#endif
|
||||
|
||||
#define LIBSSH2_SOCKET_UNKNOWN 1
|
||||
#define LIBSSH2_SOCKET_CONNECTED 0
|
||||
#define LIBSSH2_SOCKET_DISCONNECTED (-1)
|
||||
#define SSH2_SOCKET_UNKNOWN 1
|
||||
#define SSH2_SOCKET_CONNECTED 0
|
||||
#define SSH2_SOCKET_DISCONNECTED (-1)
|
||||
|
||||
/* Initial packet state, prior to MAC check */
|
||||
#define LIBSSH2_MAC_UNCONFIRMED 1
|
||||
#define SSH2_MAC_UNCONFIRMED 1
|
||||
/* When MAC type is "none" (proto initiation phase) all packets are deemed
|
||||
"confirmed" */
|
||||
#define LIBSSH2_MAC_CONFIRMED 0
|
||||
#define SSH2_MAC_CONFIRMED 0
|
||||
/* Something bad is going on */
|
||||
#define LIBSSH2_MAC_INVALID (-1)
|
||||
#define SSH2_MAC_INVALID (-1)
|
||||
|
||||
/* Flags for _libssh2_error_flags */
|
||||
/* Flags for ssh2_err_flags() */
|
||||
/* Error message is allocated on the heap */
|
||||
#define LIBSSH2_ERR_FLAG_DUP 1
|
||||
#define SSH2_ERR_FLAG_DUP 1
|
||||
|
||||
/* SSH Packet Types -- Defined by Internet draft */
|
||||
/* Transport Layer */
|
||||
@@ -1133,7 +1134,8 @@ void _libssh2_debug_low(LIBSSH2_SESSION *session, int context,
|
||||
#define SSH_MSG_KEX_DH_GEX_INIT 32
|
||||
#define SSH_MSG_KEX_DH_GEX_REPLY 33
|
||||
|
||||
/* ecdh */
|
||||
/* ECDH
|
||||
https://datatracker.ietf.org/doc/html/rfc9941 */
|
||||
#define SSH2_MSG_KEX_ECDH_INIT 30
|
||||
#define SSH2_MSG_KEX_ECDH_REPLY 31
|
||||
|
||||
@@ -1175,75 +1177,72 @@ void _libssh2_debug_low(LIBSSH2_SESSION *session, int context,
|
||||
#define SSH_OPEN_UNKNOWN_CHANNELTYPE 3
|
||||
#define SSH_OPEN_RESOURCE_SHORTAGE 4
|
||||
|
||||
ssize_t _libssh2_recv(libssh2_socket_t socket, void *buffer,
|
||||
size_t length, int flags, void **abstract);
|
||||
ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer,
|
||||
size_t length, int flags, void **abstract);
|
||||
ssize_t ssh2_recv(libssh2_socket_t socket, void *buffer,
|
||||
size_t length, int flags, void **abstract);
|
||||
ssize_t ssh2_send(libssh2_socket_t socket, const void *buffer,
|
||||
size_t length, int flags, void **abstract);
|
||||
|
||||
#define LIBSSH2_DEFAULT_READ_TIMEOUT 60 /* generic timeout in seconds used when
|
||||
waiting for more data to arrive */
|
||||
int ssh2_kex_exchange(LIBSSH2_SESSION *session, int reexchange,
|
||||
struct key_exchange_state *key_state);
|
||||
|
||||
int _libssh2_kex_exchange(LIBSSH2_SESSION *session, int reexchange,
|
||||
struct key_exchange_state *key_state);
|
||||
|
||||
unsigned char *_libssh2_kex_agree_instr(unsigned char *haystack,
|
||||
size_t haystack_len,
|
||||
const unsigned char *needle,
|
||||
size_t needle_len);
|
||||
unsigned char *ssh2_kex_agree_instr(unsigned char *haystack,
|
||||
size_t haystack_len,
|
||||
const unsigned char *needle,
|
||||
size_t needle_len);
|
||||
|
||||
/* Let crypt.c/hostkey.c expose their method structs */
|
||||
const struct crypt_method **libssh2_crypt_methods(void);
|
||||
const struct hostkey_method **libssh2_hostkey_methods(void);
|
||||
const struct crypt_method **ssh2_crypt_methods(void);
|
||||
const struct hostkey_method **ssh2_hostkey_methods(void);
|
||||
|
||||
int _libssh2_bcrypt_pbkdf(const char *pass,
|
||||
size_t passlen,
|
||||
const uint8_t *salt,
|
||||
size_t saltlen,
|
||||
uint8_t *key,
|
||||
size_t keylen,
|
||||
unsigned int rounds);
|
||||
int ssh2_bcrypt_pbkdf(const char *pass,
|
||||
size_t passlen,
|
||||
const uint8_t *salt,
|
||||
size_t saltlen,
|
||||
uint8_t *key,
|
||||
size_t keylen,
|
||||
unsigned int rounds);
|
||||
|
||||
/* pem.c */
|
||||
int _libssh2_pem_parse(LIBSSH2_SESSION *session,
|
||||
const char *headerbegin,
|
||||
const char *headerend,
|
||||
const unsigned char *passphrase,
|
||||
FILE *fp, unsigned char **data, size_t *datalen);
|
||||
int _libssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
const char *headerbegin,
|
||||
const char *headerend,
|
||||
const unsigned char *passphrase,
|
||||
const char *filedata, size_t filedata_len,
|
||||
unsigned char **data, size_t *datalen);
|
||||
int ssh2_pem_parse(LIBSSH2_SESSION *session,
|
||||
const char *headerbegin,
|
||||
const char *headerend,
|
||||
const unsigned char *passphrase,
|
||||
FILE *fp, unsigned char **data, size_t *datalen);
|
||||
int ssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
const char *headerbegin,
|
||||
const char *headerend,
|
||||
const unsigned char *passphrase,
|
||||
const char *filedata, size_t filedata_len,
|
||||
unsigned char **data, size_t *datalen);
|
||||
/* OpenSSL keys */
|
||||
int _libssh2_openssh_pem_parse(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
FILE *fp, struct string_buf **decrypted_buf);
|
||||
int _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
struct string_buf **decrypted_buf);
|
||||
int ssh2_openssh_pem_parse(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
FILE *fp, struct string_buf **decrypted_buf);
|
||||
int ssh2_openssh_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
struct string_buf **decrypted_buf);
|
||||
|
||||
int _libssh2_pem_decode_sequence(unsigned char **data, size_t *datalen);
|
||||
int _libssh2_pem_decode_integer(unsigned char **data, size_t *datalen,
|
||||
unsigned char **i, unsigned int *ilen);
|
||||
int ssh2_pem_decode_sequence(unsigned char **data, size_t *datalen);
|
||||
int ssh2_pem_decode_integer(unsigned char **data, size_t *datalen,
|
||||
unsigned char **i, unsigned int *ilen);
|
||||
|
||||
/* global.c */
|
||||
void _libssh2_init_if_needed(void);
|
||||
void ssh2_init_if_needed(void);
|
||||
|
||||
/* Utility function for certificate auth */
|
||||
size_t plain_method(char *method, size_t method_len);
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||
#define SSH2_ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||
|
||||
/* define to output the libssh2_int64_t type in a *printf() */
|
||||
#if defined(__MINGW32__) || (defined(_MSC_VER) && (_MSC_VER >= 1800))
|
||||
#define LIBSSH2_INT64_T_FORMAT PRId64
|
||||
#define SSH2_INT64_T_FORMAT PRId64
|
||||
#elif defined(_WIN32)
|
||||
#define LIBSSH2_INT64_T_FORMAT "I64d"
|
||||
#define SSH2_INT64_T_FORMAT "I64d"
|
||||
#else
|
||||
#define LIBSSH2_INT64_T_FORMAT "lld"
|
||||
#define SSH2_INT64_T_FORMAT "lld"
|
||||
#endif
|
||||
|
||||
/* In Windows the default file mode is text but an application can override it.
|
||||
|
||||
97
src/mac.c
97
src/mac.c
@@ -93,7 +93,7 @@ static int mac_method_common_init(LIBSSH2_SESSION *session, unsigned char *key,
|
||||
static int mac_method_common_dtor(LIBSSH2_SESSION *session, void **abstract)
|
||||
{
|
||||
if(*abstract) {
|
||||
LIBSSH2_FREE(session, *abstract);
|
||||
SSH2_FREE(session, *abstract);
|
||||
}
|
||||
*abstract = NULL;
|
||||
|
||||
@@ -111,23 +111,23 @@ static int mac_method_hmac_sha2_512_hash(LIBSSH2_SESSION *session,
|
||||
const unsigned char *addtl,
|
||||
size_t addtl_len, void **abstract)
|
||||
{
|
||||
libssh2_hmac_ctx ctx;
|
||||
ssh2_hmac_ctx ctx;
|
||||
unsigned char seqno_buf[4];
|
||||
int res;
|
||||
(void)session;
|
||||
|
||||
_libssh2_htonu32(seqno_buf, seqno);
|
||||
ssh2_htonu32(seqno_buf, seqno);
|
||||
|
||||
if(!_libssh2_hmac_ctx_init(&ctx))
|
||||
if(!ssh2_hmac_ctx_init(&ctx))
|
||||
return 1;
|
||||
res = _libssh2_hmac_sha512_init(&ctx, *abstract, 64) &&
|
||||
_libssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
_libssh2_hmac_update(&ctx, packet, packet_len);
|
||||
res = ssh2_hmac_sha512_init(&ctx, *abstract, 64) &&
|
||||
ssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
ssh2_hmac_update(&ctx, packet, packet_len);
|
||||
if(res && addtl && addtl_len)
|
||||
res = _libssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
res = ssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
if(res)
|
||||
res = _libssh2_hmac_final(&ctx, buf);
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
res = ssh2_hmac_final(&ctx, buf);
|
||||
ssh2_hmac_cleanup(&ctx);
|
||||
|
||||
return !res;
|
||||
}
|
||||
@@ -165,23 +165,23 @@ static int mac_method_hmac_sha2_256_hash(LIBSSH2_SESSION *session,
|
||||
const unsigned char *addtl,
|
||||
size_t addtl_len, void **abstract)
|
||||
{
|
||||
libssh2_hmac_ctx ctx;
|
||||
ssh2_hmac_ctx ctx;
|
||||
unsigned char seqno_buf[4];
|
||||
int res;
|
||||
(void)session;
|
||||
|
||||
_libssh2_htonu32(seqno_buf, seqno);
|
||||
ssh2_htonu32(seqno_buf, seqno);
|
||||
|
||||
if(!_libssh2_hmac_ctx_init(&ctx))
|
||||
if(!ssh2_hmac_ctx_init(&ctx))
|
||||
return 1;
|
||||
res = _libssh2_hmac_sha256_init(&ctx, *abstract, 32) &&
|
||||
_libssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
_libssh2_hmac_update(&ctx, packet, packet_len);
|
||||
res = ssh2_hmac_sha256_init(&ctx, *abstract, 32) &&
|
||||
ssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
ssh2_hmac_update(&ctx, packet, packet_len);
|
||||
if(res && addtl && addtl_len)
|
||||
res = _libssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
res = ssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
if(res)
|
||||
res = _libssh2_hmac_final(&ctx, buf);
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
res = ssh2_hmac_final(&ctx, buf);
|
||||
ssh2_hmac_cleanup(&ctx);
|
||||
|
||||
return !res;
|
||||
}
|
||||
@@ -218,23 +218,23 @@ static int mac_method_hmac_sha1_hash(LIBSSH2_SESSION *session,
|
||||
const unsigned char *addtl,
|
||||
size_t addtl_len, void **abstract)
|
||||
{
|
||||
libssh2_hmac_ctx ctx;
|
||||
ssh2_hmac_ctx ctx;
|
||||
unsigned char seqno_buf[4];
|
||||
int res;
|
||||
(void)session;
|
||||
|
||||
_libssh2_htonu32(seqno_buf, seqno);
|
||||
ssh2_htonu32(seqno_buf, seqno);
|
||||
|
||||
if(!_libssh2_hmac_ctx_init(&ctx))
|
||||
if(!ssh2_hmac_ctx_init(&ctx))
|
||||
return 1;
|
||||
res = _libssh2_hmac_sha1_init(&ctx, *abstract, 20) &&
|
||||
_libssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
_libssh2_hmac_update(&ctx, packet, packet_len);
|
||||
res = ssh2_hmac_sha1_init(&ctx, *abstract, 20) &&
|
||||
ssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
ssh2_hmac_update(&ctx, packet, packet_len);
|
||||
if(res && addtl && addtl_len)
|
||||
res = _libssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
res = ssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
if(res)
|
||||
res = _libssh2_hmac_final(&ctx, buf);
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
res = ssh2_hmac_final(&ctx, buf);
|
||||
ssh2_hmac_cleanup(&ctx);
|
||||
|
||||
return !res;
|
||||
}
|
||||
@@ -300,23 +300,23 @@ static int mac_method_hmac_md5_hash(LIBSSH2_SESSION *session,
|
||||
const unsigned char *addtl,
|
||||
size_t addtl_len, void **abstract)
|
||||
{
|
||||
libssh2_hmac_ctx ctx;
|
||||
ssh2_hmac_ctx ctx;
|
||||
unsigned char seqno_buf[4];
|
||||
int res;
|
||||
(void)session;
|
||||
|
||||
_libssh2_htonu32(seqno_buf, seqno);
|
||||
ssh2_htonu32(seqno_buf, seqno);
|
||||
|
||||
if(!_libssh2_hmac_ctx_init(&ctx))
|
||||
if(!ssh2_hmac_ctx_init(&ctx))
|
||||
return 1;
|
||||
res = _libssh2_hmac_md5_init(&ctx, *abstract, 16) &&
|
||||
_libssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
_libssh2_hmac_update(&ctx, packet, packet_len);
|
||||
res = ssh2_hmac_md5_init(&ctx, *abstract, 16) &&
|
||||
ssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
ssh2_hmac_update(&ctx, packet, packet_len);
|
||||
if(res && addtl && addtl_len)
|
||||
res = _libssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
res = ssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
if(res)
|
||||
res = _libssh2_hmac_final(&ctx, buf);
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
res = ssh2_hmac_final(&ctx, buf);
|
||||
ssh2_hmac_cleanup(&ctx);
|
||||
|
||||
return !res;
|
||||
}
|
||||
@@ -373,23 +373,23 @@ static int mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION *session,
|
||||
const unsigned char *addtl,
|
||||
size_t addtl_len, void **abstract)
|
||||
{
|
||||
libssh2_hmac_ctx ctx;
|
||||
ssh2_hmac_ctx ctx;
|
||||
unsigned char seqno_buf[4];
|
||||
int res;
|
||||
(void)session;
|
||||
|
||||
_libssh2_htonu32(seqno_buf, seqno);
|
||||
ssh2_htonu32(seqno_buf, seqno);
|
||||
|
||||
if(!_libssh2_hmac_ctx_init(&ctx))
|
||||
if(!ssh2_hmac_ctx_init(&ctx))
|
||||
return 1;
|
||||
res = _libssh2_hmac_ripemd160_init(&ctx, *abstract, 20) &&
|
||||
_libssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
_libssh2_hmac_update(&ctx, packet, packet_len);
|
||||
res = ssh2_hmac_ripemd160_init(&ctx, *abstract, 20) &&
|
||||
ssh2_hmac_update(&ctx, seqno_buf, 4) &&
|
||||
ssh2_hmac_update(&ctx, packet, packet_len);
|
||||
if(res && addtl && addtl_len)
|
||||
res = _libssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
res = ssh2_hmac_update(&ctx, addtl, addtl_len);
|
||||
if(res)
|
||||
res = _libssh2_hmac_final(&ctx, buf);
|
||||
_libssh2_hmac_cleanup(&ctx);
|
||||
res = ssh2_hmac_final(&ctx, buf);
|
||||
ssh2_hmac_cleanup(&ctx);
|
||||
|
||||
return !res;
|
||||
}
|
||||
@@ -441,7 +441,7 @@ static const struct mac_method *mac_methods[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
const struct mac_method **_libssh2_mac_methods(void)
|
||||
const struct mac_method **ssh2_mac_methods(void)
|
||||
{
|
||||
return mac_methods;
|
||||
}
|
||||
@@ -498,8 +498,7 @@ static const struct mac_method mac_method_hmac_aesgcm = {
|
||||
|
||||
/* See if the negotiated crypto method has its own authentication scheme that
|
||||
* obviates the need for a separate negotiated hmac method */
|
||||
const struct mac_method *_libssh2_mac_override(
|
||||
const struct crypt_method *crypt)
|
||||
const struct mac_method *ssh2_mac_override(const struct crypt_method *crypt)
|
||||
{
|
||||
#if LIBSSH2_AES_GCM
|
||||
if(!strcmp(crypt->name, "aes256-gcm@openssh.com") ||
|
||||
|
||||
@@ -62,8 +62,7 @@ struct mac_method {
|
||||
int etm; /* encrypt-then-mac */
|
||||
};
|
||||
|
||||
const struct mac_method **_libssh2_mac_methods(void);
|
||||
const struct mac_method *_libssh2_mac_override(
|
||||
const struct crypt_method *crypt);
|
||||
const struct mac_method **ssh2_mac_methods(void);
|
||||
const struct mac_method *ssh2_mac_override(const struct crypt_method *crypt);
|
||||
|
||||
#endif /* LIBSSH2_MAC_H */
|
||||
|
||||
482
src/mbedtls.c
482
src/mbedtls.c
File diff suppressed because it is too large
Load Diff
373
src/mbedtls.h
373
src/mbedtls.h
@@ -39,7 +39,7 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#define LIBSSH2_CRYPTO_ENGINE libssh2_mbedtls
|
||||
#define SSH2_CRYPTO_ENGINE libssh2_mbedtls
|
||||
|
||||
#include <mbedtls/version.h>
|
||||
#include <mbedtls/platform.h>
|
||||
@@ -110,83 +110,83 @@
|
||||
* mbedTLS backend: Generic functions
|
||||
*/
|
||||
|
||||
#define libssh2_crypto_init() _libssh2_mbedtls_init()
|
||||
#define libssh2_crypto_exit() _libssh2_mbedtls_free()
|
||||
#define ssh2_crypto_init() ssh2_mbed_init()
|
||||
#define ssh2_crypto_exit() ssh2_mbed_free()
|
||||
|
||||
#define _libssh2_random(buf, len) _libssh2_mbedtls_random(buf, len)
|
||||
#define ssh2_random(buf, len) ssh2_mbed_random(buf, len)
|
||||
|
||||
#define libssh2_prepare_iovec(vec, len) /* Empty. */
|
||||
#define ssh2_prepare_iovec(vec, len) /* Empty. */
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* mbedTLS backend: HMAC functions
|
||||
*/
|
||||
|
||||
#define libssh2_hmac_ctx mbedtls_md_context_t
|
||||
#define ssh2_hmac_ctx mbedtls_md_context_t
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* mbedTLS backend: SHA1 functions
|
||||
*/
|
||||
|
||||
#define libssh2_sha1_ctx mbedtls_md_context_t
|
||||
#define ssh2_sha1_ctx mbedtls_md_context_t
|
||||
|
||||
#define libssh2_sha1_init(pctx) \
|
||||
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA1, NULL, 0)
|
||||
#define libssh2_sha1_update(ctx, data, datalen) \
|
||||
#define ssh2_sha1_init(pctx) \
|
||||
ssh2_mbed_hash_init(pctx, MBEDTLS_MD_SHA1, NULL, 0)
|
||||
#define ssh2_sha1_update(ctx, data, datalen) \
|
||||
(mbedtls_md_update(&(ctx), (const unsigned char *)(data), datalen) == 0)
|
||||
#define libssh2_sha1_final(ctx, hash) \
|
||||
_libssh2_mbedtls_hash_final(&(ctx), hash)
|
||||
#define libssh2_sha1(data, datalen, hash) \
|
||||
_libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA1, hash)
|
||||
#define ssh2_sha1_final(ctx, hash) \
|
||||
ssh2_mbed_hash_final(&(ctx), hash)
|
||||
#define ssh2_sha1(data, datalen, hash) \
|
||||
ssh2_mbed_hash(data, datalen, MBEDTLS_MD_SHA1, hash)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* mbedTLS backend: SHA256 functions
|
||||
*/
|
||||
|
||||
#define libssh2_sha256_ctx mbedtls_md_context_t
|
||||
#define ssh2_sha256_ctx mbedtls_md_context_t
|
||||
|
||||
#define libssh2_sha256_init(pctx) \
|
||||
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA256, NULL, 0)
|
||||
#define libssh2_sha256_update(ctx, data, datalen) \
|
||||
#define ssh2_sha256_init(pctx) \
|
||||
ssh2_mbed_hash_init(pctx, MBEDTLS_MD_SHA256, NULL, 0)
|
||||
#define ssh2_sha256_update(ctx, data, datalen) \
|
||||
(mbedtls_md_update(&(ctx), (const unsigned char *)(data), datalen) == 0)
|
||||
#define libssh2_sha256_final(ctx, hash) \
|
||||
_libssh2_mbedtls_hash_final(&(ctx), hash)
|
||||
#define libssh2_sha256(data, datalen, hash) \
|
||||
_libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA256, hash)
|
||||
#define ssh2_sha256_final(ctx, hash) \
|
||||
ssh2_mbed_hash_final(&(ctx), hash)
|
||||
#define ssh2_sha256(data, datalen, hash) \
|
||||
ssh2_mbed_hash(data, datalen, MBEDTLS_MD_SHA256, hash)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* mbedTLS backend: SHA384 functions
|
||||
*/
|
||||
|
||||
#define libssh2_sha384_ctx mbedtls_md_context_t
|
||||
#define ssh2_sha384_ctx mbedtls_md_context_t
|
||||
|
||||
#define libssh2_sha384_init(pctx) \
|
||||
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA384, NULL, 0)
|
||||
#define libssh2_sha384_update(ctx, data, datalen) \
|
||||
#define ssh2_sha384_init(pctx) \
|
||||
ssh2_mbed_hash_init(pctx, MBEDTLS_MD_SHA384, NULL, 0)
|
||||
#define ssh2_sha384_update(ctx, data, datalen) \
|
||||
(mbedtls_md_update(&(ctx), (const unsigned char *)(data), datalen) == 0)
|
||||
#define libssh2_sha384_final(ctx, hash) \
|
||||
_libssh2_mbedtls_hash_final(&(ctx), hash)
|
||||
#define libssh2_sha384(data, datalen, hash) \
|
||||
_libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA384, hash)
|
||||
#define ssh2_sha384_final(ctx, hash) \
|
||||
ssh2_mbed_hash_final(&(ctx), hash)
|
||||
#define ssh2_sha384(data, datalen, hash) \
|
||||
ssh2_mbed_hash(data, datalen, MBEDTLS_MD_SHA384, hash)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* mbedTLS backend: SHA512 functions
|
||||
*/
|
||||
|
||||
#define libssh2_sha512_ctx mbedtls_md_context_t
|
||||
#define ssh2_sha512_ctx mbedtls_md_context_t
|
||||
|
||||
#define libssh2_sha512_init(pctx) \
|
||||
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_SHA512, NULL, 0)
|
||||
#define libssh2_sha512_update(ctx, data, datalen) \
|
||||
#define ssh2_sha512_init(pctx) \
|
||||
ssh2_mbed_hash_init(pctx, MBEDTLS_MD_SHA512, NULL, 0)
|
||||
#define ssh2_sha512_update(ctx, data, datalen) \
|
||||
(mbedtls_md_update(&(ctx), (const unsigned char *)(data), datalen) == 0)
|
||||
#define libssh2_sha512_final(ctx, hash) \
|
||||
_libssh2_mbedtls_hash_final(&(ctx), hash)
|
||||
#define libssh2_sha512(data, datalen, hash) \
|
||||
_libssh2_mbedtls_hash(data, datalen, MBEDTLS_MD_SHA512, hash)
|
||||
#define ssh2_sha512_final(ctx, hash) \
|
||||
ssh2_mbed_hash_final(&(ctx), hash)
|
||||
#define ssh2_sha512(data, datalen, hash) \
|
||||
ssh2_mbed_hash(data, datalen, MBEDTLS_MD_SHA512, hash)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
@@ -194,14 +194,14 @@
|
||||
*/
|
||||
|
||||
#if LIBSSH2_MD5 || LIBSSH2_MD5_PEM
|
||||
#define libssh2_md5_ctx mbedtls_md_context_t
|
||||
#define ssh2_md5_ctx mbedtls_md_context_t
|
||||
|
||||
#define libssh2_md5_init(pctx) \
|
||||
_libssh2_mbedtls_hash_init(pctx, MBEDTLS_MD_MD5, NULL, 0)
|
||||
#define libssh2_md5_update(ctx, data, datalen) \
|
||||
#define ssh2_md5_init(pctx) \
|
||||
ssh2_mbed_hash_init(pctx, MBEDTLS_MD_MD5, NULL, 0)
|
||||
#define ssh2_md5_update(ctx, data, datalen) \
|
||||
(mbedtls_md_update(&(ctx), (const unsigned char *)(data), datalen) == 0)
|
||||
#define libssh2_md5_final(ctx, hash) \
|
||||
_libssh2_mbedtls_hash_final(&(ctx), hash)
|
||||
#define ssh2_md5_final(ctx, hash) \
|
||||
ssh2_mbed_hash_final(&(ctx), hash)
|
||||
#endif
|
||||
|
||||
/*******************************************************************/
|
||||
@@ -209,37 +209,29 @@
|
||||
* mbedTLS backend: RSA functions
|
||||
*/
|
||||
|
||||
#define libssh2_rsa_ctx mbedtls_rsa_context
|
||||
|
||||
#define _libssh2_rsa_new(rsactx, e, e_len, n, n_len, \
|
||||
d, d_len, p, p_len, q, q_len, \
|
||||
e1, e1_len, e2, e2_len, c, c_len) \
|
||||
_libssh2_mbedtls_rsa_new(rsactx, e, e_len, n, n_len, \
|
||||
d, d_len, p, p_len, q, q_len, \
|
||||
e1, e1_len, e2, e2_len, c, c_len)
|
||||
|
||||
#define _libssh2_rsa_new_private(rsactx, s, filename, passphrase) \
|
||||
_libssh2_mbedtls_rsa_new_private(rsactx, s, filename, passphrase)
|
||||
|
||||
#define _libssh2_rsa_new_private_frommemory(rsactx, s, filedata, \
|
||||
filedata_len, passphrase) \
|
||||
_libssh2_mbedtls_rsa_new_private_frommemory(rsactx, s, filedata, \
|
||||
filedata_len, passphrase)
|
||||
|
||||
#define _libssh2_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) \
|
||||
_libssh2_mbedtls_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len)
|
||||
|
||||
#define _libssh2_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len) \
|
||||
_libssh2_mbedtls_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len)
|
||||
|
||||
#define _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) \
|
||||
_libssh2_mbedtls_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len)
|
||||
|
||||
#define _libssh2_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) \
|
||||
_libssh2_mbedtls_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len)
|
||||
|
||||
#define _libssh2_rsa_free(rsactx) \
|
||||
_libssh2_mbedtls_rsa_free(rsactx)
|
||||
#define ssh2_rsa_ctx mbedtls_rsa_context
|
||||
#define ssh2_rsa_new(rsactx, e, e_len, n, n_len, \
|
||||
d, d_len, p, p_len, q, q_len, \
|
||||
e1, e1_len, e2, e2_len, c, c_len) \
|
||||
ssh2_mbed_rsa_new(rsactx, e, e_len, n, n_len, \
|
||||
d, d_len, p, p_len, q, q_len, \
|
||||
e1, e1_len, e2, e2_len, c, c_len)
|
||||
#define ssh2_rsa_new_private(rsactx, s, filename, passphrase) \
|
||||
ssh2_mbed_rsa_new_private(rsactx, s, filename, passphrase)
|
||||
#define ssh2_rsa_new_private_frommemory(rsactx, s, filedata, \
|
||||
filedata_len, passphrase) \
|
||||
ssh2_mbed_rsa_new_private_frommemory(rsactx, s, filedata, \
|
||||
filedata_len, passphrase)
|
||||
#define ssh2_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) \
|
||||
ssh2_mbed_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len)
|
||||
#define ssh2_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len) \
|
||||
ssh2_mbed_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len)
|
||||
#define ssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) \
|
||||
ssh2_mbed_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len)
|
||||
#define ssh2_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) \
|
||||
ssh2_mbed_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len)
|
||||
#define ssh2_rsa_free(rsactx) \
|
||||
ssh2_mbed_rsa_free(rsactx)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
@@ -250,25 +242,25 @@
|
||||
|
||||
typedef enum {
|
||||
#ifdef MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
LIBSSH2_EC_CURVE_NISTP256 = MBEDTLS_ECP_DP_SECP256R1,
|
||||
SSH2_EC_CURVE_NISTP256 = MBEDTLS_ECP_DP_SECP256R1,
|
||||
#else
|
||||
LIBSSH2_EC_CURVE_NISTP256 = MBEDTLS_ECP_DP_NONE,
|
||||
SSH2_EC_CURVE_NISTP256 = MBEDTLS_ECP_DP_NONE,
|
||||
#endif
|
||||
#ifdef MBEDTLS_ECP_DP_SECP384R1_ENABLED
|
||||
LIBSSH2_EC_CURVE_NISTP384 = MBEDTLS_ECP_DP_SECP384R1,
|
||||
SSH2_EC_CURVE_NISTP384 = MBEDTLS_ECP_DP_SECP384R1,
|
||||
#else
|
||||
LIBSSH2_EC_CURVE_NISTP384 = MBEDTLS_ECP_DP_NONE,
|
||||
SSH2_EC_CURVE_NISTP384 = MBEDTLS_ECP_DP_NONE,
|
||||
#endif
|
||||
#ifdef MBEDTLS_ECP_DP_SECP521R1_ENABLED
|
||||
LIBSSH2_EC_CURVE_NISTP521 = MBEDTLS_ECP_DP_SECP521R1
|
||||
SSH2_EC_CURVE_NISTP521 = MBEDTLS_ECP_DP_SECP521R1
|
||||
#else
|
||||
LIBSSH2_EC_CURVE_NISTP521 = MBEDTLS_ECP_DP_NONE,
|
||||
SSH2_EC_CURVE_NISTP521 = MBEDTLS_ECP_DP_NONE,
|
||||
#endif
|
||||
} libssh2_curve_type;
|
||||
} ssh2_curve_type;
|
||||
|
||||
# define libssh2_ec_key mbedtls_ecp_keypair
|
||||
# define ssh2_ec_key mbedtls_ecp_keypair
|
||||
#else
|
||||
# define libssh2_ec_key void
|
||||
# define ssh2_ec_key void
|
||||
#endif /* LIBSSH2_ECDSA */
|
||||
|
||||
/*******************************************************************/
|
||||
@@ -278,38 +270,29 @@ typedef enum {
|
||||
|
||||
#if LIBSSH2_ECDSA
|
||||
|
||||
#define libssh2_ecdsa_ctx mbedtls_ecdsa_context
|
||||
|
||||
#define _libssh2_ecdsa_create_key(session, privkey, pubkey_octal, \
|
||||
pubkey_octal_len, curve) \
|
||||
_libssh2_mbedtls_ecdsa_create_key(session, privkey, pubkey_octal, \
|
||||
pubkey_octal_len, curve)
|
||||
|
||||
#define _libssh2_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve) \
|
||||
_libssh2_mbedtls_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve)
|
||||
|
||||
#define _libssh2_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len) \
|
||||
_libssh2_mbedtls_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len)
|
||||
|
||||
#define _libssh2_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len) \
|
||||
_libssh2_mbedtls_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len)
|
||||
|
||||
#define _libssh2_ecdsa_new_private(ctx, session, filename, passphrase) \
|
||||
_libssh2_mbedtls_ecdsa_new_private(ctx, session, filename, passphrase)
|
||||
|
||||
#define _libssh2_ecdsa_new_private_frommemory(ctx, session, filedata, \
|
||||
filedata_len, passphrase) \
|
||||
_libssh2_mbedtls_ecdsa_new_private_frommemory(ctx, session, filedata, \
|
||||
filedata_len, passphrase)
|
||||
|
||||
#define _libssh2_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len) \
|
||||
_libssh2_mbedtls_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len)
|
||||
|
||||
#define _libssh2_ecdsa_get_curve_type(ctx) \
|
||||
_libssh2_mbedtls_ecdsa_get_curve_type(ctx)
|
||||
|
||||
#define _libssh2_ecdsa_free(ctx) \
|
||||
_libssh2_mbedtls_ecdsa_free(ctx)
|
||||
#define ssh2_ecdsa_ctx mbedtls_ecdsa_context
|
||||
#define ssh2_ecdsa_create_key(session, privkey, pubkey_octal, \
|
||||
pubkey_octal_len, curve) \
|
||||
ssh2_mbed_ecdsa_create_key(session, privkey, pubkey_octal, \
|
||||
pubkey_octal_len, curve)
|
||||
#define ssh2_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve) \
|
||||
ssh2_mbed_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve)
|
||||
#define ssh2_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len) \
|
||||
ssh2_mbed_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len)
|
||||
#define ssh2_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len) \
|
||||
ssh2_mbed_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len)
|
||||
#define ssh2_ecdsa_new_private(ctx, session, filename, passphrase) \
|
||||
ssh2_mbed_ecdsa_new_private(ctx, session, filename, passphrase)
|
||||
#define ssh2_ecdsa_new_private_frommemory(ctx, session, filedata, \
|
||||
filedata_len, passphrase) \
|
||||
ssh2_mbed_ecdsa_new_private_frommemory(ctx, session, filedata, \
|
||||
filedata_len, passphrase)
|
||||
#define ssh2_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len) \
|
||||
ssh2_mbed_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len)
|
||||
#define ssh2_ecdsa_get_curve_type(ctx) \
|
||||
ssh2_mbed_ecdsa_get_curve_type(ctx)
|
||||
#define ssh2_ecdsa_free(ctx) \
|
||||
ssh2_mbed_ecdsa_free(ctx)
|
||||
|
||||
#endif /* LIBSSH2_ECDSA */
|
||||
|
||||
@@ -318,80 +301,78 @@ typedef enum {
|
||||
* mbedTLS backend: Key functions
|
||||
*/
|
||||
|
||||
#define _libssh2_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) \
|
||||
_libssh2_mbedtls_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw)
|
||||
#define _libssh2_pub_priv_keyfilememory(s, m, m_len, p, p_len, \
|
||||
pk, pk_len, pw) \
|
||||
_libssh2_mbedtls_pub_priv_keyfilememory(s, m, m_len, p, p_len, \
|
||||
pk, pk_len, pw)
|
||||
#define _libssh2_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \
|
||||
f, kh, kh_len, pk, pk_len, pw) \
|
||||
_libssh2_mbedtls_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \
|
||||
f, kh, kh_len, pk, pk_len, pw)
|
||||
#define ssh2_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) \
|
||||
ssh2_mbed_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw)
|
||||
#define ssh2_pub_priv_keyfilememory(s, m, m_len, p, p_len, pk, pk_len, pw) \
|
||||
ssh2_mbed_pub_priv_keyfilememory(s, m, m_len, p, p_len, pk, pk_len, pw)
|
||||
#define ssh2_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \
|
||||
f, kh, kh_len, pk, pk_len, pw) \
|
||||
ssh2_mbed_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \
|
||||
f, kh, kh_len, pk, pk_len, pw)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* mbedTLS backend: Cipher Context structure
|
||||
*/
|
||||
|
||||
#define libssh2_cipher_ctx mbedtls_cipher_context_t
|
||||
#define ssh2_cipher_ctx mbedtls_cipher_context_t
|
||||
|
||||
#define LIBSSH2_CIPHER_T(algo) mbedtls_cipher_type_t algo
|
||||
#define SSH2_CIPHER_T(algo) mbedtls_cipher_type_t algo
|
||||
|
||||
#define libssh2_cipher_aes256ctr MBEDTLS_CIPHER_AES_256_CTR
|
||||
#define libssh2_cipher_aes192ctr MBEDTLS_CIPHER_AES_192_CTR
|
||||
#define libssh2_cipher_aes128ctr MBEDTLS_CIPHER_AES_128_CTR
|
||||
#define libssh2_cipher_aes256 MBEDTLS_CIPHER_AES_256_CBC
|
||||
#define libssh2_cipher_aes192 MBEDTLS_CIPHER_AES_192_CBC
|
||||
#define libssh2_cipher_aes128 MBEDTLS_CIPHER_AES_128_CBC
|
||||
#define ssh2_cipher_aes256ctr MBEDTLS_CIPHER_AES_256_CTR
|
||||
#define ssh2_cipher_aes192ctr MBEDTLS_CIPHER_AES_192_CTR
|
||||
#define ssh2_cipher_aes128ctr MBEDTLS_CIPHER_AES_128_CTR
|
||||
#define ssh2_cipher_aes256 MBEDTLS_CIPHER_AES_256_CBC
|
||||
#define ssh2_cipher_aes192 MBEDTLS_CIPHER_AES_192_CBC
|
||||
#define ssh2_cipher_aes128 MBEDTLS_CIPHER_AES_128_CBC
|
||||
#ifdef MBEDTLS_CIPHER_BLOWFISH_CBC
|
||||
#define libssh2_cipher_blowfish MBEDTLS_CIPHER_BLOWFISH_CBC
|
||||
#define ssh2_cipher_blowfish MBEDTLS_CIPHER_BLOWFISH_CBC
|
||||
#endif
|
||||
#ifdef MBEDTLS_CIPHER_ARC4_128
|
||||
#define libssh2_cipher_arcfour MBEDTLS_CIPHER_ARC4_128
|
||||
#define ssh2_cipher_arcfour MBEDTLS_CIPHER_ARC4_128
|
||||
#endif
|
||||
#define libssh2_cipher_3des MBEDTLS_CIPHER_DES_EDE3_CBC
|
||||
#define libssh2_cipher_chacha20 MBEDTLS_CIPHER_CHACHA20_POLY1305
|
||||
#define ssh2_cipher_3des MBEDTLS_CIPHER_DES_EDE3_CBC
|
||||
#define ssh2_cipher_chacha20 MBEDTLS_CIPHER_CHACHA20_POLY1305
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* mbedTLS backend: Cipher functions
|
||||
*/
|
||||
|
||||
#define _libssh2_cipher_init(ctx, type, iv, secret, encrypt) \
|
||||
_libssh2_mbedtls_cipher_init(ctx, type, iv, secret, encrypt)
|
||||
#define _libssh2_cipher_crypt(ctx, type, encrypt, block, blocklen, fl) \
|
||||
_libssh2_mbedtls_cipher_crypt(ctx, type, encrypt, block, blocklen, fl)
|
||||
#define _libssh2_cipher_dtor(ctx) \
|
||||
_libssh2_mbedtls_cipher_dtor(ctx)
|
||||
#define ssh2_cipher_init(ctx, type, iv, secret, encrypt) \
|
||||
ssh2_mbed_cipher_init(ctx, type, iv, secret, encrypt)
|
||||
#define ssh2_cipher_crypt(ctx, type, encrypt, block, blocklen, fl) \
|
||||
ssh2_mbed_cipher_crypt(ctx, type, encrypt, block, blocklen, fl)
|
||||
#define ssh2_cipher_dtor(ctx) \
|
||||
ssh2_mbed_cipher_dtor(ctx)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* mbedTLS backend: BigNumber Support
|
||||
*/
|
||||
|
||||
#define libssh2_bn_ctx int /* not used */
|
||||
#define _libssh2_bn_ctx_new() 0 /* not used */
|
||||
#define _libssh2_bn_ctx_free(bnctx) ((void)0) /* not used */
|
||||
#define ssh2_bn_ctx int /* not used */
|
||||
#define ssh2_bn_ctx_new() 0 /* not used */
|
||||
#define ssh2_bn_ctx_free(bnctx) ((void)0) /* not used */
|
||||
|
||||
#define libssh2_bn mbedtls_mpi
|
||||
#define ssh2_bn mbedtls_mpi
|
||||
|
||||
#define _libssh2_bn_init() \
|
||||
_libssh2_mbedtls_bignum_init()
|
||||
#define _libssh2_bn_init_from_bin() \
|
||||
_libssh2_mbedtls_bignum_init()
|
||||
#define _libssh2_bn_set_word(bn, word) \
|
||||
#define ssh2_bn_init() \
|
||||
ssh2_mbed_bn_init()
|
||||
#define ssh2_bn_init_from_bin() \
|
||||
ssh2_mbed_bn_init()
|
||||
#define ssh2_bn_set_word(bn, word) \
|
||||
mbedtls_mpi_lset(bn, word)
|
||||
#define _libssh2_bn_from_bin(bn, len, bin) \
|
||||
#define ssh2_bn_from_bin(bn, len, bin) \
|
||||
mbedtls_mpi_read_binary(bn, bin, len)
|
||||
#define _libssh2_bn_to_bin(bn, bin) \
|
||||
#define ssh2_bn_to_bin(bn, bin) \
|
||||
mbedtls_mpi_write_binary(bn, bin, mbedtls_mpi_size(bn))
|
||||
#define _libssh2_bn_bytes(bn) \
|
||||
#define ssh2_bn_bytes(bn) \
|
||||
mbedtls_mpi_size(bn)
|
||||
#define _libssh2_bn_bits(bn) \
|
||||
#define ssh2_bn_bits(bn) \
|
||||
mbedtls_mpi_bitlen(bn)
|
||||
#define _libssh2_bn_free(bn) \
|
||||
_libssh2_mbedtls_bignum_free(bn)
|
||||
#define ssh2_bn_free(bn) \
|
||||
ssh2_mbed_bn_free(bn)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
@@ -400,62 +381,56 @@ typedef enum {
|
||||
|
||||
/* Default generate and safe prime sizes for
|
||||
diffie-hellman-group-exchange-sha1 */
|
||||
#define LIBSSH2_DH_GEX_MINGROUP 2048
|
||||
#define LIBSSH2_DH_GEX_OPTGROUP 4096
|
||||
#define LIBSSH2_DH_GEX_MAXGROUP 8192
|
||||
#define SSH2_DH_GEX_MINGROUP 2048
|
||||
#define SSH2_DH_GEX_OPTGROUP 4096
|
||||
#define SSH2_DH_GEX_MAXGROUP 8192
|
||||
|
||||
#define LIBSSH2_DH_MAX_MODULUS_BITS 16384
|
||||
#define SSH2_DH_MAX_MODULUS_BITS 16384
|
||||
|
||||
#define libssh2_dh_ctx mbedtls_mpi *
|
||||
#define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx)
|
||||
#define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \
|
||||
_libssh2_dh_key_pair(dhctx, public, g, p, group_order)
|
||||
#define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \
|
||||
_libssh2_dh_secret(dhctx, secret, f, p)
|
||||
#define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx)
|
||||
#define ssh2_dh_ctx mbedtls_mpi *
|
||||
#define ssh2_dh_init(dhctx) ssh2_mbed_dh_init(dhctx)
|
||||
#define ssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \
|
||||
ssh2_mbed_dh_key_pair(dhctx, public, g, p, group_order)
|
||||
#define ssh2_dh_secret(dhctx, secret, f, p, bnctx) \
|
||||
ssh2_mbed_dh_secret(dhctx, secret, f, p)
|
||||
#define ssh2_dh_dtor(dhctx) ssh2_mbed_dh_dtor(dhctx)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* mbedTLS backend: forward declarations
|
||||
*/
|
||||
|
||||
void _libssh2_mbedtls_init(void);
|
||||
void ssh2_mbed_init(void);
|
||||
void ssh2_mbed_free(void);
|
||||
|
||||
void _libssh2_mbedtls_free(void);
|
||||
int ssh2_mbed_random(unsigned char *buf, size_t len);
|
||||
|
||||
int _libssh2_mbedtls_random(unsigned char *buf, size_t len);
|
||||
void ssh2_mbed_cipher_dtor(ssh2_cipher_ctx *ctx);
|
||||
|
||||
void _libssh2_mbedtls_cipher_dtor(libssh2_cipher_ctx *ctx);
|
||||
int ssh2_mbed_hash_init(mbedtls_md_context_t *ctx,
|
||||
mbedtls_md_type_t mdtype,
|
||||
const unsigned char *key, size_t keylen);
|
||||
int ssh2_mbed_hash_final(mbedtls_md_context_t *ctx, unsigned char *hash);
|
||||
int ssh2_mbed_hash(const unsigned char *data, size_t datalen,
|
||||
mbedtls_md_type_t mdtype, unsigned char *hash);
|
||||
|
||||
int _libssh2_mbedtls_hash_init(mbedtls_md_context_t *ctx,
|
||||
mbedtls_md_type_t mdtype,
|
||||
const unsigned char *key, size_t keylen);
|
||||
ssh2_bn *ssh2_mbed_bn_init(void);
|
||||
void ssh2_mbed_bn_free(ssh2_bn *bn);
|
||||
|
||||
int _libssh2_mbedtls_hash_final(mbedtls_md_context_t *ctx,
|
||||
unsigned char *hash);
|
||||
int _libssh2_mbedtls_hash(const unsigned char *data, size_t datalen,
|
||||
mbedtls_md_type_t mdtype, unsigned char *hash);
|
||||
|
||||
libssh2_bn *_libssh2_mbedtls_bignum_init(void);
|
||||
|
||||
void _libssh2_mbedtls_bignum_free(libssh2_bn *bn);
|
||||
|
||||
void _libssh2_mbedtls_rsa_free(libssh2_rsa_ctx *ctx);
|
||||
void ssh2_mbed_rsa_free(ssh2_rsa_ctx *ctx);
|
||||
|
||||
#if LIBSSH2_ECDSA
|
||||
libssh2_curve_type _libssh2_mbedtls_ecdsa_key_get_curve_type(
|
||||
libssh2_ecdsa_ctx *ctx);
|
||||
int _libssh2_mbedtls_ecdsa_curve_type_from_name(const char *name,
|
||||
libssh2_curve_type *out_type);
|
||||
void _libssh2_mbedtls_ecdsa_free(libssh2_ecdsa_ctx *ctx);
|
||||
ssh2_curve_type ssh2_mbed_ecdsa_key_get_curve_type(ssh2_ecdsa_ctx *ctx);
|
||||
int ssh2_mbed_ecdsa_curve_type_from_name(const char *name,
|
||||
ssh2_curve_type *out_type);
|
||||
void ssh2_mbed_ecdsa_free(ssh2_ecdsa_ctx *ctx);
|
||||
#endif /* LIBSSH2_ECDSA */
|
||||
|
||||
void _libssh2_init_aes_ctr(void);
|
||||
void _libssh2_dh_init(libssh2_dh_ctx *dhctx);
|
||||
int _libssh2_dh_key_pair(libssh2_dh_ctx *dhctx, libssh2_bn *public,
|
||||
libssh2_bn *g, libssh2_bn *p, int group_order);
|
||||
int _libssh2_dh_secret(libssh2_dh_ctx *dhctx, libssh2_bn *secret,
|
||||
libssh2_bn *f, libssh2_bn *p);
|
||||
void _libssh2_dh_dtor(libssh2_dh_ctx *dhctx);
|
||||
void ssh2_mbed_dh_init(ssh2_dh_ctx *dhctx);
|
||||
int ssh2_mbed_dh_key_pair(ssh2_dh_ctx *dhctx, ssh2_bn *public,
|
||||
ssh2_bn *g, ssh2_bn *p, int group_order);
|
||||
int ssh2_mbed_dh_secret(ssh2_dh_ctx *dhctx, ssh2_bn *secret,
|
||||
ssh2_bn *f, ssh2_bn *p);
|
||||
void ssh2_mbed_dh_dtor(ssh2_dh_ctx *dhctx);
|
||||
|
||||
#endif /* LIBSSH2_MBEDTLS_H */
|
||||
|
||||
212
src/misc.c
212
src/misc.c
@@ -50,11 +50,11 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Force parameter type. */
|
||||
#define libssh2_recv(s, b, l, f) recv(s, b, (int)(l), f)
|
||||
#define libssh2_send(s, b, l, f) send(s, b, (int)(l), f)
|
||||
#define SSH2_RECV_LOW(s, b, l, f) recv(s, b, (int)(l), f)
|
||||
#define SSH2_SEND_LOW(s, b, l, f) send(s, b, (int)(l), f)
|
||||
#else
|
||||
#define libssh2_recv recv
|
||||
#define libssh2_send send
|
||||
#define SSH2_RECV_LOW recv
|
||||
#define SSH2_SEND_LOW send
|
||||
#endif
|
||||
|
||||
/* snprintf not in Visual Studio CRT and _snprintf dangerously incompatible.
|
||||
@@ -67,7 +67,7 @@
|
||||
* number of chars placed in cp excluding the trailing null char. For
|
||||
* cp_max_len > 0 the return value is always < cp_max_len; for cp_max_len
|
||||
* <= 0 the return value is 0 (and no chars are written to cp). */
|
||||
int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...)
|
||||
int ssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
int n;
|
||||
@@ -81,8 +81,8 @@ int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...)
|
||||
}
|
||||
#endif
|
||||
|
||||
int _libssh2_error_flags(LIBSSH2_SESSION *session, int errcode,
|
||||
const char *errmsg, int errflags)
|
||||
int ssh2_err_flags(LIBSSH2_SESSION *session, int errcode,
|
||||
const char *errmsg, int errflags)
|
||||
{
|
||||
if(!session) {
|
||||
if(errmsg)
|
||||
@@ -90,18 +90,18 @@ int _libssh2_error_flags(LIBSSH2_SESSION *session, int errcode,
|
||||
return errcode;
|
||||
}
|
||||
|
||||
if(session->err_flags & LIBSSH2_ERR_FLAG_DUP)
|
||||
LIBSSH2_FREE(session, (char *)LIBSSH2_UNCONST(session->err_msg));
|
||||
if(session->err_flags & SSH2_ERR_FLAG_DUP)
|
||||
SSH2_FREE(session, (char *)SSH2_UNCONST(session->err_msg));
|
||||
|
||||
session->err_code = errcode;
|
||||
session->err_flags = 0;
|
||||
|
||||
if(errmsg && ((errflags & LIBSSH2_ERR_FLAG_DUP) != 0)) {
|
||||
if(errmsg && ((errflags & SSH2_ERR_FLAG_DUP) != 0)) {
|
||||
size_t len = strlen(errmsg);
|
||||
char *copy = LIBSSH2_ALLOC(session, len + 1);
|
||||
char *copy = SSH2_ALLOC(session, len + 1);
|
||||
if(copy) {
|
||||
memcpy(copy, errmsg, len + 1);
|
||||
session->err_flags = LIBSSH2_ERR_FLAG_DUP;
|
||||
session->err_flags = SSH2_ERR_FLAG_DUP;
|
||||
session->err_msg = copy;
|
||||
}
|
||||
else
|
||||
@@ -116,20 +116,20 @@ int _libssh2_error_flags(LIBSSH2_SESSION *session, int errcode,
|
||||
/* if this is EAGAIN and we are in non-blocking mode, do not generate
|
||||
a debug output for this */
|
||||
return errcode;
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_ERROR, "%d - %s", session->err_code,
|
||||
session->err_msg));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_ERROR, "%d - %s", session->err_code,
|
||||
session->err_msg));
|
||||
#endif
|
||||
|
||||
return errcode;
|
||||
}
|
||||
|
||||
int _libssh2_error(LIBSSH2_SESSION *session, int errcode, const char *errmsg)
|
||||
int ssh2_err(LIBSSH2_SESSION *session, int errcode, const char *errmsg)
|
||||
{
|
||||
return _libssh2_error_flags(session, errcode, errmsg, 0);
|
||||
return ssh2_err_flags(session, errcode, errmsg, 0);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
int _libssh2_wsa2errno(void)
|
||||
int ssh2_wsa2errno(void)
|
||||
{
|
||||
switch(WSAGetLastError()) {
|
||||
case WSAEWOULDBLOCK:
|
||||
@@ -152,18 +152,18 @@ int _libssh2_wsa2errno(void)
|
||||
/*
|
||||
* Replacement for the standard recv, return -errno on failure.
|
||||
*/
|
||||
ssize_t _libssh2_recv(libssh2_socket_t socket, void *buffer, size_t length,
|
||||
int flags, void **abstract)
|
||||
ssize_t ssh2_recv(libssh2_socket_t socket, void *buffer, size_t length,
|
||||
int flags, void **abstract)
|
||||
{
|
||||
ssize_t rc;
|
||||
|
||||
(void)abstract;
|
||||
|
||||
rc = libssh2_recv(socket, buffer, length, flags);
|
||||
rc = SSH2_RECV_LOW(socket, buffer, length, flags);
|
||||
if(rc < 0) {
|
||||
int err;
|
||||
#ifdef _WIN32
|
||||
err = _libssh2_wsa2errno();
|
||||
err = ssh2_wsa2errno();
|
||||
#else
|
||||
err = errno;
|
||||
#endif
|
||||
@@ -189,19 +189,19 @@ ssize_t _libssh2_recv(libssh2_socket_t socket, void *buffer, size_t length,
|
||||
/*
|
||||
* Replacement for the standard send, return -errno on failure.
|
||||
*/
|
||||
ssize_t _libssh2_send(libssh2_socket_t socket,
|
||||
const void *buffer, size_t length,
|
||||
int flags, void **abstract)
|
||||
ssize_t ssh2_send(libssh2_socket_t socket,
|
||||
const void *buffer, size_t length,
|
||||
int flags, void **abstract)
|
||||
{
|
||||
ssize_t rc;
|
||||
|
||||
(void)abstract;
|
||||
|
||||
rc = libssh2_send(socket, buffer, length, flags);
|
||||
rc = SSH2_SEND_LOW(socket, buffer, length, flags);
|
||||
if(rc < 0) {
|
||||
int err;
|
||||
#ifdef _WIN32
|
||||
err = _libssh2_wsa2errno();
|
||||
err = ssh2_wsa2errno();
|
||||
#else
|
||||
err = errno;
|
||||
#endif
|
||||
@@ -219,7 +219,7 @@ ssize_t _libssh2_send(libssh2_socket_t socket,
|
||||
return rc;
|
||||
}
|
||||
|
||||
uint32_t _libssh2_ntohu32(const unsigned char *buf)
|
||||
uint32_t ssh2_ntohu32(const unsigned char *buf)
|
||||
{
|
||||
return
|
||||
((uint32_t)buf[0] << 24) |
|
||||
@@ -228,7 +228,7 @@ uint32_t _libssh2_ntohu32(const unsigned char *buf)
|
||||
((uint32_t)buf[3]);
|
||||
}
|
||||
|
||||
libssh2_uint64_t _libssh2_ntohu64(const unsigned char *buf)
|
||||
libssh2_uint64_t ssh2_ntohu64(const unsigned char *buf)
|
||||
{
|
||||
return
|
||||
((libssh2_uint64_t)buf[0] << 56) |
|
||||
@@ -241,7 +241,7 @@ libssh2_uint64_t _libssh2_ntohu64(const unsigned char *buf)
|
||||
((libssh2_uint64_t)buf[7]);
|
||||
}
|
||||
|
||||
void _libssh2_htonu32(unsigned char *buf, uint32_t value)
|
||||
void ssh2_htonu32(unsigned char *buf, uint32_t value)
|
||||
{
|
||||
buf[0] = (unsigned char)((value >> 24) & 0xFF);
|
||||
buf[1] = (value >> 16) & 0xFF;
|
||||
@@ -249,13 +249,13 @@ void _libssh2_htonu32(unsigned char *buf, uint32_t value)
|
||||
buf[3] = value & 0xFF;
|
||||
}
|
||||
|
||||
void _libssh2_store_u32(unsigned char **buf, uint32_t value)
|
||||
void ssh2_store_u32(unsigned char **buf, uint32_t value)
|
||||
{
|
||||
_libssh2_htonu32(*buf, value);
|
||||
ssh2_htonu32(*buf, value);
|
||||
*buf += sizeof(uint32_t);
|
||||
}
|
||||
|
||||
void _libssh2_store_u64(unsigned char **buf, libssh2_uint64_t value)
|
||||
void ssh2_store_u64(unsigned char **buf, libssh2_uint64_t value)
|
||||
{
|
||||
unsigned char *ptr = *buf;
|
||||
|
||||
@@ -271,11 +271,11 @@ void _libssh2_store_u64(unsigned char **buf, libssh2_uint64_t value)
|
||||
*buf += sizeof(libssh2_uint64_t);
|
||||
}
|
||||
|
||||
int _libssh2_store_str(unsigned char **buf, const char *str, size_t len)
|
||||
int ssh2_store_str(unsigned char **buf, const char *str, size_t len)
|
||||
{
|
||||
uint32_t len_stored = (uint32_t)len;
|
||||
|
||||
_libssh2_store_u32(buf, len_stored);
|
||||
ssh2_store_u32(buf, len_stored);
|
||||
if(len_stored) {
|
||||
memcpy(*buf, str, len_stored);
|
||||
*buf += len_stored;
|
||||
@@ -285,8 +285,8 @@ int _libssh2_store_str(unsigned char **buf, const char *str, size_t len)
|
||||
return len_stored == len;
|
||||
}
|
||||
|
||||
int _libssh2_store_hybrid_str(unsigned char **buf, const char *str_1,
|
||||
size_t len_1, const char *str_2, size_t len_2)
|
||||
int ssh2_store_hybrid_str(unsigned char **buf, const char *str_1,
|
||||
size_t len_1, const char *str_2, size_t len_2)
|
||||
{
|
||||
uint32_t len_stored;
|
||||
|
||||
@@ -295,7 +295,7 @@ int _libssh2_store_hybrid_str(unsigned char **buf, const char *str_1,
|
||||
|
||||
len_stored = (uint32_t)len_1 + (uint32_t)len_2;
|
||||
|
||||
_libssh2_store_u32(buf, len_stored);
|
||||
ssh2_store_u32(buf, len_stored);
|
||||
if(len_1) {
|
||||
memcpy(*buf, str_1, len_1);
|
||||
*buf += len_1;
|
||||
@@ -310,9 +310,8 @@ int _libssh2_store_hybrid_str(unsigned char **buf, const char *str_1,
|
||||
return len_stored == len_1 + len_2;
|
||||
}
|
||||
|
||||
int _libssh2_store_bignum2_bytes(unsigned char **buf,
|
||||
const unsigned char *bytes,
|
||||
size_t len)
|
||||
int ssh2_store_bignum_bytes(unsigned char **buf,
|
||||
const unsigned char *bytes, size_t len)
|
||||
{
|
||||
uint32_t len_stored;
|
||||
uint32_t extraByte;
|
||||
@@ -325,7 +324,7 @@ int _libssh2_store_bignum2_bytes(unsigned char **buf,
|
||||
len_stored = (uint32_t)len;
|
||||
if(extraByte && len_stored == UINT32_MAX)
|
||||
len_stored--;
|
||||
_libssh2_store_u32(buf, len_stored + extraByte);
|
||||
ssh2_store_u32(buf, len_stored + extraByte);
|
||||
|
||||
if(extraByte) {
|
||||
*buf[0] = 0;
|
||||
@@ -374,7 +373,7 @@ int libssh2_base64_decode(LIBSSH2_SESSION *session,
|
||||
int rc;
|
||||
size_t dlen;
|
||||
|
||||
rc = _libssh2_base64_decode(session, dest, &dlen, src, src_len);
|
||||
rc = ssh2_base64_decode(session, dest, &dlen, src, src_len);
|
||||
|
||||
if(dest_len)
|
||||
*dest_len = (unsigned int)dlen;
|
||||
@@ -386,9 +385,9 @@ int libssh2_base64_decode(LIBSSH2_SESSION *session,
|
||||
/*
|
||||
* Decode a base64 chunk and store it into a newly alloc'd buffer
|
||||
*/
|
||||
int _libssh2_base64_decode(LIBSSH2_SESSION *session,
|
||||
char **data, size_t *datalen,
|
||||
const char *src, size_t src_len)
|
||||
int ssh2_base64_decode(LIBSSH2_SESSION *session,
|
||||
char **data, size_t *datalen,
|
||||
const char *src, size_t src_len)
|
||||
{
|
||||
unsigned char *d;
|
||||
const char *s;
|
||||
@@ -396,11 +395,11 @@ int _libssh2_base64_decode(LIBSSH2_SESSION *session,
|
||||
size_t i = 0, len = 0;
|
||||
|
||||
*datalen = 0;
|
||||
*data = LIBSSH2_ALLOC(session, src_len);
|
||||
*data = SSH2_ALLOC(session, src_len);
|
||||
d = (unsigned char *)*data;
|
||||
if(!d) {
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for base64 decoding");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for base64 decoding");
|
||||
}
|
||||
|
||||
for(s = src; s < (src + src_len); s++) {
|
||||
@@ -428,9 +427,9 @@ int _libssh2_base64_decode(LIBSSH2_SESSION *session,
|
||||
if((i % 4) == 1) {
|
||||
/* Invalid -- We have a byte which belongs exclusively to a partial
|
||||
octet */
|
||||
LIBSSH2_FREE(session, *data);
|
||||
SSH2_FREE(session, *data);
|
||||
*data = NULL;
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_INVAL, "Invalid base64");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_INVAL, "Invalid base64");
|
||||
}
|
||||
|
||||
*datalen = len;
|
||||
@@ -442,15 +441,15 @@ static const char table64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
/*
|
||||
* _libssh2_base64_encode
|
||||
* ssh2_base64_encode()
|
||||
*
|
||||
* Returns the length of the newly created base64 string. The third argument
|
||||
* is a pointer to an allocated area holding the base64 data. If something
|
||||
* went wrong, 0 is returned.
|
||||
*
|
||||
*/
|
||||
size_t _libssh2_base64_encode(LIBSSH2_SESSION *session,
|
||||
const char *inp, size_t insize, char **outptr)
|
||||
size_t ssh2_base64_encode(LIBSSH2_SESSION *session,
|
||||
const char *inp, size_t insize, char **outptr)
|
||||
{
|
||||
unsigned char ibuf[3];
|
||||
unsigned char obuf[4];
|
||||
@@ -466,7 +465,7 @@ size_t _libssh2_base64_encode(LIBSSH2_SESSION *session,
|
||||
if(insize == 0)
|
||||
return 0; /* nothing to encode */
|
||||
|
||||
base64data = output = LIBSSH2_ALLOC(session, insize * 4 / 3 + 4);
|
||||
base64data = output = SSH2_ALLOC(session, insize * 4 / 3 + 4);
|
||||
if(!output)
|
||||
return 0;
|
||||
|
||||
@@ -521,7 +520,7 @@ size_t _libssh2_base64_encode(LIBSSH2_SESSION *session,
|
||||
LIBSSH2_API
|
||||
void libssh2_free(LIBSSH2_SESSION *session, void *ptr)
|
||||
{
|
||||
LIBSSH2_FREE(session, ptr);
|
||||
SSH2_FREE(session, ptr);
|
||||
}
|
||||
|
||||
#ifdef LIBSSH2DEBUG
|
||||
@@ -543,8 +542,8 @@ int libssh2_trace_sethandler(LIBSSH2_SESSION *session, void *context,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _libssh2_debug_low(LIBSSH2_SESSION *session, int context,
|
||||
const char *format, ...)
|
||||
void ssh2_deb_low(LIBSSH2_SESSION *session, int context,
|
||||
const char *format, ...)
|
||||
{
|
||||
char buffer[1536];
|
||||
int len, msglen, buflen = sizeof(buffer);
|
||||
@@ -572,7 +571,7 @@ void _libssh2_debug_low(LIBSSH2_SESSION *session, int context,
|
||||
}
|
||||
|
||||
/* Find the first matching context string for this message */
|
||||
for(contextindex = 0; contextindex < ARRAY_SIZE(contexts);
|
||||
for(contextindex = 0; contextindex < SSH2_ARRAYSIZE(contexts);
|
||||
contextindex++) {
|
||||
if((context & (1 << contextindex)) != 0) {
|
||||
contexttext = contexts[contextindex];
|
||||
@@ -635,14 +634,13 @@ int libssh2_trace_sethandler(LIBSSH2_SESSION *session, void *context,
|
||||
#endif
|
||||
|
||||
/* init the list head */
|
||||
void _libssh2_list_init(struct list_head *head)
|
||||
void ssh2_list_init(struct list_head *head)
|
||||
{
|
||||
head->first = head->last = NULL;
|
||||
}
|
||||
|
||||
/* add a node to the list */
|
||||
void _libssh2_list_add(struct list_head *head,
|
||||
struct list_node *entry)
|
||||
void ssh2_list_add(struct list_head *head, struct list_node *entry)
|
||||
{
|
||||
/* store a pointer to the head */
|
||||
entry->head = head;
|
||||
@@ -664,25 +662,25 @@ void _libssh2_list_add(struct list_head *head,
|
||||
}
|
||||
|
||||
/* return the "first" node in the list this head points to */
|
||||
void *_libssh2_list_first(struct list_head *head)
|
||||
void *ssh2_list_first(struct list_head *head)
|
||||
{
|
||||
return head->first;
|
||||
}
|
||||
|
||||
/* return the next node in the list */
|
||||
void *_libssh2_list_next(struct list_node *node)
|
||||
void *ssh2_list_next(struct list_node *node)
|
||||
{
|
||||
return node->next;
|
||||
}
|
||||
|
||||
/* return the prev node in the list */
|
||||
void *_libssh2_list_prev(struct list_node *node)
|
||||
void *ssh2_list_prev(struct list_node *node)
|
||||
{
|
||||
return node->prev;
|
||||
}
|
||||
|
||||
/* remove this node from the list */
|
||||
void _libssh2_list_remove(struct list_node *entry)
|
||||
void ssh2_list_remove(struct list_node *entry)
|
||||
{
|
||||
if(entry->prev)
|
||||
entry->prev->next = entry->next;
|
||||
@@ -697,7 +695,7 @@ void _libssh2_list_remove(struct list_node *entry)
|
||||
|
||||
#if 0
|
||||
/* insert a node before the given 'after' entry */
|
||||
void _libssh2_list_insert(struct list_node *after, /* insert before this */
|
||||
void ssh2_list_insert(struct list_node *after, /* insert before this */
|
||||
struct list_node *entry)
|
||||
{
|
||||
/* 'after' is next to 'entry' */
|
||||
@@ -744,7 +742,7 @@ void _libssh2_list_insert(struct list_node *after, /* insert before this */
|
||||
* DISCLAIMED. This includes but is not limited to warranties of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
int _libssh2_gettimeofday(struct timeval *tp, void *tzp)
|
||||
int ssh2_gettimeofday(struct timeval *tp, void *tzp)
|
||||
{
|
||||
(void)tzp;
|
||||
if(tp) {
|
||||
@@ -771,9 +769,9 @@ int _libssh2_gettimeofday(struct timeval *tp, void *tzp)
|
||||
}
|
||||
#endif
|
||||
|
||||
void *_libssh2_calloc(LIBSSH2_SESSION *session, size_t size)
|
||||
void *ssh2_calloc(LIBSSH2_SESSION *session, size_t size)
|
||||
{
|
||||
void *p = LIBSSH2_ALLOC(session, size);
|
||||
void *p = SSH2_ALLOC(session, size);
|
||||
if(p) {
|
||||
memset(p, 0, size);
|
||||
}
|
||||
@@ -782,10 +780,10 @@ void *_libssh2_calloc(LIBSSH2_SESSION *session, size_t size)
|
||||
|
||||
/* XOR operation on buffers input1 and input2, result in output.
|
||||
It is safe to use an input buffer as the output buffer. */
|
||||
void _libssh2_xor_data(unsigned char *output,
|
||||
const unsigned char *input1,
|
||||
const unsigned char *input2,
|
||||
size_t length)
|
||||
void ssh2_xor_data(unsigned char *output,
|
||||
const unsigned char *input1,
|
||||
const unsigned char *input2,
|
||||
size_t length)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@@ -796,7 +794,7 @@ void _libssh2_xor_data(unsigned char *output,
|
||||
#ifdef LIBSSH2_MEMZERO
|
||||
static void *(* const volatile memset_libssh)(void *, int, size_t) = memset;
|
||||
|
||||
void _libssh2_memzero(void *buf, size_t size)
|
||||
void ssh2_memzero(void *buf, size_t size)
|
||||
{
|
||||
memset_libssh(buf, 0, size);
|
||||
}
|
||||
@@ -804,32 +802,32 @@ void _libssh2_memzero(void *buf, size_t size)
|
||||
|
||||
/* String buffer */
|
||||
|
||||
struct string_buf *_libssh2_string_buf_new(LIBSSH2_SESSION *session)
|
||||
struct string_buf *ssh2_string_buf_new(LIBSSH2_SESSION *session)
|
||||
{
|
||||
struct string_buf *ret;
|
||||
|
||||
ret = _libssh2_calloc(session, sizeof(*ret));
|
||||
ret = ssh2_calloc(session, sizeof(*ret));
|
||||
if(!ret)
|
||||
return NULL;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void _libssh2_string_buf_free(LIBSSH2_SESSION *session, struct string_buf *buf)
|
||||
void ssh2_string_buf_free(LIBSSH2_SESSION *session, struct string_buf *buf)
|
||||
{
|
||||
if(!buf)
|
||||
return;
|
||||
|
||||
if(buf->data)
|
||||
LIBSSH2_FREE(session, buf->data);
|
||||
SSH2_FREE(session, buf->data);
|
||||
|
||||
LIBSSH2_FREE(session, buf);
|
||||
SSH2_FREE(session, buf);
|
||||
buf = NULL;
|
||||
}
|
||||
|
||||
int _libssh2_get_byte(struct string_buf *buf, unsigned char *out)
|
||||
int ssh2_get_byte(struct string_buf *buf, unsigned char *out)
|
||||
{
|
||||
if(!_libssh2_check_length(buf, 1)) {
|
||||
if(!ssh2_check_length(buf, 1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -838,9 +836,9 @@ int _libssh2_get_byte(struct string_buf *buf, unsigned char *out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _libssh2_get_boolean(struct string_buf *buf, unsigned char *out)
|
||||
int ssh2_get_boolean(struct string_buf *buf, unsigned char *out)
|
||||
{
|
||||
if(!_libssh2_check_length(buf, 1)) {
|
||||
if(!ssh2_check_length(buf, 1)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -849,47 +847,47 @@ int _libssh2_get_boolean(struct string_buf *buf, unsigned char *out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _libssh2_get_u32(struct string_buf *buf, uint32_t *out)
|
||||
int ssh2_get_u32(struct string_buf *buf, uint32_t *out)
|
||||
{
|
||||
if(!_libssh2_check_length(buf, 4)) {
|
||||
if(!ssh2_check_length(buf, 4)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*out = _libssh2_ntohu32(buf->dataptr);
|
||||
*out = ssh2_ntohu32(buf->dataptr);
|
||||
buf->dataptr += 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _libssh2_get_u64(struct string_buf *buf, libssh2_uint64_t *out)
|
||||
int ssh2_get_u64(struct string_buf *buf, libssh2_uint64_t *out)
|
||||
{
|
||||
if(!_libssh2_check_length(buf, 8)) {
|
||||
if(!ssh2_check_length(buf, 8)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*out = _libssh2_ntohu64(buf->dataptr);
|
||||
*out = ssh2_ntohu64(buf->dataptr);
|
||||
buf->dataptr += 8;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _libssh2_match_string(struct string_buf *buf, const char *match)
|
||||
int ssh2_match_string(struct string_buf *buf, const char *match)
|
||||
{
|
||||
unsigned char *out;
|
||||
size_t len = 0;
|
||||
if(_libssh2_get_string(buf, &out, &len) || len != strlen(match) ||
|
||||
if(ssh2_get_string(buf, &out, &len) || len != strlen(match) ||
|
||||
strncmp((char *)out, match, strlen(match)) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _libssh2_get_string(struct string_buf *buf, unsigned char **outbuf,
|
||||
size_t *outlen)
|
||||
int ssh2_get_string(struct string_buf *buf, unsigned char **outbuf,
|
||||
size_t *outlen)
|
||||
{
|
||||
uint32_t data_len;
|
||||
if(!buf || _libssh2_get_u32(buf, &data_len) != 0) {
|
||||
if(!buf || ssh2_get_u32(buf, &data_len) != 0) {
|
||||
return -1;
|
||||
}
|
||||
if(!_libssh2_check_length(buf, data_len)) {
|
||||
if(!ssh2_check_length(buf, data_len)) {
|
||||
return -1;
|
||||
}
|
||||
*outbuf = buf->dataptr;
|
||||
@@ -901,18 +899,18 @@ int _libssh2_get_string(struct string_buf *buf, unsigned char **outbuf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _libssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf,
|
||||
unsigned char **outbuf, size_t *outlen)
|
||||
int ssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf,
|
||||
unsigned char **outbuf, size_t *outlen)
|
||||
{
|
||||
size_t str_len;
|
||||
unsigned char *str;
|
||||
|
||||
if(_libssh2_get_string(buf, &str, &str_len)) {
|
||||
if(ssh2_get_string(buf, &str, &str_len)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(str_len) {
|
||||
*outbuf = LIBSSH2_ALLOC(session, str_len);
|
||||
*outbuf = SSH2_ALLOC(session, str_len);
|
||||
if(*outbuf) {
|
||||
memcpy(*outbuf, str, str_len);
|
||||
}
|
||||
@@ -930,17 +928,17 @@ int _libssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _libssh2_get_bignum_bytes(struct string_buf *buf, unsigned char **outbuf,
|
||||
size_t *outlen)
|
||||
int ssh2_get_bignum_bytes(struct string_buf *buf, unsigned char **outbuf,
|
||||
size_t *outlen)
|
||||
{
|
||||
uint32_t data_len;
|
||||
uint32_t bn_len;
|
||||
unsigned char *bnptr;
|
||||
|
||||
if(_libssh2_get_u32(buf, &data_len)) {
|
||||
if(ssh2_get_u32(buf, &data_len)) {
|
||||
return -1;
|
||||
}
|
||||
if(!_libssh2_check_length(buf, data_len)) {
|
||||
if(!ssh2_check_length(buf, data_len)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -962,24 +960,24 @@ int _libssh2_get_bignum_bytes(struct string_buf *buf, unsigned char **outbuf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Given the current location in buf, _libssh2_check_length ensures
|
||||
/* Given the current location in buf, ssh2_check_length() ensures
|
||||
callers can read the next len number of bytes out of the buffer
|
||||
before reading the buffer content */
|
||||
|
||||
int _libssh2_check_length(struct string_buf *buf, size_t requested_len)
|
||||
int ssh2_check_length(struct string_buf *buf, size_t requested_len)
|
||||
{
|
||||
unsigned char *endp = &buf->data[buf->len];
|
||||
size_t left = endp - buf->dataptr;
|
||||
return (requested_len <= left) && (left <= buf->len);
|
||||
}
|
||||
|
||||
int _libssh2_eob(struct string_buf *buf)
|
||||
int ssh2_eob(struct string_buf *buf)
|
||||
{
|
||||
unsigned char *endp = &buf->data[buf->len];
|
||||
return buf->dataptr >= endp;
|
||||
}
|
||||
|
||||
int _libssh2_timingsafe_bcmp(const void *b1, const void *b2, size_t n)
|
||||
int ssh2_timingsafe_bcmp(const void *b1, const void *b2, size_t n)
|
||||
{
|
||||
const unsigned char *p1 = (const unsigned char *)b1;
|
||||
const unsigned char *p2 = (const unsigned char *)b2;
|
||||
|
||||
114
src/misc.h
114
src/misc.h
@@ -40,23 +40,23 @@
|
||||
*/
|
||||
|
||||
#ifdef LIBSSH2_NO_CLEAR_MEMORY
|
||||
#define _libssh2_explicit_zero(buf, size) \
|
||||
do { \
|
||||
(void)(buf); \
|
||||
(void)(size); \
|
||||
#define ssh2_explicit_zero(buf, size) \
|
||||
do { \
|
||||
(void)(buf); \
|
||||
(void)(size); \
|
||||
} while(0)
|
||||
#elif defined(_WIN32)
|
||||
#define _libssh2_explicit_zero(buf, size) SecureZeroMemory(buf, size)
|
||||
#define ssh2_explicit_zero(buf, size) SecureZeroMemory(buf, size)
|
||||
#elif defined(HAVE_EXPLICIT_BZERO)
|
||||
#define _libssh2_explicit_zero(buf, size) explicit_bzero(buf, size)
|
||||
#define ssh2_explicit_zero(buf, size) explicit_bzero(buf, size)
|
||||
#elif defined(HAVE_EXPLICIT_MEMSET)
|
||||
#define _libssh2_explicit_zero(buf, size) (void)explicit_memset(buf, 0, size)
|
||||
#define ssh2_explicit_zero(buf, size) (void)explicit_memset(buf, 0, size)
|
||||
#elif defined(HAVE_MEMSET_S)
|
||||
#define _libssh2_explicit_zero(buf, size) (void)memset_s(buf, size, 0, size)
|
||||
#define ssh2_explicit_zero(buf, size) (void)memset_s(buf, size, 0, size)
|
||||
#else
|
||||
#define LIBSSH2_MEMZERO
|
||||
void _libssh2_memzero(void *buf, size_t size);
|
||||
#define _libssh2_explicit_zero(buf, size) _libssh2_memzero(buf, size)
|
||||
void ssh2_memzero(void *buf, size_t size);
|
||||
#define ssh2_explicit_zero(buf, size) ssh2_memzero(buf, size)
|
||||
#endif
|
||||
|
||||
struct list_head {
|
||||
@@ -76,74 +76,70 @@ struct string_buf {
|
||||
size_t len;
|
||||
};
|
||||
|
||||
int _libssh2_error_flags(LIBSSH2_SESSION *session, int errcode,
|
||||
const char *errmsg, int errflags);
|
||||
int _libssh2_error(LIBSSH2_SESSION *session, int errcode, const char *errmsg);
|
||||
int ssh2_err_flags(LIBSSH2_SESSION *session, int errcode,
|
||||
const char *errmsg, int errflags);
|
||||
int ssh2_err(LIBSSH2_SESSION *session, int errcode, const char *errmsg);
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Convert Win32 WSAGetLastError to errno equivalent */
|
||||
int _libssh2_wsa2errno(void);
|
||||
int ssh2_wsa2errno(void);
|
||||
#endif
|
||||
|
||||
void _libssh2_list_init(struct list_head *head);
|
||||
void ssh2_list_init(struct list_head *head);
|
||||
|
||||
/* add a node last in the list */
|
||||
void _libssh2_list_add(struct list_head *head,
|
||||
struct list_node *entry);
|
||||
void ssh2_list_add(struct list_head *head, struct list_node *entry);
|
||||
|
||||
/* return the "first" node in the list this head points to */
|
||||
void *_libssh2_list_first(struct list_head *head);
|
||||
void *ssh2_list_first(struct list_head *head);
|
||||
|
||||
/* return the next node in the list */
|
||||
void *_libssh2_list_next(struct list_node *node);
|
||||
void *ssh2_list_next(struct list_node *node);
|
||||
|
||||
/* return the prev node in the list */
|
||||
void *_libssh2_list_prev(struct list_node *node);
|
||||
void *ssh2_list_prev(struct list_node *node);
|
||||
|
||||
/* remove this node from the list */
|
||||
void _libssh2_list_remove(struct list_node *entry);
|
||||
void ssh2_list_remove(struct list_node *entry);
|
||||
|
||||
int _libssh2_base64_decode(LIBSSH2_SESSION *session,
|
||||
char **data, size_t *datalen,
|
||||
const char *src, size_t src_len);
|
||||
size_t _libssh2_base64_encode(LIBSSH2_SESSION *session,
|
||||
const char *inp, size_t insize, char **outptr);
|
||||
int ssh2_base64_decode(LIBSSH2_SESSION *session, char **data, size_t *datalen,
|
||||
const char *src, size_t src_len);
|
||||
size_t ssh2_base64_encode(LIBSSH2_SESSION *session,
|
||||
const char *inp, size_t insize, char **outptr);
|
||||
|
||||
uint32_t _libssh2_ntohu32(const unsigned char *buf);
|
||||
libssh2_uint64_t _libssh2_ntohu64(const unsigned char *buf);
|
||||
void _libssh2_htonu32(unsigned char *buf, uint32_t value);
|
||||
void _libssh2_store_u32(unsigned char **buf, uint32_t value);
|
||||
void _libssh2_store_u64(unsigned char **buf, libssh2_uint64_t value);
|
||||
int _libssh2_store_str(unsigned char **buf, const char *str, size_t len);
|
||||
int _libssh2_store_hybrid_str(unsigned char **buf, const char *str_1,
|
||||
size_t len_1, const char *str_2, size_t len_2);
|
||||
int _libssh2_store_bignum2_bytes(unsigned char **buf,
|
||||
const unsigned char *bytes,
|
||||
size_t len);
|
||||
void *_libssh2_calloc(LIBSSH2_SESSION *session, size_t size);
|
||||
uint32_t ssh2_ntohu32(const unsigned char *buf);
|
||||
libssh2_uint64_t ssh2_ntohu64(const unsigned char *buf);
|
||||
void ssh2_htonu32(unsigned char *buf, uint32_t value);
|
||||
void ssh2_store_u32(unsigned char **buf, uint32_t value);
|
||||
void ssh2_store_u64(unsigned char **buf, libssh2_uint64_t value);
|
||||
int ssh2_store_str(unsigned char **buf, const char *str, size_t len);
|
||||
int ssh2_store_hybrid_str(unsigned char **buf, const char *str_1,
|
||||
size_t len_1, const char *str_2, size_t len_2);
|
||||
int ssh2_store_bignum_bytes(unsigned char **buf,
|
||||
const unsigned char *bytes, size_t len);
|
||||
void *ssh2_calloc(LIBSSH2_SESSION *session, size_t size);
|
||||
|
||||
struct string_buf *_libssh2_string_buf_new(LIBSSH2_SESSION *session);
|
||||
void _libssh2_string_buf_free(LIBSSH2_SESSION *session,
|
||||
struct string_buf *buf);
|
||||
int _libssh2_get_boolean(struct string_buf *buf, unsigned char *out);
|
||||
int _libssh2_get_byte(struct string_buf *buf, unsigned char *out);
|
||||
int _libssh2_get_u32(struct string_buf *buf, uint32_t *out);
|
||||
int _libssh2_get_u64(struct string_buf *buf, libssh2_uint64_t *out);
|
||||
int _libssh2_match_string(struct string_buf *buf, const char *match);
|
||||
int _libssh2_get_string(struct string_buf *buf, unsigned char **outbuf,
|
||||
size_t *outlen);
|
||||
int _libssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf,
|
||||
unsigned char **outbuf, size_t *outlen);
|
||||
int _libssh2_get_bignum_bytes(struct string_buf *buf, unsigned char **outbuf,
|
||||
size_t *outlen);
|
||||
int _libssh2_check_length(struct string_buf *buf, size_t requested_len);
|
||||
int _libssh2_eob(struct string_buf *buf);
|
||||
struct string_buf *ssh2_string_buf_new(LIBSSH2_SESSION *session);
|
||||
void ssh2_string_buf_free(LIBSSH2_SESSION *session, struct string_buf *buf);
|
||||
int ssh2_get_boolean(struct string_buf *buf, unsigned char *out);
|
||||
int ssh2_get_byte(struct string_buf *buf, unsigned char *out);
|
||||
int ssh2_get_u32(struct string_buf *buf, uint32_t *out);
|
||||
int ssh2_get_u64(struct string_buf *buf, libssh2_uint64_t *out);
|
||||
int ssh2_match_string(struct string_buf *buf, const char *match);
|
||||
int ssh2_get_string(struct string_buf *buf, unsigned char **outbuf,
|
||||
size_t *outlen);
|
||||
int ssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf,
|
||||
unsigned char **outbuf, size_t *outlen);
|
||||
int ssh2_get_bignum_bytes(struct string_buf *buf, unsigned char **outbuf,
|
||||
size_t *outlen);
|
||||
int ssh2_check_length(struct string_buf *buf, size_t requested_len);
|
||||
int ssh2_eob(struct string_buf *buf);
|
||||
|
||||
void _libssh2_xor_data(unsigned char *output,
|
||||
const unsigned char *input1,
|
||||
const unsigned char *input2,
|
||||
size_t length);
|
||||
void ssh2_xor_data(unsigned char *output,
|
||||
const unsigned char *input1,
|
||||
const unsigned char *input2,
|
||||
size_t length);
|
||||
|
||||
int _libssh2_timingsafe_bcmp(const void *b1, const void *b2, size_t n);
|
||||
int ssh2_timingsafe_bcmp(const void *b1, const void *b2, size_t n);
|
||||
|
||||
#endif /* LIBSSH2_MISC_H */
|
||||
|
||||
1507
src/openssl.c
1507
src/openssl.c
File diff suppressed because it is too large
Load Diff
292
src/openssl.h
292
src/openssl.h
@@ -40,7 +40,7 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#define LIBSSH2_CRYPTO_ENGINE libssh2_openssl
|
||||
#define SSH2_CRYPTO_ENGINE libssh2_openssl
|
||||
|
||||
/* disable deprecated warnings in OpenSSL 3 */
|
||||
#define OPENSSL_SUPPRESS_DEPRECATED
|
||||
@@ -225,125 +225,122 @@
|
||||
|
||||
#define EC_MAX_POINT_LEN ((528 * 2 / 8) + 1)
|
||||
|
||||
#define _libssh2_random(buf, len) _libssh2_openssl_random(buf, len)
|
||||
#define ssh2_random(buf, len) ssh2_ossl_random(buf, len)
|
||||
|
||||
#define libssh2_prepare_iovec(vec, len) /* Empty. */
|
||||
#define ssh2_prepare_iovec(vec, len) /* Empty. */
|
||||
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
#define libssh2_sha1_ctx EVP_MD_CTX *
|
||||
#define ssh2_sha1_ctx EVP_MD_CTX *
|
||||
#else
|
||||
#define libssh2_sha1_ctx EVP_MD_CTX
|
||||
#define ssh2_sha1_ctx EVP_MD_CTX
|
||||
#endif
|
||||
|
||||
/* returns 0 in case of failure */
|
||||
int _libssh2_sha1_init(libssh2_sha1_ctx *ctx);
|
||||
int _libssh2_sha1_update(libssh2_sha1_ctx *ctx,
|
||||
const void *data, size_t len);
|
||||
int _libssh2_sha1_final(libssh2_sha1_ctx *ctx, unsigned char *out);
|
||||
int _libssh2_sha1(const unsigned char *message, size_t len,
|
||||
unsigned char *out);
|
||||
#define libssh2_sha1_init(x) _libssh2_sha1_init(x)
|
||||
#define libssh2_sha1_update(ctx, data, len) \
|
||||
_libssh2_sha1_update(&(ctx), data, len)
|
||||
#define libssh2_sha1_final(ctx, out) _libssh2_sha1_final(&(ctx), out)
|
||||
#define libssh2_sha1(x, y, z) _libssh2_sha1(x, y, z)
|
||||
int ssh2_ossl_sha1_init(ssh2_sha1_ctx *ctx);
|
||||
int ssh2_ossl_sha1_update(ssh2_sha1_ctx *ctx, const void *data, size_t len);
|
||||
int ssh2_ossl_sha1_final(ssh2_sha1_ctx *ctx, unsigned char *out);
|
||||
int ssh2_ossl_sha1(const unsigned char *message, size_t len,
|
||||
unsigned char *out);
|
||||
#define ssh2_sha1_init(x) ssh2_ossl_sha1_init(x)
|
||||
#define ssh2_sha1_update(ctx, data, len) \
|
||||
ssh2_ossl_sha1_update(&(ctx), data, len)
|
||||
#define ssh2_sha1_final(ctx, out) ssh2_ossl_sha1_final(&(ctx), out)
|
||||
#define ssh2_sha1(x, y, z) ssh2_ossl_sha1(x, y, z)
|
||||
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
#define libssh2_sha256_ctx EVP_MD_CTX *
|
||||
#define ssh2_sha256_ctx EVP_MD_CTX *
|
||||
#else
|
||||
#define libssh2_sha256_ctx EVP_MD_CTX
|
||||
#define ssh2_sha256_ctx EVP_MD_CTX
|
||||
#endif
|
||||
|
||||
/* returns 0 in case of failure */
|
||||
int _libssh2_sha256_init(libssh2_sha256_ctx *ctx);
|
||||
int _libssh2_sha256_update(libssh2_sha256_ctx *ctx,
|
||||
const void *data, size_t len);
|
||||
int _libssh2_sha256_final(libssh2_sha256_ctx *ctx, unsigned char *out);
|
||||
int _libssh2_sha256(const unsigned char *message, size_t len,
|
||||
unsigned char *out);
|
||||
#define libssh2_sha256_init(x) _libssh2_sha256_init(x)
|
||||
#define libssh2_sha256_update(ctx, data, len) \
|
||||
_libssh2_sha256_update(&(ctx), data, len)
|
||||
#define libssh2_sha256_final(ctx, out) _libssh2_sha256_final(&(ctx), out)
|
||||
#define libssh2_sha256(x, y, z) _libssh2_sha256(x, y, z)
|
||||
int ssh2_ossl_sha256_init(ssh2_sha256_ctx *ctx);
|
||||
int ssh2_ossl_sha256_update(ssh2_sha256_ctx *ctx, const void *data,
|
||||
size_t len);
|
||||
int ssh2_ossl_sha256_final(ssh2_sha256_ctx *ctx, unsigned char *out);
|
||||
int ssh2_ossl_sha256(const unsigned char *message, size_t len,
|
||||
unsigned char *out);
|
||||
#define ssh2_sha256_init(x) ssh2_ossl_sha256_init(x)
|
||||
#define ssh2_sha256_update(ctx, data, len) \
|
||||
ssh2_ossl_sha256_update(&(ctx), data, len)
|
||||
#define ssh2_sha256_final(ctx, out) ssh2_ossl_sha256_final(&(ctx), out)
|
||||
#define ssh2_sha256(x, y, z) ssh2_ossl_sha256(x, y, z)
|
||||
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
#define libssh2_sha384_ctx EVP_MD_CTX *
|
||||
#define ssh2_sha384_ctx EVP_MD_CTX *
|
||||
#else
|
||||
#define libssh2_sha384_ctx EVP_MD_CTX
|
||||
#define ssh2_sha384_ctx EVP_MD_CTX
|
||||
#endif
|
||||
|
||||
/* returns 0 in case of failure */
|
||||
int _libssh2_sha384_init(libssh2_sha384_ctx *ctx);
|
||||
int _libssh2_sha384_update(libssh2_sha384_ctx *ctx,
|
||||
const void *data, size_t len);
|
||||
int _libssh2_sha384_final(libssh2_sha384_ctx *ctx, unsigned char *out);
|
||||
int _libssh2_sha384(const unsigned char *message, size_t len,
|
||||
unsigned char *out);
|
||||
#define libssh2_sha384_init(x) _libssh2_sha384_init(x)
|
||||
#define libssh2_sha384_update(ctx, data, len) \
|
||||
_libssh2_sha384_update(&(ctx), data, len)
|
||||
#define libssh2_sha384_final(ctx, out) _libssh2_sha384_final(&(ctx), out)
|
||||
#define libssh2_sha384(x, y, z) _libssh2_sha384(x, y, z)
|
||||
int ssh2_ossl_sha384_init(ssh2_sha384_ctx *ctx);
|
||||
int ssh2_ossl_sha384_update(ssh2_sha384_ctx *ctx, const void *data,
|
||||
size_t len);
|
||||
int ssh2_ossl_sha384_final(ssh2_sha384_ctx *ctx, unsigned char *out);
|
||||
int ssh2_ossl_sha384(const unsigned char *message, size_t len,
|
||||
unsigned char *out);
|
||||
#define ssh2_sha384_init(x) ssh2_ossl_sha384_init(x)
|
||||
#define ssh2_sha384_update(ctx, data, len) \
|
||||
ssh2_ossl_sha384_update(&(ctx), data, len)
|
||||
#define ssh2_sha384_final(ctx, out) ssh2_ossl_sha384_final(&(ctx), out)
|
||||
#define ssh2_sha384(x, y, z) ssh2_ossl_sha384(x, y, z)
|
||||
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
#define libssh2_sha512_ctx EVP_MD_CTX *
|
||||
#define ssh2_sha512_ctx EVP_MD_CTX *
|
||||
#else
|
||||
#define libssh2_sha512_ctx EVP_MD_CTX
|
||||
#define ssh2_sha512_ctx EVP_MD_CTX
|
||||
#endif
|
||||
|
||||
/* returns 0 in case of failure */
|
||||
int _libssh2_sha512_init(libssh2_sha512_ctx *ctx);
|
||||
int _libssh2_sha512_update(libssh2_sha512_ctx *ctx,
|
||||
const void *data, size_t len);
|
||||
int _libssh2_sha512_final(libssh2_sha512_ctx *ctx, unsigned char *out);
|
||||
int _libssh2_sha512(const unsigned char *message, size_t len,
|
||||
unsigned char *out);
|
||||
#define libssh2_sha512_init(x) _libssh2_sha512_init(x)
|
||||
#define libssh2_sha512_update(ctx, data, len) \
|
||||
_libssh2_sha512_update(&(ctx), data, len)
|
||||
#define libssh2_sha512_final(ctx, out) _libssh2_sha512_final(&(ctx), out)
|
||||
#define libssh2_sha512(x, y, z) _libssh2_sha512(x, y, z)
|
||||
int ssh2_ossl_sha512_init(ssh2_sha512_ctx *ctx);
|
||||
int ssh2_ossl_sha512_update(ssh2_sha512_ctx *ctx, const void *data,
|
||||
size_t len);
|
||||
int ssh2_ossl_sha512_final(ssh2_sha512_ctx *ctx, unsigned char *out);
|
||||
int ssh2_ossl_sha512(const unsigned char *message, size_t len,
|
||||
unsigned char *out);
|
||||
#define ssh2_sha512_init(x) ssh2_ossl_sha512_init(x)
|
||||
#define ssh2_sha512_update(ctx, data, len) \
|
||||
ssh2_ossl_sha512_update(&(ctx), data, len)
|
||||
#define ssh2_sha512_final(ctx, out) ssh2_ossl_sha512_final(&(ctx), out)
|
||||
#define ssh2_sha512(x, y, z) ssh2_ossl_sha512(x, y, z)
|
||||
|
||||
#if LIBSSH2_MD5 || LIBSSH2_MD5_PEM
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
#define libssh2_md5_ctx EVP_MD_CTX *
|
||||
#define ssh2_md5_ctx EVP_MD_CTX *
|
||||
#else
|
||||
#define libssh2_md5_ctx EVP_MD_CTX
|
||||
#define ssh2_md5_ctx EVP_MD_CTX
|
||||
#endif
|
||||
|
||||
/* returns 0 in case of failure */
|
||||
int _libssh2_md5_init(libssh2_md5_ctx *ctx);
|
||||
int _libssh2_md5_update(libssh2_md5_ctx *ctx,
|
||||
const void *data, size_t len);
|
||||
int _libssh2_md5_final(libssh2_md5_ctx *ctx, unsigned char *out);
|
||||
#define libssh2_md5_init(x) _libssh2_md5_init(x)
|
||||
#define libssh2_md5_update(ctx, data, len) \
|
||||
_libssh2_md5_update(&(ctx), data, len)
|
||||
#define libssh2_md5_final(ctx, out) _libssh2_md5_final(&(ctx), out)
|
||||
int ssh2_ossl_md5_init(ssh2_md5_ctx *ctx);
|
||||
int ssh2_ossl_md5_update(ssh2_md5_ctx *ctx, const void *data, size_t len);
|
||||
int ssh2_ossl_md5_final(ssh2_md5_ctx *ctx, unsigned char *out);
|
||||
#define ssh2_md5_init(x) ssh2_ossl_md5_init(x)
|
||||
#define ssh2_md5_update(ctx, data, len) ssh2_ossl_md5_update(&(ctx), data, len)
|
||||
#define ssh2_md5_final(ctx, out) ssh2_ossl_md5_final(&(ctx), out)
|
||||
#endif /* LIBSSH2_MD5 || LIBSSH2_MD5_PEM */
|
||||
|
||||
#ifdef USE_OPENSSL_3
|
||||
#define libssh2_hmac_ctx EVP_MAC_CTX *
|
||||
#define ssh2_hmac_ctx EVP_MAC_CTX *
|
||||
#elif defined(HAVE_OPAQUE_STRUCTS)
|
||||
#define libssh2_hmac_ctx HMAC_CTX *
|
||||
#define ssh2_hmac_ctx HMAC_CTX *
|
||||
#else /* !HAVE_OPAQUE_STRUCTS */
|
||||
#define libssh2_hmac_ctx HMAC_CTX
|
||||
#define ssh2_hmac_ctx HMAC_CTX
|
||||
#endif /* USE_OPENSSL_3 */
|
||||
|
||||
void _libssh2_openssl_crypto_init(void);
|
||||
void _libssh2_openssl_crypto_exit(void);
|
||||
#define libssh2_crypto_init() _libssh2_openssl_crypto_init()
|
||||
#define libssh2_crypto_exit() _libssh2_openssl_crypto_exit()
|
||||
void ssh2_ossl_init(void);
|
||||
void ssh2_ossl_exit(void);
|
||||
#define ssh2_crypto_init() ssh2_ossl_init()
|
||||
#define ssh2_crypto_exit() ssh2_ossl_exit()
|
||||
|
||||
#if LIBSSH2_RSA
|
||||
|
||||
#ifdef USE_OPENSSL_3
|
||||
#define libssh2_rsa_ctx EVP_PKEY
|
||||
#define _libssh2_rsa_free(rsactx) EVP_PKEY_free(rsactx)
|
||||
#define ssh2_rsa_ctx EVP_PKEY
|
||||
#define ssh2_rsa_free(rsactx) EVP_PKEY_free(rsactx)
|
||||
#else
|
||||
#define libssh2_rsa_ctx RSA
|
||||
#define _libssh2_rsa_free(rsactx) RSA_free(rsactx)
|
||||
#define ssh2_rsa_ctx RSA
|
||||
#define ssh2_rsa_free(rsactx) RSA_free(rsactx)
|
||||
#endif
|
||||
|
||||
#endif /* LIBSSH2_RSA */
|
||||
@@ -351,11 +348,11 @@ void _libssh2_openssl_crypto_exit(void);
|
||||
#if LIBSSH2_DSA
|
||||
|
||||
#ifdef USE_OPENSSL_3
|
||||
#define libssh2_dsa_ctx EVP_PKEY
|
||||
#define _libssh2_dsa_free(rsactx) EVP_PKEY_free(rsactx)
|
||||
#define ssh2_dsa_ctx EVP_PKEY
|
||||
#define ssh2_dsa_free(rsactx) EVP_PKEY_free(rsactx)
|
||||
#else
|
||||
#define libssh2_dsa_ctx DSA
|
||||
#define _libssh2_dsa_free(dsactx) DSA_free(dsactx)
|
||||
#define ssh2_dsa_ctx DSA
|
||||
#define ssh2_dsa_free(dsactx) DSA_free(dsactx)
|
||||
#endif
|
||||
|
||||
#endif /* LIBSSH2_DSA */
|
||||
@@ -363,100 +360,99 @@ void _libssh2_openssl_crypto_exit(void);
|
||||
#if LIBSSH2_ECDSA
|
||||
|
||||
#ifdef USE_OPENSSL_3
|
||||
#define libssh2_ecdsa_ctx EVP_PKEY
|
||||
#define _libssh2_ecdsa_free(ecdsactx) EVP_PKEY_free(ecdsactx)
|
||||
#define libssh2_ec_key EVP_PKEY
|
||||
#define ssh2_ecdsa_ctx EVP_PKEY
|
||||
#define ssh2_ecdsa_free(ecdsactx) EVP_PKEY_free(ecdsactx)
|
||||
#define ssh2_ec_key EVP_PKEY
|
||||
#else
|
||||
#define libssh2_ecdsa_ctx EC_KEY
|
||||
#define _libssh2_ecdsa_free(ecdsactx) EC_KEY_free(ecdsactx)
|
||||
#define libssh2_ec_key EC_KEY
|
||||
#define ssh2_ecdsa_ctx EC_KEY
|
||||
#define ssh2_ecdsa_free(ecdsactx) EC_KEY_free(ecdsactx)
|
||||
#define ssh2_ec_key EC_KEY
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
LIBSSH2_EC_CURVE_NISTP256 = NID_X9_62_prime256v1,
|
||||
LIBSSH2_EC_CURVE_NISTP384 = NID_secp384r1,
|
||||
LIBSSH2_EC_CURVE_NISTP521 = NID_secp521r1
|
||||
} libssh2_curve_type;
|
||||
SSH2_EC_CURVE_NISTP256 = NID_X9_62_prime256v1,
|
||||
SSH2_EC_CURVE_NISTP384 = NID_secp384r1,
|
||||
SSH2_EC_CURVE_NISTP521 = NID_secp521r1
|
||||
} ssh2_curve_type;
|
||||
#else /* !LIBSSH2_ECDSA */
|
||||
#define libssh2_ec_key void
|
||||
#define ssh2_ec_key void
|
||||
#endif /* LIBSSH2_ECDSA */
|
||||
|
||||
#if LIBSSH2_ED25519
|
||||
#define libssh2_ed25519_ctx EVP_PKEY
|
||||
#define _libssh2_ed25519_free(ctx) EVP_PKEY_free(ctx)
|
||||
#define ssh2_ed25519_ctx EVP_PKEY
|
||||
#define ssh2_ed25519_free(ctx) EVP_PKEY_free(ctx)
|
||||
#endif /* LIBSSH2_ED25519 */
|
||||
|
||||
#define LIBSSH2_CIPHER_T(name) const EVP_CIPHER *(*(name))(void)
|
||||
#define SSH2_CIPHER_T(name) const EVP_CIPHER *(*(name))(void)
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
#define libssh2_cipher_ctx EVP_CIPHER_CTX *
|
||||
#define ssh2_cipher_ctx EVP_CIPHER_CTX *
|
||||
#else
|
||||
#define libssh2_cipher_ctx EVP_CIPHER_CTX
|
||||
#define ssh2_cipher_ctx EVP_CIPHER_CTX
|
||||
#endif
|
||||
|
||||
#define libssh2_cipher_aes256gcm EVP_aes_256_gcm
|
||||
#define libssh2_cipher_aes128gcm EVP_aes_128_gcm
|
||||
#define ssh2_cipher_aes256gcm EVP_aes_256_gcm
|
||||
#define ssh2_cipher_aes128gcm EVP_aes_128_gcm
|
||||
|
||||
#define libssh2_cipher_aes256 EVP_aes_256_cbc
|
||||
#define libssh2_cipher_aes192 EVP_aes_192_cbc
|
||||
#define libssh2_cipher_aes128 EVP_aes_128_cbc
|
||||
#define libssh2_cipher_aes128ctr EVP_aes_128_ctr
|
||||
#define libssh2_cipher_aes192ctr EVP_aes_192_ctr
|
||||
#define libssh2_cipher_aes256ctr EVP_aes_256_ctr
|
||||
#define libssh2_cipher_blowfish EVP_bf_cbc
|
||||
#define libssh2_cipher_arcfour EVP_rc4
|
||||
#define libssh2_cipher_cast5 EVP_cast5_cbc
|
||||
#define libssh2_cipher_3des EVP_des_ede3_cbc
|
||||
#define libssh2_cipher_chacha20 NULL
|
||||
#define ssh2_cipher_aes256 EVP_aes_256_cbc
|
||||
#define ssh2_cipher_aes192 EVP_aes_192_cbc
|
||||
#define ssh2_cipher_aes128 EVP_aes_128_cbc
|
||||
#define ssh2_cipher_aes128ctr EVP_aes_128_ctr
|
||||
#define ssh2_cipher_aes192ctr EVP_aes_192_ctr
|
||||
#define ssh2_cipher_aes256ctr EVP_aes_256_ctr
|
||||
#define ssh2_cipher_blowfish EVP_bf_cbc
|
||||
#define ssh2_cipher_arcfour EVP_rc4
|
||||
#define ssh2_cipher_cast5 EVP_cast5_cbc
|
||||
#define ssh2_cipher_3des EVP_des_ede3_cbc
|
||||
#define ssh2_cipher_chacha20 NULL
|
||||
|
||||
#ifdef HAVE_OPAQUE_STRUCTS
|
||||
#define _libssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_free(*(ctx))
|
||||
#define ssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_free(*(ctx))
|
||||
#else
|
||||
#define _libssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_cleanup(ctx)
|
||||
#define ssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_cleanup(ctx)
|
||||
#endif
|
||||
|
||||
#define libssh2_bn BIGNUM
|
||||
#define libssh2_bn_ctx BN_CTX
|
||||
#define _libssh2_bn_ctx_new() BN_CTX_new()
|
||||
#define _libssh2_bn_ctx_free(bnctx) BN_CTX_free(bnctx)
|
||||
#define _libssh2_bn_init() BN_new()
|
||||
#define _libssh2_bn_init_from_bin() _libssh2_bn_init()
|
||||
#define _libssh2_bn_set_word(bn, val) !BN_set_word(bn, val)
|
||||
int _libssh2_bn_from_bin(libssh2_bn *bn, size_t len,
|
||||
const unsigned char *val);
|
||||
#define _libssh2_bn_to_bin(bn, val) (BN_bn2bin(bn, val) <= 0)
|
||||
#define _libssh2_bn_bytes(bn) BN_num_bytes(bn)
|
||||
#define _libssh2_bn_bits(bn) BN_num_bits(bn)
|
||||
#define _libssh2_bn_free(bn) BN_clear_free(bn)
|
||||
#define ssh2_bn BIGNUM
|
||||
#define ssh2_bn_ctx BN_CTX
|
||||
#define ssh2_bn_ctx_new() BN_CTX_new()
|
||||
#define ssh2_bn_ctx_free(bnctx) BN_CTX_free(bnctx)
|
||||
#define ssh2_bn_init() BN_new()
|
||||
#define ssh2_bn_init_from_bin() ssh2_bn_init()
|
||||
#define ssh2_bn_set_word(bn, val) !BN_set_word(bn, val)
|
||||
int ssh2_bn_from_bin(ssh2_bn *bn, size_t len, const unsigned char *val);
|
||||
#define ssh2_bn_to_bin(bn, val) (BN_bn2bin(bn, val) <= 0)
|
||||
#define ssh2_bn_bytes(bn) BN_num_bytes(bn)
|
||||
#define ssh2_bn_bits(bn) BN_num_bits(bn)
|
||||
#define ssh2_bn_free(bn) BN_clear_free(bn)
|
||||
|
||||
/* Default generate and safe prime sizes for
|
||||
diffie-hellman-group-exchange-sha1 */
|
||||
#define LIBSSH2_DH_GEX_MINGROUP 2048
|
||||
#define LIBSSH2_DH_GEX_OPTGROUP 4096
|
||||
#define LIBSSH2_DH_GEX_MAXGROUP 8192
|
||||
#define SSH2_DH_GEX_MINGROUP 2048
|
||||
#define SSH2_DH_GEX_OPTGROUP 4096
|
||||
#define SSH2_DH_GEX_MAXGROUP 8192
|
||||
|
||||
#define LIBSSH2_DH_MAX_MODULUS_BITS 16384
|
||||
#define SSH2_DH_MAX_MODULUS_BITS 16384
|
||||
|
||||
#define libssh2_dh_ctx BIGNUM *
|
||||
#define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx)
|
||||
#define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \
|
||||
_libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx)
|
||||
#define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \
|
||||
_libssh2_dh_secret(dhctx, secret, f, p, bnctx)
|
||||
#define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx)
|
||||
void _libssh2_dh_init(libssh2_dh_ctx *dhctx);
|
||||
int _libssh2_dh_key_pair(libssh2_dh_ctx *dhctx, libssh2_bn *public,
|
||||
libssh2_bn *g, libssh2_bn *p,
|
||||
int group_order,
|
||||
libssh2_bn_ctx *bnctx);
|
||||
int _libssh2_dh_secret(libssh2_dh_ctx *dhctx, libssh2_bn *secret,
|
||||
libssh2_bn *f, libssh2_bn *p,
|
||||
libssh2_bn_ctx *bnctx);
|
||||
void _libssh2_dh_dtor(libssh2_dh_ctx *dhctx);
|
||||
#define ssh2_dh_ctx BIGNUM *
|
||||
#define ssh2_dh_init(dhctx) ssh2_ossl_dh_init(dhctx)
|
||||
#define ssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \
|
||||
ssh2_ossl_dh_key_pair(dhctx, public, g, p, group_order, bnctx)
|
||||
#define ssh2_dh_secret(dhctx, secret, f, p, bnctx) \
|
||||
ssh2_ossl_dh_secret(dhctx, secret, f, p, bnctx)
|
||||
#define ssh2_dh_dtor(dhctx) ssh2_ossl_dh_dtor(dhctx)
|
||||
void ssh2_ossl_dh_init(ssh2_dh_ctx *dhctx);
|
||||
int ssh2_ossl_dh_key_pair(ssh2_dh_ctx *dhctx, ssh2_bn *public,
|
||||
ssh2_bn *g, ssh2_bn *p,
|
||||
int group_order,
|
||||
ssh2_bn_ctx *bnctx);
|
||||
int ssh2_ossl_dh_secret(ssh2_dh_ctx *dhctx, ssh2_bn *secret,
|
||||
ssh2_bn *f, ssh2_bn *p,
|
||||
ssh2_bn_ctx *bnctx);
|
||||
void ssh2_ossl_dh_dtor(ssh2_dh_ctx *dhctx);
|
||||
|
||||
int _libssh2_openssl_random(void *buf, size_t len);
|
||||
int ssh2_ossl_random(void *buf, size_t len);
|
||||
|
||||
const EVP_CIPHER *_libssh2_EVP_aes_128_ctr(void);
|
||||
const EVP_CIPHER *_libssh2_EVP_aes_192_ctr(void);
|
||||
const EVP_CIPHER *_libssh2_EVP_aes_256_ctr(void);
|
||||
const EVP_CIPHER *ssh2_EVP_aes_128_ctr(void);
|
||||
const EVP_CIPHER *ssh2_EVP_aes_192_ctr(void);
|
||||
const EVP_CIPHER *ssh2_EVP_aes_256_ctr(void);
|
||||
|
||||
#endif /* LIBSSH2_OPENSSL_H */
|
||||
|
||||
501
src/os400qc3.c
501
src/os400qc3.c
File diff suppressed because it is too large
Load Diff
231
src/os400qc3.h
231
src/os400qc3.h
@@ -40,7 +40,7 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#define LIBSSH2_CRYPTO_ENGINE libssh2_os400qc3
|
||||
#define SSH2_CRYPTO_ENGINE libssh2_os400qc3
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -199,7 +199,7 @@
|
||||
|
||||
#if LIBSSH2_ECDSA
|
||||
#else
|
||||
#define libssh2_ec_key void
|
||||
#define ssh2_ec_key void
|
||||
#endif
|
||||
|
||||
/*******************************************************************
|
||||
@@ -220,7 +220,7 @@ struct os400qc3_bn { /* Big number. */
|
||||
unsigned int length; /* Length of bignum (# bytes). */
|
||||
};
|
||||
|
||||
#define libssh2_bn struct os400qc3_bn
|
||||
#define ssh2_bn struct os400qc3_bn
|
||||
|
||||
struct os400qc3_cipher { /* Algorithm description. */
|
||||
char *fmt; /* Format of Qc3 structure. */
|
||||
@@ -240,118 +240,89 @@ struct os400qc3_dh_ctx { /* Diffie-Hellman context. */
|
||||
*
|
||||
*******************************************************************/
|
||||
|
||||
#define libssh2_crypto_init()
|
||||
#define libssh2_crypto_exit()
|
||||
#define ssh2_crypto_init()
|
||||
#define ssh2_crypto_exit()
|
||||
|
||||
#define libssh2_sha1_ctx Qc3_Format_ALGD0100_T
|
||||
#define libssh2_sha256_ctx Qc3_Format_ALGD0100_T
|
||||
#define libssh2_sha384_ctx Qc3_Format_ALGD0100_T
|
||||
#define libssh2_sha512_ctx Qc3_Format_ALGD0100_T
|
||||
#define libssh2_hmac_ctx struct os400qc3_crypto_ctx
|
||||
#define libssh2_cipher_ctx struct os400qc3_crypto_ctx
|
||||
#define ssh2_sha1_ctx Qc3_Format_ALGD0100_T
|
||||
#define ssh2_sha256_ctx Qc3_Format_ALGD0100_T
|
||||
#define ssh2_sha384_ctx Qc3_Format_ALGD0100_T
|
||||
#define ssh2_sha512_ctx Qc3_Format_ALGD0100_T
|
||||
#define ssh2_hmac_ctx struct os400qc3_crypto_ctx
|
||||
#define ssh2_cipher_ctx struct os400qc3_crypto_ctx
|
||||
|
||||
#define libssh2_sha1_init(x) _libssh2_os400qc3_hash_init(x, Qc3_SHA1)
|
||||
#define libssh2_sha1_update(ctx, data, len) \
|
||||
_libssh2_os400qc3_hash_update(&(ctx), data, len)
|
||||
#define libssh2_sha1_final(ctx, out) \
|
||||
_libssh2_os400qc3_hash_final(&(ctx), out)
|
||||
#define libssh2_sha256_init(x) \
|
||||
_libssh2_os400qc3_hash_init(x, Qc3_SHA256)
|
||||
#define libssh2_sha256_update(ctx, data, len) \
|
||||
_libssh2_os400qc3_hash_update(&(ctx), data, len)
|
||||
#define libssh2_sha256_final(ctx, out) \
|
||||
_libssh2_os400qc3_hash_final(&(ctx), out)
|
||||
#define libssh2_sha256(message, len, out) \
|
||||
_libssh2_os400qc3_hash(message, len, out, Qc3_SHA256)
|
||||
#define libssh2_sha384_init(x) \
|
||||
_libssh2_os400qc3_hash_init(x, Qc3_SHA384)
|
||||
#define libssh2_sha384_update(ctx, data, len) \
|
||||
_libssh2_os400qc3_hash_update(&(ctx), data, len)
|
||||
#define libssh2_sha384_final(ctx, out) \
|
||||
_libssh2_os400qc3_hash_final(&(ctx), out)
|
||||
#define libssh2_sha384(message, len, out) \
|
||||
_libssh2_os400qc3_hash(message, len, out, Qc3_SHA384)
|
||||
#define libssh2_sha512_init(x) \
|
||||
_libssh2_os400qc3_hash_init(x, Qc3_SHA512)
|
||||
#define libssh2_sha512_update(ctx, data, len) \
|
||||
_libssh2_os400qc3_hash_update(&(ctx), data, len)
|
||||
#define libssh2_sha512_final(ctx, out) \
|
||||
_libssh2_os400qc3_hash_final(&(ctx), out)
|
||||
#define libssh2_sha512(message, len, out) \
|
||||
_libssh2_os400qc3_hash(message, len, out, Qc3_SHA512)
|
||||
#define ssh2_sha1_init(x) ssh2_os400qc3_hash_init(x, Qc3_SHA1)
|
||||
#define ssh2_sha1_update(ctx, d, l) ssh2_os400qc3_hash_update(&(ctx), d, l)
|
||||
#define ssh2_sha1_final(ctx, out) ssh2_os400qc3_hash_final(&(ctx), out)
|
||||
#define ssh2_sha256_init(x) ssh2_os400qc3_hash_init(x, Qc3_SHA256)
|
||||
#define ssh2_sha256_update(ctx, d, l) ssh2_os400qc3_hash_update(&(ctx), d, l)
|
||||
#define ssh2_sha256_final(ctx, out) ssh2_os400qc3_hash_final(&(ctx), out)
|
||||
#define ssh2_sha256(d, l, out) ssh2_os400qc3_hash(d, l, out, Qc3_SHA256)
|
||||
#define ssh2_sha384_init(x) ssh2_os400qc3_hash_init(x, Qc3_SHA384)
|
||||
#define ssh2_sha384_update(ctx, d, l) ssh2_os400qc3_hash_update(&(ctx), d, l)
|
||||
#define ssh2_sha384_final(ctx, out) ssh2_os400qc3_hash_final(&(ctx), out)
|
||||
#define ssh2_sha384(d, l, out) ssh2_os400qc3_hash(d, l, out, Qc3_SHA384)
|
||||
#define ssh2_sha512_init(x) ssh2_os400qc3_hash_init(x, Qc3_SHA512)
|
||||
#define ssh2_sha512_update(ctx, d, l) ssh2_os400qc3_hash_update(&(ctx), d, l)
|
||||
#define ssh2_sha512_final(ctx, out) ssh2_os400qc3_hash_final(&(ctx), out)
|
||||
#define ssh2_sha512(d, l, out) ssh2_os400qc3_hash(d, l, out, Qc3_SHA512)
|
||||
|
||||
#if LIBSSH2_MD5 || LIBSSH2_MD5_PEM
|
||||
#define MD5_DIGEST_LENGTH 16
|
||||
#define libssh2_md5_ctx Qc3_Format_ALGD0100_T
|
||||
#define libssh2_md5_init(x) \
|
||||
_libssh2_os400qc3_hash_init(x, Qc3_MD5)
|
||||
#define libssh2_md5_update(ctx, data, len) \
|
||||
_libssh2_os400qc3_hash_update(&(ctx), data, len)
|
||||
#define libssh2_md5_final(ctx, out) \
|
||||
_libssh2_os400qc3_hash_final(&(ctx), out)
|
||||
#define MD5_DIGEST_LENGTH 16
|
||||
#define ssh2_md5_ctx Qc3_Format_ALGD0100_T
|
||||
#define ssh2_md5_init(x) ssh2_os400qc3_hash_init(x, Qc3_MD5)
|
||||
#define ssh2_md5_update(ctx, d, l) ssh2_os400qc3_hash_update(&(ctx), d, l)
|
||||
#define ssh2_md5_final(ctx, out) ssh2_os400qc3_hash_final(&(ctx), out)
|
||||
#endif
|
||||
|
||||
#define libssh2_bn_ctx int /* Not used. */
|
||||
#define ssh2_bn_ctx int /* Not used. */
|
||||
|
||||
#define _libssh2_bn_ctx_new() 0
|
||||
#define _libssh2_bn_ctx_free(bnctx) ((void)0)
|
||||
#define ssh2_bn_ctx_new() 0
|
||||
#define ssh2_bn_ctx_free(bnctx) ((void)0)
|
||||
|
||||
#define _libssh2_bn_init_from_bin() _libssh2_bn_init()
|
||||
#define _libssh2_bn_bytes(bn) ((bn)->length)
|
||||
#define ssh2_bn_init_from_bin() ssh2_bn_init()
|
||||
#define ssh2_bn_bytes(bn) ((bn)->length)
|
||||
|
||||
#define LIBSSH2_CIPHER_T(name) struct os400qc3_cipher name
|
||||
#define libssh2_cipher_aes128 \
|
||||
{ Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CBC, 16 }
|
||||
#define libssh2_cipher_aes192 \
|
||||
{ Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CBC, 24 }
|
||||
#define libssh2_cipher_aes256 \
|
||||
{ Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CBC, 32 }
|
||||
#define libssh2_cipher_aes128ctr \
|
||||
{ Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CTR, 16 }
|
||||
#define libssh2_cipher_aes192ctr \
|
||||
{ Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CTR, 24 }
|
||||
#define libssh2_cipher_aes256ctr \
|
||||
{ Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CTR, 32 }
|
||||
#define libssh2_cipher_3des \
|
||||
{ Qc3_Alg_Block_Cipher, Qc3_TDES, 8, Qc3_CBC, 24 }
|
||||
#define SSH2_CIPHER_T(name) struct os400qc3_cipher name
|
||||
#define ssh2_cipher_aes128 {Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CBC, 16}
|
||||
#define ssh2_cipher_aes192 {Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CBC, 24}
|
||||
#define ssh2_cipher_aes256 {Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CBC, 32}
|
||||
#define ssh2_cipher_aes128ctr {Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CTR, 16}
|
||||
#define ssh2_cipher_aes192ctr {Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CTR, 24}
|
||||
#define ssh2_cipher_aes256ctr {Qc3_Alg_Block_Cipher, Qc3_AES, 16, Qc3_CTR, 32}
|
||||
#define ssh2_cipher_3des {Qc3_Alg_Block_Cipher, Qc3_TDES, 8, Qc3_CBC, 24}
|
||||
/* Nonsense values for chacha20-poly1305 */
|
||||
#define libssh2_cipher_chacha20 \
|
||||
{ Qc3_Alg_Stream_Cipher, Qc3_RC4, 8, 0, 16 }
|
||||
#define libssh2_cipher_arcfour \
|
||||
{ Qc3_Alg_Stream_Cipher, Qc3_RC4, 8, 0, 16 }
|
||||
#define ssh2_cipher_chacha20 {Qc3_Alg_Stream_Cipher, Qc3_RC4, 8, 0, 16}
|
||||
#define ssh2_cipher_arcfour {Qc3_Alg_Stream_Cipher, Qc3_RC4, 8, 0, 16}
|
||||
|
||||
#define _libssh2_cipher_dtor(ctx) _libssh2_os400qc3_crypto_dtor(ctx)
|
||||
#define ssh2_cipher_dtor(ctx) ssh2_os400qc3_crypto_dtor(ctx)
|
||||
|
||||
#define libssh2_rsa_ctx struct os400qc3_crypto_ctx
|
||||
#define _libssh2_rsa_free(ctx) \
|
||||
(_libssh2_os400qc3_crypto_dtor(ctx), free((char *)ctx))
|
||||
#define libssh2_prepare_iovec(vec, len) memset((char *)(vec), 0, \
|
||||
(len) * sizeof(struct iovec))
|
||||
#define _libssh2_rsa_sha1_signv(session, sig, siglen, count, vector, ctx) \
|
||||
_libssh2_os400qc3_rsa_signv(session, Qc3_SHA1, sig, siglen, \
|
||||
count, vector, ctx)
|
||||
#define _libssh2_rsa_sha2_256_signv(session, sig, siglen, cnt, vector, ctx) \
|
||||
_libssh2_os400qc3_rsa_signv(session, Qc3_SHA256, sig, siglen, \
|
||||
cnt, vector, ctx)
|
||||
#define _libssh2_rsa_sha2_512_signv(session, sig, siglen, cnt, vector, ctx) \
|
||||
_libssh2_os400qc3_rsa_signv(session, Qc3_SHA512, sig, siglen, \
|
||||
cnt, vector, ctx)
|
||||
#define ssh2_rsa_ctx struct os400qc3_crypto_ctx
|
||||
#define ssh2_rsa_free(ctx) \
|
||||
(ssh2_os400qc3_crypto_dtor(ctx), free((char *)ctx))
|
||||
#define ssh2_prepare_iovec(vec, len) \
|
||||
memset((char *)(vec), 0, (len) * sizeof(struct iovec))
|
||||
#define ssh2_rsa_sha1_signv(session, sig, siglen, count, vector, ctx) \
|
||||
ssh2_os400qc3_rsa_signv(session, Qc3_SHA1, sig, siglen, count, vector, ctx)
|
||||
#define ssh2_rsa_sha2_256_signv(session, sig, siglen, cnt, vector, ctx) \
|
||||
ssh2_os400qc3_rsa_signv(session, Qc3_SHA256, sig, siglen, cnt, vector, ctx)
|
||||
#define ssh2_rsa_sha2_512_signv(session, sig, siglen, cnt, vector, ctx) \
|
||||
ssh2_os400qc3_rsa_signv(session, Qc3_SHA512, sig, siglen, cnt, vector, ctx)
|
||||
|
||||
/* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1
|
||||
Qc3 is limited to a maximum 2048-bit modulus/key size. */
|
||||
#define LIBSSH2_DH_GEX_MINGROUP 1024
|
||||
#define LIBSSH2_DH_GEX_OPTGROUP 1536
|
||||
#define LIBSSH2_DH_GEX_MAXGROUP 2048
|
||||
#define SSH2_DH_GEX_MINGROUP 1024
|
||||
#define SSH2_DH_GEX_OPTGROUP 1536
|
||||
#define SSH2_DH_GEX_MAXGROUP 2048
|
||||
|
||||
#define LIBSSH2_DH_MAX_MODULUS_BITS 2048
|
||||
#define SSH2_DH_MAX_MODULUS_BITS 2048
|
||||
|
||||
#define libssh2_dh_ctx struct os400qc3_dh_ctx
|
||||
#define libssh2_dh_init(dhctx) _libssh2_os400qc3_dh_init(dhctx)
|
||||
#define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \
|
||||
_libssh2_os400qc3_dh_key_pair(dhctx, public, g, p, group_order)
|
||||
#define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \
|
||||
_libssh2_os400qc3_dh_secret(dhctx, secret, f, p)
|
||||
#define libssh2_dh_dtor(dhctx) _libssh2_os400qc3_dh_dtor(dhctx)
|
||||
#define ssh2_dh_ctx struct os400qc3_dh_ctx
|
||||
#define ssh2_dh_init(dhctx) ssh2_os400qc3_dh_init(dhctx)
|
||||
#define ssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \
|
||||
ssh2_os400qc3_dh_key_pair(dhctx, public, g, p, group_order)
|
||||
#define ssh2_dh_secret(dhctx, secret, f, p, bnctx) \
|
||||
ssh2_os400qc3_dh_secret(dhctx, secret, f, p)
|
||||
#define ssh2_dh_dtor(dhctx) ssh2_os400qc3_dh_dtor(dhctx)
|
||||
|
||||
/*******************************************************************
|
||||
*
|
||||
@@ -359,40 +330,36 @@ struct os400qc3_dh_ctx { /* Diffie-Hellman context. */
|
||||
*
|
||||
*******************************************************************/
|
||||
|
||||
libssh2_bn *_libssh2_bn_init(void);
|
||||
void_libssh2_bn_free(libssh2_bn *bn);
|
||||
unsigned long _libssh2_bn_bits(libssh2_bn *bn);
|
||||
int _libssh2_bn_from_bin(libssh2_bn *bn, size_t len,
|
||||
const unsigned char *v);
|
||||
int _libssh2_bn_set_word(libssh2_bn *bn, unsigned long val);
|
||||
int _libssh2_bn_to_bin(libssh2_bn *bn, unsigned char *val);
|
||||
int _libssh2_random(unsigned char *buf, size_t len);
|
||||
void _libssh2_os400qc3_crypto_dtor(struct os400qc3_crypto_ctx *x);
|
||||
int _libssh2_os400qc3_hash_init(Qc3_Format_ALGD0100_T *x,
|
||||
unsigned int algo);
|
||||
int _libssh2_os400qc3_hash_update(Qc3_Format_ALGD0100_T *ctx,
|
||||
const unsigned char *data,
|
||||
int len);
|
||||
int _libssh2_os400qc3_hash_final(Qc3_Format_ALGD0100_T *ctx,
|
||||
unsigned char *out);
|
||||
int _libssh2_os400qc3_hash(const unsigned char *message,
|
||||
unsigned long len, unsigned char *out,
|
||||
unsigned int algo);
|
||||
int _libssh2_os400qc3_rsa_signv(LIBSSH2_SESSION *session, int algo,
|
||||
unsigned char **signature,
|
||||
size_t *signature_len,
|
||||
int veccount,
|
||||
const struct iovec vector[],
|
||||
libssh2_rsa_ctx *ctx);
|
||||
void _libssh2_os400qc3_dh_init(libssh2_dh_ctx *dhctx);
|
||||
int _libssh2_os400qc3_dh_key_pair(libssh2_dh_ctx *dhctx,
|
||||
libssh2_bn *public,
|
||||
libssh2_bn *g,
|
||||
libssh2_bn *p, int group_order);
|
||||
int _libssh2_os400qc3_dh_secret(libssh2_dh_ctx *dhctx,
|
||||
libssh2_bn *secret,
|
||||
libssh2_bn *f, libssh2_bn *p);
|
||||
void _libssh2_os400qc3_dh_dtor(libssh2_dh_ctx *dhctx);
|
||||
ssh2_bn *ssh2_bn_init(void);
|
||||
voidssh2_bn_free(ssh2_bn *bn);
|
||||
unsigned long ssh2_bn_bits(ssh2_bn *bn);
|
||||
int ssh2_bn_from_bin(ssh2_bn *bn, size_t len, const unsigned char *v);
|
||||
int ssh2_bn_set_word(ssh2_bn *bn, unsigned long val);
|
||||
int ssh2_bn_to_bin(ssh2_bn *bn, unsigned char *val);
|
||||
int ssh2_random(unsigned char *buf, size_t len);
|
||||
void ssh2_os400qc3_crypto_dtor(struct os400qc3_crypto_ctx *x);
|
||||
int ssh2_os400qc3_hash_init(Qc3_Format_ALGD0100_T *x, unsigned int algo);
|
||||
int ssh2_os400qc3_hash_update(Qc3_Format_ALGD0100_T *ctx,
|
||||
const unsigned char *data, int len);
|
||||
int ssh2_os400qc3_hash_final(Qc3_Format_ALGD0100_T *ctx, unsigned char *out);
|
||||
int ssh2_os400qc3_hash(const unsigned char *message,
|
||||
unsigned long len, unsigned char *out,
|
||||
unsigned int algo);
|
||||
int ssh2_os400qc3_rsa_signv(LIBSSH2_SESSION *session, int algo,
|
||||
unsigned char **signature,
|
||||
size_t *signature_len,
|
||||
int veccount,
|
||||
const struct iovec vector[],
|
||||
ssh2_rsa_ctx *ctx);
|
||||
void ssh2_os400qc3_dh_init(ssh2_dh_ctx *dhctx);
|
||||
int ssh2_os400qc3_dh_key_pair(ssh2_dh_ctx *dhctx,
|
||||
ssh2_bn *public,
|
||||
ssh2_bn *g,
|
||||
ssh2_bn *p, int group_order);
|
||||
int ssh2_os400qc3_dh_secret(ssh2_dh_ctx *dhctx,
|
||||
ssh2_bn *secret,
|
||||
ssh2_bn *f, ssh2_bn *p);
|
||||
void ssh2_os400qc3_dh_dtor(ssh2_dh_ctx *dhctx);
|
||||
|
||||
#endif /* LIBSSH2_OS400QC3_H */
|
||||
|
||||
|
||||
1087
src/packet.c
1087
src/packet.c
File diff suppressed because it is too large
Load Diff
53
src/packet.h
53
src/packet.h
@@ -40,38 +40,37 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
int _libssh2_packet_read(LIBSSH2_SESSION *session);
|
||||
int ssh2_packet_read(LIBSSH2_SESSION *session);
|
||||
|
||||
int _libssh2_packet_ask(LIBSSH2_SESSION *session, unsigned char packet_type,
|
||||
unsigned char **data, size_t *data_len,
|
||||
int match_ofs,
|
||||
int ssh2_packet_ask(LIBSSH2_SESSION *session, unsigned char packet_type,
|
||||
unsigned char **data, size_t *data_len,
|
||||
int match_ofs,
|
||||
const unsigned char *match_buf,
|
||||
size_t match_len);
|
||||
|
||||
int ssh2_packet_askv(LIBSSH2_SESSION *session,
|
||||
const unsigned char *packet_types,
|
||||
unsigned char **data, size_t *data_len,
|
||||
int match_ofs,
|
||||
const unsigned char *match_buf,
|
||||
size_t match_len);
|
||||
int ssh2_packet_require(LIBSSH2_SESSION *session,
|
||||
unsigned char packet_type, unsigned char **data,
|
||||
size_t *data_len, int match_ofs,
|
||||
const unsigned char *match_buf,
|
||||
size_t match_len);
|
||||
|
||||
int _libssh2_packet_askv(LIBSSH2_SESSION *session,
|
||||
size_t match_len,
|
||||
struct packet_require_state *state);
|
||||
int ssh2_packet_requirev(LIBSSH2_SESSION *session,
|
||||
const unsigned char *packet_types,
|
||||
unsigned char **data, size_t *data_len,
|
||||
int match_ofs,
|
||||
const unsigned char *match_buf,
|
||||
size_t match_len);
|
||||
int _libssh2_packet_require(LIBSSH2_SESSION *session,
|
||||
unsigned char packet_type, unsigned char **data,
|
||||
size_t *data_len, int match_ofs,
|
||||
const unsigned char *match_buf,
|
||||
size_t match_len,
|
||||
struct packet_require_state *state);
|
||||
int _libssh2_packet_requirev(LIBSSH2_SESSION *session,
|
||||
const unsigned char *packet_types,
|
||||
unsigned char **data, size_t *data_len,
|
||||
int match_ofs,
|
||||
const unsigned char *match_buf,
|
||||
size_t match_len,
|
||||
struct packet_requirev_state *state);
|
||||
int _libssh2_packet_burn(LIBSSH2_SESSION *session,
|
||||
libssh2_nonblocking_states *state);
|
||||
int _libssh2_packet_write(LIBSSH2_SESSION *session, unsigned char *data,
|
||||
unsigned long data_len);
|
||||
int _libssh2_packet_add(LIBSSH2_SESSION *session, unsigned char *data,
|
||||
size_t datalen, int macstate, uint32_t seq);
|
||||
size_t match_len,
|
||||
struct packet_requirev_state *state);
|
||||
int ssh2_packet_burn(LIBSSH2_SESSION *session, ssh2_NB_states *state);
|
||||
int ssh2_packet_write(LIBSSH2_SESSION *session, unsigned char *data,
|
||||
unsigned long data_len);
|
||||
int ssh2_packet_add(LIBSSH2_SESSION *session, unsigned char *data,
|
||||
size_t datalen, int macstate, uint32_t seq);
|
||||
|
||||
#endif /* LIBSSH2_PACKET_H */
|
||||
|
||||
386
src/pem.c
386
src/pem.c
@@ -104,11 +104,11 @@ static unsigned char hex_decode(char digit)
|
||||
((digit >= 'A') ? (0xA + (digit - 'A')) : (digit - '0'));
|
||||
}
|
||||
|
||||
int _libssh2_pem_parse(LIBSSH2_SESSION *session,
|
||||
const char *headerbegin,
|
||||
const char *headerend,
|
||||
const unsigned char *passphrase,
|
||||
FILE *fp, unsigned char **data, size_t *datalen)
|
||||
int ssh2_pem_parse(LIBSSH2_SESSION *session,
|
||||
const char *headerbegin,
|
||||
const char *headerend,
|
||||
const unsigned char *passphrase,
|
||||
FILE *fp, unsigned char **data, size_t *datalen)
|
||||
{
|
||||
int ret = -1;
|
||||
char *filedata = NULL;
|
||||
@@ -116,62 +116,61 @@ int _libssh2_pem_parse(LIBSSH2_SESSION *session,
|
||||
size_t filedata_len;
|
||||
|
||||
if(fseek(fp, 0L, SEEK_END) != 0) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||
"Bad seek to file end in PEM parsing");
|
||||
ssh2_err(session, LIBSSH2_ERROR_FILE,
|
||||
"Bad seek to file end in PEM parsing");
|
||||
goto out;
|
||||
}
|
||||
file_size = ftell(fp);
|
||||
if(file_size < 0) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||
"Error determining size in PEM parsing");
|
||||
ssh2_err(session, LIBSSH2_ERROR_FILE,
|
||||
"Error determining size in PEM parsing");
|
||||
goto out;
|
||||
}
|
||||
if(file_size == 0) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||
"Zero-length file in PEM parsing");
|
||||
ssh2_err(session, LIBSSH2_ERROR_FILE,
|
||||
"Zero-length file in PEM parsing");
|
||||
goto out;
|
||||
}
|
||||
if(file_size > (1024 * 1024)) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||
"Input too large in PEM parsing");
|
||||
ssh2_err(session, LIBSSH2_ERROR_FILE,
|
||||
"Input too large in PEM parsing");
|
||||
goto out;
|
||||
}
|
||||
if(fseek(fp, 0L, SEEK_SET) != 0) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_FILE,
|
||||
"Bad seek to 0 in PEM parsing");
|
||||
ssh2_err(session, LIBSSH2_ERROR_FILE, "Bad seek to 0 in PEM parsing");
|
||||
goto out;
|
||||
}
|
||||
|
||||
filedata_len = (size_t)file_size;
|
||||
filedata = LIBSSH2_ALLOC(session, filedata_len);
|
||||
filedata = SSH2_ALLOC(session, filedata_len);
|
||||
if(!filedata) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for PEM parsing");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for PEM parsing");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(fread(filedata, 1, filedata_len, fp) != filedata_len) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_FILE, "Bad read in PEM parsing");
|
||||
ssh2_err(session, LIBSSH2_ERROR_FILE, "Bad read in PEM parsing");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = _libssh2_pem_parse_memory(session, headerbegin, headerend,
|
||||
passphrase, filedata, filedata_len,
|
||||
data, datalen);
|
||||
ret = ssh2_pem_parse_memory(session, headerbegin, headerend,
|
||||
passphrase, filedata, filedata_len,
|
||||
data, datalen);
|
||||
|
||||
out:
|
||||
if(filedata) {
|
||||
LIBSSH2_FREE(session, filedata);
|
||||
SSH2_FREE(session, filedata);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _libssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
const char *headerbegin,
|
||||
const char *headerend,
|
||||
const unsigned char *passphrase,
|
||||
const char *filedata, size_t filedata_len,
|
||||
unsigned char **data, size_t *datalen)
|
||||
int ssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
const char *headerbegin,
|
||||
const char *headerend,
|
||||
const unsigned char *passphrase,
|
||||
const char *filedata, size_t filedata_len,
|
||||
unsigned char **data, size_t *datalen)
|
||||
{
|
||||
char line[LINE_SIZE];
|
||||
unsigned char iv[LINE_SIZE];
|
||||
@@ -206,7 +205,7 @@ int _libssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
goto out;
|
||||
}
|
||||
|
||||
all_methods = libssh2_crypt_methods();
|
||||
all_methods = ssh2_crypt_methods();
|
||||
/* !checksrc! disable EQUALSNULL 1 */
|
||||
while((cur_method = *all_methods++) != NULL) {
|
||||
if(*cur_method->pem_annotation &&
|
||||
@@ -220,8 +219,8 @@ int _libssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
|
||||
/* None of the available crypt methods were able to decrypt the key */
|
||||
if(!method) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALGO_UNSUPPORTED,
|
||||
"Unable to decrypt PEM, unsupported algorithm");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALGO_UNSUPPORTED,
|
||||
"Unable to decrypt PEM, unsupported algorithm");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
@@ -247,10 +246,10 @@ int _libssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
size_t linelen;
|
||||
|
||||
linelen = strlen(line);
|
||||
tmp = LIBSSH2_REALLOC(session, b64data, b64datalen + linelen);
|
||||
tmp = SSH2_REALLOC(session, b64data, b64datalen + linelen);
|
||||
if(!tmp) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for PEM parsing");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for PEM parsing");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
@@ -271,15 +270,15 @@ int _libssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(_libssh2_base64_decode(session, (char **)data, datalen,
|
||||
b64data, b64datalen)) {
|
||||
if(ssh2_base64_decode(session, (char **)data, datalen,
|
||||
b64data, b64datalen)) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(*datalen == 0) {
|
||||
/* Invalid decode */
|
||||
LIBSSH2_FREE(session, *data);
|
||||
SSH2_FREE(session, *data);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
@@ -292,26 +291,26 @@ int _libssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
int blocksize = method->blocksize;
|
||||
void *abstract;
|
||||
unsigned char secret[2 * MD5_DIGEST_LENGTH];
|
||||
libssh2_md5_ctx fingerprint_ctx;
|
||||
ssh2_md5_ctx fingerprint_ctx;
|
||||
|
||||
/* Perform key derivation (PBKDF1/MD5) */
|
||||
if(!libssh2_md5_init(&fingerprint_ctx) ||
|
||||
!libssh2_md5_update(fingerprint_ctx, passphrase,
|
||||
strlen((const char *)passphrase)) ||
|
||||
!libssh2_md5_update(fingerprint_ctx, iv, 8) ||
|
||||
!libssh2_md5_final(fingerprint_ctx, secret)) {
|
||||
if(!ssh2_md5_init(&fingerprint_ctx) ||
|
||||
!ssh2_md5_update(fingerprint_ctx, passphrase,
|
||||
strlen((const char *)passphrase)) ||
|
||||
!ssh2_md5_update(fingerprint_ctx, iv, 8) ||
|
||||
!ssh2_md5_final(fingerprint_ctx, secret)) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
if(method->secret_len > MD5_DIGEST_LENGTH) {
|
||||
if(!libssh2_md5_init(&fingerprint_ctx) ||
|
||||
!libssh2_md5_update(fingerprint_ctx, secret,
|
||||
MD5_DIGEST_LENGTH) ||
|
||||
!libssh2_md5_update(fingerprint_ctx, passphrase,
|
||||
strlen((const char *)passphrase)) ||
|
||||
!libssh2_md5_update(fingerprint_ctx, iv, 8) ||
|
||||
!libssh2_md5_final(fingerprint_ctx,
|
||||
secret + MD5_DIGEST_LENGTH)) {
|
||||
if(!ssh2_md5_init(&fingerprint_ctx) ||
|
||||
!ssh2_md5_update(fingerprint_ctx, secret,
|
||||
MD5_DIGEST_LENGTH) ||
|
||||
!ssh2_md5_update(fingerprint_ctx, passphrase,
|
||||
strlen((const char *)passphrase)) ||
|
||||
!ssh2_md5_update(fingerprint_ctx, iv, 8) ||
|
||||
!ssh2_md5_final(fingerprint_ctx,
|
||||
secret + MD5_DIGEST_LENGTH)) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
@@ -320,34 +319,34 @@ int _libssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
/* Initialize the decryption */
|
||||
if(method->init(session, method, iv, &free_iv, secret, &free_secret, 0,
|
||||
&abstract)) {
|
||||
_libssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
_libssh2_explicit_zero(*data, *datalen);
|
||||
LIBSSH2_FREE(session, *data);
|
||||
ssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
ssh2_explicit_zero(*data, *datalen);
|
||||
SSH2_FREE(session, *data);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(free_secret) {
|
||||
_libssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
ssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
}
|
||||
|
||||
/* Do the actual decryption */
|
||||
if((*datalen % blocksize) != 0) {
|
||||
_libssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
ssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
method->dtor(session, &abstract);
|
||||
_libssh2_explicit_zero(*data, *datalen);
|
||||
LIBSSH2_FREE(session, *data);
|
||||
ssh2_explicit_zero(*data, *datalen);
|
||||
SSH2_FREE(session, *data);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(method->flags & LIBSSH2_CRYPT_FLAG_REQUIRES_FULL_PACKET) {
|
||||
if(method->flags & SSH2_CRYPT_FLAG_REQUIRES_FULL_PACKET) {
|
||||
if(method->crypt(session, 0, *data, *datalen, &abstract, 0)) {
|
||||
ret = LIBSSH2_ERROR_DECRYPT;
|
||||
_libssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
ssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
method->dtor(session, &abstract);
|
||||
_libssh2_explicit_zero(*data, *datalen);
|
||||
LIBSSH2_FREE(session, *data);
|
||||
ssh2_explicit_zero(*data, *datalen);
|
||||
SSH2_FREE(session, *data);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@@ -362,10 +361,10 @@ int _libssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
? LAST_BLOCK
|
||||
: MIDDLE_BLOCK))) {
|
||||
ret = LIBSSH2_ERROR_DECRYPT;
|
||||
_libssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
ssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
method->dtor(session, &abstract);
|
||||
_libssh2_explicit_zero(*data, *datalen);
|
||||
LIBSSH2_FREE(session, *data);
|
||||
ssh2_explicit_zero(*data, *datalen);
|
||||
SSH2_FREE(session, *data);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -378,19 +377,19 @@ int _libssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
if(padding > *datalen) {
|
||||
/* Invalid padding len */
|
||||
ret = LIBSSH2_ERROR_DECRYPT;
|
||||
_libssh2_explicit_zero(*data, *datalen);
|
||||
LIBSSH2_FREE(session, *data);
|
||||
ssh2_explicit_zero(*data, *datalen);
|
||||
SSH2_FREE(session, *data);
|
||||
goto out;
|
||||
}
|
||||
memset(&(*data)[*datalen - padding], 0, padding);
|
||||
*datalen -= padding;
|
||||
|
||||
/* Clean up */
|
||||
_libssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
ssh2_explicit_zero((char *)secret, sizeof(secret));
|
||||
method->dtor(session, &abstract);
|
||||
#else
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALGO_UNSUPPORTED,
|
||||
"Unable to decrypt PEM, MD5 not enabled");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALGO_UNSUPPORTED,
|
||||
"Unable to decrypt PEM, MD5 not enabled");
|
||||
ret = -1;
|
||||
goto out;
|
||||
#endif
|
||||
@@ -399,8 +398,8 @@ int _libssh2_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
ret = 0;
|
||||
out:
|
||||
if(b64data) {
|
||||
_libssh2_explicit_zero(b64data, b64datalen);
|
||||
LIBSSH2_FREE(session, b64data);
|
||||
ssh2_explicit_zero(b64data, b64datalen);
|
||||
SSH2_FREE(session, b64data);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -410,11 +409,11 @@ out:
|
||||
#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
|
||||
#define OPENSSH_HEADER_END "-----END OPENSSH PRIVATE KEY-----"
|
||||
|
||||
static int _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
const char *b64data,
|
||||
size_t b64datalen,
|
||||
struct string_buf **decrypted_buf)
|
||||
static int ssh2_openssh_pem_parse_data(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
const char *b64data,
|
||||
size_t b64datalen,
|
||||
struct string_buf **decrypted_buf)
|
||||
{
|
||||
const struct crypt_method *method = NULL;
|
||||
struct string_buf decoded, decrypted, kdf_buf;
|
||||
@@ -437,8 +436,7 @@ static int _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION *session,
|
||||
*decrypted_buf = NULL;
|
||||
|
||||
/* decode file */
|
||||
if(_libssh2_base64_decode(session, (char **)&f, &f_len,
|
||||
b64data, b64datalen)) {
|
||||
if(ssh2_base64_decode(session, (char **)&f, &f_len, b64data, b64datalen)) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
@@ -449,35 +447,31 @@ static int _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION *session,
|
||||
decoded.len = f_len;
|
||||
|
||||
if(decoded.len < strlen(AUTH_MAGIC)) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, "key too short");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO, "key too short");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(strncmp((const char *)decoded.dataptr, AUTH_MAGIC,
|
||||
strlen(AUTH_MAGIC)) != 0) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"key auth magic mismatch");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"key auth magic mismatch");
|
||||
goto out;
|
||||
}
|
||||
|
||||
decoded.dataptr += strlen(AUTH_MAGIC) + 1;
|
||||
|
||||
if(_libssh2_get_string(&decoded, &ciphername, &tmp_len) ||
|
||||
tmp_len == 0) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"ciphername is missing");
|
||||
if(ssh2_get_string(&decoded, &ciphername, &tmp_len) || tmp_len == 0) {
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO, "ciphername is missing");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(_libssh2_get_string(&decoded, &kdfname, &tmp_len) ||
|
||||
tmp_len == 0) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"kdfname is missing");
|
||||
if(ssh2_get_string(&decoded, &kdfname, &tmp_len) || tmp_len == 0) {
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO, "kdfname is missing");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(_libssh2_get_string(&decoded, &kdf, &kdf_len)) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, "kdf is missing");
|
||||
if(ssh2_get_string(&decoded, &kdf, &kdf_len)) {
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO, "kdf is missing");
|
||||
goto out;
|
||||
}
|
||||
else {
|
||||
@@ -495,34 +489,33 @@ static int _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION *session,
|
||||
|
||||
if(strcmp((const char *)kdfname, "none") != 0 &&
|
||||
strcmp((const char *)kdfname, "bcrypt") != 0) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, "unknown cipher");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO, "unknown cipher");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(!strcmp((const char *)kdfname, "none") &&
|
||||
strcmp((const char *)ciphername, "none") != 0) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, "invalid format");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO, "invalid format");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(_libssh2_get_u32(&decoded, &nkeys) != 0 || nkeys != 1) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Multiple keys are unsupported");
|
||||
if(ssh2_get_u32(&decoded, &nkeys) != 0 || nkeys != 1) {
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Multiple keys are unsupported");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* unencrypted public key */
|
||||
|
||||
if(_libssh2_get_string(&decoded, &buf, &tmp_len) || tmp_len == 0) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Invalid private key; "
|
||||
"expect embedded public key");
|
||||
if(ssh2_get_string(&decoded, &buf, &tmp_len) || tmp_len == 0) {
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Invalid private key; expect embedded public key");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(_libssh2_get_string(&decoded, &buf, &tmp_len) || tmp_len == 0) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Private key data not found");
|
||||
if(ssh2_get_string(&decoded, &buf, &tmp_len) || tmp_len == 0) {
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Private key data not found");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -533,21 +526,20 @@ static int _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION *session,
|
||||
if(ciphername && strcmp((const char *)ciphername, "none") != 0) {
|
||||
const struct crypt_method **all_methods, *cur_method;
|
||||
|
||||
all_methods = libssh2_crypt_methods();
|
||||
all_methods = ssh2_crypt_methods();
|
||||
/* !checksrc! disable EQUALSNULL 1 */
|
||||
while((cur_method = *all_methods++) != NULL) {
|
||||
if(*cur_method->name &&
|
||||
memcmp(ciphername, cur_method->name,
|
||||
strlen(cur_method->name)) == 0) {
|
||||
method = cur_method;
|
||||
}
|
||||
if(*cur_method->name && memcmp(ciphername, cur_method->name,
|
||||
strlen(cur_method->name)) == 0) {
|
||||
method = cur_method;
|
||||
}
|
||||
}
|
||||
|
||||
/* None of the available crypt methods were able to decrypt the key */
|
||||
|
||||
if(!method) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"No supported cipher found");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"No supported cipher found");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@@ -561,50 +553,50 @@ static int _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION *session,
|
||||
ivlen = method->iv_len;
|
||||
total_len = keylen + ivlen;
|
||||
|
||||
key = LIBSSH2_CALLOC(session, total_len);
|
||||
key = SSH2_CALLOC(session, total_len);
|
||||
if(!key) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Could not alloc key");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Could not alloc key");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(strcmp((const char *)kdfname, "bcrypt") == 0 && passphrase) {
|
||||
if((_libssh2_get_string(&kdf_buf, &salt, &salt_len)) ||
|
||||
(_libssh2_get_u32(&kdf_buf, &rounds) != 0)) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"kdf contains unexpected values");
|
||||
if((ssh2_get_string(&kdf_buf, &salt, &salt_len)) ||
|
||||
(ssh2_get_u32(&kdf_buf, &rounds) != 0)) {
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"kdf contains unexpected values");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(_libssh2_bcrypt_pbkdf((const char *)passphrase,
|
||||
strlen((const char *)passphrase),
|
||||
salt, salt_len, key,
|
||||
keylen + ivlen, rounds) < 0) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_DECRYPT,
|
||||
"invalid format");
|
||||
if(ssh2_bcrypt_pbkdf((const char *)passphrase,
|
||||
strlen((const char *)passphrase),
|
||||
salt, salt_len, key,
|
||||
keylen + ivlen, rounds) < 0) {
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_DECRYPT,
|
||||
"invalid format");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_KEYFILE_AUTH_FAILED,
|
||||
"bcrypted without passphrase");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_KEYFILE_AUTH_FAILED,
|
||||
"bcrypted without passphrase");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Set up decryption */
|
||||
blocksize = method->blocksize;
|
||||
|
||||
key_part = LIBSSH2_CALLOC(session, keylen);
|
||||
key_part = SSH2_CALLOC(session, keylen);
|
||||
if(!key_part) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Could not alloc key part");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Could not alloc key part");
|
||||
goto out;
|
||||
}
|
||||
|
||||
iv_part = LIBSSH2_CALLOC(session, ivlen);
|
||||
iv_part = SSH2_CALLOC(session, ivlen);
|
||||
if(!iv_part) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Could not alloc iv part");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Could not alloc iv part");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -625,7 +617,7 @@ static int _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION *session,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(method->flags & LIBSSH2_CRYPT_FLAG_REQUIRES_FULL_PACKET) {
|
||||
if(method->flags & SSH2_CRYPT_FLAG_REQUIRES_FULL_PACKET) {
|
||||
if(method->crypt(session, 0, decrypted.data,
|
||||
decrypted.len,
|
||||
&abstract,
|
||||
@@ -662,16 +654,16 @@ static int _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION *session,
|
||||
* appended to the encrypted key */
|
||||
if(strcmp(method->name, "aes256-gcm@openssh.com") == 0 ||
|
||||
strcmp(method->name, "aes128-gcm@openssh.com") == 0) {
|
||||
if(!_libssh2_check_length(&decoded, 16)) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"GCM auth tag missing");
|
||||
if(!ssh2_check_length(&decoded, 16)) {
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"GCM auth tag missing");
|
||||
method->dtor(session, &abstract);
|
||||
goto out;
|
||||
}
|
||||
if(method->crypt(session, 0, decoded.dataptr, 16, &abstract,
|
||||
LAST_BLOCK)) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_DECRYPT,
|
||||
"GCM auth tag invalid");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_DECRYPT,
|
||||
"GCM auth tag invalid");
|
||||
method->dtor(session, &abstract);
|
||||
goto out;
|
||||
}
|
||||
@@ -684,31 +676,29 @@ static int _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION *session,
|
||||
|
||||
/* Check random bytes match */
|
||||
|
||||
if(_libssh2_get_u32(&decrypted, &check1) != 0 ||
|
||||
_libssh2_get_u32(&decrypted, &check2) != 0 ||
|
||||
if(ssh2_get_u32(&decrypted, &check1) != 0 ||
|
||||
ssh2_get_u32(&decrypted, &check2) != 0 ||
|
||||
check1 != check2) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Private key unpack failed (correct password?)");
|
||||
ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Private key unpack failed (correct password?)");
|
||||
ret = LIBSSH2_ERROR_KEYFILE_AUTH_FAILED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(decrypted_buf) {
|
||||
/* copy data to out-going buffer */
|
||||
struct string_buf *out_buf = _libssh2_string_buf_new(session);
|
||||
struct string_buf *out_buf = ssh2_string_buf_new(session);
|
||||
if(!out_buf) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"decrypted struct");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for decrypted struct");
|
||||
goto out;
|
||||
}
|
||||
|
||||
out_buf->data = LIBSSH2_CALLOC(session, decrypted.len);
|
||||
out_buf->data = SSH2_CALLOC(session, decrypted.len);
|
||||
if(!out_buf->data) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"decrypted struct");
|
||||
_libssh2_string_buf_free(session, out_buf);
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for decrypted struct");
|
||||
ssh2_string_buf_free(session, out_buf);
|
||||
goto out;
|
||||
}
|
||||
memcpy(out_buf->data, decrypted.data, decrypted.len);
|
||||
@@ -723,28 +713,28 @@ out:
|
||||
|
||||
/* Clean up */
|
||||
if(key) {
|
||||
_libssh2_explicit_zero(key, total_len);
|
||||
LIBSSH2_FREE(session, key);
|
||||
ssh2_explicit_zero(key, total_len);
|
||||
SSH2_FREE(session, key);
|
||||
}
|
||||
if(key_part) {
|
||||
_libssh2_explicit_zero(key_part, keylen);
|
||||
LIBSSH2_FREE(session, key_part);
|
||||
ssh2_explicit_zero(key_part, keylen);
|
||||
SSH2_FREE(session, key_part);
|
||||
}
|
||||
if(iv_part) {
|
||||
_libssh2_explicit_zero(iv_part, ivlen);
|
||||
LIBSSH2_FREE(session, iv_part);
|
||||
ssh2_explicit_zero(iv_part, ivlen);
|
||||
SSH2_FREE(session, iv_part);
|
||||
}
|
||||
if(f) {
|
||||
_libssh2_explicit_zero(f, f_len);
|
||||
LIBSSH2_FREE(session, f);
|
||||
ssh2_explicit_zero(f, f_len);
|
||||
SSH2_FREE(session, f);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _libssh2_openssh_pem_parse(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
FILE *fp, struct string_buf **decrypted_buf)
|
||||
int ssh2_openssh_pem_parse(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
FILE *fp, struct string_buf **decrypted_buf)
|
||||
{
|
||||
char line[LINE_SIZE];
|
||||
char *b64data = NULL;
|
||||
@@ -771,10 +761,10 @@ int _libssh2_openssh_pem_parse(LIBSSH2_SESSION *session,
|
||||
size_t linelen;
|
||||
|
||||
linelen = strlen(line);
|
||||
tmp = LIBSSH2_REALLOC(session, b64data, b64datalen + linelen);
|
||||
tmp = SSH2_REALLOC(session, b64data, b64datalen + linelen);
|
||||
if(!tmp) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for PEM parsing");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for PEM parsing");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
@@ -795,15 +785,15 @@ int _libssh2_openssh_pem_parse(LIBSSH2_SESSION *session,
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = _libssh2_openssh_pem_parse_data(session,
|
||||
passphrase,
|
||||
(const char *)b64data,
|
||||
b64datalen,
|
||||
decrypted_buf);
|
||||
ret = ssh2_openssh_pem_parse_data(session,
|
||||
passphrase,
|
||||
(const char *)b64data,
|
||||
b64datalen,
|
||||
decrypted_buf);
|
||||
|
||||
if(b64data) {
|
||||
_libssh2_explicit_zero(b64data, b64datalen);
|
||||
LIBSSH2_FREE(session, b64data);
|
||||
ssh2_explicit_zero(b64data, b64datalen);
|
||||
SSH2_FREE(session, b64data);
|
||||
}
|
||||
|
||||
out:
|
||||
@@ -811,11 +801,11 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
struct string_buf **decrypted_buf)
|
||||
int ssh2_openssh_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
const unsigned char *passphrase,
|
||||
const char *filedata,
|
||||
size_t filedata_len,
|
||||
struct string_buf **decrypted_buf)
|
||||
{
|
||||
char line[LINE_SIZE];
|
||||
char *b64data = NULL;
|
||||
@@ -824,17 +814,16 @@ int _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
int ret;
|
||||
|
||||
if(!filedata || filedata_len <= 0)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Error parsing PEM: filedata missing");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Error parsing PEM: filedata missing");
|
||||
|
||||
do {
|
||||
|
||||
*line = '\0';
|
||||
|
||||
if(off >= filedata_len)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Error parsing PEM: "
|
||||
"OpenSSH header not found");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Error parsing PEM: OpenSSH header not found");
|
||||
|
||||
if(readline_memory(line, LINE_SIZE, filedata, filedata_len, &off)) {
|
||||
return -1;
|
||||
@@ -849,11 +838,10 @@ int _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
size_t linelen;
|
||||
|
||||
linelen = strlen(line);
|
||||
tmp = LIBSSH2_REALLOC(session, b64data, b64datalen + linelen);
|
||||
tmp = SSH2_REALLOC(session, b64data, b64datalen + linelen);
|
||||
if(!tmp) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"PEM parsing");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for PEM parsing");
|
||||
goto out;
|
||||
}
|
||||
memcpy(tmp + b64datalen, line, linelen);
|
||||
@@ -864,8 +852,8 @@ int _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
*line = '\0';
|
||||
|
||||
if(off >= filedata_len) {
|
||||
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Error parsing PEM: offset out of bounds");
|
||||
ret = ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Error parsing PEM: offset out of bounds");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -876,16 +864,16 @@ int _libssh2_openssh_pem_parse_memory(LIBSSH2_SESSION *session,
|
||||
} while(strcmp(line, OPENSSH_HEADER_END) != 0);
|
||||
|
||||
if(!b64data)
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
|
||||
"Error parsing PEM: base 64 data missing");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_PROTO,
|
||||
"Error parsing PEM: base 64 data missing");
|
||||
|
||||
ret = _libssh2_openssh_pem_parse_data(session, passphrase, b64data,
|
||||
b64datalen, decrypted_buf);
|
||||
ret = ssh2_openssh_pem_parse_data(session, passphrase, b64data,
|
||||
b64datalen, decrypted_buf);
|
||||
|
||||
out:
|
||||
if(b64data) {
|
||||
_libssh2_explicit_zero(b64data, b64datalen);
|
||||
LIBSSH2_FREE(session, b64data);
|
||||
ssh2_explicit_zero(b64data, b64datalen);
|
||||
SSH2_FREE(session, b64data);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -924,7 +912,7 @@ static int read_asn1_length(const unsigned char *data,
|
||||
return nextpos;
|
||||
}
|
||||
|
||||
int _libssh2_pem_decode_sequence(unsigned char **data, size_t *datalen)
|
||||
int ssh2_pem_decode_sequence(unsigned char **data, size_t *datalen)
|
||||
{
|
||||
size_t len;
|
||||
int lenlen;
|
||||
@@ -951,8 +939,8 @@ int _libssh2_pem_decode_sequence(unsigned char **data, size_t *datalen)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _libssh2_pem_decode_integer(unsigned char **data, size_t *datalen,
|
||||
unsigned char **i, unsigned int *ilen)
|
||||
int ssh2_pem_decode_integer(unsigned char **data, size_t *datalen,
|
||||
unsigned char **i, unsigned int *ilen)
|
||||
{
|
||||
size_t len;
|
||||
int lenlen;
|
||||
|
||||
637
src/publickey.c
637
src/publickey.c
File diff suppressed because it is too large
Load Diff
485
src/scp.c
485
src/scp.c
@@ -53,8 +53,8 @@
|
||||
#define scpsize_strtol strtol
|
||||
#endif
|
||||
|
||||
/* Max. length of a quoted string after libssh2_shell_quotearg() processing */
|
||||
#define _libssh2_shell_quotedsize(s) (3 * strlen(s) + 2)
|
||||
/* Max. length of a quoted string after shell_quotearg() processing */
|
||||
#define shell_quotedsize(s) (3 * strlen(s) + 2)
|
||||
|
||||
/*
|
||||
This function quotes a string in a way suitable to be used with a
|
||||
@@ -284,27 +284,26 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
const char *tmp_err_msg;
|
||||
|
||||
if(!path) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_INVAL,
|
||||
"Path argument can not be null");
|
||||
ssh2_err(session, LIBSSH2_ERROR_INVAL,
|
||||
"Path argument can not be null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_idle) {
|
||||
if(session->scpRecv_state == ssh2_NB_state_idle) {
|
||||
session->scpRecv_mode = 0;
|
||||
session->scpRecv_size = 0;
|
||||
session->scpRecv_mtime = 0;
|
||||
session->scpRecv_atime = 0;
|
||||
|
||||
session->scpRecv_command_len =
|
||||
_libssh2_shell_quotedsize(path) + sizeof("scp -f ") + (sb ? 1 : 0);
|
||||
shell_quotedsize(path) + sizeof("scp -f ") + (sb ? 1 : 0);
|
||||
|
||||
session->scpRecv_command =
|
||||
LIBSSH2_ALLOC(session, session->scpRecv_command_len);
|
||||
SSH2_ALLOC(session, session->scpRecv_command_len);
|
||||
|
||||
if(!session->scpRecv_command) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate a command buffer for "
|
||||
"SCP session");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate a command buffer for SCP session");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -331,69 +330,67 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
/* the command to exec should _not_ be null-terminated */
|
||||
session->scpRecv_command_len = cmd_len;
|
||||
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SCP,
|
||||
"Opening channel for SCP receive"));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SCP,
|
||||
"Opening channel for SCP receive"));
|
||||
|
||||
session->scpRecv_state = libssh2_NB_state_created;
|
||||
session->scpRecv_state = ssh2_NB_state_created;
|
||||
}
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_created) {
|
||||
if(session->scpRecv_state == ssh2_NB_state_created) {
|
||||
/* Allocate a channel */
|
||||
session->scpRecv_channel =
|
||||
_libssh2_channel_open(session, "session",
|
||||
sizeof("session") - 1,
|
||||
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
|
||||
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL,
|
||||
0);
|
||||
ssh2_channel_open(session, "session",
|
||||
sizeof("session") - 1,
|
||||
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
|
||||
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
|
||||
if(!session->scpRecv_channel) {
|
||||
if(libssh2_session_last_errno(session) !=
|
||||
LIBSSH2_ERROR_EAGAIN) {
|
||||
LIBSSH2_FREE(session, session->scpRecv_command);
|
||||
if(libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) {
|
||||
SSH2_FREE(session, session->scpRecv_command);
|
||||
session->scpRecv_command = NULL;
|
||||
session->scpRecv_state = libssh2_NB_state_idle;
|
||||
session->scpRecv_state = ssh2_NB_state_idle;
|
||||
}
|
||||
else {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block starting up channel");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block starting up channel");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
session->scpRecv_state = libssh2_NB_state_sent;
|
||||
session->scpRecv_state = ssh2_NB_state_sent;
|
||||
}
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent) {
|
||||
if(session->scpRecv_state == ssh2_NB_state_sent) {
|
||||
/* Request SCP for the desired file */
|
||||
rc = _libssh2_channel_process_startup(session->scpRecv_channel, "exec",
|
||||
sizeof("exec") - 1,
|
||||
(char *)session->scpRecv_command,
|
||||
session->scpRecv_command_len);
|
||||
rc = ssh2_channel_process_startup(session->scpRecv_channel, "exec",
|
||||
sizeof("exec") - 1,
|
||||
(char *)session->scpRecv_command,
|
||||
session->scpRecv_command_len);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block requesting SCP startup");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block requesting SCP startup");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc) {
|
||||
LIBSSH2_FREE(session, session->scpRecv_command);
|
||||
SSH2_FREE(session, session->scpRecv_command);
|
||||
session->scpRecv_command = NULL;
|
||||
goto scp_recv_error;
|
||||
}
|
||||
LIBSSH2_FREE(session, session->scpRecv_command);
|
||||
SSH2_FREE(session, session->scpRecv_command);
|
||||
session->scpRecv_command = NULL;
|
||||
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SCP, "Sending initial wakeup"));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SCP, "Sending initial wakeup"));
|
||||
/* SCP ACK */
|
||||
session->scpRecv_response[0] = '\0';
|
||||
|
||||
session->scpRecv_state = libssh2_NB_state_sent1;
|
||||
session->scpRecv_state = ssh2_NB_state_sent1;
|
||||
}
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent1) {
|
||||
rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
if(session->scpRecv_state == ssh2_NB_state_sent1) {
|
||||
rc = (int)ssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block sending initial wakeup");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block sending initial wakeup");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc != 1) {
|
||||
@@ -403,29 +400,28 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
/* Parse SCP response */
|
||||
session->scpRecv_response_len = 0;
|
||||
|
||||
session->scpRecv_state = libssh2_NB_state_sent2;
|
||||
session->scpRecv_state = ssh2_NB_state_sent2;
|
||||
}
|
||||
|
||||
if((session->scpRecv_state == libssh2_NB_state_sent2) ||
|
||||
(session->scpRecv_state == libssh2_NB_state_sent3)) {
|
||||
if((session->scpRecv_state == ssh2_NB_state_sent2) ||
|
||||
(session->scpRecv_state == ssh2_NB_state_sent3)) {
|
||||
while(sb && (session->scpRecv_response_len <
|
||||
LIBSSH2_SCP_RESPONSE_BUFLEN)) {
|
||||
SSH2_SCP_RESPONSE_BUFLEN)) {
|
||||
unsigned char *s, *p;
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent2) {
|
||||
rc = (int)_libssh2_channel_read(session->scpRecv_channel, 0,
|
||||
(char *)session->
|
||||
scpRecv_response +
|
||||
session->scpRecv_response_len,
|
||||
1);
|
||||
if(session->scpRecv_state == ssh2_NB_state_sent2) {
|
||||
rc = (int)ssh2_channel_read(session->scpRecv_channel, 0,
|
||||
(char *)session->
|
||||
scpRecv_response +
|
||||
session->scpRecv_response_len, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for SCP response");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for SCP response");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc < 0) {
|
||||
/* error, give up */
|
||||
_libssh2_error(session, rc, "Failed reading SCP response");
|
||||
ssh2_err(session, rc, "Failed reading SCP response");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
else if(rc == 0)
|
||||
@@ -444,30 +440,30 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
The following string MUST be newline terminated
|
||||
*/
|
||||
err_len =
|
||||
_libssh2_channel_packet_data_len(session->
|
||||
scpRecv_channel, 0);
|
||||
err_msg = LIBSSH2_ALLOC(session, err_len + 1);
|
||||
ssh2_channel_packet_data_len(session->scpRecv_channel,
|
||||
0);
|
||||
err_msg = SSH2_ALLOC(session, err_len + 1);
|
||||
if(!err_msg) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Failed to get memory ");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Failed to get memory ");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
/* Read the remote error message */
|
||||
(void)_libssh2_channel_read(session->scpRecv_channel, 0,
|
||||
err_msg, err_len);
|
||||
(void)ssh2_channel_read(session->scpRecv_channel, 0,
|
||||
err_msg, err_len);
|
||||
/* If it failed for any reason, we ignore it anyway. */
|
||||
|
||||
/* null-terminate the error */
|
||||
err_msg[err_len] = 0;
|
||||
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SCP, "got %02x %s",
|
||||
session->scpRecv_response[0], err_msg));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SCP, "got %02x %s",
|
||||
session->scpRecv_response[0], err_msg));
|
||||
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Failed to recv file");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Failed to recv file");
|
||||
|
||||
LIBSSH2_FREE(session, err_msg);
|
||||
SSH2_FREE(session, err_msg);
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
@@ -482,8 +478,8 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
1] != '\r') &&
|
||||
(session->scpRecv_response[session->scpRecv_response_len -
|
||||
1] != '\n')) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid data in SCP response");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid data in SCP response");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
@@ -491,11 +487,10 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
(session->scpRecv_response[session->scpRecv_response_len -
|
||||
1] != '\n')) {
|
||||
if(session->scpRecv_response_len ==
|
||||
LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
||||
SSH2_SCP_RESPONSE_BUFLEN) {
|
||||
/* You had your chance */
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Unterminated response from "
|
||||
"SCP server");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Unterminated response from SCP server");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
/* Way too short to be an SCP response, or not done yet,
|
||||
@@ -516,9 +511,8 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
|
||||
if(session->scpRecv_response_len < 8) {
|
||||
/* EOL came too soon */
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"too short");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, too short");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
@@ -527,9 +521,9 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
p = (unsigned char *)strchr((char *)s, ' ');
|
||||
if(!p || ((p - s) <= 0)) {
|
||||
/* No spaces or space in the wrong spot */
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"malformed mtime");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"malformed mtime");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
@@ -540,9 +534,9 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
s = (unsigned char *)strchr((char *)p, ' ');
|
||||
if(!s || ((s - p) <= 0)) {
|
||||
/* No spaces or space in the wrong spot */
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"malformed mtime.usec");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"malformed mtime.usec");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
@@ -551,9 +545,9 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
p = (unsigned char *)strchr((char *)s, ' ');
|
||||
if(!p || ((p - s) <= 0)) {
|
||||
/* No spaces or space in the wrong spot */
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"too short or malformed");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"too short or malformed");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
@@ -564,25 +558,25 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
/* SCP ACK */
|
||||
session->scpRecv_response[0] = '\0';
|
||||
|
||||
session->scpRecv_state = libssh2_NB_state_sent3;
|
||||
session->scpRecv_state = ssh2_NB_state_sent3;
|
||||
}
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent3) {
|
||||
rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
if(session->scpRecv_state == ssh2_NB_state_sent3) {
|
||||
rc = (int)ssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting to send SCP ACK");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting to send SCP ACK");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc != 1) {
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SCP,
|
||||
"mtime = %ld, atime = %ld",
|
||||
session->scpRecv_mtime,
|
||||
session->scpRecv_atime));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SCP,
|
||||
"mtime = %ld, atime = %ld",
|
||||
session->scpRecv_mtime,
|
||||
session->scpRecv_atime));
|
||||
|
||||
/* We *should* check that atime.usec is valid, but why let
|
||||
that stop use? */
|
||||
@@ -590,34 +584,33 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
}
|
||||
}
|
||||
|
||||
session->scpRecv_state = libssh2_NB_state_sent4;
|
||||
session->scpRecv_state = ssh2_NB_state_sent4;
|
||||
}
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent4) {
|
||||
if(session->scpRecv_state == ssh2_NB_state_sent4) {
|
||||
session->scpRecv_response_len = 0;
|
||||
|
||||
session->scpRecv_state = libssh2_NB_state_sent5;
|
||||
session->scpRecv_state = ssh2_NB_state_sent5;
|
||||
}
|
||||
|
||||
if((session->scpRecv_state == libssh2_NB_state_sent5) ||
|
||||
(session->scpRecv_state == libssh2_NB_state_sent6)) {
|
||||
while(session->scpRecv_response_len < LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
||||
if((session->scpRecv_state == ssh2_NB_state_sent5) ||
|
||||
(session->scpRecv_state == ssh2_NB_state_sent6)) {
|
||||
while(session->scpRecv_response_len < SSH2_SCP_RESPONSE_BUFLEN) {
|
||||
char *s, *p, *e = NULL;
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent5) {
|
||||
rc = (int)_libssh2_channel_read(session->scpRecv_channel, 0,
|
||||
(char *)session->
|
||||
scpRecv_response +
|
||||
session->scpRecv_response_len,
|
||||
1);
|
||||
if(session->scpRecv_state == ssh2_NB_state_sent5) {
|
||||
rc = (int)ssh2_channel_read(session->scpRecv_channel, 0,
|
||||
(char *)session->
|
||||
scpRecv_response +
|
||||
session->scpRecv_response_len, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for SCP response");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for SCP response");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc < 0) {
|
||||
/* error, bail out */
|
||||
_libssh2_error(session, rc, "Failed reading SCP response");
|
||||
ssh2_err(session, rc, "Failed reading SCP response");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
else if(rc == 0)
|
||||
@@ -626,8 +619,8 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
session->scpRecv_response_len++;
|
||||
|
||||
if(session->scpRecv_response[0] != 'C') {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
@@ -638,8 +631,8 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
1] != '\n') &&
|
||||
(session->scpRecv_response[session->scpRecv_response_len -
|
||||
1] < 32)) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid data in SCP response");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid data in SCP response");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
@@ -647,11 +640,10 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
(session->scpRecv_response[session->scpRecv_response_len -
|
||||
1] != '\n')) {
|
||||
if(session->scpRecv_response_len ==
|
||||
LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
||||
SSH2_SCP_RESPONSE_BUFLEN) {
|
||||
/* You had your chance */
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Unterminated response "
|
||||
"from SCP server");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Unterminated response from SCP server");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
/* Way too short to be an SCP response, or not done yet,
|
||||
@@ -673,9 +665,8 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
|
||||
if(session->scpRecv_response_len < 6) {
|
||||
/* EOL came too soon */
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"too short");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, too short");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
@@ -684,9 +675,9 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
p = strchr(s, ' ');
|
||||
if(!p || ((p - s) <= 0)) {
|
||||
/* No spaces or space in the wrong spot */
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"malformed mode");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"malformed mode");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
@@ -694,18 +685,17 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
/* Make sure we do not get fooled by leftover values */
|
||||
session->scpRecv_mode = strtol(s, &e, 8);
|
||||
if(e && *e) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"invalid mode");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, invalid mode");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
s = strchr(p, ' ');
|
||||
if(!s || ((s - p) <= 0)) {
|
||||
/* No spaces or space in the wrong spot */
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"too short or malformed");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"too short or malformed");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
@@ -713,33 +703,31 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
/* Make sure we do not get fooled by leftover values */
|
||||
session->scpRecv_size = scpsize_strtol(p, &e, 10);
|
||||
if(e && *e) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, "
|
||||
"invalid size");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid response from SCP server, invalid size");
|
||||
goto scp_recv_error;
|
||||
}
|
||||
|
||||
/* SCP ACK */
|
||||
session->scpRecv_response[0] = '\0';
|
||||
|
||||
session->scpRecv_state = libssh2_NB_state_sent6;
|
||||
session->scpRecv_state = ssh2_NB_state_sent6;
|
||||
}
|
||||
|
||||
if(session->scpRecv_state == libssh2_NB_state_sent6) {
|
||||
rc = (int)_libssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
if(session->scpRecv_state == ssh2_NB_state_sent6) {
|
||||
rc = (int)ssh2_channel_write(session->scpRecv_channel, 0,
|
||||
session->scpRecv_response, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block sending SCP ACK");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block sending SCP ACK");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc != 1) {
|
||||
goto scp_recv_error;
|
||||
}
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SCP,
|
||||
"mode = 0%lo size = %ld",
|
||||
session->scpRecv_mode,
|
||||
(long)session->scpRecv_size));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SCP, "mode = 0%lo size = %ld",
|
||||
session->scpRecv_mode,
|
||||
(long)session->scpRecv_size));
|
||||
|
||||
/* We *should* check that basename is valid, but why let that
|
||||
stop us? */
|
||||
@@ -747,7 +735,7 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
}
|
||||
}
|
||||
|
||||
session->scpRecv_state = libssh2_NB_state_sent7;
|
||||
session->scpRecv_state = ssh2_NB_state_sent7;
|
||||
}
|
||||
|
||||
if(sb) {
|
||||
@@ -759,15 +747,15 @@ static LIBSSH2_CHANNEL *scp_recv(LIBSSH2_SESSION *session,
|
||||
sb->st_mode = (unsigned short)session->scpRecv_mode;
|
||||
}
|
||||
|
||||
session->scpRecv_state = libssh2_NB_state_idle;
|
||||
session->scpRecv_state = ssh2_NB_state_idle;
|
||||
return session->scpRecv_channel;
|
||||
|
||||
scp_recv_empty_channel:
|
||||
/* the code only jumps here as a result of a zero read from channel_read()
|
||||
so we check EOF status to avoid getting stuck in a loop */
|
||||
if(libssh2_channel_eof(session->scpRecv_channel))
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Unexpected channel close");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Unexpected channel close");
|
||||
else
|
||||
return session->scpRecv_channel;
|
||||
/* fall-through */
|
||||
@@ -780,7 +768,7 @@ scp_recv_error:
|
||||
session->err_code = tmp_err_code;
|
||||
session->err_msg = tmp_err_msg;
|
||||
session->scpRecv_channel = NULL;
|
||||
session->scpRecv_state = libssh2_NB_state_idle;
|
||||
session->scpRecv_state = ssh2_NB_state_idle;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -848,23 +836,22 @@ static LIBSSH2_CHANNEL *scp_send(LIBSSH2_SESSION *session,
|
||||
const char *tmp_err_msg;
|
||||
|
||||
if(!path) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_INVAL,
|
||||
"Path argument can not be null");
|
||||
ssh2_err(session, LIBSSH2_ERROR_INVAL,
|
||||
"Path argument can not be null");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_idle) {
|
||||
if(session->scpSend_state == ssh2_NB_state_idle) {
|
||||
session->scpSend_command_len =
|
||||
_libssh2_shell_quotedsize(path) + sizeof("scp -t ") +
|
||||
shell_quotedsize(path) + sizeof("scp -t ") +
|
||||
((mtime || atime) ? 1 : 0);
|
||||
|
||||
session->scpSend_command =
|
||||
LIBSSH2_ALLOC(session, session->scpSend_command_len);
|
||||
SSH2_ALLOC(session, session->scpSend_command_len);
|
||||
|
||||
if(!session->scpSend_command) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate a command buffer for "
|
||||
"SCP session");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate a command buffer for SCP session");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -891,149 +878,147 @@ static LIBSSH2_CHANNEL *scp_send(LIBSSH2_SESSION *session,
|
||||
/* the command to exec should _not_ be null-terminated */
|
||||
session->scpSend_command_len = cmd_len;
|
||||
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SCP,
|
||||
"Opening channel for SCP send"));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SCP, "Opening channel for SCP send"));
|
||||
/* Allocate a channel */
|
||||
|
||||
session->scpSend_state = libssh2_NB_state_created;
|
||||
session->scpSend_state = ssh2_NB_state_created;
|
||||
}
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_created) {
|
||||
if(session->scpSend_state == ssh2_NB_state_created) {
|
||||
session->scpSend_channel =
|
||||
_libssh2_channel_open(session, "session", sizeof("session") - 1,
|
||||
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
|
||||
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
|
||||
ssh2_channel_open(session, "session", sizeof("session") - 1,
|
||||
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
|
||||
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
|
||||
if(!session->scpSend_channel) {
|
||||
if(libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) {
|
||||
/* previous call set libssh2_session_last_error(), pass it
|
||||
through */
|
||||
LIBSSH2_FREE(session, session->scpSend_command);
|
||||
SSH2_FREE(session, session->scpSend_command);
|
||||
session->scpSend_command = NULL;
|
||||
session->scpSend_state = libssh2_NB_state_idle;
|
||||
session->scpSend_state = ssh2_NB_state_idle;
|
||||
}
|
||||
else {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block starting up channel");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block starting up channel");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
session->scpSend_state = libssh2_NB_state_sent;
|
||||
session->scpSend_state = ssh2_NB_state_sent;
|
||||
}
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_sent) {
|
||||
if(session->scpSend_state == ssh2_NB_state_sent) {
|
||||
/* Request SCP for the desired file */
|
||||
rc = _libssh2_channel_process_startup(session->scpSend_channel, "exec",
|
||||
sizeof("exec") - 1,
|
||||
(char *)session->scpSend_command,
|
||||
session->scpSend_command_len);
|
||||
rc = ssh2_channel_process_startup(session->scpSend_channel, "exec",
|
||||
sizeof("exec") - 1,
|
||||
(char *)session->scpSend_command,
|
||||
session->scpSend_command_len);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block requesting SCP startup");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block requesting SCP startup");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc) {
|
||||
/* previous call set libssh2_session_last_error(), pass it
|
||||
through */
|
||||
LIBSSH2_FREE(session, session->scpSend_command);
|
||||
SSH2_FREE(session, session->scpSend_command);
|
||||
session->scpSend_command = NULL;
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Unknown error while getting error string");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Unknown error while getting error string");
|
||||
goto scp_send_error;
|
||||
}
|
||||
LIBSSH2_FREE(session, session->scpSend_command);
|
||||
SSH2_FREE(session, session->scpSend_command);
|
||||
session->scpSend_command = NULL;
|
||||
|
||||
session->scpSend_state = libssh2_NB_state_sent1;
|
||||
session->scpSend_state = ssh2_NB_state_sent1;
|
||||
}
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_sent1) {
|
||||
if(session->scpSend_state == ssh2_NB_state_sent1) {
|
||||
/* Wait for ACK */
|
||||
rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *)session->scpSend_response, 1);
|
||||
rc = (int)ssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *)session->scpSend_response, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for response from remote");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for response from remote");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc < 0) {
|
||||
_libssh2_error(session, rc, "SCP failure");
|
||||
ssh2_err(session, rc, "SCP failure");
|
||||
goto scp_send_error;
|
||||
}
|
||||
else if(!rc)
|
||||
/* remain in the same state */
|
||||
goto scp_send_empty_channel;
|
||||
else if(session->scpSend_response[0]) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid ACK response from remote");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid ACK response from remote");
|
||||
goto scp_send_error;
|
||||
}
|
||||
if(mtime || atime) {
|
||||
/* Send mtime and atime to be used for file */
|
||||
session->scpSend_response_len =
|
||||
snprintf((char *)session->scpSend_response,
|
||||
LIBSSH2_SCP_RESPONSE_BUFLEN, "T%ld 0 %ld 0\n",
|
||||
SSH2_SCP_RESPONSE_BUFLEN, "T%ld 0 %ld 0\n",
|
||||
(long)mtime, (long)atime);
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SCP, "Sent %s",
|
||||
session->scpSend_response));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SCP, "Sent %s",
|
||||
session->scpSend_response));
|
||||
}
|
||||
|
||||
session->scpSend_state = libssh2_NB_state_sent2;
|
||||
session->scpSend_state = ssh2_NB_state_sent2;
|
||||
}
|
||||
|
||||
/* Send mtime and atime to be used for file */
|
||||
if(mtime || atime) {
|
||||
if(session->scpSend_state == libssh2_NB_state_sent2) {
|
||||
rc = (int)_libssh2_channel_write(session->scpSend_channel, 0,
|
||||
session->scpSend_response,
|
||||
session->scpSend_response_len);
|
||||
if(session->scpSend_state == ssh2_NB_state_sent2) {
|
||||
rc = (int)ssh2_channel_write(session->scpSend_channel, 0,
|
||||
session->scpSend_response,
|
||||
session->scpSend_response_len);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block sending time data for SCP file");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block sending time data for SCP file");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc != (int)session->scpSend_response_len) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"Unable to send time data for SCP file");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"Unable to send time data for SCP file");
|
||||
goto scp_send_error;
|
||||
}
|
||||
|
||||
session->scpSend_state = libssh2_NB_state_sent3;
|
||||
session->scpSend_state = ssh2_NB_state_sent3;
|
||||
}
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_sent3) {
|
||||
if(session->scpSend_state == ssh2_NB_state_sent3) {
|
||||
/* Wait for ACK */
|
||||
rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *)session->scpSend_response,
|
||||
1);
|
||||
rc = (int)ssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *)session->scpSend_response, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for response");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for response");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc < 0) {
|
||||
_libssh2_error(session, rc, "SCP failure");
|
||||
ssh2_err(session, rc, "SCP failure");
|
||||
goto scp_send_error;
|
||||
}
|
||||
else if(!rc)
|
||||
/* remain in the same state */
|
||||
goto scp_send_empty_channel;
|
||||
else if(session->scpSend_response[0]) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid SCP ACK response");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid SCP ACK response");
|
||||
goto scp_send_error;
|
||||
}
|
||||
|
||||
session->scpSend_state = libssh2_NB_state_sent4;
|
||||
session->scpSend_state = ssh2_NB_state_sent4;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(session->scpSend_state == libssh2_NB_state_sent2) {
|
||||
session->scpSend_state = libssh2_NB_state_sent4;
|
||||
if(session->scpSend_state == ssh2_NB_state_sent2) {
|
||||
session->scpSend_state = ssh2_NB_state_sent4;
|
||||
}
|
||||
}
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_sent4) {
|
||||
if(session->scpSend_state == ssh2_NB_state_sent4) {
|
||||
/* Send mode, size, and basename */
|
||||
const char *base = strrchr(path, '/');
|
||||
if(base)
|
||||
@@ -1043,45 +1028,44 @@ static LIBSSH2_CHANNEL *scp_send(LIBSSH2_SESSION *session,
|
||||
|
||||
session->scpSend_response_len =
|
||||
snprintf((char *)session->scpSend_response,
|
||||
LIBSSH2_SCP_RESPONSE_BUFLEN, "C0%o %"
|
||||
LIBSSH2_INT64_T_FORMAT " %s\n", mode,
|
||||
size, base);
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SCP, "Sent %s",
|
||||
session->scpSend_response));
|
||||
SSH2_SCP_RESPONSE_BUFLEN,
|
||||
"C0%o %" SSH2_INT64_T_FORMAT " %s\n", mode, size, base);
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SCP, "Sent %s",
|
||||
session->scpSend_response));
|
||||
|
||||
session->scpSend_state = libssh2_NB_state_sent5;
|
||||
session->scpSend_state = ssh2_NB_state_sent5;
|
||||
}
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_sent5) {
|
||||
rc = (int)_libssh2_channel_write(session->scpSend_channel, 0,
|
||||
session->scpSend_response,
|
||||
session->scpSend_response_len);
|
||||
if(session->scpSend_state == ssh2_NB_state_sent5) {
|
||||
rc = (int)ssh2_channel_write(session->scpSend_channel, 0,
|
||||
session->scpSend_response,
|
||||
session->scpSend_response_len);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block send core file data for SCP file");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block send core file data for SCP file");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc != (int)session->scpSend_response_len) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"Unable to send core file data for SCP file");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"Unable to send core file data for SCP file");
|
||||
goto scp_send_error;
|
||||
}
|
||||
|
||||
session->scpSend_state = libssh2_NB_state_sent6;
|
||||
session->scpSend_state = ssh2_NB_state_sent6;
|
||||
}
|
||||
|
||||
if(session->scpSend_state == libssh2_NB_state_sent6) {
|
||||
if(session->scpSend_state == ssh2_NB_state_sent6) {
|
||||
/* Wait for ACK */
|
||||
rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *)session->scpSend_response, 1);
|
||||
rc = (int)ssh2_channel_read(session->scpSend_channel, 0,
|
||||
(char *)session->scpSend_response, 1);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for response");
|
||||
ssh2_err(session, LIBSSH2_ERROR_EAGAIN,
|
||||
"Would block waiting for response");
|
||||
return NULL;
|
||||
}
|
||||
else if(rc < 0) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid ACK response from remote");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Invalid ACK response from remote");
|
||||
goto scp_send_error;
|
||||
}
|
||||
else if(rc == 0)
|
||||
@@ -1092,38 +1076,37 @@ static LIBSSH2_CHANNEL *scp_send(LIBSSH2_SESSION *session,
|
||||
char *err_msg;
|
||||
|
||||
err_len =
|
||||
_libssh2_channel_packet_data_len(session->scpSend_channel, 0);
|
||||
err_msg = LIBSSH2_ALLOC(session, err_len + 1);
|
||||
ssh2_channel_packet_data_len(session->scpSend_channel, 0);
|
||||
err_msg = SSH2_ALLOC(session, err_len + 1);
|
||||
if(!err_msg) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"failed to get memory");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC, "failed to get memory");
|
||||
goto scp_send_error;
|
||||
}
|
||||
|
||||
/* Read the remote error message */
|
||||
rc = (int)_libssh2_channel_read(session->scpSend_channel, 0,
|
||||
err_msg, err_len);
|
||||
rc = (int)ssh2_channel_read(session->scpSend_channel, 0,
|
||||
err_msg, err_len);
|
||||
if(rc > 0) {
|
||||
err_msg[err_len] = 0;
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SCP, "got %02x %s",
|
||||
session->scpSend_response[0], err_msg));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SCP, "got %02x %s",
|
||||
session->scpSend_response[0], err_msg));
|
||||
}
|
||||
LIBSSH2_FREE(session, err_msg);
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"failed to send file");
|
||||
SSH2_FREE(session, err_msg);
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"failed to send file");
|
||||
goto scp_send_error;
|
||||
}
|
||||
}
|
||||
|
||||
session->scpSend_state = libssh2_NB_state_idle;
|
||||
session->scpSend_state = ssh2_NB_state_idle;
|
||||
return session->scpSend_channel;
|
||||
|
||||
scp_send_empty_channel:
|
||||
/* the code only jumps here as a result of a zero read from channel_read()
|
||||
so we check EOF status to avoid getting stuck in a loop */
|
||||
if(libssh2_channel_eof(session->scpSend_channel)) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Unexpected channel close");
|
||||
ssh2_err(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||
"Unexpected channel close");
|
||||
}
|
||||
else
|
||||
return session->scpSend_channel;
|
||||
@@ -1137,7 +1120,7 @@ scp_send_error:
|
||||
session->err_code = tmp_err_code;
|
||||
session->err_msg = tmp_err_msg;
|
||||
session->scpSend_channel = NULL;
|
||||
session->scpSend_state = libssh2_NB_state_idle;
|
||||
session->scpSend_state = ssh2_NB_state_idle;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
475
src/session.c
475
src/session.c
File diff suppressed because it is too large
Load Diff
@@ -62,7 +62,7 @@
|
||||
if(((rc) != LIBSSH2_ERROR_EAGAIN) || !(sess) || \
|
||||
!(sess)->api_block_mode) \
|
||||
break; \
|
||||
(rc) = _libssh2_wait_socket(sess, entry_time); \
|
||||
(rc) = ssh2_wait_socket(sess, entry_time); \
|
||||
} while(!(rc)); \
|
||||
} while(0)
|
||||
|
||||
@@ -81,13 +81,13 @@
|
||||
if(!(sess) || !(sess)->api_block_mode || (ptr) != NULL || \
|
||||
libssh2_session_last_errno(sess) != LIBSSH2_ERROR_EAGAIN) \
|
||||
break; \
|
||||
(rc) = _libssh2_wait_socket(sess, entry_time); \
|
||||
(rc) = ssh2_wait_socket(sess, entry_time); \
|
||||
} while(!(rc)); \
|
||||
} while(0)
|
||||
|
||||
int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time);
|
||||
int ssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time);
|
||||
|
||||
/* this is the lib-internal set blocking function */
|
||||
int _libssh2_session_set_blocking(LIBSSH2_SESSION *session, int blocking);
|
||||
int ssh2_session_set_blocking(LIBSSH2_SESSION *session, int blocking);
|
||||
|
||||
#endif /* LIBSSH2_SESSION_H */
|
||||
|
||||
1899
src/sftp.c
1899
src/sftp.c
File diff suppressed because it is too large
Load Diff
44
src/sftp.h
44
src/sftp.h
@@ -91,8 +91,8 @@ struct _LIBSSH2_SFTP_HANDLE {
|
||||
LIBSSH2_SFTP_HANDLE_DIR
|
||||
} handle_type;
|
||||
|
||||
union libssh2_sftp_handle_data {
|
||||
struct libssh2_sftp_handle_file_data {
|
||||
union ssh2_sftp_handle_data {
|
||||
struct ssh2_sftp_handle_file_data {
|
||||
libssh2_uint64_t offset;
|
||||
libssh2_uint64_t offset_sent;
|
||||
size_t acked; /* container for acked data that has not been
|
||||
@@ -109,7 +109,7 @@ struct _LIBSSH2_SFTP_HANDLE {
|
||||
|
||||
char eof; /* we have read to the end */
|
||||
} file;
|
||||
struct libssh2_sftp_handle_dir_data {
|
||||
struct ssh2_sftp_handle_dir_data {
|
||||
uint32_t names_left;
|
||||
void *names_packet;
|
||||
char *next_name;
|
||||
@@ -118,7 +118,7 @@ struct _LIBSSH2_SFTP_HANDLE {
|
||||
} u;
|
||||
|
||||
/* State variables used in libssh2_sftp_close_handle() */
|
||||
libssh2_nonblocking_states close_state;
|
||||
ssh2_NB_states close_state;
|
||||
uint32_t close_request_id;
|
||||
unsigned char *close_packet;
|
||||
|
||||
@@ -141,7 +141,7 @@ struct _LIBSSH2_SFTP {
|
||||
|
||||
uint32_t last_errno;
|
||||
|
||||
/* Holder for partial packet, use in libssh2_sftp_packet_read() */
|
||||
/* Holder for partial packet, use in sftp_packet_read() */
|
||||
unsigned char packet_header[9];
|
||||
/* packet size (4) packet type (1) request id (4) */
|
||||
size_t packet_header_len; /* packet_header length */
|
||||
@@ -149,83 +149,83 @@ struct _LIBSSH2_SFTP {
|
||||
uint32_t partial_len; /* Desired number of bytes */
|
||||
size_t partial_received; /* Bytes received so far */
|
||||
|
||||
/* Time that libssh2_sftp_packet_requirev() started reading */
|
||||
/* Time that sftp_packet_requirev() started reading */
|
||||
time_t requirev_start;
|
||||
|
||||
/* State variables used in libssh2_sftp_open_ex() */
|
||||
libssh2_nonblocking_states open_state;
|
||||
ssh2_NB_states open_state;
|
||||
unsigned char *open_packet;
|
||||
uint32_t open_packet_len; /* 32-bit on the wire */
|
||||
size_t open_packet_sent;
|
||||
uint32_t open_request_id;
|
||||
|
||||
/* State variable used in sftp_read() */
|
||||
libssh2_nonblocking_states read_state;
|
||||
ssh2_NB_states read_state;
|
||||
|
||||
/* State variable used in sftp_packet_read() */
|
||||
libssh2_nonblocking_states packet_state;
|
||||
ssh2_NB_states packet_state;
|
||||
|
||||
/* State variable used in sftp_write() */
|
||||
libssh2_nonblocking_states write_state;
|
||||
ssh2_NB_states write_state;
|
||||
|
||||
/* State variables used in sftp_fsync() */
|
||||
libssh2_nonblocking_states fsync_state;
|
||||
ssh2_NB_states fsync_state;
|
||||
unsigned char *fsync_packet;
|
||||
uint32_t fsync_request_id;
|
||||
|
||||
/* State variables used in libssh2_sftp_readdir() */
|
||||
libssh2_nonblocking_states readdir_state;
|
||||
ssh2_NB_states readdir_state;
|
||||
unsigned char *readdir_packet;
|
||||
uint32_t readdir_request_id;
|
||||
|
||||
/* State variables used in libssh2_sftp_fstat_ex() */
|
||||
libssh2_nonblocking_states fstat_state;
|
||||
ssh2_NB_states fstat_state;
|
||||
unsigned char *fstat_packet;
|
||||
uint32_t fstat_request_id;
|
||||
|
||||
/* State variables used in libssh2_sftp_unlink_ex() */
|
||||
libssh2_nonblocking_states unlink_state;
|
||||
ssh2_NB_states unlink_state;
|
||||
unsigned char *unlink_packet;
|
||||
uint32_t unlink_request_id;
|
||||
|
||||
/* State variables used in libssh2_sftp_rename_ex() */
|
||||
libssh2_nonblocking_states rename_state;
|
||||
ssh2_NB_states rename_state;
|
||||
unsigned char *rename_packet;
|
||||
unsigned char *rename_s;
|
||||
uint32_t rename_request_id;
|
||||
|
||||
/* State variables used in libssh2_sftp_posix_rename_ex() */
|
||||
libssh2_nonblocking_states posix_rename_state;
|
||||
ssh2_NB_states posix_rename_state;
|
||||
unsigned char *posix_rename_packet;
|
||||
uint32_t posix_rename_request_id;
|
||||
|
||||
/* State variables used in libssh2_sftp_fstatvfs() */
|
||||
libssh2_nonblocking_states fstatvfs_state;
|
||||
ssh2_NB_states fstatvfs_state;
|
||||
unsigned char *fstatvfs_packet;
|
||||
uint32_t fstatvfs_request_id;
|
||||
|
||||
/* State variables used in libssh2_sftp_statvfs() */
|
||||
libssh2_nonblocking_states statvfs_state;
|
||||
ssh2_NB_states statvfs_state;
|
||||
unsigned char *statvfs_packet;
|
||||
uint32_t statvfs_request_id;
|
||||
|
||||
/* State variables used in libssh2_sftp_mkdir() */
|
||||
libssh2_nonblocking_states mkdir_state;
|
||||
ssh2_NB_states mkdir_state;
|
||||
unsigned char *mkdir_packet;
|
||||
uint32_t mkdir_request_id;
|
||||
|
||||
/* State variables used in libssh2_sftp_rmdir() */
|
||||
libssh2_nonblocking_states rmdir_state;
|
||||
ssh2_NB_states rmdir_state;
|
||||
unsigned char *rmdir_packet;
|
||||
uint32_t rmdir_request_id;
|
||||
|
||||
/* State variables used in libssh2_sftp_stat() */
|
||||
libssh2_nonblocking_states stat_state;
|
||||
ssh2_NB_states stat_state;
|
||||
unsigned char *stat_packet;
|
||||
uint32_t stat_request_id;
|
||||
|
||||
/* State variables used in libssh2_sftp_symlink() */
|
||||
libssh2_nonblocking_states symlink_state;
|
||||
ssh2_NB_states symlink_state;
|
||||
unsigned char *symlink_packet;
|
||||
uint32_t symlink_request_id;
|
||||
};
|
||||
|
||||
229
src/transport.c
229
src/transport.c
@@ -135,7 +135,7 @@ static int decrypt(LIBSSH2_SESSION *session, unsigned char *source,
|
||||
|
||||
while(len > 0) {
|
||||
/* normally decrypt up to blocksize bytes at a time */
|
||||
ssize_t decryptlen = LIBSSH2_MIN(blocksize, len);
|
||||
ssize_t decryptlen = SSH2_MIN(blocksize, len);
|
||||
/* The first block is special (since it needs to be decoded to get the
|
||||
length of the remainder of the block) and takes priority. When the
|
||||
length finally gets to the last blocksize bytes, and there is no
|
||||
@@ -154,7 +154,7 @@ static int decrypt(LIBSSH2_SESSION *session, unsigned char *source,
|
||||
if(session->remote.crypt->crypt(session, 0, source, decryptlen,
|
||||
&session->remote.crypt_abstract,
|
||||
lowerfirstlast)) {
|
||||
LIBSSH2_FREE(session, p->payload);
|
||||
SSH2_FREE(session, p->payload);
|
||||
p->payload = NULL;
|
||||
return LIBSSH2_ERROR_DECRYPT;
|
||||
}
|
||||
@@ -191,8 +191,8 @@ static int fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
||||
remote_mac = session->remote.mac;
|
||||
}
|
||||
|
||||
if(session->fullpacket_state == libssh2_NB_state_idle) {
|
||||
session->fullpacket_macstate = LIBSSH2_MAC_CONFIRMED;
|
||||
if(session->fullpacket_state == ssh2_NB_state_idle) {
|
||||
session->fullpacket_macstate = SSH2_MAC_CONFIRMED;
|
||||
session->fullpacket_payload_len = p->packet_length - 1;
|
||||
|
||||
if(encrypted && remote_mac) {
|
||||
@@ -223,12 +223,11 @@ static int fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
||||
* buffer. Note that 'payload_len' here is the packet_length
|
||||
* field which includes the padding but not the MAC.
|
||||
*/
|
||||
if(_libssh2_timingsafe_bcmp(macbuf,
|
||||
p->payload + p->total_num - mac_len,
|
||||
mac_len)) {
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Failed MAC check"));
|
||||
session->fullpacket_macstate = LIBSSH2_MAC_INVALID;
|
||||
if(ssh2_timingsafe_bcmp(macbuf,
|
||||
p->payload + p->total_num - mac_len,
|
||||
mac_len)) {
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SOCKET, "Failed MAC check"));
|
||||
session->fullpacket_macstate = SSH2_MAC_INVALID;
|
||||
}
|
||||
else if(etm) {
|
||||
/* MAC was ok and we start by decrypting the first block that
|
||||
@@ -250,7 +249,7 @@ static int fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
||||
|
||||
/* we need buffer for decrypt */
|
||||
decrypt_size = p->total_num - mac_len - 4;
|
||||
decrypt_buffer = LIBSSH2_ALLOC(session, decrypt_size);
|
||||
decrypt_buffer = SSH2_ALLOC(session, decrypt_size);
|
||||
if(!decrypt_buffer) {
|
||||
return LIBSSH2_ERROR_ALLOC;
|
||||
}
|
||||
@@ -260,7 +259,7 @@ static int fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
||||
p->padding_length = first_block[0];
|
||||
|
||||
if(p->padding_length > p->packet_length - 1) {
|
||||
LIBSSH2_FREE(session, decrypt_buffer);
|
||||
SSH2_FREE(session, decrypt_buffer);
|
||||
return LIBSSH2_ERROR_PROTO;
|
||||
}
|
||||
|
||||
@@ -274,13 +273,13 @@ static int fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
||||
decrypt_buffer + blocksize - 1,
|
||||
decrypt_size - blocksize, LAST_BLOCK);
|
||||
if(rc) {
|
||||
LIBSSH2_FREE(session, decrypt_buffer);
|
||||
SSH2_FREE(session, decrypt_buffer);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
/* replace encrypted payload with plain text payload */
|
||||
LIBSSH2_FREE(session, p->payload);
|
||||
SSH2_FREE(session, p->payload);
|
||||
p->payload = decrypt_buffer;
|
||||
}
|
||||
}
|
||||
@@ -297,7 +296,7 @@ static int fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
||||
/* Check for and deal with decompression */
|
||||
compressed = session->local.comp &&
|
||||
session->local.comp->compress &&
|
||||
((session->state & LIBSSH2_STATE_AUTHENTICATED) ||
|
||||
((session->state & SSH2_STATE_AUTHENTICATED) ||
|
||||
session->local.comp->use_in_auth);
|
||||
|
||||
if(compressed && session->remote.comp_abstract) {
|
||||
@@ -315,7 +314,7 @@ static int fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
||||
p->payload,
|
||||
session->fullpacket_payload_len,
|
||||
&session->remote.comp_abstract);
|
||||
LIBSSH2_FREE(session, p->payload);
|
||||
SSH2_FREE(session, p->payload);
|
||||
p->payload = NULL;
|
||||
if(rc)
|
||||
return rc;
|
||||
@@ -326,25 +325,25 @@ static int fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
||||
|
||||
session->fullpacket_packet_type = p->payload[0];
|
||||
|
||||
debugdump(session, "libssh2_transport_read() plain",
|
||||
debugdump(session, "ssh2_transport_read() plain",
|
||||
p->payload, session->fullpacket_payload_len);
|
||||
|
||||
session->fullpacket_state = libssh2_NB_state_created;
|
||||
session->fullpacket_state = ssh2_NB_state_created;
|
||||
}
|
||||
|
||||
if(session->fullpacket_state == libssh2_NB_state_created) {
|
||||
rc = _libssh2_packet_add(session, p->payload,
|
||||
session->fullpacket_payload_len,
|
||||
session->fullpacket_macstate, seq);
|
||||
if(session->fullpacket_state == ssh2_NB_state_created) {
|
||||
rc = ssh2_packet_add(session, p->payload,
|
||||
session->fullpacket_payload_len,
|
||||
session->fullpacket_macstate, seq);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN)
|
||||
return rc;
|
||||
if(rc) {
|
||||
session->fullpacket_state = libssh2_NB_state_idle;
|
||||
session->fullpacket_state = ssh2_NB_state_idle;
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
session->fullpacket_state = libssh2_NB_state_idle;
|
||||
session->fullpacket_state = ssh2_NB_state_idle;
|
||||
|
||||
if(session->kex_strict &&
|
||||
session->fullpacket_packet_type == SSH_MSG_NEWKEYS) {
|
||||
@@ -363,9 +362,9 @@ static int fullpacket(LIBSSH2_SESSION *session, int encrypted /* 1 or 0 */)
|
||||
* This function reads the binary stream as specified in chapter 6 of RFC4253
|
||||
* "The Secure Shell (SSH) Transport Layer Protocol"
|
||||
*
|
||||
* DOES NOT call _libssh2_error() for ANY error case.
|
||||
* DOES NOT call ssh2_err() for ANY error case.
|
||||
*/
|
||||
int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
int ssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
{
|
||||
int rc;
|
||||
struct transportpacket *p = &session->packet;
|
||||
@@ -393,24 +392,24 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
/*
|
||||
* All channels, systems, subsystems, etc eventually make it down here
|
||||
* when looking for more incoming data. If a key exchange is going on
|
||||
* (LIBSSH2_STATE_EXCHANGING_KEYS bit is set) then the remote end
|
||||
* (SSH2_STATE_EXCHANGING_KEYS bit is set) then the remote end
|
||||
* ONLY sends key exchange related traffic. In non-blocking mode, there is
|
||||
* a chance to break out of the kex_exchange function with an EAGAIN
|
||||
* status, and never come back to it. If LIBSSH2_STATE_EXCHANGING_KEYS is
|
||||
* status, and never come back to it. If SSH2_STATE_EXCHANGING_KEYS is
|
||||
* active, then we must redirect to the key exchange. However, if
|
||||
* kex_exchange is active (as in it is the one that calls this execution
|
||||
* of packet_read, then do not redirect, as that would be an infinite loop!
|
||||
*/
|
||||
|
||||
if(session->state & LIBSSH2_STATE_EXCHANGING_KEYS &&
|
||||
!(session->state & LIBSSH2_STATE_KEX_ACTIVE)) {
|
||||
if(session->state & SSH2_STATE_EXCHANGING_KEYS &&
|
||||
!(session->state & SSH2_STATE_KEX_ACTIVE)) {
|
||||
|
||||
/* Whoever wants a packet does not get anything until the key
|
||||
* re-exchange is done!
|
||||
*/
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Redirecting into the"
|
||||
" key re-exchange from _libssh2_transport_read"));
|
||||
rc = _libssh2_kex_exchange(session, 1, &session->startup_key_state);
|
||||
ssh2_deb((session, LIBSSH2_TRACE_TRANS, "Redirecting into the"
|
||||
" key re-exchange from ssh2_transport_read()"));
|
||||
rc = ssh2_kex_exchange(session, 1, &session->startup_key_state);
|
||||
if(rc)
|
||||
return rc;
|
||||
}
|
||||
@@ -420,19 +419,19 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
* I know this is ugly and not a really good use of "goto", but
|
||||
* this case statement would be even uglier to do it any other way
|
||||
*/
|
||||
if(session->readPack_state == libssh2_NB_state_jump1) {
|
||||
session->readPack_state = libssh2_NB_state_idle;
|
||||
if(session->readPack_state == ssh2_NB_state_jump1) {
|
||||
session->readPack_state = ssh2_NB_state_idle;
|
||||
encrypted = session->readPack_encrypted;
|
||||
goto libssh2_transport_read_point1;
|
||||
goto ssh2_transport_read_point1;
|
||||
}
|
||||
|
||||
do {
|
||||
int etm;
|
||||
if(session->socket_state == LIBSSH2_SOCKET_DISCONNECTED) {
|
||||
if(session->socket_state == SSH2_SOCKET_DISCONNECTED) {
|
||||
return LIBSSH2_ERROR_SOCKET_DISCONNECT;
|
||||
}
|
||||
|
||||
if(session->state & LIBSSH2_STATE_NEWKEYS) {
|
||||
if(session->state & SSH2_STATE_NEWKEYS) {
|
||||
blocksize = session->remote.crypt->blocksize;
|
||||
}
|
||||
else {
|
||||
@@ -485,9 +484,9 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
}
|
||||
|
||||
/* now read a big chunk from the network into the temp buffer */
|
||||
nread = LIBSSH2_RECV(session, &p->buf[remainbuf],
|
||||
PACKETBUFSIZE - remainbuf,
|
||||
LIBSSH2_SOCKET_RECV_FLAGS(session));
|
||||
nread = SSH2_RECV(session, &p->buf[remainbuf],
|
||||
PACKETBUFSIZE - remainbuf,
|
||||
SSH2_SOCKET_RECV_FLAGS(session));
|
||||
if(nread <= 0) {
|
||||
/* check if this is due to EAGAIN and return the special
|
||||
return code if so, error out normally otherwise */
|
||||
@@ -496,18 +495,17 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
LIBSSH2_SESSION_BLOCK_INBOUND;
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
}
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Error recving %ld bytes (got %ld)",
|
||||
(long)(PACKETBUFSIZE - remainbuf),
|
||||
(long)-nread));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Error recving %ld bytes (got %ld)",
|
||||
(long)(PACKETBUFSIZE - remainbuf), (long)-nread));
|
||||
return LIBSSH2_ERROR_SOCKET_RECV;
|
||||
}
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Recved %ld/%ld bytes to %p+%ld", (long)nread,
|
||||
(long)(PACKETBUFSIZE - remainbuf), (void *)p->buf,
|
||||
(long)remainbuf));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Recved %ld/%ld bytes to %p+%ld", (long)nread,
|
||||
(long)(PACKETBUFSIZE - remainbuf), (void *)p->buf,
|
||||
(long)remainbuf));
|
||||
|
||||
debugdump(session, "libssh2_transport_read() raw",
|
||||
debugdump(session, "ssh2_transport_read() raw",
|
||||
&p->buf[remainbuf], nread);
|
||||
/* advance write pointer */
|
||||
p->writeidx += nread;
|
||||
@@ -561,17 +559,17 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
if(rc != LIBSSH2_ERROR_NONE) {
|
||||
p->total_num = 0; /* no packet buffer available */
|
||||
if(p->payload)
|
||||
LIBSSH2_FREE(session, p->payload);
|
||||
SSH2_FREE(session, p->payload);
|
||||
p->payload = NULL;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* store size in buffers for use below */
|
||||
ptr = &block[0];
|
||||
_libssh2_store_u32(&ptr, len);
|
||||
ssh2_store_u32(&ptr, len);
|
||||
|
||||
ptr = &p->init[0];
|
||||
_libssh2_store_u32(&ptr, len);
|
||||
ssh2_store_u32(&ptr, len);
|
||||
}
|
||||
else {
|
||||
if(encrypted) {
|
||||
@@ -598,7 +596,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
/* we now have the initial blocksize bytes decrypted,
|
||||
* and we can extract packet and padding length from it
|
||||
*/
|
||||
p->packet_length = _libssh2_ntohu32(block);
|
||||
p->packet_length = ssh2_ntohu32(block);
|
||||
}
|
||||
|
||||
if(!encrypted || !CRYPT_FLAG_R(session, REQUIRES_FULL_PACKET)) {
|
||||
@@ -616,7 +614,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
|
||||
/* we collect entire undecrypted packet including the
|
||||
packet length field that we run MAC over */
|
||||
p->packet_length = _libssh2_ntohu32(block);
|
||||
p->packet_length = ssh2_ntohu32(block);
|
||||
total_num = 4 + p->packet_length + remote_mac->mac_len;
|
||||
}
|
||||
else {
|
||||
@@ -645,7 +643,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
*/
|
||||
total_num = 4;
|
||||
|
||||
p->packet_length = _libssh2_ntohu32(block);
|
||||
p->packet_length = ssh2_ntohu32(block);
|
||||
if(p->packet_length < 1)
|
||||
return LIBSSH2_ERROR_DECRYPT;
|
||||
|
||||
@@ -675,7 +673,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
|
||||
/* Get a packet handle put data into. We get one to
|
||||
hold all data, including padding and MAC. */
|
||||
p->payload = LIBSSH2_ALLOC(session, total_num);
|
||||
p->payload = SSH2_ALLOC(session, total_num);
|
||||
if(!p->payload) {
|
||||
return LIBSSH2_ERROR_ALLOC;
|
||||
}
|
||||
@@ -698,7 +696,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
}
|
||||
else {
|
||||
if(p->payload)
|
||||
LIBSSH2_FREE(session, p->payload);
|
||||
SSH2_FREE(session, p->payload);
|
||||
p->payload = NULL;
|
||||
return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
|
||||
}
|
||||
@@ -763,7 +761,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
amount to decrypt even more */
|
||||
if((p->data_num + numbytes) >= (p->total_num - skip)) {
|
||||
/* decrypt the entire rest of the package */
|
||||
numdecrypt = LIBSSH2_MAX(0,
|
||||
numdecrypt = SSH2_MAX(0,
|
||||
(int)(p->total_num - skip) - (int)p->data_num);
|
||||
firstlast = LAST_BLOCK;
|
||||
}
|
||||
@@ -782,7 +780,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
if(CRYPT_FLAG_R(session, INTEGRATED_MAC)) {
|
||||
/* Make sure that we save enough bytes to make the last
|
||||
* block large enough to hold the entire integrated MAC */
|
||||
numdecrypt = LIBSSH2_MIN(numdecrypt,
|
||||
numdecrypt = SSH2_MIN(numdecrypt,
|
||||
(int)(p->total_num - skip - blocksize - p->data_num));
|
||||
numbytes = 0;
|
||||
}
|
||||
@@ -858,7 +856,7 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
}
|
||||
else {
|
||||
if(p->payload)
|
||||
LIBSSH2_FREE(session, p->payload);
|
||||
SSH2_FREE(session, p->payload);
|
||||
p->payload = NULL;
|
||||
return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
|
||||
}
|
||||
@@ -877,13 +875,13 @@ int _libssh2_transport_read(LIBSSH2_SESSION *session)
|
||||
|
||||
if(!remainpack) {
|
||||
/* we have a full packet */
|
||||
libssh2_transport_read_point1:
|
||||
ssh2_transport_read_point1:
|
||||
rc = fullpacket(session, encrypted);
|
||||
if(rc == LIBSSH2_ERROR_EAGAIN) {
|
||||
|
||||
if(session->packAdd_state != libssh2_NB_state_idle) {
|
||||
if(session->packAdd_state != ssh2_NB_state_idle) {
|
||||
/* fullpacket only returns LIBSSH2_ERROR_EAGAIN if
|
||||
* libssh2_packet_add() returns LIBSSH2_ERROR_EAGAIN. If
|
||||
* ssh2_packet_add() returns LIBSSH2_ERROR_EAGAIN. If
|
||||
* that returns LIBSSH2_ERROR_EAGAIN but the packAdd_state
|
||||
* is idle, then the packet has been added to the brigade,
|
||||
* but some immediate action that was taken based on the
|
||||
@@ -892,7 +890,7 @@ libssh2_transport_read_point1:
|
||||
* in.
|
||||
*/
|
||||
session->readPack_encrypted = encrypted;
|
||||
session->readPack_state = libssh2_NB_state_jump1;
|
||||
session->readPack_state = ssh2_NB_state_jump1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
@@ -926,8 +924,8 @@ static int send_existing(LIBSSH2_SESSION *session, const unsigned char *data,
|
||||
we do not add this one up until the previous one has been sent. To
|
||||
make the caller really notice his/hers flaw, we return error for
|
||||
this case */
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Address is different, returning EAGAIN"));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Address is different, returning EAGAIN"));
|
||||
return LIBSSH2_ERROR_EAGAIN;
|
||||
}
|
||||
|
||||
@@ -936,17 +934,16 @@ static int send_existing(LIBSSH2_SESSION *session, const unsigned char *data,
|
||||
/* number of bytes left to send */
|
||||
length = p->ototal_num - p->osent;
|
||||
|
||||
rc = LIBSSH2_SEND(session, &p->outbuf[p->osent], length,
|
||||
LIBSSH2_SOCKET_SEND_FLAGS(session));
|
||||
rc = SSH2_SEND(session, &p->outbuf[p->osent], length,
|
||||
SSH2_SOCKET_SEND_FLAGS(session));
|
||||
if(rc < 0)
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Error sending %ld bytes: %ld",
|
||||
(long)length, (long)-rc));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Error sending %ld bytes: %ld", (long)length, (long)-rc));
|
||||
else {
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Sent %ld/%ld bytes at %p+%lu", (long)rc, (long)length,
|
||||
(void *)p->outbuf, (unsigned long)p->osent));
|
||||
debugdump(session, "libssh2_transport_write send()",
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Sent %ld/%ld bytes at %p+%lu", (long)rc, (long)length,
|
||||
(void *)p->outbuf, (unsigned long)p->osent));
|
||||
debugdump(session, "ssh2_transport_send()",
|
||||
&p->outbuf[p->osent], rc);
|
||||
}
|
||||
|
||||
@@ -988,14 +985,14 @@ static int send_existing(LIBSSH2_SESSION *session, const unsigned char *data,
|
||||
* then be called with the same argument set (same data pointer and same
|
||||
* data_len) until ERROR_NONE or failure is returned.
|
||||
*
|
||||
* This function DOES NOT call _libssh2_error() on any errors.
|
||||
* This function DOES NOT call ssh2_err() on any errors.
|
||||
*/
|
||||
int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
const unsigned char *data, size_t data_len,
|
||||
const unsigned char *data2, size_t data2_len)
|
||||
int ssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
const unsigned char *data, size_t data_len,
|
||||
const unsigned char *data2, size_t data2_len)
|
||||
{
|
||||
int blocksize =
|
||||
(session->state & LIBSSH2_STATE_NEWKEYS) ?
|
||||
(session->state & SSH2_STATE_NEWKEYS) ?
|
||||
session->local.crypt->blocksize : 8;
|
||||
ssize_t padding_length;
|
||||
size_t packet_length;
|
||||
@@ -1021,22 +1018,22 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
* exchange, we must complete that key exchange before continuing to write
|
||||
* further data.
|
||||
*
|
||||
* See the similar block in _libssh2_transport_read for more details.
|
||||
* See the similar block in ssh2_transport_read() for more details.
|
||||
*/
|
||||
if(session->state & LIBSSH2_STATE_EXCHANGING_KEYS &&
|
||||
!(session->state & LIBSSH2_STATE_KEX_ACTIVE)) {
|
||||
if(session->state & SSH2_STATE_EXCHANGING_KEYS &&
|
||||
!(session->state & SSH2_STATE_KEX_ACTIVE)) {
|
||||
/* Do not write any new packets if we are still in the middle of a key
|
||||
* exchange. */
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Redirecting into the"
|
||||
" key re-exchange from _libssh2_transport_send"));
|
||||
rc = _libssh2_kex_exchange(session, 1, &session->startup_key_state);
|
||||
ssh2_deb((session, LIBSSH2_TRACE_TRANS, "Redirecting into the"
|
||||
" key re-exchange from ssh2_transport_send()"));
|
||||
rc = ssh2_kex_exchange(session, 1, &session->startup_key_state);
|
||||
if(rc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
debugdump(session, "libssh2_transport_write plain", data, data_len);
|
||||
debugdump(session, "ssh2_transport_send() plain", data, data_len);
|
||||
if(data2)
|
||||
debugdump(session, "libssh2_transport_write plain2", data2, data2_len);
|
||||
debugdump(session, "ssh2_transport_send() plain2", data2, data2_len);
|
||||
|
||||
/* FIRST, check if we have a pending write to complete. send_existing
|
||||
only sanity-check data and data_len and not data2 and data2_len! */
|
||||
@@ -1050,7 +1047,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
/* set by send_existing if data was sent */
|
||||
return rc;
|
||||
|
||||
encrypted = (session->state & LIBSSH2_STATE_NEWKEYS) ? 1 : 0;
|
||||
encrypted = (session->state & SSH2_STATE_NEWKEYS) ? 1 : 0;
|
||||
|
||||
if(encrypted && session->local.crypt &&
|
||||
CRYPT_FLAG_L(session, REQUIRES_FULL_PACKET)) {
|
||||
@@ -1064,7 +1061,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
|
||||
compressed = session->local.comp &&
|
||||
session->local.comp->compress &&
|
||||
((session->state & LIBSSH2_STATE_AUTHENTICATED) ||
|
||||
((session->state & SSH2_STATE_AUTHENTICATED) ||
|
||||
session->local.comp->use_in_auth);
|
||||
|
||||
if(encrypted && compressed && session->local.comp_abstract) {
|
||||
@@ -1162,14 +1159,14 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
|
||||
/* store packet_length, which is the size of the whole packet except
|
||||
the MAC and the packet_length field itself */
|
||||
_libssh2_htonu32(p->outbuf, (uint32_t)(packet_length - 4));
|
||||
ssh2_htonu32(p->outbuf, (uint32_t)(packet_length - 4));
|
||||
/* store padding_length */
|
||||
p->outbuf[4] = (unsigned char)padding_length;
|
||||
|
||||
/* fill the padding area with random junk */
|
||||
if(_libssh2_random(p->outbuf + 5 + data_len, padding_length)) {
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_RANDGEN,
|
||||
"Unable to get random bytes for packet padding");
|
||||
if(ssh2_random(p->outbuf + 5 + data_len, padding_length)) {
|
||||
return ssh2_err(session, LIBSSH2_ERROR_RANDGEN,
|
||||
"Unable to get random bytes for packet padding");
|
||||
}
|
||||
|
||||
if(encrypted) {
|
||||
@@ -1186,8 +1183,8 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
session->local.seqno, p->outbuf,
|
||||
packet_length, NULL, 0,
|
||||
&session->local.mac_abstract))
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_MAC_FAILURE,
|
||||
"Failed to calculate MAC");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_MAC_FAILURE,
|
||||
"Failed to calculate MAC");
|
||||
}
|
||||
|
||||
if(CRYPT_FLAG_L(session, REQUIRES_FULL_PACKET)) {
|
||||
@@ -1209,8 +1206,8 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
for(i = etm_crypt_offset; i < packet_length;
|
||||
i += session->local.crypt->blocksize) {
|
||||
unsigned char *ptr = &p->outbuf[i];
|
||||
size_t bsize = LIBSSH2_MIN(session->local.crypt->blocksize,
|
||||
(int)(packet_length - i));
|
||||
size_t bsize = SSH2_MIN(session->local.crypt->blocksize,
|
||||
(int)(packet_length - i));
|
||||
/* The INTEGRATED_MAC case always has an extra call below, so
|
||||
it never is LAST_BLOCK up here. */
|
||||
int firstlast = i == 0 ? FIRST_BLOCK :
|
||||
@@ -1230,11 +1227,10 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
/* advance the loop counter by the extra amount */
|
||||
i += bsize - session->local.crypt->blocksize;
|
||||
}
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SOCKET,
|
||||
"crypting bytes %lu-%lu", (unsigned long)i,
|
||||
(unsigned long)(i + bsize - 1)));
|
||||
if(session->local.crypt->crypt(session, 0, ptr,
|
||||
bsize,
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SOCKET,
|
||||
"crypting bytes %lu-%lu", (unsigned long)i,
|
||||
(unsigned long)(i + bsize - 1)));
|
||||
if(session->local.crypt->crypt(session, 0, ptr, bsize,
|
||||
&session->local.crypt_abstract,
|
||||
firstlast))
|
||||
return LIBSSH2_ERROR_ENCRYPT; /* encryption failure */
|
||||
@@ -1246,8 +1242,7 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
int authlen = local_mac ? local_mac->mac_len : 0;
|
||||
assert((size_t)total_length <=
|
||||
packet_length + session->local.crypt->blocksize);
|
||||
if(session->local.crypt->crypt(session,
|
||||
0,
|
||||
if(session->local.crypt->crypt(session, 0,
|
||||
&p->outbuf[packet_length],
|
||||
authlen,
|
||||
&session->local.crypt_abstract,
|
||||
@@ -1266,8 +1261,8 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
session->local.seqno, p->outbuf,
|
||||
packet_length, NULL, 0,
|
||||
&session->local.mac_abstract))
|
||||
return _libssh2_error(session, LIBSSH2_ERROR_MAC_FAILURE,
|
||||
"Failed to calculate MAC");
|
||||
return ssh2_err(session, LIBSSH2_ERROR_MAC_FAILURE,
|
||||
"Failed to calculate MAC");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1277,17 +1272,17 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
session->local.seqno = 0;
|
||||
}
|
||||
|
||||
ret = LIBSSH2_SEND(session, p->outbuf, total_length,
|
||||
LIBSSH2_SOCKET_SEND_FLAGS(session));
|
||||
ret = SSH2_SEND(session, p->outbuf, total_length,
|
||||
SSH2_SOCKET_SEND_FLAGS(session));
|
||||
if(ret < 0)
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Error sending %ld bytes: %ld",
|
||||
(long)total_length, (long)-ret));
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Error sending %ld bytes: %ld",
|
||||
(long)total_length, (long)-ret));
|
||||
else {
|
||||
_libssh2_debug((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Sent %ld/%ld bytes at %p",
|
||||
(long)ret, (long)total_length, (void *)p->outbuf));
|
||||
debugdump(session, "libssh2_transport_write send()", p->outbuf, ret);
|
||||
ssh2_deb((session, LIBSSH2_TRACE_SOCKET,
|
||||
"Sent %ld/%ld bytes at %p",
|
||||
(long)ret, (long)total_length, (void *)p->outbuf));
|
||||
debugdump(session, "ssh2_transport_send()", p->outbuf, ret);
|
||||
}
|
||||
|
||||
if(ret != total_length) {
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include "packet.h"
|
||||
|
||||
/*
|
||||
* libssh2_transport_send
|
||||
* ssh2_transport_send()
|
||||
*
|
||||
* Send a packet, encrypting it and adding a MAC code if necessary
|
||||
* Returns 0 on success, non-zero on failure.
|
||||
@@ -61,14 +61,14 @@
|
||||
* then be called with the same argument set (same data pointer and same
|
||||
* data_len) until ERROR_NONE or failure is returned.
|
||||
*
|
||||
* This function DOES NOT call _libssh2_error() on any errors.
|
||||
* This function DOES NOT call ssh2_err() on any errors.
|
||||
*/
|
||||
int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
const unsigned char *data, size_t data_len,
|
||||
const unsigned char *data2, size_t data2_len);
|
||||
int ssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
const unsigned char *data, size_t data_len,
|
||||
const unsigned char *data2, size_t data2_len);
|
||||
|
||||
/*
|
||||
* _libssh2_transport_read
|
||||
* ssh2_transport_read()
|
||||
*
|
||||
* Collect a packet into the input brigade block only controls whether or not
|
||||
* to wait for a packet to start.
|
||||
@@ -82,6 +82,6 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session,
|
||||
* This function reads the binary stream as specified in chapter 6 of RFC4253
|
||||
* "The Secure Shell (SSH) Transport Layer Protocol"
|
||||
*/
|
||||
int _libssh2_transport_read(LIBSSH2_SESSION *session);
|
||||
int ssh2_transport_read(LIBSSH2_SESSION *session);
|
||||
|
||||
#endif /* LIBSSH2_TRANSPORT_H */
|
||||
|
||||
1317
src/userauth.c
1317
src/userauth.c
File diff suppressed because it is too large
Load Diff
@@ -40,7 +40,7 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
int _libssh2_userauth_publickey(
|
||||
int ssh2_userauth_publickey(
|
||||
LIBSSH2_SESSION *session,
|
||||
const char *username,
|
||||
size_t username_len,
|
||||
|
||||
@@ -55,67 +55,61 @@ int userauth_keyboard_interactive_decode_info_request(LIBSSH2_SESSION *session)
|
||||
decoded.len = session->userauth_kybd_data_len;
|
||||
|
||||
if(session->userauth_kybd_data_len < 17) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
|
||||
"userauth keyboard data buffer too small "
|
||||
"to get length");
|
||||
ssh2_err(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
|
||||
"userauth keyboard data buffer too small to get length");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* byte SSH_MSG_USERAUTH_INFO_REQUEST */
|
||||
_libssh2_get_byte(&decoded, &packet_type);
|
||||
ssh2_get_byte(&decoded, &packet_type);
|
||||
|
||||
/* string name (ISO-10646 UTF-8) */
|
||||
if(_libssh2_copy_string(session, &decoded,
|
||||
&session->userauth_kybd_auth_name,
|
||||
&session->userauth_kybd_auth_name_len) == -1) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to decode "
|
||||
"keyboard-interactive 'name' "
|
||||
"request field");
|
||||
if(ssh2_copy_string(session, &decoded,
|
||||
&session->userauth_kybd_auth_name,
|
||||
&session->userauth_kybd_auth_name_len) == -1) {
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to decode keyboard-interactive 'name' "
|
||||
"request field");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* string instruction (ISO-10646 UTF-8) */
|
||||
if(_libssh2_copy_string(session, &decoded,
|
||||
&session->userauth_kybd_auth_instruction,
|
||||
&session->userauth_kybd_auth_instruction_len)
|
||||
== -1) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to decode "
|
||||
"keyboard-interactive 'instruction' "
|
||||
"request field");
|
||||
if(ssh2_copy_string(session, &decoded,
|
||||
&session->userauth_kybd_auth_instruction,
|
||||
&session->userauth_kybd_auth_instruction_len) == -1) {
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to decode keyboard-interactive 'instruction' "
|
||||
"request field");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* string language tag (as defined in [RFC-3066]) */
|
||||
if(_libssh2_get_string(&decoded, &language_tag, &language_tag_len) == -1) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to decode "
|
||||
"keyboard-interactive 'language tag' "
|
||||
"request field");
|
||||
if(ssh2_get_string(&decoded, &language_tag, &language_tag_len) == -1) {
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to decode keyboard-interactive 'language tag' "
|
||||
"request field");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* int num-prompts */
|
||||
if(_libssh2_get_u32(&decoded, &tmp_u32) == -1) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
|
||||
"Unable to decode "
|
||||
"keyboard-interactive number of keyboard prompts");
|
||||
if(ssh2_get_u32(&decoded, &tmp_u32) == -1) {
|
||||
ssh2_err(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
|
||||
"Unable to decode "
|
||||
"keyboard-interactive number of keyboard prompts");
|
||||
return -1;
|
||||
}
|
||||
|
||||
session->userauth_kybd_num_prompts = tmp_u32;
|
||||
if(session->userauth_kybd_num_prompts != tmp_u32) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY,
|
||||
"Unable to decode "
|
||||
"keyboard-interactive number of keyboard prompts");
|
||||
ssh2_err(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY,
|
||||
"Unable to decode "
|
||||
"keyboard-interactive number of keyboard prompts");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(session->userauth_kybd_num_prompts > 100) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY,
|
||||
"Too many replies for "
|
||||
"keyboard-interactive prompts");
|
||||
ssh2_err(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY,
|
||||
"Too many replies for keyboard-interactive prompts");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -124,46 +118,40 @@ int userauth_keyboard_interactive_decode_info_request(LIBSSH2_SESSION *session)
|
||||
}
|
||||
|
||||
session->userauth_kybd_prompts =
|
||||
LIBSSH2_CALLOC(session,
|
||||
sizeof(LIBSSH2_USERAUTH_KBDINT_PROMPT) *
|
||||
session->userauth_kybd_num_prompts);
|
||||
SSH2_CALLOC(session, sizeof(LIBSSH2_USERAUTH_KBDINT_PROMPT) *
|
||||
session->userauth_kybd_num_prompts);
|
||||
if(!session->userauth_kybd_prompts) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"keyboard-interactive prompts array");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"keyboard-interactive prompts array");
|
||||
return -1;
|
||||
}
|
||||
|
||||
session->userauth_kybd_responses =
|
||||
LIBSSH2_CALLOC(session,
|
||||
sizeof(LIBSSH2_USERAUTH_KBDINT_RESPONSE) *
|
||||
session->userauth_kybd_num_prompts);
|
||||
SSH2_CALLOC(session, sizeof(LIBSSH2_USERAUTH_KBDINT_RESPONSE) *
|
||||
session->userauth_kybd_num_prompts);
|
||||
if(!session->userauth_kybd_responses) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"keyboard-interactive responses array");
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for "
|
||||
"keyboard-interactive responses array");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(i = 0; i < session->userauth_kybd_num_prompts; i++) {
|
||||
/* string prompt[1] (ISO-10646 UTF-8) */
|
||||
if(_libssh2_copy_string(session, &decoded,
|
||||
&session->userauth_kybd_prompts[i].text,
|
||||
&session->userauth_kybd_prompts[i].length)
|
||||
== -1) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to decode "
|
||||
"keyboard-interactive prompt message");
|
||||
if(ssh2_copy_string(session, &decoded,
|
||||
&session->userauth_kybd_prompts[i].text,
|
||||
&session->userauth_kybd_prompts[i].length) == -1) {
|
||||
ssh2_err(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to decode keyboard-interactive prompt message");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* boolean echo[1] */
|
||||
if(_libssh2_get_boolean(&decoded,
|
||||
&session->userauth_kybd_prompts[i].echo)
|
||||
== -1) {
|
||||
_libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
|
||||
"Unable to decode "
|
||||
"user auth keyboard prompt echo");
|
||||
if(ssh2_get_boolean(&decoded,
|
||||
&session->userauth_kybd_prompts[i].echo) == -1) {
|
||||
ssh2_err(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
|
||||
"Unable to decode user auth keyboard prompt echo");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,5 +50,5 @@ const char *libssh2_version(int req_version_num)
|
||||
LIBSSH2_API
|
||||
libssh2_crypto_engine_t libssh2_crypto_engine(void)
|
||||
{
|
||||
return LIBSSH2_CRYPTO_ENGINE;
|
||||
return SSH2_CRYPTO_ENGINE;
|
||||
}
|
||||
|
||||
1540
src/wincng.c
1540
src/wincng.c
File diff suppressed because it is too large
Load Diff
460
src/wincng.h
460
src/wincng.h
@@ -40,7 +40,7 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#define LIBSSH2_CRYPTO_ENGINE libssh2_wincng
|
||||
#define SSH2_CRYPTO_ENGINE libssh2_wincng
|
||||
|
||||
/* required for cross-compilation against the w64 mingw-runtime package */
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600)
|
||||
@@ -108,7 +108,7 @@
|
||||
|
||||
#if LIBSSH2_ECDSA
|
||||
#else
|
||||
#define libssh2_ec_key void
|
||||
#define ssh2_ec_key void
|
||||
#endif
|
||||
|
||||
/*******************************************************************/
|
||||
@@ -116,7 +116,7 @@
|
||||
* Windows CNG backend: Global context handles
|
||||
*/
|
||||
|
||||
struct libssh2_wincng_ctx {
|
||||
struct wcng_ctx {
|
||||
BCRYPT_ALG_HANDLE hAlgRNG;
|
||||
BCRYPT_ALG_HANDLE hAlgHashMD5;
|
||||
BCRYPT_ALG_HANDLE hAlgHashSHA1;
|
||||
@@ -137,32 +137,32 @@ struct libssh2_wincng_ctx {
|
||||
BCRYPT_ALG_HANDLE hAlgDH;
|
||||
BCRYPT_ALG_HANDLE hAlgChacha20;
|
||||
#if LIBSSH2_ECDSA
|
||||
BCRYPT_ALG_HANDLE hAlgECDH[3]; /* indexed by libssh2_curve_type */
|
||||
BCRYPT_ALG_HANDLE hAlgECDSA[3]; /* indexed by libssh2_curve_type */
|
||||
BCRYPT_ALG_HANDLE hAlgECDH[3]; /* indexed by ssh2_curve_type */
|
||||
BCRYPT_ALG_HANDLE hAlgECDSA[3]; /* indexed by ssh2_curve_type */
|
||||
#endif
|
||||
volatile int hasAlgDHwithKDF; /* -1=no, 0=maybe, 1=yes */
|
||||
};
|
||||
|
||||
extern struct libssh2_wincng_ctx wincng_ctx;
|
||||
extern struct wcng_ctx ssh2_wcng;
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* Windows CNG backend: Generic functions
|
||||
*/
|
||||
|
||||
#define libssh2_crypto_init() _libssh2_wincng_init()
|
||||
#define libssh2_crypto_exit() _libssh2_wincng_free()
|
||||
#define ssh2_crypto_init() ssh2_wcng_init()
|
||||
#define ssh2_crypto_exit() ssh2_wcng_free()
|
||||
|
||||
#define _libssh2_random(buf, len) _libssh2_wincng_random(buf, len)
|
||||
#define ssh2_random(buf, len) ssh2_wcng_random(buf, len)
|
||||
|
||||
#define libssh2_prepare_iovec(vec, len) /* Empty. */
|
||||
#define ssh2_prepare_iovec(vec, len) /* Empty. */
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* Windows CNG backend: Hash structure
|
||||
*/
|
||||
|
||||
struct wincng_hash_ctx {
|
||||
struct wcng_hash_ctx {
|
||||
BCRYPT_HASH_HANDLE hHash;
|
||||
unsigned char *pbHashObject;
|
||||
ULONG dwHashObject;
|
||||
@@ -173,77 +173,77 @@ struct wincng_hash_ctx {
|
||||
* Windows CNG backend: Hash functions
|
||||
*/
|
||||
|
||||
#define libssh2_sha1_ctx struct wincng_hash_ctx
|
||||
#define libssh2_sha1_init(ctx) \
|
||||
(_libssh2_wincng_hash_init(ctx, wincng_ctx.hAlgHashSHA1, \
|
||||
SHA_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#define libssh2_sha1_update(ctx, data, datalen) \
|
||||
(_libssh2_wincng_hash_update(&(ctx), data, (ULONG)(datalen)) == 0)
|
||||
#define libssh2_sha1_final(ctx, hash) \
|
||||
(_libssh2_wincng_hash_final(&(ctx), hash) == 0)
|
||||
#define libssh2_sha1(data, datalen, hash) \
|
||||
_libssh2_wincng_hash(data, datalen, wincng_ctx.hAlgHashSHA1, \
|
||||
hash, SHA_DIGEST_LENGTH)
|
||||
#define ssh2_sha1_ctx struct wcng_hash_ctx
|
||||
#define ssh2_sha1_init(ctx) \
|
||||
(ssh2_wcng_hash_init(ctx, ssh2_wcng.hAlgHashSHA1, \
|
||||
SHA_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#define ssh2_sha1_update(ctx, data, datalen) \
|
||||
(ssh2_wcng_hash_update(&(ctx), data, (ULONG)(datalen)) == 0)
|
||||
#define ssh2_sha1_final(ctx, hash) \
|
||||
(ssh2_wcng_hash_final(&(ctx), hash) == 0)
|
||||
#define ssh2_sha1(data, datalen, hash) \
|
||||
ssh2_wcng_hash(data, datalen, ssh2_wcng.hAlgHashSHA1, \
|
||||
hash, SHA_DIGEST_LENGTH)
|
||||
|
||||
#define libssh2_sha256_ctx struct wincng_hash_ctx
|
||||
#define libssh2_sha256_init(ctx) \
|
||||
(_libssh2_wincng_hash_init(ctx, wincng_ctx.hAlgHashSHA256, \
|
||||
SHA256_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#define libssh2_sha256_update(ctx, data, datalen) \
|
||||
(_libssh2_wincng_hash_update(&(ctx), data, (ULONG)(datalen)) == 0)
|
||||
#define libssh2_sha256_final(ctx, hash) \
|
||||
(_libssh2_wincng_hash_final(&(ctx), hash) == 0)
|
||||
#define libssh2_sha256(data, datalen, hash) \
|
||||
_libssh2_wincng_hash(data, datalen, wincng_ctx.hAlgHashSHA256, \
|
||||
hash, SHA256_DIGEST_LENGTH)
|
||||
#define ssh2_sha256_ctx struct wcng_hash_ctx
|
||||
#define ssh2_sha256_init(ctx) \
|
||||
(ssh2_wcng_hash_init(ctx, ssh2_wcng.hAlgHashSHA256, \
|
||||
SHA256_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#define ssh2_sha256_update(ctx, data, datalen) \
|
||||
(ssh2_wcng_hash_update(&(ctx), data, (ULONG)(datalen)) == 0)
|
||||
#define ssh2_sha256_final(ctx, hash) \
|
||||
(ssh2_wcng_hash_final(&(ctx), hash) == 0)
|
||||
#define ssh2_sha256(data, datalen, hash) \
|
||||
ssh2_wcng_hash(data, datalen, ssh2_wcng.hAlgHashSHA256, \
|
||||
hash, SHA256_DIGEST_LENGTH)
|
||||
|
||||
#define libssh2_sha384_ctx struct wincng_hash_ctx
|
||||
#define libssh2_sha384_init(ctx) \
|
||||
(_libssh2_wincng_hash_init(ctx, wincng_ctx.hAlgHashSHA384, \
|
||||
SHA384_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#define libssh2_sha384_update(ctx, data, datalen) \
|
||||
(_libssh2_wincng_hash_update(&(ctx), data, (ULONG)(datalen)) == 0)
|
||||
#define libssh2_sha384_final(ctx, hash) \
|
||||
(_libssh2_wincng_hash_final(&(ctx), hash) == 0)
|
||||
#define libssh2_sha384(data, datalen, hash) \
|
||||
_libssh2_wincng_hash(data, datalen, wincng_ctx.hAlgHashSHA384, \
|
||||
hash, SHA384_DIGEST_LENGTH)
|
||||
#define ssh2_sha384_ctx struct wcng_hash_ctx
|
||||
#define ssh2_sha384_init(ctx) \
|
||||
(ssh2_wcng_hash_init(ctx, ssh2_wcng.hAlgHashSHA384, \
|
||||
SHA384_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#define ssh2_sha384_update(ctx, data, datalen) \
|
||||
(ssh2_wcng_hash_update(&(ctx), data, (ULONG)(datalen)) == 0)
|
||||
#define ssh2_sha384_final(ctx, hash) \
|
||||
(ssh2_wcng_hash_final(&(ctx), hash) == 0)
|
||||
#define ssh2_sha384(data, datalen, hash) \
|
||||
ssh2_wcng_hash(data, datalen, ssh2_wcng.hAlgHashSHA384, \
|
||||
hash, SHA384_DIGEST_LENGTH)
|
||||
|
||||
#define libssh2_sha512_ctx struct wincng_hash_ctx
|
||||
#define libssh2_sha512_init(ctx) \
|
||||
(_libssh2_wincng_hash_init(ctx, wincng_ctx.hAlgHashSHA512, \
|
||||
SHA512_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#define libssh2_sha512_update(ctx, data, datalen) \
|
||||
(_libssh2_wincng_hash_update(&(ctx), data, (ULONG)(datalen)) == 0)
|
||||
#define libssh2_sha512_final(ctx, hash) \
|
||||
(_libssh2_wincng_hash_final(&(ctx), hash) == 0)
|
||||
#define libssh2_sha512(data, datalen, hash) \
|
||||
_libssh2_wincng_hash(data, datalen, wincng_ctx.hAlgHashSHA512, \
|
||||
hash, SHA512_DIGEST_LENGTH)
|
||||
#define ssh2_sha512_ctx struct wcng_hash_ctx
|
||||
#define ssh2_sha512_init(ctx) \
|
||||
(ssh2_wcng_hash_init(ctx, ssh2_wcng.hAlgHashSHA512, \
|
||||
SHA512_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#define ssh2_sha512_update(ctx, data, datalen) \
|
||||
(ssh2_wcng_hash_update(&(ctx), data, (ULONG)(datalen)) == 0)
|
||||
#define ssh2_sha512_final(ctx, hash) \
|
||||
(ssh2_wcng_hash_final(&(ctx), hash) == 0)
|
||||
#define ssh2_sha512(data, datalen, hash) \
|
||||
ssh2_wcng_hash(data, datalen, ssh2_wcng.hAlgHashSHA512, \
|
||||
hash, SHA512_DIGEST_LENGTH)
|
||||
|
||||
#if LIBSSH2_MD5 || LIBSSH2_MD5_PEM
|
||||
#define libssh2_md5_ctx struct wincng_hash_ctx
|
||||
#define libssh2_md5_init(ctx) \
|
||||
(_libssh2_wincng_hash_init(ctx, wincng_ctx.hAlgHashMD5, \
|
||||
MD5_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#define libssh2_md5_update(ctx, data, datalen) \
|
||||
(_libssh2_wincng_hash_update(&(ctx), data, (ULONG)(datalen)) == 0)
|
||||
#define libssh2_md5_final(ctx, hash) \
|
||||
(_libssh2_wincng_hash_final(&(ctx), hash) == 0)
|
||||
#define ssh2_md5_ctx struct wcng_hash_ctx
|
||||
#define ssh2_md5_init(ctx) \
|
||||
(ssh2_wcng_hash_init(ctx, ssh2_wcng.hAlgHashMD5, \
|
||||
MD5_DIGEST_LENGTH, NULL, 0) == 0)
|
||||
#define ssh2_md5_update(ctx, data, datalen) \
|
||||
(ssh2_wcng_hash_update(&(ctx), data, (ULONG)(datalen)) == 0)
|
||||
#define ssh2_md5_final(ctx, hash) \
|
||||
(ssh2_wcng_hash_final(&(ctx), hash) == 0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Windows CNG backend: HMAC functions
|
||||
*/
|
||||
|
||||
#define libssh2_hmac_ctx struct wincng_hash_ctx
|
||||
#define ssh2_hmac_ctx struct wcng_hash_ctx
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* Windows CNG backend: Key Context structure
|
||||
*/
|
||||
|
||||
struct wincng_key_ctx {
|
||||
struct wcng_key_ctx {
|
||||
BCRYPT_KEY_HANDLE hKey;
|
||||
void *pbKeyObject;
|
||||
DWORD cbKeyObject;
|
||||
@@ -253,127 +253,112 @@ struct wincng_key_ctx {
|
||||
* Windows CNG backend: RSA functions
|
||||
*/
|
||||
|
||||
#define libssh2_rsa_ctx struct wincng_key_ctx
|
||||
#define _libssh2_rsa_new(rsactx, e, e_len, n, n_len, \
|
||||
d, d_len, p, p_len, q, q_len, \
|
||||
e1, e1_len, e2, e2_len, c, c_len) \
|
||||
_libssh2_wincng_rsa_new(rsactx, e, e_len, n, n_len, \
|
||||
d, d_len, p, p_len, q, q_len, \
|
||||
e1, e1_len, e2, e2_len, c, c_len)
|
||||
#define _libssh2_rsa_new_private(rsactx, s, filename, passphrase) \
|
||||
_libssh2_wincng_rsa_new_private(rsactx, s, filename, passphrase)
|
||||
#define _libssh2_rsa_new_private_frommemory(rsactx, s, filedata, \
|
||||
filedata_len, passphrase) \
|
||||
_libssh2_wincng_rsa_new_private_frommemory(rsactx, s, filedata, \
|
||||
filedata_len, passphrase)
|
||||
#define _libssh2_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) \
|
||||
_libssh2_wincng_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len)
|
||||
#define _libssh2_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len) \
|
||||
_libssh2_wincng_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len)
|
||||
#define _libssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) \
|
||||
_libssh2_wincng_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len)
|
||||
#define _libssh2_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) \
|
||||
_libssh2_wincng_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len)
|
||||
#define _libssh2_rsa_free(rsactx) \
|
||||
_libssh2_wincng_rsa_free(rsactx)
|
||||
#define ssh2_rsa_ctx struct wcng_key_ctx
|
||||
#define ssh2_rsa_new(rsactx, e, e_len, n, n_len, d, d_len, p, p_len, \
|
||||
q, q_len, e1, e1_len, e2, e2_len, c, c_len) \
|
||||
ssh2_wcng_rsa_new(rsactx, e, e_len, n, n_len, d, d_len, p, p_len, \
|
||||
q, q_len, e1, e1_len, e2, e2_len, c, c_len)
|
||||
#define ssh2_rsa_new_private(rsactx, s, filename, passphrase) \
|
||||
ssh2_wcng_rsa_new_private(rsactx, s, filename, passphrase)
|
||||
#define ssh2_rsa_new_private_frommemory(rsactx, s, filedata, \
|
||||
filedata_len, passphrase) \
|
||||
ssh2_wcng_rsa_new_private_frommemory(rsactx, s, filedata, \
|
||||
filedata_len, passphrase)
|
||||
#define ssh2_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len) \
|
||||
ssh2_wcng_rsa_sha1_sign(s, rsactx, hash, hash_len, sig, sig_len)
|
||||
#define ssh2_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len) \
|
||||
ssh2_wcng_rsa_sha2_sign(s, rsactx, hash, hash_len, sig, sig_len)
|
||||
#define ssh2_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len) \
|
||||
ssh2_wcng_rsa_sha1_verify(rsactx, sig, sig_len, m, m_len)
|
||||
#define ssh2_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len) \
|
||||
ssh2_wcng_rsa_sha2_verify(rsactx, hash_len, sig, sig_len, m, m_len)
|
||||
#define ssh2_rsa_free(rsactx) \
|
||||
ssh2_wcng_rsa_free(rsactx)
|
||||
|
||||
/*
|
||||
* Windows CNG backend: DSA functions
|
||||
*/
|
||||
|
||||
#define libssh2_dsa_ctx struct wincng_key_ctx
|
||||
#define _libssh2_dsa_new(dsactx, p, p_len, q, q_len, \
|
||||
g, g_len, y, y_len, x, x_len) \
|
||||
_libssh2_wincng_dsa_new(dsactx, p, p_len, q, q_len, \
|
||||
g, g_len, y, y_len, x, x_len)
|
||||
#define _libssh2_dsa_new_private(dsactx, s, filename, passphrase) \
|
||||
_libssh2_wincng_dsa_new_private(dsactx, s, filename, passphrase)
|
||||
#define _libssh2_dsa_new_private_frommemory(dsactx, s, filedata, \
|
||||
filedata_len, passphrase) \
|
||||
_libssh2_wincng_dsa_new_private_frommemory(dsactx, s, filedata, \
|
||||
filedata_len, passphrase)
|
||||
#define _libssh2_dsa_sha1_sign(dsactx, hash, hash_len, sig) \
|
||||
_libssh2_wincng_dsa_sha1_sign(dsactx, hash, hash_len, sig)
|
||||
#define _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len) \
|
||||
_libssh2_wincng_dsa_sha1_verify(dsactx, sig, m, m_len)
|
||||
#define _libssh2_dsa_free(dsactx) \
|
||||
_libssh2_wincng_dsa_free(dsactx)
|
||||
#define ssh2_dsa_ctx struct wcng_key_ctx
|
||||
#define ssh2_dsa_new(dsactx, p, p_len, q, q_len, g, g_len, y, y_len, \
|
||||
x, x_len) \
|
||||
ssh2_wcng_dsa_new(dsactx, p, p_len, q, q_len, g, g_len, y, y_len, \
|
||||
x, x_len)
|
||||
#define ssh2_dsa_new_private(dsactx, s, filename, passphrase) \
|
||||
ssh2_wcng_dsa_new_private(dsactx, s, filename, passphrase)
|
||||
#define ssh2_dsa_new_private_frommemory(dsactx, s, filedata, \
|
||||
filedata_len, passphrase) \
|
||||
ssh2_wcng_dsa_new_private_frommemory(dsactx, s, filedata, \
|
||||
filedata_len, passphrase)
|
||||
#define ssh2_dsa_sha1_sign(dsactx, hash, hash_len, sig) \
|
||||
ssh2_wcng_dsa_sha1_sign(dsactx, hash, hash_len, sig)
|
||||
#define ssh2_dsa_sha1_verify(dsactx, sig, m, m_len) \
|
||||
ssh2_wcng_dsa_sha1_verify(dsactx, sig, m, m_len)
|
||||
#define ssh2_dsa_free(dsactx) \
|
||||
ssh2_wcng_dsa_free(dsactx)
|
||||
|
||||
/*
|
||||
* Windows CNG backend: ECDSA functions
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
LIBSSH2_EC_CURVE_NISTP256 = 0,
|
||||
LIBSSH2_EC_CURVE_NISTP384 = 1,
|
||||
LIBSSH2_EC_CURVE_NISTP521 = 2,
|
||||
} libssh2_curve_type;
|
||||
SSH2_EC_CURVE_NISTP256 = 0,
|
||||
SSH2_EC_CURVE_NISTP384 = 1,
|
||||
SSH2_EC_CURVE_NISTP521 = 2,
|
||||
} ssh2_curve_type;
|
||||
|
||||
struct wincng_ecdsa_ctx {
|
||||
struct wcng_ecdsa_ctx {
|
||||
BCRYPT_KEY_HANDLE handle;
|
||||
libssh2_curve_type curve;
|
||||
ssh2_curve_type curve;
|
||||
};
|
||||
|
||||
#define libssh2_ecdsa_ctx struct wincng_ecdsa_ctx
|
||||
|
||||
#define ssh2_ecdsa_ctx struct wcng_ecdsa_ctx
|
||||
#if LIBSSH2_ECDSA
|
||||
#define libssh2_ec_key struct wincng_ecdsa_ctx
|
||||
#define ssh2_ec_key struct wcng_ecdsa_ctx
|
||||
#endif
|
||||
|
||||
void _libssh2_wincng_ecdsa_free(libssh2_ecdsa_ctx* ctx);
|
||||
|
||||
#define _libssh2_ecdsa_create_key(session, privkey, pubkey_octal, \
|
||||
pubkey_octal_len, curve) \
|
||||
_libssh2_wincng_ecdh_create_key(session, privkey, pubkey_octal, \
|
||||
pubkey_octal_len, curve)
|
||||
|
||||
#define _libssh2_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve) \
|
||||
_libssh2_wincng_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve)
|
||||
|
||||
#define _libssh2_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len) \
|
||||
_libssh2_wincng_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len)
|
||||
|
||||
#define _libssh2_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len) \
|
||||
_libssh2_wincng_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len)
|
||||
|
||||
#define _libssh2_ecdsa_new_private(ctx, session, filename, passphrase) \
|
||||
_libssh2_wincng_ecdsa_new_private(ctx, session, filename, passphrase)
|
||||
|
||||
#define _libssh2_ecdsa_new_private_frommemory(ctx, session, filedata, \
|
||||
filedata_len, passphrase) \
|
||||
_libssh2_wincng_ecdsa_new_private_frommemory(ctx, session, filedata, \
|
||||
filedata_len, passphrase)
|
||||
|
||||
#define _libssh2_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len) \
|
||||
_libssh2_wincng_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len)
|
||||
|
||||
#define _libssh2_ecdsa_get_curve_type(ctx) \
|
||||
_libssh2_wincng_ecdsa_get_curve_type(ctx)
|
||||
|
||||
#define _libssh2_ecdsa_free(ecdsactx) \
|
||||
_libssh2_wincng_ecdsa_free(ecdsactx)
|
||||
void ssh2_wcng_ecdsa_free(ssh2_ecdsa_ctx* ctx);
|
||||
#define ssh2_ecdsa_create_key(session, privkey, pubkey_octal, \
|
||||
pubkey_octal_len, curve) \
|
||||
ssh2_wcng_ecdh_create_key(session, privkey, pubkey_octal, \
|
||||
pubkey_octal_len, curve)
|
||||
#define ssh2_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve) \
|
||||
ssh2_wcng_ecdsa_curve_name_with_octal_new(ctx, k, k_len, curve)
|
||||
#define ssh2_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len) \
|
||||
ssh2_wcng_ecdh_gen_k(k, privkey, server_pubkey, server_pubkey_len)
|
||||
#define ssh2_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len) \
|
||||
ssh2_wcng_ecdsa_verify(ctx, r, r_len, s, s_len, m, m_len)
|
||||
#define ssh2_ecdsa_new_private(ctx, session, filename, passphrase) \
|
||||
ssh2_wcng_ecdsa_new_private(ctx, session, filename, passphrase)
|
||||
#define ssh2_ecdsa_new_private_frommemory(ctx, session, filedata, \
|
||||
filedata_len, passphrase) \
|
||||
ssh2_wcng_ecdsa_new_private_frommemory(ctx, session, filedata, \
|
||||
filedata_len, passphrase)
|
||||
#define ssh2_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len) \
|
||||
ssh2_wcng_ecdsa_sign(session, ctx, hash, hash_len, sign, sign_len)
|
||||
#define ssh2_ecdsa_get_curve_type(ctx) \
|
||||
ssh2_wcng_ecdsa_get_curve_type(ctx)
|
||||
#define ssh2_ecdsa_free(ecdsactx) \
|
||||
ssh2_wcng_ecdsa_free(ecdsactx)
|
||||
|
||||
/*
|
||||
* Windows CNG backend: Key functions
|
||||
*/
|
||||
|
||||
#define _libssh2_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) \
|
||||
_libssh2_wincng_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw)
|
||||
#define _libssh2_pub_priv_keyfilememory(s, m, m_len, p, p_len, \
|
||||
pk, pk_len, pw) \
|
||||
_libssh2_wincng_pub_priv_keyfilememory(s, m, m_len, p, p_len, \
|
||||
pk, pk_len, pw)
|
||||
#define _libssh2_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \
|
||||
f, kh, kh_len, pk, pk_len, pw) \
|
||||
_libssh2_wincng_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \
|
||||
f, kh, kh_len, pk, pk_len, pw)
|
||||
#define ssh2_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw) \
|
||||
ssh2_wcng_pub_priv_keyfile(s, m, m_len, p, p_len, pk, pw)
|
||||
#define ssh2_pub_priv_keyfilememory(s, m, m_len, p, p_len, pk, pk_len, pw) \
|
||||
ssh2_wcng_pub_priv_keyfilememory(s, m, m_len, p, p_len, pk, pk_len, pw)
|
||||
#define ssh2_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \
|
||||
f, kh, kh_len, pk, pk_len, pw) \
|
||||
ssh2_wcng_sk_pub_keyfilememory(s, m, m_len, p, p_len, alg, app, \
|
||||
f, kh, kh_len, pk, pk_len, pw)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* Windows CNG backend: Cipher Context structure
|
||||
*/
|
||||
|
||||
struct libssh2_wincng_cipher_ctx {
|
||||
struct wcng_cipher_ctx {
|
||||
BCRYPT_KEY_HANDLE hKey;
|
||||
unsigned char *pbKeyObject;
|
||||
unsigned char *pbIV;
|
||||
@@ -384,13 +369,13 @@ struct libssh2_wincng_cipher_ctx {
|
||||
ULONG dwCtrLength;
|
||||
};
|
||||
|
||||
#define libssh2_cipher_ctx struct libssh2_wincng_cipher_ctx
|
||||
#define ssh2_cipher_ctx struct wcng_cipher_ctx
|
||||
|
||||
/*
|
||||
* Windows CNG backend: Cipher Type structure
|
||||
*/
|
||||
|
||||
struct libssh2_wincng_cipher_type {
|
||||
struct wcng_cipher_t {
|
||||
BCRYPT_ALG_HANDLE *phAlg;
|
||||
ULONG dwKeyLength;
|
||||
int useIV; /* TODO: Convert to bool when a C89-compatible bool type
|
||||
@@ -398,69 +383,69 @@ struct libssh2_wincng_cipher_type {
|
||||
int ctrMode;
|
||||
};
|
||||
|
||||
#define LIBSSH2_CIPHER_T(type) struct libssh2_wincng_cipher_type type
|
||||
#define SSH2_CIPHER_T(type) struct wcng_cipher_t type
|
||||
|
||||
#define libssh2_cipher_aes256ctr { &wincng_ctx.hAlgAES_ECB, 32, 0, 1 }
|
||||
#define libssh2_cipher_aes192ctr { &wincng_ctx.hAlgAES_ECB, 24, 0, 1 }
|
||||
#define libssh2_cipher_aes128ctr { &wincng_ctx.hAlgAES_ECB, 16, 0, 1 }
|
||||
#define libssh2_cipher_aes256 { &wincng_ctx.hAlgAES_CBC, 32, 1, 0 }
|
||||
#define libssh2_cipher_aes192 { &wincng_ctx.hAlgAES_CBC, 24, 1, 0 }
|
||||
#define libssh2_cipher_aes128 { &wincng_ctx.hAlgAES_CBC, 16, 1, 0 }
|
||||
#define libssh2_cipher_arcfour { &wincng_ctx.hAlgRC4_NA, 16, 0, 0 }
|
||||
#define libssh2_cipher_3des { &wincng_ctx.hAlg3DES_CBC, 24, 1, 0 }
|
||||
#define libssh2_cipher_chacha20 { &wincng_ctx.hAlgChacha20, 24, 1, 0 }
|
||||
#define ssh2_cipher_aes256ctr { &ssh2_wcng.hAlgAES_ECB, 32, 0, 1 }
|
||||
#define ssh2_cipher_aes192ctr { &ssh2_wcng.hAlgAES_ECB, 24, 0, 1 }
|
||||
#define ssh2_cipher_aes128ctr { &ssh2_wcng.hAlgAES_ECB, 16, 0, 1 }
|
||||
#define ssh2_cipher_aes256 { &ssh2_wcng.hAlgAES_CBC, 32, 1, 0 }
|
||||
#define ssh2_cipher_aes192 { &ssh2_wcng.hAlgAES_CBC, 24, 1, 0 }
|
||||
#define ssh2_cipher_aes128 { &ssh2_wcng.hAlgAES_CBC, 16, 1, 0 }
|
||||
#define ssh2_cipher_arcfour { &ssh2_wcng.hAlgRC4_NA, 16, 0, 0 }
|
||||
#define ssh2_cipher_3des { &ssh2_wcng.hAlg3DES_CBC, 24, 1, 0 }
|
||||
#define ssh2_cipher_chacha20 { &ssh2_wcng.hAlgChacha20, 24, 1, 0 }
|
||||
|
||||
/*
|
||||
* Windows CNG backend: Cipher functions
|
||||
*/
|
||||
|
||||
#define _libssh2_cipher_init(ctx, type, iv, secret, encrypt) \
|
||||
_libssh2_wincng_cipher_init(ctx, type, iv, secret, encrypt)
|
||||
#define _libssh2_cipher_crypt(ctx, type, encrypt, block, blocklen, fl) \
|
||||
_libssh2_wincng_cipher_crypt(ctx, type, encrypt, block, blocklen, fl)
|
||||
#define _libssh2_cipher_dtor(ctx) \
|
||||
_libssh2_wincng_cipher_dtor(ctx)
|
||||
#define ssh2_cipher_init(ctx, type, iv, secret, encrypt) \
|
||||
ssh2_wcng_cipher_init(ctx, type, iv, secret, encrypt)
|
||||
#define ssh2_cipher_crypt(ctx, type, encrypt, block, blocklen, fl) \
|
||||
ssh2_wcng_cipher_crypt(ctx, type, encrypt, block, blocklen, fl)
|
||||
#define ssh2_cipher_dtor(ctx) \
|
||||
ssh2_wcng_cipher_dtor(ctx)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* Windows CNG backend: BigNumber Context
|
||||
*/
|
||||
|
||||
#define libssh2_bn_ctx int /* not used */
|
||||
#define _libssh2_bn_ctx_new() 0 /* not used */
|
||||
#define _libssh2_bn_ctx_free(bnctx) ((void)0) /* not used */
|
||||
#define ssh2_bn_ctx int /* not used */
|
||||
#define ssh2_bn_ctx_new() 0 /* not used */
|
||||
#define ssh2_bn_ctx_free(bnctx) ((void)0) /* not used */
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* Windows CNG backend: BigNumber structure
|
||||
*/
|
||||
|
||||
struct libssh2_wincng_bignum {
|
||||
struct wcng_bn {
|
||||
unsigned char *bignum;
|
||||
ULONG length;
|
||||
};
|
||||
|
||||
#define libssh2_bn struct libssh2_wincng_bignum
|
||||
#define ssh2_bn struct wcng_bn
|
||||
|
||||
/*
|
||||
* Windows CNG backend: BigNumber functions
|
||||
*/
|
||||
|
||||
#define _libssh2_bn_init() \
|
||||
_libssh2_wincng_bignum_init()
|
||||
#define _libssh2_bn_init_from_bin() \
|
||||
_libssh2_bn_init()
|
||||
#define _libssh2_bn_set_word(bn, word) \
|
||||
_libssh2_wincng_bignum_set_word(bn, word)
|
||||
#define _libssh2_bn_from_bin(bn, len, bin) \
|
||||
_libssh2_wincng_bignum_from_bin(bn, (ULONG)(len), bin)
|
||||
#define _libssh2_bn_to_bin(bn, bin) \
|
||||
_libssh2_wincng_bignum_to_bin(bn, bin)
|
||||
#define _libssh2_bn_bytes(bn) bn->length
|
||||
#define _libssh2_bn_bits(bn) \
|
||||
_libssh2_wincng_bignum_bits(bn)
|
||||
#define _libssh2_bn_free(bn) \
|
||||
_libssh2_wincng_bignum_free(bn)
|
||||
#define ssh2_bn_init() \
|
||||
ssh2_wcng_bn_init()
|
||||
#define ssh2_bn_init_from_bin() \
|
||||
ssh2_bn_init()
|
||||
#define ssh2_bn_set_word(bn, word) \
|
||||
ssh2_wcng_bn_set_word(bn, word)
|
||||
#define ssh2_bn_from_bin(bn, len, bin) \
|
||||
ssh2_wcng_bn_from_bin(bn, (ULONG)(len), bin)
|
||||
#define ssh2_bn_to_bin(bn, bin) \
|
||||
ssh2_wcng_bn_to_bin(bn, bin)
|
||||
#define ssh2_bn_bytes(bn) bn->length
|
||||
#define ssh2_bn_bits(bn) \
|
||||
ssh2_wcng_bn_bits(bn)
|
||||
#define ssh2_bn_free(bn) \
|
||||
ssh2_wcng_bn_free(bn)
|
||||
|
||||
/*
|
||||
* Windows CNG backend: Diffie-Hellman support
|
||||
@@ -468,13 +453,13 @@ struct libssh2_wincng_bignum {
|
||||
|
||||
/* Default generate and safe prime sizes for
|
||||
diffie-hellman-group-exchange-sha1 */
|
||||
#define LIBSSH2_DH_GEX_MINGROUP 2048
|
||||
#define LIBSSH2_DH_GEX_OPTGROUP 4096
|
||||
#define LIBSSH2_DH_GEX_MAXGROUP 4096
|
||||
#define SSH2_DH_GEX_MINGROUP 2048
|
||||
#define SSH2_DH_GEX_OPTGROUP 4096
|
||||
#define SSH2_DH_GEX_MAXGROUP 4096
|
||||
|
||||
#define LIBSSH2_DH_MAX_MODULUS_BITS 16384
|
||||
#define SSH2_DH_MAX_MODULUS_BITS 16384
|
||||
|
||||
struct wincng_dh_ctx {
|
||||
struct wcng_dh_ctx {
|
||||
/* holds our private and public key components */
|
||||
BCRYPT_KEY_HANDLE dh_handle;
|
||||
/* records the parsed out modulus and generator
|
||||
@@ -482,57 +467,56 @@ struct wincng_dh_ctx {
|
||||
BCRYPT_DH_PARAMETER_HEADER *dh_params;
|
||||
/* records the parsed out private key component for
|
||||
* fallback if the DH API raw KDF is not supported */
|
||||
struct libssh2_wincng_bignum *dh_privbn;
|
||||
struct wcng_bn *dh_privbn;
|
||||
};
|
||||
|
||||
#define libssh2_dh_ctx struct wincng_dh_ctx
|
||||
#define ssh2_dh_ctx struct wcng_dh_ctx
|
||||
|
||||
#define libssh2_dh_init(dhctx) _libssh2_dh_init(dhctx)
|
||||
#define libssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \
|
||||
_libssh2_dh_key_pair(dhctx, public, g, p, group_order)
|
||||
#define libssh2_dh_secret(dhctx, secret, f, p, bnctx) \
|
||||
_libssh2_dh_secret(dhctx, secret, f, p)
|
||||
#define libssh2_dh_dtor(dhctx) _libssh2_dh_dtor(dhctx)
|
||||
#define ssh2_dh_init(dhctx) ssh2_wcng_dh_init(dhctx)
|
||||
#define ssh2_dh_key_pair(dhctx, public, g, p, group_order, bnctx) \
|
||||
ssh2_wcng_dh_key_pair(dhctx, public, g, p, group_order)
|
||||
#define ssh2_dh_secret(dhctx, secret, f, p, bnctx) \
|
||||
ssh2_wcng_dh_secret(dhctx, secret, f, p)
|
||||
#define ssh2_dh_dtor(dhctx) ssh2_wcng_dh_dtor(dhctx)
|
||||
|
||||
/*******************************************************************/
|
||||
/*
|
||||
* Windows CNG backend: forward declarations
|
||||
*/
|
||||
void _libssh2_wincng_init(void);
|
||||
void _libssh2_wincng_free(void);
|
||||
int _libssh2_wincng_random(void *buf, size_t len);
|
||||
void ssh2_wcng_init(void);
|
||||
void ssh2_wcng_free(void);
|
||||
int ssh2_wcng_random(void *buf, size_t len);
|
||||
|
||||
int _libssh2_wincng_hash_init(struct wincng_hash_ctx *ctx,
|
||||
BCRYPT_ALG_HANDLE hAlg, ULONG hashlen,
|
||||
unsigned char *key, ULONG keylen);
|
||||
int _libssh2_wincng_hash_update(struct wincng_hash_ctx *ctx,
|
||||
const void *data, ULONG datalen);
|
||||
int _libssh2_wincng_hash_final(struct wincng_hash_ctx *ctx,
|
||||
unsigned char *hash);
|
||||
int _libssh2_wincng_hash(const unsigned char *data, ULONG datalen,
|
||||
BCRYPT_ALG_HANDLE hAlg,
|
||||
unsigned char *hash, ULONG hashlen);
|
||||
int ssh2_wcng_hash_init(struct wcng_hash_ctx *ctx,
|
||||
BCRYPT_ALG_HANDLE hAlg, ULONG hashlen,
|
||||
unsigned char *key, ULONG keylen);
|
||||
int ssh2_wcng_hash_update(struct wcng_hash_ctx *ctx,
|
||||
const void *data, ULONG datalen);
|
||||
int ssh2_wcng_hash_final(struct wcng_hash_ctx *ctx,
|
||||
unsigned char *hash);
|
||||
int ssh2_wcng_hash(const unsigned char *data, ULONG datalen,
|
||||
BCRYPT_ALG_HANDLE hAlg,
|
||||
unsigned char *hash, ULONG hashlen);
|
||||
|
||||
void _libssh2_wincng_rsa_free(libssh2_rsa_ctx *rsa);
|
||||
void ssh2_wcng_rsa_free(ssh2_rsa_ctx *rsa);
|
||||
|
||||
#if LIBSSH2_DSA
|
||||
void _libssh2_wincng_dsa_free(libssh2_dsa_ctx *dsa);
|
||||
void ssh2_wcng_dsa_free(ssh2_dsa_ctx *dsa);
|
||||
#endif
|
||||
|
||||
void _libssh2_wincng_cipher_dtor(libssh2_cipher_ctx *ctx);
|
||||
void ssh2_wcng_cipher_dtor(ssh2_cipher_ctx *ctx);
|
||||
|
||||
libssh2_bn *_libssh2_wincng_bignum_init(void);
|
||||
int _libssh2_wincng_bignum_set_word(libssh2_bn *bn, ULONG word);
|
||||
ULONG _libssh2_wincng_bignum_bits(const libssh2_bn *bn);
|
||||
int _libssh2_wincng_bignum_from_bin(libssh2_bn *bn, ULONG len,
|
||||
const unsigned char *bin);
|
||||
int _libssh2_wincng_bignum_to_bin(const libssh2_bn *bn, unsigned char *bin);
|
||||
void _libssh2_wincng_bignum_free(libssh2_bn *bn);
|
||||
void _libssh2_dh_init(struct wincng_dh_ctx *dhctx);
|
||||
int _libssh2_dh_key_pair(struct wincng_dh_ctx *dhctx, libssh2_bn *public,
|
||||
libssh2_bn *g, libssh2_bn *p, int group_order);
|
||||
int _libssh2_dh_secret(struct wincng_dh_ctx *dhctx, libssh2_bn *secret,
|
||||
libssh2_bn *f, libssh2_bn *p);
|
||||
void _libssh2_dh_dtor(struct wincng_dh_ctx *dhctx);
|
||||
ssh2_bn *ssh2_wcng_bn_init(void);
|
||||
int ssh2_wcng_bn_set_word(ssh2_bn *bn, ULONG word);
|
||||
ULONG ssh2_wcng_bn_bits(const ssh2_bn *bn);
|
||||
int ssh2_wcng_bn_from_bin(ssh2_bn *bn, ULONG len, const unsigned char *bin);
|
||||
int ssh2_wcng_bn_to_bin(const ssh2_bn *bn, unsigned char *bin);
|
||||
void ssh2_wcng_bn_free(ssh2_bn *bn);
|
||||
void ssh2_wcng_dh_init(ssh2_dh_ctx *dhctx);
|
||||
int ssh2_wcng_dh_key_pair(ssh2_dh_ctx *dhctx, ssh2_bn *public,
|
||||
ssh2_bn *g, ssh2_bn *p, int group_order);
|
||||
int ssh2_wcng_dh_secret(ssh2_dh_ctx *dhctx, ssh2_bn *secret,
|
||||
ssh2_bn *f, ssh2_bn *p);
|
||||
void ssh2_wcng_dh_dtor(ssh2_dh_ctx *dhctx);
|
||||
|
||||
#endif /* LIBSSH2_WINCNG_H */
|
||||
|
||||
@@ -80,7 +80,7 @@ int openssh_fixture_have_docker(void)
|
||||
}
|
||||
|
||||
static int run_command_varg(char **output, const char *command, va_list args)
|
||||
LIBSSH2_PRINTF(2, 0);
|
||||
SSH2_PRINTF(2, 0);
|
||||
|
||||
static int run_command_varg(char **output, const char *command, va_list args)
|
||||
{
|
||||
@@ -155,7 +155,7 @@ static int run_command_varg(char **output, const char *command, va_list args)
|
||||
}
|
||||
|
||||
static int run_command(char **output, const char *command, ...)
|
||||
LIBSSH2_PRINTF(2, 3);
|
||||
SSH2_PRINTF(2, 3);
|
||||
|
||||
static int run_command(char **output, const char *command, ...)
|
||||
{
|
||||
|
||||
@@ -224,7 +224,6 @@ failed_malloc_test_cases[FAILED_MALLOC_TEST_CASES_LEN] = {
|
||||
static int alloc_count = 0;
|
||||
static int free_count = 0;
|
||||
|
||||
/* libssh2_default_alloc */
|
||||
static LIBSSH2_ALLOC_FUNC(test_alloc)
|
||||
{
|
||||
int *threshold_int_ptr = *abstract;
|
||||
@@ -236,7 +235,6 @@ static LIBSSH2_ALLOC_FUNC(test_alloc)
|
||||
return malloc(count);
|
||||
}
|
||||
|
||||
/* libssh2_default_free */
|
||||
static LIBSSH2_FREE_FUNC(test_free)
|
||||
{
|
||||
(void)abstract;
|
||||
@@ -262,7 +260,7 @@ static int test_case(int num,
|
||||
return 1;
|
||||
}
|
||||
|
||||
session->userauth_kybd_data = LIBSSH2_ALLOC(session, data_len);
|
||||
session->userauth_kybd_data = SSH2_ALLOC(session, data_len);
|
||||
session->userauth_kybd_data_len = data_len;
|
||||
memcpy(session->userauth_kybd_data, data, data_len);
|
||||
|
||||
|
||||
@@ -30,24 +30,24 @@ int test(LIBSSH2_SESSION *session)
|
||||
|
||||
const char *hostkey = libssh2_session_hostkey(session, &len, &type);
|
||||
if(!hostkey) {
|
||||
print_last_session_error("libssh2_session_hostkey");
|
||||
print_last_session_error("libssh2_session_hostkey()");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(type == LIBSSH2_HOSTKEY_TYPE_ED25519) {
|
||||
rc = _libssh2_base64_decode(session, &expected_hostkey, &expected_len,
|
||||
EXPECTED_ED25519_HOSTKEY,
|
||||
strlen(EXPECTED_ED25519_HOSTKEY));
|
||||
rc = ssh2_base64_decode(session, &expected_hostkey, &expected_len,
|
||||
EXPECTED_ED25519_HOSTKEY,
|
||||
strlen(EXPECTED_ED25519_HOSTKEY));
|
||||
}
|
||||
else if(type == LIBSSH2_HOSTKEY_TYPE_ECDSA_256) {
|
||||
rc = _libssh2_base64_decode(session, &expected_hostkey, &expected_len,
|
||||
EXPECTED_ECDSA_HOSTKEY,
|
||||
strlen(EXPECTED_ECDSA_HOSTKEY));
|
||||
rc = ssh2_base64_decode(session, &expected_hostkey, &expected_len,
|
||||
EXPECTED_ECDSA_HOSTKEY,
|
||||
strlen(EXPECTED_ECDSA_HOSTKEY));
|
||||
}
|
||||
else if(type == LIBSSH2_HOSTKEY_TYPE_RSA) {
|
||||
rc = _libssh2_base64_decode(session, &expected_hostkey, &expected_len,
|
||||
EXPECTED_RSA_HOSTKEY,
|
||||
strlen(EXPECTED_RSA_HOSTKEY));
|
||||
rc = ssh2_base64_decode(session, &expected_hostkey, &expected_len,
|
||||
EXPECTED_RSA_HOSTKEY,
|
||||
strlen(EXPECTED_RSA_HOSTKEY));
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Unexpected type of hostkey: %i\n", type);
|
||||
@@ -55,7 +55,7 @@ int test(LIBSSH2_SESSION *session)
|
||||
}
|
||||
|
||||
if(rc) {
|
||||
print_last_session_error("_libssh2_base64_decode");
|
||||
print_last_session_error("ssh2_base64_decode()");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,21 +43,19 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int test_libssh2_base64_decode(LIBSSH2_SESSION *session)
|
||||
static int test_ssh2_base64_decode(LIBSSH2_SESSION *session)
|
||||
{
|
||||
char *data;
|
||||
size_t datalen;
|
||||
const char *src = "Zm5vcmQ=";
|
||||
int ret;
|
||||
|
||||
ret = _libssh2_base64_decode(session, &data, &datalen,
|
||||
src, strlen(src));
|
||||
ret = ssh2_base64_decode(session, &data, &datalen, src, strlen(src));
|
||||
if(ret)
|
||||
return ret;
|
||||
|
||||
if(datalen != 5 || strcmp(data, "fnord") != 0) {
|
||||
fprintf(stderr,
|
||||
"_libssh2_base64_decode() failed (%d, %.*s)\n",
|
||||
fprintf(stderr, "ssh2_base64_decode() failed (%d, %.*s)\n",
|
||||
(int)datalen, (int)datalen, data);
|
||||
return 1;
|
||||
}
|
||||
@@ -86,7 +84,7 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
test_libssh2_base64_decode(session);
|
||||
test_ssh2_base64_decode(session);
|
||||
|
||||
libssh2_session_free(session);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user