1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-29 13:01:14 +03:00

tidy-up: fix more nits

- fix indentation errors.
- reformat `cmake/FindmbedTLS.cmake`
- replace a macro with a variable in `example/sftp_RW_nonblock.c`.
- delete macOS macro `_DARWIN_USE_64_BIT_INODE` from the
  OS/400 config header, `os400/libssh2_config.h`.
- fix other minor nits.

Closes #983
This commit is contained in:
Viktor Szakats
2023-04-18 08:41:20 +00:00
parent 2213352758
commit 17801d2064
23 changed files with 160 additions and 182 deletions

View File

@ -10,55 +10,53 @@
# MBEDX509_LIBRARY - path to mbedTLS X.509 library # MBEDX509_LIBRARY - path to mbedTLS X.509 library
# MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library # MBEDCRYPTO_LIBRARY - path to mbedTLS Crypto library
FIND_PATH(MBEDTLS_INCLUDE_DIR mbedtls/version.h) find_path(MBEDTLS_INCLUDE_DIR mbedtls/version.h)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES) if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
# Already in cache, be silent # Already in cache, be silent
SET(MBEDTLS_FIND_QUIETLY TRUE) set(MBEDTLS_FIND_QUIETLY TRUE)
ENDIF() endif()
FIND_LIBRARY(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509) find_library(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509)
FIND_LIBRARY(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509) find_library(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509)
FIND_LIBRARY(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto) find_library(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY) if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
SET(MBEDTLS_FOUND TRUE) set(MBEDTLS_FOUND TRUE)
ENDIF() endif()
IF(MBEDTLS_FOUND) if(MBEDTLS_FOUND)
# split mbedTLS into -L and -l linker options, so we can set them for pkg-config # split mbedTLS into -L and -l linker options, so we can set them for pkg-config
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH) get_filename_component(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH)
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE) get_filename_component(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE) get_filename_component(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE) get_filename_component(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE)
STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE}) string(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE}) string(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE}) string(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE})
SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}") set(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
IF(NOT MBEDTLS_FIND_QUIETLY) if(NOT MBEDTLS_FIND_QUIETLY)
MESSAGE(STATUS "Found mbedTLS:") message(STATUS "Found mbedTLS:")
FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT) file(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT}) string(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
IF (MBEDTLSMATCH) if(MBEDTLSMATCH)
STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH}) string(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
MESSAGE(STATUS " version ${MBEDTLS_VERSION}") message(STATUS " version ${MBEDTLS_VERSION}")
ENDIF(MBEDTLSMATCH) endif()
MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}") message(STATUS " TLS: ${MBEDTLS_LIBRARY}")
MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}") message(STATUS " X509: ${MBEDX509_LIBRARY}")
MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}") message(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
ENDIF(NOT MBEDTLS_FIND_QUIETLY) endif()
ELSE(MBEDTLS_FOUND) elseif(MBEDTLS_FIND_REQUIRED)
IF(MBEDTLS_FIND_REQUIRED) message(FATAL_ERROR "Could not find mbedTLS")
MESSAGE(FATAL_ERROR "Could not find mbedTLS") endif()
ENDIF(MBEDTLS_FIND_REQUIRED)
ENDIF(MBEDTLS_FOUND)
MARK_AS_ADVANCED( mark_as_advanced(
MBEDTLS_INCLUDE_DIR MBEDTLS_INCLUDE_DIR
MBEDTLS_LIBRARY_DIR MBEDTLS_LIBRARY_DIR
MBEDTLS_LIBRARIES MBEDTLS_LIBRARIES
MBEDTLS_LIBRARY MBEDTLS_LIBRARY
MBEDX509_LIBRARY MBEDX509_LIBRARY
MBEDCRYPTO_LIBRARY MBEDCRYPTO_LIBRARY
) )

View File

@ -7,8 +7,7 @@ libssh2_sftp_realpath - convenience macro for \fIlibssh2_sftp_symlink_ex(3)\fP
#include <libssh2_sftp.h> #include <libssh2_sftp.h>
#define libssh2_sftp_realpath(sftp, path, target, maxlen) \\ #define libssh2_sftp_realpath(sftp, path, target, maxlen) \\
libssh2_sftp_symlink_ex((sftp), \\ libssh2_sftp_symlink_ex((sftp), (path), strlen(path), \\
(path), strlen(path), \\
(target), (maxlen), \\ (target), (maxlen), \\
LIBSSH2_SFTP_REALPATH) LIBSSH2_SFTP_REALPATH)
.fi .fi

