Initially the libssh2 code was indented with tabs of 4 spaces. Some of
the recent commits converted the tabs to 4 spaces, which matched the initial indent size. Other commits converted the tabs to 8 spaces, this didn't match. All the code has been converted to 4 space indents. No changes to line lengths or actual code was performed. This is in preperation to my up coming non-blocking work so my commits should only be code changes and line lengths in the code I am working on.
Этот коммит содержится в:
родитель
355c9c634b
Коммит
412b25d971
@ -75,15 +75,15 @@ typedef unsigned long long libssh2_uint64_t;
|
|||||||
typedef long long libssh2_int64_t;
|
typedef long long libssh2_int64_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define LIBSSH2_VERSION "0.15-CVS"
|
#define LIBSSH2_VERSION "0.15-CVS"
|
||||||
#define LIBSSH2_APINO 200507211326
|
#define LIBSSH2_APINO 200507211326
|
||||||
|
|
||||||
/* Part of every banner, user specified or not */
|
/* Part of every banner, user specified or not */
|
||||||
#define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION
|
#define LIBSSH2_SSH_BANNER "SSH-2.0-libssh2_" LIBSSH2_VERSION
|
||||||
|
|
||||||
/* We *could* add a comment here if we so chose */
|
/* We *could* add a comment here if we so chose */
|
||||||
#define LIBSSH2_SSH_DEFAULT_BANNER LIBSSH2_SSH_BANNER
|
#define LIBSSH2_SSH_DEFAULT_BANNER LIBSSH2_SSH_BANNER
|
||||||
#define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
|
#define LIBSSH2_SSH_DEFAULT_BANNER_WITH_CRLF LIBSSH2_SSH_DEFAULT_BANNER "\r\n"
|
||||||
|
|
||||||
/* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 */
|
/* Default generate and safe prime sizes for diffie-hellman-group-exchange-sha1 */
|
||||||
#define LIBSSH2_DH_GEX_MINGROUP 1024
|
#define LIBSSH2_DH_GEX_MINGROUP 1024
|
||||||
@ -91,177 +91,177 @@ typedef long long libssh2_int64_t;
|
|||||||
#define LIBSSH2_DH_GEX_MAXGROUP 2048
|
#define LIBSSH2_DH_GEX_MAXGROUP 2048
|
||||||
|
|
||||||
/* Defaults for pty requests */
|
/* Defaults for pty requests */
|
||||||
#define LIBSSH2_TERM_WIDTH 80
|
#define LIBSSH2_TERM_WIDTH 80
|
||||||
#define LIBSSH2_TERM_HEIGHT 24
|
#define LIBSSH2_TERM_HEIGHT 24
|
||||||
#define LIBSSH2_TERM_WIDTH_PX 0
|
#define LIBSSH2_TERM_WIDTH_PX 0
|
||||||
#define LIBSSH2_TERM_HEIGHT_PX 0
|
#define LIBSSH2_TERM_HEIGHT_PX 0
|
||||||
|
|
||||||
/* 1/4 second */
|
/* 1/4 second */
|
||||||
#define LIBSSH2_SOCKET_POLL_UDELAY 250000
|
#define LIBSSH2_SOCKET_POLL_UDELAY 250000
|
||||||
/* 0.25 * 120 == 30 seconds */
|
/* 0.25 * 120 == 30 seconds */
|
||||||
#define LIBSSH2_SOCKET_POLL_MAXLOOPS 120
|
#define LIBSSH2_SOCKET_POLL_MAXLOOPS 120
|
||||||
|
|
||||||
/* Maximum size to allow a payload to compress to, plays it safe by falling short of spec limits */
|
/* Maximum size to allow a payload to compress to, plays it safe by falling short of spec limits */
|
||||||
#define LIBSSH2_PACKET_MAXCOMP 32000
|
#define LIBSSH2_PACKET_MAXCOMP 32000
|
||||||
|
|
||||||
/* Maximum size to allow a payload to deccompress to, plays it safe by allowing more than spec requires */
|
/* Maximum size to allow a payload to deccompress to, plays it safe by allowing more than spec requires */
|
||||||
#define LIBSSH2_PACKET_MAXDECOMP 40000
|
#define LIBSSH2_PACKET_MAXDECOMP 40000
|
||||||
|
|
||||||
/* Maximum size for an inbound compressed payload, plays it safe by overshooting spec limits */
|
/* Maximum size for an inbound compressed payload, plays it safe by overshooting spec limits */
|
||||||
#define LIBSSH2_PACKET_MAXPAYLOAD 40000
|
#define LIBSSH2_PACKET_MAXPAYLOAD 40000
|
||||||
|
|
||||||
/* Malloc callbacks */
|
/* Malloc callbacks */
|
||||||
#define LIBSSH2_ALLOC_FUNC(name) void *name(size_t count, void **abstract)
|
#define LIBSSH2_ALLOC_FUNC(name) void *name(size_t count, void **abstract)
|
||||||
#define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, void **abstract)
|
#define LIBSSH2_REALLOC_FUNC(name) void *name(void *ptr, size_t count, void **abstract)
|
||||||
#define LIBSSH2_FREE_FUNC(name) void name(void *ptr, void **abstract)
|
#define LIBSSH2_FREE_FUNC(name) void name(void *ptr, void **abstract)
|
||||||
|
|
||||||
typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT
|
typedef struct _LIBSSH2_USERAUTH_KBDINT_PROMPT
|
||||||
{
|
{
|
||||||
char* text;
|
char* text;
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
unsigned char echo;
|
unsigned char echo;
|
||||||
} LIBSSH2_USERAUTH_KBDINT_PROMPT;
|
} LIBSSH2_USERAUTH_KBDINT_PROMPT;
|
||||||
|
|
||||||
typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
|
typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE
|
||||||
{
|
{
|
||||||
char* text;
|
char* text;
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
} LIBSSH2_USERAUTH_KBDINT_RESPONSE;
|
} LIBSSH2_USERAUTH_KBDINT_RESPONSE;
|
||||||
|
|
||||||
/* 'keyboard-interactive' authentication callback */
|
/* 'keyboard-interactive' authentication callback */
|
||||||
#define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) void name_(const char* name, int name_len, const char* instruction, int instruction_len, int num_prompts, const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract)
|
#define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) void name_(const char* name, int name_len, const char* instruction, int instruction_len, int num_prompts, const LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts, LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses, void **abstract)
|
||||||
|
|
||||||
/* Callbacks for special SSH packets */
|
/* Callbacks for special SSH packets */
|
||||||
#define LIBSSH2_IGNORE_FUNC(name) void name(LIBSSH2_SESSION *session, const char *message, int message_len, void **abstract)
|
#define LIBSSH2_IGNORE_FUNC(name) void name(LIBSSH2_SESSION *session, const char *message, int message_len, void **abstract)
|
||||||
#define LIBSSH2_DEBUG_FUNC(name) void name(LIBSSH2_SESSION *session, int always_display, const char *message, int message_len, const char *language, int language_len,void **abstract)
|
#define LIBSSH2_DEBUG_FUNC(name) void name(LIBSSH2_SESSION *session, int always_display, const char *message, int message_len, const char *language, int language_len,void **abstract)
|
||||||
#define LIBSSH2_DISCONNECT_FUNC(name) void name(LIBSSH2_SESSION *session, int reason, const char *message, int message_len, const char *language, int language_len, void **abstract)
|
#define LIBSSH2_DISCONNECT_FUNC(name) void name(LIBSSH2_SESSION *session, int reason, const char *message, int message_len, const char *language, int language_len, void **abstract)
|
||||||
#define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, void **abstract)
|
#define LIBSSH2_PASSWD_CHANGEREQ_FUNC(name) void name(LIBSSH2_SESSION *session, char **newpw, int *newpw_len, void **abstract)
|
||||||
#define LIBSSH2_MACERROR_FUNC(name) int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, void **abstract)
|
#define LIBSSH2_MACERROR_FUNC(name) int name(LIBSSH2_SESSION *session, const char *packet, int packet_len, void **abstract)
|
||||||
#define LIBSSH2_X11_OPEN_FUNC(name) void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, const char *shost, int sport, void **abstract)
|
#define LIBSSH2_X11_OPEN_FUNC(name) void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, const char *shost, int sport, void **abstract)
|
||||||
|
|
||||||
#define LIBSSH2_CHANNEL_CLOSE_FUNC(name) void name(LIBSSH2_SESSION *session, void **session_abstract, LIBSSH2_CHANNEL *channel, void **channel_abstract)
|
#define LIBSSH2_CHANNEL_CLOSE_FUNC(name) void name(LIBSSH2_SESSION *session, void **session_abstract, LIBSSH2_CHANNEL *channel, void **channel_abstract)
|
||||||
|
|
||||||
/* libssh2_session_callback_set() constants */
|
/* libssh2_session_callback_set() constants */
|
||||||
#define LIBSSH2_CALLBACK_IGNORE 0
|
#define LIBSSH2_CALLBACK_IGNORE 0
|
||||||
#define LIBSSH2_CALLBACK_DEBUG 1
|
#define LIBSSH2_CALLBACK_DEBUG 1
|
||||||
#define LIBSSH2_CALLBACK_DISCONNECT 2
|
#define LIBSSH2_CALLBACK_DISCONNECT 2
|
||||||
#define LIBSSH2_CALLBACK_MACERROR 3
|
#define LIBSSH2_CALLBACK_MACERROR 3
|
||||||
#define LIBSSH2_CALLBACK_X11 4
|
#define LIBSSH2_CALLBACK_X11 4
|
||||||
|
|
||||||
/* libssh2_session_method_pref() constants */
|
/* libssh2_session_method_pref() constants */
|
||||||
#define LIBSSH2_METHOD_KEX 0
|
#define LIBSSH2_METHOD_KEX 0
|
||||||
#define LIBSSH2_METHOD_HOSTKEY 1
|
#define LIBSSH2_METHOD_HOSTKEY 1
|
||||||
#define LIBSSH2_METHOD_CRYPT_CS 2
|
#define LIBSSH2_METHOD_CRYPT_CS 2
|
||||||
#define LIBSSH2_METHOD_CRYPT_SC 3
|
#define LIBSSH2_METHOD_CRYPT_SC 3
|
||||||
#define LIBSSH2_METHOD_MAC_CS 4
|
#define LIBSSH2_METHOD_MAC_CS 4
|
||||||
#define LIBSSH2_METHOD_MAC_SC 5
|
#define LIBSSH2_METHOD_MAC_SC 5
|
||||||
#define LIBSSH2_METHOD_COMP_CS 6
|
#define LIBSSH2_METHOD_COMP_CS 6
|
||||||
#define LIBSSH2_METHOD_COMP_SC 7
|
#define LIBSSH2_METHOD_COMP_SC 7
|
||||||
#define LIBSSH2_METHOD_LANG_CS 8
|
#define LIBSSH2_METHOD_LANG_CS 8
|
||||||
#define LIBSSH2_METHOD_LANG_SC 9
|
#define LIBSSH2_METHOD_LANG_SC 9
|
||||||
|
|
||||||
/* session.flags bits */
|
/* session.flags bits */
|
||||||
#define LIBSSH2_FLAG_SIGPIPE 0x00000001
|
#define LIBSSH2_FLAG_SIGPIPE 0x00000001
|
||||||
|
|
||||||
typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION;
|
typedef struct _LIBSSH2_SESSION LIBSSH2_SESSION;
|
||||||
typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL;
|
typedef struct _LIBSSH2_CHANNEL LIBSSH2_CHANNEL;
|
||||||
typedef struct _LIBSSH2_LISTENER LIBSSH2_LISTENER;
|
typedef struct _LIBSSH2_LISTENER LIBSSH2_LISTENER;
|
||||||
|
|
||||||
typedef struct _LIBSSH2_POLLFD {
|
typedef struct _LIBSSH2_POLLFD {
|
||||||
unsigned char type; /* LIBSSH2_POLLFD_* below */
|
unsigned char type; /* LIBSSH2_POLLFD_* below */
|
||||||
|
|
||||||
union {
|
union {
|
||||||
int socket; /* File descriptors -- examined with system select() call */
|
int socket; /* File descriptors -- examined with system select() call */
|
||||||
LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */
|
LIBSSH2_CHANNEL *channel; /* Examined by checking internal state */
|
||||||
LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound connections waiting to be accepted? */
|
LIBSSH2_LISTENER *listener; /* Read polls only -- are inbound connections waiting to be accepted? */
|
||||||
} fd;
|
} fd;
|
||||||
|
|
||||||
unsigned long events; /* Requested Events */
|
unsigned long events; /* Requested Events */
|
||||||
unsigned long revents; /* Returned Events */
|
unsigned long revents; /* Returned Events */
|
||||||
} LIBSSH2_POLLFD;
|
} LIBSSH2_POLLFD;
|
||||||
|
|
||||||
/* Poll FD Descriptor Types */
|
/* Poll FD Descriptor Types */
|
||||||
#define LIBSSH2_POLLFD_SOCKET 1
|
#define LIBSSH2_POLLFD_SOCKET 1
|
||||||
#define LIBSSH2_POLLFD_CHANNEL 2
|
#define LIBSSH2_POLLFD_CHANNEL 2
|
||||||
#define LIBSSH2_POLLFD_LISTENER 3
|
#define LIBSSH2_POLLFD_LISTENER 3
|
||||||
|
|
||||||
/* Note: Win32 Doesn't actually have a poll() implementation, so some of these values are faked with select() data */
|
/* Note: Win32 Doesn't actually have a poll() implementation, so some of these values are faked with select() data */
|
||||||
/* Poll FD events/revents -- Match sys/poll.h where possible */
|
/* Poll FD events/revents -- Match sys/poll.h where possible */
|
||||||
#define LIBSSH2_POLLFD_POLLIN 0x0001 /* Data available to be read or connection available -- All */
|
#define LIBSSH2_POLLFD_POLLIN 0x0001 /* Data available to be read or connection available -- All */
|
||||||
#define LIBSSH2_POLLFD_POLLPRI 0x0002 /* Priority data available to be read -- Socket only */
|
#define LIBSSH2_POLLFD_POLLPRI 0x0002 /* Priority data available to be read -- Socket only */
|
||||||
#define LIBSSH2_POLLFD_POLLEXT 0x0002 /* Extended data available to be read -- Channel only */
|
#define LIBSSH2_POLLFD_POLLEXT 0x0002 /* Extended data available to be read -- Channel only */
|
||||||
#define LIBSSH2_POLLFD_POLLOUT 0x0004 /* Can may be written -- Socket/Channel */
|
#define LIBSSH2_POLLFD_POLLOUT 0x0004 /* Can may be written -- Socket/Channel */
|
||||||
/* revents only */
|
/* revents only */
|
||||||
#define LIBSSH2_POLLFD_POLLERR 0x0008 /* Error Condition -- Socket */
|
#define LIBSSH2_POLLFD_POLLERR 0x0008 /* Error Condition -- Socket */
|
||||||
#define LIBSSH2_POLLFD_POLLHUP 0x0010 /* HangUp/EOF -- Socket */
|
#define LIBSSH2_POLLFD_POLLHUP 0x0010 /* HangUp/EOF -- Socket */
|
||||||
#define LIBSSH2_POLLFD_SESSION_CLOSED 0x0010 /* Session Disconnect */
|
#define LIBSSH2_POLLFD_SESSION_CLOSED 0x0010 /* Session Disconnect */
|
||||||
#define LIBSSH2_POLLFD_POLLNVAL 0x0020 /* Invalid request -- Socket Only */
|
#define LIBSSH2_POLLFD_POLLNVAL 0x0020 /* Invalid request -- Socket Only */
|
||||||
#define LIBSSH2_POLLFD_POLLEX 0x0040 /* Exception Condition -- Socket/Win32 */
|
#define LIBSSH2_POLLFD_POLLEX 0x0040 /* Exception Condition -- Socket/Win32 */
|
||||||
#define LIBSSH2_POLLFD_CHANNEL_CLOSED 0x0080 /* Channel Disconnect */
|
#define LIBSSH2_POLLFD_CHANNEL_CLOSED 0x0080 /* Channel Disconnect */
|
||||||
#define LIBSSH2_POLLFD_LISTENER_CLOSED 0x0080 /* Listener Disconnect */
|
#define LIBSSH2_POLLFD_LISTENER_CLOSED 0x0080 /* Listener Disconnect */
|
||||||
|
|
||||||
/* Hash Types */
|
/* Hash Types */
|
||||||
#define LIBSSH2_HOSTKEY_HASH_MD5 1
|
#define LIBSSH2_HOSTKEY_HASH_MD5 1
|
||||||
#define LIBSSH2_HOSTKEY_HASH_SHA1 2
|
#define LIBSSH2_HOSTKEY_HASH_SHA1 2
|
||||||
|
|
||||||
/* Disconnect Codes (defined by SSH protocol) */
|
/* Disconnect Codes (defined by SSH protocol) */
|
||||||
#define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1
|
#define SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT 1
|
||||||
#define SSH_DISCONNECT_PROTOCOL_ERROR 2
|
#define SSH_DISCONNECT_PROTOCOL_ERROR 2
|
||||||
#define SSH_DISCONNECT_KEY_EXCHANGE_FAILED 3
|
#define SSH_DISCONNECT_KEY_EXCHANGE_FAILED 3
|
||||||
#define SSH_DISCONNECT_RESERVED 4
|
#define SSH_DISCONNECT_RESERVED 4
|
||||||
#define SSH_DISCONNECT_MAC_ERROR 5
|
#define SSH_DISCONNECT_MAC_ERROR 5
|
||||||
#define SSH_DISCONNECT_COMPRESSION_ERROR 6
|
#define SSH_DISCONNECT_COMPRESSION_ERROR 6
|
||||||
#define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE 7
|
#define SSH_DISCONNECT_SERVICE_NOT_AVAILABLE 7
|
||||||
#define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8
|
#define SSH_DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED 8
|
||||||
#define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9
|
#define SSH_DISCONNECT_HOST_KEY_NOT_VERIFIABLE 9
|
||||||
#define SSH_DISCONNECT_CONNECTION_LOST 10
|
#define SSH_DISCONNECT_CONNECTION_LOST 10
|
||||||
#define SSH_DISCONNECT_BY_APPLICATION 11
|
#define SSH_DISCONNECT_BY_APPLICATION 11
|
||||||
#define SSH_DISCONNECT_TOO_MANY_CONNECTIONS 12
|
#define SSH_DISCONNECT_TOO_MANY_CONNECTIONS 12
|
||||||
#define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER 13
|
#define SSH_DISCONNECT_AUTH_CANCELLED_BY_USER 13
|
||||||
#define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14
|
#define SSH_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE 14
|
||||||
#define SSH_DISCONNECT_ILLEGAL_USER_NAME 15
|
#define SSH_DISCONNECT_ILLEGAL_USER_NAME 15
|
||||||
|
|
||||||
/* Error Codes (defined by libssh2) */
|
/* Error Codes (defined by libssh2) */
|
||||||
#define LIBSSH2_ERROR_SOCKET_NONE -1
|
#define LIBSSH2_ERROR_SOCKET_NONE -1
|
||||||
#define LIBSSH2_ERROR_BANNER_NONE -2
|
#define LIBSSH2_ERROR_BANNER_NONE -2
|
||||||
#define LIBSSH2_ERROR_BANNER_SEND -3
|
#define LIBSSH2_ERROR_BANNER_SEND -3
|
||||||
#define LIBSSH2_ERROR_INVALID_MAC -4
|
#define LIBSSH2_ERROR_INVALID_MAC -4
|
||||||
#define LIBSSH2_ERROR_KEX_FAILURE -5
|
#define LIBSSH2_ERROR_KEX_FAILURE -5
|
||||||
#define LIBSSH2_ERROR_ALLOC -6
|
#define LIBSSH2_ERROR_ALLOC -6
|
||||||
#define LIBSSH2_ERROR_SOCKET_SEND -7
|
#define LIBSSH2_ERROR_SOCKET_SEND -7
|
||||||
#define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE -8
|
#define LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE -8
|
||||||
#define LIBSSH2_ERROR_TIMEOUT -9
|
#define LIBSSH2_ERROR_TIMEOUT -9
|
||||||
#define LIBSSH2_ERROR_HOSTKEY_INIT -10
|
#define LIBSSH2_ERROR_HOSTKEY_INIT -10
|
||||||
#define LIBSSH2_ERROR_HOSTKEY_SIGN -11
|
#define LIBSSH2_ERROR_HOSTKEY_SIGN -11
|
||||||
#define LIBSSH2_ERROR_DECRYPT -12
|
#define LIBSSH2_ERROR_DECRYPT -12
|
||||||
#define LIBSSH2_ERROR_SOCKET_DISCONNECT -13
|
#define LIBSSH2_ERROR_SOCKET_DISCONNECT -13
|
||||||
#define LIBSSH2_ERROR_PROTO -14
|
#define LIBSSH2_ERROR_PROTO -14
|
||||||
#define LIBSSH2_ERROR_PASSWORD_EXPIRED -15
|
#define LIBSSH2_ERROR_PASSWORD_EXPIRED -15
|
||||||
#define LIBSSH2_ERROR_FILE -16
|
#define LIBSSH2_ERROR_FILE -16
|
||||||
#define LIBSSH2_ERROR_METHOD_NONE -17
|
#define LIBSSH2_ERROR_METHOD_NONE -17
|
||||||
#define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED -18
|
#define LIBSSH2_ERROR_PUBLICKEY_UNRECOGNIZED -18
|
||||||
#define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED -19
|
#define LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED -19
|
||||||
#define LIBSSH2_ERROR_CHANNEL_OUTOFORDER -20
|
#define LIBSSH2_ERROR_CHANNEL_OUTOFORDER -20
|
||||||
#define LIBSSH2_ERROR_CHANNEL_FAILURE -21
|
#define LIBSSH2_ERROR_CHANNEL_FAILURE -21
|
||||||
#define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED -22
|
#define LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED -22
|
||||||
#define LIBSSH2_ERROR_CHANNEL_UNKNOWN -23
|
#define LIBSSH2_ERROR_CHANNEL_UNKNOWN -23
|
||||||
#define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED -24
|
#define LIBSSH2_ERROR_CHANNEL_WINDOW_EXCEEDED -24
|
||||||
#define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED -25
|
#define LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED -25
|
||||||
#define LIBSSH2_ERROR_CHANNEL_CLOSED -26
|
#define LIBSSH2_ERROR_CHANNEL_CLOSED -26
|
||||||
#define LIBSSH2_ERROR_CHANNEL_EOF_SENT -27
|
#define LIBSSH2_ERROR_CHANNEL_EOF_SENT -27
|
||||||
#define LIBSSH2_ERROR_SCP_PROTOCOL -28
|
#define LIBSSH2_ERROR_SCP_PROTOCOL -28
|
||||||
#define LIBSSH2_ERROR_ZLIB -29
|
#define LIBSSH2_ERROR_ZLIB -29
|
||||||
#define LIBSSH2_ERROR_SOCKET_TIMEOUT -30
|
#define LIBSSH2_ERROR_SOCKET_TIMEOUT -30
|
||||||
#define LIBSSH2_ERROR_SFTP_PROTOCOL -31
|
#define LIBSSH2_ERROR_SFTP_PROTOCOL -31
|
||||||
#define LIBSSH2_ERROR_REQUEST_DENIED -32
|
#define LIBSSH2_ERROR_REQUEST_DENIED -32
|
||||||
#define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED -33
|
#define LIBSSH2_ERROR_METHOD_NOT_SUPPORTED -33
|
||||||
#define LIBSSH2_ERROR_INVAL -34
|
#define LIBSSH2_ERROR_INVAL -34
|
||||||
#define LIBSSH2_ERROR_INVALID_POLL_TYPE -35
|
#define LIBSSH2_ERROR_INVALID_POLL_TYPE -35
|
||||||
#define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL -36
|
#define LIBSSH2_ERROR_PUBLICKEY_PROTOCOL -36
|
||||||
|
|
||||||
/* Session API */
|
/* Session API */
|
||||||
LIBSSH2_API LIBSSH2_SESSION *libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), LIBSSH2_FREE_FUNC((*my_free)), LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);
|
LIBSSH2_API LIBSSH2_SESSION *libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), LIBSSH2_FREE_FUNC((*my_free)), LIBSSH2_REALLOC_FUNC((*my_realloc)), void *abstract);
|
||||||
#define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL)
|
#define libssh2_session_init() libssh2_session_init_ex(NULL, NULL, NULL, NULL)
|
||||||
LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session);
|
LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session);
|
||||||
|
|
||||||
LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbtype, void *callback);
|
LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbtype, void *callback);
|
||||||
@ -269,7 +269,7 @@ LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session, const char *banner)
|
|||||||
|
|
||||||
LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int socket);
|
LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int socket);
|
||||||
LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, const char *description, const char *lang);
|
LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, const char *description, const char *lang);
|
||||||
#define libssh2_session_disconnect(session, description) libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, (description), "")
|
#define libssh2_session_disconnect(session, description) libssh2_session_disconnect_ex((session), SSH_DISCONNECT_BY_APPLICATION, (description), "")
|
||||||
LIBSSH2_API void libssh2_session_free(LIBSSH2_SESSION *session);
|
LIBSSH2_API void libssh2_session_free(LIBSSH2_SESSION *session);
|
||||||
|
|
||||||
LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hash_type);
|
LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hash_type);
|
||||||
@ -284,20 +284,20 @@ LIBSSH2_API int libssh2_session_flag(LIBSSH2_SESSION *session, int flag, int val
|
|||||||
LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session, const char *username, unsigned int username_len);
|
LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session, const char *username, unsigned int username_len);
|
||||||
LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
|
LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session);
|
||||||
LIBSSH2_API int libssh2_userauth_password_ex(LIBSSH2_SESSION *session, const char *username, unsigned int username_len, const char *password, unsigned int password_len, LIBSSH2_PASSWD_CHANGEREQ_FUNC((*passwd_change_cb)));
|
LIBSSH2_API int libssh2_userauth_password_ex(LIBSSH2_SESSION *session, const char *username, unsigned int username_len, const char *password, unsigned int password_len, LIBSSH2_PASSWD_CHANGEREQ_FUNC((*passwd_change_cb)));
|
||||||
#define libssh2_userauth_password(session, username, password) libssh2_userauth_password_ex((session), (username), strlen(username), (password), strlen(password), NULL)
|
#define libssh2_userauth_password(session, username, password) libssh2_userauth_password_ex((session), (username), strlen(username), (password), strlen(password), NULL)
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session, const char *username, unsigned int username_len,
|
LIBSSH2_API int libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session, const char *username, unsigned int username_len,
|
||||||
const char *publickey, const char *privatekey,
|
const char *publickey, const char *privatekey,
|
||||||
const char *passphrase);
|
const char *passphrase);
|
||||||
#define libssh2_userauth_publickey_fromfile(session, username, publickey, privatekey, passphrase) \
|
#define libssh2_userauth_publickey_fromfile(session, username, publickey, privatekey, passphrase) \
|
||||||
libssh2_userauth_publickey_fromfile_ex((session), (username), strlen(username), (publickey), (privatekey), (passphrase))
|
libssh2_userauth_publickey_fromfile_ex((session), (username), strlen(username), (publickey), (privatekey), (passphrase))
|
||||||
LIBSSH2_API int libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session, const char *username, unsigned int username_len,
|
LIBSSH2_API int libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session, const char *username, unsigned int username_len,
|
||||||
const char *publickey, const char *privatekey,
|
const char *publickey, const char *privatekey,
|
||||||
const char *passphrase,
|
const char *passphrase,
|
||||||
const char *hostname, unsigned int hostname_len,
|
const char *hostname, unsigned int hostname_len,
|
||||||
const char *local_username, unsigned int local_username_len);
|
const char *local_username, unsigned int local_username_len);
|
||||||
#define libssh2_userauth_hostbased_fromfile(session, username, publickey, privatekey, passphrase, hostname) \
|
#define libssh2_userauth_hostbased_fromfile(session, username, publickey, privatekey, passphrase, hostname) \
|
||||||
libssh2_userauth_hostbased_fromfile_ex((session), (username), strlen(username), (publickey), (privatekey), (passphrase), (hostname), strlen(hostname), (username), strlen(username))
|
libssh2_userauth_hostbased_fromfile_ex((session), (username), strlen(username), (publickey), (privatekey), (passphrase), (hostname), strlen(hostname), (username), strlen(username))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* response_callback is provided with filled by library prompts array,
|
* response_callback is provided with filled by library prompts array,
|
||||||
@ -306,32 +306,32 @@ LIBSSH2_API int libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION *session,
|
|||||||
* after callback return, but before subsequent callback invokation.
|
* after callback return, but before subsequent callback invokation.
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session, const char *username, unsigned int username_len,
|
LIBSSH2_API int libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION* session, const char *username, unsigned int username_len,
|
||||||
LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC((*response_callback)));
|
LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC((*response_callback)));
|
||||||
#define libssh2_userauth_keyboard_interactive(session, username, response_callback) \
|
#define libssh2_userauth_keyboard_interactive(session, username, response_callback) \
|
||||||
libssh2_userauth_keyboard_interactive_ex((session), (username), strlen(username), (response_callback))
|
libssh2_userauth_keyboard_interactive_ex((session), (username), strlen(username), (response_callback))
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeout);
|
LIBSSH2_API int libssh2_poll(LIBSSH2_POLLFD *fds, unsigned int nfds, long timeout);
|
||||||
|
|
||||||
/* Channel API */
|
/* Channel API */
|
||||||
#define LIBSSH2_CHANNEL_WINDOW_DEFAULT 65536
|
#define LIBSSH2_CHANNEL_WINDOW_DEFAULT 65536
|
||||||
#define LIBSSH2_CHANNEL_PACKET_DEFAULT 16384
|
#define LIBSSH2_CHANNEL_PACKET_DEFAULT 16384
|
||||||
#define LIBSSH2_CHANNEL_MINADJUST 1024
|
#define LIBSSH2_CHANNEL_MINADJUST 1024
|
||||||
|
|
||||||
/* Extended Data Handling */
|
/* Extended Data Handling */
|
||||||
#define LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL 0
|
#define LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL 0
|
||||||
#define LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE 1
|
#define LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE 1
|
||||||
#define LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE 2
|
#define LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE 2
|
||||||
|
|
||||||
#define SSH_EXTENDED_DATA_STDERR 1
|
#define SSH_EXTENDED_DATA_STDERR 1
|
||||||
|
|
||||||
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type, unsigned int channel_type_len, unsigned int window_size, unsigned int packet_size, const char *message, unsigned int message_len);
|
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *channel_type, unsigned int channel_type_len, unsigned int window_size, unsigned int packet_size, const char *message, unsigned int message_len);
|
||||||
#define libssh2_channel_open_session(session) libssh2_channel_open_ex((session), "session", sizeof("session") - 1, LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
|
#define libssh2_channel_open_session(session) libssh2_channel_open_ex((session), "session", sizeof("session") - 1, LIBSSH2_CHANNEL_WINDOW_DEFAULT, LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0)
|
||||||
|
|
||||||
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host, int port, const char *shost, int sport);
|
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_channel_direct_tcpip_ex(LIBSSH2_SESSION *session, const char *host, int port, const char *shost, int sport);
|
||||||
#define libssh2_channel_direct_tcpip(session, host, port) libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22)
|
#define libssh2_channel_direct_tcpip(session, host, port) libssh2_channel_direct_tcpip_ex((session), (host), (port), "127.0.0.1", 22)
|
||||||
|
|
||||||
LIBSSH2_API LIBSSH2_LISTENER *libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host, int port, int *bound_port, int queue_maxsize);
|
LIBSSH2_API LIBSSH2_LISTENER *libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host, int port, int *bound_port, int queue_maxsize);
|
||||||
#define libssh2_channel_forward_listen(session, port) libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
|
#define libssh2_channel_forward_listen(session, port) libssh2_channel_forward_listen_ex((session), NULL, (port), NULL, 16)
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
|
LIBSSH2_API int libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener);
|
||||||
|
|
||||||
@ -341,22 +341,22 @@ LIBSSH2_API int libssh2_channel_setenv_ex(LIBSSH2_CHANNEL *channel, char *varnam
|
|||||||
#define libssh2_channel_setenv(channel, varname, value) libssh2_channel_setenv_ex((channel), (varname), strlen(varname), (value), strlen(value))
|
#define libssh2_channel_setenv(channel, varname, value) libssh2_channel_setenv_ex((channel), (varname), strlen(varname), (value), strlen(value))
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel, const char *term, unsigned int term_len, const char *modes, unsigned int modes_len, int width, int height, int width_px, int height_px);
|
LIBSSH2_API int libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL *channel, const char *term, unsigned int term_len, const char *modes, unsigned int modes_len, int width, int height, int width_px, int height_px);
|
||||||
#define libssh2_channel_request_pty(channel, term) libssh2_channel_request_pty_ex((channel), (term), strlen(term), NULL, 0, LIBSSH2_TERM_WIDTH, LIBSSH2_TERM_HEIGHT, LIBSSH2_TERM_WIDTH_PX, LIBSSH2_TERM_HEIGHT_PX)
|
#define libssh2_channel_request_pty(channel, term) libssh2_channel_request_pty_ex((channel), (term), strlen(term), NULL, 0, LIBSSH2_TERM_WIDTH, LIBSSH2_TERM_HEIGHT, LIBSSH2_TERM_WIDTH_PX, LIBSSH2_TERM_HEIGHT_PX)
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel, int single_connection, const char *auth_proto, const char *auth_cookie, int screen_number);
|
LIBSSH2_API int libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel, int single_connection, const char *auth_proto, const char *auth_cookie, int screen_number);
|
||||||
#define libssh2_channel_x11_req(channel, screen_number) libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number))
|
#define libssh2_channel_x11_req(channel, screen_number) libssh2_channel_x11_req_ex((channel), 0, NULL, NULL, (screen_number))
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, const char *request, unsigned int request_len, const char *message, unsigned int message_len);
|
LIBSSH2_API int libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, const char *request, unsigned int request_len, const char *message, unsigned int message_len);
|
||||||
#define libssh2_channel_shell(channel) libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, NULL, 0)
|
#define libssh2_channel_shell(channel) libssh2_channel_process_startup((channel), "shell", sizeof("shell") - 1, NULL, 0)
|
||||||
#define libssh2_channel_exec(channel, command) libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, (command), strlen(command))
|
#define libssh2_channel_exec(channel, command) libssh2_channel_process_startup((channel), "exec", sizeof("exec") - 1, (command), strlen(command))
|
||||||
#define libssh2_channel_subsystem(channel, subsystem) libssh2_channel_process_startup((channel), "subsystem", sizeof("subsystem") - 1, (subsystem), strlen(subsystem))
|
#define libssh2_channel_subsystem(channel, subsystem) libssh2_channel_process_startup((channel), "subsystem", sizeof("subsystem") - 1, (subsystem), strlen(subsystem))
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
|
LIBSSH2_API int libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
|
||||||
int stream_id, char *buf,
|
int stream_id, char *buf,
|
||||||
size_t buflen);
|
size_t buflen);
|
||||||
LIBSSH2_API int libssh2_channel_readnb_ex(LIBSSH2_CHANNEL *channel,
|
LIBSSH2_API int libssh2_channel_readnb_ex(LIBSSH2_CHANNEL *channel,
|
||||||
int stream_id, char *buf,
|
int stream_id, char *buf,
|
||||||
size_t buflen);
|
size_t buflen);
|
||||||
|
|
||||||
/* This is a public error code from libssh2_channel_read() that is returned
|
/* This is a public error code from libssh2_channel_read() that is returned
|
||||||
when it would otherwise block. */
|
when it would otherwise block. */
|
||||||
@ -364,32 +364,32 @@ LIBSSH2_API int libssh2_channel_readnb_ex(LIBSSH2_CHANNEL *channel,
|
|||||||
|
|
||||||
#define libssh2_channel_read(channel, buf, buflen) \
|
#define libssh2_channel_read(channel, buf, buflen) \
|
||||||
libssh2_channel_read_ex((channel), 0, (buf), (buflen))
|
libssh2_channel_read_ex((channel), 0, (buf), (buflen))
|
||||||
#define libssh2_channel_read_stderr(channel, buf, buflen) libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
|
#define libssh2_channel_read_stderr(channel, buf, buflen) libssh2_channel_read_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
|
||||||
#define libssh2_channel_readnb(channel, buf, buflen) \
|
#define libssh2_channel_readnb(channel, buf, buflen) \
|
||||||
libssh2_channel_readnb_ex((channel), 0, (buf), (buflen))
|
libssh2_channel_readnb_ex((channel), 0, (buf), (buflen))
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel, int extended);
|
LIBSSH2_API int libssh2_poll_channel_read(LIBSSH2_CHANNEL *channel, int extended);
|
||||||
|
|
||||||
LIBSSH2_API unsigned long libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel, unsigned long *read_avail, unsigned long *window_size_initial);
|
LIBSSH2_API unsigned long libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel, unsigned long *read_avail, unsigned long *window_size_initial);
|
||||||
#define libssh2_channel_window_read(channel) libssh2_channel_window_read_ex((channel), NULL, NULL)
|
#define libssh2_channel_window_read(channel) libssh2_channel_window_read_ex((channel), NULL, NULL)
|
||||||
|
|
||||||
LIBSSH2_API unsigned long libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel, unsigned long adjustment, unsigned char force);
|
LIBSSH2_API unsigned long libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel, unsigned long adjustment, unsigned char force);
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
|
LIBSSH2_API int libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
|
||||||
int stream_id, const char *buf,
|
int stream_id, const char *buf,
|
||||||
size_t buflen);
|
size_t buflen);
|
||||||
LIBSSH2_API int libssh2_channel_writenb_ex(LIBSSH2_CHANNEL *channel,
|
LIBSSH2_API int libssh2_channel_writenb_ex(LIBSSH2_CHANNEL *channel,
|
||||||
int stream_id, const char *buf,
|
int stream_id, const char *buf,
|
||||||
size_t buflen);
|
size_t buflen);
|
||||||
|
|
||||||
#define libssh2_channel_write(channel, buf, buflen) \
|
#define libssh2_channel_write(channel, buf, buflen) \
|
||||||
libssh2_channel_write_ex((channel), 0, (buf), (buflen))
|
libssh2_channel_write_ex((channel), 0, (buf), (buflen))
|
||||||
#define libssh2_channel_writenb(channel, buf, buflen) \
|
#define libssh2_channel_writenb(channel, buf, buflen) \
|
||||||
libssh2_channel_writenb_ex((channel), 0, (buf), (buflen))
|
libssh2_channel_writenb_ex((channel), 0, (buf), (buflen))
|
||||||
#define libssh2_channel_write_stderr(channel, buf, buflen) libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
|
#define libssh2_channel_write_stderr(channel, buf, buflen) libssh2_channel_write_ex((channel), SSH_EXTENDED_DATA_STDERR, (buf), (buflen))
|
||||||
|
|
||||||
LIBSSH2_API unsigned long libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel, unsigned long *window_size_initial);
|
LIBSSH2_API unsigned long libssh2_channel_window_write_ex(LIBSSH2_CHANNEL *channel, unsigned long *window_size_initial);
|
||||||
#define libssh2_channel_window_write(channel) libssh2_channel_window_write_ex((channel), NULL)
|
#define libssh2_channel_window_write(channel) libssh2_channel_window_write_ex((channel), NULL)
|
||||||
|
|
||||||
LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel, int blocking);
|
LIBSSH2_API void libssh2_channel_set_blocking(LIBSSH2_CHANNEL *channel, int blocking);
|
||||||
LIBSSH2_API int libssh2_channel_get_blocking(LIBSSH2_CHANNEL *channel);
|
LIBSSH2_API int libssh2_channel_get_blocking(LIBSSH2_CHANNEL *channel);
|
||||||
@ -400,13 +400,13 @@ LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel,
|
|||||||
* if LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read (FIFO) from the standard data channel
|
* if LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read (FIFO) from the standard data channel
|
||||||
*/
|
*/
|
||||||
/* DEPRECATED */
|
/* DEPRECATED */
|
||||||
#define libssh2_channel_ignore_extended_data(channel, ignore) libssh2_channel_handle_extended_data((channel), (ignore) ? LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL )
|
#define libssh2_channel_ignore_extended_data(channel, ignore) libssh2_channel_handle_extended_data((channel), (ignore) ? LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL )
|
||||||
|
|
||||||
#define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA -1
|
#define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA -1
|
||||||
#define LIBSSH2_CHANNEL_FLUSH_ALL -2
|
#define LIBSSH2_CHANNEL_FLUSH_ALL -2
|
||||||
LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel, int streamid);
|
LIBSSH2_API int libssh2_channel_flush_ex(LIBSSH2_CHANNEL *channel, int streamid);
|
||||||
#define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0)
|
#define libssh2_channel_flush(channel) libssh2_channel_flush_ex((channel), 0)
|
||||||
#define libssh2_channel_flush_stderr(channel) libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR)
|
#define libssh2_channel_flush_stderr(channel) libssh2_channel_flush_ex((channel), SSH_EXTENDED_DATA_STDERR)
|
||||||
LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel);
|
LIBSSH2_API int libssh2_channel_get_exit_status(LIBSSH2_CHANNEL* channel);
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
|
LIBSSH2_API int libssh2_channel_send_eof(LIBSSH2_CHANNEL *channel);
|
||||||
@ -417,7 +417,7 @@ LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel);
|
|||||||
|
|
||||||
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat *sb);
|
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat *sb);
|
||||||
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t size, long mtime, long atime);
|
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t size, long mtime, long atime);
|
||||||
#define libssh2_scp_send(session, path, mode, size) libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0)
|
#define libssh2_scp_send(session, path, mode, size) libssh2_scp_send_ex((session), (path), (mode), (size), 0, 0)
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest, unsigned int *dest_len, const char *src, unsigned int src_len);
|
LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest, unsigned int *dest_len, const char *src, unsigned int src_len);
|
||||||
|
|
||||||
@ -426,14 +426,14 @@ LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **dest, uns
|
|||||||
enabled
|
enabled
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
|
LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask);
|
||||||
#define LIBSSH2_TRACE_TRANS (1<<1)
|
#define LIBSSH2_TRACE_TRANS (1<<1)
|
||||||
#define LIBSSH2_TRACE_KEX (1<<2)
|
#define LIBSSH2_TRACE_KEX (1<<2)
|
||||||
#define LIBSSH2_TRACE_AUTH (1<<3)
|
#define LIBSSH2_TRACE_AUTH (1<<3)
|
||||||
#define LIBSSH2_TRACE_CONN (1<<4)
|
#define LIBSSH2_TRACE_CONN (1<<4)
|
||||||
#define LIBSSH2_TRACE_SCP (1<<5)
|
#define LIBSSH2_TRACE_SCP (1<<5)
|
||||||
#define LIBSSH2_TRACE_SFTP (1<<6)
|
#define LIBSSH2_TRACE_SFTP (1<<6)
|
||||||
#define LIBSSH2_TRACE_ERROR (1<<7)
|
#define LIBSSH2_TRACE_ERROR (1<<7)
|
||||||
#define LIBSSH2_TRACE_PUBLICKEY (1<<8)
|
#define LIBSSH2_TRACE_PUBLICKEY (1<<8)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
@ -44,32 +44,32 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef LIBSSH2_PUBLICKEY_H
|
#ifndef LIBSSH2_PUBLICKEY_H
|
||||||
#define LIBSSH2_PUBLICKEY_H 1
|
#define LIBSSH2_PUBLICKEY_H 1
|
||||||
|
|
||||||
typedef struct _LIBSSH2_PUBLICKEY LIBSSH2_PUBLICKEY;
|
typedef struct _LIBSSH2_PUBLICKEY LIBSSH2_PUBLICKEY;
|
||||||
|
|
||||||
typedef struct _libssh2_publickey_attribute {
|
typedef struct _libssh2_publickey_attribute {
|
||||||
const char *name;
|
const char *name;
|
||||||
unsigned long name_len;
|
unsigned long name_len;
|
||||||
const char *value;
|
const char *value;
|
||||||
unsigned long value_len;
|
unsigned long value_len;
|
||||||
char mandatory;
|
char mandatory;
|
||||||
} libssh2_publickey_attribute;
|
} libssh2_publickey_attribute;
|
||||||
|
|
||||||
typedef struct _libssh2_publickey_list {
|
typedef struct _libssh2_publickey_list {
|
||||||
unsigned char *packet; /* For freeing */
|
unsigned char *packet; /* For freeing */
|
||||||
|
|
||||||
const unsigned char *name;
|
const unsigned char *name;
|
||||||
unsigned long name_len;
|
unsigned long name_len;
|
||||||
const unsigned char *blob;
|
const unsigned char *blob;
|
||||||
unsigned long blob_len;
|
unsigned long blob_len;
|
||||||
unsigned long num_attrs;
|
unsigned long num_attrs;
|
||||||
libssh2_publickey_attribute *attrs; /* free me */
|
libssh2_publickey_attribute *attrs; /* free me */
|
||||||
} libssh2_publickey_list;
|
} libssh2_publickey_list;
|
||||||
|
|
||||||
/* Generally use the first macro here, but if both name and value are string literals, you can use _fast() to take advantage of preprocessing */
|
/* Generally use the first macro here, but if both name and value are string literals, you can use _fast() to take advantage of preprocessing */
|
||||||
#define libssh2_publickey_attribute(name, value, mandatory) { (name), strlen(name), (value), strlen(value), (mandatory) },
|
#define libssh2_publickey_attribute(name, value, mandatory) { (name), strlen(name), (value), strlen(value), (mandatory) },
|
||||||
#define libssh2_publickey_attribute_fast(name, value, mandatory) { (name), sizeof(name) - 1, (value), sizeof(value) - 1, (mandatory) },
|
#define libssh2_publickey_attribute_fast(name, value, mandatory) { (name), sizeof(name) - 1, (value), sizeof(value) - 1, (mandatory) },
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -79,15 +79,15 @@ extern "C" {
|
|||||||
LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session);
|
LIBSSH2_API LIBSSH2_PUBLICKEY *libssh2_publickey_init(LIBSSH2_SESSION *session);
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, unsigned long name_len,
|
LIBSSH2_API int libssh2_publickey_add_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, unsigned long name_len,
|
||||||
const unsigned char *blob, unsigned long blob_len, char overwrite,
|
const unsigned char *blob, unsigned long blob_len, char overwrite,
|
||||||
unsigned long num_attrs, const libssh2_publickey_attribute attrs[]);
|
unsigned long num_attrs, const libssh2_publickey_attribute attrs[]);
|
||||||
#define libssh2_publickey_add(pkey, name, blob, blob_len, overwrite, num_attrs, attrs) \
|
#define libssh2_publickey_add(pkey, name, blob, blob_len, overwrite, num_attrs, attrs) \
|
||||||
libssh2_publickey_add_ex((pkey), (name), strlen(name), (blob), (blob_len), (overwrite), (num_attrs), (attrs))
|
libssh2_publickey_add_ex((pkey), (name), strlen(name), (blob), (blob_len), (overwrite), (num_attrs), (attrs))
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, unsigned long name_len,
|
LIBSSH2_API int libssh2_publickey_remove_ex(LIBSSH2_PUBLICKEY *pkey, const unsigned char *name, unsigned long name_len,
|
||||||
const unsigned char *blob, unsigned long blob_len);
|
const unsigned char *blob, unsigned long blob_len);
|
||||||
#define libssh2_publickey_remove(pkey, name, blob, blob_len) \
|
#define libssh2_publickey_remove(pkey, name, blob, blob_len) \
|
||||||
libssh2_publickey_remove_ex((pkey), (name), strlen(name), (blob), (blob_len))
|
libssh2_publickey_remove_ex((pkey), (name), strlen(name), (blob), (blob_len))
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, libssh2_publickey_list **pkey_list);
|
LIBSSH2_API int libssh2_publickey_list_fetch(LIBSSH2_PUBLICKEY *pkey, unsigned long *num_keys, libssh2_publickey_list **pkey_list);
|
||||||
LIBSSH2_API void libssh2_publickey_list_free(LIBSSH2_PUBLICKEY *pkey, libssh2_publickey_list *pkey_list);
|
LIBSSH2_API void libssh2_publickey_list_free(LIBSSH2_PUBLICKEY *pkey, libssh2_publickey_list *pkey_list);
|
||||||
|
@ -51,61 +51,61 @@ extern "C" {
|
|||||||
*
|
*
|
||||||
* Let's start with Version 3 (The version found in OpenSSH) and go from there
|
* Let's start with Version 3 (The version found in OpenSSH) and go from there
|
||||||
*/
|
*/
|
||||||
#define LIBSSH2_SFTP_VERSION 3
|
#define LIBSSH2_SFTP_VERSION 3
|
||||||
#define LIBSSH2_SFTP_PACKET_MAXLEN 40000
|
#define LIBSSH2_SFTP_PACKET_MAXLEN 40000
|
||||||
|
|
||||||
typedef struct _LIBSSH2_SFTP LIBSSH2_SFTP;
|
typedef struct _LIBSSH2_SFTP LIBSSH2_SFTP;
|
||||||
typedef struct _LIBSSH2_SFTP_HANDLE LIBSSH2_SFTP_HANDLE;
|
typedef struct _LIBSSH2_SFTP_HANDLE LIBSSH2_SFTP_HANDLE;
|
||||||
typedef struct _LIBSSH2_SFTP_ATTRIBUTES LIBSSH2_SFTP_ATTRIBUTES;
|
typedef struct _LIBSSH2_SFTP_ATTRIBUTES LIBSSH2_SFTP_ATTRIBUTES;
|
||||||
|
|
||||||
/* Flags for open_ex() */
|
/* Flags for open_ex() */
|
||||||
#define LIBSSH2_SFTP_OPENFILE 0
|
#define LIBSSH2_SFTP_OPENFILE 0
|
||||||
#define LIBSSH2_SFTP_OPENDIR 1
|
#define LIBSSH2_SFTP_OPENDIR 1
|
||||||
|
|
||||||
/* Flags for rename_ex() */
|
/* Flags for rename_ex() */
|
||||||
#define LIBSSH2_SFTP_RENAME_OVERWRITE 0x00000001
|
#define LIBSSH2_SFTP_RENAME_OVERWRITE 0x00000001
|
||||||
#define LIBSSH2_SFTP_RENAME_ATOMIC 0x00000002
|
#define LIBSSH2_SFTP_RENAME_ATOMIC 0x00000002
|
||||||
#define LIBSSH2_SFTP_RENAME_NATIVE 0x00000004
|
#define LIBSSH2_SFTP_RENAME_NATIVE 0x00000004
|
||||||
|
|
||||||
/* Flags for stat_ex() */
|
/* Flags for stat_ex() */
|
||||||
#define LIBSSH2_SFTP_STAT 0
|
#define LIBSSH2_SFTP_STAT 0
|
||||||
#define LIBSSH2_SFTP_LSTAT 1
|
#define LIBSSH2_SFTP_LSTAT 1
|
||||||
#define LIBSSH2_SFTP_SETSTAT 2
|
#define LIBSSH2_SFTP_SETSTAT 2
|
||||||
|
|
||||||
/* Flags for symlink_ex() */
|
/* Flags for symlink_ex() */
|
||||||
#define LIBSSH2_SFTP_SYMLINK 0
|
#define LIBSSH2_SFTP_SYMLINK 0
|
||||||
#define LIBSSH2_SFTP_READLINK 1
|
#define LIBSSH2_SFTP_READLINK 1
|
||||||
#define LIBSSH2_SFTP_REALPATH 2
|
#define LIBSSH2_SFTP_REALPATH 2
|
||||||
|
|
||||||
/* SFTP attribute flag bits */
|
/* SFTP attribute flag bits */
|
||||||
#define LIBSSH2_SFTP_ATTR_SIZE 0x00000001
|
#define LIBSSH2_SFTP_ATTR_SIZE 0x00000001
|
||||||
#define LIBSSH2_SFTP_ATTR_UIDGID 0x00000002
|
#define LIBSSH2_SFTP_ATTR_UIDGID 0x00000002
|
||||||
#define LIBSSH2_SFTP_ATTR_PERMISSIONS 0x00000004
|
#define LIBSSH2_SFTP_ATTR_PERMISSIONS 0x00000004
|
||||||
#define LIBSSH2_SFTP_ATTR_ACMODTIME 0x00000008
|
#define LIBSSH2_SFTP_ATTR_ACMODTIME 0x00000008
|
||||||
#define LIBSSH2_SFTP_ATTR_EXTENDED 0x80000000
|
#define LIBSSH2_SFTP_ATTR_EXTENDED 0x80000000
|
||||||
|
|
||||||
struct _LIBSSH2_SFTP_ATTRIBUTES {
|
struct _LIBSSH2_SFTP_ATTRIBUTES {
|
||||||
/* If flags & ATTR_* bit is set, then the value in this struct will be meaningful
|
/* If flags & ATTR_* bit is set, then the value in this struct will be meaningful
|
||||||
* Otherwise it should be ignored
|
* Otherwise it should be ignored
|
||||||
*/
|
*/
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
libssh2_uint64_t filesize;
|
libssh2_uint64_t filesize;
|
||||||
unsigned long uid, gid;
|
unsigned long uid, gid;
|
||||||
unsigned long permissions;
|
unsigned long permissions;
|
||||||
unsigned long atime, mtime;
|
unsigned long atime, mtime;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* SFTP filetypes */
|
/* SFTP filetypes */
|
||||||
#define LIBSSH2_SFTP_TYPE_REGULAR 1
|
#define LIBSSH2_SFTP_TYPE_REGULAR 1
|
||||||
#define LIBSSH2_SFTP_TYPE_DIRECTORY 2
|
#define LIBSSH2_SFTP_TYPE_DIRECTORY 2
|
||||||
#define LIBSSH2_SFTP_TYPE_SYMLINK 3
|
#define LIBSSH2_SFTP_TYPE_SYMLINK 3
|
||||||
#define LIBSSH2_SFTP_TYPE_SPECIAL 4
|
#define LIBSSH2_SFTP_TYPE_SPECIAL 4
|
||||||
#define LIBSSH2_SFTP_TYPE_UNKNOWN 5
|
#define LIBSSH2_SFTP_TYPE_UNKNOWN 5
|
||||||
#define LIBSSH2_SFTP_TYPE_SOCKET 6
|
#define LIBSSH2_SFTP_TYPE_SOCKET 6
|
||||||
#define LIBSSH2_SFTP_TYPE_CHAR_DEVICE 7
|
#define LIBSSH2_SFTP_TYPE_CHAR_DEVICE 7
|
||||||
#define LIBSSH2_SFTP_TYPE_BLOCK_DEVICE 8
|
#define LIBSSH2_SFTP_TYPE_BLOCK_DEVICE 8
|
||||||
#define LIBSSH2_SFTP_TYPE_FIFO 9
|
#define LIBSSH2_SFTP_TYPE_FIFO 9
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reproduce the POSIX file modes here for systems that are not
|
* Reproduce the POSIX file modes here for systems that are not
|
||||||
@ -114,64 +114,64 @@ struct _LIBSSH2_SFTP_ATTRIBUTES {
|
|||||||
* These is used in "permissions" of "struct _LIBSSH2_SFTP_ATTRIBUTES"
|
* These is used in "permissions" of "struct _LIBSSH2_SFTP_ATTRIBUTES"
|
||||||
*/
|
*/
|
||||||
/* File type */
|
/* File type */
|
||||||
#define LIBSSH2_SFTP_S_IFMT 0170000 /* type of file mask */
|
#define LIBSSH2_SFTP_S_IFMT 0170000 /* type of file mask */
|
||||||
#define LIBSSH2_SFTP_S_IFIFO 0010000 /* named pipe (fifo) */
|
#define LIBSSH2_SFTP_S_IFIFO 0010000 /* named pipe (fifo) */
|
||||||
#define LIBSSH2_SFTP_S_IFCHR 0020000 /* character special */
|
#define LIBSSH2_SFTP_S_IFCHR 0020000 /* character special */
|
||||||
#define LIBSSH2_SFTP_S_IFDIR 0040000 /* directory */
|
#define LIBSSH2_SFTP_S_IFDIR 0040000 /* directory */
|
||||||
#define LIBSSH2_SFTP_S_IFBLK 0060000 /* block special */
|
#define LIBSSH2_SFTP_S_IFBLK 0060000 /* block special */
|
||||||
#define LIBSSH2_SFTP_S_IFREG 0100000 /* regular */
|
#define LIBSSH2_SFTP_S_IFREG 0100000 /* regular */
|
||||||
#define LIBSSH2_SFTP_S_IFLNK 0120000 /* symbolic link */
|
#define LIBSSH2_SFTP_S_IFLNK 0120000 /* symbolic link */
|
||||||
#define LIBSSH2_SFTP_S_IFSOCK 0140000 /* socket */
|
#define LIBSSH2_SFTP_S_IFSOCK 0140000 /* socket */
|
||||||
|
|
||||||
/* File mode */
|
/* File mode */
|
||||||
/* Read, write, execute/search by owner */
|
/* Read, write, execute/search by owner */
|
||||||
#define LIBSSH2_SFTP_S_IRWXU 0000700 /* RWX mask for owner */
|
#define LIBSSH2_SFTP_S_IRWXU 0000700 /* RWX mask for owner */
|
||||||
#define LIBSSH2_SFTP_S_IRUSR 0000400 /* R for owner */
|
#define LIBSSH2_SFTP_S_IRUSR 0000400 /* R for owner */
|
||||||
#define LIBSSH2_SFTP_S_IWUSR 0000200 /* W for owner */
|
#define LIBSSH2_SFTP_S_IWUSR 0000200 /* W for owner */
|
||||||
#define LIBSSH2_SFTP_S_IXUSR 0000100 /* X for owner */
|
#define LIBSSH2_SFTP_S_IXUSR 0000100 /* X for owner */
|
||||||
/* Read, write, execute/search by group */
|
/* Read, write, execute/search by group */
|
||||||
#define LIBSSH2_SFTP_S_IRWXG 0000070 /* RWX mask for group */
|
#define LIBSSH2_SFTP_S_IRWXG 0000070 /* RWX mask for group */
|
||||||
#define LIBSSH2_SFTP_S_IRGRP 0000040 /* R for group */
|
#define LIBSSH2_SFTP_S_IRGRP 0000040 /* R for group */
|
||||||
#define LIBSSH2_SFTP_S_IWGRP 0000020 /* W for group */
|
#define LIBSSH2_SFTP_S_IWGRP 0000020 /* W for group */
|
||||||
#define LIBSSH2_SFTP_S_IXGRP 0000010 /* X for group */
|
#define LIBSSH2_SFTP_S_IXGRP 0000010 /* X for group */
|
||||||
/* Read, write, execute/search by others */
|
/* Read, write, execute/search by others */
|
||||||
#define LIBSSH2_SFTP_S_IRWXO 0000007 /* RWX mask for other */
|
#define LIBSSH2_SFTP_S_IRWXO 0000007 /* RWX mask for other */
|
||||||
#define LIBSSH2_SFTP_S_IROTH 0000004 /* R for other */
|
#define LIBSSH2_SFTP_S_IROTH 0000004 /* R for other */
|
||||||
#define LIBSSH2_SFTP_S_IWOTH 0000002 /* W for other */
|
#define LIBSSH2_SFTP_S_IWOTH 0000002 /* W for other */
|
||||||
#define LIBSSH2_SFTP_S_IXOTH 0000001 /* X for other */
|
#define LIBSSH2_SFTP_S_IXOTH 0000001 /* X for other */
|
||||||
|
|
||||||
/* SFTP File Transfer Flags -- (e.g. flags parameter to sftp_open())
|
/* SFTP File Transfer Flags -- (e.g. flags parameter to sftp_open())
|
||||||
* Danger will robinson... APPEND doesn't have any effect on OpenSSH servers */
|
* Danger will robinson... APPEND doesn't have any effect on OpenSSH servers */
|
||||||
#define LIBSSH2_FXF_READ 0x00000001
|
#define LIBSSH2_FXF_READ 0x00000001
|
||||||
#define LIBSSH2_FXF_WRITE 0x00000002
|
#define LIBSSH2_FXF_WRITE 0x00000002
|
||||||
#define LIBSSH2_FXF_APPEND 0x00000004
|
#define LIBSSH2_FXF_APPEND 0x00000004
|
||||||
#define LIBSSH2_FXF_CREAT 0x00000008
|
#define LIBSSH2_FXF_CREAT 0x00000008
|
||||||
#define LIBSSH2_FXF_TRUNC 0x00000010
|
#define LIBSSH2_FXF_TRUNC 0x00000010
|
||||||
#define LIBSSH2_FXF_EXCL 0x00000020
|
#define LIBSSH2_FXF_EXCL 0x00000020
|
||||||
|
|
||||||
/* SFTP Status Codes (returned by libssh2_sftp_last_error() ) */
|
/* SFTP Status Codes (returned by libssh2_sftp_last_error() ) */
|
||||||
#define LIBSSH2_FX_OK 0
|
#define LIBSSH2_FX_OK 0
|
||||||
#define LIBSSH2_FX_EOF 1
|
#define LIBSSH2_FX_EOF 1
|
||||||
#define LIBSSH2_FX_NO_SUCH_FILE 2
|
#define LIBSSH2_FX_NO_SUCH_FILE 2
|
||||||
#define LIBSSH2_FX_PERMISSION_DENIED 3
|
#define LIBSSH2_FX_PERMISSION_DENIED 3
|
||||||
#define LIBSSH2_FX_FAILURE 4
|
#define LIBSSH2_FX_FAILURE 4
|
||||||
#define LIBSSH2_FX_BAD_MESSAGE 5
|
#define LIBSSH2_FX_BAD_MESSAGE 5
|
||||||
#define LIBSSH2_FX_NO_CONNECTION 6
|
#define LIBSSH2_FX_NO_CONNECTION 6
|
||||||
#define LIBSSH2_FX_CONNECTION_LOST 7
|
#define LIBSSH2_FX_CONNECTION_LOST 7
|
||||||
#define LIBSSH2_FX_OP_UNSUPPORTED 8
|
#define LIBSSH2_FX_OP_UNSUPPORTED 8
|
||||||
#define LIBSSH2_FX_INVALID_HANDLE 9
|
#define LIBSSH2_FX_INVALID_HANDLE 9
|
||||||
#define LIBSSH2_FX_NO_SUCH_PATH 10
|
#define LIBSSH2_FX_NO_SUCH_PATH 10
|
||||||
#define LIBSSH2_FX_FILE_ALREADY_EXISTS 11
|
#define LIBSSH2_FX_FILE_ALREADY_EXISTS 11
|
||||||
#define LIBSSH2_FX_WRITE_PROTECT 12
|
#define LIBSSH2_FX_WRITE_PROTECT 12
|
||||||
#define LIBSSH2_FX_NO_MEDIA 13
|
#define LIBSSH2_FX_NO_MEDIA 13
|
||||||
#define LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM 14
|
#define LIBSSH2_FX_NO_SPACE_ON_FILESYSTEM 14
|
||||||
#define LIBSSH2_FX_QUOTA_EXCEEDED 15
|
#define LIBSSH2_FX_QUOTA_EXCEEDED 15
|
||||||
#define LIBSSH2_FX_UNKNOWN_PRINCIPLE 16
|
#define LIBSSH2_FX_UNKNOWN_PRINCIPLE 16
|
||||||
#define LIBSSH2_FX_LOCK_CONFlICT 17
|
#define LIBSSH2_FX_LOCK_CONFlICT 17
|
||||||
#define LIBSSH2_FX_DIR_NOT_EMPTY 18
|
#define LIBSSH2_FX_DIR_NOT_EMPTY 18
|
||||||
#define LIBSSH2_FX_NOT_A_DIRECTORY 19
|
#define LIBSSH2_FX_NOT_A_DIRECTORY 19
|
||||||
#define LIBSSH2_FX_INVALID_FILENAME 20
|
#define LIBSSH2_FX_INVALID_FILENAME 20
|
||||||
#define LIBSSH2_FX_LINK_LOOP 21
|
#define LIBSSH2_FX_LINK_LOOP 21
|
||||||
|
|
||||||
/* SFTP API */
|
/* SFTP API */
|
||||||
LIBSSH2_API LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session);
|
LIBSSH2_API LIBSSH2_SFTP *libssh2_sftp_init(LIBSSH2_SESSION *session);
|
||||||
@ -180,16 +180,16 @@ LIBSSH2_API unsigned long libssh2_sftp_last_error(LIBSSH2_SFTP *sftp);
|
|||||||
|
|
||||||
/* File / Directory Ops */
|
/* File / Directory Ops */
|
||||||
LIBSSH2_API LIBSSH2_SFTP_HANDLE *libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, const char *filename, unsigned int filename_len, unsigned long flags, long mode, int open_type);
|
LIBSSH2_API LIBSSH2_SFTP_HANDLE *libssh2_sftp_open_ex(LIBSSH2_SFTP *sftp, const char *filename, unsigned int filename_len, unsigned long flags, long mode, int open_type);
|
||||||
#define libssh2_sftp_open(sftp, filename, flags, mode) libssh2_sftp_open_ex((sftp), (filename), strlen(filename), (flags), (mode), LIBSSH2_SFTP_OPENFILE)
|
#define libssh2_sftp_open(sftp, filename, flags, mode) libssh2_sftp_open_ex((sftp), (filename), strlen(filename), (flags), (mode), LIBSSH2_SFTP_OPENFILE)
|
||||||
#define libssh2_sftp_opendir(sftp, path) libssh2_sftp_open_ex((sftp), (path), strlen(path), 0, 0, LIBSSH2_SFTP_OPENDIR)
|
#define libssh2_sftp_opendir(sftp, path) libssh2_sftp_open_ex((sftp), (path), strlen(path), 0, 0, LIBSSH2_SFTP_OPENDIR)
|
||||||
|
|
||||||
/* This is a public error code from libssh2_sftp_read() that is returned
|
/* This is a public error code from libssh2_sftp_read() that is returned
|
||||||
when it would otherwise block. */
|
when it would otherwise block. */
|
||||||
#define LIBSSH2SFTP_EAGAIN -2
|
#define LIBSSH2SFTP_EAGAIN -2
|
||||||
LIBSSH2_API ssize_t libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle,
|
LIBSSH2_API ssize_t libssh2_sftp_read(LIBSSH2_SFTP_HANDLE *handle,
|
||||||
char *buffer, size_t buffer_maxlen);
|
char *buffer, size_t buffer_maxlen);
|
||||||
LIBSSH2_API ssize_t libssh2_sftp_readnb(LIBSSH2_SFTP_HANDLE *handle,
|
LIBSSH2_API ssize_t libssh2_sftp_readnb(LIBSSH2_SFTP_HANDLE *handle,
|
||||||
char *buffer, size_t buffer_maxlen);
|
char *buffer, size_t buffer_maxlen);
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
|
LIBSSH2_API int libssh2_sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
|
||||||
size_t buffer_maxlen, LIBSSH2_SFTP_ATTRIBUTES *attrs);
|
size_t buffer_maxlen, LIBSSH2_SFTP_ATTRIBUTES *attrs);
|
||||||
@ -197,52 +197,52 @@ LIBSSH2_API int libssh2_sftp_readdirnb(LIBSSH2_SFTP_HANDLE *handle, char *buffer
|
|||||||
size_t buffer_maxlen, LIBSSH2_SFTP_ATTRIBUTES *attrs);
|
size_t buffer_maxlen, LIBSSH2_SFTP_ATTRIBUTES *attrs);
|
||||||
|
|
||||||
LIBSSH2_API ssize_t libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle,
|
LIBSSH2_API ssize_t libssh2_sftp_write(LIBSSH2_SFTP_HANDLE *handle,
|
||||||
const char *buffer, size_t count);
|
const char *buffer, size_t count);
|
||||||
LIBSSH2_API ssize_t libssh2_sftp_writenb(LIBSSH2_SFTP_HANDLE *handle,
|
LIBSSH2_API ssize_t libssh2_sftp_writenb(LIBSSH2_SFTP_HANDLE *handle,
|
||||||
const char *buffer, size_t count);
|
const char *buffer, size_t count);
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle);
|
LIBSSH2_API int libssh2_sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle);
|
||||||
#define libssh2_sftp_close(handle) libssh2_sftp_close_handle(handle)
|
#define libssh2_sftp_close(handle) libssh2_sftp_close_handle(handle)
|
||||||
#define libssh2_sftp_closedir(handle) libssh2_sftp_close_handle(handle)
|
#define libssh2_sftp_closedir(handle) libssh2_sftp_close_handle(handle)
|
||||||
|
|
||||||
LIBSSH2_API void libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE *handle, size_t offset);
|
LIBSSH2_API void libssh2_sftp_seek(LIBSSH2_SFTP_HANDLE *handle, size_t offset);
|
||||||
#define libssh2_sftp_rewind(handle) libssh2_sftp_seek((handle), 0)
|
#define libssh2_sftp_rewind(handle) libssh2_sftp_seek((handle), 0)
|
||||||
|
|
||||||
LIBSSH2_API size_t libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE *handle);
|
LIBSSH2_API size_t libssh2_sftp_tell(LIBSSH2_SFTP_HANDLE *handle);
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_ATTRIBUTES *attrs, int setstat);
|
LIBSSH2_API int libssh2_sftp_fstat_ex(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_ATTRIBUTES *attrs, int setstat);
|
||||||
#define libssh2_sftp_fstat(handle, attrs) libssh2_sftp_fstat_ex((handle), (attrs), 0)
|
#define libssh2_sftp_fstat(handle, attrs) libssh2_sftp_fstat_ex((handle), (attrs), 0)
|
||||||
#define libssh2_sftp_fsetstat(handle, attrs) libssh2_sftp_fstat_ex((handle), (attrs), 1)
|
#define libssh2_sftp_fsetstat(handle, attrs) libssh2_sftp_fstat_ex((handle), (attrs), 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Miscellaneous Ops */
|
/* Miscellaneous Ops */
|
||||||
LIBSSH2_API int libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp, const char *source_filename, unsigned int srouce_filename_len,
|
LIBSSH2_API int libssh2_sftp_rename_ex(LIBSSH2_SFTP *sftp, const char *source_filename, unsigned int srouce_filename_len,
|
||||||
const char *dest_filename, unsigned int dest_filename_len,
|
const char *dest_filename, unsigned int dest_filename_len,
|
||||||
long flags);
|
long flags);
|
||||||
#define libssh2_sftp_rename(sftp, sourcefile, destfile) libssh2_sftp_rename_ex((sftp), (sourcefile), strlen(sourcefile), (destfile), strlen(destfile), \
|
#define libssh2_sftp_rename(sftp, sourcefile, destfile) libssh2_sftp_rename_ex((sftp), (sourcefile), strlen(sourcefile), (destfile), strlen(destfile), \
|
||||||
LIBSSH2_SFTP_RENAME_OVERWRITE | LIBSSH2_SFTP_RENAME_ATOMIC | LIBSSH2_SFTP_RENAME_NATIVE)
|
LIBSSH2_SFTP_RENAME_OVERWRITE | LIBSSH2_SFTP_RENAME_ATOMIC | LIBSSH2_SFTP_RENAME_NATIVE)
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_sftp_unlink_ex(LIBSSH2_SFTP *sftp, const char *filename, unsigned int filename_len);
|
LIBSSH2_API int libssh2_sftp_unlink_ex(LIBSSH2_SFTP *sftp, const char *filename, unsigned int filename_len);
|
||||||
#define libssh2_sftp_unlink(sftp, filename) libssh2_sftp_unlink_ex((sftp), (filename), strlen(filename))
|
#define libssh2_sftp_unlink(sftp, filename) libssh2_sftp_unlink_ex((sftp), (filename), strlen(filename))
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_sftp_mkdir_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, long mode);
|
LIBSSH2_API int libssh2_sftp_mkdir_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, long mode);
|
||||||
#define libssh2_sftp_mkdir(sftp, path, mode) libssh2_sftp_mkdir_ex((sftp), (path), strlen(path), (mode))
|
#define libssh2_sftp_mkdir(sftp, path, mode) libssh2_sftp_mkdir_ex((sftp), (path), strlen(path), (mode))
|
||||||
LIBSSH2_API int libssh2_sftp_mkdirnb_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, long mode);
|
LIBSSH2_API int libssh2_sftp_mkdirnb_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, long mode);
|
||||||
#define libssh2_sftp_mkdirnb(sftp, path, mode) libssh2_sftp_mkdirnb_ex((sftp), (path), strlen(path), (mode))
|
#define libssh2_sftp_mkdirnb(sftp, path, mode) libssh2_sftp_mkdirnb_ex((sftp), (path), strlen(path), (mode))
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len);
|
LIBSSH2_API int libssh2_sftp_rmdir_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len);
|
||||||
#define libssh2_sftp_rmdir(sftp, path) libssh2_sftp_rmdir_ex((sftp), (path), strlen(path))
|
#define libssh2_sftp_rmdir(sftp, path) libssh2_sftp_rmdir_ex((sftp), (path), strlen(path))
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, int stat_type, LIBSSH2_SFTP_ATTRIBUTES *attrs);
|
LIBSSH2_API int libssh2_sftp_stat_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, int stat_type, LIBSSH2_SFTP_ATTRIBUTES *attrs);
|
||||||
#define libssh2_sftp_stat(sftp, path, attrs) libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_STAT, (attrs))
|
#define libssh2_sftp_stat(sftp, path, attrs) libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_STAT, (attrs))
|
||||||
#define libssh2_sftp_lstat(sftp, path, attrs) libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_LSTAT, (attrs))
|
#define libssh2_sftp_lstat(sftp, path, attrs) libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_LSTAT, (attrs))
|
||||||
#define libssh2_sftp_setstat(sftp, path, attrs) libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_SETSTAT, (attrs))
|
#define libssh2_sftp_setstat(sftp, path, attrs) libssh2_sftp_stat_ex((sftp), (path), strlen(path), LIBSSH2_SFTP_SETSTAT, (attrs))
|
||||||
|
|
||||||
LIBSSH2_API int libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, char *target, unsigned int target_len, int link_type);
|
LIBSSH2_API int libssh2_sftp_symlink_ex(LIBSSH2_SFTP *sftp, const char *path, unsigned int path_len, char *target, unsigned int target_len, int link_type);
|
||||||
#define libssh2_sftp_symlink(sftp, orig, linkpath) libssh2_sftp_symlink_ex((sftp), (orig), strlen(orig), (linkpath), strlen(linkpath), LIBSSH2_SFTP_SYMLINK)
|
#define libssh2_sftp_symlink(sftp, orig, linkpath) libssh2_sftp_symlink_ex((sftp), (orig), strlen(orig), (linkpath), strlen(linkpath), LIBSSH2_SFTP_SYMLINK)
|
||||||
#define libssh2_sftp_readlink(sftp, path, target, maxlen) libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), LIBSSH2_SFTP_READLINK)
|
#define libssh2_sftp_readlink(sftp, path, target, maxlen) libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), LIBSSH2_SFTP_READLINK)
|
||||||
#define libssh2_sftp_realpath(sftp, path, target, maxlen) libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), LIBSSH2_SFTP_REALPATH)
|
#define libssh2_sftp_realpath(sftp, path, target, maxlen) libssh2_sftp_symlink_ex((sftp), (path), strlen(path), (target), (maxlen), LIBSSH2_SFTP_REALPATH)
|
||||||
|
|
||||||
LIBSSH2_API void libssh2_sftp_set_blocking(LIBSSH2_SFTP *session, int blocking);
|
LIBSSH2_API void libssh2_sftp_set_blocking(LIBSSH2_SFTP *session, int blocking);
|
||||||
LIBSSH2_API int libssh2_sftp_get_blocking(LIBSSH2_SFTP *session);
|
LIBSSH2_API int libssh2_sftp_get_blocking(LIBSSH2_SFTP *session);
|
||||||
|
1936
src/channel.c
1936
src/channel.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
344
src/comp.c
344
src/comp.c
@ -48,33 +48,33 @@
|
|||||||
* Minimalist compression: Absolutely none
|
* Minimalist compression: Absolutely none
|
||||||
*/
|
*/
|
||||||
static int libssh2_comp_method_none_comp(LIBSSH2_SESSION *session,
|
static int libssh2_comp_method_none_comp(LIBSSH2_SESSION *session,
|
||||||
int compress,
|
int compress,
|
||||||
unsigned char **dest,
|
unsigned char **dest,
|
||||||
unsigned long *dest_len,
|
unsigned long *dest_len,
|
||||||
unsigned long payload_limit,
|
unsigned long payload_limit,
|
||||||
int *free_dest,
|
int *free_dest,
|
||||||
const unsigned char *src,
|
const unsigned char *src,
|
||||||
unsigned long src_len,
|
unsigned long src_len,
|
||||||
void **abstract)
|
void **abstract)
|
||||||
{
|
{
|
||||||
(void)session;
|
(void)session;
|
||||||
(void)compress;
|
(void)compress;
|
||||||
(void)payload_limit;
|
(void)payload_limit;
|
||||||
(void)abstract;
|
(void)abstract;
|
||||||
*dest = (unsigned char *)src;
|
*dest = (unsigned char *)src;
|
||||||
*dest_len = src_len;
|
*dest_len = src_len;
|
||||||
|
|
||||||
*free_dest = 0;
|
*free_dest = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_COMP_METHOD libssh2_comp_method_none = {
|
static const LIBSSH2_COMP_METHOD libssh2_comp_method_none = {
|
||||||
"none",
|
"none",
|
||||||
NULL,
|
NULL,
|
||||||
libssh2_comp_method_none_comp,
|
libssh2_comp_method_none_comp,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef LIBSSH2_HAVE_ZLIB
|
#ifdef LIBSSH2_HAVE_ZLIB
|
||||||
@ -89,16 +89,16 @@ static const LIBSSH2_COMP_METHOD libssh2_comp_method_none = {
|
|||||||
|
|
||||||
static voidpf libssh2_comp_method_zlib_alloc(voidpf opaque, uInt items, uInt size)
|
static voidpf libssh2_comp_method_zlib_alloc(voidpf opaque, uInt items, uInt size)
|
||||||
{
|
{
|
||||||
LIBSSH2_SESSION *session = (LIBSSH2_SESSION*)opaque;
|
LIBSSH2_SESSION *session = (LIBSSH2_SESSION*)opaque;
|
||||||
|
|
||||||
return (voidpf)LIBSSH2_ALLOC(session, items * size);
|
return (voidpf)LIBSSH2_ALLOC(session, items * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void libssh2_comp_method_zlib_free(voidpf opaque, voidpf address)
|
static void libssh2_comp_method_zlib_free(voidpf opaque, voidpf address)
|
||||||
{
|
{
|
||||||
LIBSSH2_SESSION *session = (LIBSSH2_SESSION*)opaque;
|
LIBSSH2_SESSION *session = (LIBSSH2_SESSION*)opaque;
|
||||||
|
|
||||||
LIBSSH2_FREE(session, address);
|
LIBSSH2_FREE(session, address);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -107,34 +107,34 @@ static void libssh2_comp_method_zlib_free(voidpf opaque, voidpf address)
|
|||||||
*/
|
*/
|
||||||
static int libssh2_comp_method_zlib_init(LIBSSH2_SESSION *session, int compress, void **abstract)
|
static int libssh2_comp_method_zlib_init(LIBSSH2_SESSION *session, int compress, void **abstract)
|
||||||
{
|
{
|
||||||
z_stream *strm;
|
z_stream *strm;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
strm = LIBSSH2_ALLOC(session, sizeof(z_stream));
|
strm = LIBSSH2_ALLOC(session, sizeof(z_stream));
|
||||||
if (!strm) {
|
if (!strm) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for zlib compression/decompression", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for zlib compression/decompression", 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(strm, 0, sizeof(z_stream));
|
memset(strm, 0, sizeof(z_stream));
|
||||||
|
|
||||||
strm->opaque = (voidpf)session;
|
strm->opaque = (voidpf)session;
|
||||||
strm->zalloc = (alloc_func)libssh2_comp_method_zlib_alloc;
|
strm->zalloc = (alloc_func)libssh2_comp_method_zlib_alloc;
|
||||||
strm->zfree = (free_func)libssh2_comp_method_zlib_free;
|
strm->zfree = (free_func)libssh2_comp_method_zlib_free;
|
||||||
if (compress) {
|
if (compress) {
|
||||||
/* deflate */
|
/* deflate */
|
||||||
status = deflateInit(strm, Z_DEFAULT_COMPRESSION);
|
status = deflateInit(strm, Z_DEFAULT_COMPRESSION);
|
||||||
} else {
|
} else {
|
||||||
/* inflate */
|
/* inflate */
|
||||||
status = inflateInit(strm);
|
status = inflateInit(strm);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status != Z_OK) {
|
if (status != Z_OK) {
|
||||||
LIBSSH2_FREE(session, strm);
|
LIBSSH2_FREE(session, strm);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*abstract = strm;
|
*abstract = strm;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -142,124 +142,124 @@ static int libssh2_comp_method_zlib_init(LIBSSH2_SESSION *session, int compress,
|
|||||||
* zlib, a compression standard for all occasions
|
* zlib, a compression standard for all occasions
|
||||||
*/
|
*/
|
||||||
static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
||||||
int compress,
|
int compress,
|
||||||
unsigned char **dest,
|
unsigned char **dest,
|
||||||
unsigned long *dest_len,
|
unsigned long *dest_len,
|
||||||
unsigned long payload_limit,
|
unsigned long payload_limit,
|
||||||
int *free_dest,
|
int *free_dest,
|
||||||
const unsigned char *src,
|
const unsigned char *src,
|
||||||
unsigned long src_len,
|
unsigned long src_len,
|
||||||
void **abstract)
|
void **abstract)
|
||||||
{
|
{
|
||||||
z_stream *strm = *abstract;
|
z_stream *strm = *abstract;
|
||||||
/* A short-term alloc of a full data chunk is better than a series of
|
/* A short-term alloc of a full data chunk is better than a series of
|
||||||
reallocs */
|
reallocs */
|
||||||
char *out;
|
char *out;
|
||||||
int out_maxlen = compress ? (src_len + 4) : (2 * src_len);
|
int out_maxlen = compress ? (src_len + 4) : (2 * src_len);
|
||||||
int limiter = 0;
|
int limiter = 0;
|
||||||
|
|
||||||
/* In practice they never come smaller than this */
|
/* In practice they never come smaller than this */
|
||||||
if (out_maxlen < 25) {
|
if (out_maxlen < 25) {
|
||||||
out_maxlen = 25;
|
out_maxlen = 25;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out_maxlen > (int)payload_limit) {
|
if (out_maxlen > (int)payload_limit) {
|
||||||
out_maxlen = payload_limit;
|
out_maxlen = payload_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
strm->next_in = (unsigned char *)src;
|
strm->next_in = (unsigned char *)src;
|
||||||
strm->avail_in = src_len;
|
strm->avail_in = src_len;
|
||||||
strm->next_out = (unsigned char *)LIBSSH2_ALLOC(session, out_maxlen);
|
strm->next_out = (unsigned char *)LIBSSH2_ALLOC(session, out_maxlen);
|
||||||
out = (char *)strm->next_out;
|
out = (char *)strm->next_out;
|
||||||
strm->avail_out = out_maxlen;
|
strm->avail_out = out_maxlen;
|
||||||
if (!strm->next_out) {
|
if (!strm->next_out) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate compression/decompression buffer", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate compression/decompression buffer", 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while (strm->avail_in) {
|
while (strm->avail_in) {
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (compress) {
|
if (compress) {
|
||||||
status = deflate(strm, Z_PARTIAL_FLUSH);
|
status = deflate(strm, Z_PARTIAL_FLUSH);
|
||||||
} else {
|
} else {
|
||||||
status = inflate(strm, Z_PARTIAL_FLUSH);
|
status = inflate(strm, Z_PARTIAL_FLUSH);
|
||||||
}
|
}
|
||||||
if (status != Z_OK) {
|
if (status != Z_OK) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ZLIB, "compress/decompression failure", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ZLIB, "compress/decompression failure", 0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (strm->avail_in) {
|
if (strm->avail_in) {
|
||||||
unsigned long out_ofs = out_maxlen - strm->avail_out;
|
unsigned long out_ofs = out_maxlen - strm->avail_out;
|
||||||
char *newout;
|
char *newout;
|
||||||
|
|
||||||
out_maxlen += compress ? (strm->avail_in + 4) : (2 * strm->avail_in);
|
out_maxlen += compress ? (strm->avail_in + 4) : (2 * strm->avail_in);
|
||||||
|
|
||||||
if ((out_maxlen > (int)payload_limit) &&
|
if ((out_maxlen > (int)payload_limit) &&
|
||||||
!compress && limiter++) {
|
!compress && limiter++) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ZLIB,
|
libssh2_error(session, LIBSSH2_ERROR_ZLIB,
|
||||||
"Excessive growth in decompression phase", 0);
|
"Excessive growth in decompression phase", 0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
|
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
|
||||||
if (!newout) {
|
if (!newout) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to expand compress/decompression buffer", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to expand compress/decompression buffer", 0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
out = newout;
|
out = newout;
|
||||||
strm->next_out = (unsigned char *)out + out_ofs;
|
strm->next_out = (unsigned char *)out + out_ofs;
|
||||||
strm->avail_out += compress ? (strm->avail_in + 4) : (2 * strm->avail_in);
|
strm->avail_out += compress ? (strm->avail_in + 4) : (2 * strm->avail_in);
|
||||||
} else while (!strm->avail_out) {
|
} else while (!strm->avail_out) {
|
||||||
/* Done with input, might be a byte or two in internal buffer during compress
|
/* Done with input, might be a byte or two in internal buffer during compress
|
||||||
* Or potentially many bytes if it's a decompress
|
* Or potentially many bytes if it's a decompress
|
||||||
*/
|
*/
|
||||||
int grow_size = compress ? 8 : 1024;
|
int grow_size = compress ? 8 : 1024;
|
||||||
char *newout;
|
char *newout;
|
||||||
|
|
||||||
if (out_maxlen >= (int)payload_limit) {
|
if (out_maxlen >= (int)payload_limit) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ZLIB, "Excessive growth in decompression phase", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ZLIB, "Excessive growth in decompression phase", 0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grow_size > (int)(payload_limit - out_maxlen)) {
|
if (grow_size > (int)(payload_limit - out_maxlen)) {
|
||||||
grow_size = payload_limit - out_maxlen;
|
grow_size = payload_limit - out_maxlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_maxlen += grow_size;
|
out_maxlen += grow_size;
|
||||||
strm->avail_out = grow_size;
|
strm->avail_out = grow_size;
|
||||||
|
|
||||||
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
|
newout = LIBSSH2_REALLOC(session, out, out_maxlen);
|
||||||
if (!newout) {
|
if (!newout) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to expand final compress/decompress buffer", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to expand final compress/decompress buffer", 0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
out = newout;
|
out = newout;
|
||||||
strm->next_out = (unsigned char *)out + out_maxlen -
|
strm->next_out = (unsigned char *)out + out_maxlen -
|
||||||
grow_size;
|
grow_size;
|
||||||
|
|
||||||
if (compress) {
|
if (compress) {
|
||||||
status = deflate(strm, Z_PARTIAL_FLUSH);
|
status = deflate(strm, Z_PARTIAL_FLUSH);
|
||||||
} else {
|
} else {
|
||||||
status = inflate(strm, Z_PARTIAL_FLUSH);
|
status = inflate(strm, Z_PARTIAL_FLUSH);
|
||||||
}
|
}
|
||||||
if (status != Z_OK) {
|
if (status != Z_OK) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ZLIB, "compress/decompression failure", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ZLIB, "compress/decompression failure", 0);
|
||||||
LIBSSH2_FREE(session, out);
|
LIBSSH2_FREE(session, out);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*dest = (unsigned char *)out;
|
*dest = (unsigned char *)out;
|
||||||
*dest_len = out_maxlen - strm->avail_out;
|
*dest_len = out_maxlen - strm->avail_out;
|
||||||
*free_dest = 1;
|
*free_dest = 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -268,31 +268,31 @@ static int libssh2_comp_method_zlib_comp(LIBSSH2_SESSION *session,
|
|||||||
*/
|
*/
|
||||||
static int libssh2_comp_method_zlib_dtor(LIBSSH2_SESSION *session, int compress, void **abstract)
|
static int libssh2_comp_method_zlib_dtor(LIBSSH2_SESSION *session, int compress, void **abstract)
|
||||||
{
|
{
|
||||||
z_stream *strm = *abstract;
|
z_stream *strm = *abstract;
|
||||||
|
|
||||||
if (strm) {
|
if (strm) {
|
||||||
if (compress) {
|
if (compress) {
|
||||||
/* deflate */
|
/* deflate */
|
||||||
deflateEnd(strm);
|
deflateEnd(strm);
|
||||||
} else {
|
} else {
|
||||||
/* inflate */
|
/* inflate */
|
||||||
inflateEnd(strm);
|
inflateEnd(strm);
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBSSH2_FREE(session, strm);
|
LIBSSH2_FREE(session, strm);
|
||||||
}
|
}
|
||||||
|
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_COMP_METHOD libssh2_comp_method_zlib = {
|
static const LIBSSH2_COMP_METHOD libssh2_comp_method_zlib = {
|
||||||
"zlib",
|
"zlib",
|
||||||
libssh2_comp_method_zlib_init,
|
libssh2_comp_method_zlib_init,
|
||||||
libssh2_comp_method_zlib_comp,
|
libssh2_comp_method_zlib_comp,
|
||||||
libssh2_comp_method_zlib_dtor,
|
libssh2_comp_method_zlib_dtor,
|
||||||
};
|
};
|
||||||
#endif /* LIBSSH2_HAVE_ZLIB */
|
#endif /* LIBSSH2_HAVE_ZLIB */
|
||||||
|
|
||||||
@ -301,14 +301,14 @@ static const LIBSSH2_COMP_METHOD libssh2_comp_method_zlib = {
|
|||||||
*********************** */
|
*********************** */
|
||||||
|
|
||||||
static const LIBSSH2_COMP_METHOD *_libssh2_comp_methods[] = {
|
static const LIBSSH2_COMP_METHOD *_libssh2_comp_methods[] = {
|
||||||
&libssh2_comp_method_none,
|
&libssh2_comp_method_none,
|
||||||
#ifdef LIBSSH2_HAVE_ZLIB
|
#ifdef LIBSSH2_HAVE_ZLIB
|
||||||
&libssh2_comp_method_zlib,
|
&libssh2_comp_method_zlib,
|
||||||
#endif /* LIBSSH2_HAVE_ZLIB */
|
#endif /* LIBSSH2_HAVE_ZLIB */
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const LIBSSH2_COMP_METHOD **libssh2_comp_methods(void) {
|
const LIBSSH2_COMP_METHOD **libssh2_comp_methods(void) {
|
||||||
return _libssh2_comp_methods;
|
return _libssh2_comp_methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
254
src/crypt.c
254
src/crypt.c
@ -43,205 +43,205 @@
|
|||||||
*/
|
*/
|
||||||
static int libssh2_crypt_none_crypt(LIBSSH2_SESSION *session, unsigned char *buf, void **abstract)
|
static int libssh2_crypt_none_crypt(LIBSSH2_SESSION *session, unsigned char *buf, void **abstract)
|
||||||
{
|
{
|
||||||
/* Do nothing to the data! */
|
/* Do nothing to the data! */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_none = {
|
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_none = {
|
||||||
"none",
|
"none",
|
||||||
8, /* blocksize (SSH2 defines minimum blocksize as 8) */
|
8, /* blocksize (SSH2 defines minimum blocksize as 8) */
|
||||||
0, /* iv_len */
|
0, /* iv_len */
|
||||||
0, /* secret_len */
|
0, /* secret_len */
|
||||||
0, /* flags */
|
0, /* flags */
|
||||||
NULL,
|
NULL,
|
||||||
libssh2_crypt_none_crypt,
|
libssh2_crypt_none_crypt,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
#endif /* LIBSSH2_CRYPT_NONE */
|
#endif /* LIBSSH2_CRYPT_NONE */
|
||||||
|
|
||||||
struct crypt_ctx {
|
struct crypt_ctx {
|
||||||
int encrypt;
|
int encrypt;
|
||||||
_libssh2_cipher_type(algo);
|
_libssh2_cipher_type(algo);
|
||||||
_libssh2_cipher_ctx h;
|
_libssh2_cipher_ctx h;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int _libssh2_init (LIBSSH2_SESSION *session,
|
static int _libssh2_init (LIBSSH2_SESSION *session,
|
||||||
const LIBSSH2_CRYPT_METHOD *method,
|
const LIBSSH2_CRYPT_METHOD *method,
|
||||||
unsigned char *iv, int *free_iv,
|
unsigned char *iv, int *free_iv,
|
||||||
unsigned char *secret, int *free_secret,
|
unsigned char *secret, int *free_secret,
|
||||||
int encrypt, void **abstract)
|
int encrypt, void **abstract)
|
||||||
{
|
{
|
||||||
struct crypt_ctx *ctx = LIBSSH2_ALLOC(session,
|
struct crypt_ctx *ctx = LIBSSH2_ALLOC(session,
|
||||||
sizeof(struct crypt_ctx));
|
sizeof(struct crypt_ctx));
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ctx->encrypt = encrypt;
|
ctx->encrypt = encrypt;
|
||||||
ctx->algo = method->algo;
|
ctx->algo = method->algo;
|
||||||
if (_libssh2_cipher_init (&ctx->h, ctx->algo, iv, secret, encrypt))
|
if (_libssh2_cipher_init (&ctx->h, ctx->algo, iv, secret, encrypt))
|
||||||
{
|
{
|
||||||
LIBSSH2_FREE (session, ctx);
|
LIBSSH2_FREE (session, ctx);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*abstract = ctx;
|
*abstract = ctx;
|
||||||
*free_iv = 1;
|
*free_iv = 1;
|
||||||
*free_secret = 1;
|
*free_secret = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _libssh2_encrypt(LIBSSH2_SESSION *session, unsigned char *block, void **abstract)
|
static int _libssh2_encrypt(LIBSSH2_SESSION *session, unsigned char *block, void **abstract)
|
||||||
{
|
{
|
||||||
struct crypt_ctx *cctx = *(struct crypt_ctx **)abstract;
|
struct crypt_ctx *cctx = *(struct crypt_ctx **)abstract;
|
||||||
(void)session;
|
(void)session;
|
||||||
return _libssh2_cipher_crypt(&cctx->h, cctx->algo,
|
return _libssh2_cipher_crypt(&cctx->h, cctx->algo,
|
||||||
cctx->encrypt, block);
|
cctx->encrypt, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _libssh2_dtor(LIBSSH2_SESSION *session, void **abstract)
|
static int _libssh2_dtor(LIBSSH2_SESSION *session, void **abstract)
|
||||||
{
|
{
|
||||||
struct crypt_ctx **cctx = (struct crypt_ctx **)abstract;
|
struct crypt_ctx **cctx = (struct crypt_ctx **)abstract;
|
||||||
if (cctx && *cctx) {
|
if (cctx && *cctx) {
|
||||||
_libssh2_cipher_dtor(&(*cctx)->h);
|
_libssh2_cipher_dtor(&(*cctx)->h);
|
||||||
LIBSSH2_FREE(session, *cctx);
|
LIBSSH2_FREE(session, *cctx);
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LIBSSH2_AES
|
#if LIBSSH2_AES
|
||||||
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes128_cbc = {
|
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes128_cbc = {
|
||||||
"aes128-cbc",
|
"aes128-cbc",
|
||||||
16, /* blocksize */
|
16, /* blocksize */
|
||||||
16, /* initial value length */
|
16, /* initial value length */
|
||||||
16, /* secret length -- 16*8 == 128bit */
|
16, /* secret length -- 16*8 == 128bit */
|
||||||
0, /* flags */
|
0, /* flags */
|
||||||
&_libssh2_init,
|
&_libssh2_init,
|
||||||
&_libssh2_encrypt,
|
&_libssh2_encrypt,
|
||||||
&_libssh2_dtor,
|
&_libssh2_dtor,
|
||||||
_libssh2_cipher_aes128
|
_libssh2_cipher_aes128
|
||||||
};
|
};
|
||||||
|
|
||||||
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes192_cbc = {
|
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes192_cbc = {
|
||||||
"aes192-cbc",
|
"aes192-cbc",
|
||||||
16, /* blocksize */
|
16, /* blocksize */
|
||||||
16, /* initial value length */
|
16, /* initial value length */
|
||||||
24, /* secret length -- 24*8 == 192bit */
|
24, /* secret length -- 24*8 == 192bit */
|
||||||
0, /* flags */
|
0, /* flags */
|
||||||
&_libssh2_init,
|
&_libssh2_init,
|
||||||
&_libssh2_encrypt,
|
&_libssh2_encrypt,
|
||||||
&_libssh2_dtor,
|
&_libssh2_dtor,
|
||||||
_libssh2_cipher_aes192
|
_libssh2_cipher_aes192
|
||||||
};
|
};
|
||||||
|
|
||||||
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes256_cbc = {
|
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_aes256_cbc = {
|
||||||
"aes256-cbc",
|
"aes256-cbc",
|
||||||
16, /* blocksize */
|
16, /* blocksize */
|
||||||
16, /* initial value length */
|
16, /* initial value length */
|
||||||
32, /* secret length -- 32*8 == 256bit */
|
32, /* secret length -- 32*8 == 256bit */
|
||||||
0, /* flags */
|
0, /* flags */
|
||||||
&_libssh2_init,
|
&_libssh2_init,
|
||||||
&_libssh2_encrypt,
|
&_libssh2_encrypt,
|
||||||
&_libssh2_dtor,
|
&_libssh2_dtor,
|
||||||
_libssh2_cipher_aes256
|
_libssh2_cipher_aes256
|
||||||
};
|
};
|
||||||
|
|
||||||
/* rijndael-cbc@lysator.liu.se == aes256-cbc */
|
/* rijndael-cbc@lysator.liu.se == aes256-cbc */
|
||||||
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_rijndael_cbc_lysator_liu_se = {
|
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_rijndael_cbc_lysator_liu_se = {
|
||||||
"rijndael-cbc@lysator.liu.se",
|
"rijndael-cbc@lysator.liu.se",
|
||||||
16, /* blocksize */
|
16, /* blocksize */
|
||||||
16, /* initial value length */
|
16, /* initial value length */
|
||||||
32, /* secret length -- 32*8 == 256bit */
|
32, /* secret length -- 32*8 == 256bit */
|
||||||
0, /* flags */
|
0, /* flags */
|
||||||
&_libssh2_init,
|
&_libssh2_init,
|
||||||
&_libssh2_encrypt,
|
&_libssh2_encrypt,
|
||||||
&_libssh2_dtor,
|
&_libssh2_dtor,
|
||||||
_libssh2_cipher_aes256
|
_libssh2_cipher_aes256
|
||||||
};
|
};
|
||||||
#endif /* LIBSSH2_AES */
|
#endif /* LIBSSH2_AES */
|
||||||
|
|
||||||
#if LIBSSH2_BLOWFISH
|
#if LIBSSH2_BLOWFISH
|
||||||
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_blowfish_cbc = {
|
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_blowfish_cbc = {
|
||||||
"blowfish-cbc",
|
"blowfish-cbc",
|
||||||
8, /* blocksize */
|
8, /* blocksize */
|
||||||
8, /* initial value length */
|
8, /* initial value length */
|
||||||
16, /* secret length */
|
16, /* secret length */
|
||||||
0, /* flags */
|
0, /* flags */
|
||||||
&_libssh2_init,
|
&_libssh2_init,
|
||||||
&_libssh2_encrypt,
|
&_libssh2_encrypt,
|
||||||
&_libssh2_dtor,
|
&_libssh2_dtor,
|
||||||
_libssh2_cipher_blowfish
|
_libssh2_cipher_blowfish
|
||||||
};
|
};
|
||||||
#endif /* LIBSSH2_BLOWFISH */
|
#endif /* LIBSSH2_BLOWFISH */
|
||||||
|
|
||||||
#if LIBSSH2_RC4
|
#if LIBSSH2_RC4
|
||||||
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_arcfour = {
|
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_arcfour = {
|
||||||
"arcfour",
|
"arcfour",
|
||||||
8, /* blocksize */
|
8, /* blocksize */
|
||||||
8, /* initial value length */
|
8, /* initial value length */
|
||||||
16, /* secret length */
|
16, /* secret length */
|
||||||
0, /* flags */
|
0, /* flags */
|
||||||
&_libssh2_init,
|
&_libssh2_init,
|
||||||
&_libssh2_encrypt,
|
&_libssh2_encrypt,
|
||||||
&_libssh2_dtor,
|
&_libssh2_dtor,
|
||||||
_libssh2_cipher_arcfour
|
_libssh2_cipher_arcfour
|
||||||
};
|
};
|
||||||
#endif /* LIBSSH2_RC4 */
|
#endif /* LIBSSH2_RC4 */
|
||||||
|
|
||||||
#if LIBSSH2_CAST
|
#if LIBSSH2_CAST
|
||||||
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_cast128_cbc = {
|
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_cast128_cbc = {
|
||||||
"cast128-cbc",
|
"cast128-cbc",
|
||||||
8, /* blocksize */
|
8, /* blocksize */
|
||||||
8, /* initial value length */
|
8, /* initial value length */
|
||||||
16, /* secret length */
|
16, /* secret length */
|
||||||
0, /* flags */
|
0, /* flags */
|
||||||
&_libssh2_init,
|
&_libssh2_init,
|
||||||
&_libssh2_encrypt,
|
&_libssh2_encrypt,
|
||||||
&_libssh2_dtor,
|
&_libssh2_dtor,
|
||||||
_libssh2_cipher_cast5
|
_libssh2_cipher_cast5
|
||||||
};
|
};
|
||||||
#endif /* LIBSSH2_CAST */
|
#endif /* LIBSSH2_CAST */
|
||||||
|
|
||||||
#if LIBSSH2_3DES
|
#if LIBSSH2_3DES
|
||||||
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_3des_cbc = {
|
static const LIBSSH2_CRYPT_METHOD libssh2_crypt_method_3des_cbc = {
|
||||||
"3des-cbc",
|
"3des-cbc",
|
||||||
8, /* blocksize */
|
8, /* blocksize */
|
||||||
8, /* initial value length */
|
8, /* initial value length */
|
||||||
24, /* secret length */
|
24, /* secret length */
|
||||||
0, /* flags */
|
0, /* flags */
|
||||||
&_libssh2_init,
|
&_libssh2_init,
|
||||||
&_libssh2_encrypt,
|
&_libssh2_encrypt,
|
||||||
&_libssh2_dtor,
|
&_libssh2_dtor,
|
||||||
_libssh2_cipher_3des
|
_libssh2_cipher_3des
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const LIBSSH2_CRYPT_METHOD *_libssh2_crypt_methods[] = {
|
static const LIBSSH2_CRYPT_METHOD *_libssh2_crypt_methods[] = {
|
||||||
#if LIBSSH2_AES
|
#if LIBSSH2_AES
|
||||||
&libssh2_crypt_method_aes256_cbc,
|
&libssh2_crypt_method_aes256_cbc,
|
||||||
&libssh2_crypt_method_rijndael_cbc_lysator_liu_se, /* == aes256-cbc */
|
&libssh2_crypt_method_rijndael_cbc_lysator_liu_se, /* == aes256-cbc */
|
||||||
&libssh2_crypt_method_aes192_cbc,
|
&libssh2_crypt_method_aes192_cbc,
|
||||||
&libssh2_crypt_method_aes128_cbc,
|
&libssh2_crypt_method_aes128_cbc,
|
||||||
#endif /* LIBSSH2_AES */
|
#endif /* LIBSSH2_AES */
|
||||||
#if LIBSSH2_BLOWFISH
|
#if LIBSSH2_BLOWFISH
|
||||||
&libssh2_crypt_method_blowfish_cbc,
|
&libssh2_crypt_method_blowfish_cbc,
|
||||||
#endif /* LIBSSH2_BLOWFISH */
|
#endif /* LIBSSH2_BLOWFISH */
|
||||||
#if LIBSSH2_RC4
|
#if LIBSSH2_RC4
|
||||||
&libssh2_crypt_method_arcfour,
|
&libssh2_crypt_method_arcfour,
|
||||||
#endif /* LIBSSH2_RC4 */
|
#endif /* LIBSSH2_RC4 */
|
||||||
#if LIBSSH2_CAST
|
#if LIBSSH2_CAST
|
||||||
&libssh2_crypt_method_cast128_cbc,
|
&libssh2_crypt_method_cast128_cbc,
|
||||||
#endif /* LIBSSH2_CAST */
|
#endif /* LIBSSH2_CAST */
|
||||||
#if LIBSSH2_3DES
|
#if LIBSSH2_3DES
|
||||||
&libssh2_crypt_method_3des_cbc,
|
&libssh2_crypt_method_3des_cbc,
|
||||||
#endif /* LIBSSH2_DES */
|
#endif /* LIBSSH2_DES */
|
||||||
#ifdef LIBSSH2_CRYPT_NONE
|
#ifdef LIBSSH2_CRYPT_NONE
|
||||||
&libssh2_crypt_method_none,
|
&libssh2_crypt_method_none,
|
||||||
#endif
|
#endif
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Expose to kex.c */
|
/* Expose to kex.c */
|
||||||
const LIBSSH2_CRYPT_METHOD **libssh2_crypt_methods(void) {
|
const LIBSSH2_CRYPT_METHOD **libssh2_crypt_methods(void) {
|
||||||
return _libssh2_crypt_methods;
|
return _libssh2_crypt_methods;
|
||||||
}
|
}
|
||||||
|
394
src/hostkey.c
394
src/hostkey.c
@ -54,44 +54,44 @@ static int libssh2_hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION *session, void **
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
libssh2_hostkey_method_ssh_rsa_init(LIBSSH2_SESSION *session,
|
libssh2_hostkey_method_ssh_rsa_init(LIBSSH2_SESSION *session,
|
||||||
const unsigned char *hostkey_data,
|
const unsigned char *hostkey_data,
|
||||||
unsigned long hostkey_data_len,
|
unsigned long hostkey_data_len,
|
||||||
void **abstract)
|
void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_rsa_ctx *rsactx;
|
libssh2_rsa_ctx *rsactx;
|
||||||
const unsigned char *s, *e, *n;
|
const unsigned char *s, *e, *n;
|
||||||
unsigned long len, e_len, n_len;
|
unsigned long len, e_len, n_len;
|
||||||
|
|
||||||
(void)hostkey_data_len;
|
(void)hostkey_data_len;
|
||||||
|
|
||||||
if (*abstract) {
|
if (*abstract) {
|
||||||
libssh2_hostkey_method_ssh_rsa_dtor(session, abstract);
|
libssh2_hostkey_method_ssh_rsa_dtor(session, abstract);
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = hostkey_data;
|
s = hostkey_data;
|
||||||
len = libssh2_ntohu32(s);
|
len = libssh2_ntohu32(s);
|
||||||
s += 4;
|
s += 4;
|
||||||
|
|
||||||
if (len != 7 || strncmp((char *)s, "ssh-rsa", 7) != 0) {
|
if (len != 7 || strncmp((char *)s, "ssh-rsa", 7) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
s += 7;
|
s += 7;
|
||||||
|
|
||||||
e_len = libssh2_ntohu32(s);
|
e_len = libssh2_ntohu32(s);
|
||||||
s += 4;
|
s += 4;
|
||||||
|
|
||||||
e = s; s += e_len;
|
e = s; s += e_len;
|
||||||
n_len = libssh2_ntohu32(s); s += 4;
|
n_len = libssh2_ntohu32(s); s += 4;
|
||||||
n = s; s += n_len;
|
n = s; s += n_len;
|
||||||
|
|
||||||
if (_libssh2_rsa_new (&rsactx, e, e_len, n, n_len, NULL, 0,
|
if (_libssh2_rsa_new (&rsactx, e, e_len, n, n_len, NULL, 0,
|
||||||
NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0))
|
NULL, 0, NULL, 0, NULL, 0, NULL, 0, NULL, 0))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*abstract = rsactx;
|
*abstract = rsactx;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -99,31 +99,31 @@ libssh2_hostkey_method_ssh_rsa_init(LIBSSH2_SESSION *session,
|
|||||||
* Load a Private Key from a PEM file
|
* Load a Private Key from a PEM file
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION *session,
|
static int libssh2_hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION *session,
|
||||||
const char *privkeyfile, unsigned const char *passphrase, void **abstract)
|
const char *privkeyfile, unsigned const char *passphrase, void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_rsa_ctx *rsactx;
|
libssh2_rsa_ctx *rsactx;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (*abstract) {
|
if (*abstract) {
|
||||||
libssh2_hostkey_method_ssh_rsa_dtor(session, abstract);
|
libssh2_hostkey_method_ssh_rsa_dtor(session, abstract);
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fp = fopen(privkeyfile, "r");
|
fp = fopen(privkeyfile, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_rsa_new_private (&rsactx, session, fp, passphrase);
|
ret = _libssh2_rsa_new_private (&rsactx, session, fp, passphrase);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*abstract = rsactx;
|
*abstract = rsactx;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -131,18 +131,18 @@ static int libssh2_hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION *session,
|
|||||||
* Verify signature created by remote
|
* Verify signature created by remote
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION *session,
|
static int libssh2_hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION *session,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
unsigned long sig_len,
|
unsigned long sig_len,
|
||||||
const unsigned char *m,
|
const unsigned char *m,
|
||||||
unsigned long m_len,
|
unsigned long m_len,
|
||||||
void **abstract)
|
void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx*)(*abstract);
|
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx*)(*abstract);
|
||||||
(void)session;
|
(void)session;
|
||||||
|
|
||||||
/* Skip past keyname_len(4) + keyname(7){"ssh-rsa"} + signature_len(4) */
|
/* Skip past keyname_len(4) + keyname(7){"ssh-rsa"} + signature_len(4) */
|
||||||
sig += 15; sig_len -= 15;
|
sig += 15; sig_len -= 15;
|
||||||
return _libssh2_rsa_sha1_verify (rsactx, sig, sig_len, m, m_len);
|
return _libssh2_rsa_sha1_verify (rsactx, sig, sig_len, m, m_len);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -150,27 +150,27 @@ static int libssh2_hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION *session,
|
|||||||
* Construct a signature from an array of vectors
|
* Construct a signature from an array of vectors
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION *session, unsigned char **signature, unsigned long *signature_len,
|
static int libssh2_hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION *session, unsigned char **signature, unsigned long *signature_len,
|
||||||
unsigned long veccount, const struct iovec datavec[], void **abstract)
|
unsigned long veccount, const struct iovec datavec[], void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx*)(*abstract);
|
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx*)(*abstract);
|
||||||
int ret;
|
int ret;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||||
libssh2_sha1_ctx ctx;
|
libssh2_sha1_ctx ctx;
|
||||||
|
|
||||||
libssh2_sha1_init(&ctx);
|
libssh2_sha1_init(&ctx);
|
||||||
for(i = 0; i < veccount; i++) {
|
for(i = 0; i < veccount; i++) {
|
||||||
libssh2_sha1_update(ctx, datavec[i].iov_base, datavec[i].iov_len);
|
libssh2_sha1_update(ctx, datavec[i].iov_base, datavec[i].iov_len);
|
||||||
}
|
}
|
||||||
libssh2_sha1_final(ctx, hash);
|
libssh2_sha1_final(ctx, hash);
|
||||||
|
|
||||||
ret = _libssh2_rsa_sha1_sign(session, rsactx, hash, SHA_DIGEST_LENGTH,
|
ret = _libssh2_rsa_sha1_sign(session, rsactx, hash, SHA_DIGEST_LENGTH,
|
||||||
signature, signature_len);
|
signature, signature_len);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -178,28 +178,28 @@ static int libssh2_hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION *session, unsign
|
|||||||
* Shutdown the hostkey
|
* Shutdown the hostkey
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION *session,
|
static int libssh2_hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION *session,
|
||||||
void **abstract)
|
void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx*)(*abstract);
|
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx*)(*abstract);
|
||||||
(void)session;
|
(void)session;
|
||||||
|
|
||||||
_libssh2_rsa_free(rsactx);
|
_libssh2_rsa_free(rsactx);
|
||||||
|
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_rsa = {
|
static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_rsa = {
|
||||||
"ssh-rsa",
|
"ssh-rsa",
|
||||||
MD5_DIGEST_LENGTH,
|
MD5_DIGEST_LENGTH,
|
||||||
libssh2_hostkey_method_ssh_rsa_init,
|
libssh2_hostkey_method_ssh_rsa_init,
|
||||||
libssh2_hostkey_method_ssh_rsa_initPEM,
|
libssh2_hostkey_method_ssh_rsa_initPEM,
|
||||||
libssh2_hostkey_method_ssh_rsa_sig_verify,
|
libssh2_hostkey_method_ssh_rsa_sig_verify,
|
||||||
libssh2_hostkey_method_ssh_rsa_signv,
|
libssh2_hostkey_method_ssh_rsa_signv,
|
||||||
NULL, /* encrypt */
|
NULL, /* encrypt */
|
||||||
libssh2_hostkey_method_ssh_rsa_dtor,
|
libssh2_hostkey_method_ssh_rsa_dtor,
|
||||||
};
|
};
|
||||||
#endif /* LIBSSH2_RSA */
|
#endif /* LIBSSH2_RSA */
|
||||||
|
|
||||||
@ -215,41 +215,41 @@ static int libssh2_hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION *session, void **
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
libssh2_hostkey_method_ssh_dss_init(LIBSSH2_SESSION *session,
|
libssh2_hostkey_method_ssh_dss_init(LIBSSH2_SESSION *session,
|
||||||
const unsigned char *hostkey_data,
|
const unsigned char *hostkey_data,
|
||||||
unsigned long hostkey_data_len,
|
unsigned long hostkey_data_len,
|
||||||
void **abstract)
|
void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_dsa_ctx *dsactx;
|
libssh2_dsa_ctx *dsactx;
|
||||||
const unsigned char *p, *q, *g, *y, *s;
|
const unsigned char *p, *q, *g, *y, *s;
|
||||||
unsigned long p_len, q_len, g_len, y_len, len;
|
unsigned long p_len, q_len, g_len, y_len, len;
|
||||||
(void)hostkey_data_len;
|
(void)hostkey_data_len;
|
||||||
|
|
||||||
if (*abstract) {
|
if (*abstract) {
|
||||||
libssh2_hostkey_method_ssh_dss_dtor(session, abstract);
|
libssh2_hostkey_method_ssh_dss_dtor(session, abstract);
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = hostkey_data;
|
s = hostkey_data;
|
||||||
len = libssh2_ntohu32(s); s += 4;
|
len = libssh2_ntohu32(s); s += 4;
|
||||||
if (len != 7 || strncmp((char *)s, "ssh-dss", 7) != 0) {
|
if (len != 7 || strncmp((char *)s, "ssh-dss", 7) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
} s += 7;
|
} s += 7;
|
||||||
|
|
||||||
p_len = libssh2_ntohu32(s); s += 4;
|
p_len = libssh2_ntohu32(s); s += 4;
|
||||||
p = s; s += p_len;
|
p = s; s += p_len;
|
||||||
q_len = libssh2_ntohu32(s); s += 4;
|
q_len = libssh2_ntohu32(s); s += 4;
|
||||||
q = s; s += q_len;
|
q = s; s += q_len;
|
||||||
g_len = libssh2_ntohu32(s); s += 4;
|
g_len = libssh2_ntohu32(s); s += 4;
|
||||||
g = s; s += g_len;
|
g = s; s += g_len;
|
||||||
y_len = libssh2_ntohu32(s); s += 4;
|
y_len = libssh2_ntohu32(s); s += 4;
|
||||||
y = s; s += y_len;
|
y = s; s += y_len;
|
||||||
|
|
||||||
_libssh2_dsa_new(&dsactx, p, p_len, q, q_len, g, g_len,
|
_libssh2_dsa_new(&dsactx, p, p_len, q, q_len, g, g_len,
|
||||||
y, y_len, NULL, 0);
|
y, y_len, NULL, 0);
|
||||||
|
|
||||||
*abstract = dsactx;
|
*abstract = dsactx;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -257,33 +257,33 @@ libssh2_hostkey_method_ssh_dss_init(LIBSSH2_SESSION *session,
|
|||||||
* Load a Private Key from a PEM file
|
* Load a Private Key from a PEM file
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION *session,
|
static int libssh2_hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION *session,
|
||||||
const char *privkeyfile,
|
const char *privkeyfile,
|
||||||
unsigned const char *passphrase,
|
unsigned const char *passphrase,
|
||||||
void **abstract)
|
void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_dsa_ctx *dsactx;
|
libssh2_dsa_ctx *dsactx;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (*abstract) {
|
if (*abstract) {
|
||||||
libssh2_hostkey_method_ssh_dss_dtor(session, abstract);
|
libssh2_hostkey_method_ssh_dss_dtor(session, abstract);
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fp = fopen(privkeyfile, "r");
|
fp = fopen(privkeyfile, "r");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_dsa_new_private (&dsactx, session, fp, passphrase);
|
ret = _libssh2_dsa_new_private (&dsactx, session, fp, passphrase);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*abstract = dsactx;
|
*abstract = dsactx;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -291,17 +291,17 @@ static int libssh2_hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION *session,
|
|||||||
* Verify signature created by remote
|
* Verify signature created by remote
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION *session, const unsigned char *sig, unsigned long sig_len,
|
static int libssh2_hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION *session, const unsigned char *sig, unsigned long sig_len,
|
||||||
const unsigned char *m, unsigned long m_len, void **abstract)
|
const unsigned char *m, unsigned long m_len, void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx*)(*abstract);
|
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx*)(*abstract);
|
||||||
|
|
||||||
/* Skip past keyname_len(4) + keyname(7){"ssh-dss"} + signature_len(4) */
|
/* Skip past keyname_len(4) + keyname(7){"ssh-dss"} + signature_len(4) */
|
||||||
sig += 15; sig_len -= 15;
|
sig += 15; sig_len -= 15;
|
||||||
if (sig_len != 40) {
|
if (sig_len != 40) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_PROTO, "Invalid DSS signature length", 0);
|
libssh2_error(session, LIBSSH2_ERROR_PROTO, "Invalid DSS signature length", 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len);
|
return _libssh2_dsa_sha1_verify(dsactx, sig, m, m_len);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -309,35 +309,35 @@ static int libssh2_hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION *session, c
|
|||||||
* Construct a signature from an array of vectors
|
* Construct a signature from an array of vectors
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_dss_signv(LIBSSH2_SESSION *session, unsigned char **signature, unsigned long *signature_len,
|
static int libssh2_hostkey_method_ssh_dss_signv(LIBSSH2_SESSION *session, unsigned char **signature, unsigned long *signature_len,
|
||||||
unsigned long veccount, const struct iovec datavec[], void **abstract)
|
unsigned long veccount, const struct iovec datavec[], void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx*)(*abstract);
|
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx*)(*abstract);
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||||
libssh2_sha1_ctx ctx;
|
libssh2_sha1_ctx ctx;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
*signature = LIBSSH2_ALLOC(session, 2 * SHA_DIGEST_LENGTH);
|
*signature = LIBSSH2_ALLOC(session, 2 * SHA_DIGEST_LENGTH);
|
||||||
if (!*signature) {
|
if (!*signature) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*signature_len = 2 * SHA_DIGEST_LENGTH;
|
*signature_len = 2 * SHA_DIGEST_LENGTH;
|
||||||
memset(*signature, 0, 2 * SHA_DIGEST_LENGTH);
|
memset(*signature, 0, 2 * SHA_DIGEST_LENGTH);
|
||||||
|
|
||||||
libssh2_sha1_init(&ctx);
|
libssh2_sha1_init(&ctx);
|
||||||
for(i = 0; i < veccount; i++) {
|
for(i = 0; i < veccount; i++) {
|
||||||
libssh2_sha1_update(ctx, datavec[i].iov_base, datavec[i].iov_len);
|
libssh2_sha1_update(ctx, datavec[i].iov_base, datavec[i].iov_len);
|
||||||
}
|
}
|
||||||
libssh2_sha1_final(ctx, hash);
|
libssh2_sha1_final(ctx, hash);
|
||||||
|
|
||||||
if (_libssh2_dsa_sha1_sign(dsactx, hash, SHA_DIGEST_LENGTH,
|
if (_libssh2_dsa_sha1_sign(dsactx, hash, SHA_DIGEST_LENGTH,
|
||||||
*signature))
|
*signature))
|
||||||
{
|
{
|
||||||
LIBSSH2_FREE(session, *signature);
|
LIBSSH2_FREE(session, *signature);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -345,44 +345,44 @@ static int libssh2_hostkey_method_ssh_dss_signv(LIBSSH2_SESSION *session, unsign
|
|||||||
* Shutdown the hostkey method
|
* Shutdown the hostkey method
|
||||||
*/
|
*/
|
||||||
static int libssh2_hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION *session,
|
static int libssh2_hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION *session,
|
||||||
void **abstract)
|
void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx*)(*abstract);
|
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx*)(*abstract);
|
||||||
(void)session;
|
(void)session;
|
||||||
|
|
||||||
_libssh2_dsa_free(dsactx);
|
_libssh2_dsa_free(dsactx);
|
||||||
|
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_dss = {
|
static const LIBSSH2_HOSTKEY_METHOD libssh2_hostkey_method_ssh_dss = {
|
||||||
"ssh-dss",
|
"ssh-dss",
|
||||||
MD5_DIGEST_LENGTH,
|
MD5_DIGEST_LENGTH,
|
||||||
libssh2_hostkey_method_ssh_dss_init,
|
libssh2_hostkey_method_ssh_dss_init,
|
||||||
libssh2_hostkey_method_ssh_dss_initPEM,
|
libssh2_hostkey_method_ssh_dss_initPEM,
|
||||||
libssh2_hostkey_method_ssh_dss_sig_verify,
|
libssh2_hostkey_method_ssh_dss_sig_verify,
|
||||||
libssh2_hostkey_method_ssh_dss_signv,
|
libssh2_hostkey_method_ssh_dss_signv,
|
||||||
NULL, /* encrypt */
|
NULL, /* encrypt */
|
||||||
libssh2_hostkey_method_ssh_dss_dtor,
|
libssh2_hostkey_method_ssh_dss_dtor,
|
||||||
};
|
};
|
||||||
#endif /* LIBSSH2_DSA */
|
#endif /* LIBSSH2_DSA */
|
||||||
|
|
||||||
static const LIBSSH2_HOSTKEY_METHOD *_libssh2_hostkey_methods[] = {
|
static const LIBSSH2_HOSTKEY_METHOD *_libssh2_hostkey_methods[] = {
|
||||||
#if LIBSSH2_RSA
|
#if LIBSSH2_RSA
|
||||||
&libssh2_hostkey_method_ssh_rsa,
|
&libssh2_hostkey_method_ssh_rsa,
|
||||||
#endif /* LIBSSH2_RSA */
|
#endif /* LIBSSH2_RSA */
|
||||||
#if LIBSSH2_DSA
|
#if LIBSSH2_DSA
|
||||||
&libssh2_hostkey_method_ssh_dss,
|
&libssh2_hostkey_method_ssh_dss,
|
||||||
#endif /* LIBSSH2_DSA */
|
#endif /* LIBSSH2_DSA */
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const LIBSSH2_HOSTKEY_METHOD **libssh2_hostkey_methods(void)
|
const LIBSSH2_HOSTKEY_METHOD **libssh2_hostkey_methods(void)
|
||||||
{
|
{
|
||||||
return _libssh2_hostkey_methods;
|
return _libssh2_hostkey_methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* {{{ libssh2_hostkey_hash
|
/* {{{ libssh2_hostkey_hash
|
||||||
@ -393,18 +393,18 @@ const LIBSSH2_HOSTKEY_METHOD **libssh2_hostkey_methods(void)
|
|||||||
*/
|
*/
|
||||||
LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hash_type)
|
LIBSSH2_API const char *libssh2_hostkey_hash(LIBSSH2_SESSION *session, int hash_type)
|
||||||
{
|
{
|
||||||
switch (hash_type) {
|
switch (hash_type) {
|
||||||
#if LIBSSH2_MD5
|
#if LIBSSH2_MD5
|
||||||
case LIBSSH2_HOSTKEY_HASH_MD5:
|
case LIBSSH2_HOSTKEY_HASH_MD5:
|
||||||
return (char *)session->server_hostkey_md5;
|
return (char *)session->server_hostkey_md5;
|
||||||
break;
|
break;
|
||||||
#endif /* LIBSSH2_MD5 */
|
#endif /* LIBSSH2_MD5 */
|
||||||
case LIBSSH2_HOSTKEY_HASH_SHA1:
|
case LIBSSH2_HOSTKEY_HASH_SHA1:
|
||||||
return (char *)session->server_hostkey_sha1;
|
return (char *)session->server_hostkey_sha1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
2052
src/kex.c
2052
src/kex.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
798
src/libgcrypt.c
798
src/libgcrypt.c
@ -39,529 +39,529 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
||||||
const unsigned char *edata,
|
const unsigned char *edata,
|
||||||
unsigned long elen,
|
unsigned long elen,
|
||||||
const unsigned char *ndata,
|
const unsigned char *ndata,
|
||||||
unsigned long nlen,
|
unsigned long nlen,
|
||||||
const unsigned char *ddata,
|
const unsigned char *ddata,
|
||||||
unsigned long dlen,
|
unsigned long dlen,
|
||||||
const unsigned char *pdata,
|
const unsigned char *pdata,
|
||||||
unsigned long plen,
|
unsigned long plen,
|
||||||
const unsigned char *qdata,
|
const unsigned char *qdata,
|
||||||
unsigned long qlen,
|
unsigned long qlen,
|
||||||
const unsigned char *e1data,
|
const unsigned char *e1data,
|
||||||
unsigned long e1len,
|
unsigned long e1len,
|
||||||
const unsigned char *e2data,
|
const unsigned char *e2data,
|
||||||
unsigned long e2len,
|
unsigned long e2len,
|
||||||
const unsigned char *coeffdata,
|
const unsigned char *coeffdata,
|
||||||
unsigned long coefflen)
|
unsigned long coefflen)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
(void)e1data;
|
(void)e1data;
|
||||||
(void)e1len;
|
(void)e1len;
|
||||||
(void)e2data;
|
(void)e2data;
|
||||||
(void)e2len;
|
(void)e2len;
|
||||||
|
|
||||||
if (ddata) {
|
if (ddata) {
|
||||||
rc = gcry_sexp_build
|
rc = gcry_sexp_build
|
||||||
(rsa, NULL,
|
(rsa, NULL,
|
||||||
"(private-key(rsa(n%b)(e%b)(d%b)(q%b)(p%b)(u%b)))",
|
"(private-key(rsa(n%b)(e%b)(d%b)(q%b)(p%b)(u%b)))",
|
||||||
nlen, ndata, elen, edata, dlen, ddata, plen, pdata,
|
nlen, ndata, elen, edata, dlen, ddata, plen, pdata,
|
||||||
qlen, qdata, coefflen, coeffdata);
|
qlen, qdata, coefflen, coeffdata);
|
||||||
} else {
|
} else {
|
||||||
rc = gcry_sexp_build (rsa, NULL, "(public-key(rsa(n%b)(e%b)))",
|
rc = gcry_sexp_build (rsa, NULL, "(public-key(rsa(n%b)(e%b)))",
|
||||||
nlen, ndata, elen, edata);
|
nlen, ndata, elen, edata);
|
||||||
}
|
}
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
*rsa = NULL;
|
*rsa = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa,
|
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
unsigned long sig_len,
|
unsigned long sig_len,
|
||||||
const unsigned char *m,
|
const unsigned char *m,
|
||||||
unsigned long m_len)
|
unsigned long m_len)
|
||||||
{
|
{
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||||
gcry_sexp_t s_sig, s_hash;
|
gcry_sexp_t s_sig, s_hash;
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
|
|
||||||
libssh2_sha1(m, m_len, hash);
|
libssh2_sha1(m, m_len, hash);
|
||||||
|
|
||||||
rc = gcry_sexp_build (&s_hash, NULL,
|
rc = gcry_sexp_build (&s_hash, NULL,
|
||||||
"(data (flags pkcs1) (hash sha1 %b))",
|
"(data (flags pkcs1) (hash sha1 %b))",
|
||||||
SHA_DIGEST_LENGTH, hash);
|
SHA_DIGEST_LENGTH, hash);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = gcry_sexp_build (&s_sig, NULL, "(sig-val(rsa(s %b)))",
|
rc = gcry_sexp_build (&s_sig, NULL, "(sig-val(rsa(s %b)))",
|
||||||
sig_len, sig);
|
sig_len, sig);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
gcry_sexp_release (s_hash);
|
gcry_sexp_release (s_hash);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = gcry_pk_verify (s_sig, s_hash, rsa);
|
rc = gcry_pk_verify (s_sig, s_hash, rsa);
|
||||||
gcry_sexp_release (s_sig);
|
gcry_sexp_release (s_sig);
|
||||||
gcry_sexp_release (s_hash);
|
gcry_sexp_release (s_hash);
|
||||||
|
|
||||||
return (rc == 0) ? 0 : -1;
|
return (rc == 0) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
||||||
const unsigned char *p,
|
const unsigned char *p,
|
||||||
unsigned long p_len,
|
unsigned long p_len,
|
||||||
const unsigned char *q,
|
const unsigned char *q,
|
||||||
unsigned long q_len,
|
unsigned long q_len,
|
||||||
const unsigned char *g,
|
const unsigned char *g,
|
||||||
unsigned long g_len,
|
unsigned long g_len,
|
||||||
const unsigned char *y,
|
const unsigned char *y,
|
||||||
unsigned long y_len,
|
unsigned long y_len,
|
||||||
const unsigned char *x,
|
const unsigned char *x,
|
||||||
unsigned long x_len)
|
unsigned long x_len)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (x_len) {
|
if (x_len) {
|
||||||
rc = gcry_sexp_build
|
rc = gcry_sexp_build
|
||||||
(dsactx, NULL,
|
(dsactx, NULL,
|
||||||
"(private-key(dsa(p%b)(q%b)(g%b)(y%b)(x%b)))",
|
"(private-key(dsa(p%b)(q%b)(g%b)(y%b)(x%b)))",
|
||||||
p_len, p, q_len, q, g_len, g, y_len, y, x_len, x);
|
p_len, p, q_len, q, g_len, g, y_len, y, x_len, x);
|
||||||
} else {
|
} else {
|
||||||
rc = gcry_sexp_build (dsactx, NULL,
|
rc = gcry_sexp_build (dsactx, NULL,
|
||||||
"(public-key(dsa(p%b)(q%b)(g%b)(y%b)))",
|
"(public-key(dsa(p%b)(q%b)(g%b)(y%b)))",
|
||||||
p_len, p, q_len, q, g_len, g, y_len, y);
|
p_len, p, q_len, q, g_len, g, y_len, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
*dsactx = NULL;
|
*dsactx = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
||||||
LIBSSH2_SESSION *session,
|
LIBSSH2_SESSION *session,
|
||||||
FILE *fp,
|
FILE *fp,
|
||||||
unsigned const char *passphrase)
|
unsigned const char *passphrase)
|
||||||
{
|
{
|
||||||
char *data, *save_data;
|
char *data, *save_data;
|
||||||
unsigned int datalen;
|
unsigned int datalen;
|
||||||
int ret;
|
int ret;
|
||||||
char *n, *e, *d, *p, *q, *e1, *e2, *coeff;
|
char *n, *e, *d, *p, *q, *e1, *e2, *coeff;
|
||||||
unsigned int nlen, elen, dlen, plen, qlen, e1len, e2len, coefflen;
|
unsigned int nlen, elen, dlen, plen, qlen, e1len, e2len, coefflen;
|
||||||
|
|
||||||
(void)passphrase;
|
(void)passphrase;
|
||||||
|
|
||||||
ret = _libssh2_pem_parse (session,
|
ret = _libssh2_pem_parse (session,
|
||||||
"-----BEGIN RSA PRIVATE KEY-----",
|
"-----BEGIN RSA PRIVATE KEY-----",
|
||||||
"-----END RSA PRIVATE KEY-----",
|
"-----END RSA PRIVATE KEY-----",
|
||||||
fp, &data, &datalen);
|
fp, &data, &datalen);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
save_data = data;
|
save_data = data;
|
||||||
|
|
||||||
if (_libssh2_pem_decode_sequence (&data, &datalen)) {
|
if (_libssh2_pem_decode_sequence (&data, &datalen)) {
|
||||||
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 != 0 || (nlen != 1 && *n != '\0')) {
|
if (ret != 0 || (nlen != 1 && *n != '\0')) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &n, &nlen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &n, &nlen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &e, &elen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &e, &elen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &d, &dlen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &d, &dlen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &p, &plen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &p, &plen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &q, &qlen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &q, &qlen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &e1, &e1len);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &e1, &e1len);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &e2, &e2len);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &e2, &e2len);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &coeff, &coefflen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &coeff, &coefflen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_libssh2_rsa_new (rsa, e, elen, n, nlen, d, dlen, p, plen,
|
if (_libssh2_rsa_new (rsa, e, elen, n, nlen, d, dlen, p, plen,
|
||||||
q, qlen, e1, e1len, e2, e2len,
|
q, qlen, e1, e1len, e2, e2len,
|
||||||
coeff, coefflen)) {
|
coeff, coefflen)) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
LIBSSH2_FREE (session, save_data);
|
LIBSSH2_FREE (session, save_data);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
||||||
LIBSSH2_SESSION *session,
|
LIBSSH2_SESSION *session,
|
||||||
FILE *fp,
|
FILE *fp,
|
||||||
unsigned const char *passphrase)
|
unsigned const char *passphrase)
|
||||||
{
|
{
|
||||||
char *data, *save_data;
|
char *data, *save_data;
|
||||||
unsigned int datalen;
|
unsigned int datalen;
|
||||||
int ret;
|
int ret;
|
||||||
char *p, *q, *g, *y, *x;
|
char *p, *q, *g, *y, *x;
|
||||||
unsigned int plen, qlen, glen, ylen, xlen;
|
unsigned int plen, qlen, glen, ylen, xlen;
|
||||||
|
|
||||||
(void)passphrase;
|
(void)passphrase;
|
||||||
|
|
||||||
ret = _libssh2_pem_parse (session,
|
ret = _libssh2_pem_parse (session,
|
||||||
"-----BEGIN DSA PRIVATE KEY-----",
|
"-----BEGIN DSA PRIVATE KEY-----",
|
||||||
"-----END DSA PRIVATE KEY-----",
|
"-----END DSA PRIVATE KEY-----",
|
||||||
fp, &data, &datalen);
|
fp, &data, &datalen);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
save_data = data;
|
save_data = data;
|
||||||
|
|
||||||
if (_libssh2_pem_decode_sequence (&data, &datalen)) {
|
if (_libssh2_pem_decode_sequence (&data, &datalen)) {
|
||||||
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, &p, &plen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &p, &plen);
|
||||||
if (ret != 0 || (plen != 1 && *p != '\0')) {
|
if (ret != 0 || (plen != 1 && *p != '\0')) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &p, &plen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &p, &plen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &q, &qlen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &q, &qlen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &g, &glen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &g, &glen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &y, &ylen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &y, &ylen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = _libssh2_pem_decode_integer (&data, &datalen, &x, &xlen);
|
ret = _libssh2_pem_decode_integer (&data, &datalen, &x, &xlen);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datalen != 0) {
|
if (datalen != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_libssh2_dsa_new (dsa, p, plen, q, qlen,
|
if (_libssh2_dsa_new (dsa, p, plen, q, qlen,
|
||||||
g, glen, y, ylen, x, xlen)) {
|
g, glen, y, ylen, x, xlen)) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
LIBSSH2_FREE (session, save_data);
|
LIBSSH2_FREE (session, save_data);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
||||||
libssh2_dsa_ctx *rsactx,
|
libssh2_dsa_ctx *rsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len,
|
||||||
unsigned char **signature,
|
unsigned char **signature,
|
||||||
unsigned long *signature_len)
|
unsigned long *signature_len)
|
||||||
{
|
{
|
||||||
gcry_sexp_t sig_sexp;
|
gcry_sexp_t sig_sexp;
|
||||||
gcry_sexp_t data;
|
gcry_sexp_t data;
|
||||||
int rc;
|
int rc;
|
||||||
const char *tmp;
|
const char *tmp;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
if (hash_len != SHA_DIGEST_LENGTH) {
|
if (hash_len != SHA_DIGEST_LENGTH) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gcry_sexp_build (&data, NULL,
|
if (gcry_sexp_build (&data, NULL,
|
||||||
"(data (flags pkcs1) (hash sha1 %b))",
|
"(data (flags pkcs1) (hash sha1 %b))",
|
||||||
hash_len, hash)) {
|
hash_len, hash)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = gcry_pk_sign (&sig_sexp, data, rsactx);
|
rc = gcry_pk_sign (&sig_sexp, data, rsactx);
|
||||||
|
|
||||||
gcry_sexp_release (data);
|
gcry_sexp_release (data);
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
data = gcry_sexp_find_token(sig_sexp, "s", 0);
|
data = gcry_sexp_find_token(sig_sexp, "s", 0);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = gcry_sexp_nth_data(data, 1, &size);
|
tmp = gcry_sexp_nth_data(data, 1, &size);
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp[0] == '\0') {
|
if (tmp[0] == '\0') {
|
||||||
tmp++;
|
tmp++;
|
||||||
size--;
|
size--;
|
||||||
}
|
}
|
||||||
|
|
||||||
*signature = LIBSSH2_ALLOC(session, size);
|
*signature = LIBSSH2_ALLOC(session, size);
|
||||||
memcpy (*signature, tmp, size);
|
memcpy (*signature, tmp, size);
|
||||||
*signature_len = size;
|
*signature_len = size;
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len,
|
||||||
unsigned char *sig)
|
unsigned char *sig)
|
||||||
{
|
{
|
||||||
unsigned char zhash[SHA_DIGEST_LENGTH+1];
|
unsigned char zhash[SHA_DIGEST_LENGTH+1];
|
||||||
gcry_sexp_t sig_sexp;
|
gcry_sexp_t sig_sexp;
|
||||||
gcry_sexp_t data;
|
gcry_sexp_t data;
|
||||||
int ret;
|
int ret;
|
||||||
const char *tmp;
|
const char *tmp;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
if (hash_len != SHA_DIGEST_LENGTH) {
|
if (hash_len != SHA_DIGEST_LENGTH) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy (zhash + 1, hash, hash_len);
|
memcpy (zhash + 1, hash, hash_len);
|
||||||
zhash[0] = 0;
|
zhash[0] = 0;
|
||||||
|
|
||||||
if (gcry_sexp_build (&data, NULL, "(data (value %b))",
|
if (gcry_sexp_build (&data, NULL, "(data (value %b))",
|
||||||
hash_len + 1, zhash)) {
|
hash_len + 1, zhash)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gcry_pk_sign (&sig_sexp, data, dsactx);
|
ret = gcry_pk_sign (&sig_sexp, data, dsactx);
|
||||||
|
|
||||||
gcry_sexp_release (data);
|
gcry_sexp_release (data);
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract R. */
|
/* Extract R. */
|
||||||
|
|
||||||
data = gcry_sexp_find_token(sig_sexp, "r", 0);
|
data = gcry_sexp_find_token(sig_sexp, "r", 0);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = gcry_sexp_nth_data(data, 1, &size);
|
tmp = gcry_sexp_nth_data(data, 1, &size);
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp[0] == '\0') {
|
if (tmp[0] == '\0') {
|
||||||
tmp++;
|
tmp++;
|
||||||
size--;
|
size--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size != 20) {
|
if (size != 20) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy (sig, tmp, 20);
|
memcpy (sig, tmp, 20);
|
||||||
|
|
||||||
gcry_sexp_release (data);
|
gcry_sexp_release (data);
|
||||||
|
|
||||||
/* Extract S. */
|
/* Extract S. */
|
||||||
|
|
||||||
data = gcry_sexp_find_token(sig_sexp, "s",0);
|
data = gcry_sexp_find_token(sig_sexp, "s",0);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = gcry_sexp_nth_data(data, 1, &size);
|
tmp = gcry_sexp_nth_data(data, 1, &size);
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp[0] == '\0') {
|
if (tmp[0] == '\0') {
|
||||||
tmp++;
|
tmp++;
|
||||||
size--;
|
size--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size != 20) {
|
if (size != 20) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy (sig + 20, tmp, 20);
|
memcpy (sig + 20, tmp, 20);
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
if (sig_sexp) {
|
if (sig_sexp) {
|
||||||
gcry_sexp_release (sig_sexp);
|
gcry_sexp_release (sig_sexp);
|
||||||
}
|
}
|
||||||
if (data) {
|
if (data) {
|
||||||
gcry_sexp_release (data);
|
gcry_sexp_release (data);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
const unsigned char *m,
|
const unsigned char *m,
|
||||||
unsigned long m_len)
|
unsigned long m_len)
|
||||||
{
|
{
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH+1];
|
unsigned char hash[SHA_DIGEST_LENGTH+1];
|
||||||
gcry_sexp_t s_sig, s_hash;
|
gcry_sexp_t s_sig, s_hash;
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
|
|
||||||
libssh2_sha1(m, m_len, hash+1);
|
libssh2_sha1(m, m_len, hash+1);
|
||||||
hash[0] = 0;
|
hash[0] = 0;
|
||||||
|
|
||||||
if (gcry_sexp_build (&s_hash, NULL, "(data(flags raw)(value %b))",
|
if (gcry_sexp_build (&s_hash, NULL, "(data(flags raw)(value %b))",
|
||||||
SHA_DIGEST_LENGTH+1, hash)) {
|
SHA_DIGEST_LENGTH+1, hash)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gcry_sexp_build (&s_sig, NULL, "(sig-val(dsa(r %b)(s %b)))",
|
if (gcry_sexp_build (&s_sig, NULL, "(sig-val(dsa(r %b)(s %b)))",
|
||||||
20, sig, 20, sig + 20)) {
|
20, sig, 20, sig + 20)) {
|
||||||
gcry_sexp_release (s_hash);
|
gcry_sexp_release (s_hash);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = gcry_pk_verify (s_sig, s_hash, dsactx);
|
rc = gcry_pk_verify (s_sig, s_hash, dsactx);
|
||||||
gcry_sexp_release (s_sig);
|
gcry_sexp_release (s_sig);
|
||||||
gcry_sexp_release (s_hash);
|
gcry_sexp_release (s_hash);
|
||||||
|
|
||||||
return (rc == 0) ? 0 : -1;
|
return (rc == 0) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
unsigned char *iv,
|
unsigned char *iv,
|
||||||
unsigned char *secret,
|
unsigned char *secret,
|
||||||
int encrypt)
|
int encrypt)
|
||||||
{
|
{
|
||||||
int mode = 0, ret;
|
int mode = 0, ret;
|
||||||
int keylen = gcry_cipher_get_algo_keylen (algo);
|
int keylen = gcry_cipher_get_algo_keylen (algo);
|
||||||
|
|
||||||
(void)encrypt;
|
(void)encrypt;
|
||||||
|
|
||||||
if (algo != GCRY_CIPHER_ARCFOUR) {
|
if (algo != GCRY_CIPHER_ARCFOUR) {
|
||||||
mode = GCRY_CIPHER_MODE_CBC;
|
mode = GCRY_CIPHER_MODE_CBC;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gcry_cipher_open (h, algo, mode, 0);
|
ret = gcry_cipher_open (h, algo, mode, 0);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = gcry_cipher_setkey (*h, secret, keylen);
|
ret = gcry_cipher_setkey (*h, secret, keylen);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
gcry_cipher_close (*h);
|
gcry_cipher_close (*h);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (algo != GCRY_CIPHER_ARCFOUR) {
|
if (algo != GCRY_CIPHER_ARCFOUR) {
|
||||||
int blklen = gcry_cipher_get_algo_blklen (algo);
|
int blklen = gcry_cipher_get_algo_blklen (algo);
|
||||||
ret = gcry_cipher_setiv (*h, iv, blklen);
|
ret = gcry_cipher_setiv (*h, iv, blklen);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
gcry_cipher_close (*h);
|
gcry_cipher_close (*h);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
int encrypt,
|
int encrypt,
|
||||||
unsigned char *block)
|
unsigned char *block)
|
||||||
{
|
{
|
||||||
size_t blklen = gcry_cipher_get_algo_blklen (algo);
|
size_t blklen = gcry_cipher_get_algo_blklen (algo);
|
||||||
int ret;
|
int ret;
|
||||||
if (blklen == 1) {
|
if (blklen == 1) {
|
||||||
/* Hack for arcfour. */
|
/* Hack for arcfour. */
|
||||||
blklen = 8;
|
blklen = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encrypt) {
|
if (encrypt) {
|
||||||
ret = gcry_cipher_encrypt (*ctx, block, blklen,
|
ret = gcry_cipher_encrypt (*ctx, block, blklen,
|
||||||
block, blklen);
|
block, blklen);
|
||||||
} else {
|
} else {
|
||||||
ret = gcry_cipher_decrypt (*ctx, block, blklen,
|
ret = gcry_cipher_decrypt (*ctx, block, blklen,
|
||||||
block, blklen);
|
block, blklen);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
112
src/libgcrypt.h
112
src/libgcrypt.h
@ -53,7 +53,7 @@
|
|||||||
#define MD5_DIGEST_LENGTH 16
|
#define MD5_DIGEST_LENGTH 16
|
||||||
#define SHA_DIGEST_LENGTH 20
|
#define SHA_DIGEST_LENGTH 20
|
||||||
|
|
||||||
#define libssh2_random(buf, len) \
|
#define libssh2_random(buf, len) \
|
||||||
(gcry_randomize ((buf), (len), GCRY_STRONG_RANDOM), 1)
|
(gcry_randomize ((buf), (len), GCRY_STRONG_RANDOM), 1)
|
||||||
|
|
||||||
#define libssh2_sha1_ctx gcry_md_hd_t
|
#define libssh2_sha1_ctx gcry_md_hd_t
|
||||||
@ -86,7 +86,7 @@
|
|||||||
gcry_md_write (ctx, data, datalen)
|
gcry_md_write (ctx, data, datalen)
|
||||||
#define libssh2_hmac_final(ctx, data) \
|
#define libssh2_hmac_final(ctx, data) \
|
||||||
memcpy (data, gcry_md_read (ctx, 0), \
|
memcpy (data, gcry_md_read (ctx, 0), \
|
||||||
gcry_md_get_algo_dlen (gcry_md_get_algo (ctx)))
|
gcry_md_get_algo_dlen (gcry_md_get_algo (ctx)))
|
||||||
#define libssh2_hmac_cleanup(ctx) gcry_md_close (*ctx);
|
#define libssh2_hmac_cleanup(ctx) gcry_md_close (*ctx);
|
||||||
|
|
||||||
#define libssh2_crypto_init() gcry_control (GCRYCTL_DISABLE_SECMEM)
|
#define libssh2_crypto_init() gcry_control (GCRYCTL_DISABLE_SECMEM)
|
||||||
@ -94,65 +94,65 @@
|
|||||||
#define libssh2_rsa_ctx struct gcry_sexp
|
#define libssh2_rsa_ctx struct gcry_sexp
|
||||||
|
|
||||||
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
||||||
const unsigned char *edata,
|
const unsigned char *edata,
|
||||||
unsigned long elen,
|
unsigned long elen,
|
||||||
const unsigned char *ndata,
|
const unsigned char *ndata,
|
||||||
unsigned long nlen,
|
unsigned long nlen,
|
||||||
const unsigned char *ddata,
|
const unsigned char *ddata,
|
||||||
unsigned long dlen,
|
unsigned long dlen,
|
||||||
const unsigned char *pdata,
|
const unsigned char *pdata,
|
||||||
unsigned long plen,
|
unsigned long plen,
|
||||||
const unsigned char *qdata,
|
const unsigned char *qdata,
|
||||||
unsigned long qlen,
|
unsigned long qlen,
|
||||||
const unsigned char *e1data,
|
const unsigned char *e1data,
|
||||||
unsigned long e1len,
|
unsigned long e1len,
|
||||||
const unsigned char *e2data,
|
const unsigned char *e2data,
|
||||||
unsigned long e2len,
|
unsigned long e2len,
|
||||||
const unsigned char *coeffdata,
|
const unsigned char *coeffdata,
|
||||||
unsigned long coefflen);
|
unsigned long coefflen);
|
||||||
int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
||||||
LIBSSH2_SESSION *session,
|
LIBSSH2_SESSION *session,
|
||||||
FILE *fp,
|
FILE *fp,
|
||||||
unsigned const char *passphrase);
|
unsigned const char *passphrase);
|
||||||
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa,
|
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
unsigned long sig_len,
|
unsigned long sig_len,
|
||||||
const unsigned char *m,
|
const unsigned char *m,
|
||||||
unsigned long m_len);
|
unsigned long m_len);
|
||||||
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
||||||
libssh2_rsa_ctx *rsactx,
|
libssh2_rsa_ctx *rsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len,
|
||||||
unsigned char **signature,
|
unsigned char **signature,
|
||||||
unsigned long *signature_len);
|
unsigned long *signature_len);
|
||||||
|
|
||||||
#define _libssh2_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_ctx struct gcry_sexp
|
||||||
|
|
||||||
int _libssh2_dsa_new(libssh2_dsa_ctx **dsa,
|
int _libssh2_dsa_new(libssh2_dsa_ctx **dsa,
|
||||||
const unsigned char *pdata,
|
const unsigned char *pdata,
|
||||||
unsigned long plen,
|
unsigned long plen,
|
||||||
const unsigned char *qdata,
|
const unsigned char *qdata,
|
||||||
unsigned long qlen,
|
unsigned long qlen,
|
||||||
const unsigned char *gdata,
|
const unsigned char *gdata,
|
||||||
unsigned long glen,
|
unsigned long glen,
|
||||||
const unsigned char *ydata,
|
const unsigned char *ydata,
|
||||||
unsigned long ylen,
|
unsigned long ylen,
|
||||||
const unsigned char *x,
|
const unsigned char *x,
|
||||||
unsigned long x_len);
|
unsigned long x_len);
|
||||||
int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
||||||
LIBSSH2_SESSION *session,
|
LIBSSH2_SESSION *session,
|
||||||
FILE *fp,
|
FILE *fp,
|
||||||
unsigned const char *passphrase);
|
unsigned const char *passphrase);
|
||||||
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsa,
|
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsa,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
const unsigned char *m,
|
const unsigned char *m,
|
||||||
unsigned long m_len);
|
unsigned long m_len);
|
||||||
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len,
|
||||||
unsigned char *sig);
|
unsigned char *sig);
|
||||||
|
|
||||||
#define _libssh2_dsa_free(dsactx) gcry_sexp_release (dsactx)
|
#define _libssh2_dsa_free(dsactx) gcry_sexp_release (dsactx)
|
||||||
|
|
||||||
@ -168,15 +168,15 @@ int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
|||||||
#define _libssh2_cipher_3des GCRY_CIPHER_3DES
|
#define _libssh2_cipher_3des GCRY_CIPHER_3DES
|
||||||
|
|
||||||
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
unsigned char *iv,
|
unsigned char *iv,
|
||||||
unsigned char *secret,
|
unsigned char *secret,
|
||||||
int encrypt);
|
int encrypt);
|
||||||
|
|
||||||
int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
int encrypt,
|
int encrypt,
|
||||||
unsigned char *block);
|
unsigned char *block);
|
||||||
|
|
||||||
#define _libssh2_cipher_dtor(ctx) gcry_cipher_close(*(ctx))
|
#define _libssh2_cipher_dtor(ctx) gcry_cipher_close(*(ctx))
|
||||||
|
|
||||||
|
@ -90,325 +90,325 @@
|
|||||||
*/
|
*/
|
||||||
#define MAX_SSH_PACKET_LEN 35000
|
#define MAX_SSH_PACKET_LEN 35000
|
||||||
|
|
||||||
#define LIBSSH2_ALLOC(session, count) session->alloc((count), &(session)->abstract)
|
#define LIBSSH2_ALLOC(session, count) session->alloc((count), &(session)->abstract)
|
||||||
#define LIBSSH2_REALLOC(session, ptr, count) ((ptr) ? session->realloc((ptr), (count), &(session)->abstract) : session->alloc((count), &(session)->abstract))
|
#define LIBSSH2_REALLOC(session, ptr, count) ((ptr) ? session->realloc((ptr), (count), &(session)->abstract) : session->alloc((count), &(session)->abstract))
|
||||||
#define LIBSSH2_FREE(session, ptr) session->free((ptr), &(session)->abstract)
|
#define LIBSSH2_FREE(session, ptr) session->free((ptr), &(session)->abstract)
|
||||||
|
|
||||||
#define LIBSSH2_IGNORE(session, data, datalen) session->ssh_msg_ignore((session), (data), (datalen), &(session)->abstract)
|
#define LIBSSH2_IGNORE(session, data, datalen) session->ssh_msg_ignore((session), (data), (datalen), &(session)->abstract)
|
||||||
#define LIBSSH2_DEBUG(session, always_display, message, message_len, language, language_len) \
|
#define LIBSSH2_DEBUG(session, always_display, message, message_len, language, language_len) \
|
||||||
session->ssh_msg_disconnect((session), (always_display), (message), (message_len), (language), (language_len), &(session)->abstract)
|
session->ssh_msg_disconnect((session), (always_display), (message), (message_len), (language), (language_len), &(session)->abstract)
|
||||||
#define LIBSSH2_DISCONNECT(session, reason, message, message_len, language, language_len) \
|
#define LIBSSH2_DISCONNECT(session, reason, message, message_len, language, language_len) \
|
||||||
session->ssh_msg_disconnect((session), (reason), (message), (message_len), (language), (language_len), &(session)->abstract)
|
session->ssh_msg_disconnect((session), (reason), (message), (message_len), (language), (language_len), &(session)->abstract)
|
||||||
|
|
||||||
#define LIBSSH2_MACERROR(session, data, datalen) session->macerror((session), (data), (datalen), &(session)->abstract)
|
#define LIBSSH2_MACERROR(session, data, datalen) session->macerror((session), (data), (datalen), &(session)->abstract)
|
||||||
#define LIBSSH2_X11_OPEN(channel, shost, sport) channel->session->x11(((channel)->session), (channel), (shost), (sport), (&(channel)->session->abstract))
|
#define LIBSSH2_X11_OPEN(channel, shost, sport) channel->session->x11(((channel)->session), (channel), (shost), (sport), (&(channel)->session->abstract))
|
||||||
|
|
||||||
#define LIBSSH2_CHANNEL_CLOSE(session, channel) channel->close_cb((session), &(session)->abstract, (channel), &(channel)->abstract)
|
#define LIBSSH2_CHANNEL_CLOSE(session, channel) channel->close_cb((session), &(session)->abstract, (channel), &(channel)->abstract)
|
||||||
|
|
||||||
typedef struct _LIBSSH2_KEX_METHOD LIBSSH2_KEX_METHOD;
|
typedef struct _LIBSSH2_KEX_METHOD LIBSSH2_KEX_METHOD;
|
||||||
typedef struct _LIBSSH2_HOSTKEY_METHOD LIBSSH2_HOSTKEY_METHOD;
|
typedef struct _LIBSSH2_HOSTKEY_METHOD LIBSSH2_HOSTKEY_METHOD;
|
||||||
typedef struct _LIBSSH2_MAC_METHOD LIBSSH2_MAC_METHOD;
|
typedef struct _LIBSSH2_MAC_METHOD LIBSSH2_MAC_METHOD;
|
||||||
typedef struct _LIBSSH2_CRYPT_METHOD LIBSSH2_CRYPT_METHOD;
|
typedef struct _LIBSSH2_CRYPT_METHOD LIBSSH2_CRYPT_METHOD;
|
||||||
typedef struct _LIBSSH2_COMP_METHOD LIBSSH2_COMP_METHOD;
|
typedef struct _LIBSSH2_COMP_METHOD LIBSSH2_COMP_METHOD;
|
||||||
|
|
||||||
typedef struct _LIBSSH2_PACKET LIBSSH2_PACKET;
|
typedef struct _LIBSSH2_PACKET LIBSSH2_PACKET;
|
||||||
typedef struct _LIBSSH2_PACKET_BRIGADE LIBSSH2_PACKET_BRIGADE;
|
typedef struct _LIBSSH2_PACKET_BRIGADE LIBSSH2_PACKET_BRIGADE;
|
||||||
typedef struct _LIBSSH2_CHANNEL_BRIGADE LIBSSH2_CHANNEL_BRIGADE;
|
typedef struct _LIBSSH2_CHANNEL_BRIGADE LIBSSH2_CHANNEL_BRIGADE;
|
||||||
|
|
||||||
struct _LIBSSH2_PACKET {
|
struct _LIBSSH2_PACKET {
|
||||||
unsigned char type;
|
unsigned char type;
|
||||||
|
|
||||||
/* Unencrypted Payload (no type byte, no padding, just the facts ma'am) */
|
/* Unencrypted Payload (no type byte, no padding, just the facts ma'am) */
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
unsigned long data_len;
|
unsigned long data_len;
|
||||||
|
|
||||||
/* Where to start reading data from,
|
/* Where to start reading data from,
|
||||||
* used for channel data that's been partially consumed */
|
* used for channel data that's been partially consumed */
|
||||||
unsigned long data_head;
|
unsigned long data_head;
|
||||||
|
|
||||||
/* Can the message be confirmed? */
|
/* Can the message be confirmed? */
|
||||||
int mac;
|
int mac;
|
||||||
|
|
||||||
LIBSSH2_PACKET_BRIGADE *brigade;
|
LIBSSH2_PACKET_BRIGADE *brigade;
|
||||||
|
|
||||||
LIBSSH2_PACKET *next, *prev;
|
LIBSSH2_PACKET *next, *prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_PACKET_BRIGADE {
|
struct _LIBSSH2_PACKET_BRIGADE {
|
||||||
LIBSSH2_PACKET *head, *tail;
|
LIBSSH2_PACKET *head, *tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _libssh2_channel_data {
|
typedef struct _libssh2_channel_data {
|
||||||
/* Identifier */
|
/* Identifier */
|
||||||
unsigned long id;
|
unsigned long id;
|
||||||
|
|
||||||
/* Limits and restrictions */
|
/* Limits and restrictions */
|
||||||
unsigned long window_size_initial, window_size, packet_size;
|
unsigned long window_size_initial, window_size, packet_size;
|
||||||
|
|
||||||
/* Set to 1 when CHANNEL_CLOSE / CHANNEL_EOF sent/received */
|
/* Set to 1 when CHANNEL_CLOSE / CHANNEL_EOF sent/received */
|
||||||
char close, eof, extended_data_ignore_mode;
|
char close, eof, extended_data_ignore_mode;
|
||||||
} libssh2_channel_data;
|
} libssh2_channel_data;
|
||||||
|
|
||||||
struct _LIBSSH2_CHANNEL {
|
struct _LIBSSH2_CHANNEL {
|
||||||
unsigned char *channel_type;
|
unsigned char *channel_type;
|
||||||
unsigned channel_type_len;
|
unsigned channel_type_len;
|
||||||
|
|
||||||
int blocking;
|
int blocking;
|
||||||
|
|
||||||
/* channel's program exit status */
|
/* channel's program exit status */
|
||||||
int exit_status;
|
int exit_status;
|
||||||
|
|
||||||
libssh2_channel_data local, remote;
|
libssh2_channel_data local, remote;
|
||||||
unsigned long adjust_queue; /* Amount of bytes to be refunded to receive window (but not yet sent) */
|
unsigned long adjust_queue; /* Amount of bytes to be refunded to receive window (but not yet sent) */
|
||||||
|
|
||||||
LIBSSH2_SESSION *session;
|
LIBSSH2_SESSION *session;
|
||||||
|
|
||||||
LIBSSH2_CHANNEL *next, *prev;
|
LIBSSH2_CHANNEL *next, *prev;
|
||||||
|
|
||||||
void *abstract;
|
void *abstract;
|
||||||
LIBSSH2_CHANNEL_CLOSE_FUNC((*close_cb));
|
LIBSSH2_CHANNEL_CLOSE_FUNC((*close_cb));
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_CHANNEL_BRIGADE {
|
struct _LIBSSH2_CHANNEL_BRIGADE {
|
||||||
LIBSSH2_CHANNEL *head, *tail;
|
LIBSSH2_CHANNEL *head, *tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_LISTENER {
|
struct _LIBSSH2_LISTENER {
|
||||||
LIBSSH2_SESSION *session;
|
LIBSSH2_SESSION *session;
|
||||||
|
|
||||||
char *host;
|
char *host;
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
LIBSSH2_CHANNEL *queue;
|
LIBSSH2_CHANNEL *queue;
|
||||||
int queue_size;
|
int queue_size;
|
||||||
int queue_maxsize;
|
int queue_maxsize;
|
||||||
|
|
||||||
LIBSSH2_LISTENER *prev, *next;
|
LIBSSH2_LISTENER *prev, *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _libssh2_endpoint_data {
|
typedef struct _libssh2_endpoint_data {
|
||||||
unsigned char *banner;
|
unsigned char *banner;
|
||||||
|
|
||||||
unsigned char *kexinit;
|
unsigned char *kexinit;
|
||||||
unsigned long kexinit_len;
|
unsigned long kexinit_len;
|
||||||
|
|
||||||
const LIBSSH2_CRYPT_METHOD *crypt;
|
const LIBSSH2_CRYPT_METHOD *crypt;
|
||||||
void *crypt_abstract;
|
void *crypt_abstract;
|
||||||
|
|
||||||
const LIBSSH2_MAC_METHOD *mac;
|
const LIBSSH2_MAC_METHOD *mac;
|
||||||
unsigned long seqno;
|
unsigned long seqno;
|
||||||
void *mac_abstract;
|
void *mac_abstract;
|
||||||
|
|
||||||
const LIBSSH2_COMP_METHOD *comp;
|
const LIBSSH2_COMP_METHOD *comp;
|
||||||
void *comp_abstract;
|
void *comp_abstract;
|
||||||
|
|
||||||
/* Method Preferences -- NULL yields "load order" */
|
/* Method Preferences -- NULL yields "load order" */
|
||||||
char *crypt_prefs;
|
char *crypt_prefs;
|
||||||
char *mac_prefs;
|
char *mac_prefs;
|
||||||
char *comp_prefs;
|
char *comp_prefs;
|
||||||
char *lang_prefs;
|
char *lang_prefs;
|
||||||
} libssh2_endpoint_data;
|
} libssh2_endpoint_data;
|
||||||
|
|
||||||
#define PACKETBUFSIZE 4096
|
#define PACKETBUFSIZE 4096
|
||||||
|
|
||||||
struct transportpacket {
|
struct transportpacket {
|
||||||
/* ------------- for incoming data --------------- */
|
/* ------------- for incoming data --------------- */
|
||||||
unsigned char buf[PACKETBUFSIZE];
|
unsigned char buf[PACKETBUFSIZE];
|
||||||
unsigned char init[5]; /* first 5 bytes of the incoming data stream,
|
unsigned char init[5]; /* first 5 bytes of the incoming data stream,
|
||||||
still encrypted */
|
still encrypted */
|
||||||
int writeidx; /* at what array index we do the next write into
|
int writeidx; /* at what array index we do the next write into
|
||||||
the buffer */
|
the buffer */
|
||||||
int readidx; /* at what array index we do the next read from
|
int readidx; /* at what array index we do the next read from
|
||||||
the buffer */
|
the buffer */
|
||||||
int packet_length; /* the most recent packet_length as read from the
|
int packet_length; /* the most recent packet_length as read from the
|
||||||
network data */
|
network data */
|
||||||
int padding_length; /* the most recent padding_length as read from the
|
int padding_length; /* the most recent padding_length as read from the
|
||||||
network data */
|
network data */
|
||||||
int data_num; /* How much of the total package that has been read
|
int data_num; /* How much of the total package that has been read
|
||||||
so far. */
|
so far. */
|
||||||
int total_num; /* How much a total package is supposed to be, in
|
int total_num; /* How much a total package is supposed to be, in
|
||||||
number of bytes. A full package is
|
number of bytes. A full package is
|
||||||
packet_length + padding_length + 4 +
|
packet_length + padding_length + 4 +
|
||||||
mac_length. */
|
mac_length. */
|
||||||
unsigned char *payload; /* this is a pointer to a LIBSSH2_ALLOC()
|
unsigned char *payload; /* this is a pointer to a LIBSSH2_ALLOC()
|
||||||
area to which we write decrypted data */
|
area to which we write decrypted data */
|
||||||
unsigned char *wptr; /* write pointer into the payload to where we
|
unsigned char *wptr; /* write pointer into the payload to where we
|
||||||
are currently writing decrypted data */
|
are currently writing decrypted data */
|
||||||
|
|
||||||
/* ------------- for outgoing data --------------- */
|
/* ------------- for outgoing data --------------- */
|
||||||
unsigned char *outbuf; /* pointer to a LIBSSH2_ALLOC() area for the
|
unsigned char *outbuf; /* pointer to a LIBSSH2_ALLOC() area for the
|
||||||
outgoing data */
|
outgoing data */
|
||||||
int ototal_num; /* size of outbuf in number of bytes */
|
int ototal_num; /* size of outbuf in number of bytes */
|
||||||
unsigned char *odata; /* original pointer to the data we stored in
|
unsigned char *odata; /* original pointer to the data we stored in
|
||||||
outbuf */
|
outbuf */
|
||||||
unsigned long olen; /* original size of the data we stored in
|
unsigned long olen; /* original size of the data we stored in
|
||||||
outbuf */
|
outbuf */
|
||||||
unsigned long osent; /* number of bytes already sent */
|
unsigned long osent; /* number of bytes already sent */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_SESSION {
|
struct _LIBSSH2_SESSION {
|
||||||
/* Memory management callbacks */
|
/* Memory management callbacks */
|
||||||
void *abstract;
|
void *abstract;
|
||||||
LIBSSH2_ALLOC_FUNC((*alloc));
|
LIBSSH2_ALLOC_FUNC((*alloc));
|
||||||
LIBSSH2_REALLOC_FUNC((*realloc));
|
LIBSSH2_REALLOC_FUNC((*realloc));
|
||||||
LIBSSH2_FREE_FUNC((*free));
|
LIBSSH2_FREE_FUNC((*free));
|
||||||
|
|
||||||
/* Other callbacks */
|
/* Other callbacks */
|
||||||
LIBSSH2_IGNORE_FUNC((*ssh_msg_ignore));
|
LIBSSH2_IGNORE_FUNC((*ssh_msg_ignore));
|
||||||
LIBSSH2_DEBUG_FUNC((*ssh_msg_debug));
|
LIBSSH2_DEBUG_FUNC((*ssh_msg_debug));
|
||||||
LIBSSH2_DISCONNECT_FUNC((*ssh_msg_disconnect));
|
LIBSSH2_DISCONNECT_FUNC((*ssh_msg_disconnect));
|
||||||
LIBSSH2_MACERROR_FUNC((*macerror));
|
LIBSSH2_MACERROR_FUNC((*macerror));
|
||||||
LIBSSH2_X11_OPEN_FUNC((*x11));
|
LIBSSH2_X11_OPEN_FUNC((*x11));
|
||||||
|
|
||||||
/* Method preferences -- NULL yields "load order" */
|
/* Method preferences -- NULL yields "load order" */
|
||||||
char *kex_prefs;
|
char *kex_prefs;
|
||||||
char *hostkey_prefs;
|
char *hostkey_prefs;
|
||||||
|
|
||||||
int state;
|
int state;
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
/* Agreed Key Exchange Method */
|
/* Agreed Key Exchange Method */
|
||||||
const LIBSSH2_KEX_METHOD *kex;
|
const LIBSSH2_KEX_METHOD *kex;
|
||||||
int burn_optimistic_kexinit:1;
|
int burn_optimistic_kexinit:1;
|
||||||
|
|
||||||
unsigned char *session_id;
|
unsigned char *session_id;
|
||||||
unsigned long session_id_len;
|
unsigned long session_id_len;
|
||||||
|
|
||||||
/* Server's public key */
|
/* Server's public key */
|
||||||
const LIBSSH2_HOSTKEY_METHOD *hostkey;
|
const LIBSSH2_HOSTKEY_METHOD *hostkey;
|
||||||
void *server_hostkey_abstract;
|
void *server_hostkey_abstract;
|
||||||
|
|
||||||
/* Either set with libssh2_session_hostkey() (for server mode)
|
/* Either set with libssh2_session_hostkey() (for server mode)
|
||||||
* Or read from server in (eg) KEXDH_INIT (for client mode)
|
* Or read from server in (eg) KEXDH_INIT (for client mode)
|
||||||
*/
|
*/
|
||||||
unsigned char *server_hostkey;
|
unsigned char *server_hostkey;
|
||||||
unsigned long server_hostkey_len;
|
unsigned long server_hostkey_len;
|
||||||
#if LIBSSH2_MD5
|
#if LIBSSH2_MD5
|
||||||
unsigned char server_hostkey_md5[MD5_DIGEST_LENGTH];
|
unsigned char server_hostkey_md5[MD5_DIGEST_LENGTH];
|
||||||
#endif /* ! LIBSSH2_MD5 */
|
#endif /* ! LIBSSH2_MD5 */
|
||||||
unsigned char server_hostkey_sha1[SHA_DIGEST_LENGTH];
|
unsigned char server_hostkey_sha1[SHA_DIGEST_LENGTH];
|
||||||
|
|
||||||
/* (remote as source of data -- packet_read ) */
|
/* (remote as source of data -- packet_read ) */
|
||||||
libssh2_endpoint_data remote;
|
libssh2_endpoint_data remote;
|
||||||
|
|
||||||
/* (local as source of data -- packet_write ) */
|
/* (local as source of data -- packet_write ) */
|
||||||
libssh2_endpoint_data local;
|
libssh2_endpoint_data local;
|
||||||
|
|
||||||
/* Inbound Data buffer -- Sometimes the packet that comes in isn't the packet we're ready for */
|
/* Inbound Data buffer -- Sometimes the packet that comes in isn't the packet we're ready for */
|
||||||
LIBSSH2_PACKET_BRIGADE packets;
|
LIBSSH2_PACKET_BRIGADE packets;
|
||||||
|
|
||||||
/* Active connection channels */
|
/* Active connection channels */
|
||||||
LIBSSH2_CHANNEL_BRIGADE channels;
|
LIBSSH2_CHANNEL_BRIGADE channels;
|
||||||
unsigned long next_channel;
|
unsigned long next_channel;
|
||||||
|
|
||||||
LIBSSH2_LISTENER *listeners;
|
LIBSSH2_LISTENER *listeners;
|
||||||
|
|
||||||
/* Actual I/O socket */
|
/* Actual I/O socket */
|
||||||
int socket_fd;
|
int socket_fd;
|
||||||
int socket_block;
|
int socket_block;
|
||||||
int socket_state;
|
int socket_state;
|
||||||
|
|
||||||
/* Error tracking */
|
/* Error tracking */
|
||||||
char *err_msg;
|
char *err_msg;
|
||||||
unsigned long err_msglen;
|
unsigned long err_msglen;
|
||||||
int err_should_free;
|
int err_should_free;
|
||||||
int err_code;
|
int err_code;
|
||||||
|
|
||||||
/* struct members for packet-level reading */
|
/* struct members for packet-level reading */
|
||||||
struct transportpacket packet;
|
struct transportpacket packet;
|
||||||
#ifdef LIBSSH2DEBUG
|
#ifdef LIBSSH2DEBUG
|
||||||
int showmask; /* what debug/trace messages to display */
|
int showmask; /* what debug/trace messages to display */
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* session.state bits */
|
/* session.state bits */
|
||||||
#define LIBSSH2_STATE_EXCHANGING_KEYS 0x00000001
|
#define LIBSSH2_STATE_EXCHANGING_KEYS 0x00000001
|
||||||
#define LIBSSH2_STATE_NEWKEYS 0x00000002
|
#define LIBSSH2_STATE_NEWKEYS 0x00000002
|
||||||
#define LIBSSH2_STATE_AUTHENTICATED 0x00000004
|
#define LIBSSH2_STATE_AUTHENTICATED 0x00000004
|
||||||
|
|
||||||
/* session.flag helpers */
|
/* session.flag helpers */
|
||||||
#ifdef MSG_NOSIGNAL
|
#ifdef MSG_NOSIGNAL
|
||||||
#define LIBSSH2_SOCKET_SEND_FLAGS(session) (((session)->flags & LIBSSH2_FLAG_SIGPIPE) ? 0 : MSG_NOSIGNAL)
|
#define LIBSSH2_SOCKET_SEND_FLAGS(session) (((session)->flags & LIBSSH2_FLAG_SIGPIPE) ? 0 : MSG_NOSIGNAL)
|
||||||
#define LIBSSH2_SOCKET_RECV_FLAGS(session) (((session)->flags & LIBSSH2_FLAG_SIGPIPE) ? 0 : MSG_NOSIGNAL)
|
#define LIBSSH2_SOCKET_RECV_FLAGS(session) (((session)->flags & LIBSSH2_FLAG_SIGPIPE) ? 0 : MSG_NOSIGNAL)
|
||||||
#else
|
#else
|
||||||
/* If MSG_NOSIGNAL isn't defined we're SOL on blocking SIGPIPE */
|
/* If MSG_NOSIGNAL isn't defined we're SOL on blocking SIGPIPE */
|
||||||
#define LIBSSH2_SOCKET_SEND_FLAGS(session) 0
|
#define LIBSSH2_SOCKET_SEND_FLAGS(session) 0
|
||||||
#define LIBSSH2_SOCKET_RECV_FLAGS(session) 0
|
#define LIBSSH2_SOCKET_RECV_FLAGS(session) 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* libssh2 extensible ssh api, ultimately I'd like to allow loading additional methods via .so/.dll */
|
/* libssh2 extensible ssh api, ultimately I'd like to allow loading additional methods via .so/.dll */
|
||||||
|
|
||||||
struct _LIBSSH2_KEX_METHOD {
|
struct _LIBSSH2_KEX_METHOD {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
/* Key exchange, populates session->* and returns 0 on success, non-0 on error */
|
/* Key exchange, populates session->* and returns 0 on success, non-0 on error */
|
||||||
int (*exchange_keys)(LIBSSH2_SESSION *session);
|
int (*exchange_keys)(LIBSSH2_SESSION *session);
|
||||||
|
|
||||||
long flags;
|
long flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_HOSTKEY_METHOD {
|
struct _LIBSSH2_HOSTKEY_METHOD {
|
||||||
const char *name;
|
const char *name;
|
||||||
unsigned long hash_len;
|
unsigned long hash_len;
|
||||||
|
|
||||||
int (*init)(LIBSSH2_SESSION *session, const unsigned char *hostkey_data, unsigned long hostkey_data_len, void **abstract);
|
int (*init)(LIBSSH2_SESSION *session, const unsigned char *hostkey_data, unsigned long hostkey_data_len, void **abstract);
|
||||||
int (*initPEM)(LIBSSH2_SESSION *session, const char *privkeyfile, unsigned const char *passphrase, void **abstract);
|
int (*initPEM)(LIBSSH2_SESSION *session, const char *privkeyfile, unsigned const char *passphrase, void **abstract);
|
||||||
int (*sig_verify)(LIBSSH2_SESSION *session, const unsigned char *sig, unsigned long sig_len, const unsigned char *m, unsigned long m_len, void **abstract);
|
int (*sig_verify)(LIBSSH2_SESSION *session, const unsigned char *sig, unsigned long sig_len, const unsigned char *m, unsigned long m_len, void **abstract);
|
||||||
int (*signv)(LIBSSH2_SESSION *session, unsigned char **signature, unsigned long *signature_len, unsigned long veccount, const struct iovec datavec[], void **abstract);
|
int (*signv)(LIBSSH2_SESSION *session, unsigned char **signature, unsigned long *signature_len, unsigned long veccount, const struct iovec datavec[], void **abstract);
|
||||||
int (*encrypt)(LIBSSH2_SESSION *session, unsigned char **dst, unsigned long *dst_len, const unsigned char *src, unsigned long src_len, void **abstract);
|
int (*encrypt)(LIBSSH2_SESSION *session, unsigned char **dst, unsigned long *dst_len, const unsigned char *src, unsigned long src_len, void **abstract);
|
||||||
int (*dtor)(LIBSSH2_SESSION *session, void **abstract);
|
int (*dtor)(LIBSSH2_SESSION *session, void **abstract);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_CRYPT_METHOD {
|
struct _LIBSSH2_CRYPT_METHOD {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
int blocksize;
|
int blocksize;
|
||||||
|
|
||||||
/* iv and key sizes (-1 for variable length) */
|
/* iv and key sizes (-1 for variable length) */
|
||||||
int iv_len;
|
int iv_len;
|
||||||
int secret_len;
|
int secret_len;
|
||||||
|
|
||||||
long flags;
|
long flags;
|
||||||
|
|
||||||
int (*init)(LIBSSH2_SESSION *session, const LIBSSH2_CRYPT_METHOD *method, unsigned char *iv, int *free_iv, unsigned char *secret, int *free_secret, int encrypt, void **abstract);
|
int (*init)(LIBSSH2_SESSION *session, const LIBSSH2_CRYPT_METHOD *method, unsigned char *iv, int *free_iv, unsigned char *secret, int *free_secret, int encrypt, void **abstract);
|
||||||
int (*crypt)(LIBSSH2_SESSION *session, unsigned char *block, void **abstract);
|
int (*crypt)(LIBSSH2_SESSION *session, unsigned char *block, void **abstract);
|
||||||
int (*dtor)(LIBSSH2_SESSION *session, void **abstract);
|
int (*dtor)(LIBSSH2_SESSION *session, void **abstract);
|
||||||
|
|
||||||
_libssh2_cipher_type(algo);
|
_libssh2_cipher_type(algo);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_COMP_METHOD {
|
struct _LIBSSH2_COMP_METHOD {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
int (*init)(LIBSSH2_SESSION *session, int compress, void **abstract);
|
int (*init)(LIBSSH2_SESSION *session, int compress, void **abstract);
|
||||||
int (*comp)(LIBSSH2_SESSION *session, int compress, unsigned char **dest, unsigned long *dest_len, unsigned long payload_limit, int *free_dest,
|
int (*comp)(LIBSSH2_SESSION *session, int compress, unsigned char **dest, unsigned long *dest_len, unsigned long payload_limit, int *free_dest,
|
||||||
const unsigned char *src, unsigned long src_len, void **abstract);
|
const unsigned char *src, unsigned long src_len, void **abstract);
|
||||||
int (*dtor)(LIBSSH2_SESSION *session, int compress, void **abstract);
|
int (*dtor)(LIBSSH2_SESSION *session, int compress, void **abstract);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _LIBSSH2_MAC_METHOD {
|
struct _LIBSSH2_MAC_METHOD {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
/* The length of a given MAC packet */
|
/* The length of a given MAC packet */
|
||||||
int mac_len;
|
int mac_len;
|
||||||
|
|
||||||
/* integrity key length */
|
/* integrity key length */
|
||||||
int key_len;
|
int key_len;
|
||||||
|
|
||||||
/* Message Authentication Code Hashing algo */
|
/* Message Authentication Code Hashing algo */
|
||||||
int (*init)(LIBSSH2_SESSION *session, unsigned char *key, int *free_key, void **abstract);
|
int (*init)(LIBSSH2_SESSION *session, unsigned char *key, int *free_key, void **abstract);
|
||||||
int (*hash)(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno, const unsigned char *packet, unsigned long packet_len, const unsigned char *addtl, unsigned long addtl_len, void **abstract);
|
int (*hash)(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno, const unsigned char *packet, unsigned long packet_len, const unsigned char *addtl, unsigned long addtl_len, void **abstract);
|
||||||
int (*dtor)(LIBSSH2_SESSION *session, void **abstract);
|
int (*dtor)(LIBSSH2_SESSION *session, void **abstract);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LIBSSH2_DBG_TRANS 1
|
#define LIBSSH2_DBG_TRANS 1
|
||||||
#define LIBSSH2_DBG_KEX 2
|
#define LIBSSH2_DBG_KEX 2
|
||||||
#define LIBSSH2_DBG_AUTH 3
|
#define LIBSSH2_DBG_AUTH 3
|
||||||
#define LIBSSH2_DBG_CONN 4
|
#define LIBSSH2_DBG_CONN 4
|
||||||
#define LIBSSH2_DBG_SCP 5
|
#define LIBSSH2_DBG_SCP 5
|
||||||
#define LIBSSH2_DBG_SFTP 6
|
#define LIBSSH2_DBG_SFTP 6
|
||||||
#define LIBSSH2_DBG_ERROR 7
|
#define LIBSSH2_DBG_ERROR 7
|
||||||
#define LIBSSH2_DBG_PUBLICKEY 8
|
#define LIBSSH2_DBG_PUBLICKEY 8
|
||||||
#ifdef LIBSSH2DEBUG
|
#ifdef LIBSSH2DEBUG
|
||||||
void _libssh2_debug(LIBSSH2_SESSION *session, int context, const char *format, ...);
|
void _libssh2_debug(LIBSSH2_SESSION *session, int context, const char *format, ...);
|
||||||
#else
|
#else
|
||||||
@ -421,103 +421,103 @@ void _libssh2_debug(LIBSSH2_SESSION *session, int context, const char *format, .
|
|||||||
#else
|
#else
|
||||||
/* no gcc and not C99, do static and hopefully inline */
|
/* no gcc and not C99, do static and hopefully inline */
|
||||||
static inline void _libssh2_debug(LIBSSH2_SESSION *session, int context,
|
static inline void _libssh2_debug(LIBSSH2_SESSION *session, int context,
|
||||||
const char *format, ...) {}
|
const char *format, ...) {}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LIBSSH2DEBUG
|
#ifdef LIBSSH2DEBUG
|
||||||
#define libssh2_error(session, errcode, errmsg, should_free) \
|
#define libssh2_error(session, errcode, errmsg, should_free) \
|
||||||
{ \
|
{ \
|
||||||
if (session->err_msg && session->err_should_free) { \
|
if (session->err_msg && session->err_should_free) { \
|
||||||
LIBSSH2_FREE(session, session->err_msg); \
|
LIBSSH2_FREE(session, session->err_msg); \
|
||||||
} \
|
} \
|
||||||
session->err_msg = (char *)errmsg; \
|
session->err_msg = (char *)errmsg; \
|
||||||
session->err_msglen = strlen(errmsg); \
|
session->err_msglen = strlen(errmsg); \
|
||||||
session->err_should_free = should_free; \
|
session->err_should_free = should_free; \
|
||||||
session->err_code = errcode; \
|
session->err_code = errcode; \
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_ERROR, "%d - %s", session->err_code, session->err_msg); \
|
_libssh2_debug(session, LIBSSH2_DBG_ERROR, "%d - %s", session->err_code, session->err_msg); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* ! LIBSSH2DEBUG */
|
#else /* ! LIBSSH2DEBUG */
|
||||||
|
|
||||||
#define libssh2_error(session, errcode, errmsg, should_free) \
|
#define libssh2_error(session, errcode, errmsg, should_free) \
|
||||||
{ \
|
{ \
|
||||||
if (session->err_msg && session->err_should_free) { \
|
if (session->err_msg && session->err_should_free) { \
|
||||||
LIBSSH2_FREE(session, session->err_msg); \
|
LIBSSH2_FREE(session, session->err_msg); \
|
||||||
} \
|
} \
|
||||||
session->err_msg = (char *)errmsg; \
|
session->err_msg = (char *)errmsg; \
|
||||||
session->err_msglen = strlen(errmsg); \
|
session->err_msglen = strlen(errmsg); \
|
||||||
session->err_should_free = should_free; \
|
session->err_should_free = should_free; \
|
||||||
session->err_code = errcode; \
|
session->err_code = errcode; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* LIBSSH2_DEBUG_ENABLED */
|
#endif /* LIBSSH2_DEBUG_ENABLED */
|
||||||
|
|
||||||
|
|
||||||
#define LIBSSH2_SOCKET_UNKNOWN 1
|
#define LIBSSH2_SOCKET_UNKNOWN 1
|
||||||
#define LIBSSH2_SOCKET_CONNECTED 0
|
#define LIBSSH2_SOCKET_CONNECTED 0
|
||||||
#define LIBSSH2_SOCKET_DISCONNECTED -1
|
#define LIBSSH2_SOCKET_DISCONNECTED -1
|
||||||
|
|
||||||
/* Initial packet state, prior to MAC check */
|
/* Initial packet state, prior to MAC check */
|
||||||
#define LIBSSH2_MAC_UNCONFIRMED 1
|
#define LIBSSH2_MAC_UNCONFIRMED 1
|
||||||
/* When MAC type is "none" (proto initiation phase) all packets are deemed "confirmed" */
|
/* When MAC type is "none" (proto initiation phase) all packets are deemed "confirmed" */
|
||||||
#define LIBSSH2_MAC_CONFIRMED 0
|
#define LIBSSH2_MAC_CONFIRMED 0
|
||||||
/* Something very bad is going on */
|
/* Something very bad is going on */
|
||||||
#define LIBSSH2_MAC_INVALID -1
|
#define LIBSSH2_MAC_INVALID -1
|
||||||
|
|
||||||
/* SSH Packet Types -- Defined by internet draft */
|
/* SSH Packet Types -- Defined by internet draft */
|
||||||
/* Transport Layer */
|
/* Transport Layer */
|
||||||
#define SSH_MSG_DISCONNECT 1
|
#define SSH_MSG_DISCONNECT 1
|
||||||
#define SSH_MSG_IGNORE 2
|
#define SSH_MSG_IGNORE 2
|
||||||
#define SSH_MSG_UNIMPLEMENTED 3
|
#define SSH_MSG_UNIMPLEMENTED 3
|
||||||
#define SSH_MSG_DEBUG 4
|
#define SSH_MSG_DEBUG 4
|
||||||
#define SSH_MSG_SERVICE_REQUEST 5
|
#define SSH_MSG_SERVICE_REQUEST 5
|
||||||
#define SSH_MSG_SERVICE_ACCEPT 6
|
#define SSH_MSG_SERVICE_ACCEPT 6
|
||||||
|
|
||||||
#define SSH_MSG_KEXINIT 20
|
#define SSH_MSG_KEXINIT 20
|
||||||
#define SSH_MSG_NEWKEYS 21
|
#define SSH_MSG_NEWKEYS 21
|
||||||
|
|
||||||
/* diffie-hellman-group1-sha1 */
|
/* diffie-hellman-group1-sha1 */
|
||||||
#define SSH_MSG_KEXDH_INIT 30
|
#define SSH_MSG_KEXDH_INIT 30
|
||||||
#define SSH_MSG_KEXDH_REPLY 31
|
#define SSH_MSG_KEXDH_REPLY 31
|
||||||
|
|
||||||
/* diffie-hellman-group-exchange-sha1 */
|
/* diffie-hellman-group-exchange-sha1 */
|
||||||
#define SSH_MSG_KEX_DH_GEX_REQUEST_OLD 30
|
#define SSH_MSG_KEX_DH_GEX_REQUEST_OLD 30
|
||||||
#define SSH_MSG_KEX_DH_GEX_REQUEST 34
|
#define SSH_MSG_KEX_DH_GEX_REQUEST 34
|
||||||
#define SSH_MSG_KEX_DH_GEX_GROUP 31
|
#define SSH_MSG_KEX_DH_GEX_GROUP 31
|
||||||
#define SSH_MSG_KEX_DH_GEX_INIT 32
|
#define SSH_MSG_KEX_DH_GEX_INIT 32
|
||||||
#define SSH_MSG_KEX_DH_GEX_REPLY 33
|
#define SSH_MSG_KEX_DH_GEX_REPLY 33
|
||||||
|
|
||||||
/* User Authentication */
|
/* User Authentication */
|
||||||
#define SSH_MSG_USERAUTH_REQUEST 50
|
#define SSH_MSG_USERAUTH_REQUEST 50
|
||||||
#define SSH_MSG_USERAUTH_FAILURE 51
|
#define SSH_MSG_USERAUTH_FAILURE 51
|
||||||
#define SSH_MSG_USERAUTH_SUCCESS 52
|
#define SSH_MSG_USERAUTH_SUCCESS 52
|
||||||
#define SSH_MSG_USERAUTH_BANNER 53
|
#define SSH_MSG_USERAUTH_BANNER 53
|
||||||
|
|
||||||
/* "public key" method */
|
/* "public key" method */
|
||||||
#define SSH_MSG_USERAUTH_PK_OK 60
|
#define SSH_MSG_USERAUTH_PK_OK 60
|
||||||
/* "password" method */
|
/* "password" method */
|
||||||
#define SSH_MSG_USERAUTH_PASSWD_CHANGEREQ 60
|
#define SSH_MSG_USERAUTH_PASSWD_CHANGEREQ 60
|
||||||
/* "keyboard-interactive" method */
|
/* "keyboard-interactive" method */
|
||||||
#define SSH_MSG_USERAUTH_INFO_REQUEST 60
|
#define SSH_MSG_USERAUTH_INFO_REQUEST 60
|
||||||
#define SSH_MSG_USERAUTH_INFO_RESPONSE 61
|
#define SSH_MSG_USERAUTH_INFO_RESPONSE 61
|
||||||
|
|
||||||
/* Channels */
|
/* Channels */
|
||||||
#define SSH_MSG_GLOBAL_REQUEST 80
|
#define SSH_MSG_GLOBAL_REQUEST 80
|
||||||
#define SSH_MSG_REQUEST_SUCCESS 81
|
#define SSH_MSG_REQUEST_SUCCESS 81
|
||||||
#define SSH_MSG_REQUEST_FAILURE 82
|
#define SSH_MSG_REQUEST_FAILURE 82
|
||||||
|
|
||||||
#define SSH_MSG_CHANNEL_OPEN 90
|
#define SSH_MSG_CHANNEL_OPEN 90
|
||||||
#define SSH_MSG_CHANNEL_OPEN_CONFIRMATION 91
|
#define SSH_MSG_CHANNEL_OPEN_CONFIRMATION 91
|
||||||
#define SSH_MSG_CHANNEL_OPEN_FAILURE 92
|
#define SSH_MSG_CHANNEL_OPEN_FAILURE 92
|
||||||
#define SSH_MSG_CHANNEL_WINDOW_ADJUST 93
|
#define SSH_MSG_CHANNEL_WINDOW_ADJUST 93
|
||||||
#define SSH_MSG_CHANNEL_DATA 94
|
#define SSH_MSG_CHANNEL_DATA 94
|
||||||
#define SSH_MSG_CHANNEL_EXTENDED_DATA 95
|
#define SSH_MSG_CHANNEL_EXTENDED_DATA 95
|
||||||
#define SSH_MSG_CHANNEL_EOF 96
|
#define SSH_MSG_CHANNEL_EOF 96
|
||||||
#define SSH_MSG_CHANNEL_CLOSE 97
|
#define SSH_MSG_CHANNEL_CLOSE 97
|
||||||
#define SSH_MSG_CHANNEL_REQUEST 98
|
#define SSH_MSG_CHANNEL_REQUEST 98
|
||||||
#define SSH_MSG_CHANNEL_SUCCESS 99
|
#define SSH_MSG_CHANNEL_SUCCESS 99
|
||||||
#define SSH_MSG_CHANNEL_FAILURE 100
|
#define SSH_MSG_CHANNEL_FAILURE 100
|
||||||
|
|
||||||
void libssh2_session_shutdown(LIBSSH2_SESSION *session);
|
void libssh2_session_shutdown(LIBSSH2_SESSION *session);
|
||||||
|
|
||||||
@ -527,7 +527,7 @@ void libssh2_htonu32(unsigned char *buf, unsigned long val);
|
|||||||
void libssh2_htonu64(unsigned char *buf, libssh2_uint64_t val);
|
void libssh2_htonu64(unsigned char *buf, libssh2_uint64_t val);
|
||||||
|
|
||||||
#define LIBSSH2_READ_TIMEOUT 60 /* generic timeout in seconds used when
|
#define LIBSSH2_READ_TIMEOUT 60 /* generic timeout in seconds used when
|
||||||
waiting for more data to arrive */
|
waiting for more data to arrive */
|
||||||
int libssh2_waitsocket(LIBSSH2_SESSION *session, long seconds);
|
int libssh2_waitsocket(LIBSSH2_SESSION *session, long seconds);
|
||||||
|
|
||||||
|
|
||||||
@ -548,17 +548,17 @@ typedef int libssh2pack_t;
|
|||||||
libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION *session);
|
libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION *session);
|
||||||
|
|
||||||
int libssh2_packet_ask_ex(LIBSSH2_SESSION *session, unsigned char packet_type, unsigned char **data, unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len, int poll_socket);
|
int libssh2_packet_ask_ex(LIBSSH2_SESSION *session, unsigned char packet_type, unsigned char **data, unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len, int poll_socket);
|
||||||
#define libssh2_packet_ask(session, packet_type, data, data_len, poll_socket) \
|
#define libssh2_packet_ask(session, packet_type, data, data_len, poll_socket) \
|
||||||
libssh2_packet_ask_ex((session), (packet_type), (data), (data_len), 0, NULL, 0, (poll_socket))
|
libssh2_packet_ask_ex((session), (packet_type), (data), (data_len), 0, NULL, 0, (poll_socket))
|
||||||
int libssh2_packet_askv_ex(LIBSSH2_SESSION *session, const unsigned char *packet_types, unsigned char **data, unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len, int poll_socket);
|
int libssh2_packet_askv_ex(LIBSSH2_SESSION *session, const unsigned char *packet_types, unsigned char **data, unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len, int poll_socket);
|
||||||
#define libssh2_packet_askv(session, packet_types, data, data_len, poll_socket) \
|
#define libssh2_packet_askv(session, packet_types, data, data_len, poll_socket) \
|
||||||
libssh2_packet_askv_ex((session), (packet_types), (data), (data_len), 0, NULL, 0, (poll_socket))
|
libssh2_packet_askv_ex((session), (packet_types), (data), (data_len), 0, NULL, 0, (poll_socket))
|
||||||
int libssh2_packet_require_ex(LIBSSH2_SESSION *session, unsigned char packet_type, unsigned char **data, unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len);
|
int libssh2_packet_require_ex(LIBSSH2_SESSION *session, unsigned char packet_type, unsigned char **data, unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len);
|
||||||
#define libssh2_packet_require(session, packet_type, data, data_len) \
|
#define libssh2_packet_require(session, packet_type, data, data_len) \
|
||||||
libssh2_packet_require_ex((session), (packet_type), (data), (data_len), 0, NULL, 0)
|
libssh2_packet_require_ex((session), (packet_type), (data), (data_len), 0, NULL, 0)
|
||||||
int libssh2_packet_requirev_ex(LIBSSH2_SESSION *session, const unsigned char *packet_types, unsigned char **data, unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len);
|
int libssh2_packet_requirev_ex(LIBSSH2_SESSION *session, const unsigned char *packet_types, unsigned char **data, unsigned long *data_len, unsigned long match_ofs, const unsigned char *match_buf, unsigned long match_len);
|
||||||
#define libssh2_packet_requirev(session, packet_types, data, data_len) \
|
#define libssh2_packet_requirev(session, packet_types, data, data_len) \
|
||||||
libssh2_packet_requirev_ex((session), (packet_types), (data), (data_len), 0, NULL, 0)
|
libssh2_packet_requirev_ex((session), (packet_types), (data), (data_len), 0, NULL, 0)
|
||||||
int libssh2_packet_burn(LIBSSH2_SESSION *session);
|
int libssh2_packet_burn(LIBSSH2_SESSION *session);
|
||||||
int libssh2_packet_write(LIBSSH2_SESSION *session, unsigned char *data, unsigned long data_len);
|
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);
|
int libssh2_packet_add(LIBSSH2_SESSION *session, unsigned char *data, size_t datalen, int macstate);
|
||||||
@ -566,15 +566,15 @@ int libssh2_kex_exchange(LIBSSH2_SESSION *session, int reexchange);
|
|||||||
unsigned long libssh2_channel_nextid(LIBSSH2_SESSION *session);
|
unsigned long libssh2_channel_nextid(LIBSSH2_SESSION *session);
|
||||||
LIBSSH2_CHANNEL *libssh2_channel_locate(LIBSSH2_SESSION *session, unsigned long channel_id);
|
LIBSSH2_CHANNEL *libssh2_channel_locate(LIBSSH2_SESSION *session, unsigned long channel_id);
|
||||||
ssize_t _libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
|
ssize_t _libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel,
|
||||||
int stream_id, char *buf, size_t buflen);
|
int stream_id, char *buf, size_t buflen);
|
||||||
#define _libssh2_channel_read(channel, buf, buflen) \
|
#define _libssh2_channel_read(channel, buf, buflen) \
|
||||||
_libssh2_channel_read_ex((channel), 0, (buf), (buflen))
|
_libssh2_channel_read_ex((channel), 0, (buf), (buflen))
|
||||||
#undef libssh2_channel_read /* never use this internally */
|
#undef libssh2_channel_read /* never use this internally */
|
||||||
#define libssh2_channel_read fix this code
|
#define libssh2_channel_read fix this code
|
||||||
|
|
||||||
int _libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
|
int _libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel,
|
||||||
int stream_id,
|
int stream_id,
|
||||||
const char *buf, size_t buflen);
|
const char *buf, size_t buflen);
|
||||||
#define _libssh2_channel_write(channel, buf, buflen) \
|
#define _libssh2_channel_write(channel, buf, buflen) \
|
||||||
_libssh2_channel_write_ex((channel), 0, (buf), (buflen))
|
_libssh2_channel_write_ex((channel), 0, (buf), (buflen))
|
||||||
|
|
||||||
@ -588,16 +588,16 @@ const LIBSSH2_COMP_METHOD **libssh2_comp_methods(void);
|
|||||||
const LIBSSH2_MAC_METHOD **libssh2_mac_methods(void);
|
const LIBSSH2_MAC_METHOD **libssh2_mac_methods(void);
|
||||||
|
|
||||||
/* Language API doesn't exist yet. Just act like we've agreed on a language */
|
/* Language API doesn't exist yet. Just act like we've agreed on a language */
|
||||||
#define libssh2_kex_agree_lang(session, endpoint, str, str_len) 0
|
#define libssh2_kex_agree_lang(session, endpoint, str, str_len) 0
|
||||||
|
|
||||||
/* pem.c */
|
/* pem.c */
|
||||||
int _libssh2_pem_parse (LIBSSH2_SESSION *session,
|
int _libssh2_pem_parse (LIBSSH2_SESSION *session,
|
||||||
const char *headerbegin,
|
const char *headerbegin,
|
||||||
const char *headerend,
|
const char *headerend,
|
||||||
FILE *fp,
|
FILE *fp,
|
||||||
char **data, unsigned int *datalen);
|
char **data, unsigned int *datalen);
|
||||||
int _libssh2_pem_decode_sequence (unsigned char **data, unsigned int *datalen);
|
int _libssh2_pem_decode_sequence (unsigned char **data, unsigned int *datalen);
|
||||||
int _libssh2_pem_decode_integer (unsigned char **data, unsigned int *datalen,
|
int _libssh2_pem_decode_integer (unsigned char **data, unsigned int *datalen,
|
||||||
unsigned char **i, unsigned int *ilen);
|
unsigned char **i, unsigned int *ilen);
|
||||||
|
|
||||||
#endif /* LIBSSH2_H */
|
#endif /* LIBSSH2_H */
|
||||||
|
240
src/mac.c
240
src/mac.c
@ -42,21 +42,21 @@
|
|||||||
* Minimalist MAC: No MAC
|
* Minimalist MAC: No MAC
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_none_MAC(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int libssh2_mac_none_MAC(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
const unsigned char *packet, unsigned long packet_len,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
||||||
static LIBSSH2_MAC_METHOD libssh2_mac_method_none = {
|
static LIBSSH2_MAC_METHOD libssh2_mac_method_none = {
|
||||||
"none",
|
"none",
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
NULL,
|
NULL,
|
||||||
libssh2_mac_none_MAC,
|
libssh2_mac_none_MAC,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
#endif /* LIBSSH2_MAC_NONE */
|
#endif /* LIBSSH2_MAC_NONE */
|
||||||
|
|
||||||
@ -65,11 +65,11 @@ static LIBSSH2_MAC_METHOD libssh2_mac_method_none = {
|
|||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_common_init(LIBSSH2_SESSION *session, unsigned char *key, int *free_key, void **abstract)
|
static int libssh2_mac_method_common_init(LIBSSH2_SESSION *session, unsigned char *key, int *free_key, void **abstract)
|
||||||
{
|
{
|
||||||
*abstract = key;
|
*abstract = key;
|
||||||
*free_key = 0;
|
*free_key = 0;
|
||||||
(void)session;
|
(void)session;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -78,12 +78,12 @@ static int libssh2_mac_method_common_init(LIBSSH2_SESSION *session, unsigned cha
|
|||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_common_dtor(LIBSSH2_SESSION *session, void **abstract)
|
static int libssh2_mac_method_common_dtor(LIBSSH2_SESSION *session, void **abstract)
|
||||||
{
|
{
|
||||||
if (*abstract) {
|
if (*abstract) {
|
||||||
LIBSSH2_FREE(session, *abstract);
|
LIBSSH2_FREE(session, *abstract);
|
||||||
}
|
}
|
||||||
*abstract = NULL;
|
*abstract = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -91,120 +91,120 @@ static int libssh2_mac_method_common_dtor(LIBSSH2_SESSION *session, void **abstr
|
|||||||
* Calculate hash using full sha1 value
|
* Calculate hash using full sha1 value
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_hmac_sha1_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int libssh2_mac_method_hmac_sha1_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
const unsigned char *packet, unsigned long packet_len,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_hmac_ctx ctx;
|
libssh2_hmac_ctx ctx;
|
||||||
unsigned char seqno_buf[4];
|
unsigned char seqno_buf[4];
|
||||||
(void)session;
|
(void)session;
|
||||||
|
|
||||||
libssh2_htonu32(seqno_buf, seqno);
|
libssh2_htonu32(seqno_buf, seqno);
|
||||||
|
|
||||||
libssh2_hmac_sha1_init(&ctx, *abstract, 20);
|
libssh2_hmac_sha1_init(&ctx, *abstract, 20);
|
||||||
libssh2_hmac_update(ctx, seqno_buf, 4);
|
libssh2_hmac_update(ctx, seqno_buf, 4);
|
||||||
libssh2_hmac_update(ctx, packet, packet_len);
|
libssh2_hmac_update(ctx, packet, packet_len);
|
||||||
if (addtl && addtl_len) {
|
if (addtl && addtl_len) {
|
||||||
libssh2_hmac_update(ctx, addtl, addtl_len);
|
libssh2_hmac_update(ctx, addtl, addtl_len);
|
||||||
}
|
}
|
||||||
libssh2_hmac_final(ctx, buf);
|
libssh2_hmac_final(ctx, buf);
|
||||||
libssh2_hmac_cleanup(&ctx);
|
libssh2_hmac_cleanup(&ctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1 = {
|
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1 = {
|
||||||
"hmac-sha1",
|
"hmac-sha1",
|
||||||
20,
|
20,
|
||||||
20,
|
20,
|
||||||
libssh2_mac_method_common_init,
|
libssh2_mac_method_common_init,
|
||||||
libssh2_mac_method_hmac_sha1_hash,
|
libssh2_mac_method_hmac_sha1_hash,
|
||||||
libssh2_mac_method_common_dtor,
|
libssh2_mac_method_common_dtor,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* {{{ libssh2_mac_method_hmac_sha1_96_hash
|
/* {{{ libssh2_mac_method_hmac_sha1_96_hash
|
||||||
* Calculate hash using first 96 bits of sha1 value
|
* Calculate hash using first 96 bits of sha1 value
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_hmac_sha1_96_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int libssh2_mac_method_hmac_sha1_96_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
const unsigned char *packet, unsigned long packet_len,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
||||||
{
|
{
|
||||||
unsigned char temp[SHA_DIGEST_LENGTH];
|
unsigned char temp[SHA_DIGEST_LENGTH];
|
||||||
|
|
||||||
libssh2_mac_method_hmac_sha1_hash(session, temp, seqno, packet, packet_len, addtl, addtl_len, abstract);
|
libssh2_mac_method_hmac_sha1_hash(session, temp, seqno, packet, packet_len, addtl, addtl_len, abstract);
|
||||||
memcpy(buf, (char *)temp, 96 / 8);
|
memcpy(buf, (char *)temp, 96 / 8);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1_96 = {
|
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_sha1_96 = {
|
||||||
"hmac-sha1-96",
|
"hmac-sha1-96",
|
||||||
12,
|
12,
|
||||||
20,
|
20,
|
||||||
libssh2_mac_method_common_init,
|
libssh2_mac_method_common_init,
|
||||||
libssh2_mac_method_hmac_sha1_96_hash,
|
libssh2_mac_method_hmac_sha1_96_hash,
|
||||||
libssh2_mac_method_common_dtor,
|
libssh2_mac_method_common_dtor,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* {{{ libssh2_mac_method_hmac_md5_hash
|
/* {{{ libssh2_mac_method_hmac_md5_hash
|
||||||
* Calculate hash using full md5 value
|
* Calculate hash using full md5 value
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_hmac_md5_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int libssh2_mac_method_hmac_md5_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
const unsigned char *packet, unsigned long packet_len,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_hmac_ctx ctx;
|
libssh2_hmac_ctx ctx;
|
||||||
unsigned char seqno_buf[4];
|
unsigned char seqno_buf[4];
|
||||||
(void)session;
|
(void)session;
|
||||||
|
|
||||||
libssh2_htonu32(seqno_buf, seqno);
|
libssh2_htonu32(seqno_buf, seqno);
|
||||||
|
|
||||||
libssh2_hmac_md5_init(&ctx, *abstract, 16);
|
libssh2_hmac_md5_init(&ctx, *abstract, 16);
|
||||||
libssh2_hmac_update(ctx, seqno_buf, 4);
|
libssh2_hmac_update(ctx, seqno_buf, 4);
|
||||||
libssh2_hmac_update(ctx, packet, packet_len);
|
libssh2_hmac_update(ctx, packet, packet_len);
|
||||||
if (addtl && addtl_len) {
|
if (addtl && addtl_len) {
|
||||||
libssh2_hmac_update(ctx, addtl, addtl_len);
|
libssh2_hmac_update(ctx, addtl, addtl_len);
|
||||||
}
|
}
|
||||||
libssh2_hmac_final(ctx, buf);
|
libssh2_hmac_final(ctx, buf);
|
||||||
libssh2_hmac_cleanup(&ctx);
|
libssh2_hmac_cleanup(&ctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5 = {
|
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5 = {
|
||||||
"hmac-md5",
|
"hmac-md5",
|
||||||
16,
|
16,
|
||||||
16,
|
16,
|
||||||
libssh2_mac_method_common_init,
|
libssh2_mac_method_common_init,
|
||||||
libssh2_mac_method_hmac_md5_hash,
|
libssh2_mac_method_hmac_md5_hash,
|
||||||
libssh2_mac_method_common_dtor,
|
libssh2_mac_method_common_dtor,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* {{{ libssh2_mac_method_hmac_md5_96_hash
|
/* {{{ libssh2_mac_method_hmac_md5_96_hash
|
||||||
* Calculate hash using first 96 bits of md5 value
|
* Calculate hash using first 96 bits of md5 value
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_hmac_md5_96_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int libssh2_mac_method_hmac_md5_96_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
const unsigned char *packet, unsigned long packet_len,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
||||||
{
|
{
|
||||||
unsigned char temp[MD5_DIGEST_LENGTH];
|
unsigned char temp[MD5_DIGEST_LENGTH];
|
||||||
|
|
||||||
libssh2_mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len, addtl, addtl_len, abstract);
|
libssh2_mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len, addtl, addtl_len, abstract);
|
||||||
memcpy(buf, (char *)temp, 96 / 8);
|
memcpy(buf, (char *)temp, 96 / 8);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5_96 = {
|
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5_96 = {
|
||||||
"hmac-md5-96",
|
"hmac-md5-96",
|
||||||
12,
|
12,
|
||||||
16,
|
16,
|
||||||
libssh2_mac_method_common_init,
|
libssh2_mac_method_common_init,
|
||||||
libssh2_mac_method_hmac_md5_96_hash,
|
libssh2_mac_method_hmac_md5_96_hash,
|
||||||
libssh2_mac_method_common_dtor,
|
libssh2_mac_method_common_dtor,
|
||||||
};
|
};
|
||||||
|
|
||||||
#if LIBSSH2_HMAC_RIPEMD
|
#if LIBSSH2_HMAC_RIPEMD
|
||||||
@ -212,63 +212,63 @@ static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_md5_96 = {
|
|||||||
* Calculate hash using ripemd160 value
|
* Calculate hash using ripemd160 value
|
||||||
*/
|
*/
|
||||||
static int libssh2_mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
static int libssh2_mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION *session, unsigned char *buf, unsigned long seqno,
|
||||||
const unsigned char *packet, unsigned long packet_len,
|
const unsigned char *packet, unsigned long packet_len,
|
||||||
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
const unsigned char *addtl, unsigned long addtl_len, void **abstract)
|
||||||
{
|
{
|
||||||
libssh2_hmac_ctx ctx;
|
libssh2_hmac_ctx ctx;
|
||||||
unsigned char seqno_buf[4];
|
unsigned char seqno_buf[4];
|
||||||
(void)session;
|
(void)session;
|
||||||
|
|
||||||
libssh2_htonu32(seqno_buf, seqno);
|
libssh2_htonu32(seqno_buf, seqno);
|
||||||
|
|
||||||
libssh2_hmac_ripemd160_init(&ctx, *abstract, 20);
|
libssh2_hmac_ripemd160_init(&ctx, *abstract, 20);
|
||||||
libssh2_hmac_update(ctx, seqno_buf, 4);
|
libssh2_hmac_update(ctx, seqno_buf, 4);
|
||||||
libssh2_hmac_update(ctx, packet, packet_len);
|
libssh2_hmac_update(ctx, packet, packet_len);
|
||||||
if (addtl && addtl_len) {
|
if (addtl && addtl_len) {
|
||||||
libssh2_hmac_update(ctx, addtl, addtl_len);
|
libssh2_hmac_update(ctx, addtl, addtl_len);
|
||||||
}
|
}
|
||||||
libssh2_hmac_final(ctx, buf);
|
libssh2_hmac_final(ctx, buf);
|
||||||
libssh2_hmac_cleanup(&ctx);
|
libssh2_hmac_cleanup(&ctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_ripemd160 = {
|
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_ripemd160 = {
|
||||||
"hmac-ripemd160",
|
"hmac-ripemd160",
|
||||||
20,
|
20,
|
||||||
20,
|
20,
|
||||||
libssh2_mac_method_common_init,
|
libssh2_mac_method_common_init,
|
||||||
libssh2_mac_method_hmac_ripemd160_hash,
|
libssh2_mac_method_hmac_ripemd160_hash,
|
||||||
libssh2_mac_method_common_dtor,
|
libssh2_mac_method_common_dtor,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_ripemd160_openssh_com = {
|
static const LIBSSH2_MAC_METHOD libssh2_mac_method_hmac_ripemd160_openssh_com = {
|
||||||
"hmac-ripemd160@openssh.com",
|
"hmac-ripemd160@openssh.com",
|
||||||
20,
|
20,
|
||||||
20,
|
20,
|
||||||
libssh2_mac_method_common_init,
|
libssh2_mac_method_common_init,
|
||||||
libssh2_mac_method_hmac_ripemd160_hash,
|
libssh2_mac_method_hmac_ripemd160_hash,
|
||||||
libssh2_mac_method_common_dtor,
|
libssh2_mac_method_common_dtor,
|
||||||
};
|
};
|
||||||
#endif /* LIBSSH2_HMAC_RIPEMD */
|
#endif /* LIBSSH2_HMAC_RIPEMD */
|
||||||
|
|
||||||
static const LIBSSH2_MAC_METHOD *_libssh2_mac_methods[] = {
|
static const LIBSSH2_MAC_METHOD *_libssh2_mac_methods[] = {
|
||||||
&libssh2_mac_method_hmac_sha1,
|
&libssh2_mac_method_hmac_sha1,
|
||||||
&libssh2_mac_method_hmac_sha1_96,
|
&libssh2_mac_method_hmac_sha1_96,
|
||||||
&libssh2_mac_method_hmac_md5,
|
&libssh2_mac_method_hmac_md5,
|
||||||
&libssh2_mac_method_hmac_md5_96,
|
&libssh2_mac_method_hmac_md5_96,
|
||||||
#ifdef LIBSSH2_HMAC_RIPEMD
|
#ifdef LIBSSH2_HMAC_RIPEMD
|
||||||
&libssh2_mac_method_hmac_ripemd160,
|
&libssh2_mac_method_hmac_ripemd160,
|
||||||
&libssh2_mac_method_hmac_ripemd160_openssh_com,
|
&libssh2_mac_method_hmac_ripemd160_openssh_com,
|
||||||
#endif /* LIBSSH2_HMAC_RIPEMD */
|
#endif /* LIBSSH2_HMAC_RIPEMD */
|
||||||
#ifdef LIBSSH2_MAC_NONE
|
#ifdef LIBSSH2_MAC_NONE
|
||||||
&libssh2_mac_method_none,
|
&libssh2_mac_method_none,
|
||||||
#endif /* LIBSSH2_MAC_NONE */
|
#endif /* LIBSSH2_MAC_NONE */
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
const LIBSSH2_MAC_METHOD **libssh2_mac_methods(void) {
|
const LIBSSH2_MAC_METHOD **libssh2_mac_methods(void) {
|
||||||
return _libssh2_mac_methods;
|
return _libssh2_mac_methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
174
src/misc.c
174
src/misc.c
@ -44,7 +44,7 @@
|
|||||||
*/
|
*/
|
||||||
unsigned long libssh2_ntohu32(const unsigned char *buf)
|
unsigned long libssh2_ntohu32(const unsigned char *buf)
|
||||||
{
|
{
|
||||||
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -54,12 +54,12 @@ unsigned long libssh2_ntohu32(const unsigned char *buf)
|
|||||||
*/
|
*/
|
||||||
libssh2_uint64_t libssh2_ntohu64(const unsigned char *buf)
|
libssh2_uint64_t libssh2_ntohu64(const unsigned char *buf)
|
||||||
{
|
{
|
||||||
unsigned long msl, lsl;
|
unsigned long msl, lsl;
|
||||||
|
|
||||||
msl = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
msl = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
||||||
lsl = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
|
lsl = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
|
||||||
|
|
||||||
return ((msl * 65536) * 65536) + lsl;
|
return ((msl * 65536) * 65536) + lsl;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -67,10 +67,10 @@ libssh2_uint64_t libssh2_ntohu64(const unsigned char *buf)
|
|||||||
*/
|
*/
|
||||||
void libssh2_htonu32(unsigned char *buf, unsigned long value)
|
void libssh2_htonu32(unsigned char *buf, unsigned long value)
|
||||||
{
|
{
|
||||||
buf[0] = (value >> 24) & 0xFF;
|
buf[0] = (value >> 24) & 0xFF;
|
||||||
buf[1] = (value >> 16) & 0xFF;
|
buf[1] = (value >> 16) & 0xFF;
|
||||||
buf[2] = (value >> 8) & 0xFF;
|
buf[2] = (value >> 8) & 0xFF;
|
||||||
buf[3] = value & 0xFF;
|
buf[3] = value & 0xFF;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -78,17 +78,17 @@ void libssh2_htonu32(unsigned char *buf, unsigned long value)
|
|||||||
*/
|
*/
|
||||||
void libssh2_htonu64(unsigned char *buf, libssh2_uint64_t value)
|
void libssh2_htonu64(unsigned char *buf, libssh2_uint64_t value)
|
||||||
{
|
{
|
||||||
unsigned long msl = (value / 65536) / 65536;
|
unsigned long msl = (value / 65536) / 65536;
|
||||||
|
|
||||||
buf[0] = (msl >> 24) & 0xFF;
|
buf[0] = (msl >> 24) & 0xFF;
|
||||||
buf[1] = (msl >> 16) & 0xFF;
|
buf[1] = (msl >> 16) & 0xFF;
|
||||||
buf[2] = (msl >> 8) & 0xFF;
|
buf[2] = (msl >> 8) & 0xFF;
|
||||||
buf[3] = msl & 0xFF;
|
buf[3] = msl & 0xFF;
|
||||||
|
|
||||||
buf[4] = (value >> 24) & 0xFF;
|
buf[4] = (value >> 24) & 0xFF;
|
||||||
buf[5] = (value >> 16) & 0xFF;
|
buf[5] = (value >> 16) & 0xFF;
|
||||||
buf[6] = (value >> 8) & 0xFF;
|
buf[6] = (value >> 8) & 0xFF;
|
||||||
buf[7] = value & 0xFF;
|
buf[7] = value & 0xFF;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -130,97 +130,97 @@ static const short libssh2_base64_reverse_table[256] = {
|
|||||||
* Decode a base64 chunk and store it into a newly alloc'd buffer
|
* Decode a base64 chunk and store it into a newly alloc'd buffer
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, unsigned int *datalen,
|
LIBSSH2_API int libssh2_base64_decode(LIBSSH2_SESSION *session, char **data, unsigned int *datalen,
|
||||||
const char *src, unsigned int src_len)
|
const char *src, unsigned int src_len)
|
||||||
{
|
{
|
||||||
unsigned char *s, *d;
|
unsigned char *s, *d;
|
||||||
short v;
|
short v;
|
||||||
int i = 0, len = 0;
|
int i = 0, len = 0;
|
||||||
|
|
||||||
*data = LIBSSH2_ALLOC(session, (3 * src_len / 4) + 1);
|
*data = LIBSSH2_ALLOC(session, (3 * src_len / 4) + 1);
|
||||||
d = (unsigned char *)*data;
|
d = (unsigned char *)*data;
|
||||||
if (!d) {
|
if (!d) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(s = (unsigned char *)src; ((char*)s) < (src + src_len); s++) {
|
for(s = (unsigned char *)src; ((char*)s) < (src + src_len); s++) {
|
||||||
if ((v = libssh2_base64_reverse_table[*s]) < 0) continue;
|
if ((v = libssh2_base64_reverse_table[*s]) < 0) continue;
|
||||||
switch (i % 4) {
|
switch (i % 4) {
|
||||||
case 0:
|
case 0:
|
||||||
d[len] = v << 2;
|
d[len] = v << 2;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
d[len++] |= v >> 4;
|
d[len++] |= v >> 4;
|
||||||
d[len] = v << 4;
|
d[len] = v << 4;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
d[len++] |= v >> 2;
|
d[len++] |= v >> 2;
|
||||||
d[len] = v << 6;
|
d[len] = v << 6;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
d[len++] |= v;
|
d[len++] |= v;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if ((i % 4) == 1) {
|
if ((i % 4) == 1) {
|
||||||
/* Invalid -- We have a byte which belongs exclusively to a partial octet */
|
/* Invalid -- We have a byte which belongs exclusively to a partial octet */
|
||||||
LIBSSH2_FREE(session, *data);
|
LIBSSH2_FREE(session, *data);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*datalen = len;
|
*datalen = len;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#ifdef LIBSSH2DEBUG
|
#ifdef LIBSSH2DEBUG
|
||||||
LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask)
|
LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask)
|
||||||
{
|
{
|
||||||
session->showmask = bitmask;
|
session->showmask = bitmask;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _libssh2_debug(LIBSSH2_SESSION *session, int context,
|
void _libssh2_debug(LIBSSH2_SESSION *session, int context,
|
||||||
const char *format, ...)
|
const char *format, ...)
|
||||||
{
|
{
|
||||||
char buffer[1536];
|
char buffer[1536];
|
||||||
int len;
|
int len;
|
||||||
va_list vargs;
|
va_list vargs;
|
||||||
static const char * const contexts[9] = {
|
static const char * const contexts[9] = {
|
||||||
"Unknown",
|
"Unknown",
|
||||||
"Transport",
|
"Transport",
|
||||||
"Key Exchange",
|
"Key Exchange",
|
||||||
"Userauth",
|
"Userauth",
|
||||||
"Connection",
|
"Connection",
|
||||||
"scp",
|
"scp",
|
||||||
"SFTP Subsystem",
|
"SFTP Subsystem",
|
||||||
"Failure Event",
|
"Failure Event",
|
||||||
"Publickey Subsystem",
|
"Publickey Subsystem",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (context < 1 || context > 8) {
|
if (context < 1 || context > 8) {
|
||||||
context = 0;
|
context = 0;
|
||||||
}
|
}
|
||||||
if(!(session->showmask & (1<<context))) {
|
if(!(session->showmask & (1<<context))) {
|
||||||
/* no such output asked for */
|
/* no such output asked for */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = snprintf(buffer, 1535, "[libssh2] %s: ", contexts[context]);
|
len = snprintf(buffer, 1535, "[libssh2] %s: ", contexts[context]);
|
||||||
|
|
||||||
va_start(vargs, format);
|
va_start(vargs, format);
|
||||||
len += vsnprintf(buffer + len, 1535 - len, format, vargs);
|
len += vsnprintf(buffer + len, 1535 - len, format, vargs);
|
||||||
buffer[len] = '\n';
|
buffer[len] = '\n';
|
||||||
va_end(vargs);
|
va_end(vargs);
|
||||||
write(2, buffer, len + 1);
|
write(2, buffer, len + 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask)
|
LIBSSH2_API int libssh2_trace(LIBSSH2_SESSION *session, int bitmask)
|
||||||
{
|
{
|
||||||
(void)session;
|
(void)session;
|
||||||
(void)bitmask;
|
(void)bitmask;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
371
src/openssl.c
371
src/openssl.c
@ -44,156 +44,155 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
||||||
const unsigned char *edata,
|
const unsigned char *edata,
|
||||||
unsigned long elen,
|
unsigned long elen,
|
||||||
const unsigned char *ndata,
|
const unsigned char *ndata,
|
||||||
unsigned long nlen,
|
unsigned long nlen,
|
||||||
const unsigned char *ddata,
|
const unsigned char *ddata,
|
||||||
unsigned long dlen,
|
unsigned long dlen,
|
||||||
const unsigned char *pdata,
|
const unsigned char *pdata,
|
||||||
unsigned long plen,
|
unsigned long plen,
|
||||||
const unsigned char *qdata,
|
const unsigned char *qdata,
|
||||||
unsigned long qlen,
|
unsigned long qlen,
|
||||||
const unsigned char *e1data,
|
const unsigned char *e1data,
|
||||||
unsigned long e1len,
|
unsigned long e1len,
|
||||||
const unsigned char *e2data,
|
const unsigned char *e2data,
|
||||||
unsigned long e2len,
|
unsigned long e2len,
|
||||||
const unsigned char *coeffdata,
|
const unsigned char *coeffdata,
|
||||||
unsigned long coefflen)
|
unsigned long coefflen)
|
||||||
{
|
{
|
||||||
*rsa = RSA_new();
|
*rsa = RSA_new();
|
||||||
|
|
||||||
(*rsa)->e = BN_new();
|
(*rsa)->e = BN_new();
|
||||||
BN_bin2bn(edata, elen, (*rsa)->e);
|
BN_bin2bn(edata, elen, (*rsa)->e);
|
||||||
|
|
||||||
(*rsa)->n = BN_new();
|
(*rsa)->n = BN_new();
|
||||||
BN_bin2bn(ndata, nlen, (*rsa)->n);
|
BN_bin2bn(ndata, nlen, (*rsa)->n);
|
||||||
|
|
||||||
if (ddata)
|
if (ddata) {
|
||||||
{
|
(*rsa)->d = BN_new();
|
||||||
(*rsa)->d = BN_new();
|
BN_bin2bn(ddata, dlen, (*rsa)->d);
|
||||||
BN_bin2bn(ddata, dlen, (*rsa)->d);
|
|
||||||
|
|
||||||
(*rsa)->p = BN_new();
|
(*rsa)->p = BN_new();
|
||||||
BN_bin2bn(pdata, plen, (*rsa)->p);
|
BN_bin2bn(pdata, plen, (*rsa)->p);
|
||||||
|
|
||||||
(*rsa)->q = BN_new();
|
(*rsa)->q = BN_new();
|
||||||
BN_bin2bn(qdata, qlen, (*rsa)->q);
|
BN_bin2bn(qdata, qlen, (*rsa)->q);
|
||||||
|
|
||||||
(*rsa)->dmp1 = BN_new();
|
(*rsa)->dmp1 = BN_new();
|
||||||
BN_bin2bn(e1data, e1len, (*rsa)->dmp1);
|
BN_bin2bn(e1data, e1len, (*rsa)->dmp1);
|
||||||
|
|
||||||
(*rsa)->dmq1 = BN_new();
|
(*rsa)->dmq1 = BN_new();
|
||||||
BN_bin2bn(e2data, e2len, (*rsa)->dmq1);
|
BN_bin2bn(e2data, e2len, (*rsa)->dmq1);
|
||||||
|
|
||||||
(*rsa)->iqmp = BN_new();
|
(*rsa)->iqmp = BN_new();
|
||||||
BN_bin2bn(coeffdata, coefflen, (*rsa)->iqmp);
|
BN_bin2bn(coeffdata, coefflen, (*rsa)->iqmp);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsactx,
|
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsactx,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
unsigned long sig_len,
|
unsigned long sig_len,
|
||||||
const unsigned char *m,
|
const unsigned char *m,
|
||||||
unsigned long m_len)
|
unsigned long m_len)
|
||||||
{
|
{
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
SHA1(m, m_len, hash);
|
SHA1(m, m_len, hash);
|
||||||
ret = RSA_verify(NID_sha1, hash, SHA_DIGEST_LENGTH,
|
ret = RSA_verify(NID_sha1, hash, SHA_DIGEST_LENGTH,
|
||||||
(unsigned char *)sig, sig_len, rsactx);
|
(unsigned char *)sig, sig_len, rsactx);
|
||||||
return (ret == 1) ? 0 : -1;
|
return (ret == 1) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
int _libssh2_dsa_new(libssh2_dsa_ctx **dsactx,
|
||||||
const unsigned char *p,
|
const unsigned char *p,
|
||||||
unsigned long p_len,
|
unsigned long p_len,
|
||||||
const unsigned char *q,
|
const unsigned char *q,
|
||||||
unsigned long q_len,
|
unsigned long q_len,
|
||||||
const unsigned char *g,
|
const unsigned char *g,
|
||||||
unsigned long g_len,
|
unsigned long g_len,
|
||||||
const unsigned char *y,
|
const unsigned char *y,
|
||||||
unsigned long y_len,
|
unsigned long y_len,
|
||||||
const unsigned char *x,
|
const unsigned char *x,
|
||||||
unsigned long x_len)
|
unsigned long x_len)
|
||||||
{
|
{
|
||||||
*dsactx = DSA_new();
|
*dsactx = DSA_new();
|
||||||
|
|
||||||
(*dsactx)->p = BN_new();
|
(*dsactx)->p = BN_new();
|
||||||
BN_bin2bn(p, p_len, (*dsactx)->p);
|
BN_bin2bn(p, p_len, (*dsactx)->p);
|
||||||
|
|
||||||
(*dsactx)->q = BN_new();
|
(*dsactx)->q = BN_new();
|
||||||
BN_bin2bn(q, q_len, (*dsactx)->q);
|
BN_bin2bn(q, q_len, (*dsactx)->q);
|
||||||
|
|
||||||
(*dsactx)->g = BN_new();
|
(*dsactx)->g = BN_new();
|
||||||
BN_bin2bn(g, g_len, (*dsactx)->g);
|
BN_bin2bn(g, g_len, (*dsactx)->g);
|
||||||
|
|
||||||
(*dsactx)->pub_key = BN_new();
|
(*dsactx)->pub_key = BN_new();
|
||||||
BN_bin2bn(y, y_len, (*dsactx)->pub_key);
|
BN_bin2bn(y, y_len, (*dsactx)->pub_key);
|
||||||
|
|
||||||
if (x_len) {
|
if (x_len) {
|
||||||
(*dsactx)->priv_key = BN_new();
|
(*dsactx)->priv_key = BN_new();
|
||||||
BN_bin2bn(x, x_len, (*dsactx)->priv_key);
|
BN_bin2bn(x, x_len, (*dsactx)->priv_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
const unsigned char *m,
|
const unsigned char *m,
|
||||||
unsigned long m_len)
|
unsigned long m_len)
|
||||||
{
|
{
|
||||||
unsigned char hash[SHA_DIGEST_LENGTH];
|
unsigned char hash[SHA_DIGEST_LENGTH];
|
||||||
DSA_SIG dsasig;
|
DSA_SIG dsasig;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dsasig.r = BN_new();
|
dsasig.r = BN_new();
|
||||||
BN_bin2bn(sig, 20, dsasig.r);
|
BN_bin2bn(sig, 20, dsasig.r);
|
||||||
dsasig.s = BN_new();
|
dsasig.s = BN_new();
|
||||||
BN_bin2bn(sig + 20, 20, dsasig.s);
|
BN_bin2bn(sig + 20, 20, dsasig.s);
|
||||||
|
|
||||||
libssh2_sha1(m, m_len, hash);
|
libssh2_sha1(m, m_len, hash);
|
||||||
ret = DSA_do_verify(hash, SHA_DIGEST_LENGTH, &dsasig, dsactx);
|
ret = DSA_do_verify(hash, SHA_DIGEST_LENGTH, &dsasig, dsactx);
|
||||||
BN_clear_free(dsasig.s);
|
BN_clear_free(dsasig.s);
|
||||||
BN_clear_free(dsasig.r);
|
BN_clear_free(dsasig.r);
|
||||||
|
|
||||||
return (ret == 1) ? 0 : -1;
|
return (ret == 1) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
unsigned char *iv,
|
unsigned char *iv,
|
||||||
unsigned char *secret,
|
unsigned char *secret,
|
||||||
int encrypt)
|
int encrypt)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX_init(h);
|
EVP_CIPHER_CTX_init(h);
|
||||||
EVP_CipherInit(h, algo(), secret, iv, encrypt);
|
EVP_CipherInit(h, algo(), secret, iv, encrypt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
int encrypt,
|
int encrypt,
|
||||||
unsigned char *block)
|
unsigned char *block)
|
||||||
{
|
{
|
||||||
int blocksize = ctx->cipher->block_size;
|
int blocksize = ctx->cipher->block_size;
|
||||||
unsigned char buf[EVP_MAX_BLOCK_LENGTH];
|
unsigned char buf[EVP_MAX_BLOCK_LENGTH];
|
||||||
int ret;
|
int ret;
|
||||||
(void)algo;
|
(void)algo;
|
||||||
(void)encrypt;
|
(void)encrypt;
|
||||||
|
|
||||||
if (blocksize == 1) {
|
if (blocksize == 1) {
|
||||||
/* Hack for arcfour. */
|
/* Hack for arcfour. */
|
||||||
blocksize = 8;
|
blocksize = 8;
|
||||||
}
|
}
|
||||||
ret = EVP_Cipher(ctx, buf, block, blocksize);
|
ret = EVP_Cipher(ctx, buf, block, blocksize);
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
memcpy(block, buf, blocksize);
|
memcpy(block, buf, blocksize);
|
||||||
}
|
}
|
||||||
return ret == 1 ? 0 : 1;
|
return ret == 1 ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Optionally call a passphrase callback specified by the
|
/* TODO: Optionally call a passphrase callback specified by the
|
||||||
@ -201,119 +200,119 @@ int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
passphrase_cb(char *buf, int size,
|
passphrase_cb(char *buf, int size,
|
||||||
int rwflag, char *passphrase)
|
int rwflag, char *passphrase)
|
||||||
{
|
{
|
||||||
int passphrase_len = strlen(passphrase);
|
int passphrase_len = strlen(passphrase);
|
||||||
(void)rwflag;
|
(void)rwflag;
|
||||||
|
|
||||||
if (passphrase_len > (size - 1)) {
|
if (passphrase_len > (size - 1)) {
|
||||||
passphrase_len = size - 1;
|
passphrase_len = size - 1;
|
||||||
}
|
}
|
||||||
memcpy(buf, passphrase, passphrase_len);
|
memcpy(buf, passphrase, passphrase_len);
|
||||||
buf[passphrase_len] = '\0';
|
buf[passphrase_len] = '\0';
|
||||||
|
|
||||||
return passphrase_len;
|
return passphrase_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
||||||
LIBSSH2_SESSION *session,
|
LIBSSH2_SESSION *session,
|
||||||
FILE *fp,
|
FILE *fp,
|
||||||
unsigned const char *passphrase)
|
unsigned const char *passphrase)
|
||||||
{
|
{
|
||||||
(void)session;
|
(void)session;
|
||||||
if (!EVP_get_cipherbyname("des")) {
|
if (!EVP_get_cipherbyname("des")) {
|
||||||
/* If this cipher isn't loaded it's a pretty good indication that none are.
|
/* If this cipher isn't loaded it's a pretty good indication that none are.
|
||||||
* I have *NO DOUBT* that there's a better way to deal with this ($#&%#$(%$#(
|
* I have *NO DOUBT* that there's a better way to deal with this ($#&%#$(%$#(
|
||||||
* Someone buy me an OpenSSL manual and I'll read up on it.
|
* Someone buy me an OpenSSL manual and I'll read up on it.
|
||||||
*/
|
*/
|
||||||
OpenSSL_add_all_ciphers();
|
OpenSSL_add_all_ciphers();
|
||||||
}
|
}
|
||||||
*rsa = PEM_read_RSAPrivateKey(fp, NULL, (void*)passphrase_cb,
|
*rsa = PEM_read_RSAPrivateKey(fp, NULL, (void*)passphrase_cb,
|
||||||
(void*)passphrase);
|
(void*)passphrase);
|
||||||
if (!*rsa) {
|
if (!*rsa) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
||||||
LIBSSH2_SESSION *session,
|
LIBSSH2_SESSION *session,
|
||||||
FILE *fp,
|
FILE *fp,
|
||||||
unsigned const char *passphrase)
|
unsigned const char *passphrase)
|
||||||
{
|
{
|
||||||
(void)session;
|
(void)session;
|
||||||
if (!EVP_get_cipherbyname("des")) {
|
if (!EVP_get_cipherbyname("des")) {
|
||||||
/* If this cipher isn't loaded it's a pretty good indication that none are.
|
/* If this cipher isn't loaded it's a pretty good indication that none are.
|
||||||
* I have *NO DOUBT* that there's a better way to deal with this ($#&%#$(%$#(
|
* I have *NO DOUBT* that there's a better way to deal with this ($#&%#$(%$#(
|
||||||
* Someone buy me an OpenSSL manual and I'll read up on it.
|
* Someone buy me an OpenSSL manual and I'll read up on it.
|
||||||
*/
|
*/
|
||||||
OpenSSL_add_all_ciphers();
|
OpenSSL_add_all_ciphers();
|
||||||
}
|
}
|
||||||
*dsa = PEM_read_DSAPrivateKey(fp, NULL, (void*)passphrase_cb,
|
*dsa = PEM_read_DSAPrivateKey(fp, NULL, (void*)passphrase_cb,
|
||||||
(void*)passphrase);
|
(void*)passphrase);
|
||||||
if (!*dsa) {
|
if (!*dsa) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
||||||
libssh2_rsa_ctx *rsactx,
|
libssh2_rsa_ctx *rsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len,
|
||||||
unsigned char **signature,
|
unsigned char **signature,
|
||||||
unsigned long *signature_len)
|
unsigned long *signature_len)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
unsigned char *sig;
|
unsigned char *sig;
|
||||||
unsigned int sig_len;
|
unsigned int sig_len;
|
||||||
|
|
||||||
sig_len = RSA_size(rsactx);
|
sig_len = RSA_size(rsactx);
|
||||||
sig = LIBSSH2_ALLOC(session, sig_len);
|
sig = LIBSSH2_ALLOC(session, sig_len);
|
||||||
|
|
||||||
if (!sig) {
|
if (!sig) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = RSA_sign(NID_sha1, hash, hash_len, sig, &sig_len, rsactx);
|
ret = RSA_sign(NID_sha1, hash, hash_len, sig, &sig_len, rsactx);
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
LIBSSH2_FREE(session, sig);
|
LIBSSH2_FREE(session, sig);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*signature = sig;
|
*signature = sig;
|
||||||
*signature_len = sig_len;
|
*signature_len = sig_len;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len,
|
||||||
unsigned char *signature)
|
unsigned char *signature)
|
||||||
{
|
{
|
||||||
DSA_SIG *sig;
|
DSA_SIG *sig;
|
||||||
int r_len, s_len, rs_pad;
|
int r_len, s_len, rs_pad;
|
||||||
(void)hash_len;
|
(void)hash_len;
|
||||||
|
|
||||||
sig = DSA_do_sign(hash, SHA_DIGEST_LENGTH, dsactx);
|
sig = DSA_do_sign(hash, SHA_DIGEST_LENGTH, dsactx);
|
||||||
if (!sig) {
|
if (!sig) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
r_len = BN_num_bytes(sig->r);
|
r_len = BN_num_bytes(sig->r);
|
||||||
s_len = BN_num_bytes(sig->s);
|
s_len = BN_num_bytes(sig->s);
|
||||||
rs_pad = (2 * SHA_DIGEST_LENGTH) - (r_len + s_len);
|
rs_pad = (2 * SHA_DIGEST_LENGTH) - (r_len + s_len);
|
||||||
if (rs_pad < 0) {
|
if (rs_pad < 0) {
|
||||||
DSA_SIG_free(sig);
|
DSA_SIG_free(sig);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
BN_bn2bin(sig->r, signature + rs_pad);
|
BN_bn2bin(sig->r, signature + rs_pad);
|
||||||
BN_bn2bin(sig->s, signature + rs_pad + r_len);
|
BN_bn2bin(sig->s, signature + rs_pad + r_len);
|
||||||
|
|
||||||
DSA_SIG_free(sig);
|
DSA_SIG_free(sig);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
110
src/openssl.h
110
src/openssl.h
@ -100,7 +100,7 @@
|
|||||||
# define LIBSSH2_3DES 1
|
# define LIBSSH2_3DES 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define libssh2_random(buf, len) \
|
#define libssh2_random(buf, len) \
|
||||||
RAND_bytes ((buf), (len))
|
RAND_bytes ((buf), (len))
|
||||||
|
|
||||||
#define libssh2_sha1_ctx SHA_CTX
|
#define libssh2_sha1_ctx SHA_CTX
|
||||||
@ -132,65 +132,65 @@
|
|||||||
#define libssh2_rsa_ctx RSA
|
#define libssh2_rsa_ctx RSA
|
||||||
|
|
||||||
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
int _libssh2_rsa_new(libssh2_rsa_ctx **rsa,
|
||||||
const unsigned char *edata,
|
const unsigned char *edata,
|
||||||
unsigned long elen,
|
unsigned long elen,
|
||||||
const unsigned char *ndata,
|
const unsigned char *ndata,
|
||||||
unsigned long nlen,
|
unsigned long nlen,
|
||||||
const unsigned char *ddata,
|
const unsigned char *ddata,
|
||||||
unsigned long dlen,
|
unsigned long dlen,
|
||||||
const unsigned char *pdata,
|
const unsigned char *pdata,
|
||||||
unsigned long plen,
|
unsigned long plen,
|
||||||
const unsigned char *qdata,
|
const unsigned char *qdata,
|
||||||
unsigned long qlen,
|
unsigned long qlen,
|
||||||
const unsigned char *e1data,
|
const unsigned char *e1data,
|
||||||
unsigned long e1len,
|
unsigned long e1len,
|
||||||
const unsigned char *e2data,
|
const unsigned char *e2data,
|
||||||
unsigned long e2len,
|
unsigned long e2len,
|
||||||
const unsigned char *coeffdata,
|
const unsigned char *coeffdata,
|
||||||
unsigned long coefflen);
|
unsigned long coefflen);
|
||||||
int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
int _libssh2_rsa_new_private (libssh2_rsa_ctx **rsa,
|
||||||
LIBSSH2_SESSION *session,
|
LIBSSH2_SESSION *session,
|
||||||
FILE *fp,
|
FILE *fp,
|
||||||
unsigned const char *passphrase);
|
unsigned const char *passphrase);
|
||||||
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa,
|
int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx *rsa,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
unsigned long sig_len,
|
unsigned long sig_len,
|
||||||
const unsigned char *m,
|
const unsigned char *m,
|
||||||
unsigned long m_len);
|
unsigned long m_len);
|
||||||
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION *session,
|
||||||
libssh2_rsa_ctx *rsactx,
|
libssh2_rsa_ctx *rsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len,
|
||||||
unsigned char **signature,
|
unsigned char **signature,
|
||||||
unsigned long *signature_len);
|
unsigned long *signature_len);
|
||||||
|
|
||||||
#define _libssh2_rsa_free(rsactx) RSA_free(rsactx)
|
#define _libssh2_rsa_free(rsactx) RSA_free(rsactx)
|
||||||
|
|
||||||
#define libssh2_dsa_ctx DSA
|
#define libssh2_dsa_ctx DSA
|
||||||
|
|
||||||
int _libssh2_dsa_new(libssh2_dsa_ctx **dsa,
|
int _libssh2_dsa_new(libssh2_dsa_ctx **dsa,
|
||||||
const unsigned char *pdata,
|
const unsigned char *pdata,
|
||||||
unsigned long plen,
|
unsigned long plen,
|
||||||
const unsigned char *qdata,
|
const unsigned char *qdata,
|
||||||
unsigned long qlen,
|
unsigned long qlen,
|
||||||
const unsigned char *gdata,
|
const unsigned char *gdata,
|
||||||
unsigned long glen,
|
unsigned long glen,
|
||||||
const unsigned char *ydata,
|
const unsigned char *ydata,
|
||||||
unsigned long ylen,
|
unsigned long ylen,
|
||||||
const unsigned char *x,
|
const unsigned char *x,
|
||||||
unsigned long x_len);
|
unsigned long x_len);
|
||||||
int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
int _libssh2_dsa_new_private (libssh2_dsa_ctx **dsa,
|
||||||
LIBSSH2_SESSION *session,
|
LIBSSH2_SESSION *session,
|
||||||
FILE *fp,
|
FILE *fp,
|
||||||
unsigned const char *passphrase);
|
unsigned const char *passphrase);
|
||||||
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
int _libssh2_dsa_sha1_verify(libssh2_dsa_ctx *dsactx,
|
||||||
const unsigned char *sig,
|
const unsigned char *sig,
|
||||||
const unsigned char *m,
|
const unsigned char *m,
|
||||||
unsigned long m_len);
|
unsigned long m_len);
|
||||||
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
||||||
const unsigned char *hash,
|
const unsigned char *hash,
|
||||||
unsigned long hash_len,
|
unsigned long hash_len,
|
||||||
unsigned char *sig);
|
unsigned char *sig);
|
||||||
|
|
||||||
#define _libssh2_dsa_free(dsactx) DSA_free(dsactx)
|
#define _libssh2_dsa_free(dsactx) DSA_free(dsactx)
|
||||||
|
|
||||||
@ -206,15 +206,15 @@ int _libssh2_dsa_sha1_sign(libssh2_dsa_ctx *dsactx,
|
|||||||
#define _libssh2_cipher_3des EVP_des_ede3_cbc
|
#define _libssh2_cipher_3des EVP_des_ede3_cbc
|
||||||
|
|
||||||
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
int _libssh2_cipher_init (_libssh2_cipher_ctx *h,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
unsigned char *iv,
|
unsigned char *iv,
|
||||||
unsigned char *secret,
|
unsigned char *secret,
|
||||||
int encrypt);
|
int encrypt);
|
||||||
|
|
||||||
int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
int _libssh2_cipher_crypt(_libssh2_cipher_ctx *ctx,
|
||||||
_libssh2_cipher_type(algo),
|
_libssh2_cipher_type(algo),
|
||||||
int encrypt,
|
int encrypt,
|
||||||
unsigned char *block);
|
unsigned char *block);
|
||||||
|
|
||||||
#define _libssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_cleanup(ctx)
|
#define _libssh2_cipher_dtor(ctx) EVP_CIPHER_CTX_cleanup(ctx)
|
||||||
|
|
||||||
|
1340
src/packet.c
1340
src/packet.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
286
src/pem.c
286
src/pem.c
@ -39,191 +39,191 @@
|
|||||||
|
|
||||||
static int readline (char *line, int line_size, FILE *fp)
|
static int readline (char *line, int line_size, FILE *fp)
|
||||||
{
|
{
|
||||||
if (!fgets(line, line_size, fp))
|
if (!fgets(line, line_size, fp))
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (*line && line[strlen(line) - 1] == '\r')
|
if (*line && line[strlen(line) - 1] == '\r')
|
||||||
{
|
{
|
||||||
line[strlen(line) - 1] = '\0';
|
line[strlen(line) - 1] = '\0';
|
||||||
}
|
}
|
||||||
if (*line && line[strlen(line) - 1] == '\n')
|
if (*line && line[strlen(line) - 1] == '\n')
|
||||||
{
|
{
|
||||||
line[strlen(line) - 1] = '\0';
|
line[strlen(line) - 1] = '\0';
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LINE_SIZE 128
|
#define LINE_SIZE 128
|
||||||
|
|
||||||
int _libssh2_pem_parse (LIBSSH2_SESSION *session,
|
int _libssh2_pem_parse (LIBSSH2_SESSION *session,
|
||||||
const char *headerbegin,
|
const char *headerbegin,
|
||||||
const char *headerend,
|
const char *headerend,
|
||||||
FILE *fp,
|
FILE *fp,
|
||||||
char **data, unsigned int *datalen)
|
char **data, unsigned int *datalen)
|
||||||
{
|
{
|
||||||
char line[LINE_SIZE];
|
char line[LINE_SIZE];
|
||||||
char *b64data = NULL;
|
char *b64data = NULL;
|
||||||
unsigned int b64datalen = 0;
|
unsigned int b64datalen = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (readline(line, LINE_SIZE, fp))
|
if (readline(line, LINE_SIZE, fp))
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (strcmp (line, headerbegin) != 0);
|
while (strcmp (line, headerbegin) != 0);
|
||||||
|
|
||||||
*line = '\0';
|
*line = '\0';
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (*line)
|
if (*line)
|
||||||
{
|
{
|
||||||
char *tmp;
|
char *tmp;
|
||||||
size_t linelen;
|
size_t linelen;
|
||||||
|
|
||||||
linelen = strlen (line);
|
linelen = strlen (line);
|
||||||
tmp = LIBSSH2_REALLOC (session, b64data,
|
tmp = LIBSSH2_REALLOC (session, b64data,
|
||||||
b64datalen + linelen);
|
b64datalen + linelen);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
{
|
{
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
memcpy (tmp + b64datalen, line, linelen);
|
memcpy (tmp + b64datalen, line, linelen);
|
||||||
b64data = tmp;
|
b64data = tmp;
|
||||||
b64datalen += linelen;
|
b64datalen += linelen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readline(line, LINE_SIZE, fp))
|
if (readline(line, LINE_SIZE, fp))
|
||||||
{
|
{
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} while (strcmp (line, headerend) != 0);
|
} while (strcmp (line, headerend) != 0);
|
||||||
|
|
||||||
if (libssh2_base64_decode(session, data, datalen,
|
if (libssh2_base64_decode(session, data, datalen,
|
||||||
b64data, b64datalen))
|
b64data, b64datalen))
|
||||||
{
|
{
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
if (b64data) {
|
if (b64data) {
|
||||||
LIBSSH2_FREE (session, b64data);
|
LIBSSH2_FREE (session, b64data);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_asn1_length (const unsigned char *data,
|
static int read_asn1_length (const unsigned char *data,
|
||||||
unsigned int datalen,
|
unsigned int datalen,
|
||||||
unsigned int *len)
|
unsigned int *len)
|
||||||
{
|
{
|
||||||
unsigned int lenlen;
|
unsigned int lenlen;
|
||||||
int nextpos;
|
int nextpos;
|
||||||
|
|
||||||
if (datalen < 1)
|
if (datalen < 1)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*len = data[0];
|
*len = data[0];
|
||||||
|
|
||||||
if (*len >= 0x80)
|
if (*len >= 0x80)
|
||||||
{
|
{
|
||||||
lenlen = *len & 0x7F;
|
lenlen = *len & 0x7F;
|
||||||
*len = data[1];
|
*len = data[1];
|
||||||
if (1 + lenlen > datalen)
|
if (1 + lenlen > datalen)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (lenlen > 1)
|
if (lenlen > 1)
|
||||||
{
|
{
|
||||||
*len <<= 8;
|
*len <<= 8;
|
||||||
*len |= data[2];
|
*len |= data[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lenlen = 0;
|
lenlen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
nextpos = 1 + lenlen;
|
nextpos = 1 + lenlen;
|
||||||
if (lenlen > 2 || 1 + lenlen + *len > datalen)
|
if (lenlen > 2 || 1 + lenlen + *len > datalen)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nextpos;
|
return nextpos;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_pem_decode_sequence (unsigned char **data, unsigned int *datalen)
|
int _libssh2_pem_decode_sequence (unsigned char **data, unsigned int *datalen)
|
||||||
{
|
{
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
int lenlen;
|
int lenlen;
|
||||||
|
|
||||||
if (*datalen < 1)
|
if (*datalen < 1)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*data)[0] != '\x30')
|
if ((*data)[0] != '\x30')
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*data)++;
|
(*data)++;
|
||||||
(*datalen)--;
|
(*datalen)--;
|
||||||
|
|
||||||
lenlen = read_asn1_length (*data, *datalen, &len);
|
lenlen = read_asn1_length (*data, *datalen, &len);
|
||||||
if (lenlen < 0 || lenlen + len != *datalen)
|
if (lenlen < 0 || lenlen + len != *datalen)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*data += lenlen;
|
*data += lenlen;
|
||||||
*datalen -= lenlen;
|
*datalen -= lenlen;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _libssh2_pem_decode_integer (unsigned char **data, unsigned int *datalen,
|
int _libssh2_pem_decode_integer (unsigned char **data, unsigned int *datalen,
|
||||||
unsigned char **i, unsigned int *ilen)
|
unsigned char **i, unsigned int *ilen)
|
||||||
{
|
{
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
int lenlen;
|
int lenlen;
|
||||||
|
|
||||||
if (*datalen < 1)
|
if (*datalen < 1)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*data)[0] != '\x02')
|
if ((*data)[0] != '\x02')
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*data)++;
|
(*data)++;
|
||||||
(*datalen)--;
|
(*datalen)--;
|
||||||
|
|
||||||
lenlen = read_asn1_length (*data, *datalen, &len);
|
lenlen = read_asn1_length (*data, *datalen, &len);
|
||||||
if (lenlen < 0 || lenlen + len > *datalen)
|
if (lenlen < 0 || lenlen + len > *datalen)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*data += lenlen;
|
*data += lenlen;
|
||||||
*datalen -= lenlen;
|
*datalen -= lenlen;
|
||||||
|
|
||||||
*i = *data;
|
*i = *data;
|
||||||
*ilen = len;
|
*ilen = len;
|
||||||
|
|
||||||
*data += len;
|
*data += len;
|
||||||
*datalen -= len;
|
*datalen -= len;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
1032
src/publickey.c
1032
src/publickey.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
644
src/scp.c
644
src/scp.c
@ -39,289 +39,289 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define LIBSSH2_SCP_RESPONSE_BUFLEN 256
|
#define LIBSSH2_SCP_RESPONSE_BUFLEN 256
|
||||||
|
|
||||||
/* {{{ libssh2_scp_recv
|
/* {{{ libssh2_scp_recv
|
||||||
* [BLOCKING]
|
* [BLOCKING]
|
||||||
* Open a channel and request a remote file via SCP
|
* Open a channel and request a remote file via SCP
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
|
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
|
||||||
const char *path,
|
const char *path,
|
||||||
struct stat *sb)
|
struct stat *sb)
|
||||||
{
|
{
|
||||||
int path_len = strlen(path);
|
int path_len = strlen(path);
|
||||||
unsigned char *command, response[LIBSSH2_SCP_RESPONSE_BUFLEN];
|
unsigned char *command, response[LIBSSH2_SCP_RESPONSE_BUFLEN];
|
||||||
unsigned long command_len = path_len + sizeof("scp -f "), response_len;
|
unsigned long command_len = path_len + sizeof("scp -f "), response_len;
|
||||||
LIBSSH2_CHANNEL *channel;
|
LIBSSH2_CHANNEL *channel;
|
||||||
long mode = 0, size = 0, mtime = 0, atime = 0;
|
long mode = 0, size = 0, mtime = 0, atime = 0;
|
||||||
|
|
||||||
if (sb) {
|
if (sb) {
|
||||||
command_len++;
|
command_len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
command = LIBSSH2_ALLOC(session, command_len);
|
command = LIBSSH2_ALLOC(session, command_len);
|
||||||
if (!command) {
|
if (!command) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate a command buffer for scp session", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate a command buffer for scp session", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (sb) {
|
if (sb) {
|
||||||
memcpy(command, "scp -pf ", sizeof("scp -pf ") - 1);
|
memcpy(command, "scp -pf ", sizeof("scp -pf ") - 1);
|
||||||
memcpy(command + sizeof("scp -pf ") - 1, path, path_len);
|
memcpy(command + sizeof("scp -pf ") - 1, path, path_len);
|
||||||
} else {
|
} else {
|
||||||
memcpy(command, "scp -f ", sizeof("scp -f ") - 1);
|
memcpy(command, "scp -f ", sizeof("scp -f ") - 1);
|
||||||
memcpy(command + sizeof("scp -f ") - 1, path, path_len);
|
memcpy(command + sizeof("scp -f ") - 1, path, path_len);
|
||||||
}
|
}
|
||||||
command[command_len - 1] = '\0';
|
command[command_len - 1] = '\0';
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Opening channel for SCP receive");
|
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Opening channel for SCP receive");
|
||||||
/* Allocate a channel */
|
/* Allocate a channel */
|
||||||
if ((channel = libssh2_channel_open_session(session)) == NULL) {
|
if ((channel = libssh2_channel_open_session(session)) == NULL) {
|
||||||
LIBSSH2_FREE(session, command);
|
LIBSSH2_FREE(session, command);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Use blocking I/O for negotiation phase */
|
/* Use blocking I/O for negotiation phase */
|
||||||
libssh2_channel_set_blocking(channel, 1);
|
libssh2_channel_set_blocking(channel, 1);
|
||||||
|
|
||||||
/* Request SCP for the desired file */
|
/* Request SCP for the desired file */
|
||||||
if (libssh2_channel_process_startup(channel, "exec", sizeof("exec") - 1, command, command_len)) {
|
if (libssh2_channel_process_startup(channel, "exec", sizeof("exec") - 1, command, command_len)) {
|
||||||
LIBSSH2_FREE(session, command);
|
LIBSSH2_FREE(session, command);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
LIBSSH2_FREE(session, command);
|
LIBSSH2_FREE(session, command);
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Sending initial wakeup");
|
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Sending initial wakeup");
|
||||||
/* SCP ACK */
|
/* SCP ACK */
|
||||||
response[0] = '\0';
|
response[0] = '\0';
|
||||||
if (libssh2_channel_write(channel, response, 1) != 1) {
|
if (libssh2_channel_write(channel, response, 1) != 1) {
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse SCP response */
|
/* Parse SCP response */
|
||||||
response_len = 0;
|
response_len = 0;
|
||||||
while (sb && (response_len < LIBSSH2_SCP_RESPONSE_BUFLEN)) {
|
while (sb && (response_len < LIBSSH2_SCP_RESPONSE_BUFLEN)) {
|
||||||
unsigned char *s, *p;
|
unsigned char *s, *p;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = _libssh2_channel_read(channel, response + response_len, 1);
|
rc = _libssh2_channel_read(channel, response + response_len, 1);
|
||||||
if(rc <= 0) {
|
if(rc <= 0) {
|
||||||
/* Timeout, give up */
|
/* Timeout, give up */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Timed out waiting for SCP response", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Timed out waiting for SCP response", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
response_len++;
|
response_len++;
|
||||||
|
|
||||||
if (response[0] != 'T') {
|
if (response[0] != 'T') {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid data in SCP response, missing Time data", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid data in SCP response, missing Time data", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((response_len > 1) &&
|
if ((response_len > 1) &&
|
||||||
((response[response_len-1] < '0') || (response[response_len-1] > '9')) &&
|
((response[response_len-1] < '0') || (response[response_len-1] > '9')) &&
|
||||||
(response[response_len-1] != ' ') &&
|
(response[response_len-1] != ' ') &&
|
||||||
(response[response_len-1] != '\r') &&
|
(response[response_len-1] != '\r') &&
|
||||||
(response[response_len-1] != '\n')) {
|
(response[response_len-1] != '\n')) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid data in SCP response", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid data in SCP response", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((response_len < 9) || (response[response_len-1] != '\n')) {
|
if ((response_len < 9) || (response[response_len-1] != '\n')) {
|
||||||
if (response_len == LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
if (response_len == LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
||||||
/* You had your chance */
|
/* You had your chance */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Unterminated response from SCP server", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Unterminated response from SCP server", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Way too short to be an SCP response, or not done yet, short circuit */
|
/* Way too short to be an SCP response, or not done yet, short circuit */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We're guaranteed not to go under response_len == 0 by the logic above */
|
/* We're guaranteed not to go under response_len == 0 by the logic above */
|
||||||
while ((response[response_len-1] == '\r') || (response[response_len-1] == '\n')) response_len--;
|
while ((response[response_len-1] == '\r') || (response[response_len-1] == '\n')) response_len--;
|
||||||
response[response_len] = '\0';
|
response[response_len] = '\0';
|
||||||
|
|
||||||
if (response_len < 8) {
|
if (response_len < 8) {
|
||||||
/* EOL came too soon */
|
/* EOL came too soon */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = response + 1;
|
s = response + 1;
|
||||||
|
|
||||||
p = strchr(s, ' ');
|
p = strchr(s, ' ');
|
||||||
if (!p || ((p - s) <= 0)) {
|
if (!p || ((p - s) <= 0)) {
|
||||||
/* No spaces or space in the wrong spot */
|
/* No spaces or space in the wrong spot */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, malformed mtime", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, malformed mtime", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(p++) = '\0';
|
*(p++) = '\0';
|
||||||
/* Make sure we don't get fooled by leftover values */
|
/* Make sure we don't get fooled by leftover values */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
mtime = strtol(s, NULL, 10);
|
mtime = strtol(s, NULL, 10);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid mtime", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid mtime", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
s = strchr(p, ' ');
|
s = strchr(p, ' ');
|
||||||
if (!s || ((s - p) <= 0)) {
|
if (!s || ((s - p) <= 0)) {
|
||||||
/* No spaces or space in the wrong spot */
|
/* No spaces or space in the wrong spot */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, malformed mtime.usec", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, malformed mtime.usec", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ignore mtime.usec */
|
/* Ignore mtime.usec */
|
||||||
s++;
|
s++;
|
||||||
p = strchr(s, ' ');
|
p = strchr(s, ' ');
|
||||||
if (!p || ((p - s) <= 0)) {
|
if (!p || ((p - s) <= 0)) {
|
||||||
/* No spaces or space in the wrong spot */
|
/* No spaces or space in the wrong spot */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short or malformed", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short or malformed", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(p++) = '\0';
|
*(p++) = '\0';
|
||||||
/* Make sure we don't get fooled by leftover values */
|
/* Make sure we don't get fooled by leftover values */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
atime = strtol(s, NULL, 10);
|
atime = strtol(s, NULL, 10);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid atime", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid atime", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SCP ACK */
|
/* SCP ACK */
|
||||||
response[0] = '\0';
|
response[0] = '\0';
|
||||||
if (libssh2_channel_write(channel, response, 1) != 1) {
|
if (libssh2_channel_write(channel, response, 1) != 1) {
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "mtime = %ld, atime = %ld", mtime, atime);
|
_libssh2_debug(session, LIBSSH2_DBG_SCP, "mtime = %ld, atime = %ld", mtime, atime);
|
||||||
|
|
||||||
/* We *should* check that atime.usec is valid, but why let that stop use? */
|
/* We *should* check that atime.usec is valid, but why let that stop use? */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
response_len = 0;
|
response_len = 0;
|
||||||
while (response_len < LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
while (response_len < LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
||||||
char *s, *p, *e = NULL;
|
char *s, *p, *e = NULL;
|
||||||
|
|
||||||
if (_libssh2_channel_read(channel, response + response_len, 1) <= 0) {
|
if (_libssh2_channel_read(channel, response + response_len, 1) <= 0) {
|
||||||
/* Timeout, give up */
|
/* Timeout, give up */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Timed out waiting for SCP response", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Timed out waiting for SCP response", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
response_len++;
|
response_len++;
|
||||||
|
|
||||||
if (response[0] != 'C') {
|
if (response[0] != 'C') {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((response_len > 1) &&
|
if ((response_len > 1) &&
|
||||||
(response[response_len-1] != '\r') &&
|
(response[response_len-1] != '\r') &&
|
||||||
(response[response_len-1] != '\n') &&
|
(response[response_len-1] != '\n') &&
|
||||||
((response[response_len-1] < 32) || (response[response_len-1] > 126))) {
|
((response[response_len-1] < 32) || (response[response_len-1] > 126))) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid data in SCP response", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid data in SCP response", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((response_len < 7) || (response[response_len-1] != '\n')) {
|
if ((response_len < 7) || (response[response_len-1] != '\n')) {
|
||||||
if (response_len == LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
if (response_len == LIBSSH2_SCP_RESPONSE_BUFLEN) {
|
||||||
/* You had your chance */
|
/* You had your chance */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Unterminated response from SCP server", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Unterminated response from SCP server", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Way too short to be an SCP response, or not done yet, short circuit */
|
/* Way too short to be an SCP response, or not done yet, short circuit */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We're guaranteed not to go under response_len == 0 by the logic above */
|
/* We're guaranteed not to go under response_len == 0 by the logic above */
|
||||||
while ((response[response_len-1] == '\r') || (response[response_len-1] == '\n')) response_len--;
|
while ((response[response_len-1] == '\r') || (response[response_len-1] == '\n')) response_len--;
|
||||||
response[response_len] = '\0';
|
response[response_len] = '\0';
|
||||||
|
|
||||||
if (response_len < 6) {
|
if (response_len < 6) {
|
||||||
/* EOL came too soon */
|
/* EOL came too soon */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = response + 1;
|
s = response + 1;
|
||||||
|
|
||||||
p = strchr(s, ' ');
|
p = strchr(s, ' ');
|
||||||
if (!p || ((p - s) <= 0)) {
|
if (!p || ((p - s) <= 0)) {
|
||||||
/* No spaces or space in the wrong spot */
|
/* No spaces or space in the wrong spot */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, malformed mode", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, malformed mode", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(p++) = '\0';
|
*(p++) = '\0';
|
||||||
/* Make sure we don't get fooled by leftover values */
|
/* Make sure we don't get fooled by leftover values */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
mode = strtol(s, &e, 8);
|
mode = strtol(s, &e, 8);
|
||||||
if ((e && *e) || errno) {
|
if ((e && *e) || errno) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid mode", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid mode", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = strchr(p, ' ');
|
s = strchr(p, ' ');
|
||||||
if (!s || ((s - p) <= 0)) {
|
if (!s || ((s - p) <= 0)) {
|
||||||
/* No spaces or space in the wrong spot */
|
/* No spaces or space in the wrong spot */
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short or malformed", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, too short or malformed", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(s++) = '\0';
|
*(s++) = '\0';
|
||||||
/* Make sure we don't get fooled by leftover values */
|
/* Make sure we don't get fooled by leftover values */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
size = strtol(p, &e, 10);
|
size = strtol(p, &e, 10);
|
||||||
if ((e && *e) || errno) {
|
if ((e && *e) || errno) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid size", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid response from SCP server, invalid size", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SCP ACK */
|
/* SCP ACK */
|
||||||
response[0] = '\0';
|
response[0] = '\0';
|
||||||
if (libssh2_channel_write(channel, response, 1) != 1) {
|
if (libssh2_channel_write(channel, response, 1) != 1) {
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "mod = 0%lo size = %ld", mode, size);
|
_libssh2_debug(session, LIBSSH2_DBG_SCP, "mod = 0%lo size = %ld", mode, size);
|
||||||
|
|
||||||
/* We *should* check that basename is valid, but why let that stop us? */
|
/* We *should* check that basename is valid, but why let that stop us? */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sb) {
|
if (sb) {
|
||||||
memset(sb, 0, sizeof(struct stat));
|
memset(sb, 0, sizeof(struct stat));
|
||||||
|
|
||||||
sb->st_mtime = mtime;
|
sb->st_mtime = mtime;
|
||||||
sb->st_atime = atime;
|
sb->st_atime = atime;
|
||||||
sb->st_size = size;
|
sb->st_size = size;
|
||||||
sb->st_mode = mode;
|
sb->st_mode = mode;
|
||||||
}
|
}
|
||||||
/* Revert to non-blocking and let the data BEGIN! */
|
/* Revert to non-blocking and let the data BEGIN! */
|
||||||
libssh2_channel_set_blocking(channel, 0);
|
libssh2_channel_set_blocking(channel, 0);
|
||||||
|
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
@ -330,101 +330,101 @@ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session,
|
|||||||
*/
|
*/
|
||||||
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t size, long mtime, long atime)
|
LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_send_ex(LIBSSH2_SESSION *session, const char *path, int mode, size_t size, long mtime, long atime)
|
||||||
{
|
{
|
||||||
int path_len = strlen(path);
|
int path_len = strlen(path);
|
||||||
unsigned char *command, response[LIBSSH2_SCP_RESPONSE_BUFLEN];
|
unsigned char *command, response[LIBSSH2_SCP_RESPONSE_BUFLEN];
|
||||||
unsigned long response_len, command_len = path_len + sizeof("scp -t ");
|
unsigned long response_len, command_len = path_len + sizeof("scp -t ");
|
||||||
unsigned const char *base;
|
unsigned const char *base;
|
||||||
LIBSSH2_CHANNEL *channel;
|
LIBSSH2_CHANNEL *channel;
|
||||||
|
|
||||||
if (mtime || atime) {
|
if (mtime || atime) {
|
||||||
command_len++;
|
command_len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
command = LIBSSH2_ALLOC(session, command_len);
|
command = LIBSSH2_ALLOC(session, command_len);
|
||||||
if (!command) {
|
if (!command) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate a command buffer for scp session", 0);
|
libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate a command buffer for scp session", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mtime || atime) {
|
if (mtime || atime) {
|
||||||
memcpy(command, "scp -pt ", sizeof("scp -pt ") - 1);
|
memcpy(command, "scp -pt ", sizeof("scp -pt ") - 1);
|
||||||
memcpy(command + sizeof("scp -pt ") - 1, path, path_len);
|
memcpy(command + sizeof("scp -pt ") - 1, path, path_len);
|
||||||
} else {
|
} else {
|
||||||
memcpy(command, "scp -t ", sizeof("scp -t ") - 1);
|
memcpy(command, "scp -t ", sizeof("scp -t ") - 1);
|
||||||
memcpy(command + sizeof("scp -t ") - 1, path, path_len);
|
memcpy(command + sizeof("scp -t ") - 1, path, path_len);
|
||||||
}
|
}
|
||||||
command[command_len - 1] = '\0';
|
command[command_len - 1] = '\0';
|
||||||
|
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Opening channel for SCP send");
|
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Opening channel for SCP send");
|
||||||
/* Allocate a channel */
|
/* Allocate a channel */
|
||||||
if ((channel = libssh2_channel_open_session(session)) == NULL) {
|
if ((channel = libssh2_channel_open_session(session)) == NULL) {
|
||||||
/* previous call set libssh2_session_last_error(), pass it through */
|
/* previous call set libssh2_session_last_error(), pass it through */
|
||||||
LIBSSH2_FREE(session, command);
|
LIBSSH2_FREE(session, command);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Use blocking I/O for negotiation phase */
|
/* Use blocking I/O for negotiation phase */
|
||||||
libssh2_channel_set_blocking(channel, 1);
|
libssh2_channel_set_blocking(channel, 1);
|
||||||
|
|
||||||
/* Request SCP for the desired file */
|
/* Request SCP for the desired file */
|
||||||
if (libssh2_channel_process_startup(channel, "exec", sizeof("exec") - 1, command, command_len)) {
|
if (libssh2_channel_process_startup(channel, "exec", sizeof("exec") - 1, command, command_len)) {
|
||||||
/* previous call set libssh2_session_last_error(), pass it through */
|
/* previous call set libssh2_session_last_error(), pass it through */
|
||||||
LIBSSH2_FREE(session, command);
|
LIBSSH2_FREE(session, command);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
LIBSSH2_FREE(session, command);
|
LIBSSH2_FREE(session, command);
|
||||||
|
|
||||||
/* Wait for ACK */
|
/* Wait for ACK */
|
||||||
if ((_libssh2_channel_read(channel, response, 1) <= 0) || (response[0] != 0)) {
|
if ((_libssh2_channel_read(channel, response, 1) <= 0) || (response[0] != 0)) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send mtime and atime to be used for file */
|
/* Send mtime and atime to be used for file */
|
||||||
if (mtime || atime) {
|
if (mtime || atime) {
|
||||||
response_len = snprintf(response, LIBSSH2_SCP_RESPONSE_BUFLEN, "T%ld 0 %ld 0\n", mtime, atime);
|
response_len = snprintf(response, LIBSSH2_SCP_RESPONSE_BUFLEN, "T%ld 0 %ld 0\n", mtime, atime);
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Sent %s", response);
|
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Sent %s", response);
|
||||||
|
|
||||||
if (libssh2_channel_write(channel, response, response_len) != response_len) {
|
if (libssh2_channel_write(channel, response, response_len) != response_len) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send time data for SCP file", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send time data for SCP file", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Wait for ACK */
|
/* Wait for ACK */
|
||||||
if ((_libssh2_channel_read(channel, response, 1) <= 0) || (response[0] != 0)) {
|
if ((_libssh2_channel_read(channel, response, 1) <= 0) || (response[0] != 0)) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send mode, size, and basename */
|
/* Send mode, size, and basename */
|
||||||
base = strrchr(path, '/');
|
base = strrchr(path, '/');
|
||||||
if (base) {
|
if (base) {
|
||||||
base++;
|
base++;
|
||||||
} else {
|
} else {
|
||||||
base = path;
|
base = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
response_len = snprintf(response, LIBSSH2_SCP_RESPONSE_BUFLEN, "C0%o %lu %s\n", mode, (unsigned long)size, base);
|
response_len = snprintf(response, LIBSSH2_SCP_RESPONSE_BUFLEN, "C0%o %lu %s\n", mode, (unsigned long)size, base);
|
||||||
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Sent %s", response);
|
_libssh2_debug(session, LIBSSH2_DBG_SCP, "Sent %s", response);
|
||||||
if (libssh2_channel_write(channel, response, response_len) != response_len) {
|
if (libssh2_channel_write(channel, response, response_len) != response_len) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send core file data for SCP file", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send core file data for SCP file", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Wait for ACK */
|
/* Wait for ACK */
|
||||||
if ((_libssh2_channel_read(channel, response, 1) <= 0) || (response[0] != 0)) {
|
if ((_libssh2_channel_read(channel, response, 1) <= 0) || (response[0] != 0)) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote", 0);
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL, "Invalid ACK response from remote", 0);
|
||||||
libssh2_channel_free(channel);
|
libssh2_channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ready to start, switch to non-blocking and let calling app send file */
|
/* Ready to start, switch to non-blocking and let calling app send file */
|
||||||
libssh2_channel_set_blocking(channel, 0);
|
libssh2_channel_set_blocking(channel, 0);
|
||||||
|
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
1306
src/session.c
1306
src/session.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
1572
src/sftp.c
1572
src/sftp.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
1126
src/transport.c
1126
src/transport.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
1218
src/userauth.c
1218
src/userauth.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
x
Ссылка в новой задаче
Block a user