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
# 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)
# Already in cache, be silent
SET(MBEDTLS_FIND_QUIETLY TRUE)
ENDIF()
if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
# Already in cache, be silent
set(MBEDTLS_FIND_QUIETLY TRUE)
endif()
FIND_LIBRARY(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509)
FIND_LIBRARY(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509)
FIND_LIBRARY(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto)
find_library(MBEDTLS_LIBRARY NAMES mbedtls libmbedtls libmbedx509)
find_library(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509)
find_library(MBEDCRYPTO_LIBRARY NAMES mbedcrypto libmbedcrypto)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
SET(MBEDTLS_FOUND TRUE)
ENDIF()
if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
set(MBEDTLS_FOUND TRUE)
endif()
IF(MBEDTLS_FOUND)
# 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_FILE ${MBEDTLS_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_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" "" MBEDX509_LIBRARY_FILE ${MBEDX509_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}")
if(MBEDTLS_FOUND)
# 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_FILE ${MBEDTLS_LIBRARY} NAME_WE)
get_filename_component(MBEDX509_LIBRARY_FILE ${MBEDX509_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" "" MBEDX509_LIBRARY_FILE ${MBEDX509_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}")
IF(NOT MBEDTLS_FIND_QUIETLY)
MESSAGE(STATUS "Found mbedTLS:")
FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
IF (MBEDTLSMATCH)
STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
MESSAGE(STATUS " version ${MBEDTLS_VERSION}")
ENDIF(MBEDTLSMATCH)
MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}")
MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}")
MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
ENDIF(NOT MBEDTLS_FIND_QUIETLY)
ELSE(MBEDTLS_FOUND)
IF(MBEDTLS_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find mbedTLS")
ENDIF(MBEDTLS_FIND_REQUIRED)
ENDIF(MBEDTLS_FOUND)
if(NOT MBEDTLS_FIND_QUIETLY)
message(STATUS "Found mbedTLS:")
file(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
string(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
if(MBEDTLSMATCH)
string(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
message(STATUS " version ${MBEDTLS_VERSION}")
endif()
message(STATUS " TLS: ${MBEDTLS_LIBRARY}")
message(STATUS " X509: ${MBEDX509_LIBRARY}")
message(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
endif()
elseif(MBEDTLS_FIND_REQUIRED)
message(FATAL_ERROR "Could not find mbedTLS")
endif()
MARK_AS_ADVANCED(
MBEDTLS_INCLUDE_DIR
MBEDTLS_LIBRARY_DIR
MBEDTLS_LIBRARIES
MBEDTLS_LIBRARY
MBEDX509_LIBRARY
MBEDCRYPTO_LIBRARY
mark_as_advanced(
MBEDTLS_INCLUDE_DIR
MBEDTLS_LIBRARY_DIR
MBEDTLS_LIBRARIES
MBEDTLS_LIBRARY
MBEDX509_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>
#define libssh2_sftp_realpath(sftp, path, target, maxlen) \\
libssh2_sftp_symlink_ex((sftp), \\
(path), strlen(path), \\
libssh2_sftp_symlink_ex((sftp), (path), strlen(path), \\
(target), (maxlen), \\
LIBSSH2_SFTP_REALPATH)
.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:
.nf
if (!libssh2_version(LIBSSH2_VERSION_NUM)) {
fprintf (stderr, \&"Runtime libssh2 version too old!\&");
if(!libssh2_version(LIBSSH2_VERSION_NUM)) {
fprintf(stderr, \&"Runtime libssh2 version too old!\&");
exit(1);
}
.fi
Unconditionally get the version number:
printf(\&"libssh2 version: %s\&", libssh2_version(0) );
.nf
printf(\&"libssh2 version: %s\&", libssh2_version(0));
.fi
.SH AVAILABILITY
This function was added in libssh2 1.1, in previous versions there way no way
to extract this info in run-time.

View File

@ -37,16 +37,14 @@
#include <stdio.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 *privkey = "/home/username/.ssh/id_rsa";
static const char *username = "username";
static const char *password = "password";
static const char *sftppath = "/tmp/TEST"; /* source 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)
{
@ -170,9 +168,9 @@ int main(int argc, char *argv[])
}
fprintf(stderr, "\n");
tempstorage = fopen(STORAGE, "wb");
tempstorage = fopen(storage, "wb");
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;
}
@ -274,10 +272,10 @@ int main(int argc, char *argv[])
libssh2_sftp_close(sftp_handle);
fclose(tempstorage);
tempstorage = fopen(STORAGE, "rb");
tempstorage = fopen(storage, "rb");
if(!tempstorage) {
/* 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;
}

View File

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

View File

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

View File

@ -190,11 +190,6 @@
significant byte first (like Motorola and SPARC, unlike Intel). */
#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. */
#undef _FILE_OFFSET_BITS

View File

@ -1821,7 +1821,7 @@ libssh2_channel_get_exit_signal(LIBSSH2_CHANNEL *channel,
*exitsignal = LIBSSH2_ALLOC(session, namelen + 1);
if(!*exitsignal) {
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);
(*exitsignal)[namelen] = '\0';
@ -2660,7 +2660,7 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL * channel)
return 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. */
static const LIBSSH2_CRYPT_METHOD *_libssh2_crypt_methods[] = {
#if LIBSSH2_AES_CTR
&libssh2_crypt_method_aes256_ctr,
&libssh2_crypt_method_aes192_ctr,
&libssh2_crypt_method_aes128_ctr,
&libssh2_crypt_method_aes256_ctr,
&libssh2_crypt_method_aes192_ctr,
&libssh2_crypt_method_aes128_ctr,
#endif /* LIBSSH2_AES */
#if LIBSSH2_AES
&libssh2_crypt_method_aes256_cbc,

View File

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

View File

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

View File

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

View File

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

View File

@ -631,7 +631,7 @@ _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa,
"ssh-rsa", filedata, filedata_len, passphrase);
}
return rc;
return rc;
}
static unsigned char *
@ -2410,8 +2410,9 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx)
defined(OPENSSL_VERSION_MAJOR) && \
OPENSSL_VERSION_MAJOR < 3 && \
!defined(LIBRESSL_VERSION_NUMBER)
if(FIPS_mode())
return 0;
if(FIPS_mode())
return 0;
#endif
#ifdef HAVE_OPAQUE_STRUCTS
@ -2520,8 +2521,8 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session,
/* convert to octal */
if(EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED,
octal_value, octal_len, bn_ctx) != octal_len) {
rc = -1;
goto clean_exit;
rc = -1;
goto clean_exit;
}
/* 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 */
if(EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED,
octal_value, octal_len, bn_ctx) != octal_len) {
ret = -1;
goto clean_exit;
ret = -1;
goto clean_exit;
}
if(out_private_key)
@ -3514,15 +3515,15 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session,
if(rc)
return rc;
/* We have a new key file, now try and parse it using supported types */
rc = _libssh2_get_string(decrypted, &buf, NULL);
/* We have a new key file, now try and parse it using supported types */
rc = _libssh2_get_string(decrypted, &buf, NULL);
if(rc || !buf)
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Public key type in decrypted "
"key data not found");
if(rc || !buf)
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Public key type in decrypted "
"key data not found");
rc = LIBSSH2_ERROR_FILE;
rc = LIBSSH2_ERROR_FILE;
#if LIBSSH2_ED25519
if(strcmp("ssh-ed25519", (const char *)buf) == 0) {
@ -3535,7 +3536,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session,
pubkeydata_len,
(libssh2_ed25519_ctx**)key_ctx);
}
}
}
if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) {
if(!key_type ||
@ -3563,7 +3564,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session,
pubkeydata_len,
(libssh2_rsa_ctx**)key_ctx);
}
}
}
#endif
#if LIBSSH2_DSA
if(strcmp("ssh-dss", (const char *)buf) == 0) {
@ -3574,7 +3575,7 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session,
pubkeydata_len,
(libssh2_dsa_ctx**)key_ctx);
}
}
}
#endif
#if LIBSSH2_ECDSA
{
@ -3656,15 +3657,15 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session,
if(rc)
return rc;
/* We have a new key file, now try and parse it using supported types */
rc = _libssh2_get_string(decrypted, &buf, NULL);
/* We have a new key file, now try and parse it using supported types */
rc = _libssh2_get_string(decrypted, &buf, NULL);
if(rc || !buf)
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Public key type in decrypted "
"key data not found");
if(rc || !buf)
return _libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Public key type in decrypted "
"key data not found");
rc = LIBSSH2_ERROR_FILE;
rc = LIBSSH2_ERROR_FILE;
#if LIBSSH2_ED25519
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
* packet_size
*/
_libssh2_error(session,
LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
_libssh2_error(session, LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
"Packet contains more data than we offered"
" to receive, truncating");
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
* window_size
*/
_libssh2_error(session,
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
_libssh2_error(session, LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
"The current receive window is full,"
" data ignored");
LIBSSH2_FREE(session, data);
@ -840,8 +838,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
if(channelp->read_avail + datalen - data_head >
channelp->remote.window_size) {
_libssh2_error(session,
LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
_libssh2_error(session, LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED,
"Remote sent more data than current "
"window allows, truncating");
datalen = channelp->remote.window_size -

View File

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

View File

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

View File

@ -53,15 +53,15 @@
*/
#define BLOCK_ADJUST(rc, sess, x) \
do { \
time_t entry_time = time(NULL); \
do { \
rc = x; \
/* the order of the check below is important to properly deal with \
the case when the 'sess' is freed */ \
if((rc != LIBSSH2_ERROR_EAGAIN) || !sess->api_block_mode) \
break; \
rc = _libssh2_wait_socket(sess, entry_time); \
} while(!rc); \
time_t entry_time = time(NULL); \
do { \
rc = x; \
/* the order of the check below is important to properly \
deal with the case when the 'sess' is freed */ \
if((rc != LIBSSH2_ERROR_EAGAIN) || !sess->api_block_mode) \
break; \
rc = _libssh2_wait_socket(sess, entry_time); \
} while(!rc); \
} while(0)
/*
@ -72,15 +72,15 @@
*/
#define BLOCK_ADJUST_ERRNO(ptr, sess, x) \
do { \
time_t entry_time = time(NULL); \
int rc; \
do { \
ptr = x; \
if(!sess->api_block_mode || \
(ptr != NULL) || \
(libssh2_session_last_errno(sess) != LIBSSH2_ERROR_EAGAIN) ) \
break; \
rc = _libssh2_wait_socket(sess, entry_time); \
time_t entry_time = time(NULL); \
int rc; \
do { \
ptr = x; \
if(!sess->api_block_mode || \
(ptr != NULL) || \
(libssh2_session_last_errno(sess) != LIBSSH2_ERROR_EAGAIN) ) \
break; \
rc = _libssh2_wait_socket(sess, entry_time); \
} while(!rc); \
} 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:
https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02
#section-6.4
*/
*/
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"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) {
/* 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 = LIBSSH2_ALLOC(session, *sig_len);
@ -1321,7 +1321,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session,
i = filtered_algs;
/* 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) {
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
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) {
p = strchr(s, ',');

View File

@ -37,14 +37,6 @@
#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
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;
else {
_libssh2_error(session, LIBSSH2_ERROR_PROTO,
"Unsupported hash digest length");
"Unsupported hash digest length");
return -1;
}
@ -1855,8 +1855,8 @@ _libssh2_wincng_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
(void)passphrase;
return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
"Unable to extract public key from private key in memory: "
"Method unsupported in Windows CNG backend");
"Unable to extract public key from private key in memory: "
"Method unsupported in Windows CNG backend");
#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 '' -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 -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_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 "${pw}" -C 'key_ed25519_encrypted' -f 'key_ed25519_encrypted'