1
1
Этот коммит содержится в:
Andreas Schneider 2009-07-30 10:45:58 +02:00
родитель 94a57df0c9
Коммит 766bae9d76
16 изменённых файлов: 153 добавлений и 113 удалений

Просмотреть файл

@ -29,6 +29,13 @@
#ifndef _LIBSSH_PRIV_H
#define _LIBSSH_PRIV_H
#ifdef _MSC_VER
#define snprintf _snprintf
#else
#include <unistd.h>
#endif
#include "config.h"
#include "libssh/libssh.h"
@ -172,13 +179,19 @@ void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
/* strings and buffers */
/* must be 32 bits number + immediatly our data */
#ifdef _MSC_VER
#pragma pack(1)
#endif
struct ssh_string_struct {
uint32_t size;
unsigned char string[MAX_PACKET_LEN];
}
#if !defined(__SUNPRO_C)
#if !defined(__SUNPRO_C) && !defined(_MSC_VER)
__attribute__ ((packed))
#endif
#ifdef _MSC_VER
#pragma pack()
#endif
;
/** Describes a buffer state at a moment

Просмотреть файл

@ -38,7 +38,11 @@
#ifndef SFTP_H
#define SFTP_H
#include <libssh/libssh.h>
#include <sys/types.h>
#include "libssh.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -51,11 +55,19 @@ extern "C" {
#ifdef _WIN32
#ifndef uid_t
typedef long uid_t;
typedef uint32_t uid_t;
#endif /* uid_t */
#ifndef gid_t
typedef long gid_t;
typedef uint32_t gid_t;
#endif /* gid_t */
#ifdef _MSC_VER
#ifndef mode_t
typedef uint32_t mode_t;
#endif /* mode_t */
#ifndef ssize_t
typedef _W64 signed int ssize_t;
#endif /* ssize_t */
#endif /* _MSC_VER */
#endif /* _WIN32 */
typedef struct sftp_ext_struct *sftp_ext;

Просмотреть файл