View File

@ -24,15 +24,17 @@ string or NULL if the \fIrequired_version\fP isn't fulfilled.
To make sure you run with the correct libssh2 version: To make sure you run with the correct libssh2 version:
.nf .nf
if (!libssh2_version(LIBSSH2_VERSION_NUM)) { if(!libssh2_version(LIBSSH2_VERSION_NUM)) {
fprintf (stderr, \&"Runtime libssh2 version too old!\&"); fprintf(stderr, \&"Runtime libssh2 version too old!\&");
exit(1); exit(1);
} }
.fi .fi
Unconditionally get the version number: Unconditionally get the version number:
printf(\&"libssh2 version: %s\&", libssh2_version(0) ); .nf
printf(\&"libssh2 version: %s\&", libssh2_version(0));
.fi
.SH AVAILABILITY .SH AVAILABILITY
This function was added in libssh2 1.1, in previous versions there way no way This function was added in libssh2 1.1, in previous versions there way no way
to extract this info in run-time. to extract this info in run-time.

View File

@ -37,16 +37,14 @@
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#define STORAGE "/tmp/sftp-storage" /* this is the local file name this
example uses to store the downloaded
file in */
static const char *pubkey = "/home/username/.ssh/id_rsa.pub"; static const char *pubkey = "/home/username/.ssh/id_rsa.pub";
static const char *privkey = "/home/username/.ssh/id_rsa"; static const char *privkey = "/home/username/.ssh/id_rsa";
static const char *username = "username"; static const char *username = "username";
static const char *password = "password"; static const char *password = "password";
static const char *sftppath = "/tmp/TEST"; /* source path */ static const char *sftppath = "/tmp/TEST"; /* source path */
static const char *dest = "/tmp/TEST2"; /* destination path */ static const char *dest = "/tmp/TEST2"; /* destination path */
static const char *storage = "/tmp/sftp-storage"; /* local file name to store
the downloaded file in */
static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session) static int waitsocket(libssh2_socket_t socket_fd, LIBSSH2_SESSION *session)
{ {
@ -170,9 +168,9 @@ int main(int argc, char *argv[])
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
tempstorage = fopen(STORAGE, "wb"); tempstorage = fopen(storage, "wb");
if(!tempstorage) { if(!tempstorage) {
fprintf(stderr, "Can't open temp storage file %s\n", STORAGE); fprintf(stderr, "Can't open temp storage file %s\n", storage);
goto shutdown; goto shutdown;
} }
@ -274,10 +272,10 @@ int main(int argc, char *argv[])
libssh2_sftp_close(sftp_handle); libssh2_sftp_close(sftp_handle);
fclose(tempstorage); fclose(tempstorage);
tempstorage = fopen(STORAGE, "rb"); tempstorage = fopen(storage, "rb");
if(!tempstorage) { if(!tempstorage) {
/* weird, we can't read the file we just wrote to... */ /* weird, we can't read the file we just wrote to... */
fprintf(stderr, "can't open %s for reading\n", STORAGE); fprintf(stderr, "can't open %s for reading\n", storage);
goto shutdown; goto shutdown;
} }

View File

@ -50,8 +50,8 @@ static const char *sftppath = "/tmp/TEST";
/* diff in ms */ /* diff in ms */
static long tvdiff(struct timeval newer, struct timeval older) static long tvdiff(struct timeval newer, struct timeval older)
{ {
return (newer.tv_sec - older.tv_sec) * 1000 + return (newer.tv_sec - older.tv_sec) * 1000 +
(newer.tv_usec - older.tv_usec) / 1000; (newer.tv_usec - older.tv_usec) / 1000;
} }
#endif #endif

View File

@ -279,12 +279,12 @@ int main(int argc, char *argv[])
/* Instead of just running a single command with libssh2_channel_exec, /* Instead of just running a single command with libssh2_channel_exec,
* a shell can be opened on the channel instead, for interactive use. * a shell can be opened on the channel instead, for interactive use.
* You usually want a pty allocated first in that case (see above). */ * You usually want a pty allocated first in that case (see above). */
#if 0 #if 0
if(libssh2_channel_shell(channel)) { if(libssh2_channel_shell(channel)) {
fprintf(stderr, "Unable to request shell on allocated pty\n"); fprintf(stderr, "Unable to request shell on allocated pty\n");
goto shutdown; goto shutdown;
} }
#endif #endif
/* At this point the shell can be interacted with using /* At this point the shell can be interacted with using
* libssh2_channel_read() * libssh2_channel_read()

View File

@ -190,11 +190,6 @@
significant byte first (like Motorola and SPARC, unlike Intel). */ significant byte first (like Motorola and SPARC, unlike Intel). */
#define WORDS_BIGENDIAN 1 #define WORDS_BIGENDIAN 1
/* Enable large inode numbers on Mac OS X 10.5. */
#ifndef _DARWIN_USE_64_BIT_INODE
# define _DARWIN_USE_64_BIT_INODE 1
#endif
/* Number of bits in a file offset, on hosts where this is settable. */ /* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS #undef _FILE_OFFSET_BITS

View File

@ -1821,7 +1821,7 @@ libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL *channel,
*exitsignal = LIBSSH2_ALLOC(session, namelen + 1); *exitsignal = LIBSSH2_ALLOC(session, namelen + 1);
if(!*exitsignal) { if(!*exitsignal) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for signal name"); "Unable to allocate memory for signal name");
} }
memcpy(*exitsignal, channel->exit_signal, namelen); memcpy(*exitsignal, channel->exit_signal, namelen);
(*exitsignal)[namelen] = '\0'; (*exitsignal)[namelen] = '\0';
@ -2660,7 +2660,7 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL * channel)
return rc; return rc;
} }
_libssh2_error(session, rc, _libssh2_error(session, rc,
"Unable to send EOF, but closing channel anyway"); "Unable to send EOF, but closing channel anyway");
} }
} }

View File

@ -323,9 +323,9 @@ static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_3des_cbc = {
towards the start are chosen in preference to ones further down the list. */ towards the start are chosen in preference to ones further down the list. */
static const LIBSSH2_CRYPT_METHOD *_libssh2_crypt_methods[] = { static const LIBSSH2_CRYPT_METHOD *_libssh2_crypt_methods[] = {
#if LIBSSH2_AES_CTR #if LIBSSH2_AES_CTR
&libssh2_crypt_method_aes256_ctr, &libssh2_crypt_method_aes256_ctr,
&libssh2_crypt_method_aes192_ctr, &libssh2_crypt_method_aes192_ctr,
&libssh2_crypt_method_aes128_ctr, &libssh2_crypt_method_aes128_ctr,
#endif /* LIBSSH2_AES */ #endif /* LIBSSH2_AES */
#if LIBSSH2_AES #if LIBSSH2_AES
&libssh2_crypt_method_aes256_cbc, &libssh2_crypt_method_aes256_cbc,

View File

@ -269,7 +269,7 @@ hostkey_method_ssh_rsa_sha2_256_sig_verify(LIBSSH2_SESSION * session,
(void)session; (void)session;
/* Skip past keyname_len(4) + keyname(12){"rsa-sha2-256"} + /* Skip past keyname_len(4) + keyname(12){"rsa-sha2-256"} +
signature_len(4) */ signature_len(4) */
if(sig_len < 20) if(sig_len < 20)
return -1; return -1;
@ -339,7 +339,7 @@ hostkey_method_ssh_rsa_sha2_512_sig_verify(LIBSSH2_SESSION * session,
(void)session; (void)session;
/* Skip past keyname_len(4) + keyname(12){"rsa-sha2-512"} + /* Skip past keyname_len(4) + keyname(12){"rsa-sha2-512"} +
signature_len(4) */ signature_len(4) */
if(sig_len < 20) if(sig_len < 20)
return -1; return -1;
@ -510,7 +510,7 @@ hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session,
return -1; return -1;
if(_libssh2_get_string(&buf, &p, &p_len)) if(_libssh2_get_string(&buf, &p, &p_len))
return -1; return -1;
if(_libssh2_get_string(&buf, &q, &q_len)) if(_libssh2_get_string(&buf, &q, &q_len))
return -1; return -1;
@ -877,14 +877,14 @@ hostkey_method_ssh_ecdsa_sig_verify(LIBSSH2_SESSION * session,
buf.dataptr = buf.data; buf.dataptr = buf.data;
buf.len = sig_len; buf.len = sig_len;
if(_libssh2_get_string(&buf, &name, &name_len) || name_len != 19) if(_libssh2_get_string(&buf, &name, &name_len) || name_len != 19)
return -1; return -1;
if(_libssh2_get_u32(&buf, &len) != 0 || len < 8) if(_libssh2_get_u32(&buf, &len) != 0 || len < 8)
return -1; return -1;
if(_libssh2_get_string(&buf, &r, &r_len)) if(_libssh2_get_string(&buf, &r, &r_len))
return -1; return -1;
if(_libssh2_get_string(&buf, &s, &s_len)) if(_libssh2_get_string(&buf, &s, &s_len))
return -1; return -1;

View File

@ -437,7 +437,6 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session,
{ {
char fingerprint[64], *fprint = fingerprint; char fingerprint[64], *fprint = fingerprint;
int i; int i;
for(i = 0; i < 20; i++, fprint += 3) { for(i = 0; i < 20; i++, fprint += 3) {
snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]);
} }
@ -620,9 +619,9 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session,
exchange_state->h_sig_comp); exchange_state->h_sig_comp);
if(session->hostkey-> if(session->hostkey->
sig_verify(session, exchange_state->h_sig, sig_verify(session, exchange_state->h_sig,
exchange_state->h_sig_len, exchange_state->h_sig_comp, exchange_state->h_sig_len, exchange_state->h_sig_comp,
digest_len, &session->server_hostkey_abstract)) { digest_len, &session->server_hostkey_abstract)) {
ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN, ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_SIGN,
"Unable to verify hostkey signature"); "Unable to verify hostkey signature");
goto clean_exit; goto clean_exit;
@ -1718,7 +1717,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
if(data_len < 5) { if(data_len < 5) {
ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT, ret = _libssh2_error(session, LIBSSH2_ERROR_HOSTKEY_INIT,
"Host key data is too short"); "Host key data is too short");
return ret; return ret;
} }
@ -1745,9 +1744,9 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
if(_libssh2_copy_string(session, &buf, &(session->server_hostkey), if(_libssh2_copy_string(session, &buf, &(session->server_hostkey),
&server_public_key_len)) { &server_public_key_len)) {
ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, ret = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for a copy " "Unable to allocate memory for a copy "
"of the host key"); "of the host key");
goto clean_exit; goto clean_exit;
} }
@ -1800,7 +1799,6 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
{ {
char fingerprint[64], *fprint = fingerprint; char fingerprint[64], *fprint = fingerprint;
int i; int i;
for(i = 0; i < 20; i++, fprint += 3) { for(i = 0; i < 20; i++, fprint += 3) {
snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]);
} }
@ -1853,7 +1851,7 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
if(_libssh2_get_string(&buf, &server_public_key, if(_libssh2_get_string(&buf, &server_public_key,
&server_public_key_len)) { &server_public_key_len)) {
ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Unexpected key length"); "Unexpected key length");
goto clean_exit; goto clean_exit;
} }
@ -1949,13 +1947,13 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type,
} }
/* The first key exchange has been performed, /* The first key exchange has been performed,
switch to active crypt/comp/mac mode */ switch to active crypt/comp/mac mode */
session->state |= LIBSSH2_STATE_NEWKEYS; session->state |= LIBSSH2_STATE_NEWKEYS;
_libssh2_debug((session, LIBSSH2_TRACE_KEX, _libssh2_debug((session, LIBSSH2_TRACE_KEX,
"Received NEWKEYS message")); "Received NEWKEYS message"));
/* This will actually end up being just packet_type(1) /* This will actually end up being just packet_type(1)
for this packet type anyway */ for this packet type anyway */
LIBSSH2_FREE(session, exchange_state->tmp); LIBSSH2_FREE(session, exchange_state->tmp);
if(!session->session_id) { if(!session->session_id) {
@ -2430,7 +2428,6 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
{ {
char fingerprint[64], *fprint = fingerprint; char fingerprint[64], *fprint = fingerprint;
int i; int i;
for(i = 0; i < 20; i++, fprint += 3) { for(i = 0; i < 20; i++, fprint += 3) {
snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]); snprintf(fprint, 4, "%02x:", session->server_hostkey_sha1[i]);
} }
@ -2573,15 +2570,14 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data,
goto clean_exit; goto clean_exit;
} }
/* The first key exchange has been performed, switch to active /* The first key exchange has been performed,
crypt/comp/mac mode */ switch to active crypt/comp/mac mode */
session->state |= LIBSSH2_STATE_NEWKEYS; session->state |= LIBSSH2_STATE_NEWKEYS;
_libssh2_debug((session, LIBSSH2_TRACE_KEX, _libssh2_debug((session, LIBSSH2_TRACE_KEX,
"Received NEWKEYS message")); "Received NEWKEYS message"));
/* This will actually end up being just packet_type(1) for this packet /* This will actually end up being just packet_type(1)
type anyway */ for this packet type anyway */
LIBSSH2_FREE(session, exchange_state->tmp); LIBSSH2_FREE(session, exchange_state->tmp);
if(!session->session_id) { if(!session->session_id) {

View File

@ -160,8 +160,8 @@ _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa,
(void)passphrase; (void)passphrase;
return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unable to extract private key from memory: " "Unable to extract private key from memory: "
"Method unimplemented in libgcrypt backend"); "Method unimplemented in libgcrypt backend");
} }
int int
@ -197,6 +197,7 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa,
ret = -1; ret = -1;
goto fail; goto fail;
} }
/* First read Version field (should be 0). */ /* First read Version field (should be 0). */
ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen); ret = _libssh2_pem_decode_integer(&data, &datalen, &n, &nlen);
if(ret || (nlen != 1 && *n != '\0')) { if(ret || (nlen != 1 && *n != '\0')) {
@ -277,8 +278,8 @@ _libssh2_dsa_new_private_frommemory(libssh2_dsa_ctx ** dsa,
(void)passphrase; (void)passphrase;
return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unable to extract private key from memory: " "Unable to extract private key from memory: "
"Method unimplemented in libgcrypt backend"); "Method unimplemented in libgcrypt backend");
} }
int int
@ -646,8 +647,8 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
(void)passphrase; (void)passphrase;
return _libssh2_error(session, LIBSSH2_ERROR_FILE, return _libssh2_error(session, LIBSSH2_ERROR_FILE,
"Unable to extract public key from private key file: " "Unable to extract public key from private key file: "
"Method unimplemented in libgcrypt backend"); "Method unimplemented in libgcrypt backend");
} }
int int

