Skip to content

Commit ef4ffda

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/L1'
2 parents 72e1c0a + ac42afd commit ef4ffda

25 files changed

+3693
-796
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121
*.sh text eol=lf
2222
config.sub text eol=lf
2323
fixalgorithms text eol=lf
24+
runconfigure text eol=lf

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,13 @@ regress/t6.out1
254254
Makefile
255255
openbsd-compat/Makefile
256256
openbsd-compat/regress/Makefile
257-
contrib/win32/win32compat/Makefile
257+
contrib/win32/win32compat/Makefile
258+
config.h
259+
config.h
260+
regress/rsa_ssh2_cr.prv
261+
regress/rsa_ssh2_crnl.prv
262+
regress/t7.out.pub
263+
regress/t6.out2
264+
config.h
265+
configure
266+
config.h

Makefile

Lines changed: 0 additions & 616 deletions
This file was deleted.

Makefile.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CC=@CC@
4444
LD=@LD@
4545
CFLAGS=@CFLAGS@
4646
CPPFLAGS=-I. -I$(srcdir) @CPPFLAGS@ $(PATHS) @DEFS@
47-
LIBS=@LIBS@
47+
LIBS=@LIBS@ -lbcrypt
4848
K5LIBS=@K5LIBS@
4949
GSSLIBS=@GSSLIBS@
5050
SSHLIBS=@SSHLIBS@
@@ -58,7 +58,7 @@ PERL=@PERL@
5858
SED=@SED@
5959
ENT=@ENT@
6060
XAUTH_PATH=@XAUTH_PATH@
61-
LDFLAGS=-L. -Lopenbsd-compat/ -Lcontrib/win32/win32compat @LDFLAGS@
61+
LDFLAGS=-L. -Lopenbsd-compat/ -Lcontrib/win32/win32compat @LDFLAGS@ -L/lib/w32api
6262
EXEEXT=@EXEEXT@
6363
MANFMT=@MANFMT@
6464

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
See http://www.openssh.com/txt/release-7.1 for the release notes.
2+
See https://github.com/PowerShell/Win32-OpenSSH/wiki for build/deployment information
23

34
Please read http://www.openssh.com/report.html for bug reporting
45
instructions and note that we do not use Github for bug reporting or

channels.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,25 +2454,16 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
24542454
c->local_window -= win_len;
24552455
}
24562456

