Diff

Differences From Artifact [6e281a0005]:

To Artifact [303fdced77]:


1
2
3

4
5
6
7
8
9
10
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>


#include "putty.h"
#include "ssh.h"

#define GET_32BIT_LSB_FIRST(cp) \
  (((unsigned long)(unsigned char)(cp)[0]) | \
  ((unsigned long)(unsigned char)(cp)[1] << 8) | \



>







1
2
3
4
5
6
7
8
9
10
11
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>

#include "putty.h"
#include "ssh.h"

#define GET_32BIT_LSB_FIRST(cp) \
  (((unsigned long)(unsigned char)(cp)[0]) | \
  ((unsigned long)(unsigned char)(cp)[1] << 8) | \
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#define GET_16BIT(endian, cp) \
  (endian=='B' ? GET_16BIT_MSB_FIRST(cp) : GET_16BIT_LSB_FIRST(cp))

#define PUT_16BIT(endian, cp, val) \
  (endian=='B' ? PUT_16BIT_MSB_FIRST(cp, val) : PUT_16BIT_LSB_FIRST(cp, val))

const char *const x11_authnames[] = {
    "", "MIT-MAGIC-COOKIE-1"
};

struct X11Auth {
    unsigned char fakedata[64], realdata[64];
    int fakeproto, realproto;
    int fakelen, reallen;
};







|







49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#define GET_16BIT(endian, cp) \
  (endian=='B' ? GET_16BIT_MSB_FIRST(cp) : GET_16BIT_LSB_FIRST(cp))

#define PUT_16BIT(endian, cp, val) \
  (endian=='B' ? PUT_16BIT_MSB_FIRST(cp, val) : PUT_16BIT_LSB_FIRST(cp, val))

const char *const x11_authnames[] = {
    "", "MIT-MAGIC-COOKIE-1", "XDM-AUTHORIZATION-1"
};

struct X11Auth {
    unsigned char fakedata[64], realdata[64];
    int fakeproto, realproto;
    int fakelen, reallen;
};
377
378
379
380
381
382
383


384
385
386
387
388
389












390
391
392
393
394
395
396
397
	 * the fake auth data, and optionally put real auth data in
	 * instead.
	 */
        {
            char realauthdata[64];
            int realauthlen = 0;
            int authstrlen = strlen(x11_authnames[pr->auth->realproto]);


            static const char zeroes[4] = { 0,0,0,0 };

            if (pr->auth->realproto == X11_MIT) {
                assert(pr->auth->reallen <= lenof(realauthdata));
                realauthlen = pr->auth->reallen;
                memcpy(realauthdata, pr->auth->realdata, realauthlen);












            }
            /* implement other auth methods here if required */

            PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 6, authstrlen);
            PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 8, realauthlen);
        
            sk_write(s, (char *)pr->firstpkt, 12);








>
>






>
>
>
>
>
>
>
>
>
>
>
>
|







378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
	 * the fake auth data, and optionally put real auth data in
	 * instead.
	 */
        {
            char realauthdata[64];
            int realauthlen = 0;
            int authstrlen = strlen(x11_authnames[pr->auth->realproto]);
	    unsigned long ip;
	    int port;
            static const char zeroes[4] = { 0,0,0,0 };

            if (pr->auth->realproto == X11_MIT) {
                assert(pr->auth->reallen <= lenof(realauthdata));
                realauthlen = pr->auth->reallen;
                memcpy(realauthdata, pr->auth->realdata, realauthlen);
            } else if (pr->auth->realproto == X11_XDM &&
		       pr->auth->reallen == 16 &&
		       sk_getxdmdata(s, &ip, &port)) {
		time_t t;
                realauthlen = 24;
		memset(realauthdata, 0, 24);
		memcpy(realauthdata, pr->auth->realdata, 8);
		PUT_32BIT_MSB_FIRST(realauthdata+8, ip);
		PUT_16BIT_MSB_FIRST(realauthdata+12, port);
		t = time(NULL);
		PUT_32BIT_MSB_FIRST(realauthdata+14, t);
		des_encrypt_xdmauth(pr->auth->realdata+9, realauthdata, 24);
	    }
            /* implement other auth methods here if required */

            PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 6, authstrlen);
            PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 8, realauthlen);
        
            sk_write(s, (char *)pr->firstpkt, 12);