View File

@ -204,10 +204,10 @@ _libssh2_send(libssh2_socket_t sock, const void *buffer, size_t length,
#else #else
if(rc < 0) { if(rc < 0) {
#ifdef EWOULDBLOCK /* For VMS and other special unixes */ #ifdef EWOULDBLOCK /* For VMS and other special unixes */
if(errno == EWOULDBLOCK) if(errno == EWOULDBLOCK)
return -EAGAIN; return -EAGAIN;
#endif #endif
return -errno; return -errno;
} }
#endif #endif
return rc; return rc;

View File

@ -631,7 +631,7 @@ _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa,
"ssh-rsa", filedata, filedata_len, passphrase); "ssh-rsa", filedata, filedata_len, passphrase);
} }
return rc; return rc;
} }
static unsigned char * static unsigned char *
@ -2410,8 +2410,9 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx)
defined(OPENSSL_VERSION_MAJOR) && \ defined(OPENSSL_VERSION_MAJOR) && \
OPENSSL_VERSION_MAJOR < 3 && \ OPENSSL_VERSION_MAJOR < 3 && \
!defined(LIBRESSL_VERSION_NUMBER) !defined(LIBRESSL_VERSION_NUMBER)
if(FIPS_mode())
return 0; if(FIPS_mode())
return 0;
#endif #endif
#ifdef HAVE_OPAQUE_STRUCTS #ifdef HAVE_OPAQUE_STRUCTS
@ -2520,8 +2521,8 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session,
/* convert to octal */ /* convert to octal */
if(EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED, if(EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED,
octal_value, octal_len, bn_ctx) != octal_len) { octal_value, octal_len, bn_ctx) != octal_len) {
rc = -1; rc = -1;
goto clean_exit; goto clean_exit;
} }
/* Key form is: type_len(4) + type(method_len) + domain_len(4) + domain(8) /* Key form is: type_len(4) + type(method_len) + domain_len(4) + domain(8)
@ -3027,8 +3028,8 @@ _libssh2_ecdsa_create_key(LIBSSH2_SESSION *session,
/* convert to octal */ /* convert to octal */
if(EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED, if(EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED,
octal_value, octal_len, bn_ctx) != octal_len) { octal_value, octal_len, bn_ctx) != octal_len) {
ret = -1; ret = -1;
goto clean_exit; goto clean_exit;
} }
if(out_private_key) if(out_private_key)
@ -3514,15 +3515,15 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session,
if(rc) if(rc)
return rc; return rc;
/* We have a new key file, now try and parse it using supported types */ /* We have a new key file, now try and parse it using supported types */
rc = _libssh2_get_string(decrypted, &buf, NULL); rc = _libssh2_get_string(decrypted, &buf, NULL);
if(rc || !buf) if(rc || !buf)
return _libssh2_error(session, LIBSSH2_ERROR_PROTO, return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Public key type in decrypted " "Public key type in decrypted "
"key data not found"); "key data not found");
rc = LIBSSH2_ERROR_FILE; rc = LIBSSH2_ERROR_FILE;
#if LIBSSH2_ED25519 #if LIBSSH2_ED25519
if(strcmp("ssh-ed25519", (const char *)buf) == 0) { if(strcmp("ssh-ed25519", (const char *)buf) == 0) {
@ -3535,7 +3536,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session,
pubkeydata_len, pubkeydata_len,
(libssh2_ed25519_ctx**)key_ctx); (libssh2_ed25519_ctx**)key_ctx);
} }
} }
if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) {
if(!key_type || if(!key_type ||
@ -3563,7 +3564,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session,
pubkeydata_len, pubkeydata_len,
(libssh2_rsa_ctx**)key_ctx); (libssh2_rsa_ctx**)key_ctx);
} }
} }
#endif #endif
#if LIBSSH2_DSA #if LIBSSH2_DSA
if(strcmp("ssh-dss", (const char *)buf) == 0) { if(strcmp("ssh-dss", (const char *)buf) == 0) {
@ -3574,7 +3575,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session,
pubkeydata_len, pubkeydata_len,
(libssh2_dsa_ctx**)key_ctx); (libssh2_dsa_ctx**)key_ctx);
} }
} }
#endif #endif
#if LIBSSH2_ECDSA #if LIBSSH2_ECDSA
{ {
@ -3656,15 +3657,15 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session,
if(rc) if(rc)
return rc; return rc;
/* We have a new key file, now try and parse it using supported types */ /* We have a new key file, now try and parse it using supported types */
rc = _libssh2_get_string(decrypted, &buf, NULL); rc = _libssh2_get_string(decrypted, &buf, NULL);
if(rc || !buf) if(rc || !buf)
return _libssh2_error(session, LIBSSH2_ERROR_PROTO, return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Public key type in decrypted " "Public key type in decrypted "
"key data not found"); "key data not found");
rc = LIBSSH2_ERROR_FILE; rc = LIBSSH2_ERROR_FILE;
#if LIBSSH2_ED25519 #if LIBSSH2_ED25519
if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) {

View File

@ -816,8 +816,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
* Spec says we MAY ignore bytes sent beyond * Spec says we MAY ignore bytes sent beyond
* packet_size * packet_size
*/ */
_libssh2_error(session, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
"Packet contains more data than we offered" "Packet contains more data than we offered"
" to receive, truncating"); " to receive, truncating");
datalen = channelp->remote.packet_size + data_head; datalen = channelp->remote.packet_size + data_head;
@ -827,8 +826,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
* Spec says we MAY ignore bytes sent beyond * Spec says we MAY ignore bytes sent beyond
* window_size * window_size
*/ */
_libssh2_error(session, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
"The current receive window is full," "The current receive window is full,"
" data ignored"); " data ignored");
LIBSSH2_FREE(session, data); LIBSSH2_FREE(session, data);
@ -840,8 +838,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
if(channelp->read_avail + datalen - data_head > if(channelp->read_avail + datalen - data_head >
channelp->remote.window_size) { channelp->remote.window_size) {
_libssh2_error(session, _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
"Remote sent more data than current " "Remote sent more data than current "
"window allows, truncating"); "window allows, truncating");
datalen = channelp->remote.window_size - datalen = channelp->remote.window_size -

View File

@ -394,8 +394,8 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
/* decode file */ /* decode file */
if(_libssh2_base64_decode(session, (char **)&f, &f_len, if(_libssh2_base64_decode(session, (char **)&f, &f_len,
b64data, b64datalen)) { b64data, b64datalen)) {
ret = -1; ret = -1;
goto out; goto out;
} }
/* Parse the file */ /* Parse the file */
@ -458,8 +458,8 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
if(!strcmp((const char *)kdfname, "none") && if(!strcmp((const char *)kdfname, "none") &&
strcmp((const char *)ciphername, "none") != 0) { strcmp((const char *)ciphername, "none") != 0) {
ret =_libssh2_error(session, LIBSSH2_ERROR_PROTO, ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"invalid format"); "invalid format");
goto out; goto out;
} }
@ -608,10 +608,10 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session,
if(_libssh2_get_u32(&decrypted, &check1) != 0 || if(_libssh2_get_u32(&decrypted, &check1) != 0 ||
_libssh2_get_u32(&decrypted, &check2) != 0 || _libssh2_get_u32(&decrypted, &check2) != 0 ||
check1 != check2) { check1 != check2) {
_libssh2_error(session, LIBSSH2_ERROR_PROTO, _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Private key unpack failed (correct password?)"); "Private key unpack failed (correct password?)");
ret = LIBSSH2_ERROR_KEYFILE_AUTH_FAILED; ret = LIBSSH2_ERROR_KEYFILE_AUTH_FAILED;
goto out; goto out;
} }
if(decrypted_buf) { if(decrypted_buf) {

View File

@ -693,7 +693,6 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb)
*(p++) = '\0'; *(p++) = '\0';
/* Make sure we don't get fooled by leftover values */ /* Make sure we don't get fooled by leftover values */
session->scpRecv_mode = strtol(s, &e, 8); session->scpRecv_mode = strtol(s, &e, 8);
if(e && *e) { if(e && *e) {
_libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, _libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,

View File

@ -53,15 +53,15 @@
*/ */
#define BLOCK_ADJUST(rc, sess, x) \ #define BLOCK_ADJUST(rc, sess, x) \
do { \ do { \
time_t entry_time = time(NULL); \ time_t entry_time = time(NULL); \
do { \ do { \
rc = x; \ rc = x; \
/* the order of the check below is important to properly deal with \ /* the order of the check below is important to properly \
the case when the 'sess' is freed */ \ deal with the case when the 'sess' is freed */ \
if((rc != LIBSSH2_ERROR_EAGAIN) || !sess->api_block_mode) \ if((rc != LIBSSH2_ERROR_EAGAIN) || !sess->api_block_mode) \
break; \ break; \
rc = _libssh2_wait_socket(sess, entry_time); \ rc = _libssh2_wait_socket(sess, entry_time); \
} while(!rc); \ } while(!rc); \
} while(0) } while(0)
/* /*
@ -72,15 +72,15 @@
*/ */
#define BLOCK_ADJUST_ERRNO(ptr, sess, x) \ #define BLOCK_ADJUST_ERRNO(ptr, sess, x) \
do { \ do { \
time_t entry_time = time(NULL); \ time_t entry_time = time(NULL); \
int rc; \ int rc; \
do { \ do { \
ptr = x; \ ptr = x; \
if(!sess->api_block_mode || \ if(!sess->api_block_mode || \
(ptr != NULL) || \ (ptr != NULL) || \
(libssh2_session_last_errno(sess) != LIBSSH2_ERROR_EAGAIN) ) \ (libssh2_session_last_errno(sess) != LIBSSH2_ERROR_EAGAIN) ) \
break; \ break; \
rc = _libssh2_wait_socket(sess, entry_time); \ rc = _libssh2_wait_socket(sess, entry_time); \
} while(!rc); \ } while(!rc); \
} while(0) } while(0)

View File

@ -1654,7 +1654,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
requested, which shouldn't happen for normal files. See: requested, which shouldn't happen for normal files. See:
https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02 https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02
#section-6.4 #section-6.4
*/ */
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Read Packet At Unexpected Offset"); "Read Packet At Unexpected Offset");
} }

View File

@ -920,7 +920,7 @@ libssh2_sign_sk(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len,
if(sig_info.sig_s_len > 0 && sig_info.sig_s) { if(sig_info.sig_s_len > 0 && sig_info.sig_s) {
/* sig length, sig_r, sig_s, flags, counter, plus 4 bytes for each /* sig length, sig_r, sig_s, flags, counter, plus 4 bytes for each
component's length, and up to 1 extra byte for each component */ component's length, and up to 1 extra byte for each component */
*sig_len = 4 + 5 + sig_info.sig_r_len + 5 + sig_info.sig_s_len + 5; *sig_len = 4 + 5 + sig_info.sig_r_len + 5 + sig_info.sig_s_len + 5;
*sig = LIBSSH2_ALLOC(session, *sig_len); *sig = LIBSSH2_ALLOC(session, *sig_len);
@ -1321,7 +1321,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session,
i = filtered_algs; i = filtered_algs;
/* this walks the server algo list and the supported algo list and creates /* this walks the server algo list and the supported algo list and creates
a filtered list that includes matches */ a filtered list that includes matches */
while(s && *s) { while(s && *s) {
p = strchr(s, ','); p = strchr(s, ',');
@ -1359,7 +1359,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session,
} }
/* now that we have the possible supported algos, match based on the prefs /* now that we have the possible supported algos, match based on the prefs
or what is supported by the crypto backend, look for a match */ or what is supported by the crypto backend, look for a match */
while(s && *s && !match) { while(s && *s && !match) {
p = strchr(s, ','); p = strchr(s, ',');

View File

@ -37,14 +37,6 @@
#include "libssh2_priv.h" #include "libssh2_priv.h"
/*
libssh2_version() can be used like this:
if(!libssh2_version(LIBSSH2_VERSION_NUM)) {
fprintf(stderr, "Runtime libssh2 version too old!\n");
exit(1);
}
*/
LIBSSH2_API LIBSSH2_API
const char *libssh2_version(int req_version_num) const char *libssh2_version(int req_version_num)
{ {

View File

@ -1288,7 +1288,7 @@ _libssh2_wincng_rsa_sha_sign(LIBSSH2_SESSION *session,
paddingInfo.pszAlgId = BCRYPT_SHA512_ALGORITHM; paddingInfo.pszAlgId = BCRYPT_SHA512_ALGORITHM;
else { else {
_libssh2_error(session, LIBSSH2_ERROR_PROTO, _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Unsupported hash digest length"); "Unsupported hash digest length");
return -1; return -1;
} }
@ -1855,8 +1855,8 @@ _libssh2_wincng_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
(void)passphrase; (void)passphrase;
return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unable to extract public key from private key in memory: " "Unable to extract public key from private key in memory: "
"Method unsupported in Windows CNG backend"); "Method unsupported in Windows CNG backend");
#endif /* HAVE_LIBCRYPT32 */ #endif /* HAVE_LIBCRYPT32 */
} }

View File

@ -30,11 +30,11 @@ ssh-keygen -t rsa -b 2048 -N '' -m PEM -C 'key_rsa'
ssh-keygen -t rsa -b 2048 -N "${pw}" -m PEM -C 'key_rsa_encrypted' -f 'key_rsa_encrypted' ssh-keygen -t rsa -b 2048 -N "${pw}" -m PEM -C 'key_rsa_encrypted' -f 'key_rsa_encrypted'
ssh-keygen -t rsa -b 2048 -N '' -C 'key_rsa_openssh' -f 'key_rsa_openssh' ssh-keygen -t rsa -b 2048 -N '' -C 'key_rsa_openssh' -f 'key_rsa_openssh'
ssh-keygen -t rsa -b 4096 -N '' -C 'key_rsa_signed' -f 'key_rsa_signed' ssh-keygen -t rsa -b 4096 -N '' -C 'key_rsa_signed' -f 'key_rsa_signed'
ssh-keygen -I "${id}" -n "${pr}" -s 'openssh_server/ca_rsa' 'key_rsa_signed.pub' ssh-keygen -I "${id}" -n "${pr}" -s 'openssh_server/ca_rsa' 'key_rsa_signed.pub'
ssh-keygen -t ecdsa -b 384 -N '' -C 'key_ecdsa' -f 'key_ecdsa' ssh-keygen -t ecdsa -b 384 -N '' -C 'key_ecdsa' -f 'key_ecdsa'
ssh-keygen -t ecdsa -b 384 -N '' -C 'key_ecdsa_signed' -f 'key_ecdsa_signed' ssh-keygen -t ecdsa -b 384 -N '' -C 'key_ecdsa_signed' -f 'key_ecdsa_signed'
ssh-keygen -I "${id}" -n "${pr}" -s 'openssh_server/ca_ecdsa' 'key_ecdsa_signed.pub' ssh-keygen -I "${id}" -n "${pr}" -s 'openssh_server/ca_ecdsa' 'key_ecdsa_signed.pub'
ssh-keygen -t ed25519 -N '' -C 'key_ed25519' -f 'key_ed25519' ssh-keygen -t ed25519 -N '' -C 'key_ed25519' -f 'key_ed25519'
ssh-keygen -t ed25519 -N "${pw}" -C 'key_ed25519_encrypted' -f 'key_ed25519_encrypted' ssh-keygen -t ed25519 -N "${pw}" -C 'key_ed25519_encrypted' -f 'key_ed25519_encrypted'