@ -750,6 +750,22 @@ error:
return rc;
}
#ifdef _MSC_VER
static const char privKey_1[] = "%s/.ssh/identity";
static const char pubKey_1[] = "%s/.ssh/identity.pub";
static const char privKey_2[] = "%s/.ssh/id_dsa";
static const char pubKey_2[] = "%s/.ssh/id_dsa.pub";
static const char privKey_3[] = "%s/.ssh/id_rsa";
static const char pubKey_3[] = "%s/.ssh/id_rsa.pub";
/** Used different var to allow const char[] declaration */
static struct ssh_keys_struct keytab[] = {
{ privKey_1, pubKey_1},
{ privKey_2, pubKey_2},
{ privKey_3, pubKey_3},
{0}
};
#else
/* This requires GCC extensions */
static struct ssh_keys_struct keytab[] = {
{
.privatekey = "%s/.ssh/identity",
@ -768,9 +784,7 @@ static struct ssh_keys_struct keytab[] = {
.publickey = NULL
}
};
/* this function initialy was in the client */
/* but the fools are the ones who never change mind */
#endif
/**
* @brief Tries to automaticaly authenticate with public key and "none"

Просмотреть файл

@ -24,7 +24,6 @@
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
@ -929,7 +928,7 @@ int channel_write_common(ssh_channel channel, const void *data,
channel->remote_window -= effectivelen;
len -= effectivelen;
data += effectivelen;
data = ((uint8_t*)data + effectivelen);
}
leave_function();

Просмотреть файл

@ -26,7 +26,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef _WIN32
/* getaddrinfo, freeaddrinfo, getnameinfo */
@ -93,6 +92,7 @@ static void sock_set_nonblocking(socket_t sock) {
static void sock_set_blocking(socket_t sock) {
fcntl(sock, F_SETFL, 0);
}
#endif /* _WIN32 */
#ifdef HAVE_REGCOMP

Просмотреть файл

@ -21,7 +21,6 @@
* MA 02111-1307, USA.
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

Просмотреть файл

@ -25,7 +25,6 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <ctype.h>

Просмотреть файл

@ -24,7 +24,6 @@
#include <limits.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
@ -33,8 +32,8 @@
#ifdef _WIN32
#define _WIN32_IE 0x0400 //SHGetSpecialFolderPath
#include <winsock2.h> // Must be the first to include
#include <shlobj.h>
#include <winsock2.h>
#else
#include <pwd.h>
#include <arpa/inet.h>
@ -67,7 +66,6 @@
* @{ */
#ifdef _WIN32
char *ssh_get_user_home_dir(void) {
static char szPath[MAX_PATH] = {0};
@ -77,7 +75,7 @@ char *ssh_get_user_home_dir(void) {
return NULL;
}
/* we have read access on file */
int ssh_file_readaccess_ok(const char *file) {
if (_access(file, 4) < 0) {
@ -85,9 +83,8 @@ char *ssh_get_user_home_dir(void) {
}
return 1;
}
}
#else /* _WIN32 */
char *ssh_get_user_home_dir(void) {
static char szPath[PATH_MAX] = {0};
struct passwd *pwd = NULL;
@ -102,8 +99,6 @@ char *ssh_get_user_home_dir(void) {
return szPath;
}
#endif
/* we have read access on file */
int ssh_file_readaccess_ok(const char *file) {
if (access(file, R_OK) < 0) {
@ -112,13 +107,14 @@ int ssh_file_readaccess_ok(const char *file) {
return 1;
}
#endif
uint64_t ntohll(uint64_t a) {
#ifdef WORDS_BIGENDIAN
return a;
#else
uint32_t low = a & 0xffffffff;
uint32_t high = a >> 32 ;
uint32_t low = (uint32_t)(a & 0xffffffff);
uint32_t high = (uint32_t)(a >> 32);
low = ntohl(low);
high = ntohl(high);

Просмотреть файл

@ -24,10 +24,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#ifndef _WIN32
#include <pwd.h>
#else
#include <winsock2.h>
#endif
#include <sys/types.h>
#include "libssh/priv.h"
@ -589,6 +590,7 @@ int ssh_options_default_username(SSH_OPTIONS *opt) {
return 0;
}
#else
{
DWORD Size = 0;
GetUserName(NULL, &Size); //Get Size
user = malloc(Size);
@ -601,6 +603,7 @@ int ssh_options_default_username(SSH_OPTIONS *opt) {
} else {
SAFE_FREE(user);
}
}
#endif
return -1;
}
@ -836,7 +839,10 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv) {
int ssh1 = 0;
#endif
int ssh2 = 1;
#ifdef _MSC_VER
/* Not supported with a Microsoft compiler */
return -1;
#else
int saveoptind = optind; /* need to save 'em */
int saveopterr = opterr;
@ -985,6 +991,7 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv) {
}
return 0;
#endif
}
/**

Просмотреть файл

@ -23,7 +23,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
@ -148,7 +147,7 @@ static int packet_read2(SSH_SESSION *session) {
* have been decrypted)
*/
if (packet_decrypt(session,
buffer_get(session->in_buffer) + blocksize,
((uint8_t*)buffer_get(session->in_buffer) + blocksize),
buffer_get_len(session->in_buffer) - blocksize) < 0) {
ssh_set_error(session, SSH_FATAL, "Decrypt error");
goto error;

Просмотреть файл

@ -81,6 +81,7 @@ int ssh_poll(pollfd_t *fds, nfds_t nfds, int timeout) {
#include <stdio.h>
#include <windows.h>
#include <errno.h>
static int poll_rest (HANDLE *handles, int nhandles,
pollfd_t *fds, nfds_t nfds, int timeout) {

Просмотреть файл

@ -32,7 +32,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "libssh/priv.h"
#include "libssh/libssh.h"
@ -45,7 +44,7 @@
#define SOCKOPT_TYPE_ARG4 char
/* We need to provide hstrerror. Not we can't call the parameter h_errno because it's #defined */
inline char *hstrerror(int h_errno_val) {
static char *hstrerror(int h_errno_val) {
static char text[50] = {0};
snprintf(text, sizeof(text), "gethostbyname error %d\n", h_errno_val);

Просмотреть файл

@ -21,7 +21,6 @@
* MA 02111-1307, USA.
*/
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

Просмотреть файл

@ -21,7 +21,6 @@
* MA 02111-1307, USA.
*/
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
@ -264,7 +263,7 @@ int ssh_socket_completeread(struct socket *s, void *buffer, uint32_t len) {
return SSH_ERROR;
}
while((r = ssh_socket_unbuffered_read(s, buffer + total, toread))) {
while((r = ssh_socket_unbuffered_read(s, ((uint8_t*)buffer + total), toread))) {
if (r < 0) {
return SSH_ERROR;
}
@ -303,7 +302,7 @@ int ssh_socket_completewrite(struct socket *s, const void *buffer, uint32_t len)
return SSH_ERROR;
}
len -= written;
buffer += written;
buffer = ((uint8_t*)buffer + written);
}
leave_function();

Просмотреть файл

@ -22,7 +22,6 @@
*/
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#ifndef _WIN32

Просмотреть файл

@ -577,11 +577,11 @@ static int des3_set_key(struct crypto_struct *cipher, void *key) {
}
DES_set_odd_parity(key);
DES_set_odd_parity(key + 8);
DES_set_odd_parity(key + 16);
DES_set_odd_parity((void*)((uint8_t*)key + 8));
DES_set_odd_parity((void*)((uint8_t*)key + 16));
DES_set_key_unchecked(key, cipher->key);
DES_set_key_unchecked(key + 8, cipher->key + sizeof(DES_key_schedule));
DES_set_key_unchecked(key + 16, cipher->key + 2 * sizeof(DES_key_schedule));
DES_set_key_unchecked((void*)((uint8_t*)key + 8), (void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)));
DES_set_key_unchecked((void*)((uint8_t*)key + 16), (void*)((uint8_t*)cipher->key + 2 * sizeof(DES_key_schedule)));
}
return 0;
@ -590,16 +590,16 @@ static int des3_set_key(struct crypto_struct *cipher, void *key) {
static void des3_encrypt(struct crypto_struct *cipher, void *in,
void *out, unsigned long len, void *IV) {
DES_ede3_cbc_encrypt(in, out, len, cipher->key,
cipher->key + sizeof(DES_key_schedule),
cipher->key + 2 * sizeof(DES_key_schedule),
(void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)),
(void*)((uint8_t*)cipher->key + 2 * sizeof(DES_key_schedule)),
IV, 1);
}
static void des3_decrypt(struct crypto_struct *cipher, void *in,
void *out, unsigned long len, void *IV) {
DES_ede3_cbc_encrypt(in, out, len, cipher->key,
cipher->key + sizeof(DES_key_schedule),
cipher->key + 2 * sizeof(DES_key_schedule),
(void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)),
(void*)((uint8_t*)cipher->key + 2 * sizeof(DES_key_schedule)),
IV, 0);
}
@ -609,10 +609,10 @@ static void des3_1_encrypt(struct crypto_struct *cipher, void *in,
ssh_print_hexa("Encrypt IV before", IV, 24);
#endif
DES_ncbc_encrypt(in, out, len, cipher->key, IV, 1);
DES_ncbc_encrypt(out, in, len, cipher->key + sizeof(DES_key_schedule),
IV + 8, 0);
DES_ncbc_encrypt(in, out, len, cipher->key + 2 * sizeof(DES_key_schedule),
IV + 16, 1);
DES_ncbc_encrypt(out, in, len, (void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)),
(void*)((uint8_t*)IV + 8), 0);
DES_ncbc_encrypt(in, out, len, (void*)((uint8_t*)cipher->key + 2 * sizeof(DES_key_schedule)),
(void*)((uint8_t*)IV + 16), 1);
#ifdef DEBUG_CRYPTO
ssh_print_hexa("Encrypt IV after", IV, 24);
#endif
@ -624,11 +624,11 @@ static void des3_1_decrypt(struct crypto_struct *cipher, void *in,
ssh_print_hexa("Decrypt IV before", IV, 24);
#endif
DES_ncbc_encrypt(in, out, len, cipher->key + 2 * sizeof(DES_key_schedule),
DES_ncbc_encrypt(in, out, len, (void*)((uint8_t*)cipher->key + 2 * sizeof(DES_key_schedule)),
IV, 0);
DES_ncbc_encrypt(out, in, len, cipher->key + sizeof(DES_key_schedule),
IV + 8, 1);
DES_ncbc_encrypt(in, out, len, cipher->key, IV + 16, 0);
DES_ncbc_encrypt(out, in, len, (void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)),
(void*)((uint8_t*)IV + 8), 1);
DES_ncbc_encrypt(in, out, len, cipher->key, (void*)((uint8_t*)IV + 16), 0);
#ifdef DEBUG_CRYPTO
ssh_print_hexa("Decrypt IV after", IV, 24);
@ -637,90 +637,95 @@ static void des3_1_decrypt(struct crypto_struct *cipher, void *in,
#endif /* HAS_DES */
/* the table of supported ciphers */
/*
* The table of supported ciphers
*
* WARNING: If you modify crypto_struct, you must make sure the order is
* correct!
*/
static struct crypto_struct ssh_ciphertab[] = {
#ifdef HAS_BLOWFISH
{
.name = "blowfish-cbc",
.blocksize = 8,
.keylen = sizeof (BF_KEY),
.key = NULL,
.keysize = 128,
.set_encrypt_key = blowfish_set_key,
.set_decrypt_key = blowfish_set_key,
.cbc_encrypt = blowfish_encrypt,
.cbc_decrypt = blowfish_decrypt
"blowfish-cbc",
8,
sizeof (BF_KEY),
NULL,
128,
blowfish_set_key,
blowfish_set_key,
blowfish_encrypt,
blowfish_decrypt
},
#endif /* HAS_BLOWFISH */
#ifdef HAS_AES
{
.name = "aes128-cbc",
.blocksize = 16,
.keylen = sizeof(AES_KEY),
.key = NULL,
.keysize = 128,
.set_encrypt_key = aes_set_encrypt_key,
.set_decrypt_key = aes_set_decrypt_key,
.cbc_encrypt = aes_encrypt,
.cbc_decrypt = aes_decrypt
"aes128-cbc",
16,
sizeof(AES_KEY),
NULL,
128,
aes_set_encrypt_key,
aes_set_decrypt_key,
aes_encrypt,
aes_decrypt
},
{
.name = "aes192-cbc",
.blocksize = 16,
.keylen = sizeof(AES_KEY),
.key = NULL,
.keysize = 192,
.set_encrypt_key = aes_set_encrypt_key,
.set_decrypt_key = aes_set_decrypt_key,
.cbc_encrypt = aes_encrypt,
.cbc_decrypt = aes_decrypt
"aes192-cbc",
16,
sizeof(AES_KEY),
NULL,
192,
aes_set_encrypt_key,
aes_set_decrypt_key,
aes_encrypt,
aes_decrypt
},
{
.name = "aes256-cbc",
.blocksize = 16,
.keylen = sizeof(AES_KEY),
.key = NULL,
.keysize = 256,
.set_encrypt_key = aes_set_encrypt_key,
.set_decrypt_key = aes_set_decrypt_key,
.cbc_encrypt = aes_encrypt,
.cbc_decrypt = aes_decrypt
"aes256-cbc",
16,
sizeof(AES_KEY),
NULL,
256,
aes_set_encrypt_key,
aes_set_decrypt_key,
aes_encrypt,
aes_decrypt
},
#endif /* HAS_AES */
#ifdef HAS_DES
{
.name = "3des-cbc",
.blocksize = 8,
.keylen = sizeof(DES_key_schedule) * 3,
.key = NULL,
.keysize = 192,
.set_encrypt_key = des3_set_key,
.set_decrypt_key = des3_set_key,
.cbc_encrypt = des3_encrypt,
.cbc_decrypt = des3_decrypt
"3des-cbc",
8,
sizeof(DES_key_schedule) * 3,
NULL,
192,
des3_set_key,
des3_set_key,
des3_encrypt,
des3_decrypt
},
{
.name = "3des-cbc-ssh1",
.blocksize = 8,
.keylen = sizeof(DES_key_schedule) * 3,
.key = NULL,
.keysize = 192,
.set_encrypt_key = des3_set_key,
.set_decrypt_key = des3_set_key,
.cbc_encrypt = des3_1_encrypt,
.cbc_decrypt = des3_1_decrypt
"3des-cbc-ssh1",
8,
sizeof(DES_key_schedule) * 3,
NULL,
192,
des3_set_key,
des3_set_key,
des3_1_encrypt,
des3_1_decrypt
},
#endif /* HAS_DES */
{
.name = NULL,
.blocksize = 0,
.keylen = 0,
.key = NULL,
.keysize = 0,
.set_encrypt_key = NULL,
.set_decrypt_key = NULL,
.cbc_encrypt = NULL,
.cbc_decrypt = NULL
NULL,
0,
0,
NULL,
0,
NULL,
NULL,
NULL,
NULL
}
};
#endif /* OPENSSL_CRYPTO */