2457-
#ifdef WIN32_FIXME
2458-
if ( (c->client_tty) && (data_len >= 5) ) {
2459-
if ( data[0] == '\033' ) { // escape char octal 33, decimal 27
2460-
if ( (data[1] == '[') && (data[2]== '2') && (data[3]== '0') && ( data[4]== 'h' )) {
2461-
lftocrlf = 1;
2462-
data = data + 5 ; // we have processed the 5 bytes ESC sequence
2463-
data_len = data_len - 5;
2464-
}
2465-
}
2466-
}
2467-
#endif
2468-
24692457
if (c->datagram)
24702458
buffer_put_string(&c->output, data, data_len);
24712459
else {
24722460
#ifndef WIN32_FIXME
24732461
buffer_append(&c->output, data, data_len);
24742462
#else
2475-
buffer_append(&c->output, data, data_len);
2463+
if ( c->client_tty )
2464+
telProcessNetwork ( data, data_len ); // run it by ANSI engine if it is the ssh client
2465+
else
2466+
buffer_append(&c->output, data, data_len); // it is the sshd server, so pass it on
24762467
if ( c->isatty ) {
24772468
buffer_append(&c->input, data, data_len); // we echo the data if it is sshd server and pty interactive mode
24782469
if ( (data_len ==1) && (data[0] == '\b') )

cipher.c

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3535
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3636
*/
37-
37+
3838
#include "includes.h"
3939

4040
#include <sys/types.h>
@@ -43,6 +43,7 @@
4343
#include <stdarg.h>
4444
#include <stdio.h>
4545

46+
4647
#include "cipher.h"
4748
#include "misc.h"
4849
#include "sshbuf.h"
@@ -51,6 +52,12 @@
5152

5253
#include "openbsd-compat/openssl-compat.h"
5354

55+
56+
57+
#ifdef USE_MSCNG
58+
#undef WITH_OPENSSL
59+
#endif
60+
5461
#ifdef WITH_SSH1
5562
extern const EVP_CIPHER *evp_ssh1_bf(void);
5663
extern const EVP_CIPHER *evp_ssh1_3des(void);
@@ -108,9 +115,19 @@ static const struct sshcipher ciphers[] = {
108115
SSH_CIPHER_SSH2, 16, 32, 12, 16, 0, 0, EVP_aes_256_gcm },
109116
# endif /* OPENSSL_HAVE_EVPGCM */
110117
#else /* WITH_OPENSSL */
118+
119+
#ifdef USE_MSCNG
120+
{ "aes128-ctr", SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CTR, NULL },
121+
{ "aes192-ctr", SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CTR, NULL },
122+
{ "aes256-ctr", SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CTR, NULL },
123+
{ "aes128-cbc", SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CBC, NULL },
124+
{ "aes192-cbc", SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CBC, NULL },
125+
{ "aes256-cbc", SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, _CNG_CIPHER_AES | _CNG_MODE_CBC, NULL },
126+
#else
111127
{ "aes128-ctr", SSH_CIPHER_SSH2, 16, 16, 0, 0, 0, CFLAG_AESCTR, NULL },
112128
{ "aes192-ctr", SSH_CIPHER_SSH2, 16, 24, 0, 0, 0, CFLAG_AESCTR, NULL },
113129
{ "aes256-ctr", SSH_CIPHER_SSH2, 16, 32, 0, 0, 0, CFLAG_AESCTR, NULL },
130+
#endif
114131
{ "none", SSH_CIPHER_NONE, 8, 0, 0, 0, 0, CFLAG_NONE, NULL },
115132
#endif /* WITH_OPENSSL */
116133
@@ -293,6 +310,8 @@ cipher_init(struct sshcipher_ctx *cc, const struct sshcipher *cipher,
293310
const u_char *key, u_int keylen, const u_char *iv, u_int ivlen,
294311
int do_encrypt)
295312
{
313+
314+
296315
#ifdef WITH_OPENSSL
297316
int ret = SSH_ERR_INTERNAL_ERROR;
298317
const EVP_CIPHER *type;
@@ -316,11 +335,25 @@ cipher_init(struct sshcipher_ctx *cc, const struct sshcipher *cipher,
316335
return chachapoly_init(&cc->cp_ctx, key, keylen);
317336
}
318337
#ifndef WITH_OPENSSL
338+
339+
#ifdef USE_MSCNG
340+
341+
/* cng shares cipher flag with NONE. Make sure the NONE cipher isn't requested */
342+
if ((cc->cipher->flags & CFLAG_NONE) == 0)
343+
{
344+
345+
if (cng_cipher_init(&cc->cng_ctx,key,keylen,iv, ivlen,cc->cipher->flags))
346+
return SSH_ERR_LIBCRYPTO_ERROR;
347+
348+
return 0;
349+
}
350+
#else
319351
if ((cc->cipher->flags & CFLAG_AESCTR) != 0) {
320352
aesctr_keysetup(&cc->ac_ctx, key, 8 * keylen, 8 * ivlen);
321353
aesctr_ivsetup(&cc->ac_ctx, iv);
322354
return 0;
323355
}
356+
#endif
324357
if ((cc->cipher->flags & CFLAG_NONE) != 0)
325358
return 0;
326359
return SSH_ERR_INVALID_ARGUMENT;
@@ -373,6 +406,7 @@ cipher_init(struct sshcipher_ctx *cc, const struct sshcipher *cipher,
373406
return 0;
374407
}
375408

409+
376410
/*
377411
* cipher_crypt() operates as following:
378412
* Copy 'aadlen' bytes (without en/decryption) from 'src' to 'dest'.
@@ -387,18 +421,44 @@ int
387421
cipher_crypt(struct sshcipher_ctx *cc, u_int seqnr, u_char *dest,
388422
const u_char *src, u_int len, u_int aadlen, u_int authlen)
389423
{
424+
#ifdef USE_MSCNG
425+
int ret = 0;
426+
#endif
427+
390428
if ((cc->cipher->flags & CFLAG_CHACHAPOLY) != 0) {
391429
return chachapoly_crypt(&cc->cp_ctx, seqnr, dest, src,
392430
len, aadlen, authlen, cc->encrypt);
393431
}
394432
#ifndef WITH_OPENSSL
395-
if ((cc->cipher->flags & CFLAG_AESCTR) != 0) {
433+
434+
#ifdef USE_MSCNG
435+
436+
/* cng shares cipher flag with NONE. Make sure the NONE cipher isn't requested */
437+
if ((cc->cipher->flags & CFLAG_NONE) == 0)
438+
{
439+
if (aadlen)
440+
memcpy(dest, src, aadlen);
441+
if (cc->encrypt)
442+
ret = cng_cipher_encrypt(&cc->cng_ctx,dest+aadlen, len, src+aadlen,len);
443+
else
444+
ret = cng_cipher_decrypt(&cc->cng_ctx,dest+aadlen, len, src+aadlen, len);
445+
446+
if (ret != len){
447+
return SSH_ERR_LIBCRYPTO_ERROR;
448+
}
449+
return 0;
450+
}
451+
#else
452+
if ((cc->cipher->flags & CFLAG_AESCTR) != 0) {
396453
if (aadlen)
397454
memcpy(dest, src, aadlen);
398455
aesctr_encrypt_bytes(&cc->ac_ctx, src + aadlen,
399456
dest + aadlen, len);
400457
return 0;
401458
}
459+
#endif
460+
461+
402462
if ((cc->cipher->flags & CFLAG_NONE) != 0) {
403463
memcpy(dest, src, aadlen + len);
404464
return 0;
@@ -472,6 +532,10 @@ cipher_cleanup(struct sshcipher_ctx *cc)
472532
else if (EVP_CIPHER_CTX_cleanup(&cc->evp) == 0)
473533
return SSH_ERR_LIBCRYPTO_ERROR;
474534
#endif
535+
#ifdef USE_MSCNG
536+
else
537+
cng_cipher_cleanup(&cc->cng_ctx);
538+
#endif
475539
return 0;
476540
}
477541

cipher.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
#include <openssl/evp.h>
4242
#include "cipher-chachapoly.h"
4343
#include "cipher-aesctr.h"
44-
44+
#ifdef USE_MSCNG
45+
#include "contrib/win32/win32compat/cng_cipher.h"
46+
#endif
4547
/*
4648
* Cipher types for SSH-1. New types can be added, but old types should not
4749
* be removed for compatibility. The maximum allowed value is 31.
@@ -70,6 +72,10 @@ struct sshcipher_ctx {
7072
struct chachapoly_ctx cp_ctx; /* XXX union with evp? */
7173
struct aesctr_ctx ac_ctx; /* XXX union with evp? */
7274
const struct sshcipher *cipher;
75+
#ifdef USE_MSCNG
76+
struct ssh_cng_cipher_ctx cng_ctx;
77+
#endif
78+
7379
};
7480

7581
u_int cipher_mask_ssh1(int);

0 commit comments

Comments
 (0)